]> Pileus Git - ~andy/gtk/blob - gtk/a11y/gtkbooleancellaccessible.c
Convert GailRendererCell to GtkRendererCellAccessible
[~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, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */
19
20 #include "config.h"
21
22 #include <gtk/gtk.h>
23 #include "gtkbooleancellaccessible.h"
24
25
26 static gchar *property_list[] = {
27   "active",
28   "radio",
29   "sensitive",
30   NULL
31 };
32
33 G_DEFINE_TYPE (GtkBooleanCellAccessible, _gtk_boolean_cell_accessible, GTK_TYPE_RENDERER_CELL_ACCESSIBLE)
34
35
36 static gboolean
37 gtk_boolean_cell_accessible_update_cache (GtkRendererCellAccessible *cell,
38                                           gboolean                   emit_change_signal)
39 {
40   GtkBooleanCellAccessible *boolean_cell = GTK_BOOLEAN_CELL_ACCESSIBLE (cell);
41   gboolean rv = FALSE;
42   gboolean active;
43   gboolean sensitive;
44
45   g_object_get (G_OBJECT (cell->renderer),
46                 "active", &active,
47                 "sensitive", &sensitive,
48                 NULL);
49
50   if (boolean_cell->cell_value != active)
51     {
52       rv = TRUE;
53       boolean_cell->cell_value = !boolean_cell->cell_value;
54
55       if (active)
56         _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_CHECKED, emit_change_signal);
57       else
58         _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_CHECKED, emit_change_signal);
59     }
60
61   if (boolean_cell->cell_sensitive != sensitive)
62     {
63       rv = TRUE;
64       boolean_cell->cell_sensitive = !boolean_cell->cell_sensitive;
65
66       if (sensitive)
67         _gtk_cell_accessible_add_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_SENSITIVE, emit_change_signal);
68       else
69         _gtk_cell_accessible_remove_state (GTK_CELL_ACCESSIBLE (cell), ATK_STATE_SENSITIVE, emit_change_signal);
70     }
71
72   return rv;
73 }
74
75 static void
76 _gtk_boolean_cell_accessible_class_init (GtkBooleanCellAccessibleClass *klass)
77 {
78   GtkRendererCellAccessibleClass *renderer_cell_class = GTK_RENDERER_CELL_ACCESSIBLE_CLASS (klass);
79
80   renderer_cell_class->update_cache = gtk_boolean_cell_accessible_update_cache;
81   renderer_cell_class->property_list = property_list;
82 }
83
84 static void
85 _gtk_boolean_cell_accessible_init (GtkBooleanCellAccessible *cell)
86 {
87 }
88
89 AtkObject *
90 _gtk_boolean_cell_accessible_new (void)
91 {
92   GObject *object;
93   AtkObject *atk_object;
94   GtkRendererCellAccessible *cell;
95   GtkBooleanCellAccessible *boolean_cell;
96
97   object = g_object_new (GTK_TYPE_BOOLEAN_CELL_ACCESSIBLE, NULL);
98
99   atk_object = ATK_OBJECT (object);
100   atk_object->role = ATK_ROLE_TABLE_CELL;
101
102   cell = GTK_RENDERER_CELL_ACCESSIBLE (object);
103   cell->renderer = gtk_cell_renderer_toggle_new ();
104   g_object_ref_sink (cell->renderer);
105
106   boolean_cell = GTK_BOOLEAN_CELL_ACCESSIBLE (object);
107   boolean_cell->cell_value = FALSE;
108   boolean_cell->cell_sensitive = TRUE;
109
110   return atk_object;
111 }