~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to backend/wbpublic/grtui/grt_wizard_form.h

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* 
 
2
 * Copyright (c) 2007, 2011, Oracle and/or its affiliates. All rights reserved.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or
 
5
 * modify it under the terms of the GNU General Public License as
 
6
 * published by the Free Software Foundation; version 2 of the
 
7
 * License.
 
8
 * 
 
9
 * This program is distributed in the hope that it will be useful,
 
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 
12
 * GNU General Public License for more details.
 
13
 * 
 
14
 * You should have received a copy of the GNU General Public License
 
15
 * along with this program; if not, write to the Free Software
 
16
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 
17
 * 02110-1301  USA
 
18
 */
 
19
 
 
20
#ifndef _WIZARDFORM_H_
 
21
#define _WIZARDFORM_H_
 
22
 
 
23
#include <vector>
 
24
#include <set>
 
25
 
 
26
#include <grtpp.h>
 
27
#include "grt/common.h"
 
28
 
 
29
#include "wbpublic_public_interface.h"
 
30
#include "base/string_utilities.h"
 
31
 
 
32
#include "mforms/wizard.h"
 
33
#include "mforms/box.h"
 
34
#include "mforms/filechooser.h"
 
35
 
 
36
namespace bec {
 
37
  class GRTManager;
 
38
};
 
39
 
 
40
namespace mforms {
 
41
  class TextEntry;
 
42
};
 
43
 
 
44
namespace grtui {
 
45
 
 
46
  class WizardPage;
 
47
 
 
48
  class WBPUBLICBACKEND_PUBLIC_FUNC WizardForm : public ::mforms::Wizard
 
49
  {
 
50
  public:
 
51
    WizardForm(bec::GRTManager *mgr);
 
52
    virtual ~WizardForm();
 
53
 
 
54
    virtual bool run_modal();
 
55
 
 
56
    void add_page(WizardPage *page);
 
57
 
 
58
    void update_buttons();
 
59
    void update_heading();
 
60
 
 
61
    void set_problem(const std::string &text);
 
62
    void clear_problem();
 
63
 
 
64
    virtual void reset();
 
65
    
 
66
    void switch_to_page(WizardPage *page, bool advancing);
 
67
    WizardPage *get_active_page() { return _active_page; }
 
68
    int get_active_page_number();
 
69
    
 
70
    WizardPage *get_page_with_id(const std::string &id);
 
71
 
 
72
    bec::GRTManager *grtm() { return _grtm; }
 
73
    
 
74
    grt::DictRef values() { return _values; }
 
75
    
 
76
  public:
 
77
    // util stuff for storing state
 
78
    void set_wizard_option(const std::string &key, const std::string &value);
 
79
    std::string string_wizard_option(const std::string &key, const std::string &default_value= "");
 
80
 
 
81
    void set_wizard_option(const std::string &key, int value);
 
82
    int int_wizard_option(const std::string &key, int default_value= 0);
 
83
 
 
84
  private:    
 
85
    grt::DictRef _values;
 
86
     
 
87
    std::string _problem;
 
88
 
 
89
    WizardPage *_active_page;
 
90
    std::vector<WizardPage*> _pages;
 
91
    std::list<WizardPage*> _turned_pages;
 
92
 
 
93
    bool _cancelled;
 
94
  protected:
 
95
    bec::GRTManager *_grtm;
 
96
 
 
97
    virtual WizardPage *get_next_page(WizardPage *current);
 
98
    void refresh_step_list();
 
99
 
 
100
    void extra_clicked();
 
101
    
 
102
  public:
 
103
    void go_to_next();
 
104
    void go_to_back();
 
105
    void finish();
 
106
    virtual bool cancel();
 
107
  };
 
108
 
 
109
 
 
110
  /** A page of a wizard.
 
111
    */
 
112
  class WBPUBLICBACKEND_PUBLIC_FUNC WizardPage : public ::mforms::Box
 
113
  {
 
114
  public:
 
115
    WizardPage(WizardForm *form, const std::string &pageid);
 
116
 
 
117
    std::string get_id() const { return _id; }
 
118
    
 
119
    std::string get_title() const { return _title; }
 
120
    std::string get_short_title() const { return _short_title; }
 
121
    
 
122
    void set_title(const std::string &title);
 
123
    void set_short_title(const std::string &title);
 
124
 
 
125
    void validate();
 
126
 
 
127
    boost::signals2::signal<void (bool)>* signal_enter() { return &_signal_enter; }
 
128
    boost::signals2::signal<void (bool)>* signal_leave() { return &_signal_leave; }
 
129
    
 
130
  public:
 
131
 
 
132
 
 
133
  protected:
 
134
    friend class WizardForm;
 
135
 
 
136
    grt::DictRef values() { return _form->values(); }
 
137
 
 
138
    //! Subclasses must override this to implement validation.
 
139
    //! If there is a validation error, it must call _form->set_problem()
 
140
    virtual void do_validate() { }
 
141
    
 
142
    virtual int load() { return -1; } // delme XXX
 
143
    
 
144
    virtual bool pre_load();
 
145
    virtual void enter(bool advancing);
 
146
    virtual bool advance();
 
147
    virtual void leave(bool advancing);
 
148
    
 
149
    virtual bool allow_next() { return true; }
 
150
    virtual bool allow_back() { return true; }
 
151
    virtual bool allow_cancel() { return true; }
 
152
    virtual bool skip_page() { return false; } // Return true if the page should not be displayed (due to some condition).
 
153
    
 
154
    //! return true if this is the last page and pressing next should close wizard
 
155
    virtual bool next_closes_wizard() { return false; }
 
156
    
 
157
    //! overrider may return "" for default caption
 
158
    virtual std::string next_button_caption() { return ""; }
 
159
    
 
160
    virtual std::string extra_button_caption() { return ""; }
 
161
 
 
162
    std::string finish_button_caption() const
 
163
    {
 
164
#ifdef __APPLE__
 
165
      return _("Close");
 
166
#elif defined(_WIN32)
 
167
      return _("Finish");
 
168
#else
 
169
      return _("_Close");
 
170
#endif
 
171
    }
 
172
    
 
173
    virtual void extra_clicked() {}
 
174
    
 
175
  protected:
 
176
    WizardForm *_form;
 
177
    std::string _id;
 
178
    boost::signals2::signal<void (bool)> _signal_enter;
 
179
    boost::signals2::signal<void (bool)> _signal_leave;
 
180
    std::string _title;
 
181
    std::string _short_title;
 
182
    
 
183
    std::string execute_caption() const
 
184
    {
 
185
#ifdef __APPLE__
 
186
      return _("Execute");
 
187
#elif defined(_WIN32)
 
188
      return _("_Execute >");
 
189
#else
 
190
      return _("_Execute");
 
191
#endif
 
192
    }
 
193
 
 
194
    std::string finish_caption() const
 
195
    {
 
196
#ifdef __APPLE__
 
197
      return _("Finish");
 
198
#else
 
199
      return _("_Finish");
 
200
#endif
 
201
    }
 
202
 
 
203
    virtual std::string close_caption() const
 
204
    {
 
205
#ifdef __APPLE__
 
206
      return _("Close");
 
207
#else
 
208
      return _("_Close");
 
209
#endif
 
210
    }
 
211
    
 
212
  private:
 
213
    void filename_changed(mforms::TextEntry *entry);
 
214
    void browse_file_callback(mforms::TextEntry *entry, mforms::FileChooserType type,
 
215
                              const std::string &extensions);
 
216
  };
 
217
 
 
218
};
 
219
 
 
220
 
 
221
#endif