]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtktogglebuttonaccessible.c
04322f693220107b145b630c612375498fa2bcd4
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <string.h>
23 #include <gtk/gtk.h>
24 #include "gtktogglebuttonaccessible.h"
25
26
27 G_DEFINE_TYPE (GtkToggleButtonAccessible, gtk_toggle_button_accessible, GAIL_TYPE_BUTTON)
28
29 static void
30 gtk_toggle_button_accessible_toggled (GtkWidget *widget)
31 {
32   AtkObject *accessible;
33   GtkToggleButton *toggle_button;
34
35   toggle_button = GTK_TOGGLE_BUTTON (widget);
36
37   accessible = gtk_widget_get_accessible (widget);
38   atk_object_notify_state_change (accessible, ATK_STATE_CHECKED,
39                                   gtk_toggle_button_get_active (toggle_button));
40 }
41
42 static void
43 gtk_toggle_button_accessible_initialize (AtkObject *obj,
44                                          gpointer   data)
45 {
46   ATK_OBJECT_CLASS (gtk_toggle_button_accessible_parent_class)->initialize (obj, data);
47
48   g_signal_connect (data, "toggled",
49                     G_CALLBACK (gtk_toggle_button_accessible_toggled), NULL);
50
51   if (GTK_IS_CHECK_BUTTON (data))
52     obj->role = ATK_ROLE_CHECK_BOX;
53   else
54     obj->role = ATK_ROLE_TOGGLE_BUTTON;
55 }
56
57 static void
58 gtk_toggle_button_accessible_notify_gtk (GObject    *obj,
59                                          GParamSpec *pspec)
60 {
61   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
62   AtkObject *atk_obj;
63   gboolean sensitive;
64   gboolean inconsistent;
65
66   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
67   sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
68   inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
69
70   if (strcmp (pspec->name, "inconsistent") == 0)
71     {
72       atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
73       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
74     }
75   else if (strcmp (pspec->name, "sensitive") == 0)
76     {
77       /* Need to override gailwidget behavior of notifying for ENABLED */
78       atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
79       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
80     }
81   else
82     GAIL_WIDGET_CLASS (gtk_toggle_button_accessible_parent_class)->notify_gtk (obj, pspec);
83 }
84
85 static AtkStateSet*
86 gtk_toggle_button_accessible_ref_state_set (AtkObject *accessible)
87 {
88   AtkStateSet *state_set;
89   GtkToggleButton *toggle_button;
90   GtkWidget *widget;
91
92   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
93   if (widget == NULL)
94     return NULL;
95
96   state_set = ATK_OBJECT_CLASS (gtk_toggle_button_accessible_parent_class)->ref_state_set (accessible);
97   toggle_button = GTK_TOGGLE_BUTTON (widget);
98
99   if (gtk_toggle_button_get_active (toggle_button))
100     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
101
102   if (gtk_toggle_button_get_inconsistent (toggle_button))
103     {
104       atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
105       atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
106     }
107
108   return state_set;
109 }
110
111 static void
112 gtk_toggle_button_accessible_class_init (GtkToggleButtonAccessibleClass *klass)
113 {
114   GailWidgetClass *widget_class;
115   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
116
117   widget_class = (GailWidgetClass*)klass;
118   widget_class->notify_gtk = gtk_toggle_button_accessible_notify_gtk;
119
120   class->ref_state_set = gtk_toggle_button_accessible_ref_state_set;
121   class->initialize = gtk_toggle_button_accessible_initialize;
122 }
123
124 static void
125 gtk_toggle_button_accessible_init (GtkToggleButtonAccessible *button)
126 {
127 }