evolution-3.6.4/calendar/gui/ea-calendar.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  *		Bolian Yin <bolian.yin@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 <text/e-text.h>
 28 #include <libgnomecanvas/libgnomecanvas.h>
 29 #include "ea-calendar-helpers.h"
 30 #include "a11y/ea-factory.h"
 31 #include "ea-calendar.h"
 32 
 33 #include "calendar/gui/ea-cal-view.h"
 34 #include "calendar/gui/ea-cal-view-event.h"
 35 #include "calendar/gui/ea-day-view.h"
 36 #include "calendar/gui/ea-day-view-main-item.h"
 37 #include "calendar/gui/ea-week-view.h"
 38 #include "calendar/gui/ea-week-view-main-item.h"
 39 #include "calendar/gui/ea-gnome-calendar.h"
 40 
 41 EA_FACTORY (EA_TYPE_CAL_VIEW, ea_cal_view, ea_cal_view_new)
 42 EA_FACTORY (EA_TYPE_DAY_VIEW, ea_day_view, ea_day_view_new)
 43 EA_FACTORY_GOBJECT (
 44 	EA_TYPE_DAY_VIEW_MAIN_ITEM,
 45 	ea_day_view_main_item, ea_day_view_main_item_new)
 46 EA_FACTORY (EA_TYPE_WEEK_VIEW, ea_week_view, ea_week_view_new)
 47 EA_FACTORY_GOBJECT (
 48 	EA_TYPE_WEEK_VIEW_MAIN_ITEM,
 49 	ea_week_view_main_item, ea_week_view_main_item_new)
 50 EA_FACTORY (EA_TYPE_GNOME_CALENDAR, ea_gnome_calendar, ea_gnome_calendar_new)
 51 
 52 static gboolean ea_calendar_focus_watcher (GSignalInvocationHint *ihint,
 53                                            guint n_param_values,
 54                                            const GValue *param_values,
 55                                            gpointer data);
 56 
 57 static gpointer e_text_type, pixbuf_type, e_day_view_type, e_week_view_type;
 58 static gpointer e_day_view_main_item_type, e_week_view_main_item_type;
 59 
 60 void
 61 gnome_calendar_a11y_init (void)
 62 {
 63 	/* we only add focus watcher when accessibility is enabled
 64 	 */
 65 	if (atk_get_root ()) {
 66 		GtkWidget *gnome_canvas;
 67 
 68 		/* first initialize ATK support in gnome-canvas and also gail-canvas */
 69 		gnome_canvas = gnome_canvas_new ();
 70 		gtk_widget_destroy (gnome_canvas);
 71 
 72 		EA_SET_FACTORY (gnome_calendar_get_type (), ea_gnome_calendar);
 73 
 74 		/* force loading some types */
 75 		e_text_type = g_type_class_ref (E_TYPE_TEXT);
 76 		pixbuf_type = g_type_class_ref (GNOME_TYPE_CANVAS_PIXBUF);
 77 		e_day_view_type = g_type_class_ref (e_day_view_get_type ());
 78 		e_week_view_type = g_type_class_ref (E_TYPE_WEEK_VIEW);
 79 		e_day_view_main_item_type = g_type_class_ref (
 80 			e_day_view_main_item_get_type ());
 81 		e_week_view_main_item_type = g_type_class_ref (
 82 			e_week_view_main_item_get_type ());
 83 
 84 		g_signal_add_emission_hook (
 85 			g_signal_lookup ("event", E_TYPE_TEXT),
 86 			0, ea_calendar_focus_watcher,
 87 			NULL, (GDestroyNotify) NULL);
 88 		g_signal_add_emission_hook (
 89 			g_signal_lookup ("event", GNOME_TYPE_CANVAS_PIXBUF),
 90 			0, ea_calendar_focus_watcher,
 91 			NULL, (GDestroyNotify) NULL);
 92 		g_signal_add_emission_hook (
 93 			g_signal_lookup ("event-after", E_TYPE_DAY_VIEW),
 94 			0, ea_calendar_focus_watcher,
 95 			NULL, (GDestroyNotify) NULL);
 96 		g_signal_add_emission_hook (
 97 			g_signal_lookup ("event", E_TYPE_DAY_VIEW_MAIN_ITEM),
 98 			0, ea_calendar_focus_watcher,
 99 			NULL, (GDestroyNotify) NULL);
100 		g_signal_add_emission_hook (
101 			g_signal_lookup ("event-after", E_TYPE_WEEK_VIEW),
102 			0, ea_calendar_focus_watcher,
103 			NULL, (GDestroyNotify) NULL);
104 		g_signal_add_emission_hook (
105 			g_signal_lookup ("event", E_TYPE_WEEK_VIEW_MAIN_ITEM),
106 			0, ea_calendar_focus_watcher,
107 			NULL, (GDestroyNotify) NULL);
108 	}
109 }
110 
111 void
112 e_cal_view_a11y_init (void)
113 {
114 	EA_SET_FACTORY (e_calendar_view_get_type (), ea_cal_view);
115 }
116 
117 void
118 e_day_view_a11y_init (void)
119 {
120 	EA_SET_FACTORY (e_day_view_get_type (), ea_day_view);
121 }
122 
123 void
124 e_day_view_main_item_a11y_init (void)
125 {
126 	EA_SET_FACTORY (e_day_view_main_item_get_type (), ea_day_view_main_item);
127 }
128 
129 void
130 e_week_view_a11y_init (void)
131 {
132 	EA_SET_FACTORY (E_TYPE_WEEK_VIEW, ea_week_view);
133 }
134 
135 void
136 e_week_view_main_item_a11y_init (void)
137 {
138 	EA_SET_FACTORY (e_week_view_main_item_get_type (), ea_week_view_main_item);
139 }
140 
141 static gboolean
142 ea_calendar_focus_watcher (GSignalInvocationHint *ihint,
143                            guint n_param_values,
144                            const GValue *param_values,
145                            gpointer data)
146 {
147 	GObject *object;
148 	GdkEvent *event;
149 	AtkObject *ea_event = NULL;
150 
151 	object = g_value_get_object (param_values + 0);
152 	event = g_value_get_boxed (param_values + 1);
153 
154 	if ((E_IS_TEXT (object)) || (GNOME_IS_CANVAS_PIXBUF (object))) {
155 		/* "event" signal on canvas item
156 		 */
157 		GnomeCanvasItem *canvas_item;
158 
159 		canvas_item = GNOME_CANVAS_ITEM (object);
160 		if (event->type == GDK_FOCUS_CHANGE) {
161 			if (event->focus_change.in) {
162 				ea_event =
163 					ea_calendar_helpers_get_accessible_for (canvas_item);
164 				if (!ea_event)
165 					/* not canvas item we want */
166 					return TRUE;
167 
168 			}
169 			atk_focus_tracker_notify (ea_event);
170 		}
171 	}
172 	else if (E_IS_DAY_VIEW (object)) {
173 		EDayView *day_view = E_DAY_VIEW (object);
174 		if (event->type == GDK_FOCUS_CHANGE) {
175 			if (event->focus_change.in) {
176 				/* give main item chance to emit focus */
177 				gnome_canvas_item_grab_focus (day_view->main_canvas_item);
178 			}
179 		}
180 	}
181 	else if (E_IS_DAY_VIEW_MAIN_ITEM (object)) {
182 		if (event->type == GDK_FOCUS_CHANGE) {
183 			if (event->focus_change.in) {
184 				/* we should emit focus on main item */
185 				ea_event = atk_gobject_accessible_for_object (object);
186 			}
187 			else
188 				/* focus out */
189 				ea_event = NULL;
190 #ifdef ACC_DEBUG
191 			printf ("EvoAcc: focus notify on day main item %p\n", (gpointer) object);
192 #endif
193 			atk_focus_tracker_notify (ea_event);
194 		}
195 	} else if (E_IS_WEEK_VIEW (object)) {
196 		EWeekView *week_view = E_WEEK_VIEW (object);
197 		if (event->type == GDK_FOCUS_CHANGE) {
198 			if (event->focus_change.in) {
199 				/* give main item chance to emit focus */
200 				gnome_canvas_item_grab_focus (week_view->main_canvas_item);
201 			}
202 		}
203 	}
204 	else if (E_IS_WEEK_VIEW_MAIN_ITEM (object)) {
205 		if (event->type == GDK_FOCUS_CHANGE) {
206 			if (event->focus_change.in) {
207 				/* we should emit focus on main item */
208 				ea_event = atk_gobject_accessible_for_object (object);
209 			}
210 			else
211 				/* focus out */
212 				ea_event = NULL;
213 			atk_focus_tracker_notify (ea_event);
214 		}
215 	}
216 	return TRUE;
217 }