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