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