5 #define YUILogComponent "gtk" 6 #include <yui/Libyui_config.h> 10 #include "ygtkwizard.h" 12 #include "YPushButton.h" 13 #include "YAlignment.h" 14 #include "YReplacePoint.h" 19 YReplacePoint *m_replacePoint;
30 struct YGWButton :
public YPushButton {
33 YGWButton (
YGWizard *parent, GtkWidget *widget,
const std::string &label)
34 : YPushButton (parent, label), m_widget (widget), m_wizard (parent)
38 ygtk_wizard_set_button_ptr_id (getWizard(), widget,
this);
41 virtual void setLabel (
const std::string &label)
43 YPushButton::setLabel (label);
49 std::string _label = YGUtils::mapKBAccel (label);
50 ygtk_wizard_set_button_label (wizard, getWidget(), _label.c_str(), NULL);
53 virtual void setEnabled (
bool enable)
55 YWidget::setEnabled (enable);
56 ygtk_wizard_enable_button (getWizard(), getWidget(), enable);
59 virtual bool setKeyboardFocus()
61 gtk_widget_grab_focus (getWidget());
62 return gtk_widget_is_focus (getWidget());
65 virtual int preferredWidth() {
return 0; }
66 virtual int preferredHeight() {
return 0; }
67 virtual void setSize (
int w,
int h) {}
69 inline GtkWidget *getWidget() {
return m_widget; }
70 inline YGtkWizard *getWizard() {
return YGTK_WIZARD (m_wizard->getWidget()); }
77 YGWButton *m_back_button, *m_abort_button, *m_next_button, *m_notes_button;
82 YGWizard (YWidget *parent,
const std::string &backButtonLabel,
83 const std::string &abortButtonLabel,
const std::string &nextButtonLabel,
84 YWizardMode wizardMode)
85 : YWizard (NULL, backButtonLabel, abortButtonLabel, nextButtonLabel, wizardMode)
86 ,
YGWidget (
this, parent, YGTK_TYPE_WIZARD, NULL)
93 YAlignment *align = YUI::widgetFactory()->createAlignment (
this,
94 YAlignCenter, YAlignCenter);
95 align->setStretchable (YD_HORIZ,
true);
96 align->setStretchable (YD_VERT,
true);
98 m_replacePoint = YUI::widgetFactory()->createReplacePoint ((YWidget *) align);
99 YUI::widgetFactory()->createEmpty ((YWidget *) m_replacePoint);
100 m_replacePoint->showChild();
104 bool steps_enabled = wizardMode == YWizardMode_Steps;
105 bool tree_enabled = wizardMode == YWizardMode_Tree;
106 if (steps_enabled && tree_enabled) {
107 yuiError() <<
"YGWizard doesn't support both steps and tree enabled at the " 108 "same time.\nDisabling the steps...\n";
109 steps_enabled =
false;
112 ygtk_wizard_enable_steps (wizard);
114 ygtk_wizard_enable_tree (wizard);
117 m_back_button =
new YGWButton (
this, wizard->back_button, backButtonLabel);
118 m_abort_button =
new YGWButton (
this, wizard->abort_button, abortButtonLabel);
119 m_next_button =
new YGWButton (
this, wizard->next_button, nextButtonLabel);
120 m_notes_button =
new YGWButton (
this, wizard->release_notes_button, std::string());
121 ygtk_wizard_set_default_button (wizard, wizard->next_button);
124 g_signal_connect (G_OBJECT (getWidget()),
"action-triggered",
125 G_CALLBACK (action_triggered_cb),
this);
135 {
return YGTK_WIZARD (getWidget()); }
137 virtual YReplacePoint *contentsReplacePoint()
const 138 {
return m_replacePoint; }
140 virtual YPushButton *backButton()
const 141 {
return m_back_button; }
142 virtual YPushButton *abortButton()
const 143 {
return m_abort_button; }
144 virtual YPushButton *nextButton()
const 145 {
return m_next_button; }
147 virtual void setButtonLabel (YPushButton *button,
const std::string &label)
149 button->setLabel (label);
152 virtual void setHelpText (
const std::string &_text)
154 std::string productName = YUI::app()->productName();
155 std::string text(_text);
156 YGUtils::replace (text,
"&product;", 9, productName.c_str());
157 ygtk_wizard_set_help_text (getWizard(), text.c_str());
160 virtual void setDialogIcon (
const std::string &icon)
162 if (!ygtk_wizard_set_header_icon (getWizard(), icon.c_str()))
163 yuiWarning() <<
"YGWizard: could not load image: " << icon << std::endl;
164 YGDialog::currentDialog()->setIcon (icon);
167 virtual void setDialogHeading (
const std::string &heading)
169 ygtk_wizard_set_header_text (getWizard(), heading.c_str());
170 YGDialog::currentDialog()->setTitle (heading,
false);
173 virtual void setDialogTitle (
const std::string &title)
175 YGDialog::currentDialog()->setTitle (title,
true);
178 virtual void addStepHeading (
const std::string &text)
180 ygtk_wizard_add_step_header (getWizard(), text.c_str());
183 virtual void addStep (
const std::string &text,
const std::string &
id)
185 ygtk_wizard_add_step (getWizard(), text.c_str(),
id.c_str());
188 virtual void setCurrentStep (
const std::string &
id)
190 if (!ygtk_wizard_set_current_step (getWizard(),
id.c_str()))
191 yuiError() <<
"YGWizard: there is no step with id " <<
id << std::endl;
194 virtual void deleteSteps()
196 ygtk_wizard_clear_steps (getWizard());
199 virtual void updateSteps()
202 virtual void addTreeItem (
const std::string &parentID,
const std::string &text,
203 const std::string &
id)
205 if (!ygtk_wizard_add_tree_item (getWizard(), parentID.c_str(),
206 text.c_str(),
id.c_str()))
207 yuiError() <<
"YGWizard: there is no tree item with id " << parentID << std::endl;
210 virtual void selectTreeItem (
const std::string &
id)
212 if (!ygtk_wizard_select_tree_item (getWizard(),
id.c_str()))
213 yuiError() <<
"YGWizard: there is no tree item with id " <<
id << std::endl;
216 virtual std::string currentTreeSelection()
218 const char *selected = ygtk_wizard_get_tree_selection (getWizard());
221 return std::string();
224 virtual void deleteTreeItems()
226 ygtk_wizard_clear_tree (getWizard());
229 virtual void addMenu (
const std::string &text,
const std::string &
id)
231 std::string str = YGUtils::mapKBAccel (text);
232 ygtk_wizard_add_menu (getWizard(), str.c_str(),
id.c_str());
235 virtual void addSubMenu (
const std::string &parentID,
const std::string &text,
236 const std::string &
id)
238 std::string str = YGUtils::mapKBAccel(text);
239 if (!ygtk_wizard_add_sub_menu (getWizard(), parentID.c_str(), str.c_str(),
241 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
244 virtual void addMenuEntry (
const std::string &parentID,
const std::string &text,
245 const std::string &
id)
247 std::string str = YGUtils::mapKBAccel (text);
248 if (!ygtk_wizard_add_menu_entry (getWizard(), parentID.c_str(),
249 str.c_str(),
id.c_str()))
250 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
253 virtual void addMenuSeparator (
const std::string & parentID)
255 if (!ygtk_wizard_add_menu_separator (getWizard(), parentID.c_str()))
256 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
259 virtual void deleteMenus()
261 ygtk_wizard_clear_menu (getWizard());
264 virtual void showReleaseNotesButton (
const std::string &label,
const std::string &
id)
266 std::string str = YGUtils::mapKBAccel (label.c_str());
267 ygtk_wizard_set_button_label (getWizard(), m_notes_button->getWidget(), str.c_str(), NULL);
268 ygtk_wizard_set_button_str_id (getWizard(), m_notes_button->getWidget(),
id.c_str());
271 virtual void hideReleaseNotesButton()
273 ygtk_wizard_set_button_label (getWizard(), m_notes_button->getWidget(), NULL, NULL);
276 virtual void retranslateInternalButtons()
279 static void action_triggered_cb (
YGtkWizard *wizard, gpointer
id,
282 if ((GType) id_type == G_TYPE_STRING)
283 YGUI::ui()->sendEvent (
new YMenuEvent ((
char *)
id));
285 YGUI::ui()->sendEvent (
new YWidgetEvent ((YWidget *)
id, YEvent::Activated));
289 virtual void doAddChild (YWidget *ychild, GtkWidget *container)
291 if (ychild->widgetRep())
292 ygtk_wizard_set_child (getWizard(), YGWidget::get (ychild)->getLayout());
295 YGWIDGET_IMPL_CONTAINER (YWizard)
298 YWizard *YGOptionalWidgetFactory::createWizard (YWidget *parent,
299 const std::string &backButtonLabel,
const std::string &abortButtonLabel,
300 const std::string &nextButtonLabel, YWizardMode wizardMode)
302 return new YGWizard (parent, backButtonLabel, abortButtonLabel, nextButtonLabel,