1 /* GTK - The GIMP Toolkit
2 * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Lesser General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library 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 GNU
12 * Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public
15 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
19 * Modified by the GTK+ Team and others 1997-2000. See the AUTHORS
20 * file for a list of people on the GTK+ Team. See the ChangeLog
21 * files for a list of changes. These files are distributed with
22 * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27 #include "gtkradiobutton.h"
29 #include "gtkbuttonprivate.h"
31 #include "gtkmarshalers.h"
32 #include "gtkprivate.h"
34 #include "a11y/gtkradiobuttonaccessible.h"
37 * SECTION:gtkradiobutton
38 * @Short_description: A choice from multiple check buttons
39 * @Title: GtkRadioButton
40 * @See_also: #GtkComboBox
42 * A single radio button performs the same basic function as a #GtkCheckButton,
43 * as its position in the object hierarchy reflects. It is only when multiple
44 * radio buttons are grouped together that they become a different user
45 * interface component in their own right.
47 * Every radio button is a member of some group of radio buttons. When one is
48 * selected, all other radio buttons in the same group are deselected. A
49 * #GtkRadioButton is one way of giving the user a choice from many options.
51 * Radio button widgets are created with gtk_radio_button_new(), passing %NULL
52 * as the argument if this is the first radio button in a group. In subsequent
53 * calls, the group you wish to add this button to should be passed as an
54 * argument. Optionally, gtk_radio_button_new_with_label() can be used if you
55 * want a text label on the radio button.
57 * Alternatively, when adding widgets to an existing group of radio buttons,
58 * use gtk_radio_button_new_from_widget() with a #GtkRadioButton that already
59 * has a group assigned to it. The convenience function
60 * gtk_radio_button_new_with_label_from_widget() is also provided.
62 * To retrieve the group a #GtkRadioButton is assigned to, use
63 * gtk_radio_button_get_group().
65 * To remove a #GtkRadioButton from one group and make it part of a new one,
66 * use gtk_radio_button_set_group().
68 * The group list does not need to be freed, as each #GtkRadioButton will remove
69 * itself and its list item when it is destroyed.
72 * <title>How to create a group of two radio buttons.</title>
74 * void create_radio_buttons (void) {
76 * GtkWidget *window, *radio1, *radio2, *box, *entry;
77 * window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
78 * box = gtk_box_new (GTK_ORIENTATION_VERTICAL, 2);
79 * gtk_box_set_homogeneous (GTK_BOX (box), TRUE);
81 * /* Create a radio button with a GtkEntry widget */
82 * radio1 = gtk_radio_button_new (NULL);
83 * entry = gtk_entry_new (<!-- -->);
84 * gtk_container_add (GTK_CONTAINER (radio1), entry);
87 * /* Create a radio button with a label */
88 * radio2 = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (radio1),
89 * "I'm the second radio button.");
91 * /* Pack them into a box, then show all the widgets */
92 * gtk_box_pack_start (GTK_BOX (box), radio1, TRUE, TRUE, 2);
93 * gtk_box_pack_start (GTK_BOX (box), radio2, TRUE, TRUE, 2);
94 * gtk_container_add (GTK_CONTAINER (window), box);
95 * gtk_widget_show_all (window);
101 * When an unselected button in the group is clicked the clicked button
102 * receives the #GtkToggleButton::toggled signal, as does the previously
104 * Inside the #GtkToggleButton::toggled handler, gtk_toggle_button_get_active()
105 * can be used to determine if the button has been selected or deselected.
109 struct _GtkRadioButtonPrivate
120 static void gtk_radio_button_destroy (GtkWidget *widget);
121 static gboolean gtk_radio_button_focus (GtkWidget *widget,
122 GtkDirectionType direction);
123 static void gtk_radio_button_clicked (GtkButton *button);
124 static void gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
126 static void gtk_radio_button_set_property (GObject *object,
130 static void gtk_radio_button_get_property (GObject *object,
135 G_DEFINE_TYPE (GtkRadioButton, gtk_radio_button, GTK_TYPE_CHECK_BUTTON)
137 static guint group_changed_signal = 0;
140 gtk_radio_button_class_init (GtkRadioButtonClass *class)
142 GObjectClass *gobject_class;
143 GtkButtonClass *button_class;
144 GtkCheckButtonClass *check_button_class;
145 GtkWidgetClass *widget_class;
147 gobject_class = G_OBJECT_CLASS (class);
148 widget_class = (GtkWidgetClass*) class;
149 button_class = (GtkButtonClass*) class;
150 check_button_class = (GtkCheckButtonClass*) class;
152 gobject_class->set_property = gtk_radio_button_set_property;
153 gobject_class->get_property = gtk_radio_button_get_property;
156 * GtkRadioButton:group:
158 * Sets a new group for a radio button.
160 g_object_class_install_property (gobject_class,
162 g_param_spec_object ("group",
164 P_("The radio button whose group this widget belongs to."),
165 GTK_TYPE_RADIO_BUTTON,
166 GTK_PARAM_WRITABLE));
167 widget_class->destroy = gtk_radio_button_destroy;
168 widget_class->focus = gtk_radio_button_focus;
170 button_class->clicked = gtk_radio_button_clicked;
172 check_button_class->draw_indicator = gtk_radio_button_draw_indicator;
174 class->group_changed = NULL;
177 * GtkRadioButton::group-changed:
178 * @button: the object which received the signal
180 * Emitted when the group of radio buttons that a radio button belongs
181 * to changes. This is emitted when a radio button switches from
182 * being alone to being part of a group of 2 or more buttons, or
183 * vice-versa, and when a button is moved from one group of 2 or
184 * more buttons to a different one, but not when the composition
185 * of the group that a button belongs to changes.
189 group_changed_signal = g_signal_new (I_("group-changed"),
190 G_OBJECT_CLASS_TYPE (gobject_class),
192 G_STRUCT_OFFSET (GtkRadioButtonClass, group_changed),
194 _gtk_marshal_VOID__VOID,
197 g_type_class_add_private (class, sizeof (GtkRadioButtonPrivate));
199 gtk_widget_class_set_accessible_type (widget_class, GTK_TYPE_RADIO_BUTTON_ACCESSIBLE);
203 gtk_radio_button_init (GtkRadioButton *radio_button)
205 GtkRadioButtonPrivate *priv;
207 radio_button->priv = G_TYPE_INSTANCE_GET_PRIVATE (radio_button,
208 GTK_TYPE_RADIO_BUTTON,
209 GtkRadioButtonPrivate);
210 priv = radio_button->priv;
212 gtk_widget_set_receives_default (GTK_WIDGET (radio_button), FALSE);
214 _gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), TRUE);
216 GTK_BUTTON (radio_button)->priv->depress_on_activate = FALSE;
218 priv->group = g_slist_prepend (NULL, radio_button);
220 _gtk_button_set_depressed (GTK_BUTTON (radio_button), TRUE);
221 gtk_widget_set_state_flags (GTK_WIDGET (radio_button), GTK_STATE_FLAG_ACTIVE, TRUE);
225 gtk_radio_button_set_property (GObject *object,
230 GtkRadioButton *radio_button;
232 radio_button = GTK_RADIO_BUTTON (object);
237 GtkRadioButton *button;
240 button = g_value_get_object (value);
243 slist = gtk_radio_button_get_group (button);
246 gtk_radio_button_set_group (radio_button, slist);
249 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
255 gtk_radio_button_get_property (GObject *object,
263 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
269 * gtk_radio_button_set_group:
270 * @radio_button: a #GtkRadioButton.
271 * @group: (transfer none) (element-type GtkRadioButton): an existing radio
272 * button group, such as one returned from gtk_radio_button_get_group().
274 * Sets a #GtkRadioButton's group. It should be noted that this does not change
275 * the layout of your interface in any way, so if you are changing the group,
276 * it is likely you will need to re-arrange the user interface to reflect these
280 gtk_radio_button_set_group (GtkRadioButton *radio_button,
283 GtkRadioButtonPrivate *priv;
284 GtkWidget *old_group_singleton = NULL;
285 GtkWidget *new_group_singleton = NULL;
287 g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
288 g_return_if_fail (!g_slist_find (group, radio_button));
290 priv = radio_button->priv;
296 priv->group = g_slist_remove (priv->group, radio_button);
298 if (priv->group && !priv->group->next)
299 old_group_singleton = g_object_ref (priv->group->data);
301 for (slist = priv->group; slist; slist = slist->next)
303 GtkRadioButton *tmp_button;
305 tmp_button = slist->data;
307 tmp_button->priv->group = priv->group;
311 if (group && !group->next)
312 new_group_singleton = g_object_ref (group->data);
314 priv->group = g_slist_prepend (group, radio_button);
320 for (slist = group; slist; slist = slist->next)
322 GtkRadioButton *tmp_button;
324 tmp_button = slist->data;
326 tmp_button->priv->group = priv->group;
330 g_object_ref (radio_button);
332 g_object_notify (G_OBJECT (radio_button), "group");
333 g_signal_emit (radio_button, group_changed_signal, 0);
334 if (old_group_singleton)
336 g_signal_emit (old_group_singleton, group_changed_signal, 0);
337 g_object_unref (old_group_singleton);
339 if (new_group_singleton)
341 g_signal_emit (new_group_singleton, group_changed_signal, 0);
342 g_object_unref (new_group_singleton);
345 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (radio_button), group == NULL);
347 g_object_unref (radio_button);
351 * gtk_radio_button_join_group:
352 * @radio_button: the #GtkRadioButton object
353 * @group_source: (allow-none): a radio button object whos group we are
354 * joining, or %NULL to remove the radio button from its group
356 * Joins a #GtkRadioButton object to the group of another #GtkRadioButton object
358 * Use this in language bindings instead of the gtk_radio_button_get_group()
359 * and gtk_radio_button_set_group() methods
361 * A common way to set up a group of radio buttons is the following:
363 * GtkRadioButton *radio_button;
364 * GtkRadioButton *last_button;
366 * while (/* more buttons to add */)
368 * radio_button = gtk_radio_button_new (...);
370 * gtk_radio_button_join_group (radio_button, last_button);
371 * last_button = radio_button;
378 gtk_radio_button_join_group (GtkRadioButton *radio_button,
379 GtkRadioButton *group_source)
381 g_return_if_fail (GTK_IS_RADIO_BUTTON (radio_button));
382 g_return_if_fail (group_source == NULL || GTK_IS_RADIO_BUTTON (group_source));
387 group = gtk_radio_button_get_group (group_source);
391 /* if we are not already part of a group we need to set up a new one
392 and then get the newly created group */
393 gtk_radio_button_set_group (group_source, NULL);
394 group = gtk_radio_button_get_group (group_source);
397 gtk_radio_button_set_group (radio_button, group);
401 gtk_radio_button_set_group (radio_button, NULL);
406 * gtk_radio_button_new:
407 * @group: (element-type GtkRadioButton) (allow-none): an existing
408 * radio button group, or %NULL if you are creating a new group.
410 * Creates a new #GtkRadioButton. To be of any practical value, a widget should
411 * then be packed into the radio button.
413 * Returns: a new radio button
416 gtk_radio_button_new (GSList *group)
418 GtkRadioButton *radio_button;
420 radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, NULL);
423 gtk_radio_button_set_group (radio_button, group);
425 return GTK_WIDGET (radio_button);
429 * gtk_radio_button_new_with_label:
430 * @group: (element-type GtkRadioButton) (allow-none): an existing
431 * radio button group, or %NULL if you are creating a new group.
432 * @label: the text label to display next to the radio button.
434 * Creates a new #GtkRadioButton with a text label.
436 * Returns: a new radio button.
439 gtk_radio_button_new_with_label (GSList *group,
442 GtkWidget *radio_button;
444 radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON, "label", label, NULL) ;
447 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), group);
454 * gtk_radio_button_new_with_mnemonic:
455 * @group: (element-type GtkRadioButton) (allow-none): the radio button
457 * @label: the text of the button, with an underscore in front of the
460 * Creates a new #GtkRadioButton containing a label, adding it to the same
461 * group as @group. The label will be created using
462 * gtk_label_new_with_mnemonic(), so underscores in @label indicate the
463 * mnemonic for the button.
465 * Returns: a new #GtkRadioButton
468 gtk_radio_button_new_with_mnemonic (GSList *group,
471 GtkWidget *radio_button;
473 radio_button = g_object_new (GTK_TYPE_RADIO_BUTTON,
475 "use-underline", TRUE,
479 gtk_radio_button_set_group (GTK_RADIO_BUTTON (radio_button), group);
485 * gtk_radio_button_new_from_widget: (constructor)
486 * @radio_group_member: (allow-none): an existing #GtkRadioButton.
488 * Creates a new #GtkRadioButton, adding it to the same group as
489 * @radio_group_member. As with gtk_radio_button_new(), a widget
490 * should be packed into the radio button.
492 * Returns: (transfer none): a new radio button.
495 gtk_radio_button_new_from_widget (GtkRadioButton *radio_group_member)
498 if (radio_group_member)
499 l = gtk_radio_button_get_group (radio_group_member);
500 return gtk_radio_button_new (l);
504 * gtk_radio_button_new_with_label_from_widget: (constructor)
505 * @radio_group_member: (allow-none): widget to get radio group from or %NULL
506 * @label: a text string to display next to the radio button.
508 * Creates a new #GtkRadioButton with a text label, adding it to
509 * the same group as @radio_group_member.
511 * Returns: (transfer none): a new radio button.
514 gtk_radio_button_new_with_label_from_widget (GtkRadioButton *radio_group_member,
518 if (radio_group_member)
519 l = gtk_radio_button_get_group (radio_group_member);
520 return gtk_radio_button_new_with_label (l, label);
524 * gtk_radio_button_new_with_mnemonic_from_widget: (constructor)
525 * @radio_group_member: (allow-none): widget to get radio group from or %NULL
526 * @label: the text of the button, with an underscore in front of the
529 * Creates a new #GtkRadioButton containing a label. The label
530 * will be created using gtk_label_new_with_mnemonic(), so underscores
531 * in @label indicate the mnemonic for the button.
533 * Returns: (transfer none): a new #GtkRadioButton
536 gtk_radio_button_new_with_mnemonic_from_widget (GtkRadioButton *radio_group_member,
540 if (radio_group_member)
541 l = gtk_radio_button_get_group (radio_group_member);
542 return gtk_radio_button_new_with_mnemonic (l, label);
547 * gtk_radio_button_get_group:
548 * @radio_button: a #GtkRadioButton.
550 * Retrieves the group assigned to a radio button.
552 * Return value: (element-type GtkRadioButton) (transfer none): a linked list
553 * containing all the radio buttons in the same group
554 * as @radio_button. The returned list is owned by the radio button
555 * and must not be modified or freed.
558 gtk_radio_button_get_group (GtkRadioButton *radio_button)
560 g_return_val_if_fail (GTK_IS_RADIO_BUTTON (radio_button), NULL);
562 return radio_button->priv->group;
567 gtk_radio_button_destroy (GtkWidget *widget)
569 GtkWidget *old_group_singleton = NULL;
570 GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
571 GtkRadioButtonPrivate *priv = radio_button->priv;
572 GtkRadioButton *tmp_button;
574 gboolean was_in_group;
576 was_in_group = priv->group && priv->group->next;
578 priv->group = g_slist_remove (priv->group, radio_button);
579 if (priv->group && !priv->group->next)
580 old_group_singleton = priv->group->data;
582 tmp_list = priv->group;
586 tmp_button = tmp_list->data;
587 tmp_list = tmp_list->next;
589 tmp_button->priv->group = priv->group;
592 /* this button is no longer in the group */
595 if (old_group_singleton)
596 g_signal_emit (old_group_singleton, group_changed_signal, 0);
598 g_signal_emit (radio_button, group_changed_signal, 0);
600 GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->destroy (widget);
604 get_coordinates (GtkWidget *widget,
605 GtkWidget *reference,
609 GtkAllocation allocation;
611 gtk_widget_get_allocation (widget, &allocation);
612 *x = allocation.x + allocation.width / 2;
613 *y = allocation.y + allocation.height / 2;
615 gtk_widget_translate_coordinates (widget, reference, *x, *y, x, y);
619 left_right_compare (gconstpointer a,
625 get_coordinates ((GtkWidget *)a, data, &x1, &y1);
626 get_coordinates ((GtkWidget *)b, data, &x2, &y2);
629 return (x1 < x2) ? -1 : ((x1 == x2) ? 0 : 1);
631 return (y1 < y2) ? -1 : 1;
635 up_down_compare (gconstpointer a,
641 get_coordinates ((GtkWidget *)a, data, &x1, &y1);
642 get_coordinates ((GtkWidget *)b, data, &x2, &y2);
645 return (y1 < y2) ? -1 : ((y1 == y2) ? 0 : 1);
647 return (x1 < x2) ? -1 : 1;
651 gtk_radio_button_focus (GtkWidget *widget,
652 GtkDirectionType direction)
654 GtkRadioButton *radio_button = GTK_RADIO_BUTTON (widget);
655 GtkRadioButtonPrivate *priv = radio_button->priv;
658 /* Radio buttons with draw_indicator unset focus "normally", since
659 * they look like buttons to the user.
661 if (!gtk_toggle_button_get_mode (GTK_TOGGLE_BUTTON (widget)))
662 return GTK_WIDGET_CLASS (gtk_radio_button_parent_class)->focus (widget, direction);
664 if (gtk_widget_is_focus (widget))
666 GtkSettings *settings = gtk_widget_get_settings (widget);
667 GSList *focus_list, *tmp_list;
668 GtkWidget *toplevel = gtk_widget_get_toplevel (widget);
669 GtkWidget *new_focus = NULL;
670 gboolean cursor_only;
671 gboolean wrap_around;
677 focus_list = g_slist_copy (priv->group);
678 focus_list = g_slist_sort_with_data (focus_list, left_right_compare, toplevel);
682 focus_list = g_slist_copy (priv->group);
683 focus_list = g_slist_sort_with_data (focus_list, up_down_compare, toplevel);
685 case GTK_DIR_TAB_FORWARD:
686 case GTK_DIR_TAB_BACKWARD:
692 if (direction == GTK_DIR_LEFT || direction == GTK_DIR_UP)
693 focus_list = g_slist_reverse (focus_list);
695 tmp_list = g_slist_find (focus_list, widget);
699 tmp_list = tmp_list->next;
703 GtkWidget *child = tmp_list->data;
705 if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
711 tmp_list = tmp_list->next;
715 g_object_get (settings,
716 "gtk-keynav-cursor-only", &cursor_only,
717 "gtk-keynav-wrap-around", &wrap_around,
724 g_slist_free (focus_list);
730 g_slist_free (focus_list);
731 gtk_widget_error_bell (widget);
735 tmp_list = focus_list;
739 GtkWidget *child = tmp_list->data;
741 if (gtk_widget_get_mapped (child) && gtk_widget_is_sensitive (child))
747 tmp_list = tmp_list->next;
751 g_slist_free (focus_list);
755 gtk_widget_grab_focus (new_focus);
758 gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (new_focus), TRUE);
765 GtkRadioButton *selected_button = NULL;
767 /* We accept the focus if, we don't have the focus and
768 * - we are the currently active button in the group
769 * - there is no currently active radio button.
772 tmp_slist = priv->group;
775 if (gtk_toggle_button_get_active (GTK_TOGGLE_BUTTON (tmp_slist->data)))
776 selected_button = tmp_slist->data;
777 tmp_slist = tmp_slist->next;
780 if (selected_button && selected_button != radio_button)
783 gtk_widget_grab_focus (widget);
789 gtk_radio_button_clicked (GtkButton *button)
791 GtkRadioButton *radio_button = GTK_RADIO_BUTTON (button);
792 GtkRadioButtonPrivate *priv = radio_button->priv;
793 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (button);
794 GtkToggleButton *tmp_button;
795 GtkStateFlags new_state = 0;
802 g_object_ref (GTK_WIDGET (button));
804 new_state = gtk_widget_get_state_flags (GTK_WIDGET (button)) &
805 ~(GTK_STATE_FLAG_PRELIGHT |
806 GTK_STATE_FLAG_ACTIVE);
808 if (gtk_toggle_button_get_active (toggle_button))
811 tmp_list = priv->group;
815 tmp_button = tmp_list->data;
816 tmp_list = tmp_list->next;
818 if (tmp_button != toggle_button &&
819 gtk_toggle_button_get_active (tmp_button))
827 if (button->priv->in_button)
828 new_state |= GTK_STATE_FLAG_PRELIGHT;
830 new_state |= GTK_STATE_FLAG_ACTIVE;
835 _gtk_toggle_button_set_active (toggle_button,
836 !gtk_toggle_button_get_active (toggle_button));
838 if (button->priv->in_button)
839 new_state |= GTK_STATE_FLAG_PRELIGHT;
845 _gtk_toggle_button_set_active (toggle_button,
846 !gtk_toggle_button_get_active (toggle_button));
848 tmp_list = priv->group;
851 tmp_button = tmp_list->data;
852 tmp_list = tmp_list->next;
854 if (gtk_toggle_button_get_active (tmp_button) && (tmp_button != toggle_button))
856 gtk_button_clicked (GTK_BUTTON (tmp_button));
861 if (button->priv->in_button)
862 new_state |= GTK_STATE_FLAG_PRELIGHT;
864 new_state |= GTK_STATE_FLAG_ACTIVE;
867 if (gtk_toggle_button_get_inconsistent (toggle_button))
869 else if (button->priv->in_button && button->priv->button_down)
870 depressed = !gtk_toggle_button_get_active (toggle_button);
872 depressed = gtk_toggle_button_get_active (toggle_button);
874 if (gtk_widget_get_state_flags (GTK_WIDGET (button)) != new_state)
875 gtk_widget_set_state_flags (GTK_WIDGET (button), new_state, TRUE);
879 gtk_toggle_button_toggled (toggle_button);
881 g_object_notify (G_OBJECT (toggle_button), "active");
884 _gtk_button_set_depressed (button, depressed);
886 gtk_widget_queue_draw (GTK_WIDGET (button));
888 g_object_unref (button);
892 gtk_radio_button_draw_indicator (GtkCheckButton *check_button,
895 GtkAllocation allocation;
899 GtkToggleButton *toggle_button;
900 GtkStyleContext *context;
901 GtkStateFlags state = 0;
903 gint indicator_size, indicator_spacing;
907 gboolean interior_focus;
909 widget = GTK_WIDGET (check_button);
910 button = GTK_BUTTON (check_button);
911 toggle_button = GTK_TOGGLE_BUTTON (check_button);
912 context = gtk_widget_get_style_context (widget);
913 state = gtk_widget_get_state_flags (widget);
915 border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
917 gtk_widget_style_get (widget,
918 "interior-focus", &interior_focus,
919 "focus-line-width", &focus_width,
920 "focus-padding", &focus_pad,
923 _gtk_check_button_get_props (check_button, &indicator_size, &indicator_spacing);
925 gtk_widget_get_allocation (widget, &allocation);
927 x = indicator_spacing + border_width;
928 y = (allocation.height - indicator_size) / 2;
930 child = gtk_bin_get_child (GTK_BIN (check_button));
931 if (!interior_focus || !(child && gtk_widget_get_visible (child)))
932 x += focus_width + focus_pad;
934 state &= ~(GTK_STATE_FLAG_INCONSISTENT |
935 GTK_STATE_FLAG_ACTIVE |
936 GTK_STATE_FLAG_SELECTED |
937 GTK_STATE_FLAG_PRELIGHT);
939 if (gtk_toggle_button_get_inconsistent (toggle_button))
940 state |= GTK_STATE_FLAG_INCONSISTENT;
941 else if (gtk_toggle_button_get_active (toggle_button))
942 state |= GTK_STATE_FLAG_ACTIVE;
944 if (button->priv->activate_timeout ||
945 (button->priv->button_down && button->priv->in_button))
946 state |= GTK_STATE_FLAG_SELECTED;
948 if (button->priv->in_button && !(state & GTK_STATE_FLAG_INSENSITIVE))
949 state |= GTK_STATE_FLAG_PRELIGHT;
951 if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
952 x = allocation.width - (indicator_size + x);
954 gtk_style_context_save (context);
955 gtk_style_context_set_state (context, state);
957 if (state & GTK_STATE_FLAG_PRELIGHT)
958 gtk_render_background (context, cr,
959 border_width, border_width,
960 allocation.width - (2 * border_width),
961 allocation.height - (2 * border_width));
963 gtk_style_context_add_class (context, GTK_STYLE_CLASS_RADIO);
965 gtk_render_option (context, cr,
966 x, y, indicator_size, indicator_size);
968 gtk_style_context_restore (context);