]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtktogglebuttonaccessible.c
Change FSF Address
[~andy/gtk] / gtk / a11y / gtktogglebuttonaccessible.c
1 /* GAIL - The GNOME Accessibility Implementation Library
2  * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
3  *
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.
8  *
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.
13  *
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/>.
16  */
17
18 #include "config.h"
19
20 #include <string.h>
21 #include <gtk/gtk.h>
22 #include "gtktogglebuttonaccessible.h"
23
24
25 G_DEFINE_TYPE (GtkToggleButtonAccessible, _gtk_toggle_button_accessible, GTK_TYPE_BUTTON_ACCESSIBLE)
26
27 static void
28 gtk_toggle_button_accessible_toggled (GtkWidget *widget)
29 {
30   AtkObject *accessible;
31   GtkToggleButton *toggle_button;
32
33   toggle_button = GTK_TOGGLE_BUTTON (widget);
34
35   accessible = gtk_widget_get_accessible (widget);
36   atk_object_notify_state_change (accessible, ATK_STATE_CHECKED,
37                                   gtk_toggle_button_get_active (toggle_button));
38 }
39
40 static void
41 gtk_toggle_button_accessible_initialize (AtkObject *obj,
42                                          gpointer   data)
43 {
44   ATK_OBJECT_CLASS (_gtk_toggle_button_accessible_parent_class)->initialize (obj, data);
45
46   g_signal_connect (data, "toggled",
47                     G_CALLBACK (gtk_toggle_button_accessible_toggled), NULL);
48
49   obj->role = ATK_ROLE_TOGGLE_BUTTON;
50 }
51
52 static void
53 gtk_toggle_button_accessible_notify_gtk (GObject    *obj,
54                                          GParamSpec *pspec)
55 {
56   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
57   AtkObject *atk_obj;
58   gboolean sensitive;
59   gboolean inconsistent;
60
61   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
62   sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
63   inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
64
65   if (strcmp (pspec->name, "inconsistent") == 0)
66     {
67       atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
68       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
69     }
70   else if (strcmp (pspec->name, "sensitive") == 0)
71     {
72       /* Need to override gailwidget behavior of notifying for ENABLED */
73       atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
74       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
75     }
76   else
77     GTK_WIDGET_ACCESSIBLE_CLASS (_gtk_toggle_button_accessible_parent_class)->notify_gtk (obj, pspec);
78 }
79
80 static AtkStateSet*
81 gtk_toggle_button_accessible_ref_state_set (AtkObject *accessible)
82 {
83   AtkStateSet *state_set;
84   GtkToggleButton *toggle_button;
85   GtkWidget *widget;
86
87   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
88   if (widget == NULL)
89     return NULL;
90
91   state_set = ATK_OBJECT_CLASS (_gtk_toggle_button_accessible_parent_class)->ref_state_set (accessible);
92   toggle_button = GTK_TOGGLE_BUTTON (widget);
93
94   if (gtk_toggle_button_get_active (toggle_button))
95     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
96
97   if (gtk_toggle_button_get_inconsistent (toggle_button))
98     {
99       atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
100       atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
101     }
102
103   return state_set;
104 }
105
106 static void
107 _gtk_toggle_button_accessible_class_init (GtkToggleButtonAccessibleClass *klass)
108 {
109   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
110   GtkWidgetAccessibleClass *widget_class = (GtkWidgetAccessibleClass*)klass;
111
112   widget_class->notify_gtk = gtk_toggle_button_accessible_notify_gtk;
113
114   class->ref_state_set = gtk_toggle_button_accessible_ref_state_set;
115   class->initialize = gtk_toggle_button_accessible_initialize;
116 }
117
118 static void
119 _gtk_toggle_button_accessible_init (GtkToggleButtonAccessible *button)
120 {
121 }