]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkswitchaccessible.c
a11y: remove implementation for [add/remove]_global_event_listener
[~andy/gtk] / gtk / a11y / gtkswitchaccessible.c
1 /* GTK - The GIMP Toolkit
2  *
3  * Copyright (C) 2010  Intel Corporation
4  * Copyright (C) 2010  RedHat, Inc.
5  *
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.
10  *
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.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Author:
20  *      Emmanuele Bassi <ebassi@linux.intel.com>
21  *      Matthias Clasen <mclasen@redhat.com>
22  *
23  * Based on similar code from Mx.
24  */
25
26 #include "config.h"
27
28 #include <gtk/gtk.h>
29 #include "gtkintl.h"
30 #include "gtkswitchaccessible.h"
31
32
33 static void atk_action_interface_init (AtkActionIface *iface);
34
35 G_DEFINE_TYPE_WITH_CODE (GtkSwitchAccessible, _gtk_switch_accessible, GTK_TYPE_WIDGET_ACCESSIBLE,
36                          G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, atk_action_interface_init))
37
38 static AtkStateSet *
39 gtk_switch_accessible_ref_state_set (AtkObject *accessible)
40 {
41   AtkStateSet *state_set;
42   GtkWidget *widget;
43
44   state_set = ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->ref_state_set (accessible);
45
46   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
47   if (widget == NULL)
48     return state_set;
49
50   if (gtk_switch_get_active (GTK_SWITCH (widget)))
51     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
52
53   return state_set;
54 }
55
56 static void
57 gtk_switch_accessible_initialize (AtkObject *accessible,
58                                   gpointer   widget)
59 {
60   ATK_OBJECT_CLASS (_gtk_switch_accessible_parent_class)->initialize (accessible, widget);
61
62   atk_object_set_role (accessible, ATK_ROLE_TOGGLE_BUTTON);
63   atk_object_set_name (accessible, C_("light switch widget", "Switch"));
64   atk_object_set_description (accessible, _("Switches between on and off states"));
65 }
66
67 static void
68 _gtk_switch_accessible_class_init (GtkSwitchAccessibleClass *klass)
69 {
70   AtkObjectClass *atk_class = ATK_OBJECT_CLASS (klass);
71
72   atk_class->initialize = gtk_switch_accessible_initialize;
73   atk_class->ref_state_set = gtk_switch_accessible_ref_state_set;
74 }
75
76 static void
77 _gtk_switch_accessible_init (GtkSwitchAccessible *self)
78 {
79 }
80
81 static gint
82 gtk_switch_action_get_n_actions (AtkAction *action)
83 {
84   return 1;
85 }
86
87 static const gchar *
88 gtk_switch_action_get_name (AtkAction *action,
89                             gint       i)
90 {
91   if (i != 0)
92     return NULL;
93
94   return "toggle";
95 }
96
97 static gboolean
98 gtk_switch_action_do_action (AtkAction *action,
99                              gint       i)
100 {
101   GtkSwitch *sw;
102   GtkWidget *widget;
103
104   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (action));
105   if (widget == NULL)
106     return FALSE;
107
108   if (i != 0)
109     return FALSE;
110
111   if (!gtk_widget_is_sensitive (widget) || !gtk_widget_get_visible (widget))
112     return FALSE;
113
114   sw = GTK_SWITCH (widget);
115   gtk_switch_set_active (sw, !gtk_switch_get_active (sw));
116
117   return TRUE;
118 }
119
120 static void
121 atk_action_interface_init (AtkActionIface *iface)
122 {
123   iface->do_action = gtk_switch_action_do_action;
124   iface->get_n_actions = gtk_switch_action_get_n_actions;
125   iface->get_name = gtk_switch_action_get_name;
126 }