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 | |
---|
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 | GType |
---|
37 | gail_boolean_cell_get_type (void) |
---|
38 | { |
---|
39 | static GType type = 0; |
---|
40 | |
---|
41 | if (!type) |
---|
42 | { |
---|
43 | static const GTypeInfo tinfo = |
---|
44 | { |
---|
45 | sizeof (GailBooleanCellClass), |
---|
46 | (GBaseInitFunc) NULL, /* base init */ |
---|
47 | (GBaseFinalizeFunc) NULL, /* base finalize */ |
---|
48 | (GClassInitFunc) gail_boolean_cell_class_init, /* class init */ |
---|
49 | (GClassFinalizeFunc) NULL, /* class finalize */ |
---|
50 | NULL, /* class data */ |
---|
51 | sizeof (GailBooleanCell), /* instance size */ |
---|
52 | 0, /* nb preallocs */ |
---|
53 | NULL, /* instance init */ |
---|
54 | NULL /* value table */ |
---|
55 | }; |
---|
56 | |
---|
57 | type = g_type_register_static (GAIL_TYPE_RENDERER_CELL, |
---|
58 | "GailBooleanCell", &tinfo, 0); |
---|
59 | gail_cell_type_add_action_interface (type); |
---|
60 | } |
---|
61 | return type; |
---|
62 | } |
---|
63 | |
---|
64 | static void |
---|
65 | gail_boolean_cell_class_init (GailBooleanCellClass *klass) |
---|
66 | { |
---|
67 | GailRendererCellClass *renderer_cell_class = GAIL_RENDERER_CELL_CLASS (klass); |
---|
68 | |
---|
69 | renderer_cell_class->update_cache = gail_boolean_cell_update_cache; |
---|
70 | renderer_cell_class->property_list = gail_boolean_cell_property_list; |
---|
71 | } |
---|
72 | |
---|
73 | AtkObject* |
---|
74 | gail_boolean_cell_new (void) |
---|
75 | { |
---|
76 | GObject *object; |
---|
77 | AtkObject *atk_object; |
---|
78 | GailRendererCell *cell; |
---|
79 | GailBooleanCell *boolean_cell; |
---|
80 | |
---|
81 | object = g_object_new (GAIL_TYPE_BOOLEAN_CELL, NULL); |
---|
82 | |
---|
83 | g_return_val_if_fail (object != NULL, NULL); |
---|
84 | |
---|
85 | atk_object = ATK_OBJECT (object); |
---|
86 | atk_object->role = ATK_ROLE_TABLE_CELL; |
---|
87 | |
---|
88 | cell = GAIL_RENDERER_CELL(object); |
---|
89 | boolean_cell = GAIL_BOOLEAN_CELL(object); |
---|
90 | |
---|
91 | cell->renderer = gtk_cell_renderer_toggle_new (); |
---|
92 | g_object_ref (cell->renderer); |
---|
93 | gtk_object_sink (GTK_OBJECT (cell->renderer)); |
---|
94 | boolean_cell->cell_value = FALSE; |
---|
95 | return atk_object; |
---|
96 | } |
---|
97 | |
---|
98 | static gboolean |
---|
99 | gail_boolean_cell_update_cache (GailRendererCell *cell, |
---|
100 | gboolean emit_change_signal) |
---|
101 | { |
---|
102 | GailBooleanCell *boolean_cell = GAIL_BOOLEAN_CELL (cell); |
---|
103 | gboolean rv = FALSE; |
---|
104 | GValue new_value = {0, }; |
---|
105 | gboolean new_boolean; |
---|
106 | |
---|
107 | g_value_init (&new_value, G_TYPE_BOOLEAN); |
---|
108 | g_object_get_property (G_OBJECT(cell->renderer), "active", &new_value); |
---|
109 | new_boolean = g_value_get_boolean (&new_value); |
---|
110 | |
---|
111 | if (boolean_cell->cell_value != new_boolean) |
---|
112 | { |
---|
113 | rv = TRUE; |
---|
114 | boolean_cell->cell_value = !(boolean_cell->cell_value); |
---|
115 | |
---|
116 | /* Update cell's state */ |
---|
117 | |
---|
118 | if (new_boolean) |
---|
119 | gail_cell_add_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal); |
---|
120 | else |
---|
121 | gail_cell_remove_state (GAIL_CELL (cell), ATK_STATE_CHECKED, emit_change_signal); |
---|
122 | } |
---|
123 | |
---|
124 | return rv; |
---|
125 | } |
---|