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 <gdk/gdkkeysyms.h>
45 #include "gtkaccessible.h"
46 #include "gtkactivatable.h"
49 #include "gtkprivate.h"
50 #include "gtktoggleaction.h"
51 #include "gtkwidget.h"
53 #define DEFAULT_SLIDER_WIDTH (36)
54 #define DEFAULT_SLIDER_HEIGHT (22)
56 struct _GtkSwitchPrivate
58 GdkWindow *event_window;
67 guint is_dragging : 1;
70 guint use_action_appearance : 1;
78 PROP_USE_ACTION_APPEARANCE,
82 static GParamSpec *switch_props[LAST_PROP] = { NULL, };
84 static GType gtk_switch_accessible_factory_get_type (void);
86 static void gtk_switch_activatable_interface_init (GtkActivatableIface *iface);
88 G_DEFINE_TYPE_WITH_CODE (GtkSwitch, gtk_switch, GTK_TYPE_WIDGET,
89 G_IMPLEMENT_INTERFACE (GTK_TYPE_ACTIVATABLE,
90 gtk_switch_activatable_interface_init));
93 gtk_switch_button_press (GtkWidget *widget,
94 GdkEventButton *event)
96 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
97 GtkAllocation allocation;
99 gtk_widget_get_allocation (widget, &allocation);
103 /* if the event occurred in the "off" area, then this
106 if (event->x <= allocation.width / 2)
108 priv->in_press = TRUE;
112 priv->offset = event->x - allocation.width / 2;
116 /* if the event occurred in the "on" area, then this
119 if (event->x >= allocation.width / 2)
121 priv->in_press = TRUE;
125 priv->offset = event->x;
128 priv->drag_start = event->x;
130 g_object_get (gtk_widget_get_settings (widget),
131 "gtk-dnd-drag-threshold", &priv->drag_threshold,
138 gtk_switch_motion (GtkWidget *widget,
139 GdkEventMotion *event)
141 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
143 /* if this is a direct toggle we don't handle motion */
147 if (ABS (event->x - priv->drag_start) < priv->drag_threshold)
150 if (event->state & GDK_BUTTON1_MASK)
152 gint position = event->x - priv->offset;
153 GtkAllocation allocation;
156 style = gtk_widget_get_style (widget);
157 gtk_widget_get_allocation (widget, &allocation);
159 /* constrain the handle within the trough width */
160 if (position > (allocation.width / 2 - style->xthickness))
161 priv->handle_x = allocation.width / 2 - style->xthickness;
162 else if (position < style->xthickness)
163 priv->handle_x = style->xthickness;
165 priv->handle_x = position;
167 priv->is_dragging = TRUE;
169 /* we need to redraw the handle */
170 gtk_widget_queue_draw (widget);
179 gtk_switch_button_release (GtkWidget *widget,
180 GdkEventButton *event)
182 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
183 GtkAllocation allocation;
185 gtk_widget_get_allocation (widget, &allocation);
187 /* dragged toggles have a "soft" grab, so we don't care whether we
188 * are in the switch or not when the button is released; we do care
189 * for direct toggles, instead
191 if (!priv->is_dragging && !priv->in_switch)
197 priv->in_press = FALSE;
198 gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
204 if (priv->is_dragging)
206 priv->is_dragging = FALSE;
208 /* if half the handle passed the middle of the switch, then we
209 * consider it to be on
211 if ((priv->handle_x + (allocation.width / 4)) >= (allocation.width / 2))
213 gtk_switch_set_active (GTK_SWITCH (widget), TRUE);
214 priv->handle_x = allocation.width / 2;
218 gtk_switch_set_active (GTK_SWITCH (widget), FALSE);
222 gtk_widget_queue_draw (widget);
231 gtk_switch_enter (GtkWidget *widget,
232 GdkEventCrossing *event)
234 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
236 if (event->window == priv->event_window)
237 priv->in_switch = TRUE;
243 gtk_switch_leave (GtkWidget *widget,
244 GdkEventCrossing *event)
246 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
248 if (event->window == priv->event_window)
249 priv->in_switch = FALSE;
255 gtk_switch_key_release (GtkWidget *widget,
258 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
260 if (event->keyval == GDK_KEY_Return ||
261 event->keyval == GDK_KEY_KP_Enter ||
262 event->keyval == GDK_KEY_ISO_Enter ||
263 event->keyval == GDK_KEY_space ||
264 event->keyval == GDK_KEY_KP_Space)
266 gtk_switch_set_active (GTK_SWITCH (widget), !priv->is_active);
273 gtk_switch_get_preferred_width (GtkWidget *widget,
277 GtkStyle *style = gtk_widget_get_style (widget);
278 gint width, slider_width, focus_width, focus_pad;
280 PangoRectangle logical_rect;
282 width = style->xthickness * 2;
284 gtk_widget_style_get (widget,
285 "slider-width", &slider_width,
286 "focus-line-width", &focus_width,
287 "focus-padding", &focus_pad,
290 width += 2 * (focus_width + focus_pad);
292 /* Translators: if the "on" state label requires more than three
293 * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
296 layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
297 pango_layout_get_extents (layout, NULL, &logical_rect);
298 pango_extents_to_pixels (&logical_rect, NULL);
299 width += MAX (logical_rect.width, slider_width);
301 /* Translators: if the "off" state label requires more than three
302 * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
304 pango_layout_set_text (layout, C_("switch", "OFF"), -1);
305 pango_layout_get_extents (layout, NULL, &logical_rect);
306 pango_extents_to_pixels (&logical_rect, NULL);
307 width += MAX (logical_rect.width, slider_width);
309 g_object_unref (layout);
319 gtk_switch_get_preferred_height (GtkWidget *widget,
323 GtkStyle *style = gtk_widget_get_style (widget);
324 gint height, focus_width, focus_pad;
326 PangoRectangle logical_rect;
329 height = style->ythickness * 2;
331 gtk_widget_style_get (widget,
332 "focus-line-width", &focus_width,
333 "focus-padding", &focus_pad,
336 height += 2 * (focus_width + focus_pad);
338 str = g_strdup_printf ("%s%s",
340 C_("switch", "OFF"));
342 layout = gtk_widget_create_pango_layout (widget, str);
343 pango_layout_get_extents (layout, NULL, &logical_rect);
344 pango_extents_to_pixels (&logical_rect, NULL);
345 height += MAX (DEFAULT_SLIDER_HEIGHT, logical_rect.height);
347 g_object_unref (layout);
358 gtk_switch_size_allocate (GtkWidget *widget,
359 GtkAllocation *allocation)
361 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
363 gtk_widget_set_allocation (widget, allocation);
365 if (gtk_widget_get_realized (widget))
366 gdk_window_move_resize (priv->event_window,
374 gtk_switch_realize (GtkWidget *widget)
376 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
377 GdkWindow *parent_window;
378 GdkWindowAttr attributes;
379 gint attributes_mask;
380 GtkAllocation allocation;
382 gtk_widget_set_realized (widget, TRUE);
383 parent_window = gtk_widget_get_parent_window (widget);
384 gtk_widget_set_window (widget, parent_window);
385 g_object_ref (parent_window);
387 gtk_widget_get_allocation (widget, &allocation);
389 attributes.window_type = GDK_WINDOW_CHILD;
390 attributes.wclass = GDK_INPUT_ONLY;
391 attributes.x = allocation.x;
392 attributes.y = allocation.y;
393 attributes.width = allocation.width;
394 attributes.height = allocation.height;
395 attributes.event_mask = gtk_widget_get_events (widget);
396 attributes.event_mask |= (GDK_BUTTON_PRESS_MASK |
397 GDK_BUTTON_RELEASE_MASK |
398 GDK_BUTTON1_MOTION_MASK |
399 GDK_POINTER_MOTION_HINT_MASK |
400 GDK_POINTER_MOTION_MASK |
401 GDK_ENTER_NOTIFY_MASK |
402 GDK_LEAVE_NOTIFY_MASK);
403 attributes_mask = GDK_WA_X | GDK_WA_Y;
405 priv->event_window = gdk_window_new (parent_window,
408 gdk_window_set_user_data (priv->event_window, widget);
410 gtk_widget_style_attach (widget);
414 gtk_switch_unrealize (GtkWidget *widget)
416 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
418 if (priv->event_window != NULL)
420 gdk_window_set_user_data (priv->event_window, NULL);
421 gdk_window_destroy (priv->event_window);
422 priv->event_window = NULL;
425 GTK_WIDGET_CLASS (gtk_switch_parent_class)->unrealize (widget);
429 gtk_switch_map (GtkWidget *widget)
431 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
433 GTK_WIDGET_CLASS (gtk_switch_parent_class)->map (widget);
435 if (priv->event_window)
436 gdk_window_show (priv->event_window);
440 gtk_switch_unmap (GtkWidget *widget)
442 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
444 if (priv->event_window)
445 gdk_window_hide (priv->event_window);
447 GTK_WIDGET_CLASS (gtk_switch_parent_class)->unmap (widget);
451 gtk_switch_paint_handle (GtkWidget *widget,
455 GtkStyle *style = gtk_widget_get_style (widget);
457 gtk_paint_slider (style, cr,
458 gtk_widget_get_state (widget),
460 GTK_WIDGET (widget), "switch-slider",
465 GTK_ORIENTATION_HORIZONTAL);
469 gtk_switch_draw (GtkWidget *widget,
472 GtkSwitchPrivate *priv = GTK_SWITCH (widget)->priv;
477 gint label_x, label_y;
479 gint focus_width, focus_pad;
480 gint x, y, width, height;
482 gtk_widget_style_get (widget,
483 "focus-line-width", &focus_width,
484 "focus-padding", &focus_pad,
487 style = gtk_widget_get_style (widget);
491 width = gtk_widget_get_allocated_width (widget);
492 height = gtk_widget_get_allocated_height (widget);
494 if (gtk_widget_has_focus (widget))
495 gtk_paint_focus (style, cr,
496 gtk_widget_get_state (widget),
498 x, y, width, height);
500 x += focus_width + focus_pad;
501 y += focus_width + focus_pad;
502 width -= 2 * (focus_width + focus_pad);
503 height -= 2 * (focus_width + focus_pad);
505 state = priv->is_active ? GTK_STATE_SELECTED : gtk_widget_get_state (widget);
507 /* background - XXX should this be a flat box instead? we're missing
508 * the border given by the shadow with that, which would require
509 * fixing all theme engines to add a subtle border for this widget
511 gtk_paint_box (style, cr,
514 widget, "switch-background",
515 x, y, width, height);
517 if (!gtk_widget_is_sensitive (widget))
518 state = GTK_STATE_INSENSITIVE;
520 /* XXX the +1/-1 it's pixel wriggling after checking with the default
523 handle.y = y + style->ythickness + 1;
524 handle.width = (width - style->xthickness * 2) / 2;
525 handle.height = (height - style->ythickness * 2) - 1;
527 /* Translators: if the "on" state label requires more than three
528 * glyphs then use MEDIUM VERTICAL BAR (U+2759) as the text for
531 layout = gtk_widget_create_pango_layout (widget, C_("switch", "ON"));
532 pango_layout_get_extents (layout, NULL, &rect);
533 pango_extents_to_pixels (&rect, NULL);
535 label_x = x + style->xthickness
536 + ((width / 2) - rect.width - (style->xthickness * 2)) / 2;
537 label_y = y + style->ythickness
538 + (height - rect.height - (style->ythickness * 2)) / 2;
540 gtk_paint_layout (style, cr,
543 widget, "switch-on-label",
547 g_object_unref (layout);
549 /* Translators: if the "off" state label requires more than three
550 * glyphs then use WHITE CIRCLE (U+25CB) as the text for the state
552 layout = gtk_widget_create_pango_layout (widget, C_("switch", "OFF"));
553 pango_layout_get_extents (layout, NULL, &rect);
554 pango_extents_to_pixels (&rect, NULL);
556 label_x = x + style->xthickness
558 + ((width / 2) - rect.width - (style->xthickness * 2)) / 2;
559 label_y = y + style->ythickness
560 + (height - rect.height - (style->ythickness * 2)) / 2;
562 gtk_paint_layout (style, cr,
565 widget, "switch-off-label",
569 g_object_unref (layout);
571 if (priv->is_dragging)
572 handle.x = x + priv->handle_x;
573 else if (priv->is_active)
574 handle.x = x + width - handle.width - style->xthickness;
576 handle.x = x + style->xthickness;
578 gtk_switch_paint_handle (widget, cr, &handle);
584 gtk_switch_get_accessible (GtkWidget *widget)
586 static gboolean first_time = TRUE;
588 if (G_UNLIKELY (first_time))
590 AtkObjectFactory *factory;
591 AtkRegistry *registry;
593 GType derived_atk_type;
595 /* Figure out whether accessibility is enabled by looking at the
596 * type of the accessible object which would be created for the
597 * parent type of GtkSwitch
599 derived_type = g_type_parent (GTK_TYPE_SWITCH);
601 registry = atk_get_default_registry ();
602 factory = atk_registry_get_factory (registry, derived_type);
603 derived_atk_type = atk_object_factory_get_accessible_type (factory);
604 if (g_type_is_a (derived_atk_type, GTK_TYPE_ACCESSIBLE))
605 atk_registry_set_factory_type (registry,
607 gtk_switch_accessible_factory_get_type ());
612 return GTK_WIDGET_CLASS (gtk_switch_parent_class)->get_accessible (widget);
616 gtk_switch_set_related_action (GtkSwitch *sw,
619 GtkSwitchPrivate *priv = sw->priv;
621 if (priv->action == action)
624 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (sw), action);
626 priv->action = action;
630 gtk_switch_set_use_action_appearance (GtkSwitch *sw,
631 gboolean use_appearance)
633 GtkSwitchPrivate *priv = sw->priv;
635 if (priv->use_action_appearance != use_appearance)
637 priv->use_action_appearance = use_appearance;
639 gtk_activatable_sync_action_properties (GTK_ACTIVATABLE (sw), priv->action);
644 gtk_switch_set_property (GObject *gobject,
649 GtkSwitch *sw = GTK_SWITCH (gobject);
654 gtk_switch_set_active (sw, g_value_get_boolean (value));
657 case PROP_RELATED_ACTION:
658 gtk_switch_set_related_action (sw, g_value_get_object (value));
661 case PROP_USE_ACTION_APPEARANCE:
662 gtk_switch_set_use_action_appearance (sw, g_value_get_boolean (value));
666 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
671 gtk_switch_get_property (GObject *gobject,
676 GtkSwitchPrivate *priv = GTK_SWITCH (gobject)->priv;
681 g_value_set_boolean (value, priv->is_active);
684 case PROP_RELATED_ACTION:
685 g_value_set_object (value, priv->action);
688 case PROP_USE_ACTION_APPEARANCE:
689 g_value_set_boolean (value, priv->use_action_appearance);
693 G_OBJECT_WARN_INVALID_PROPERTY_ID (gobject, prop_id, pspec);
698 gtk_switch_dispose (GObject *object)
700 GtkSwitchPrivate *priv = GTK_SWITCH (object)->priv;
704 gtk_activatable_do_set_related_action (GTK_ACTIVATABLE (object), NULL);
708 G_OBJECT_CLASS (gtk_switch_parent_class)->dispose (object);
712 gtk_switch_class_init (GtkSwitchClass *klass)
714 GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
715 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
716 gpointer activatable_iface;
718 g_type_class_add_private (klass, sizeof (GtkSwitchPrivate));
720 activatable_iface = g_type_default_interface_peek (GTK_TYPE_ACTIVATABLE);
721 switch_props[PROP_RELATED_ACTION] =
722 g_param_spec_override ("related-action",
723 g_object_interface_find_property (activatable_iface,
726 switch_props[PROP_USE_ACTION_APPEARANCE] =
727 g_param_spec_override ("use-action-appearance",
728 g_object_interface_find_property (activatable_iface,
729 "use-action-appearance"));
734 * Whether the #GtkSwitch widget is in its on or off state.
736 switch_props[PROP_ACTIVE] =
737 g_param_spec_boolean ("active",
739 P_("Whether the switch is on or off"),
741 GTK_PARAM_READWRITE);
743 gobject_class->set_property = gtk_switch_set_property;
744 gobject_class->get_property = gtk_switch_get_property;
745 gobject_class->dispose = gtk_switch_dispose;
747 g_object_class_install_properties (gobject_class, LAST_PROP, switch_props);
749 widget_class->get_preferred_width = gtk_switch_get_preferred_width;
750 widget_class->get_preferred_height = gtk_switch_get_preferred_height;
751 widget_class->size_allocate = gtk_switch_size_allocate;
752 widget_class->realize = gtk_switch_realize;
753 widget_class->unrealize = gtk_switch_unrealize;
754 widget_class->map = gtk_switch_map;
755 widget_class->unmap = gtk_switch_unmap;
756 widget_class->draw = gtk_switch_draw;
757 widget_class->button_press_event = gtk_switch_button_press;
758 widget_class->button_release_event = gtk_switch_button_release;
759 widget_class->motion_notify_event = gtk_switch_motion;
760 widget_class->enter_notify_event = gtk_switch_enter;
761 widget_class->leave_notify_event = gtk_switch_leave;
762 widget_class->key_release_event = gtk_switch_key_release;
763 widget_class->get_accessible = gtk_switch_get_accessible;
766 * GtkSwitch:slider-width:
768 * The minimum width of the #GtkSwitch handle, in pixels.
770 gtk_widget_class_install_style_property (widget_class,
771 g_param_spec_int ("slider-width",
773 P_("The minimum width of the handle"),
774 DEFAULT_SLIDER_WIDTH, G_MAXINT,
775 DEFAULT_SLIDER_WIDTH,
776 GTK_PARAM_READABLE));
780 gtk_switch_init (GtkSwitch *self)
782 self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTK_TYPE_SWITCH, GtkSwitchPrivate);
783 self->priv->use_action_appearance = TRUE;
784 gtk_widget_set_has_window (GTK_WIDGET (self), FALSE);
785 gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
791 * Creates a new #GtkSwitch widget.
793 * Return value: the newly created #GtkSwitch instance
798 gtk_switch_new (void)
800 return g_object_new (GTK_TYPE_SWITCH, NULL);
804 * gtk_switch_set_active:
806 * @is_active: %TRUE if @sw should be active, and %FALSE otherwise
808 * Changes the state of @sw to the desired one.
813 gtk_switch_set_active (GtkSwitch *sw,
816 GtkSwitchPrivate *priv;
818 g_return_if_fail (GTK_IS_SWITCH (sw));
820 is_active = !!is_active;
824 if (priv->is_active != is_active)
826 AtkObject *accessible;
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 gtk_widget_queue_draw (GTK_WIDGET (sw));
843 * gtk_switch_get_active:
846 * Gets whether the #GtkSwitch is in its "on" or "off" state.
848 * Return value: %TRUE if the #GtkSwitch is active, and %FALSE otherwise
853 gtk_switch_get_active (GtkSwitch *sw)
855 g_return_val_if_fail (GTK_IS_SWITCH (sw), FALSE);
857 return sw->priv->is_active;
861 gtk_switch_update (GtkActivatable *activatable,
863 const gchar *property_name)
865 if (strcmp (property_name, "visible") == 0)
867 if (gtk_action_is_visible (action))
868 gtk_widget_show (GTK_WIDGET (activatable));
870 gtk_widget_hide (GTK_WIDGET (activatable));
872 else if (strcmp (property_name, "sensitive") == 0)
874 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
876 else if (strcmp (property_name, "active") == 0)
878 gtk_action_block_activate (action);
879 gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
880 gtk_action_unblock_activate (action);
885 gtk_switch_sync_action_properties (GtkActivatable *activatable,
891 if (gtk_action_is_visible (action))
892 gtk_widget_show (GTK_WIDGET (activatable));
894 gtk_widget_hide (GTK_WIDGET (activatable));
896 gtk_widget_set_sensitive (GTK_WIDGET (activatable), gtk_action_is_sensitive (action));
898 gtk_action_block_activate (action);
899 gtk_switch_set_active (GTK_SWITCH (activatable), gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)));
900 gtk_action_unblock_activate (action);
904 gtk_switch_activatable_interface_init (GtkActivatableIface *iface)
906 iface->update = gtk_switch_update;
907 iface->sync_action_properties = gtk_switch_sync_action_properties;
910 /* accessibility: object */
913 typedef struct _GtkSwitchAccessible GtkSwitchAccessible;
914 typedef struct _GtkSwitchAccessibleClass GtkSwitchAccessibleClass;
916 ATK_DEFINE_TYPE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_WIDGET);
919 gtk_switch_accessible_ref_state_set (AtkObject *accessible)
921 AtkStateSet *state_set;
924 state_set = ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->ref_state_set (accessible);
926 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
930 if (gtk_switch_get_active (GTK_SWITCH (widget)))
931 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
937 _gtk_switch_accessible_initialize (AtkObject *accessible,
940 ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->initialize (accessible, widget);
942 atk_object_set_role (accessible, ATK_ROLE_TOGGLE_BUTTON);
943 atk_object_set_name (accessible, C_("light switch widget", "Switch"));
944 atk_object_set_description (accessible, _("Switches between on and off states"));
948 _gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
950 AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
952 atk_class->initialize = _gtk_switch_accessible_initialize;
953 atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
957 _gtk_switch_accessible_init (GtkSwitchAccessible *self)
961 /* accessibility: factory */
963 typedef AtkObjectFactoryClass GtkSwitchAccessibleFactoryClass;
964 typedef AtkObjectFactory GtkSwitchAccessibleFactory;
966 G_DEFINE_TYPE (GtkSwitchAccessibleFactory,
967 gtk_switch_accessible_factory,
968 ATK_TYPE_OBJECT_FACTORY);
971 gtk_switch_accessible_factory_get_accessible_type (void)
973 return _gtk_switch_accessible_get_type ();
977 gtk_switch_accessible_factory_create_accessible (GObject *obj)
979 AtkObject *accessible;
981 accessible = g_object_new (_gtk_switch_accessible_get_type (), NULL);
982 atk_object_initialize (accessible, obj);
988 gtk_switch_accessible_factory_class_init (AtkObjectFactoryClass *klass)
990 klass->create_accessible = gtk_switch_accessible_factory_create_accessible;
991 klass->get_accessible_type = gtk_switch_accessible_factory_get_accessible_type;
995 gtk_switch_accessible_factory_init (AtkObjectFactory *factory)