evolution-3.6.4/widgets/table/gal-a11y-e-cell-toggle.c

No issues found

  1 /*
  2  * This program is free software; you can redistribute it and/or
  3  * modify it under the terms of the GNU Lesser General Public
  4  * License as published by the Free Software Foundation; either
  5  * version 2 of the License, or (at your option) version 3.
  6  *
  7  * This program is distributed in the hope that it will be useful,
  8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 10  * Lesser General Public License for more details.
 11  *
 12  * You should have received a copy of the GNU Lesser General Public
 13  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 14  *
 15  *
 16  * Authors:
 17  *
 18  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 19  *
 20  */
 21 
 22 #ifdef HAVE_CONFIG_H
 23 #include <config.h>
 24 #endif
 25 
 26 #include <gtk/gtk.h>
 27 
 28 #include "table/e-cell-toggle.h"
 29 #include "table/e-table-model.h"
 30 #include <glib/gi18n.h>
 31 
 32 #include "gal-a11y-e-cell-toggle.h"
 33 
 34 #define PARENT_TYPE  (gal_a11y_e_cell_get_type ())
 35 static GObjectClass *parent_class;
 36 
 37 static void gal_a11y_e_cell_toggle_class_init (GalA11yECellToggleClass *class);
 38 
 39 static void
 40 gal_a11y_e_cell_toggle_dispose (GObject *object)
 41 {
 42 	GalA11yECellToggle *a11y = GAL_A11Y_E_CELL_TOGGLE (object);
 43 
 44 	ETableModel *e_table_model = GAL_A11Y_E_CELL (a11y)->item->table_model;
 45 
 46 	if (e_table_model && a11y->model_id > 0) {
 47 		g_signal_handler_disconnect (e_table_model, a11y->model_id);
 48 		a11y->model_id = 0;
 49 	}
 50 
 51 	if (parent_class->dispose)
 52 		parent_class->dispose (object);
 53 }
 54 
 55 GType
 56 gal_a11y_e_cell_toggle_get_type (void)
 57 {
 58   static GType type = 0;
 59 
 60   if (!type)
 61     {
 62       static const GTypeInfo tinfo =
 63       {
 64 	sizeof (GalA11yECellToggleClass),
 65 	(GBaseInitFunc) NULL, /* base init */
 66 	(GBaseFinalizeFunc) NULL, /* base finalize */
 67 	(GClassInitFunc) gal_a11y_e_cell_toggle_class_init, /* class init */
 68 	(GClassFinalizeFunc) NULL, /* class finalize */
 69 	NULL, /* class data */
 70 	sizeof (GalA11yECellToggle), /* instance size */
 71 	0, /* nb preallocs */
 72 	NULL, /* instance init */
 73 	NULL /* value table */
 74       };
 75 
 76       type = g_type_register_static (GAL_A11Y_TYPE_E_CELL,
 77 				     "GalA11yECellToggle", &tinfo, 0);
 78       gal_a11y_e_cell_type_add_action_interface (type);
 79 
 80     }
 81   return type;
 82 }
 83 
 84 static void
 85 gal_a11y_e_cell_toggle_class_init (GalA11yECellToggleClass *class)
 86 {
 87 	GObjectClass *object_class = G_OBJECT_CLASS (class);
 88 
 89 	object_class->dispose      = gal_a11y_e_cell_toggle_dispose;
 90 	parent_class               = g_type_class_ref (PARENT_TYPE);
 91 }
 92 
 93 static void
 94 toggle_cell_action (GalA11yECell *cell)
 95 {
 96 	gint finished;
 97 	GtkLayout *layout;
 98 	GdkEventButton event;
 99 	gint x, y, width, height;
100 	gint row, col;
101 
102 	row = cell->row;
103 	col = cell->view_col;
104 
105 	layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (cell->item)->canvas);
106 
107 	e_table_item_get_cell_geometry (
108 		cell->item, &row, &col, &x, &y, &width, &height);
109 
110 	event.x = x + width / 2 + (gint)(GNOME_CANVAS_ITEM (cell->item)->x1);
111 	event.y = y + height / 2 + (gint)(GNOME_CANVAS_ITEM (cell->item)->y1);
112 
113 	event.type = GDK_BUTTON_PRESS;
114 	event.window = gtk_layout_get_bin_window (layout);
115 	event.button = 1;
116 	event.send_event = TRUE;
117 	event.time = GDK_CURRENT_TIME;
118 	event.axes = NULL;
119 
120 	g_signal_emit_by_name (cell->item, "event", &event, &finished);
121 }
122 
123 static void
124 model_change_cb (ETableModel *etm,
125                  gint col,
126                  gint row,
127                  GalA11yECell *cell)
128 {
129 	gint value;
130 
131 	if (col == cell->model_col && row == cell->row) {
132 
133 		value = GPOINTER_TO_INT (
134 			e_table_model_value_at (cell->cell_view->e_table_model,
135 						cell->model_col, cell->row));
136 		/* Cheat gnopernicus, or it will ignore the state change signal  */
137 		atk_focus_tracker_notify (ATK_OBJECT (cell));
138 
139 		if (value)
140 			gal_a11y_e_cell_add_state (cell, ATK_STATE_CHECKED, TRUE);
141 		else
142 			gal_a11y_e_cell_remove_state (cell, ATK_STATE_CHECKED, TRUE);
143 	}
144 }
145 
146 AtkObject *
147 gal_a11y_e_cell_toggle_new (ETableItem *item,
148                             ECellView *cell_view,
149                             AtkObject *parent,
150                             gint model_col,
151                             gint view_col,
152                             gint row)
153 {
154 	AtkObject *a11y;
155 	GalA11yECell *cell;
156 	GalA11yECellToggle *toggle_cell;
157 	gint value;
158 
159 	a11y = ATK_OBJECT (g_object_new (GAL_A11Y_TYPE_E_CELL_TOGGLE, NULL));
160 
161 	g_return_val_if_fail (a11y != NULL, NULL);
162 
163 	cell = GAL_A11Y_E_CELL (a11y);
164 	toggle_cell = GAL_A11Y_E_CELL_TOGGLE (a11y);
165 	a11y->role  = ATK_ROLE_TABLE_CELL;
166 
167 	gal_a11y_e_cell_construct (
168 		a11y,
169 		item,
170 		cell_view,
171 		parent,
172 		model_col,
173 		view_col,
174 		row);
175 
176 	gal_a11y_e_cell_add_action (
177 		cell,
178 		"toggle",
179 		/* Translators: description of a "toggle" action */
180 		_("toggle the cell"),
181 		NULL,              /* action keybinding */
182 		toggle_cell_action);
183 
184 	toggle_cell->model_id = g_signal_connect (
185 		item->table_model, "model_cell_changed",
186 		(GCallback) model_change_cb, a11y);
187 
188 	value = GPOINTER_TO_INT (
189 			e_table_model_value_at (
190 				cell->cell_view->e_table_model,
191 				cell->model_col, cell->row));
192 	if (value)
193 		gal_a11y_e_cell_add_state (cell, ATK_STATE_CHECKED, FALSE);
194 	else
195 		gal_a11y_e_cell_remove_state (cell, ATK_STATE_CHECKED, FALSE);
196 
197 	return a11y;
198 }