evolution-3.6.4/calendar/gui/ea-week-view-cell.c

No issues found

  1 /*
  2  *
  3  * This program is free software; you can redistribute it and/or
  4  * modify it under the terms of the GNU Lesser General Public
  5  * License as published by the Free Software Foundation; either
  6  * version 2 of the License, or (at your option) version 3.
  7  *
  8  * This program is distributed in the hope that it will be useful,
  9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 11  * Lesser General Public License for more details.
 12  *
 13  * You should have received a copy of the GNU Lesser General Public
 14  * License along with the program; if not, see <http://www.gnu.org/licenses/>
 15  *
 16  *
 17  * Authors:
 18  *		Bolian Yin <bolian.yin@sun.com>
 19  *		Yang Wu <Yang.Wu@sun.com>
 20  *
 21  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
 22  *
 23  */
 24 
 25 #ifdef HAVE_CONFIG_H
 26 #include <config.h>
 27 #endif
 28 
 29 #include "ea-week-view-cell.h"
 30 #include "ea-week-view-main-item.h"
 31 #include "a11y/ea-factory.h"
 32 
 33 /* EWeekViewCell */
 34 
 35 static void e_week_view_cell_class_init (EWeekViewCellClass *class);
 36 
 37 EA_FACTORY_GOBJECT (EA_TYPE_WEEK_VIEW_CELL, ea_week_view_cell, ea_week_view_cell_new)
 38 
 39 GType
 40 e_week_view_cell_get_type (void)
 41 {
 42 	static GType type = 0;
 43 
 44 	if (!type) {
 45 		static GTypeInfo tinfo = {
 46 			sizeof (EWeekViewCellClass),
 47 			(GBaseInitFunc) NULL, /* base init */
 48 			(GBaseFinalizeFunc) NULL, /* base finalize */
 49 			(GClassInitFunc) e_week_view_cell_class_init, /* class init */
 50 			(GClassFinalizeFunc) NULL, /* class finalize */
 51 			NULL, /* class data */
 52 			sizeof (EWeekViewCell), /* instance size */
 53 			0, /* nb preallocs */
 54 			(GInstanceInitFunc) NULL, /* instance init */
 55 			NULL /* value table */
 56 		};
 57 
 58 		type = g_type_register_static (
 59 			G_TYPE_OBJECT,
 60 			"EWeekViewCell", &tinfo, 0);
 61 	}
 62 
 63 	return type;
 64 }
 65 
 66 static void
 67 e_week_view_cell_class_init (EWeekViewCellClass *class)
 68 {
 69     EA_SET_FACTORY (e_week_view_cell_get_type (), ea_week_view_cell);
 70 }
 71 
 72 EWeekViewCell *
 73 e_week_view_cell_new (EWeekView *week_view,
 74                       gint row,
 75                       gint column)
 76 {
 77 	GObject *object;
 78 	EWeekViewCell *cell;
 79 
 80 	g_return_val_if_fail (E_IS_WEEK_VIEW (week_view), NULL);
 81 
 82 	object = g_object_new (E_TYPE_WEEK_VIEW_CELL, NULL);
 83 	cell = E_WEEK_VIEW_CELL (object);
 84 	cell->week_view = week_view;
 85 	cell->row = row;
 86 	cell->column = column;
 87 
 88 #ifdef ACC_DEBUG
 89 	printf ("EvoAcc: e_week_view_cell created %p\n", (gpointer) cell);
 90 #endif
 91 
 92 	return cell;
 93 }
 94 
 95 /* EaWeekViewCell */
 96 
 97 static void ea_week_view_cell_class_init (EaWeekViewCellClass *klass);
 98 
 99 static const gchar * ea_week_view_cell_get_name (AtkObject *accessible);
100 static const gchar * ea_week_view_cell_get_description (AtkObject *accessible);
101 static AtkStateSet * ea_week_view_cell_ref_state_set (AtkObject *obj);
102 static AtkObject * ea_week_view_cell_get_parent (AtkObject *accessible);
103 static gint ea_week_view_cell_get_index_in_parent (AtkObject *accessible);
104 
105 /* component interface */
106 static void atk_component_interface_init (AtkComponentIface *iface);
107 static void component_interface_get_extents (AtkComponent *component,
108 					     gint *x, gint *y,
109 					     gint *width, gint *height,
110 					     AtkCoordType coord_type);
111 static gboolean component_interface_grab_focus (AtkComponent *component);
112 
113 static gpointer parent_class = NULL;
114 
115 #ifdef ACC_DEBUG
116 static gint n_ea_week_view_cell_created = 0, n_ea_week_view_cell_destroyed = 0;
117 static void ea_week_view_cell_finalize (GObject *object);
118 #endif
119 
120 GType
121 ea_week_view_cell_get_type (void)
122 {
123 	static GType type = 0;
124 
125 	if (!type) {
126 		static GTypeInfo tinfo = {
127 			sizeof (EaWeekViewCellClass),
128 			(GBaseInitFunc) NULL, /* base init */
129 			(GBaseFinalizeFunc) NULL, /* base finalize */
130 			(GClassInitFunc) ea_week_view_cell_class_init, /* class init */
131 			(GClassFinalizeFunc) NULL, /* class finalize */
132 			NULL, /* class data */
133 			sizeof (EaWeekViewCell), /* instance size */
134 			0, /* nb preallocs */
135 			(GInstanceInitFunc) NULL, /* instance init */
136 			NULL /* value table */
137 		};
138 
139 		static const GInterfaceInfo atk_component_info = {
140 			(GInterfaceInitFunc) atk_component_interface_init,
141 			(GInterfaceFinalizeFunc) NULL,
142 			NULL
143 		};
144 		type = g_type_register_static (
145 			ATK_TYPE_GOBJECT_ACCESSIBLE,
146 			"EaWeekViewCell", &tinfo, 0);
147 		g_type_add_interface_static (
148 			type, ATK_TYPE_COMPONENT,
149 			&atk_component_info);
150 
151 	}
152 
153 	return type;
154 }
155 
156 static void
157 ea_week_view_cell_class_init (EaWeekViewCellClass *klass)
158 {
159 	AtkObjectClass *class = ATK_OBJECT_CLASS (klass);
160 
161 #ifdef ACC_DEBUG
162 	GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
163 	gobject_class->finalize = ea_week_view_cell_finalize;
164 #endif
165 
166 	parent_class = g_type_class_peek_parent (klass);
167 
168 	class->get_name = ea_week_view_cell_get_name;
169 	class->get_description = ea_week_view_cell_get_description;
170 	class->ref_state_set = ea_week_view_cell_ref_state_set;
171 
172 	class->get_parent = ea_week_view_cell_get_parent;
173 	class->get_index_in_parent = ea_week_view_cell_get_index_in_parent;
174 
175 }
176 
177 AtkObject *
178 ea_week_view_cell_new (GObject *obj)
179 {
180 	gpointer object;
181 	AtkObject *atk_object;
182 
183 	g_return_val_if_fail (E_IS_WEEK_VIEW_CELL (obj), NULL);
184 	object = g_object_new (EA_TYPE_WEEK_VIEW_CELL, NULL);
185 	atk_object = ATK_OBJECT (object);
186 	atk_object_initialize (atk_object, obj);
187 	atk_object->role = ATK_ROLE_UNKNOWN;
188 
189 #ifdef ACC_DEBUG
190 	++n_ea_week_view_cell_created;
191 	printf (
192 		"ACC_DEBUG: n_ea_week_view_cell_created = %d\n",
193 		n_ea_week_view_cell_created);
194 #endif
195 	return atk_object;
196 }
197 
198 #ifdef ACC_DEBUG
199 static void ea_week_view_cell_finalize (GObject *object)
200 {
201 	G_OBJECT_CLASS (parent_class)->finalize (object);
202 
203 	++n_ea_week_view_cell_destroyed;
204 	printf (
205 		"ACC_DEBUG: n_ea_week_view_cell_destroyed = %d\n",
206 		n_ea_week_view_cell_destroyed);
207 }
208 #endif
209 
210 static const gchar *
211 ea_week_view_cell_get_name (AtkObject *accessible)
212 {
213 	AtkGObjectAccessible *atk_gobj;
214 	GObject *g_obj;
215 	EWeekViewCell *cell;
216 
217 	g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL);
218 
219 	if (!accessible->name) {
220 		AtkObject *ea_main_item;
221 		GnomeCanvasItem *main_item;
222 		gchar *new_name;
223 		const gchar *row_label, *column_label;
224 		gint new_column, new_row;
225 		gint start_day;
226 
227 		atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
228 		g_obj = atk_gobject_accessible_get_object (atk_gobj);
229 		if (!g_obj)
230 			return NULL;
231 
232 		cell = E_WEEK_VIEW_CELL (g_obj);
233 		main_item = cell->week_view->main_canvas_item;
234 		ea_main_item = atk_gobject_accessible_for_object (G_OBJECT (main_item));
235 
236 		start_day = cell->week_view->display_start_day;
237 		if (cell->column + start_day >= 7) {
238 			new_column = cell->column + start_day - 7;
239 			new_row = cell->row + 1;
240 		} else {
241 			new_column = cell->column + start_day;
242 			new_row = cell->row;
243 		}
244 
245 		column_label = atk_table_get_column_description (
246 			ATK_TABLE (ea_main_item),
247 			new_column);
248 		row_label = atk_table_get_row_description (
249 			ATK_TABLE (ea_main_item),
250 			new_row);
251 		new_name = g_strconcat (column_label, " ", row_label, NULL);
252 		ATK_OBJECT_CLASS (parent_class)->set_name (accessible, new_name);
253 		g_free (new_name);
254 	}
255 	return accessible->name;
256 }
257 
258 static const gchar *
259 ea_week_view_cell_get_description (AtkObject *accessible)
260 {
261 	return ea_week_view_cell_get_name (accessible);
262 }
263 
264 static AtkStateSet *
265 ea_week_view_cell_ref_state_set (AtkObject *obj)
266 {
267   AtkStateSet *state_set;
268   GObject *g_obj;
269   AtkObject *parent;
270   gint x, y, width, height;
271   gint parent_x, parent_y, parent_width, parent_height;
272 
273   state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (obj);
274   g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (obj));
275   if (!g_obj)
276 	  return state_set;
277 
278   atk_state_set_add_state (state_set, ATK_STATE_SELECTABLE);
279 
280   parent = atk_object_get_parent (obj);
281   atk_component_get_extents (ATK_COMPONENT (obj), &x, &y,
282 			     &width, &height, ATK_XY_WINDOW);
283   atk_component_get_extents (ATK_COMPONENT (parent), &parent_x, &parent_y,
284 			     &parent_width, &parent_height, ATK_XY_WINDOW);
285 
286   if (x + width < parent_x || x > parent_x + parent_width ||
287       y + height < parent_y || y > parent_y + parent_height)
288 	  /* the cell is out of the main canvas */
289 	  ;
290   else
291 	  atk_state_set_add_state (state_set, ATK_STATE_VISIBLE);
292 
293   return state_set;
294 }
295 
296 static AtkObject *
297 ea_week_view_cell_get_parent (AtkObject *accessible)
298 {
299 	AtkGObjectAccessible *atk_gobj;
300 	GObject *g_obj;
301 	EWeekViewCell *cell;
302 
303 	g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), NULL);
304 
305 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
306 	g_obj = atk_gobject_accessible_get_object (atk_gobj);
307 	if (!g_obj)
308 		return NULL;
309 
310 	cell = E_WEEK_VIEW_CELL (g_obj);
311 	return atk_gobject_accessible_for_object (G_OBJECT (cell->week_view->main_canvas_item));
312 }
313 
314 static gint
315 ea_week_view_cell_get_index_in_parent (AtkObject *accessible)
316 {
317 	AtkGObjectAccessible *atk_gobj;
318 	GObject *g_obj;
319 	EWeekViewCell *cell;
320 	AtkObject *parent;
321 
322 	g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (accessible), -1);
323 
324 	atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible);
325 	g_obj = atk_gobject_accessible_get_object (atk_gobj);
326 	if (!g_obj)
327 		return -1;
328 
329 	cell = E_WEEK_VIEW_CELL (g_obj);
330 	parent = atk_object_get_parent (accessible);
331 	return atk_table_get_index_at (
332 		ATK_TABLE (parent),
333 		cell->row, cell->column);
334 }
335 
336 /* Atk Component Interface */
337 
338 static void
339 atk_component_interface_init (AtkComponentIface *iface)
340 {
341 	g_return_if_fail (iface != NULL);
342 
343 	iface->get_extents = component_interface_get_extents;
344 	iface->grab_focus = component_interface_grab_focus;
345 }
346 
347 static void
348 component_interface_get_extents (AtkComponent *component,
349                                  gint *x,
350                                  gint *y,
351                                  gint *width,
352                                  gint *height,
353                                  AtkCoordType coord_type)
354 {
355 	GObject *g_obj;
356 	AtkObject *atk_obj;
357 	EWeekViewCell *cell;
358 	EWeekView *week_view;
359 	GtkWidget *main_canvas;
360 	gint week_view_width, week_view_height;
361 	gint scroll_x, scroll_y;
362 	gint start_day;
363 
364 	*x = *y = *width = *height = 0;
365 
366 	g_return_if_fail (EA_IS_WEEK_VIEW_CELL (component));
367 
368 	g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (component));
369 	if (!g_obj)
370 		/* defunct object*/
371 		return;
372 
373 	cell = E_WEEK_VIEW_CELL (g_obj);
374 	week_view = cell->week_view;
375 	main_canvas = cell->week_view->main_canvas;
376 
377 	atk_obj = atk_gobject_accessible_for_object (G_OBJECT (main_canvas));
378 	atk_component_get_extents (
379 		ATK_COMPONENT (atk_obj),
380 		x, y,
381 		&week_view_width, &week_view_height,
382 		coord_type);
383 	gnome_canvas_get_scroll_offsets (
384 		GNOME_CANVAS (week_view->main_canvas),
385 		&scroll_x, &scroll_y);
386 	start_day = week_view->display_start_day;
387 	if (week_view->multi_week_view) {
388 		if (week_view->compress_weekend && (cell->column == (5 - start_day))) {
389                         *height = week_view->row_heights[cell->row*2];
390 			*width = week_view->col_widths[cell->column];
391 			*x += week_view->col_offsets[cell->column] - scroll_x;
392 			*y += week_view->row_offsets[cell->row*2]- scroll_y;
393 		} else if (week_view->compress_weekend && (cell->column == (6 - start_day))) {
394                         *height = week_view->row_heights[cell->row*2];
395                         *width = week_view->col_widths[cell->column - 1];
396                         *x += week_view->col_offsets[cell->column - 1]- scroll_x;
397                         *y += week_view->row_offsets[cell->row*2 + 1]- scroll_y;
398 		} else if (week_view->compress_weekend && (cell->column > (6 - start_day))) {
399                         *height = week_view->row_heights[cell->row*2]*2;
400                         *width = week_view->col_widths[cell->column - 1];
401                         *x += week_view->col_offsets[cell->column - 1] - scroll_x;
402                         *y += week_view->row_offsets[cell->row*2]- scroll_y;
403 		} else {
404 			*height = week_view->row_heights[cell->row*2]*2;
405                         *width = week_view->col_widths[cell->column];
406 			*x += week_view->col_offsets[cell->column] - scroll_x;
407 			*y += week_view->row_offsets[cell->row*2]- scroll_y;
408 		}
409 	} else {
410 		if (start_day < 3) {
411 			if (cell->column < 3) {
412                                 *height = week_view->row_heights[cell->column*2]*2;
413                                 *width = week_view->col_widths[0];
414                                 *x += week_view->col_offsets[0] - scroll_x;
415                                 *y += week_view->row_offsets[cell->column*2]- scroll_y;
416 			} else {
417 				if (cell->column == 5 - start_day) {
418                                         *height = week_view->row_heights[(cell->column - 3)*2];
419                                         *width = week_view->col_widths[1];
420                                         *x += week_view->col_offsets[1] - scroll_x;
421                                         *y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y;
422 				} else if (cell->column == 6 - start_day) {
423                                         *height = week_view->row_heights[(cell->column - 4)*2];
424                                         *width = week_view->col_widths[1];
425                                         *x += week_view->col_offsets[1] - scroll_x;
426                                         *y += week_view->row_offsets[(cell->column - 3)*2 - 1]- scroll_y;
427 				} else if (cell->column > 6 - start_day) {
428                                         *height = week_view->row_heights[(cell->column - 4)*2]*2;
429                                         *width = week_view->col_widths[1];
430                                         *x += week_view->col_offsets[1] - scroll_x;
431                                         *y += week_view->row_offsets[(cell->column - 4)*2]- scroll_y;
432 				} else {
433                                         *height = week_view->row_heights[(cell->column - 3)*2]*2;
434                                         *width = week_view->col_widths[1];
435                                         *x += week_view->col_offsets[1] - scroll_x;
436                                         *y += week_view->row_offsets[(cell->column - 3)*2]- scroll_y;
437 				}
438 			}
439 		} else if (cell->column < 4) {
440 			if (cell->column == 5 - start_day) {
441                                 *height = week_view->row_heights[cell->column*2];
442                                 *width = week_view->col_widths[0];
443                                 *x += week_view->col_offsets[0] - scroll_x;
444                                 *y += week_view->row_offsets[cell->column*2]- scroll_y;
445 			} else if (cell->column == 6 - start_day) {
446                                 *height = week_view->row_heights[(cell->column - 1)*2];
447                                 *width = week_view->col_widths[0];
448                                 *x += week_view->col_offsets[0] - scroll_x;
449                                 *y += week_view->row_offsets[cell->column*2 - 1]- scroll_y;
450 			} else if (cell->column > 6 - start_day) {
451                                 *height = week_view->row_heights[(cell->column - 1)*2]*2;
452                                 *width = week_view->col_widths[0];
453                                 *x += week_view->col_offsets[0] - scroll_x;
454                                 *y += week_view->row_offsets[(cell->column - 1)*2]- scroll_y;
455 			} else {
456                                 *height = week_view->row_heights[(cell->column)*2]*2;
457                                 *width = week_view->col_widths[0];
458                                 *x += week_view->col_offsets[0] - scroll_x;
459                                 *y += week_view->row_offsets[cell->column*2]- scroll_y;
460 			}
461 		} else {
462                         *height = week_view->row_heights[(cell->column - 4)*2]*2;
463                         *width = week_view->col_widths[1];
464                         *x += week_view->col_offsets[1] - scroll_x;
465                         *y += week_view->row_offsets[(cell->column - 4)*2]- scroll_y;
466 		}
467 	}
468 }
469 
470 static gboolean
471 component_interface_grab_focus (AtkComponent *comp)
472 {
473 	GObject *g_obj;
474 	EWeekViewCell *cell;
475 	EWeekView *week_view;
476 	GtkWidget *toplevel;
477 
478 	g_return_val_if_fail (EA_IS_WEEK_VIEW_CELL (comp), FALSE);
479 
480 	g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (comp));
481 	if (!g_obj)
482 		return FALSE;
483 
484 	cell = E_WEEK_VIEW_CELL (g_obj);
485 	week_view = cell->week_view;
486 
487 	week_view->selection_start_day = cell->row * 7 + cell->column;
488 	week_view->selection_end_day = cell->row * 7 + cell->column;
489 	gtk_widget_queue_draw (week_view->main_canvas);
490 
491 	toplevel = gtk_widget_get_toplevel (GTK_WIDGET (week_view));
492 	if (gtk_widget_is_toplevel (toplevel))
493 		gtk_window_present (GTK_WINDOW (toplevel));
494 
495 	return TRUE;
496 }