evolution-3.6.4/widgets/table/gal-a11y-e-cell-popup.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  *		Yang Wu <yang.wu@sun.com>
 18  *
 19  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 20  *
 21  */
 22 
 23 #ifdef HAVE_CONFIG_H
 24 #include <config.h>
 25 #endif
 26 
 27 #include <gdk/gdkkeysyms.h>
 28 #include <gtk/gtk.h>
 29 
 30 #include "a11y/gal-a11y-util.h"
 31 #include "table/e-cell-popup.h"
 32 #include <glib/gi18n.h>
 33 
 34 #include "gal-a11y-e-cell-popup.h"
 35 #include "gal-a11y-e-cell-registry.h"
 36 
 37 static AtkObjectClass *parent_class = NULL;
 38 #define PARENT_TYPE (gal_a11y_e_cell_get_type ())
 39 
 40 static void gal_a11y_e_cell_popup_class_init (GalA11yECellPopupClass *class);
 41 static void popup_cell_action (GalA11yECell *cell);
 42 
 43 /**
 44  * gal_a11y_e_cell_popup_get_type:
 45  * @void:
 46  *
 47  * Registers the &GalA11yECellPopup class if necessary, and returns the type ID
 48  * associated to it.
 49  *
 50  * Return value: The type ID of the &GalA11yECellPopup class.
 51  **/
 52 GType
 53 gal_a11y_e_cell_popup_get_type (void)
 54 {
 55 	static GType type = 0;
 56 
 57 	if (!type) {
 58 		GTypeInfo info = {
 59 			sizeof (GalA11yECellPopupClass),
 60 			(GBaseInitFunc) NULL,
 61 			(GBaseFinalizeFunc) NULL,
 62 			(GClassInitFunc) gal_a11y_e_cell_popup_class_init,
 63 			(GClassFinalizeFunc) NULL,
 64 			NULL, /* class_data */
 65 			sizeof (GalA11yECellPopup),
 66 			0,
 67 			(GInstanceInitFunc) NULL,
 68 			NULL /* value_cell_popup */
 69 		};
 70 
 71 		type = g_type_register_static (PARENT_TYPE, "GalA11yECellPopup", &info, 0);
 72 		gal_a11y_e_cell_type_add_action_interface (type);
 73 	}
 74 
 75 	return type;
 76 }
 77 
 78 static void
 79 gal_a11y_e_cell_popup_class_init (GalA11yECellPopupClass *class)
 80 {
 81 	parent_class = g_type_class_ref (PARENT_TYPE);
 82 }
 83 
 84 AtkObject *
 85 gal_a11y_e_cell_popup_new (ETableItem *item,
 86                            ECellView *cell_view,
 87                            AtkObject *parent,
 88                            gint model_col,
 89                            gint view_col,
 90                            gint row)
 91 {
 92 	AtkObject *a11y;
 93 	GalA11yECell *cell;
 94 	ECellPopup *popupcell;
 95 	ECellView * child_view = NULL;
 96 
 97 	popupcell=  E_CELL_POPUP (cell_view->ecell);
 98 
 99 	if (popupcell && popupcell->popup_cell_view)
100 		child_view = popupcell->popup_cell_view->child_view;
101 
102 	if (child_view && child_view->ecell) {
103 		a11y = gal_a11y_e_cell_registry_get_object (
104 			NULL,
105 			item,
106 			child_view,
107 			parent,
108 			model_col,
109 			view_col,
110 			row);
111 	} else {
112 		a11y = g_object_new (GAL_A11Y_TYPE_E_CELL_POPUP, NULL);
113 		gal_a11y_e_cell_construct (
114 			a11y,
115 			item,
116 			cell_view,
117 			parent,
118 			model_col,
119 			view_col,
120 			row);
121 		}
122 	g_return_val_if_fail (a11y != NULL, NULL);
123 	cell = GAL_A11Y_E_CELL (a11y);
124 	gal_a11y_e_cell_add_action (
125 		cell,
126 		"popup",
127 		/* Translators: description of a "popup" action */
128 		_("popup a child"),
129 		"<Alt>Down",              /* action keybinding */
130 		popup_cell_action);
131 
132 	a11y->role  = ATK_ROLE_TABLE_CELL;
133 	return a11y;
134 }
135 
136 static void
137 popup_cell_action (GalA11yECell *cell)
138 {
139 	gint finished;
140 	GdkEvent event;
141 	GtkLayout *layout;
142 
143 	layout = GTK_LAYOUT (GNOME_CANVAS_ITEM (cell->item)->canvas);
144 
145 	event.key.type = GDK_KEY_PRESS;
146 	event.key.window = gtk_layout_get_bin_window (layout);
147 	event.key.send_event = TRUE;
148 	event.key.time = GDK_CURRENT_TIME;
149 	event.key.state = GDK_MOD1_MASK;
150 	event.key.keyval = GDK_KEY_Down;
151 
152 	g_signal_emit_by_name (cell->item, "event", &event, &finished);
153 }