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_init (GailToggleButton *button);
28 static void gail_toggle_button_toggled_gtk (GtkWidget *widget);
30 static void gail_toggle_button_real_notify_gtk (GObject *obj,
33 static void gail_toggle_button_real_initialize (AtkObject *obj,
36 static AtkStateSet* gail_toggle_button_ref_state_set (AtkObject *accessible);
38 G_DEFINE_TYPE (GailToggleButton, gail_toggle_button, GAIL_TYPE_BUTTON)
41 gail_toggle_button_class_init (GailToggleButtonClass *klass)
43 GailWidgetClass *widget_class;
44 AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
46 widget_class = (GailWidgetClass*)klass;
47 widget_class->notify_gtk = gail_toggle_button_real_notify_gtk;
49 class->ref_state_set = gail_toggle_button_ref_state_set;
50 class->initialize = gail_toggle_button_real_initialize;
54 gail_toggle_button_init (GailToggleButton *button)
59 gail_toggle_button_new (GtkWidget *widget)
62 AtkObject *accessible;
64 g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), NULL);
66 object = g_object_new (GAIL_TYPE_TOGGLE_BUTTON, NULL);
68 accessible = ATK_OBJECT (object);
69 atk_object_initialize (accessible, widget);
75 gail_toggle_button_real_initialize (AtkObject *obj,
78 ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->initialize (obj, data);
80 g_signal_connect (data,
82 G_CALLBACK (gail_toggle_button_toggled_gtk),
85 if (GTK_IS_CHECK_BUTTON (data))
86 obj->role = ATK_ROLE_CHECK_BOX;
88 obj->role = ATK_ROLE_TOGGLE_BUTTON;
92 gail_toggle_button_toggled_gtk (GtkWidget *widget)
94 AtkObject *accessible;
95 GtkToggleButton *toggle_button;
97 toggle_button = GTK_TOGGLE_BUTTON (widget);
99 accessible = gtk_widget_get_accessible (widget);
100 atk_object_notify_state_change (accessible, ATK_STATE_CHECKED,
101 toggle_button->active);
105 gail_toggle_button_ref_state_set (AtkObject *accessible)
107 AtkStateSet *state_set;
108 GtkToggleButton *toggle_button;
111 state_set = ATK_OBJECT_CLASS (gail_toggle_button_parent_class)->ref_state_set (accessible);
112 widget = GTK_ACCESSIBLE (accessible)->widget;
117 toggle_button = GTK_TOGGLE_BUTTON (widget);
119 if (gtk_toggle_button_get_active (toggle_button))
120 atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
122 if (gtk_toggle_button_get_inconsistent (toggle_button))
123 atk_state_set_remove_state (state_set, ATK_STATE_ENABLED);
129 gail_toggle_button_real_notify_gtk (GObject *obj,
132 GtkToggleButton *toggle_button = GTK_TOGGLE_BUTTON (obj);
135 atk_obj = gtk_widget_get_accessible (GTK_WIDGET (toggle_button));
137 if (strcmp (pspec->name, "inconsistent") == 0)
138 atk_object_notify_state_change (atk_obj, ATK_STATE_ENABLED,
139 !gtk_toggle_button_get_inconsistent (toggle_button));
141 GAIL_WIDGET_CLASS (gail_toggle_button_parent_class)->notify_gtk (obj, pspec);