1 /* GAIL - The GNOME Accessibility Implementation Library
2 * Copyright 2001, 2002, 2003 Sun Microsystems Inc.
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.
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.
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.
24 #include "gailtogglebutton.h"
26 static void gail_toggle_button_class_init (GailToggleButtonClass *klass);
28 static void gail_toggle_button_init (GailToggleButton *button);
30 static void gail_toggle_button_toggled_gtk (GtkWidget *widget);
32 static void gail_toggle_button_real_notify_gtk (GObject *obj,
35 static void gail_toggle_button_real_initialize (AtkObject *obj,
38 static AtkStateSet* gail_toggle_button_ref_state_set (AtkObject *accessible);
40 G_DEFINE_TYPE (GailToggleButton, gail_toggle_button, GAIL_TYPE_BUTTON)
43 gail_toggle_button_class_init (GailToggleButtonClass *klass)
45 GailWidgetClass *widget_class;
46 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
48 widget_class = (GailWidgetClass*)klass;
49 widget_class->notify_gtk = gail_toggle_button_real_notify_gtk;
51 class->ref_state_set = gail_toggle_button_ref_state_set;
52 class->initialize = gail_toggle_button_real_initialize;
56 gail_toggle_button_init (GailToggleButton *button)
61 gail_toggle_button_real_initialize (AtkObject *obj,
64 ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->initialize (obj, data);
66 g_signal_connect (data,
68 G_CALLBACK (gail_toggle_button_toggled_gtk),
71 if (GTK_IS_CHECK_BUTTON (data))
72 obj->role = ATK_ROLE_CHECK_BOX;
74 obj->role = ATK_ROLE_TOGGLE_BUTTON;
78 gail_toggle_button_toggled_gtk (GtkWidget *widget)
80 AtkObject *accessible;
81 GtkToggleButton *toggle_button;
83 toggle_button = GTK_TOGGLE_BUTTON (widget);
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));
91 gail_toggle_button_ref_state_set (AtkObject *accessible)
93 AtkStateSet *state_set;
94 GtkToggleButton *toggle_button;
97 state_set = ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->ref_state_set (accessible);
98 widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible));
103 toggle_button = GTK_TOGGLE_BUTTON (widget);
105 if (gtk_toggle_button_get_active (toggle_button))
106 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
108 if (gtk_toggle_button_get_inconsistent (toggle_button))
110 atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
111 atk_state_set_add_state (state_set, ATK_STATE_INDETERMINATE);
118 gail_toggle_button_real_notify_gtk (GObject *obj,
121 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
124 gboolean inconsistent;
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);
130 if (strcmp (pspec->name, "inconsistent") == 0)
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));
135 else if (strcmp (pspec->name, "sensitive") == 0)
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));
142 GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);