1 /* GTK - The GIMP Toolkit
3 * Copyright (C) 2010 Intel Corporation
4 * Copyright (C) 2010 RedHat, Inc.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 * Emmanuele Bassi <ebassi@linux.intel.com>
23 * Matthias Clasen <mclasen@redhat.com>
25 * Based on similar code from Mx.
30 * @Short_Description: A "light switch" style toggle
32 * @See_Also: #GtkToggleButton
34 * #GtkSwitch is a widget that has two states: on or off. The user can control
35 * which state should be active by clicking the empty area, or by dragging the
41 #include "gtkswitch.h"
43 #include "gtkaccessibleprivate.h"
44 #include "gtkactivatable.h"
47 #include "gtkprivate.h"
48 #include "gtktoggleaction.h"
49 #include "gtkwidget.h"
51 #define DEFAULT_SLIDER_WIDTH (36)
52 #define DEFAULT_SLIDER_HEIGHT (22)
54 struct _GtkSwitchPrivate
56 GdkWindow *event_window;
65 guint is_dragging : 1;
68 guint use_action_appearance : 1;
76 PROP_USE_ACTION_APPEARANCE,
80 static GParamSpec *switch_props[LAST_PROP] = { NULL, };
82 static GType gtk_switch_accessible_factory_get_type (void);
84 static void gtk_switch_activatable_interface_init (GtkActivatableIface *iface);
86 G_DEFINE_TYPE_WITH_CODE (GtkSwitch, gtk_switch, GTK_TYPE_WIDGET,
87 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
88 gtk_switch_activatable_interface_init));
91 gtk_switch_button_press (GtkWidget *widget,
92 GdkEventButton *event)
94 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
95 GtkAllocation allocation;
97 gtk_widget_get_allocation (widget, &allocation);
101 /* if the event occurred in the "off" area, then this
104 if (event->x <= allocation.width / 2)
106 priv->in_press = TRUE;
110 priv->offset = event->x - allocation.width / 2;
114 /* if the event occurred in the "on" area, then this
117 if (event->x >= allocation.width / 2)
119 priv->in_press = TRUE;
123 priv->offset = event->x;
126 priv->drag_start = event->x;
128 g_object_get (gtk_widget_get_settings (widget),
129 "gtk-dnd-drag-threshold", &priv->drag_threshold,
136 gtk_switch_motion (GtkWidget *widget,
137 GdkEventMotion *event)
139 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
141 /* if this is a direct toggle we don't handle motion */
145 if (ABS (event->x - priv->drag_start) < priv->drag_threshold)
148 if (event->state & GDK_BUTTON1_MASK)
150 gint position = event->x - priv->offset;
151 GtkAllocation allocation;
152 GtkStyleContext *context;
156 context = gtk_widget_get_style_context (widget);
157 state = gtk_widget_get_state_flags (widget);
158 gtk_style_context_get_padding (context, state, &padding);
159 gtk_widget_get_allocation (widget, &allocation);
161 /* constrain the handle within the trough width */
162 if (position > (allocation.width / 2 - padding.right))
163 priv->handle_x = allocation.width / 2 - padding.right;
164 else if (position < padding.left)
165 priv->handle_x = padding.left;
167 priv->handle_x = position;
169 priv->is_dragging = TRUE;
171 /* we need to redraw the handle */
172 gtk_widget_queue_draw (widget);
181 gtk_switch_button_release (GtkWidget *widget,
182 GdkEventButton *event)
184 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
185 GtkAllocation allocation;
187 gtk_widget_get_allocation (widget, &allocation);
189 /* dragged toggles have a "soft" grab, so we don't care whether we
190 * are in the switch or not when the button is released; we do care
191 * for direct toggles, instead
193 if (!priv->is_dragging && !priv->in_switch)
199 priv->in_press = FALSE;
200 gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
205 /* toggle the switch if the handle was clicked but a drag had not been
207 if (!priv->is_dragging && !priv->in_press)
209 gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
215 if (priv->is_dragging)
217 priv->is_dragging = FALSE;
219 /* if half the handle passed the middle of the switch, then we
220 * consider it to be on
222 if ((priv->handle_x + (allocation.width / 4)) >= (allocation.width / 2))
224 gtk_switch_set_active (GTK_SWITCH (widget), TRUE);
225 priv->handle_x = allocation.width / 2;
229 gtk_switch_set_active (GTK_SWITCH (widget), FALSE);
233 gtk_widget_queue_draw (widget);
242 gtk_switch_enter (GtkWidget *widget,
243 GdkEventCrossing *event)
245 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
247 if (event->window == priv->event_window)
248 priv->in_switch = TRUE;
254 gtk_switch_leave (GtkWidget *widget,
255 GdkEventCrossing *event)
257 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
259 if (event->window == priv->event_window)
260 priv->in_switch = FALSE;
266 gtk_switch_key_release (GtkWidget *widget,
269 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
271 if (event->keyval == GDK_KEY_Return ||
272 event->keyval == GDK_KEY_KP_Enter ||
273 event->keyval == GDK_KEY_ISO_Enter ||
274 event->keyval == GDK_KEY_space ||
275 event->keyval == GDK_KEY_KP_Space)
277 gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
284 gtk_switch_get_preferred_width (GtkWidget *widget,
288 GtkStyleContext *context;
291 gint width, slider_width, focus_width, focus_pad;
293 PangoRectangle logical_rect;
295 context = gtk_widget_get_style_context (widget);
296 state = gtk_widget_get_state_flags (widget);
297 gtk_style_context_get_padding (context, state, &padding);
299 width = padding.left + padding.right;
301 gtk_widget_style_get (widget,
302 "slider-width", &slider_width,
303 "focus-line-width", &focus_width,
304 "focus-padding", &focus_pad,
307 width += 2 * (focus_width + focus_pad);
309 /* Translators: if the "on" state label requires more than three
310 * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
313 layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
314 pango_layout_get_extents (layout, NULL, &logical_rect);
315 pango_extents_to_pixels (&logical_rect, NULL);
316 width += MAX (logical_rect.width, slider_width);
318 /* Translators: if the "off" state label requires more than three
319 * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
321 pango_layout_set_text (layout, C_("switch", "OFF"), -1);
322 pango_layout_get_extents (layout, NULL, &logical_rect);
323 pango_extents_to_pixels (&logical_rect, NULL);
324 width += MAX (logical_rect.width, slider_width);
326 g_object_unref (layout);
336 gtk_switch_get_preferred_height (GtkWidget *widget,
340 GtkStyleContext *context;
343 gint height, focus_width, focus_pad;
345 PangoRectangle logical_rect;
348 context = gtk_widget_get_style_context (widget);
349 state = gtk_widget_get_state_flags (widget);
350 gtk_style_context_get_padding (context, state, &padding);
352 height = padding.top + padding.bottom;
354 gtk_widget_style_get (widget,
355 "focus-line-width", &focus_width,
356 "focus-padding", &focus_pad,
359 height += 2 * (focus_width + focus_pad);
361 str = g_strdup_printf ("%s%s",
363 C_("switch", "OFF"));
365 layout = gtk_widget_create_pango_layout (widget, str);
366 pango_layout_get_extents (layout, NULL, &logical_rect);
367 pango_extents_to_pixels (&logical_rect, NULL);
368 height += MAX (DEFAULT_SLIDER_HEIGHT, logical_rect.height);
370 g_object_unref (layout);
381 gtk_switch_size_allocate (GtkWidget *widget,
382 GtkAllocation *allocation)
384 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
386 gtk_widget_set_allocation (widget, allocation);
388 if (gtk_widget_get_realized (widget))
389 gdk_window_move_resize (priv->event_window,
397 gtk_switch_realize (GtkWidget *widget)
399 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
400 GdkWindow *parent_window;
401 GdkWindowAttr attributes;
402 gint attributes_mask;
403 GtkAllocation allocation;
405 gtk_widget_set_realized (widget, TRUE);
406 parent_window = gtk_widget_get_parent_window (widget);
407 gtk_widget_set_window (widget, parent_window);
408 g_object_ref (parent_window);
410 gtk_widget_get_allocation (widget, &allocation);
412 attributes.window_type = GDK_WINDOW_CHILD;
413 attributes.wclass = GDK_INPUT_ONLY;
414 attributes.x = allocation.x;
415 attributes.y = allocation.y;
416 attributes.width = allocation.width;
417 attributes.height = allocation.height;
418 attributes.event_mask = gtk_widget_get_events (widget);
419 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
420 GDK_BUTTON_RELEASE_MASK |
421 GDK_BUTTON1_MOTION_MASK |
422 GDK_POINTER_MOTION_HINT_MASK |
423 GDK_POINTER_MOTION_MASK |
424 GDK_ENTER_NOTIFY_MASK |
425 GDK_LEAVE_NOTIFY_MASK);
426 attributes_mask = GDK_WA_X | GDK_WA_Y;
428 priv->event_window = gdk_window_new (parent_window,
431 gdk_window_set_user_data (priv->event_window, widget);
435 gtk_switch_unrealize (GtkWidget *widget)
437 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
439 if (priv->event_window != NULL)
441 gdk_window_set_user_data (priv->event_window, NULL);
442 gdk_window_destroy (priv->event_window);
443 priv->event_window = NULL;
446 GTK_WIDGET_CLASS (gtk_switch_parent_class)->unrealize (widget);
450 gtk_switch_map (GtkWidget *widget)
452 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
454 GTK_WIDGET_CLASS (gtk_switch_parent_class)->map (widget);
456 if (priv->event_window)
457 gdk_window_show (priv->event_window);
461 gtk_switch_unmap (GtkWidget *widget)
463 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
465 if (priv->event_window)
466 gdk_window_hide (priv->event_window);
468 GTK_WIDGET_CLASS (gtk_switch_parent_class)->unmap (widget);
472 gtk_switch_paint_handle (GtkWidget *widget,
476 GtkStyleContext *context = gtk_widget_get_style_context (widget);
479 state = gtk_widget_get_state_flags (widget);
481 gtk_style_context_save (context);
482 gtk_style_context_set_state (context, state);
483 gtk_style_context_add_class (context, GTK_STYLE_CLASS_SLIDER);
485 gtk_render_slider (context, cr,
487 box->width, box->height,
488 GTK_ORIENTATION_HORIZONTAL);
490 gtk_style_context_restore (context);
494 gtk_switch_draw (GtkWidget *widget,
497 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
498 GtkStyleContext *context;
502 gint label_x, label_y;
505 gint focus_width, focus_pad;
506 gint x, y, width, height;
508 gtk_widget_style_get (widget,
509 "focus-line-width", &focus_width,
510 "focus-padding", &focus_pad,
513 context = gtk_widget_get_style_context (widget);
514 state = gtk_widget_get_state_flags (widget);
517 state |= GTK_STATE_FLAG_ACTIVE;
519 gtk_style_context_get_padding (context, state, &padding);
523 width = gtk_widget_get_allocated_width (widget);
524 height = gtk_widget_get_allocated_height (widget);
526 if (gtk_widget_has_focus (widget))
527 gtk_render_focus (context, cr, x, y, width, height);
529 gtk_style_context_save (context);
530 gtk_style_context_set_state (context, state);
532 x += focus_width + focus_pad;
533 y += focus_width + focus_pad;
534 width -= 2 * (focus_width + focus_pad);
535 height -= 2 * (focus_width + focus_pad);
537 gtk_style_context_add_class (context, GTK_STYLE_CLASS_TROUGH);
539 gtk_render_background (context, cr, x, y, width, height);
540 gtk_render_frame (context, cr, x, y, width, height);
542 /* XXX the +1/-1 it's pixel wriggling after checking with the default
545 handle.y = y + padding.top + 1;
546 handle.width = (width - padding.left - padding.right) / 2;
547 handle.height = (height - padding.top - padding.bottom) - 1;
549 /* Translators: if the "on" state label requires more than three
550 * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
553 layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
554 pango_layout_get_extents (layout, NULL, &rect);
555 pango_extents_to_pixels (&rect, NULL);
557 label_x = x + padding.left
558 + ((width / 2) - rect.width - padding.left - padding.right) / 2;
559 label_y = y + padding.top
560 + (height - rect.height - padding.top - padding.bottom) / 2;
562 gtk_render_layout (context, cr, label_x, label_y, layout);
564 g_object_unref (layout);
566 /* Translators: if the "off" state label requires more than three
567 * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
569 layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));
570 pango_layout_get_extents (layout, NULL, &rect);
571 pango_extents_to_pixels (&rect, NULL);
573 label_x = x + padding.left
575 + ((width / 2) - rect.width - padding.left - padding.right) / 2;
576 label_y = y + padding.top
577 + (height - rect.height - padding.top - padding.bottom) / 2;
579 gtk_render_layout (context, cr, label_x, label_y, layout);
581 g_object_unref (layout);
583 if (priv->is_dragging)
584 handle.x = x + priv->handle_x;
585 else if (priv->is_active)
586 handle.x = x + width - handle.width - padding.right;
588 handle.x = x + padding.left;
590 gtk_style_context_restore (context);
592 gtk_switch_paint_handle (widget, cr, &handle);
598 gtk_switch_get_accessible (GtkWidget *widget)
600 static gboolean first_time = TRUE;
602 if (G_UNLIKELY (first_time))
604 _gtk_accessible_set_factory_type (GTK_TYPE_SWITCH,
605 gtk_switch_accessible_factory_get_type ());
609 return GTK_WIDGET_CLASS (gtk_switch_parent_class)->get_accessible (widget);
613 gtk_switch_set_related_action (GtkSwitch *sw,
616 GtkSwitchPrivate *priv = sw->priv;
618 if (priv->action == action)
621 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (sw), action);
623 priv->action = action;
627 gtk_switch_set_use_action_appearance (GtkSwitch *sw,
628 gboolean use_appearance)
630 GtkSwitchPrivate *priv = sw->priv;
632 if (priv->use_action_appearance != use_appearance)
634 priv->use_action_appearance = use_appearance;
636 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (sw), priv->action);
641 gtk_switch_set_property (GObject *gobject,
646 GtkSwitch *sw = GTK_SWITCH (gobject);
651 gtk_switch_set_active (sw, g_value_get_boolean (value));
654 case PROP_RELATED_ACTION:
655 gtk_switch_set_related_action (sw, g_value_get_object (value));
658 case PROP_USE_ACTION_APPEARANCE:
659 gtk_switch_set_use_action_appearance (sw, g_value_get_boolean (value));
663 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
668 gtk_switch_get_property (GObject *gobject,
673 GtkSwitchPrivate *priv = GTK_SWITCH (gobject)->priv;
678 g_value_set_boolean (value, priv->is_active);
681 case PROP_RELATED_ACTION:
682 g_value_set_object (value, priv->action);
685 case PROP_USE_ACTION_APPEARANCE:
686 g_value_set_boolean (value, priv->use_action_appearance);
690 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
695 gtk_switch_dispose (GObject *object)
697 GtkSwitchPrivate *priv = GTK_SWITCH (object)->priv;
701 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (object), NULL);
705 G_OBJECT_CLASS (gtk_switch_parent_class)->dispose (object);
709 gtk_switch_class_init (GtkSwitchClass *klass)
711 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
712 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
713 gpointer activatable_iface;
715 g_type_class_add_private (klass, sizeof (GtkSwitchPrivate));
717 activatable_iface = g_type_default_interface_peek (GTK_TYPE_ACTIVATABLE);
718 switch_props[PROP_RELATED_ACTION] =
719 g_param_spec_override ("related-action",
720 g_object_interface_find_property (activatable_iface,
723 switch_props[PROP_USE_ACTION_APPEARANCE] =
724 g_param_spec_override ("use-action-appearance",
725 g_object_interface_find_property (activatable_iface,
726 "use-action-appearance"));
731 * Whether the #GtkSwitch widget is in its on or off state.
733 switch_props[PROP_ACTIVE] =
734 g_param_spec_boolean ("active",
736 P_("Whether the switch is on or off"),
738 GTK_PARAM_READWRITE);
740 gobject_class->set_property = gtk_switch_set_property;
741 gobject_class->get_property = gtk_switch_get_property;
742 gobject_class->dispose = gtk_switch_dispose;
744 g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
746 widget_class->get_preferred_width = gtk_switch_get_preferred_width;
747 widget_class->get_preferred_height = gtk_switch_get_preferred_height;
748 widget_class->size_allocate = gtk_switch_size_allocate;
749 widget_class->realize = gtk_switch_realize;
750 widget_class->unrealize = gtk_switch_unrealize;
751 widget_class->map = gtk_switch_map;
752 widget_class->unmap = gtk_switch_unmap;
753 widget_class->draw = gtk_switch_draw;
754 widget_class->button_press_event = gtk_switch_button_press;
755 widget_class->button_release_event = gtk_switch_button_release;
756 widget_class->motion_notify_event = gtk_switch_motion;
757 widget_class->enter_notify_event = gtk_switch_enter;
758 widget_class->leave_notify_event = gtk_switch_leave;
759 widget_class->key_release_event = gtk_switch_key_release;
760 widget_class->get_accessible = gtk_switch_get_accessible;
763 * GtkSwitch:slider-width:
765 * The minimum width of the #GtkSwitch handle, in pixels.
767 gtk_widget_class_install_style_property (widget_class,
768 g_param_spec_int ("slider-width",
770 P_("The minimum width of the handle"),
771 DEFAULT_SLIDER_WIDTH, G_MAXINT,
772 DEFAULT_SLIDER_WIDTH,
773 GTK_PARAM_READABLE));
777 gtk_switch_init (GtkSwitch *self)
779 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_SWITCH, GtkSwitchPrivate);
780 self->priv->use_action_appearance = TRUE;
781 gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
782 gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
788 * Creates a new #GtkSwitch widget.
790 * Return value: the newly created #GtkSwitch instance
795 gtk_switch_new (void)
797 return g_object_new (GTK_TYPE_SWITCH, NULL);
801 * gtk_switch_set_active:
803 * @is_active: %TRUE if @sw should be active, and %FALSE otherwise
805 * Changes the state of @sw to the desired one.
810 gtk_switch_set_active (GtkSwitch *sw,
813 GtkSwitchPrivate *priv;
815 g_return_if_fail (GTK_IS_SWITCH (sw));
817 is_active = !!is_active;
821 if (priv->is_active != is_active)
823 AtkObject *accessible;
825 GtkStyleContext *context;
827 widget = GTK_WIDGET (sw);
828 priv->is_active = is_active;
830 g_object_notify_by_pspec (G_OBJECT (sw), switch_props[PROP_ACTIVE]);
833 gtk_action_activate (priv->action);
835 accessible = gtk_widget_get_accessible (GTK_WIDGET (sw));
836 atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, priv->is_active);
838 if (gtk_widget_get_realized (widget))
840 context = gtk_widget_get_style_context (widget);
841 gtk_style_context_notify_state_change (context,
842 gtk_widget_get_window (widget),
843 NULL, GTK_STATE_ACTIVE, is_active);
846 gtk_widget_queue_draw (GTK_WIDGET (sw));
851 * gtk_switch_get_active:
854 * Gets whether the #GtkSwitch is in its "on" or "off" state.
856 * Return value: %TRUE if the #GtkSwitch is active, and %FALSE otherwise
861 gtk_switch_get_active (GtkSwitch *sw)
863 g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE);
865 return sw->priv->is_active;
869 gtk_switch_update (GtkActivatable *activatable,
871 const gchar *property_name)
873 if (strcmp (property_name, "visible") == 0)
875 if (gtk_action_is_visible (action))
876 gtk_widget_show (GTK_WIDGET (activatable));
878 gtk_widget_hide (GTK_WIDGET (activatable));
880 else if (strcmp (property_name, "sensitive") == 0)
882 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
884 else if (strcmp (property_name, "active") == 0)
886 gtk_action_block_activate (action);
887 gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
888 gtk_action_unblock_activate (action);
893 gtk_switch_sync_action_properties (GtkActivatable *activatable,
899 if (gtk_action_is_visible (action))
900 gtk_widget_show (GTK_WIDGET (activatable));
902 gtk_widget_hide (GTK_WIDGET (activatable));
904 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
906 gtk_action_block_activate (action);
907 gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
908 gtk_action_unblock_activate (action);
912 gtk_switch_activatable_interface_init (GtkActivatableIface *iface)
914 iface->update = gtk_switch_update;
915 iface->sync_action_properties = gtk_switch_sync_action_properties;
918 /* accessibility: object */
921 typedef struct _GtkSwitchAccessible GtkSwitchAccessible;
922 typedef struct _GtkSwitchAccessibleClass GtkSwitchAccessibleClass;
924 ATK_DEFINE_TYPE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_WIDGET);
927 gtk_switch_accessible_ref_state_set (AtkObject *accessible)
929 AtkStateSet *state_set;
932 state_set = ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->ref_state_set (accessible);
934 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
938 if (gtk_switch_get_active (GTK_SWITCH (widget)))
939 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
945 _gtk_switch_accessible_initialize (AtkObject *accessible,
948 ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->initialize (accessible, widget);
950 atk_object_set_role (accessible, ATK_ROLE_TOGGLE_BUTTON);
951 atk_object_set_name (accessible, C_("light switch widget", "Switch"));
952 atk_object_set_description (accessible, _("Switches between on and off states"));
956 _gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
958 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
960 atk_class->initialize = _gtk_switch_accessible_initialize;
961 atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
965 _gtk_switch_accessible_init (GtkSwitchAccessible *self)
969 /* accessibility: factory */
971 typedef AtkObjectFactoryClass GtkSwitchAccessibleFactoryClass;
972 typedef AtkObjectFactory GtkSwitchAccessibleFactory;
974 G_DEFINE_TYPE (GtkSwitchAccessibleFactory,
975 gtk_switch_accessible_factory,
976 ATK_TYPE_OBJECT_FACTORY);
979 gtk_switch_accessible_factory_get_accessible_type (void)
981 return _gtk_switch_accessible_get_type ();
985 gtk_switch_accessible_factory_create_accessible (GObject *obj)
987 AtkObject *accessible;
989 accessible = g_object_new (_gtk_switch_accessible_get_type (), NULL);
990 atk_object_initialize (accessible, obj);
996 gtk_switch_accessible_factory_class_init (AtkObjectFactoryClass *klass)
998 klass->create_accessible = gtk_switch_accessible_factory_create_accessible;
999 klass->get_accessible_type = gtk_switch_accessible_factory_get_accessible_type;
1003 gtk_switch_accessible_factory_init (AtkObjectFactory *factory)