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