]> Pileus Git - ~andy/gtk/blob - modules/other/gail/gailbooleancell.c
553fea76dc65979571a9371c878b4e361d339540
[~andy/gtk] / modules / other / gail / gailbooleancell.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 <gtk/gtk.h>
21 #include "gailbooleancell.h"
22
23 static void      gail_boolean_cell_class_init          (GailBooleanCellClass *klass);
24 static void      gail_boolean_cell_init                (GailBooleanCell *cell);
25 /* Misc */
26
27 static gboolean gail_boolean_cell_update_cache         (GailRendererCell     *cell,
28                                                         gboolean             emit_change_signal);
29
30 gchar *gail_boolean_cell_property_list[] = {
31   "active",
32   "radio",
33   NULL
34 };
35
36 G_DEFINE_TYPE_WITH_CODE (GailBooleanCell, gail_boolean_cell, GAIL_TYPE_RENDERER_CELL,
37                          gail_cell_type_add_action_interface (g_define_type_id))
38
39 static void 
40 gail_boolean_cell_class_init (GailBooleanCellClass *klass)
41 {
42   GailRendererCellClass *renderer_cell_class = GAIL_RENDERER_CELL_CLASS (klass);
43
44   renderer_cell_class->update_cache = gail_boolean_cell_update_cache;
45   renderer_cell_class->property_list = gail_boolean_cell_property_list;
46 }
47
48 static void
49 gail_boolean_cell_init (GailBooleanCell *cell)
50 {
51 }
52
53 AtkObject* 
54 gail_boolean_cell_new (void)
55 {
56   GObject *object;
57   AtkObject *atk_object;
58   GailRendererCell *cell;
59   GailBooleanCell *boolean_cell;
60
61   object = g_object_new (GAIL_TYPE_BOOLEAN_CELL, NULL);
62
63   g_return_val_if_fail (object != NULL, NULL);
64
65   atk_object = ATK_OBJECT (object);
66   atk_object->role = ATK_ROLE_TABLE_CELL;
67
68   cell = GAIL_RENDERER_CELL(object);
69   boolean_cell = GAIL_BOOLEAN_CELL(object);
70
71   cell->renderer = gtk_cell_renderer_toggle_new ();
72   g_object_ref (cell->renderer);
73   gtk_object_sink (GTK_OBJECT (cell->renderer));
74   boolean_cell->cell_value = FALSE;
75   return atk_object;
76 }
77
78 static gboolean
79 gail_boolean_cell_update_cache (GailRendererCell *cell, 
80                                 gboolean         emit_change_signal)
81 {
82   GailBooleanCell *boolean_cell = GAIL_BOOLEAN_CELL (cell);
83   gboolean rv = FALSE;
84   gboolean new_boolean;
85
86   g_object_get (G_OBJECT(cell->renderer), "active", &new_boolean, NULL);
87
88   if (boolean_cell->cell_value != new_boolean)
89     {
90       rv = TRUE;
91       boolean_cell->cell_value = !(boolean_cell->cell_value);
92
93       /* Update cell's state */
94
95     if (new_boolean)
96       gail_cell_add_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal);
97     else
98       gail_cell_remove_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal);
99     }
100
101   return rv;
102 }