]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailtogglebutton.c
63f8d441bb39e03209d2901590e4a02af894cdf8
[~andy/gtk] / modules / other / gail / gailtogglebutton.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 "gailtogglebutton.h"
25
26 static void      gail_toggle_button_class_init        (GailToggleButtonClass *klass);
27
28 static void      gail_toggle_button_init              (GailToggleButton      *button);
29
30 static void      gail_toggle_button_toggled_gtk       (GtkWidget             *widget);
31
32 static void      gail_toggle_button_real_notify_gtk   (GObject               *obj,
33                                                        GParamSpec            *pspec);
34
35 static void      gail_toggle_button_real_initialize   (AtkObject             *obj,
36                                                        gpointer              data);
37
38 static AtkStateSet* gail_toggle_button_ref_state_set  (AtkObject             *accessible);
39
40 G_DEFINE_TYPE (GailToggleButton, gail_toggle_button, GAIL_TYPE_BUTTON)
41
42 static void
43 gail_toggle_button_class_init (GailToggleButtonClass *klass)
44 {
45   GailWidgetClass *widget_class;
46   AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
47
48   widget_class = (GailWidgetClass*)klass;
49   widget_class->notify_gtk = gail_toggle_button_real_notify_gtk;
50
51   class->ref_state_set = gail_toggle_button_ref_state_set;
52   class->initialize = gail_toggle_button_real_initialize;
53 }
54
55 static void
56 gail_toggle_button_init (GailToggleButton *button)
57 {
58 }
59
60 static void
61 gail_toggle_button_real_initialize (AtkObject *obj,
62                                     gpointer  data)
63 {
64   ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->initialize (obj, data);
65
66   g_signal_connect (data,
67                     "toggled",
68                     G_CALLBACK (gail_toggle_button_toggled_gtk),
69                     NULL);
70
71   if (GTK_IS_CHECK_BUTTON (data))
72     obj->role = ATK_ROLE_CHECK_BOX;
73   else
74     obj->role = ATK_ROLE_TOGGLE_BUTTON;
75 }
76
77 static void
78 gail_toggle_button_toggled_gtk (GtkWidget       *widget)
79 {
80   AtkObject *accessible;
81   GtkToggleButton *toggle_button;
82
83   toggle_button = GTK_TOGGLE_BUTTON (widget);
84
85   accessible = gtk_widget_get_accessible (widget);
86   atk_object_notify_state_change (accessible, ATK_STATE_CHECKED, 
87                                   gtk_toggle_button_get_active (toggle_button));
88
89
90 static AtkStateSet*
91 gail_toggle_button_ref_state_set (AtkObject *accessible)
92 {
93   AtkStateSet *state_set;
94   GtkToggleButton *toggle_button;
95   GtkWidget *widget;
96
97   state_set = ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->ref_state_set (accessible);
98   widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
99  
100   if (widget == NULL)
101     return state_set;
102
103   toggle_button = GTK_TOGGLE_BUTTON (widget);
104
105   if (gtk_toggle_button_get_active (toggle_button))
106     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
107
108   if (gtk_toggle_button_get_inconsistent (toggle_button))
109     {
110       atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
111       atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
112     }
113  
114   return state_set;
115 }
116
117 static void
118 gail_toggle_button_real_notify_gtk (GObject           *obj,
119                                     GParamSpec        *pspec)
120 {
121   GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
122   AtkObject *atk_obj;
123   gboolean sensitive;
124   gboolean inconsistent;
125
126   atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
127   sensitive = gtk_widget_get_sensitive (GTK_WIDGET (toggle_button));
128   inconsistent = gtk_toggle_button_get_inconsistent (toggle_button);
129
130   if (strcmp (pspec->name, "inconsistent") == 0)
131     {
132       atk_object_notify_state_change (atk_obj, ATK_STATE_INDETERMINATE, inconsistent);
133       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
134     }
135   else if (strcmp (pspec->name, "sensitive") == 0)
136     {
137       /* Need to override gailwidget behavior of notifying for ENABLED */
138       atk_object_notify_state_change (atk_obj, ATK_STATE_SENSITIVE, sensitive);
139       atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED, (sensitive && !inconsistent));
140     }
141   else
142     GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);
143 }