]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkbooleancellaccessible.c
GtkRadioButtonAccessible: add a private struct
[~andy/gtk] / gtk / a11y / gtkbooleancellaccessible.c
1 /* GAIL - The GNOME Accessibility Enabling Library
2  * Copyright 2001 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, see <http://www.gnu.org/licenses/>.
16  */
17
18 #include "config.h"
19
20 #include <gtk/gtk.h>
21 #include "gtkbooleancellaccessible.h"
22
23 struct _GtkBooleanCellAccessiblePrivate
24 {
25   gboolean cell_value;
26   gboolean cell_sensitive;
27 };
28
29 static AtkActionIface *parent_action_iface;
30
31 static gint
32 gtk_boolean_cell_accessible_get_n_actions (AtkAction *action)
33 {
34   return parent_action_iface->get_n_actions (action) + 1;
35 }
36
37 static const gchar *
38 gtk_boolean_cell_accessible_get_description (AtkAction *action,
39                                              gint       i)
40 {
41   if (i == 0)
42     return "toggles the cell";
43
44   return parent_action_iface->get_description (action, i - 1);
45 }
46
47 static const gchar *
48 gtk_boolean_cell_accessible_action_get_name (AtkAction *action,
49                                              gint       i)
50 {
51   if (i == 0)
52     return "toggle";
53
54   return parent_action_iface->get_description (action, i - 1);
55 }
56
57 static gboolean
58 gtk_boolean_cell_accessible_do_action (AtkAction *action,
59                                        gint       i)
60 {
61   if (i == 0)
62     return parent_action_iface->do_action (action, 2);
63   else
64     return parent_action_iface->do_action (action, i - 1);
65 }
66
67 static void
68 gtk_boolean_cell_accessible_action_interface_init (AtkActionIface *iface)
69 {
70   parent_action_iface = g_type_interface_peek_parent (iface);
71
72   iface->do_action = gtk_boolean_cell_accessible_do_action;
73   iface->get_n_actions = gtk_boolean_cell_accessible_get_n_actions;
74   iface->get_description = gtk_boolean_cell_accessible_get_description;
75   iface->get_name = gtk_boolean_cell_accessible_action_get_name;
76 }
77
78
79 G_DEFINE_TYPE_EXTENDED (GtkBooleanCellAccessible, _gtk_boolean_cell_accessible, GTK_TYPE_RENDERER_CELL_ACCESSIBLE, 0,
80                         G_IMPLEMENT_INTERFACE (ATK_TYPE_ACTION, gtk_boolean_cell_accessible_action_interface_init))
81
82
83 static AtkStateSet *
84 gtk_boolean_cell_accessible_ref_state_set (AtkObject *accessible)
85 {
86   GtkBooleanCellAccessible *cell = GTK_BOOLEAN_CELL_ACCESSIBLE (accessible);
87   AtkStateSet *state_set;
88
89   state_set = ATK_OBJECT_CLASS (_gtk_boolean_cell_accessible_parent_class)->ref_state_set (accessible);
90
91   if (cell->priv->cell_value)
92     atk_state_set_add_state (state_set, ATK_STATE_CHECKED);
93
94   if (cell->priv->cell_sensitive)
95     atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE);
96   else
97     atk_state_set_remove_state (state_set, ATK_STATE_SENSITIVE);
98
99   return state_set;
100 }
101
102 static void
103 gtk_boolean_cell_accessible_update_cache (GtkCellAccessible *cell)
104 {
105   GtkBooleanCellAccessible *boolean_cell = GTK_BOOLEAN_CELL_ACCESSIBLE (cell);
106   gboolean active;
107   gboolean sensitive;
108
109   g_object_get (G_OBJECT (GTK_RENDERER_CELL_ACCESSIBLE (cell)->renderer),
110                 "active", &active,
111                 "sensitive", &sensitive,
112                 NULL);
113
114   if (boolean_cell->priv->cell_value != active)
115     {
116       boolean_cell->priv->cell_value = !boolean_cell->priv->cell_value;
117
118       atk_object_notify_state_change (ATK_OBJECT (cell), ATK_STATE_CHECKED, active);
119     }
120
121   if (boolean_cell->priv->cell_sensitive != sensitive)
122     {
123       boolean_cell->priv->cell_sensitive = !boolean_cell->priv->cell_sensitive;
124
125       atk_object_notify_state_change (ATK_OBJECT (cell), ATK_STATE_CHECKED, sensitive);
126     }
127 }
128
129 static void
130 _gtk_boolean_cell_accessible_class_init (GtkBooleanCellAccessibleClass *klass)
131 {
132   GtkCellAccessibleClass *cell_class = GTK_CELL_ACCESSIBLE_CLASS (klass);
133   AtkObjectClass *atkobject_class = ATK_OBJECT_CLASS (klass);
134
135   atkobject_class->ref_state_set = gtk_boolean_cell_accessible_ref_state_set;
136
137   cell_class->update_cache = gtk_boolean_cell_accessible_update_cache;
138
139   g_type_class_add_private (klass, sizeof (GtkBooleanCellAccessiblePrivate));
140 }
141
142 static void
143 _gtk_boolean_cell_accessible_init (GtkBooleanCellAccessible *cell)
144 {
145   cell->priv =  G_TYPE_INSTANCE_GET_PRIVATE (cell,
146                                              GTK_TYPE_BOOLEAN_CELL_ACCESSIBLE,
147                                              GtkBooleanCellAccessiblePrivate);
148 }
149