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 "gailbooleancell.h"
24 
25 static void      gail_boolean_cell_class_init          (GailBooleanCellClass *klass);
26 static void      gail_boolean_cell_init                (GailBooleanCell *cell);
27 /* Misc */
28 
29 static gboolean gail_boolean_cell_update_cache         (GailRendererCell     *cell,
30                                                         gboolean             emit_change_signal);
31 
32 gchar *gail_boolean_cell_property_list[] = {
33   "active",
34   "radio",
35   "sensitive",
36   NULL
37 };
38 
G_DEFINE_TYPE(GailBooleanCell,gail_boolean_cell,GAIL_TYPE_RENDERER_CELL)39 G_DEFINE_TYPE (GailBooleanCell, gail_boolean_cell, GAIL_TYPE_RENDERER_CELL)
40 
41 static void
42 gail_boolean_cell_class_init (GailBooleanCellClass *klass)
43 {
44   GailRendererCellClass *renderer_cell_class = GAIL_RENDERER_CELL_CLASS (klass);
45 
46   renderer_cell_class->update_cache = gail_boolean_cell_update_cache;
47   renderer_cell_class->property_list = gail_boolean_cell_property_list;
48 }
49 
50 static void
gail_boolean_cell_init(GailBooleanCell * cell)51 gail_boolean_cell_init (GailBooleanCell *cell)
52 {
53 }
54 
55 AtkObject*
gail_boolean_cell_new(void)56 gail_boolean_cell_new (void)
57 {
58   GObject *object;
59   AtkObject *atk_object;
60   GailRendererCell *cell;
61   GailBooleanCell *boolean_cell;
62 
63   object = g_object_new (GAIL_TYPE_BOOLEAN_CELL, NULL);
64 
65   g_return_val_if_fail (object != NULL, NULL);
66 
67   atk_object = ATK_OBJECT (object);
68   atk_object->role = ATK_ROLE_TABLE_CELL;
69 
70   cell = GAIL_RENDERER_CELL(object);
71   boolean_cell = GAIL_BOOLEAN_CELL(object);
72 
73   cell->renderer = gtk_cell_renderer_toggle_new ();
74   g_object_ref_sink (cell->renderer);
75   boolean_cell->cell_value = FALSE;
76   boolean_cell->cell_sensitive = TRUE;
77   return atk_object;
78 }
79 
80 static gboolean
gail_boolean_cell_update_cache(GailRendererCell * cell,gboolean emit_change_signal)81 gail_boolean_cell_update_cache (GailRendererCell *cell,
82                                 gboolean         emit_change_signal)
83 {
84   GailBooleanCell *boolean_cell = GAIL_BOOLEAN_CELL (cell);
85   gboolean rv = FALSE;
86   gboolean new_boolean;
87   gboolean new_sensitive;
88 
89   g_object_get (G_OBJECT(cell->renderer), "active", &new_boolean,
90                                           "sensitive", &new_sensitive, NULL);
91 
92   if (boolean_cell->cell_value != new_boolean)
93     {
94       rv = TRUE;
95       boolean_cell->cell_value = !(boolean_cell->cell_value);
96 
97       /* Update cell's state */
98 
99     if (new_boolean)
100       gail_cell_add_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal);
101     else
102       gail_cell_remove_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal);
103     }
104 
105   if (boolean_cell->cell_sensitive != new_sensitive)
106     {
107       rv = TRUE;
108       boolean_cell->cell_sensitive = !(boolean_cell->cell_sensitive);
109 
110       /* Update cell's state */
111 
112       if (new_sensitive)
113         gail_cell_add_state (GAIL_CELL (cell), ATK_STATE_SENSITIVE, emit_change_signal);
114       else
115         gail_cell_remove_state (GAIL_CELL (cell), ATK_STATE_SENSITIVE, emit_change_signal);
116     }
117 
118   return rv;
119 }
120