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()); }
72 virtual void activate()
74 gtk_button_clicked(GTK_BUTTON (getWidget()));
82 YGWButton *m_back_button, *m_abort_button, *m_next_button, *m_notes_button;
87 YGWizard (YWidget *parent,
const std::string &backButtonLabel,
88 const std::string &abortButtonLabel,
const std::string &nextButtonLabel,
89 YWizardMode wizardMode)
90 : YWizard (NULL, backButtonLabel, abortButtonLabel, nextButtonLabel, wizardMode)
91 ,
YGWidget (
this, parent, YGTK_TYPE_WIZARD, NULL)
98 YAlignment *align = YUI::widgetFactory()->createAlignment (
this,
99 YAlignCenter, YAlignCenter);
100 align->setStretchable (YD_HORIZ,
true);
101 align->setStretchable (YD_VERT,
true);
103 m_replacePoint = YUI::widgetFactory()->createReplacePoint ((YWidget *) align);
104 YUI::widgetFactory()->createEmpty ((YWidget *) m_replacePoint);
105 m_replacePoint->showChild();
109 bool steps_enabled = wizardMode == YWizardMode_Steps;
110 bool tree_enabled = wizardMode == YWizardMode_Tree;
111 if (steps_enabled && tree_enabled) {
112 yuiError() <<
"YGWizard doesn't support both steps and tree enabled at the "
113 "same time.\nDisabling the steps...\n";
114 steps_enabled =
false;
117 ygtk_wizard_enable_steps (wizard);
119 ygtk_wizard_enable_tree (wizard);
122 m_back_button =
new YGWButton (
this, wizard->back_button, backButtonLabel);
123 m_abort_button =
new YGWButton (
this, wizard->abort_button, abortButtonLabel);
124 m_next_button =
new YGWButton (
this, wizard->next_button, nextButtonLabel);
125 m_notes_button =
new YGWButton (
this, wizard->release_notes_button, std::string());
126 ygtk_wizard_set_default_button (wizard, wizard->next_button);
129 g_signal_connect (G_OBJECT (getWidget()),
"action-triggered",
130 G_CALLBACK (action_triggered_cb),
this);
140 {
return YGTK_WIZARD (getWidget()); }
142 virtual YReplacePoint *contentsReplacePoint()
const
143 {
return m_replacePoint; }
145 virtual YPushButton *backButton()
const
146 {
return m_back_button; }
147 virtual YPushButton *abortButton()
const
148 {
return m_abort_button; }
149 virtual YPushButton *nextButton()
const
150 {
return m_next_button; }
152 virtual void setButtonLabel (YPushButton *button,
const std::string &label)
154 button->setLabel (label);
157 virtual void setHelpText (
const std::string &_text)
159 std::string productName = YUI::app()->productName();
160 std::string text(_text);
161 YGUtils::replace (text,
"&product;", 9, productName.c_str());
162 ygtk_wizard_set_help_text (getWizard(), text.c_str());
165 virtual void setDialogIcon (
const std::string &icon)
167 if (!ygtk_wizard_set_header_icon (getWizard(), icon.c_str()))
168 yuiWarning() <<
"YGWizard: could not load image: " << icon << std::endl;
169 YGDialog::currentDialog()->setIcon (icon);
172 virtual void setDialogHeading (
const std::string &heading)
174 ygtk_wizard_set_header_text (getWizard(), heading.c_str());
175 YGDialog::currentDialog()->setTitle (heading,
false);
178 virtual std::string getDialogHeading()
180 #warning YGWizard::getDialogHeading() not implemented yet
181 yuiWarning() <<
"YGWizard::getDialogHeading() not implemented yet" << std::endl;
182 return std::string();
185 virtual void setDialogTitle (
const std::string &title)
187 YGDialog::currentDialog()->setTitle (title,
true);
190 virtual std::string getDialogTitle()
192 #warning YGWizard::getDialogTitle() not implemented yet
193 yuiWarning() <<
"YGWizard::getDialogTitle() not implemented yet" << std::endl;
194 return std::string();
197 virtual void addStepHeading (
const std::string &text)
199 ygtk_wizard_add_step_header (getWizard(), text.c_str());
202 virtual void addStep (
const std::string &text,
const std::string &
id)
204 ygtk_wizard_add_step (getWizard(), text.c_str(),
id.c_str());
207 virtual void setCurrentStep (
const std::string &
id)
209 if (!ygtk_wizard_set_current_step (getWizard(),
id.c_str()))
210 yuiError() <<
"YGWizard: there is no step with id " <<
id << std::endl;
213 virtual void deleteSteps()
215 ygtk_wizard_clear_steps (getWizard());
218 virtual void updateSteps()
221 virtual void addTreeItem (
const std::string &parentID,
const std::string &text,
222 const std::string &
id)
224 if (!ygtk_wizard_add_tree_item (getWizard(), parentID.c_str(),
225 text.c_str(),
id.c_str()))
226 yuiError() <<
"YGWizard: there is no tree item with id " << parentID << std::endl;
229 virtual void selectTreeItem (
const std::string &
id)
231 if (!ygtk_wizard_select_tree_item (getWizard(),
id.c_str()))
232 yuiError() <<
"YGWizard: there is no tree item with id " <<
id << std::endl;
235 virtual std::string currentTreeSelection()
237 const char *selected = ygtk_wizard_get_tree_selection (getWizard());
240 return std::string();
243 virtual void deleteTreeItems()
245 ygtk_wizard_clear_tree (getWizard());
248 virtual void addMenu (
const std::string &text,
const std::string &
id)
250 std::string str = YGUtils::mapKBAccel (text);
251 ygtk_wizard_add_menu (getWizard(), str.c_str(),
id.c_str());
254 virtual void addSubMenu (
const std::string &parentID,
const std::string &text,
255 const std::string &
id)
257 std::string str = YGUtils::mapKBAccel(text);
258 if (!ygtk_wizard_add_sub_menu (getWizard(), parentID.c_str(), str.c_str(),
260 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
263 virtual void addMenuEntry (
const std::string &parentID,
const std::string &text,
264 const std::string &
id)
266 std::string str = YGUtils::mapKBAccel (text);
267 if (!ygtk_wizard_add_menu_entry (getWizard(), parentID.c_str(),
268 str.c_str(),
id.c_str()))
269 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
272 virtual void addMenuSeparator (
const std::string & parentID)
274 if (!ygtk_wizard_add_menu_separator (getWizard(), parentID.c_str()))
275 yuiError() <<
"YGWizard: there is no menu item with id " << parentID << std::endl;
278 virtual void deleteMenus()
280 ygtk_wizard_clear_menu (getWizard());
283 virtual void showReleaseNotesButton (
const std::string &label,
const std::string &
id)
285 std::string str = YGUtils::mapKBAccel (label.c_str());
286 ygtk_wizard_set_button_label (getWizard(), m_notes_button->getWidget(), str.c_str(), NULL);
287 ygtk_wizard_set_button_str_id (getWizard(), m_notes_button->getWidget(),
id.c_str());
290 virtual void hideReleaseNotesButton()
292 ygtk_wizard_set_button_label (getWizard(), m_notes_button->getWidget(), NULL, NULL);
295 virtual void retranslateInternalButtons()
298 static void action_triggered_cb (
YGtkWizard *wizard, gpointer
id,
301 if ((GType) id_type == G_TYPE_STRING)
302 YGUI::ui()->sendEvent (
new YMenuEvent ((
char *)
id));
304 YGUI::ui()->sendEvent (
new YWidgetEvent ((YWidget *)
id, YEvent::Activated));
308 virtual void doAddChild (YWidget *ychild, GtkWidget *container)
310 if (ychild->widgetRep())
311 ygtk_wizard_set_child (getWizard(), YGWidget::get (ychild)->getLayout());
314 YGWIDGET_IMPL_CONTAINER (YWizard)
317 YWizard *YGOptionalWidgetFactory::createWizard (YWidget *parent,
318 const std::string &backButtonLabel,
const std::string &abortButtonLabel,
319 const std::string &nextButtonLabel, YWizardMode wizardMode)
321 return new YGWizard (parent, backButtonLabel, abortButtonLabel, nextButtonLabel,