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.
22 #include "gailtogglebutton.h"
24 static void gail_toggle_button_class_init (GailToggleButtonClass *klass);
26 static void gail_toggle_button_toggled_gtk (GtkWidget *widget);
28 static void gail_toggle_button_real_notify_gtk (GObject *obj,
31 static void gail_toggle_button_real_initialize (AtkObject *obj,
34 static AtkStateSet* gail_toggle_button_ref_state_set (AtkObject *accessible);
36 static GailButtonClass *parent_class = NULL;
39 gail_toggle_button_get_type (void)
41 static GType type = 0;
45 static const GTypeInfo tinfo =
47 sizeof (GailToggleButtonClass),
48 (GBaseInitFunc) NULL, /* base init */
49 (GBaseFinalizeFunc) NULL, /* base finalize */
50 (GClassInitFunc) gail_toggle_button_class_init, /* class init */
51 (GClassFinalizeFunc) NULL, /* class finalize */
52 NULL, /* class data */
53 sizeof (GailToggleButton), /* instance size */
55 (GInstanceInitFunc) NULL, /* instance init */
56 NULL /* value table */
59 type = g_type_register_static (GAIL_TYPE_BUTTON,
60 "GailToggleButton", &tinfo, 0);
67 gail_toggle_button_class_init (GailToggleButtonClass *klass)
69 GailWidgetClass *widget_class;
70 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
72 widget_class = (GailWidgetClass*)klass;
73 widget_class->notify_gtk = gail_toggle_button_real_notify_gtk;
75 parent_class = g_type_class_peek_parent (klass);
77 class->ref_state_set = gail_toggle_button_ref_state_set;
78 class->initialize = gail_toggle_button_real_initialize;
82 gail_toggle_button_new (GtkWidget *widget)
85 AtkObject *accessible;
87 g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), NULL);
89 object = g_object_new (GAIL_TYPE_TOGGLE_BUTTON, NULL);
91 accessible = ATK_OBJECT (object);
92 atk_object_initialize (accessible, widget);
98 gail_toggle_button_real_initialize (AtkObject *obj,
101 ATK_OBJECT_CLASS (parent_class)->initialize (obj, data);
103 g_signal_connect (data,
105 G_CALLBACK (gail_toggle_button_toggled_gtk),
108 if (GTK_IS_CHECK_BUTTON (data))
109 obj->role = ATK_ROLE_CHECK_BOX;
111 obj->role = ATK_ROLE_TOGGLE_BUTTON;
115 gail_toggle_button_toggled_gtk (GtkWidget *widget)
117 AtkObject *accessible;
118 GtkToggleButton *toggle_button;
120 toggle_button = GTK_TOGGLE_BUTTON (widget);
122 accessible = gtk_widget_get_accessible (widget);
123 atk_object_notify_state_change (accessible, ATK_STATE_CHECKED,
124 toggle_button->active);
128 gail_toggle_button_ref_state_set (AtkObject *accessible)
130 AtkStateSet *state_set;
131 GtkToggleButton *toggle_button;
134 state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible);
135 widget = GTK_ACCESSIBLE (accessible)->widget;
140 toggle_button = GTK_TOGGLE_BUTTON (widget);
142 if (gtk_toggle_button_get_active (toggle_button))
143 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
145 if (gtk_toggle_button_get_inconsistent (toggle_button))
146 atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
152 gail_toggle_button_real_notify_gtk (GObject *obj,
155 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
158 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
160 if (strcmp (pspec->name, "inconsistent") == 0)
161 atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED,
162 !gtk_toggle_button_get_inconsistent (toggle_button));
164 GAIL_WIDGET_CLASS (parent_class)->notify_gtk (obj, pspec);