5 #define YUILogComponent "gtk" 6 #include <yui/Libyui_config.h> 13 static GType getCheckRadioButtonType()
15 static GType type = 0;
20 static const GTypeInfo info = {
21 sizeof (GtkRadioButtonClass), NULL, NULL,
23 sizeof (GtkRadioButton), 0, NULL
25 type = g_type_register_static (GTK_TYPE_RADIO_BUTTON,
"YGRadioButton",
26 &info, GTypeFlags(0));
28 GtkButtonClass *klass_new = GTK_BUTTON_CLASS (g_type_class_ref (type));
29 GtkButtonClass *klass_sane =
30 GTK_BUTTON_CLASS (g_type_class_ref (GTK_TYPE_TOGGLE_BUTTON));
31 klass_new->clicked = klass_sane->clicked;
35 #include "YLayoutBox.h" 37 static bool is_horizontal_box (YWidget *widget)
39 YLayoutBox *box = dynamic_cast <YLayoutBox *> (widget);
41 return box->primary() == YD_HORIZ;
45 #include "YRadioButton.h" 46 #include "YRadioButtonGroup.h" 51 YGRadioButton (YWidget *parent,
const std::string &label,
bool isChecked)
52 : YRadioButton (NULL, label),
53 YGWidget (
this, parent, getCheckRadioButtonType(), NULL)
55 if (!is_horizontal_box (parent))
56 setStretchable (YD_HORIZ,
true);
58 gtk_button_set_use_underline (GTK_BUTTON (getWidget()), TRUE);
59 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (getWidget()), FALSE);
61 connect (getWidget(),
"toggled", G_CALLBACK (toggled_cb),
this);
65 virtual void setLabel (
const std::string &text)
69 std::string str = YGUtils::mapKBAccel(text.c_str());
70 gtk_button_set_label (GTK_BUTTON (getWidget()), str.c_str());
71 YRadioButton::setLabel (text);
75 {
return gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (getWidget())); }
77 virtual void setValue (
bool checked)
80 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (getWidget()), checked);
82 YRadioButton *yradio = static_cast <YRadioButton *> (m_ywidget);
84 buttonGroup()->uncheckOtherButtons (yradio);
88 YGWIDGET_IMPL_COMMON (YRadioButton)
89 YGWIDGET_IMPL_USE_BOLD (YRadioButton)
92 static void toggled_cb (GtkButton *button,
YGRadioButton *pThis)
94 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (button)))
95 pThis->emitEvent (YEvent::ValueChanged);
96 pThis->setValue (
true);
100 YRadioButton *YGWidgetFactory::createRadioButton (YWidget *parent,
const std::string &label,
103 YRadioButton *button =
new YGRadioButton (parent, label, isChecked);
106 YRadioButtonGroup *group = button->buttonGroup();
108 group->addRadioButton (button);
109 button->setValue (isChecked);
117 : YRadioButtonGroup (NULL),
118 YGWidget (
this, parent, GTK_TYPE_EVENT_BOX, NULL)
123 YGWIDGET_IMPL_CONTAINER (YRadioButtonGroup)
126 YRadioButtonGroup *YGWidgetFactory::createRadioButtonGroup (YWidget *parent)
131 #include "YCheckBox.h" 138 YGCheckBox(YWidget *parent,
const std::string &label,
bool isChecked)
139 : YCheckBox (NULL, label),
140 YGWidget (
this, parent, GTK_TYPE_CHECK_BUTTON, NULL)
142 if (!is_horizontal_box (parent))
143 setStretchable (YD_HORIZ,
true);
145 gtk_button_set_use_underline (GTK_BUTTON (getWidget()), TRUE);
146 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (getWidget()), isChecked);
148 connect (getWidget(),
"toggled", G_CALLBACK (toggled_cb),
this);
152 virtual void setLabel (
const std::string &text)
154 std::string str = YGUtils::mapKBAccel(text);
155 gtk_button_set_label (GTK_BUTTON (getWidget()), str.c_str());
156 YCheckBox::setLabel (text);
159 virtual YCheckBoxState value()
161 GtkToggleButton *button = GTK_TOGGLE_BUTTON (getWidget());
163 if (gtk_toggle_button_get_inconsistent (button))
164 return YCheckBox_dont_care;
165 return gtk_toggle_button_get_active (button) ? YCheckBox_on : YCheckBox_off;
168 virtual void setValue (YCheckBoxState value)
171 GtkToggleButton *button = GTK_TOGGLE_BUTTON (getWidget());
173 case YCheckBox_dont_care:
174 gtk_toggle_button_set_inconsistent (button, TRUE);
177 gtk_toggle_button_set_inconsistent (button, FALSE);
178 gtk_toggle_button_set_active (button, TRUE);
181 gtk_toggle_button_set_inconsistent (button, FALSE);
182 gtk_toggle_button_set_active (button, FALSE);
187 static void toggled_cb (GtkBox *box,
YGCheckBox *pThis)
189 GtkToggleButton *button = GTK_TOGGLE_BUTTON (box);
190 if (gtk_toggle_button_get_inconsistent (button))
191 pThis->setValue (YCheckBox_on);
192 pThis->emitEvent (YEvent::ValueChanged);
195 YGWIDGET_IMPL_COMMON (YCheckBox)
196 YGWIDGET_IMPL_USE_BOLD (YCheckBox)
199 YCheckBox *YGWidgetFactory::createCheckBox (YWidget *parent,
const std::string &label,
201 {
return new YGCheckBox (parent, label, isChecked); }