From f0d3f3afdfa314e1e8cd7d8da790878008a46aad Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Wed, 24 Jun 2009 12:59:33 -0400 Subject: Radically reorganize source code. - Collect all shell modules into a new top-level 'modules' directory: $(top_srcdir)/modules/addressbook $(top_srcdir)/modules/calendar $(top_srcdir)/modules/mail Nothing is allowed to link to these, not plugins nor other modules. THIS SOLVES BUG #571275 AND OPENS THE DOOR TO PORTING TO MAC OS X. - Mimic the libevolution-mail-shared library from master (except drop the "shared" suffix) and have libevolution-mail-importers and all mail-related plugins link to it. - Discard the a11y subdirectories and have the files live alongside their counterpart widgets. --- widgets/misc/Makefile.am | 12 +- widgets/misc/a11y/ea-calendar-cell.c | 387 ---------- widgets/misc/a11y/ea-calendar-cell.h | 86 --- widgets/misc/a11y/ea-calendar-item.c | 1314 ---------------------------------- widgets/misc/a11y/ea-calendar-item.h | 68 -- widgets/misc/a11y/ea-widgets.c | 32 - widgets/misc/a11y/ea-widgets.h | 32 - widgets/misc/e-calendar-item.c | 2 +- widgets/misc/ea-calendar-cell.c | 387 ++++++++++ widgets/misc/ea-calendar-cell.h | 86 +++ widgets/misc/ea-calendar-item.c | 1314 ++++++++++++++++++++++++++++++++++ widgets/misc/ea-calendar-item.h | 68 ++ widgets/misc/ea-widgets.c | 32 + widgets/misc/ea-widgets.h | 32 + 14 files changed, 1926 insertions(+), 1926 deletions(-) delete mode 100644 widgets/misc/a11y/ea-calendar-cell.c delete mode 100644 widgets/misc/a11y/ea-calendar-cell.h delete mode 100644 widgets/misc/a11y/ea-calendar-item.c delete mode 100644 widgets/misc/a11y/ea-calendar-item.h delete mode 100644 widgets/misc/a11y/ea-widgets.c delete mode 100644 widgets/misc/a11y/ea-widgets.h create mode 100644 widgets/misc/ea-calendar-cell.c create mode 100644 widgets/misc/ea-calendar-cell.h create mode 100644 widgets/misc/ea-calendar-item.c create mode 100644 widgets/misc/ea-calendar-item.h create mode 100644 widgets/misc/ea-widgets.c create mode 100644 widgets/misc/ea-widgets.h (limited to 'widgets/misc') diff --git a/widgets/misc/Makefile.am b/widgets/misc/Makefile.am index cbbd283fb2..c7123d6977 100644 --- a/widgets/misc/Makefile.am +++ b/widgets/misc/Makefile.am @@ -84,9 +84,9 @@ widgetsinclude_HEADERS = \ e-spinner.h \ e-timeout-activity.h \ e-url-entry.h \ - a11y/ea-calendar-cell.h \ - a11y/ea-calendar-item.h \ - a11y/ea-widgets.h + ea-calendar-cell.h \ + ea-calendar-item.h \ + ea-widgets.h libemiscwidgets_la_SOURCES = \ $(widgetsinclude_HEADERS) \ @@ -145,9 +145,9 @@ libemiscwidgets_la_SOURCES = \ e-signature-tree-view.c \ e-timeout-activity.c \ e-url-entry.c \ - a11y/ea-calendar-cell.c \ - a11y/ea-calendar-item.c \ - a11y/ea-widgets.c + ea-calendar-cell.c \ + ea-calendar-item.c \ + ea-widgets.c libemiscwidgets_la_LDFLAGS = $(NO_UNDEFINED) diff --git a/widgets/misc/a11y/ea-calendar-cell.c b/widgets/misc/a11y/ea-calendar-cell.c deleted file mode 100644 index af9471c5af..0000000000 --- a/widgets/misc/a11y/ea-calendar-cell.c +++ /dev/null @@ -1,387 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include -#include -#include "ea-calendar-cell.h" -#include "ea-calendar-item.h" -#include "a11y/ea-factory.h" - -/* ECalendarCell */ - -static void e_calendar_cell_class_init (ECalendarCellClass *class); - -EA_FACTORY_GOBJECT (EA_TYPE_CALENDAR_CELL, ea_calendar_cell, ea_calendar_cell_new) - -GType -e_calendar_cell_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo tinfo = { - sizeof (ECalendarCellClass), - (GBaseInitFunc) NULL, /* base init */ - (GBaseFinalizeFunc) NULL, /* base finalize */ - (GClassInitFunc) e_calendar_cell_class_init, /* class init */ - (GClassFinalizeFunc) NULL, /* class finalize */ - NULL, /* class data */ - sizeof (ECalendarCell), /* instance size */ - 0, /* nb preallocs */ - (GInstanceInitFunc) NULL, /* instance init */ - NULL /* value table */ - }; - - type = g_type_register_static (G_TYPE_OBJECT, - "ECalendarCell", &tinfo, 0); - } - - return type; -} - -static void -e_calendar_cell_class_init (ECalendarCellClass *class) -{ - EA_SET_FACTORY (e_calendar_cell_get_type (), ea_calendar_cell); -} - -ECalendarCell * -e_calendar_cell_new (ECalendarItem *calitem, gint row, gint column) -{ - GObject *object; - ECalendarCell *cell; - - g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), NULL); - - object = g_object_new (E_TYPE_CALENDAR_CELL, NULL); - cell = E_CALENDAR_CELL (object); - cell->calitem = calitem; - cell->row = row; - cell->column = column; - -#ifdef ACC_DEBUG - g_print ("EvoAcc: e_calendar_cell created %p\n", (gpointer)cell); -#endif - - return cell; -} - -/* EaCalendarCell */ - -static void ea_calendar_cell_class_init (EaCalendarCellClass *klass); -static void ea_calendar_cell_init (EaCalendarCell *a11y); - -static G_CONST_RETURN gchar * ea_calendar_cell_get_name (AtkObject *accessible); -static G_CONST_RETURN gchar * ea_calendar_cell_get_description (AtkObject *accessible); -static AtkObject * ea_calendar_cell_get_parent (AtkObject *accessible); -static gint ea_calendar_cell_get_index_in_parent (AtkObject *accessible); -static AtkStateSet *ea_calendar_cell_ref_state_set (AtkObject *accessible); - -/* component interface */ -static void atk_component_interface_init (AtkComponentIface *iface); -static void component_interface_get_extents (AtkComponent *component, - gint *x, gint *y, - gint *width, gint *height, - AtkCoordType coord_type); -static gboolean component_interface_grab_focus (AtkComponent *component); - -static gpointer parent_class = NULL; - -#ifdef ACC_DEBUG -static gint n_ea_calendar_cell_created = 0, n_ea_calendar_cell_destroyed = 0; -static void ea_calendar_cell_finalize (GObject *object); -#endif - -GType -ea_calendar_cell_get_type (void) -{ - static GType type = 0; - - if (!type) { - static GTypeInfo tinfo = { - sizeof (EaCalendarCellClass), - (GBaseInitFunc) NULL, /* base init */ - (GBaseFinalizeFunc) NULL, /* base finalize */ - (GClassInitFunc) ea_calendar_cell_class_init, /* class init */ - (GClassFinalizeFunc) NULL, /* class finalize */ - NULL, /* class data */ - sizeof (EaCalendarCell), /* instance size */ - 0, /* nb preallocs */ - (GInstanceInitFunc) ea_calendar_cell_init, /* instance init */ - NULL /* value table */ - }; - - static const GInterfaceInfo atk_component_info = { - (GInterfaceInitFunc) atk_component_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - type = g_type_register_static (ATK_TYPE_GOBJECT_ACCESSIBLE, - "EaCalendarCell", &tinfo, 0); - g_type_add_interface_static (type, ATK_TYPE_COMPONENT, - &atk_component_info); - } - - return type; -} - -static void -ea_calendar_cell_class_init (EaCalendarCellClass *klass) -{ - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - -#ifdef ACC_DEBUG - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - gobject_class->finalize = ea_calendar_cell_finalize; -#endif - - parent_class = g_type_class_peek_parent (klass); - - class->get_name = ea_calendar_cell_get_name; - class->get_description = ea_calendar_cell_get_description; - - class->get_parent = ea_calendar_cell_get_parent; - class->get_index_in_parent = ea_calendar_cell_get_index_in_parent; - class->ref_state_set = ea_calendar_cell_ref_state_set; -} - -static void -ea_calendar_cell_init (EaCalendarCell *a11y) -{ - a11y->state_set = atk_state_set_new (); - atk_state_set_add_state (a11y->state_set, ATK_STATE_TRANSIENT); - atk_state_set_add_state (a11y->state_set, ATK_STATE_ENABLED); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SENSITIVE); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SELECTABLE); - atk_state_set_add_state (a11y->state_set, ATK_STATE_SHOWING); - atk_state_set_add_state (a11y->state_set, ATK_STATE_FOCUSABLE); -} - -AtkObject* -ea_calendar_cell_new (GObject *obj) -{ - gpointer object; - AtkObject *atk_object; - - g_return_val_if_fail (E_IS_CALENDAR_CELL (obj), NULL); - object = g_object_new (EA_TYPE_CALENDAR_CELL, NULL); - atk_object = ATK_OBJECT (object); - atk_object_initialize (atk_object, obj); - atk_object->role = ATK_ROLE_TABLE_CELL; - -#ifdef ACC_DEBUG - ++n_ea_calendar_cell_created; - g_print ("ACC_DEBUG: n_ea_calendar_cell_created = %d\n", - n_ea_calendar_cell_created); -#endif - return atk_object; -} - -#ifdef ACC_DEBUG -static void ea_calendar_cell_finalize (GObject *object) -{ - G_OBJECT_CLASS (parent_class)->finalize (object); - - ++n_ea_calendar_cell_destroyed; - g_print ("ACC_DEBUG: n_ea_calendar_cell_destroyed = %d\n", - n_ea_calendar_cell_destroyed); -} -#endif - -static G_CONST_RETURN gchar * -ea_calendar_cell_get_name (AtkObject *accessible) -{ - GObject *g_obj; - - g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), NULL); - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); - if (!g_obj) - /* defunct object*/ - return NULL; - - if (!accessible->name) { - AtkObject *atk_obj; - EaCalendarItem *ea_calitem; - ECalendarCell *cell; - gint day_index; - gint year, month, day; - gchar buffer[128]; - - cell = E_CALENDAR_CELL (g_obj); - atk_obj = ea_calendar_cell_get_parent (accessible); - ea_calitem = EA_CALENDAR_ITEM (atk_obj); - day_index = atk_table_get_index_at (ATK_TABLE (ea_calitem), - cell->row, cell->column); - e_calendar_item_get_date_for_offset (cell->calitem, day_index, - &year, &month, &day); - - g_snprintf (buffer, 128, "%d-%d-%d", year, month + 1, day); - ATK_OBJECT_CLASS (parent_class)->set_name (accessible, buffer); - } - return accessible->name; -} - -static G_CONST_RETURN gchar * -ea_calendar_cell_get_description (AtkObject *accessible) -{ - return ea_calendar_cell_get_name (accessible); -} - -static AtkObject * -ea_calendar_cell_get_parent (AtkObject *accessible) -{ - GObject *g_obj; - ECalendarCell *cell; - ECalendarItem *calitem; - - g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), NULL); - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); - if (!g_obj) - /* defunct object*/ - return NULL; - - cell = E_CALENDAR_CELL (g_obj); - calitem = cell->calitem; - return atk_gobject_accessible_for_object (G_OBJECT (calitem)); -} - -static gint -ea_calendar_cell_get_index_in_parent (AtkObject *accessible) -{ - GObject *g_obj; - ECalendarCell *cell; - AtkObject *parent; - - g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), -1); - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); - if (!g_obj) - return -1; - cell = E_CALENDAR_CELL (g_obj); - parent = atk_object_get_parent (accessible); - return atk_table_get_index_at (ATK_TABLE (parent), - cell->row, cell->column); -} - -static AtkStateSet * -ea_calendar_cell_ref_state_set (AtkObject *accessible) -{ - EaCalendarCell *atk_cell = EA_CALENDAR_CELL (accessible); - - g_return_val_if_fail (atk_cell->state_set, NULL); - - g_object_ref(atk_cell->state_set); - - return atk_cell->state_set; - -} - -/* Atk Component Interface */ - -static void -atk_component_interface_init (AtkComponentIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->get_extents = component_interface_get_extents; - iface->grab_focus = component_interface_grab_focus; -} - -static void -component_interface_get_extents (AtkComponent *component, - gint *x, gint *y, gint *width, gint *height, - AtkCoordType coord_type) -{ - GObject *g_obj; - AtkObject *atk_obj, *atk_canvas; - ECalendarCell *cell; - ECalendarItem *calitem; - EaCalendarItem *ea_calitem; - gint day_index; - gint year, month, day; - gint canvas_x, canvas_y, canvas_width, canvas_height; - - *x = *y = *width = *height = 0; - - g_return_if_fail (EA_IS_CALENDAR_CELL (component)); - - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); - if (!g_obj) - /* defunct object*/ - return; - - cell = E_CALENDAR_CELL (g_obj); - calitem = cell->calitem; - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); - ea_calitem = EA_CALENDAR_ITEM (atk_obj); - day_index = atk_table_get_index_at (ATK_TABLE (ea_calitem), - cell->row, cell->column); - e_calendar_item_get_date_for_offset (calitem, day_index, - &year, &month, &day); - - if (!e_calendar_item_get_day_extents (calitem, - year, month, day, - x, y, width, height)) - return; - atk_canvas = atk_object_get_parent (ATK_OBJECT (ea_calitem)); - atk_component_get_extents (ATK_COMPONENT (atk_canvas), - &canvas_x, &canvas_y, - &canvas_width, &canvas_height, - coord_type); - *x += canvas_x; - *y += canvas_y; -} - -static gboolean -component_interface_grab_focus (AtkComponent *component) -{ - GObject *g_obj; - GtkWidget *toplevel; - AtkObject *ea_calitem; - ECalendarItem *calitem; - EaCalendarCell *a11y; - gint index; - - a11y = EA_CALENDAR_CELL (component); - ea_calitem = ea_calendar_cell_get_parent (ATK_OBJECT (a11y)); - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(ea_calitem)); - calitem = E_CALENDAR_ITEM (g_obj); - - index = atk_object_get_index_in_parent (ATK_OBJECT (a11y)); - - atk_selection_clear_selection (ATK_SELECTION (ea_calitem)); - atk_selection_add_selection (ATK_SELECTION (ea_calitem), index); - - gtk_widget_grab_focus (GTK_WIDGET (GNOME_CANVAS_ITEM (calitem)->canvas)); - toplevel = gtk_widget_get_toplevel (GTK_WIDGET (GNOME_CANVAS_ITEM (calitem)->canvas)); - if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel)) - gtk_window_present (GTK_WINDOW (toplevel)); - - return TRUE; - -} diff --git a/widgets/misc/a11y/ea-calendar-cell.h b/widgets/misc/a11y/ea-calendar-cell.h deleted file mode 100644 index fa68fdca55..0000000000 --- a/widgets/misc/a11y/ea-calendar-cell.h +++ /dev/null @@ -1,86 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __EA_CALENDAR_CELL_H__ -#define __EA_CALENDAR_CELL_H__ - -#include -#include "misc/e-calendar-item.h" - -G_BEGIN_DECLS - -#define E_TYPE_CALENDAR_CELL (e_calendar_cell_get_type ()) -#define E_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CALENDAR_CELL, ECalendarCell)) -#define E_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_CALENDAR_CELL, ECalendarCellClass)) -#define E_IS_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CALENDAR_CELL)) -#define E_IS_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CALENDAR_CELL)) -#define E_CALENDAR_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_CALENDAR_CELL, ECalendarCellClass)) - -typedef struct _ECalendarCell ECalendarCell; -typedef struct _ECalendarCellClass ECalendarCellClass; - -struct _ECalendarCell -{ - GObject parent; - ECalendarItem *calitem; - gint row; - gint column; -}; - -GType e_calendar_cell_get_type (void); - -struct _ECalendarCellClass -{ - GObjectClass parent_class; -}; - -ECalendarCell * e_calendar_cell_new (ECalendarItem *calitem, - gint row, gint column); - -#define EA_TYPE_CALENDAR_CELL (ea_calendar_cell_get_type ()) -#define EA_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CALENDAR_CELL, EaCalendarCell)) -#define EA_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CALENDAR_CELL, EaCalendarCellClass)) -#define EA_IS_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CALENDAR_CELL)) -#define EA_IS_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CALENDAR_CELL)) -#define EA_CALENDAR_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CALENDAR_CELL, EaCalendarCellClass)) - -typedef struct _EaCalendarCell EaCalendarCell; -typedef struct _EaCalendarCellClass EaCalendarCellClass; - -struct _EaCalendarCell -{ - AtkGObjectAccessible parent; - AtkStateSet *state_set; -}; - -GType ea_calendar_cell_get_type (void); - -struct _EaCalendarCellClass -{ - AtkGObjectAccessibleClass parent_class; -}; - -AtkObject* ea_calendar_cell_new (GObject *gobj); - -G_END_DECLS - -#endif /* __EA_CALENDAR_CELL_H__ */ diff --git a/widgets/misc/a11y/ea-calendar-item.c b/widgets/misc/a11y/ea-calendar-item.c deleted file mode 100644 index 56a01b510b..0000000000 --- a/widgets/misc/a11y/ea-calendar-item.c +++ /dev/null @@ -1,1314 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include "ea-calendar-item.h" -#include "ea-calendar-cell.h" -#include "a11y/ea-cell-table.h" - -#define EA_CALENDAR_COLUMN_NUM E_CALENDAR_COLS_PER_MONTH - -/* EaCalendarItem */ -static void ea_calendar_item_class_init (EaCalendarItemClass *klass); -static void ea_calendar_item_finalize (GObject *object); - -static G_CONST_RETURN gchar * ea_calendar_item_get_name (AtkObject *accessible); -static G_CONST_RETURN gchar * ea_calendar_item_get_description (AtkObject *accessible); -static gint ea_calendar_item_get_n_children (AtkObject *accessible); -static AtkObject *ea_calendar_item_ref_child (AtkObject *accessible, gint index); -static AtkStateSet* ea_calendar_item_ref_state_set (AtkObject *accessible); - -/* atk table interface */ -static void atk_table_interface_init (AtkTableIface *iface); -static gint table_interface_get_index_at (AtkTable *table, - gint row, - gint column); -static gint table_interface_get_column_at_index (AtkTable *table, - gint index); -static gint table_interface_get_row_at_index (AtkTable *table, - gint index); -static AtkObject* table_interface_ref_at (AtkTable *table, - gint row, - gint column); -static gint table_interface_get_n_rows (AtkTable *table); -static gint table_interface_get_n_columns (AtkTable *table); -static gint table_interface_get_column_extent_at (AtkTable *table, - gint row, - gint column); -static gint table_interface_get_row_extent_at (AtkTable *table, - gint row, - gint column); - -static gboolean table_interface_is_row_selected (AtkTable *table, - gint row); -static gboolean table_interface_is_column_selected (AtkTable *table, - gint row); -static gboolean table_interface_is_selected (AtkTable *table, - gint row, - gint column); -static gint table_interface_get_selected_rows (AtkTable *table, - gint **rows_selected); -static gint table_interface_get_selected_columns (AtkTable *table, - gint **columns_selected); -static gboolean table_interface_add_row_selection (AtkTable *table, gint row); -static gboolean table_interface_remove_row_selection (AtkTable *table, - gint row); -static gboolean table_interface_add_column_selection (AtkTable *table, - gint column); -static gboolean table_interface_remove_column_selection (AtkTable *table, - gint column); -static AtkObject* table_interface_get_row_header (AtkTable *table, gint row); -static AtkObject* table_interface_get_column_header (AtkTable *table, - gint in_col); -static AtkObject* table_interface_get_caption (AtkTable *table); - -static G_CONST_RETURN gchar * -table_interface_get_column_description (AtkTable *table, gint in_col); - -static G_CONST_RETURN gchar * -table_interface_get_row_description (AtkTable *table, gint row); - -static AtkObject* table_interface_get_summary (AtkTable *table); - -/* atk selection interface */ -static void atk_selection_interface_init (AtkSelectionIface *iface); -static gboolean selection_interface_add_selection (AtkSelection *selection, - gint i); -static gboolean selection_interface_clear_selection (AtkSelection *selection); -static AtkObject* selection_interface_ref_selection (AtkSelection *selection, - gint i); -static gint selection_interface_get_selection_count (AtkSelection *selection); -static gboolean selection_interface_is_child_selected (AtkSelection *selection, - gint i); - -/* callbacks */ -static void selection_preview_change_cb (ECalendarItem *calitem); -static void date_range_changed_cb (ECalendarItem *calitem); - -/* helpers */ -static EaCellTable *ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem); -static void ea_calendar_item_destory_cell_data (EaCalendarItem *ea_calitem); -static gboolean ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, - gint column, - gchar *buffer, - gint buffer_size); -static gboolean ea_calendar_item_get_row_label (EaCalendarItem *ea_calitem, - gint row, - gchar *buffer, - gint buffer_size); -static gboolean e_calendar_item_get_offset_for_date (ECalendarItem *calitem, - gint year, gint month, gint day, - gint *offset); -static void ea_calendar_set_focus_object (EaCalendarItem *ea_calitem, - AtkObject *item_cell); - -#ifdef ACC_DEBUG -static gint n_ea_calendar_item_created = 0; -static gint n_ea_calendar_item_destroyed = 0; -#endif - -static gpointer parent_class = NULL; - -GType -ea_calendar_item_get_type (void) -{ - static GType type = 0; - AtkObjectFactory *factory; - GTypeQuery query; - GType derived_atk_type; - - if (!type) { - static GTypeInfo tinfo = { - sizeof (EaCalendarItemClass), - (GBaseInitFunc) NULL, /* base init */ - (GBaseFinalizeFunc) NULL, /* base finalize */ - (GClassInitFunc) ea_calendar_item_class_init, /* class init */ - (GClassFinalizeFunc) NULL, /* class finalize */ - NULL, /* class data */ - sizeof (EaCalendarItem), /* instance size */ - 0, /* nb preallocs */ - (GInstanceInitFunc) NULL, /* instance init */ - NULL /* value table */ - }; - - static const GInterfaceInfo atk_table_info = { - (GInterfaceInitFunc) atk_table_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - static const GInterfaceInfo atk_selection_info = { - (GInterfaceInitFunc) atk_selection_interface_init, - (GInterfaceFinalizeFunc) NULL, - NULL - }; - - /* - * Figure out the size of the class and instance - * we are run-time deriving from (GailCanvasItem, in this case) - */ - - factory = atk_registry_get_factory (atk_get_default_registry (), - GNOME_TYPE_CANVAS_ITEM); - derived_atk_type = atk_object_factory_get_accessible_type (factory); - g_type_query (derived_atk_type, &query); - - tinfo.class_size = query.class_size; - tinfo.instance_size = query.instance_size; - - type = g_type_register_static (derived_atk_type, - "EaCalendarItem", &tinfo, 0); - g_type_add_interface_static (type, ATK_TYPE_TABLE, - &atk_table_info); - g_type_add_interface_static (type, ATK_TYPE_SELECTION, - &atk_selection_info); - } - - return type; -} - -static void -ea_calendar_item_class_init (EaCalendarItemClass *klass) -{ - GObjectClass *gobject_class = G_OBJECT_CLASS (klass); - AtkObjectClass *class = ATK_OBJECT_CLASS (klass); - - gobject_class->finalize = ea_calendar_item_finalize; - parent_class = g_type_class_peek_parent (klass); - - class->get_name = ea_calendar_item_get_name; - class->get_description = ea_calendar_item_get_description; - class->ref_state_set = ea_calendar_item_ref_state_set; - - class->get_n_children = ea_calendar_item_get_n_children; - class->ref_child = ea_calendar_item_ref_child; -} - -AtkObject* -ea_calendar_item_new (GObject *obj) -{ - gpointer object; - AtkObject *atk_object; - AtkObject *item_cell; - - g_return_val_if_fail (E_IS_CALENDAR_ITEM (obj), NULL); - object = g_object_new (EA_TYPE_CALENDAR_ITEM, NULL); - atk_object = ATK_OBJECT (object); - atk_object_initialize (atk_object, obj); - atk_object->role = ATK_ROLE_CALENDAR; - - item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_object), - 0); - if (item_cell) - ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_object), item_cell); - -#ifdef ACC_DEBUG - ++n_ea_calendar_item_created; - g_print ("ACC_DEBUG: n_ea_calendar_item_created = %d\n", - n_ea_calendar_item_created); -#endif - /* connect signal handlers */ - g_signal_connect (obj, "selection_preview_changed", - G_CALLBACK (selection_preview_change_cb), - atk_object); - g_signal_connect (obj, "date_range_changed", - G_CALLBACK (date_range_changed_cb), - atk_object); - - return atk_object; -} - -static void -ea_calendar_item_finalize (GObject *object) -{ - EaCalendarItem *ea_calitem; - - g_return_if_fail (EA_IS_CALENDAR_ITEM (object)); - - ea_calitem = EA_CALENDAR_ITEM (object); - - /* Free the allocated cell data */ - ea_calendar_item_destory_cell_data (ea_calitem); - - G_OBJECT_CLASS (parent_class)->finalize (object); -#ifdef ACC_DEBUG - ++n_ea_calendar_item_destroyed; - printf ("ACC_DEBUG: n_ea_calendar_item_destroyed = %d\n", - n_ea_calendar_item_destroyed); -#endif -} - -static G_CONST_RETURN gchar * -ea_calendar_item_get_name (AtkObject *accessible) -{ - GObject *g_obj; - ECalendarItem *calitem; - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - gchar *name_str = NULL; - gchar buffer_start[128] = ""; - gchar buffer_end[128] = ""; - struct tm day_start = { 0 }; - struct tm day_end = { 0 }; - - g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), NULL); - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); - if (!g_obj) - return NULL; - g_return_val_if_fail (E_IS_CALENDAR_ITEM (g_obj), NULL); - - calitem = E_CALENDAR_ITEM (g_obj); - if (e_calendar_item_get_date_range (calitem, - &start_year, &start_month, &start_day, - &end_year, &end_month, &end_day)) { - - day_start.tm_year = start_year - 1900; - day_start.tm_mon = start_month; - day_start.tm_mday = start_day; - day_start.tm_isdst = -1; - e_utf8_strftime (buffer_start, sizeof (buffer_start), _("%d %B %Y"), &day_start); - - day_end.tm_year = end_year - 1900; - day_end.tm_mon = end_month; - day_end.tm_mday = end_day; - day_end.tm_isdst = -1; - e_utf8_strftime (buffer_end, sizeof (buffer_end), _("%d %B %Y"), &day_end); - - name_str = g_strdup_printf (_("Calendar: from %s to %s"), buffer_start, buffer_end); - } - -#if 0 - if (e_calendar_item_get_selection (calitem, &select_start, &select_end)) { - GDate select_start, select_end; - gint year1, year2, month1, month2, day1, day2; - - year1 = g_date_get_year (&select_start); - month1 = g_date_get_month (&select_start); - day1 = g_date_get_day (&select_start); - - year2 = g_date_get_year (&select_end); - month2 = g_date_get_month (&select_end); - day2 = g_date_get_day (&select_end); - - sprintf (new_name + strlen (new_name), - " : current selection: from %d-%d-%d to %d-%d-%d.", - year1, month1, day1, - year2, month2, day2); - } -#endif - - ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_str); - g_free (name_str); - - return accessible->name; -} - -static G_CONST_RETURN gchar * -ea_calendar_item_get_description (AtkObject *accessible) -{ - if (accessible->description) - return accessible->description; - - return _("evolution calendar item"); -} - -static AtkStateSet* -ea_calendar_item_ref_state_set (AtkObject *accessible) -{ - AtkStateSet *state_set; - GObject *g_obj; - - state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible); - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); - if (!g_obj) - return state_set; - - atk_state_set_add_state (state_set, ATK_STATE_ENABLED); - atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE); - - return state_set; -} - -static gint -ea_calendar_item_get_n_children (AtkObject *accessible) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - gint n_children = 0; - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - GDate *start_date, *end_date; - - g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), -1); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - calitem = E_CALENDAR_ITEM (g_obj); - if (!e_calendar_item_get_date_range (calitem, &start_year, - &start_month, &start_day, - &end_year, &end_month, - &end_day)) - return 0; - - start_date = g_date_new_dmy (start_day, start_month + 1, start_year); - end_date = g_date_new_dmy (end_day, end_month + 1, end_year); - - n_children = g_date_days_between (start_date, end_date) + 1; - g_free (start_date); - g_free (end_date); - return n_children; -} - -static AtkObject * -ea_calendar_item_ref_child (AtkObject *accessible, gint index) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - gint n_children; - ECalendarCell *cell; - EaCellTable *cell_data; - EaCalendarItem *ea_calitem; - - g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), NULL); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return NULL; - - calitem = E_CALENDAR_ITEM (g_obj); - - n_children = ea_calendar_item_get_n_children (accessible); - if (index < 0 || index >= n_children) - return NULL; - - ea_calitem = EA_CALENDAR_ITEM (accessible); - cell_data = ea_calendar_item_get_cell_data (ea_calitem); - if (!cell_data) - return NULL; - - cell = ea_cell_table_get_cell_at_index (cell_data, index); - if (!cell) { - cell = e_calendar_cell_new (calitem, - index / EA_CALENDAR_COLUMN_NUM, - index % EA_CALENDAR_COLUMN_NUM); - ea_cell_table_set_cell_at_index (cell_data, index, cell); - g_object_unref (cell); - } - -#ifdef ACC_DEBUG - g_print ("AccDebug: ea_calendar_item children[%d]=%p\n", index, - (gpointer)cell); -#endif - return g_object_ref (atk_gobject_accessible_for_object (G_OBJECT(cell))); -} - -/* atk table interface */ - -static void -atk_table_interface_init (AtkTableIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->ref_at = table_interface_ref_at; - - iface->get_n_rows = table_interface_get_n_rows; - iface->get_n_columns = table_interface_get_n_columns; - iface->get_index_at = table_interface_get_index_at; - iface->get_column_at_index = table_interface_get_column_at_index; - iface->get_row_at_index = table_interface_get_row_at_index; - iface->get_column_extent_at = table_interface_get_column_extent_at; - iface->get_row_extent_at = table_interface_get_row_extent_at; - - iface->is_selected = table_interface_is_selected; - iface->get_selected_rows = table_interface_get_selected_rows; - iface->get_selected_columns = table_interface_get_selected_columns; - iface->is_row_selected = table_interface_is_row_selected; - iface->is_column_selected = table_interface_is_column_selected; - iface->add_row_selection = table_interface_add_row_selection; - iface->remove_row_selection = table_interface_remove_row_selection; - iface->add_column_selection = table_interface_add_column_selection; - iface->remove_column_selection = table_interface_remove_column_selection; - - iface->get_row_header = table_interface_get_row_header; - iface->get_column_header = table_interface_get_column_header; - iface->get_caption = table_interface_get_caption; - iface->get_summary = table_interface_get_summary; - iface->get_row_description = table_interface_get_row_description; - iface->get_column_description = table_interface_get_column_description; -} - -static AtkObject* -table_interface_ref_at (AtkTable *table, - gint row, - gint column) -{ - gint index; - - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - index = EA_CALENDAR_COLUMN_NUM * row + column; - return ea_calendar_item_ref_child (ATK_OBJECT (ea_calitem), index); -} - -static gint -table_interface_get_n_rows (AtkTable *table) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - gint n_children; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); - return (n_children - 1) / EA_CALENDAR_COLUMN_NUM + 1; -} - -static gint -table_interface_get_n_columns (AtkTable *table) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - return EA_CALENDAR_COLUMN_NUM; -} - -static gint -table_interface_get_index_at (AtkTable *table, - gint row, - gint column) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - return row * EA_CALENDAR_COLUMN_NUM + column; -} - -static gint -table_interface_get_column_at_index (AtkTable *table, - gint index) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - gint n_children; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); - if (index >= 0 && index < n_children) - return index % EA_CALENDAR_COLUMN_NUM; - return -1; -} - -static gint -table_interface_get_row_at_index (AtkTable *table, - gint index) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - gint n_children; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return -1; - - n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); - if (index >= 0 && index < n_children) - return index / EA_CALENDAR_COLUMN_NUM; - return -1; -} - -static gint -table_interface_get_column_extent_at (AtkTable *table, - gint row, - gint column) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - calitem = E_CALENDAR_ITEM (g_obj); - return calitem->cell_width; -} - -static gint -table_interface_get_row_extent_at (AtkTable *table, - gint row, gint column) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - calitem = E_CALENDAR_ITEM (g_obj); - return calitem->cell_height; -} - -/* any day in the row is selected, the row is selected */ -static gboolean -table_interface_is_row_selected (AtkTable *table, - gint row) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - gint n_rows; - ECalendarItem *calitem; - gint row_index_start, row_index_end; - gint sel_index_start, sel_index_end; - - GDate start_date, end_date; - - g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table), FALSE); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (table); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - n_rows = table_interface_get_n_rows (table); - if (row < 0 || row >= n_rows) - return FALSE; - - row_index_start = row * EA_CALENDAR_COLUMN_NUM; - row_index_end = row_index_start + EA_CALENDAR_COLUMN_NUM - 1; - - calitem = E_CALENDAR_ITEM (g_obj); - if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) - return FALSE; - - e_calendar_item_get_offset_for_date (calitem, - g_date_get_year (&start_date), - g_date_get_month (&start_date), - g_date_get_day (&start_date), - &sel_index_start); - e_calendar_item_get_offset_for_date (calitem, - g_date_get_year (&end_date), - g_date_get_month (&end_date), - g_date_get_day (&end_date), - &sel_index_end); - - if ((sel_index_start < row_index_start && - sel_index_end >= row_index_start) || - (sel_index_start >= row_index_start && - sel_index_start <= row_index_end)) - return TRUE; - return FALSE; -} - -static gboolean -table_interface_is_selected (AtkTable *table, - gint row, - gint column) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - gint n_rows, n_columns; - ECalendarItem *calitem; - gint index; - gint sel_index_start, sel_index_end; - - GDate start_date, end_date; - - g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table), FALSE); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (table); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - n_rows = table_interface_get_n_rows (table); - if (row < 0 || row >= n_rows) - return FALSE; - n_columns = table_interface_get_n_columns (table); - if (column < 0 || column >= n_columns) - return FALSE; - - index = table_interface_get_index_at (table, row, column); - - calitem = E_CALENDAR_ITEM (g_obj); - if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) - return FALSE; - - e_calendar_item_get_offset_for_date (calitem, - g_date_get_year (&start_date), - g_date_get_month (&start_date), - g_date_get_day (&start_date), - &sel_index_start); - e_calendar_item_get_offset_for_date (calitem, - g_date_get_year (&end_date), - g_date_get_month (&end_date), - g_date_get_day (&end_date), &sel_index_end); - - if (sel_index_start <= index && sel_index_end >= index) - return TRUE; - return FALSE; -} - -static gboolean -table_interface_is_column_selected (AtkTable *table, - gint column) -{ - return FALSE; -} - -static gint -table_interface_get_selected_rows (AtkTable *table, - gint **rows_selected) -{ - *rows_selected = NULL; - return -1; -} - -static gint -table_interface_get_selected_columns (AtkTable *table, - gint **columns_selected) -{ - *columns_selected = NULL; - return -1; -} - -static gboolean -table_interface_add_row_selection (AtkTable *table, - gint row) -{ - return FALSE; -} - -static gboolean -table_interface_remove_row_selection (AtkTable *table, - gint row) -{ - return FALSE; -} - -static gboolean -table_interface_add_column_selection (AtkTable *table, - gint column) -{ - return FALSE; -} - -static gboolean -table_interface_remove_column_selection (AtkTable *table, - gint column) -{ - /* FIXME: NOT IMPLEMENTED */ - return FALSE; -} - -static AtkObject* -table_interface_get_row_header (AtkTable *table, - gint row) -{ - /* FIXME: NOT IMPLEMENTED */ - return NULL; -} - -static AtkObject* -table_interface_get_column_header (AtkTable *table, - gint in_col) -{ - /* FIXME: NOT IMPLEMENTED */ - return NULL; -} - -static AtkObject* -table_interface_get_caption (AtkTable *table) -{ - /* FIXME: NOT IMPLEMENTED */ - return NULL; -} - -static G_CONST_RETURN gchar * -table_interface_get_column_description (AtkTable *table, gint in_col) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - const gchar *description = NULL; - EaCellTable *cell_data; - gint n_columns; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return NULL; - - n_columns = table_interface_get_n_columns (table); - if (in_col < 0 || in_col >= n_columns) - return NULL; - cell_data = ea_calendar_item_get_cell_data (ea_calitem); - if (!cell_data) - return NULL; - - description = ea_cell_table_get_column_label (cell_data, in_col); - if (!description) { - gchar buffer[128] = "column description"; - ea_calendar_item_get_column_label (ea_calitem, in_col, - buffer, sizeof (buffer)); - ea_cell_table_set_column_label (cell_data, in_col, buffer); - description = ea_cell_table_get_column_label (cell_data, - in_col); - } - return description; -} - -static G_CONST_RETURN gchar * -table_interface_get_row_description (AtkTable *table, gint row) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); - const gchar *description = NULL; - EaCellTable *cell_data; - gint n_rows; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return NULL; - - n_rows = table_interface_get_n_rows (table); - if (row < 0 || row >= n_rows) - return NULL; - cell_data = ea_calendar_item_get_cell_data (ea_calitem); - if (!cell_data) - return NULL; - - description = ea_cell_table_get_row_label (cell_data, row); - if (!description) { - gchar buffer[128] = "row description"; - ea_calendar_item_get_row_label (ea_calitem, row, - buffer, sizeof (buffer)); - ea_cell_table_set_row_label (cell_data, row, buffer); - description = ea_cell_table_get_row_label (cell_data, - row); - } - return description; -} - -static AtkObject* -table_interface_get_summary (AtkTable *table) -{ - /* FIXME: NOT IMPLEMENTED */ - return NULL; -} - -/* atkselection interface */ - -static void -atk_selection_interface_init (AtkSelectionIface *iface) -{ - g_return_if_fail (iface != NULL); - - iface->add_selection = selection_interface_add_selection; - iface->clear_selection = selection_interface_clear_selection; - iface->ref_selection = selection_interface_ref_selection; - iface->get_selection_count = selection_interface_get_selection_count; - iface->is_child_selected = selection_interface_is_child_selected; -} - -static gboolean -selection_interface_add_selection (AtkSelection *selection, gint index) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); - gint year, month, day; - GDate start_date, end_date; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - calitem = E_CALENDAR_ITEM (g_obj); - if (!e_calendar_item_get_date_for_offset (calitem, index, - &year, &month, &day)) - return FALSE; - - /* FIXME: not support mulit-selection */ - g_date_set_dmy (&start_date, day, month + 1, year); - end_date = start_date; - e_calendar_item_set_selection (calitem, &start_date, &end_date); - return TRUE; -} - -static gboolean -selection_interface_clear_selection (AtkSelection *selection) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - calitem = E_CALENDAR_ITEM (g_obj); - e_calendar_item_set_selection (calitem, NULL, NULL); - - return TRUE; -} - -static AtkObject* -selection_interface_ref_selection (AtkSelection *selection, gint i) -{ - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); - gint count, sel_offset; - GDate start_date, end_date; - - count = selection_interface_get_selection_count (selection); - if (i < 0 || i >= count) - return NULL; - - g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_calitem)); - - calitem = E_CALENDAR_ITEM (g_obj); - if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) - return NULL; - if (!e_calendar_item_get_offset_for_date (calitem, - g_date_get_year (&start_date), - g_date_get_month (&start_date) - 1, - g_date_get_day (&start_date), - &sel_offset)) - return NULL; - - return ea_calendar_item_ref_child (ATK_OBJECT (selection), sel_offset + i); -} - -static gint -selection_interface_get_selection_count (AtkSelection *selection) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); - GDate start_date, end_date; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return 0; - - calitem = E_CALENDAR_ITEM (g_obj); - if (e_calendar_item_get_selection (calitem, &start_date, &end_date)) - return g_date_days_between (&start_date, &end_date) + 1; - else - return 0; -} - -static gboolean -selection_interface_is_child_selected (AtkSelection *selection, gint index) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); - gint row, column, n_children; - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - n_children = atk_object_get_n_accessible_children (ATK_OBJECT (selection)); - if (index < 0 || index >= n_children) - return FALSE; - - row = index / EA_CALENDAR_COLUMN_NUM; - column = index % EA_CALENDAR_COLUMN_NUM; - - return table_interface_is_selected (ATK_TABLE (selection), row, column); -} - -/* callbacks */ - -static void -selection_preview_change_cb (ECalendarItem *calitem) -{ - AtkObject *atk_obj; - AtkObject *item_cell; - - g_return_if_fail (E_IS_CALENDAR_ITEM (calitem)); - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); - ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj)); - - /* only deal with the first selected child, for now */ - item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_obj), - 0); - - if (item_cell) - ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj), item_cell); - - g_signal_emit_by_name (atk_obj, - "active-descendant-changed", - item_cell); - g_signal_emit_by_name (atk_obj, "selection_changed"); -} - -static void -date_range_changed_cb (ECalendarItem *calitem) -{ - AtkObject *atk_obj; - AtkObject *item_cell; - - g_return_if_fail (E_IS_CALENDAR_ITEM (calitem)); - atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); - ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj)); - - item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_obj), - 0); - if (item_cell) - ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj), item_cell); - - g_signal_emit_by_name (atk_obj, "model_changed"); -} - -/* helpers */ - -static EaCellTable * -ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - EaCellTable *cell_data; - - g_return_val_if_fail (ea_calitem, NULL); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return NULL; - - cell_data = g_object_get_data (G_OBJECT(ea_calitem), - "ea-calendar-cell-table"); - - if (!cell_data) { - gint n_cells = ea_calendar_item_get_n_children (ATK_OBJECT(ea_calitem)); - cell_data = ea_cell_table_create (n_cells/EA_CALENDAR_COLUMN_NUM, - EA_CALENDAR_COLUMN_NUM, - FALSE); - g_object_set_data (G_OBJECT(ea_calitem), - "ea-calendar-cell-table", cell_data); - } - return cell_data; -} - -static void -ea_calendar_item_destory_cell_data (EaCalendarItem *ea_calitem) -{ - EaCellTable *cell_data; - - g_return_if_fail (ea_calitem); - - cell_data = g_object_get_data (G_OBJECT(ea_calitem), - "ea-calendar-cell-table"); - if (cell_data) { - g_object_set_data (G_OBJECT(ea_calitem), - "ea-calendar-cell-table", NULL); - ea_cell_table_destroy (cell_data); - } -} - -static gboolean -ea_calendar_item_get_row_label (EaCalendarItem *ea_calitem, gint row, - gchar *buffer, gint buffer_size) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - gint index, week_num; - gint year, month, day; - - g_return_val_if_fail (ea_calitem, FALSE); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - calitem = E_CALENDAR_ITEM (g_obj); - - index = atk_table_get_index_at (ATK_TABLE (ea_calitem), row, 0); - if (!e_calendar_item_get_date_for_offset (calitem, index, - &year, &month, &day)) - return FALSE; - - week_num = e_calendar_item_get_week_number (calitem, - day, month, year); - - g_snprintf (buffer, buffer_size, "week number : %d", week_num); - return TRUE; -} - -static gboolean -ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, gint column, - gchar *buffer, gint buffer_size) -{ - AtkGObjectAccessible *atk_gobj; - GObject *g_obj; - ECalendarItem *calitem; - const gchar *abbr_name; - - g_return_val_if_fail (ea_calitem, FALSE); - - atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); - g_obj = atk_gobject_accessible_get_object (atk_gobj); - if (!g_obj) - return FALSE; - - /* Columns are 0 = Monday ... 6 = Sunday */ - calitem = E_CALENDAR_ITEM (g_obj); - abbr_name = e_get_weekday_name (column + 1, TRUE); - g_strlcpy (buffer, abbr_name, buffer_size); - - return TRUE; -} - -/* the coordinate the e-calendar canvas coord */ -gboolean -e_calendar_item_get_day_extents (ECalendarItem *calitem, - gint year, gint month, gint date, - gint *x, gint *y, - gint *width, gint *height) -{ - GnomeCanvasItem *item; - GtkWidget *widget; - GtkStyle *style; - PangoFontDescription *font_desc; - PangoContext *pango_context; - PangoFontMetrics *font_metrics; - gint char_height, xthickness, ythickness, text_y; - gint new_year, new_month, num_months, months_offset; - gint month_x, month_y, month_cell_x, month_cell_y; - gint month_row, month_col; - gint day_row, day_col; - gint days_from_week_start; - - g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); - - item = GNOME_CANVAS_ITEM (calitem); - widget = GTK_WIDGET (item->canvas); - style = widget->style; - - /* Set up Pango prerequisites */ - font_desc = calitem->font_desc; - if (!font_desc) - font_desc = style->font_desc; - pango_context = gtk_widget_get_pango_context (widget); - font_metrics = pango_context_get_metrics (pango_context, font_desc, - pango_context_get_language (pango_context)); - - char_height = - PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + - PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)); - - xthickness = style->xthickness; - ythickness = style->ythickness; - - new_year = year; - new_month = month; - e_calendar_item_normalize_date (calitem, &new_year, &new_month); - num_months = calitem->rows * calitem->cols; - months_offset = (new_year - calitem->year) * 12 - + new_month - calitem->month; - - if (months_offset > num_months || months_offset < 0) - return FALSE; - - month_row = months_offset / calitem->cols; - month_col = months_offset % calitem->cols; - - month_x = item->x1 + xthickness + calitem->x_offset - + month_col * calitem->month_width; - month_y = item->y1 + ythickness + month_row * calitem->month_height; - - month_cell_x = month_x + E_CALENDAR_ITEM_XPAD_BEFORE_WEEK_NUMBERS - + calitem->month_lpad + E_CALENDAR_ITEM_XPAD_BEFORE_CELLS; - text_y = month_y + ythickness * 2 - + E_CALENDAR_ITEM_YPAD_ABOVE_MONTH_NAME - + char_height + E_CALENDAR_ITEM_YPAD_BELOW_MONTH_NAME - + E_CALENDAR_ITEM_YPAD_ABOVE_DAY_LETTERS + calitem->month_tpad; - - month_cell_y = text_y + char_height - + E_CALENDAR_ITEM_YPAD_BELOW_DAY_LETTERS + 1 - + E_CALENDAR_ITEM_YPAD_ABOVE_CELLS; - - days_from_week_start = - e_calendar_item_get_n_days_from_week_start (calitem, new_year, - new_month); - day_row = (date + days_from_week_start - 1) / EA_CALENDAR_COLUMN_NUM; - day_col = (date + days_from_week_start - 1) % EA_CALENDAR_COLUMN_NUM; - - *x = month_cell_x + day_col * calitem->cell_width; - *y = month_cell_y + day_row * calitem->cell_height; - *width = calitem->cell_width; - *height = calitem->cell_height; - - return TRUE; -} - -/* month is from 0 to 11 */ -gboolean -e_calendar_item_get_date_for_offset (ECalendarItem *calitem, gint day_offset, - gint *year, gint *month, gint *day) -{ - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - GDate *start_date; - - g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); - - if (!e_calendar_item_get_date_range (calitem, &start_year, - &start_month, &start_day, - &end_year, &end_month, - &end_day)) - return FALSE; - - start_date = g_date_new_dmy (start_day, start_month + 1, start_year); - - g_date_add_days (start_date, day_offset); - - *year = g_date_get_year (start_date); - *month = g_date_get_month (start_date) - 1; - *day = g_date_get_day (start_date); - - return TRUE; -} - -/* the arg month is from 0 to 11 */ -static gboolean -e_calendar_item_get_offset_for_date (ECalendarItem *calitem, - gint year, gint month, gint day, - gint *offset) -{ - gint start_year, start_month, start_day; - gint end_year, end_month, end_day; - GDate *start_date, *end_date; - - *offset = 0; - g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); - - if (!e_calendar_item_get_date_range (calitem, &start_year, - &start_month, &start_day, - &end_year, &end_month, - &end_day)) - return FALSE; - - start_date = g_date_new_dmy (start_day, start_month + 1, start_year); - end_date = g_date_new_dmy (day, month + 1, year); - - *offset = g_date_days_between (start_date, end_date); - g_free (start_date); - g_free (end_date); - - return TRUE; -} - -gint -e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem, - gint year, gint month) -{ - struct tm tmp_tm; - gint start_weekday, days_from_week_start; - - memset (&tmp_tm, 0, sizeof (tmp_tm)); - tmp_tm.tm_year = year - 1900; - tmp_tm.tm_mon = month; - tmp_tm.tm_mday = 1; - tmp_tm.tm_isdst = -1; - mktime (&tmp_tm); - start_weekday = (tmp_tm.tm_wday + 6) % 7; /* 0 to 6 */ - days_from_week_start = (start_weekday + 7 - calitem->week_start_day) - % 7; - return days_from_week_start; -} - -static void -ea_calendar_set_focus_object (EaCalendarItem *ea_calitem, AtkObject *item_cell) -{ - AtkStateSet *state_set, *old_state_set; - AtkObject *old_cell; - - old_cell = (AtkObject *)g_object_get_data (G_OBJECT(ea_calitem), "gail-focus-object"); - if (old_cell && EA_IS_CALENDAR_CELL (old_cell)) { - old_state_set = atk_object_ref_state_set (old_cell); - atk_state_set_remove_state (old_state_set, ATK_STATE_FOCUSED); - g_object_unref (old_state_set); - } - if (old_cell) - g_object_unref (old_cell); - - state_set = atk_object_ref_state_set (item_cell); - atk_state_set_add_state (state_set, ATK_STATE_FOCUSED); - g_object_set_data (G_OBJECT(ea_calitem), "gail-focus-object", item_cell); - g_object_unref (state_set); -} diff --git a/widgets/misc/a11y/ea-calendar-item.h b/widgets/misc/a11y/ea-calendar-item.h deleted file mode 100644 index 36cc671a3b..0000000000 --- a/widgets/misc/a11y/ea-calendar-item.h +++ /dev/null @@ -1,68 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#ifndef __EA_CALENDAR_ITEM_H__ -#define __EA_CALENDAR_ITEM_H__ - -#include -#include - -G_BEGIN_DECLS - -#define EA_TYPE_CALENDAR_ITEM (ea_calendar_item_get_type ()) -#define EA_CALENDAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CALENDAR_ITEM, EaCalendarItem)) -#define EA_CALENDAR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CALENDAR_ITEM, EaCalendarItemClass)) -#define EA_IS_CALENDAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CALENDAR_ITEM)) -#define EA_IS_CALENDAR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CALENDAR_ITEM)) -#define EA_CALENDAR_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CALENDAR_ITEM, EaCalendarItemClass)) - -typedef struct _EaCalendarItem EaCalendarItem; -typedef struct _EaCalendarItemClass EaCalendarItemClass; - -struct _EaCalendarItem -{ - AtkGObjectAccessible parent; -}; - -GType ea_calendar_item_get_type (void); - -struct _EaCalendarItemClass -{ - AtkGObjectAccessibleClass parent_class; -}; - -AtkObject *ea_calendar_item_new (GObject *obj); -gboolean e_calendar_item_get_day_extents (ECalendarItem *calitem, - gint year, gint month, gint date, - gint *x, gint *y, - gint *width, gint *height); -gboolean e_calendar_item_get_date_for_offset (ECalendarItem *calitem, - gint day_offset, - gint *year, gint *month, - gint *day); -gint e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem, - gint year, gint month); - -G_END_DECLS - - -#endif /* __EA_CALENDAR_ITEM_H__ */ diff --git a/widgets/misc/a11y/ea-widgets.c b/widgets/misc/a11y/ea-widgets.c deleted file mode 100644 index 9deede235e..0000000000 --- a/widgets/misc/a11y/ea-widgets.c +++ /dev/null @@ -1,32 +0,0 @@ -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -#include "a11y/ea-factory.h" -#include "ea-calendar-item.h" -#include "ea-widgets.h" - -EA_FACTORY_GOBJECT (EA_TYPE_CALENDAR_ITEM, ea_calendar_item, ea_calendar_item_new) - -void e_calendar_item_a11y_init (void) -{ - EA_SET_FACTORY (e_calendar_item_get_type (), ea_calendar_item); -} diff --git a/widgets/misc/a11y/ea-widgets.h b/widgets/misc/a11y/ea-widgets.h deleted file mode 100644 index 495222ae05..0000000000 --- a/widgets/misc/a11y/ea-widgets.h +++ /dev/null @@ -1,32 +0,0 @@ -/* - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - * - * Authors: - * Bolian Yin - * - * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) - * - */ - -/* Evolution Accessibility -*/ - -#ifndef _EA_WIDGETS_H__ -#define _EA_WIDGETS_H__ - -void e_calendar_item_a11y_init (void); - -#endif /* _EA_WIDGETS_H__ */ diff --git a/widgets/misc/e-calendar-item.c b/widgets/misc/e-calendar-item.c index 9c9bd94b15..890355620b 100644 --- a/widgets/misc/e-calendar-item.c +++ b/widgets/misc/e-calendar-item.c @@ -26,7 +26,7 @@ #endif #include "e-calendar-item.h" -#include "a11y/ea-widgets.h" +#include "ea-widgets.h" #include #include diff --git a/widgets/misc/ea-calendar-cell.c b/widgets/misc/ea-calendar-cell.c new file mode 100644 index 0000000000..af9471c5af --- /dev/null +++ b/widgets/misc/ea-calendar-cell.c @@ -0,0 +1,387 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include +#include +#include "ea-calendar-cell.h" +#include "ea-calendar-item.h" +#include "a11y/ea-factory.h" + +/* ECalendarCell */ + +static void e_calendar_cell_class_init (ECalendarCellClass *class); + +EA_FACTORY_GOBJECT (EA_TYPE_CALENDAR_CELL, ea_calendar_cell, ea_calendar_cell_new) + +GType +e_calendar_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (ECalendarCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) e_calendar_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (ECalendarCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + type = g_type_register_static (G_TYPE_OBJECT, + "ECalendarCell", &tinfo, 0); + } + + return type; +} + +static void +e_calendar_cell_class_init (ECalendarCellClass *class) +{ + EA_SET_FACTORY (e_calendar_cell_get_type (), ea_calendar_cell); +} + +ECalendarCell * +e_calendar_cell_new (ECalendarItem *calitem, gint row, gint column) +{ + GObject *object; + ECalendarCell *cell; + + g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), NULL); + + object = g_object_new (E_TYPE_CALENDAR_CELL, NULL); + cell = E_CALENDAR_CELL (object); + cell->calitem = calitem; + cell->row = row; + cell->column = column; + +#ifdef ACC_DEBUG + g_print ("EvoAcc: e_calendar_cell created %p\n", (gpointer)cell); +#endif + + return cell; +} + +/* EaCalendarCell */ + +static void ea_calendar_cell_class_init (EaCalendarCellClass *klass); +static void ea_calendar_cell_init (EaCalendarCell *a11y); + +static G_CONST_RETURN gchar * ea_calendar_cell_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_calendar_cell_get_description (AtkObject *accessible); +static AtkObject * ea_calendar_cell_get_parent (AtkObject *accessible); +static gint ea_calendar_cell_get_index_in_parent (AtkObject *accessible); +static AtkStateSet *ea_calendar_cell_ref_state_set (AtkObject *accessible); + +/* component interface */ +static void atk_component_interface_init (AtkComponentIface *iface); +static void component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, + gint *width, gint *height, + AtkCoordType coord_type); +static gboolean component_interface_grab_focus (AtkComponent *component); + +static gpointer parent_class = NULL; + +#ifdef ACC_DEBUG +static gint n_ea_calendar_cell_created = 0, n_ea_calendar_cell_destroyed = 0; +static void ea_calendar_cell_finalize (GObject *object); +#endif + +GType +ea_calendar_cell_get_type (void) +{ + static GType type = 0; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaCalendarCellClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_calendar_cell_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaCalendarCell), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) ea_calendar_cell_init, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_component_info = { + (GInterfaceInitFunc) atk_component_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + type = g_type_register_static (ATK_TYPE_GOBJECT_ACCESSIBLE, + "EaCalendarCell", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_COMPONENT, + &atk_component_info); + } + + return type; +} + +static void +ea_calendar_cell_class_init (EaCalendarCellClass *klass) +{ + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + +#ifdef ACC_DEBUG + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + gobject_class->finalize = ea_calendar_cell_finalize; +#endif + + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_calendar_cell_get_name; + class->get_description = ea_calendar_cell_get_description; + + class->get_parent = ea_calendar_cell_get_parent; + class->get_index_in_parent = ea_calendar_cell_get_index_in_parent; + class->ref_state_set = ea_calendar_cell_ref_state_set; +} + +static void +ea_calendar_cell_init (EaCalendarCell *a11y) +{ + a11y->state_set = atk_state_set_new (); + atk_state_set_add_state (a11y->state_set, ATK_STATE_TRANSIENT); + atk_state_set_add_state (a11y->state_set, ATK_STATE_ENABLED); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SENSITIVE); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SELECTABLE); + atk_state_set_add_state (a11y->state_set, ATK_STATE_SHOWING); + atk_state_set_add_state (a11y->state_set, ATK_STATE_FOCUSABLE); +} + +AtkObject* +ea_calendar_cell_new (GObject *obj) +{ + gpointer object; + AtkObject *atk_object; + + g_return_val_if_fail (E_IS_CALENDAR_CELL (obj), NULL); + object = g_object_new (EA_TYPE_CALENDAR_CELL, NULL); + atk_object = ATK_OBJECT (object); + atk_object_initialize (atk_object, obj); + atk_object->role = ATK_ROLE_TABLE_CELL; + +#ifdef ACC_DEBUG + ++n_ea_calendar_cell_created; + g_print ("ACC_DEBUG: n_ea_calendar_cell_created = %d\n", + n_ea_calendar_cell_created); +#endif + return atk_object; +} + +#ifdef ACC_DEBUG +static void ea_calendar_cell_finalize (GObject *object) +{ + G_OBJECT_CLASS (parent_class)->finalize (object); + + ++n_ea_calendar_cell_destroyed; + g_print ("ACC_DEBUG: n_ea_calendar_cell_destroyed = %d\n", + n_ea_calendar_cell_destroyed); +} +#endif + +static G_CONST_RETURN gchar * +ea_calendar_cell_get_name (AtkObject *accessible) +{ + GObject *g_obj; + + g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), NULL); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + /* defunct object*/ + return NULL; + + if (!accessible->name) { + AtkObject *atk_obj; + EaCalendarItem *ea_calitem; + ECalendarCell *cell; + gint day_index; + gint year, month, day; + gchar buffer[128]; + + cell = E_CALENDAR_CELL (g_obj); + atk_obj = ea_calendar_cell_get_parent (accessible); + ea_calitem = EA_CALENDAR_ITEM (atk_obj); + day_index = atk_table_get_index_at (ATK_TABLE (ea_calitem), + cell->row, cell->column); + e_calendar_item_get_date_for_offset (cell->calitem, day_index, + &year, &month, &day); + + g_snprintf (buffer, 128, "%d-%d-%d", year, month + 1, day); + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, buffer); + } + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_calendar_cell_get_description (AtkObject *accessible) +{ + return ea_calendar_cell_get_name (accessible); +} + +static AtkObject * +ea_calendar_cell_get_parent (AtkObject *accessible) +{ + GObject *g_obj; + ECalendarCell *cell; + ECalendarItem *calitem; + + g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), NULL); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + /* defunct object*/ + return NULL; + + cell = E_CALENDAR_CELL (g_obj); + calitem = cell->calitem; + return atk_gobject_accessible_for_object (G_OBJECT (calitem)); +} + +static gint +ea_calendar_cell_get_index_in_parent (AtkObject *accessible) +{ + GObject *g_obj; + ECalendarCell *cell; + AtkObject *parent; + + g_return_val_if_fail (EA_IS_CALENDAR_CELL (accessible), -1); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + return -1; + cell = E_CALENDAR_CELL (g_obj); + parent = atk_object_get_parent (accessible); + return atk_table_get_index_at (ATK_TABLE (parent), + cell->row, cell->column); +} + +static AtkStateSet * +ea_calendar_cell_ref_state_set (AtkObject *accessible) +{ + EaCalendarCell *atk_cell = EA_CALENDAR_CELL (accessible); + + g_return_val_if_fail (atk_cell->state_set, NULL); + + g_object_ref(atk_cell->state_set); + + return atk_cell->state_set; + +} + +/* Atk Component Interface */ + +static void +atk_component_interface_init (AtkComponentIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->get_extents = component_interface_get_extents; + iface->grab_focus = component_interface_grab_focus; +} + +static void +component_interface_get_extents (AtkComponent *component, + gint *x, gint *y, gint *width, gint *height, + AtkCoordType coord_type) +{ + GObject *g_obj; + AtkObject *atk_obj, *atk_canvas; + ECalendarCell *cell; + ECalendarItem *calitem; + EaCalendarItem *ea_calitem; + gint day_index; + gint year, month, day; + gint canvas_x, canvas_y, canvas_width, canvas_height; + + *x = *y = *width = *height = 0; + + g_return_if_fail (EA_IS_CALENDAR_CELL (component)); + + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(component)); + if (!g_obj) + /* defunct object*/ + return; + + cell = E_CALENDAR_CELL (g_obj); + calitem = cell->calitem; + atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); + ea_calitem = EA_CALENDAR_ITEM (atk_obj); + day_index = atk_table_get_index_at (ATK_TABLE (ea_calitem), + cell->row, cell->column); + e_calendar_item_get_date_for_offset (calitem, day_index, + &year, &month, &day); + + if (!e_calendar_item_get_day_extents (calitem, + year, month, day, + x, y, width, height)) + return; + atk_canvas = atk_object_get_parent (ATK_OBJECT (ea_calitem)); + atk_component_get_extents (ATK_COMPONENT (atk_canvas), + &canvas_x, &canvas_y, + &canvas_width, &canvas_height, + coord_type); + *x += canvas_x; + *y += canvas_y; +} + +static gboolean +component_interface_grab_focus (AtkComponent *component) +{ + GObject *g_obj; + GtkWidget *toplevel; + AtkObject *ea_calitem; + ECalendarItem *calitem; + EaCalendarCell *a11y; + gint index; + + a11y = EA_CALENDAR_CELL (component); + ea_calitem = ea_calendar_cell_get_parent (ATK_OBJECT (a11y)); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(ea_calitem)); + calitem = E_CALENDAR_ITEM (g_obj); + + index = atk_object_get_index_in_parent (ATK_OBJECT (a11y)); + + atk_selection_clear_selection (ATK_SELECTION (ea_calitem)); + atk_selection_add_selection (ATK_SELECTION (ea_calitem), index); + + gtk_widget_grab_focus (GTK_WIDGET (GNOME_CANVAS_ITEM (calitem)->canvas)); + toplevel = gtk_widget_get_toplevel (GTK_WIDGET (GNOME_CANVAS_ITEM (calitem)->canvas)); + if (toplevel && GTK_WIDGET_TOPLEVEL (toplevel)) + gtk_window_present (GTK_WINDOW (toplevel)); + + return TRUE; + +} diff --git a/widgets/misc/ea-calendar-cell.h b/widgets/misc/ea-calendar-cell.h new file mode 100644 index 0000000000..fa68fdca55 --- /dev/null +++ b/widgets/misc/ea-calendar-cell.h @@ -0,0 +1,86 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_CALENDAR_CELL_H__ +#define __EA_CALENDAR_CELL_H__ + +#include +#include "misc/e-calendar-item.h" + +G_BEGIN_DECLS + +#define E_TYPE_CALENDAR_CELL (e_calendar_cell_get_type ()) +#define E_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_TYPE_CALENDAR_CELL, ECalendarCell)) +#define E_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_TYPE_CALENDAR_CELL, ECalendarCellClass)) +#define E_IS_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_TYPE_CALENDAR_CELL)) +#define E_IS_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), E_TYPE_CALENDAR_CELL)) +#define E_CALENDAR_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), E_TYPE_CALENDAR_CELL, ECalendarCellClass)) + +typedef struct _ECalendarCell ECalendarCell; +typedef struct _ECalendarCellClass ECalendarCellClass; + +struct _ECalendarCell +{ + GObject parent; + ECalendarItem *calitem; + gint row; + gint column; +}; + +GType e_calendar_cell_get_type (void); + +struct _ECalendarCellClass +{ + GObjectClass parent_class; +}; + +ECalendarCell * e_calendar_cell_new (ECalendarItem *calitem, + gint row, gint column); + +#define EA_TYPE_CALENDAR_CELL (ea_calendar_cell_get_type ()) +#define EA_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CALENDAR_CELL, EaCalendarCell)) +#define EA_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CALENDAR_CELL, EaCalendarCellClass)) +#define EA_IS_CALENDAR_CELL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CALENDAR_CELL)) +#define EA_IS_CALENDAR_CELL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CALENDAR_CELL)) +#define EA_CALENDAR_CELL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CALENDAR_CELL, EaCalendarCellClass)) + +typedef struct _EaCalendarCell EaCalendarCell; +typedef struct _EaCalendarCellClass EaCalendarCellClass; + +struct _EaCalendarCell +{ + AtkGObjectAccessible parent; + AtkStateSet *state_set; +}; + +GType ea_calendar_cell_get_type (void); + +struct _EaCalendarCellClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject* ea_calendar_cell_new (GObject *gobj); + +G_END_DECLS + +#endif /* __EA_CALENDAR_CELL_H__ */ diff --git a/widgets/misc/ea-calendar-item.c b/widgets/misc/ea-calendar-item.c new file mode 100644 index 0000000000..56a01b510b --- /dev/null +++ b/widgets/misc/ea-calendar-item.c @@ -0,0 +1,1314 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "ea-calendar-item.h" +#include "ea-calendar-cell.h" +#include "a11y/ea-cell-table.h" + +#define EA_CALENDAR_COLUMN_NUM E_CALENDAR_COLS_PER_MONTH + +/* EaCalendarItem */ +static void ea_calendar_item_class_init (EaCalendarItemClass *klass); +static void ea_calendar_item_finalize (GObject *object); + +static G_CONST_RETURN gchar * ea_calendar_item_get_name (AtkObject *accessible); +static G_CONST_RETURN gchar * ea_calendar_item_get_description (AtkObject *accessible); +static gint ea_calendar_item_get_n_children (AtkObject *accessible); +static AtkObject *ea_calendar_item_ref_child (AtkObject *accessible, gint index); +static AtkStateSet* ea_calendar_item_ref_state_set (AtkObject *accessible); + +/* atk table interface */ +static void atk_table_interface_init (AtkTableIface *iface); +static gint table_interface_get_index_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_column_at_index (AtkTable *table, + gint index); +static gint table_interface_get_row_at_index (AtkTable *table, + gint index); +static AtkObject* table_interface_ref_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_n_rows (AtkTable *table); +static gint table_interface_get_n_columns (AtkTable *table); +static gint table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_row_extent_at (AtkTable *table, + gint row, + gint column); + +static gboolean table_interface_is_row_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_column_selected (AtkTable *table, + gint row); +static gboolean table_interface_is_selected (AtkTable *table, + gint row, + gint column); +static gint table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected); +static gint table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected); +static gboolean table_interface_add_row_selection (AtkTable *table, gint row); +static gboolean table_interface_remove_row_selection (AtkTable *table, + gint row); +static gboolean table_interface_add_column_selection (AtkTable *table, + gint column); +static gboolean table_interface_remove_column_selection (AtkTable *table, + gint column); +static AtkObject* table_interface_get_row_header (AtkTable *table, gint row); +static AtkObject* table_interface_get_column_header (AtkTable *table, + gint in_col); +static AtkObject* table_interface_get_caption (AtkTable *table); + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, gint in_col); + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, gint row); + +static AtkObject* table_interface_get_summary (AtkTable *table); + +/* atk selection interface */ +static void atk_selection_interface_init (AtkSelectionIface *iface); +static gboolean selection_interface_add_selection (AtkSelection *selection, + gint i); +static gboolean selection_interface_clear_selection (AtkSelection *selection); +static AtkObject* selection_interface_ref_selection (AtkSelection *selection, + gint i); +static gint selection_interface_get_selection_count (AtkSelection *selection); +static gboolean selection_interface_is_child_selected (AtkSelection *selection, + gint i); + +/* callbacks */ +static void selection_preview_change_cb (ECalendarItem *calitem); +static void date_range_changed_cb (ECalendarItem *calitem); + +/* helpers */ +static EaCellTable *ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem); +static void ea_calendar_item_destory_cell_data (EaCalendarItem *ea_calitem); +static gboolean ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, + gint column, + gchar *buffer, + gint buffer_size); +static gboolean ea_calendar_item_get_row_label (EaCalendarItem *ea_calitem, + gint row, + gchar *buffer, + gint buffer_size); +static gboolean e_calendar_item_get_offset_for_date (ECalendarItem *calitem, + gint year, gint month, gint day, + gint *offset); +static void ea_calendar_set_focus_object (EaCalendarItem *ea_calitem, + AtkObject *item_cell); + +#ifdef ACC_DEBUG +static gint n_ea_calendar_item_created = 0; +static gint n_ea_calendar_item_destroyed = 0; +#endif + +static gpointer parent_class = NULL; + +GType +ea_calendar_item_get_type (void) +{ + static GType type = 0; + AtkObjectFactory *factory; + GTypeQuery query; + GType derived_atk_type; + + if (!type) { + static GTypeInfo tinfo = { + sizeof (EaCalendarItemClass), + (GBaseInitFunc) NULL, /* base init */ + (GBaseFinalizeFunc) NULL, /* base finalize */ + (GClassInitFunc) ea_calendar_item_class_init, /* class init */ + (GClassFinalizeFunc) NULL, /* class finalize */ + NULL, /* class data */ + sizeof (EaCalendarItem), /* instance size */ + 0, /* nb preallocs */ + (GInstanceInitFunc) NULL, /* instance init */ + NULL /* value table */ + }; + + static const GInterfaceInfo atk_table_info = { + (GInterfaceInitFunc) atk_table_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + static const GInterfaceInfo atk_selection_info = { + (GInterfaceInitFunc) atk_selection_interface_init, + (GInterfaceFinalizeFunc) NULL, + NULL + }; + + /* + * Figure out the size of the class and instance + * we are run-time deriving from (GailCanvasItem, in this case) + */ + + factory = atk_registry_get_factory (atk_get_default_registry (), + GNOME_TYPE_CANVAS_ITEM); + derived_atk_type = atk_object_factory_get_accessible_type (factory); + g_type_query (derived_atk_type, &query); + + tinfo.class_size = query.class_size; + tinfo.instance_size = query.instance_size; + + type = g_type_register_static (derived_atk_type, + "EaCalendarItem", &tinfo, 0); + g_type_add_interface_static (type, ATK_TYPE_TABLE, + &atk_table_info); + g_type_add_interface_static (type, ATK_TYPE_SELECTION, + &atk_selection_info); + } + + return type; +} + +static void +ea_calendar_item_class_init (EaCalendarItemClass *klass) +{ + GObjectClass *gobject_class = G_OBJECT_CLASS (klass); + AtkObjectClass *class = ATK_OBJECT_CLASS (klass); + + gobject_class->finalize = ea_calendar_item_finalize; + parent_class = g_type_class_peek_parent (klass); + + class->get_name = ea_calendar_item_get_name; + class->get_description = ea_calendar_item_get_description; + class->ref_state_set = ea_calendar_item_ref_state_set; + + class->get_n_children = ea_calendar_item_get_n_children; + class->ref_child = ea_calendar_item_ref_child; +} + +AtkObject* +ea_calendar_item_new (GObject *obj) +{ + gpointer object; + AtkObject *atk_object; + AtkObject *item_cell; + + g_return_val_if_fail (E_IS_CALENDAR_ITEM (obj), NULL); + object = g_object_new (EA_TYPE_CALENDAR_ITEM, NULL); + atk_object = ATK_OBJECT (object); + atk_object_initialize (atk_object, obj); + atk_object->role = ATK_ROLE_CALENDAR; + + item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_object), + 0); + if (item_cell) + ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_object), item_cell); + +#ifdef ACC_DEBUG + ++n_ea_calendar_item_created; + g_print ("ACC_DEBUG: n_ea_calendar_item_created = %d\n", + n_ea_calendar_item_created); +#endif + /* connect signal handlers */ + g_signal_connect (obj, "selection_preview_changed", + G_CALLBACK (selection_preview_change_cb), + atk_object); + g_signal_connect (obj, "date_range_changed", + G_CALLBACK (date_range_changed_cb), + atk_object); + + return atk_object; +} + +static void +ea_calendar_item_finalize (GObject *object) +{ + EaCalendarItem *ea_calitem; + + g_return_if_fail (EA_IS_CALENDAR_ITEM (object)); + + ea_calitem = EA_CALENDAR_ITEM (object); + + /* Free the allocated cell data */ + ea_calendar_item_destory_cell_data (ea_calitem); + + G_OBJECT_CLASS (parent_class)->finalize (object); +#ifdef ACC_DEBUG + ++n_ea_calendar_item_destroyed; + printf ("ACC_DEBUG: n_ea_calendar_item_destroyed = %d\n", + n_ea_calendar_item_destroyed); +#endif +} + +static G_CONST_RETURN gchar * +ea_calendar_item_get_name (AtkObject *accessible) +{ + GObject *g_obj; + ECalendarItem *calitem; + gint start_year, start_month, start_day; + gint end_year, end_month, end_day; + gchar *name_str = NULL; + gchar buffer_start[128] = ""; + gchar buffer_end[128] = ""; + struct tm day_start = { 0 }; + struct tm day_end = { 0 }; + + g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), NULL); + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + return NULL; + g_return_val_if_fail (E_IS_CALENDAR_ITEM (g_obj), NULL); + + calitem = E_CALENDAR_ITEM (g_obj); + if (e_calendar_item_get_date_range (calitem, + &start_year, &start_month, &start_day, + &end_year, &end_month, &end_day)) { + + day_start.tm_year = start_year - 1900; + day_start.tm_mon = start_month; + day_start.tm_mday = start_day; + day_start.tm_isdst = -1; + e_utf8_strftime (buffer_start, sizeof (buffer_start), _("%d %B %Y"), &day_start); + + day_end.tm_year = end_year - 1900; + day_end.tm_mon = end_month; + day_end.tm_mday = end_day; + day_end.tm_isdst = -1; + e_utf8_strftime (buffer_end, sizeof (buffer_end), _("%d %B %Y"), &day_end); + + name_str = g_strdup_printf (_("Calendar: from %s to %s"), buffer_start, buffer_end); + } + +#if 0 + if (e_calendar_item_get_selection (calitem, &select_start, &select_end)) { + GDate select_start, select_end; + gint year1, year2, month1, month2, day1, day2; + + year1 = g_date_get_year (&select_start); + month1 = g_date_get_month (&select_start); + day1 = g_date_get_day (&select_start); + + year2 = g_date_get_year (&select_end); + month2 = g_date_get_month (&select_end); + day2 = g_date_get_day (&select_end); + + sprintf (new_name + strlen (new_name), + " : current selection: from %d-%d-%d to %d-%d-%d.", + year1, month1, day1, + year2, month2, day2); + } +#endif + + ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_str); + g_free (name_str); + + return accessible->name; +} + +static G_CONST_RETURN gchar * +ea_calendar_item_get_description (AtkObject *accessible) +{ + if (accessible->description) + return accessible->description; + + return _("evolution calendar item"); +} + +static AtkStateSet* +ea_calendar_item_ref_state_set (AtkObject *accessible) +{ + AtkStateSet *state_set; + GObject *g_obj; + + state_set = ATK_OBJECT_CLASS (parent_class)->ref_state_set (accessible); + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE(accessible)); + if (!g_obj) + return state_set; + + atk_state_set_add_state (state_set, ATK_STATE_ENABLED); + atk_state_set_add_state (state_set, ATK_STATE_SENSITIVE); + + return state_set; +} + +static gint +ea_calendar_item_get_n_children (AtkObject *accessible) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + gint n_children = 0; + gint start_year, start_month, start_day; + gint end_year, end_month, end_day; + GDate *start_date, *end_date; + + g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), -1); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + calitem = E_CALENDAR_ITEM (g_obj); + if (!e_calendar_item_get_date_range (calitem, &start_year, + &start_month, &start_day, + &end_year, &end_month, + &end_day)) + return 0; + + start_date = g_date_new_dmy (start_day, start_month + 1, start_year); + end_date = g_date_new_dmy (end_day, end_month + 1, end_year); + + n_children = g_date_days_between (start_date, end_date) + 1; + g_free (start_date); + g_free (end_date); + return n_children; +} + +static AtkObject * +ea_calendar_item_ref_child (AtkObject *accessible, gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + gint n_children; + ECalendarCell *cell; + EaCellTable *cell_data; + EaCalendarItem *ea_calitem; + + g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible), NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (accessible); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + calitem = E_CALENDAR_ITEM (g_obj); + + n_children = ea_calendar_item_get_n_children (accessible); + if (index < 0 || index >= n_children) + return NULL; + + ea_calitem = EA_CALENDAR_ITEM (accessible); + cell_data = ea_calendar_item_get_cell_data (ea_calitem); + if (!cell_data) + return NULL; + + cell = ea_cell_table_get_cell_at_index (cell_data, index); + if (!cell) { + cell = e_calendar_cell_new (calitem, + index / EA_CALENDAR_COLUMN_NUM, + index % EA_CALENDAR_COLUMN_NUM); + ea_cell_table_set_cell_at_index (cell_data, index, cell); + g_object_unref (cell); + } + +#ifdef ACC_DEBUG + g_print ("AccDebug: ea_calendar_item children[%d]=%p\n", index, + (gpointer)cell); +#endif + return g_object_ref (atk_gobject_accessible_for_object (G_OBJECT(cell))); +} + +/* atk table interface */ + +static void +atk_table_interface_init (AtkTableIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->ref_at = table_interface_ref_at; + + iface->get_n_rows = table_interface_get_n_rows; + iface->get_n_columns = table_interface_get_n_columns; + iface->get_index_at = table_interface_get_index_at; + iface->get_column_at_index = table_interface_get_column_at_index; + iface->get_row_at_index = table_interface_get_row_at_index; + iface->get_column_extent_at = table_interface_get_column_extent_at; + iface->get_row_extent_at = table_interface_get_row_extent_at; + + iface->is_selected = table_interface_is_selected; + iface->get_selected_rows = table_interface_get_selected_rows; + iface->get_selected_columns = table_interface_get_selected_columns; + iface->is_row_selected = table_interface_is_row_selected; + iface->is_column_selected = table_interface_is_column_selected; + iface->add_row_selection = table_interface_add_row_selection; + iface->remove_row_selection = table_interface_remove_row_selection; + iface->add_column_selection = table_interface_add_column_selection; + iface->remove_column_selection = table_interface_remove_column_selection; + + iface->get_row_header = table_interface_get_row_header; + iface->get_column_header = table_interface_get_column_header; + iface->get_caption = table_interface_get_caption; + iface->get_summary = table_interface_get_summary; + iface->get_row_description = table_interface_get_row_description; + iface->get_column_description = table_interface_get_column_description; +} + +static AtkObject* +table_interface_ref_at (AtkTable *table, + gint row, + gint column) +{ + gint index; + + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + index = EA_CALENDAR_COLUMN_NUM * row + column; + return ea_calendar_item_ref_child (ATK_OBJECT (ea_calitem), index); +} + +static gint +table_interface_get_n_rows (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + gint n_children; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); + return (n_children - 1) / EA_CALENDAR_COLUMN_NUM + 1; +} + +static gint +table_interface_get_n_columns (AtkTable *table) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + return EA_CALENDAR_COLUMN_NUM; +} + +static gint +table_interface_get_index_at (AtkTable *table, + gint row, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + return row * EA_CALENDAR_COLUMN_NUM + column; +} + +static gint +table_interface_get_column_at_index (AtkTable *table, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + gint n_children; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); + if (index >= 0 && index < n_children) + return index % EA_CALENDAR_COLUMN_NUM; + return -1; +} + +static gint +table_interface_get_row_at_index (AtkTable *table, + gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + gint n_children; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return -1; + + n_children = ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem)); + if (index >= 0 && index < n_children) + return index / EA_CALENDAR_COLUMN_NUM; + return -1; +} + +static gint +table_interface_get_column_extent_at (AtkTable *table, + gint row, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + calitem = E_CALENDAR_ITEM (g_obj); + return calitem->cell_width; +} + +static gint +table_interface_get_row_extent_at (AtkTable *table, + gint row, gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + calitem = E_CALENDAR_ITEM (g_obj); + return calitem->cell_height; +} + +/* any day in the row is selected, the row is selected */ +static gboolean +table_interface_is_row_selected (AtkTable *table, + gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + gint n_rows; + ECalendarItem *calitem; + gint row_index_start, row_index_end; + gint sel_index_start, sel_index_end; + + GDate start_date, end_date; + + g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table), FALSE); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (table); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + n_rows = table_interface_get_n_rows (table); + if (row < 0 || row >= n_rows) + return FALSE; + + row_index_start = row * EA_CALENDAR_COLUMN_NUM; + row_index_end = row_index_start + EA_CALENDAR_COLUMN_NUM - 1; + + calitem = E_CALENDAR_ITEM (g_obj); + if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) + return FALSE; + + e_calendar_item_get_offset_for_date (calitem, + g_date_get_year (&start_date), + g_date_get_month (&start_date), + g_date_get_day (&start_date), + &sel_index_start); + e_calendar_item_get_offset_for_date (calitem, + g_date_get_year (&end_date), + g_date_get_month (&end_date), + g_date_get_day (&end_date), + &sel_index_end); + + if ((sel_index_start < row_index_start && + sel_index_end >= row_index_start) || + (sel_index_start >= row_index_start && + sel_index_start <= row_index_end)) + return TRUE; + return FALSE; +} + +static gboolean +table_interface_is_selected (AtkTable *table, + gint row, + gint column) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + gint n_rows, n_columns; + ECalendarItem *calitem; + gint index; + gint sel_index_start, sel_index_end; + + GDate start_date, end_date; + + g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table), FALSE); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (table); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + n_rows = table_interface_get_n_rows (table); + if (row < 0 || row >= n_rows) + return FALSE; + n_columns = table_interface_get_n_columns (table); + if (column < 0 || column >= n_columns) + return FALSE; + + index = table_interface_get_index_at (table, row, column); + + calitem = E_CALENDAR_ITEM (g_obj); + if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) + return FALSE; + + e_calendar_item_get_offset_for_date (calitem, + g_date_get_year (&start_date), + g_date_get_month (&start_date), + g_date_get_day (&start_date), + &sel_index_start); + e_calendar_item_get_offset_for_date (calitem, + g_date_get_year (&end_date), + g_date_get_month (&end_date), + g_date_get_day (&end_date), &sel_index_end); + + if (sel_index_start <= index && sel_index_end >= index) + return TRUE; + return FALSE; +} + +static gboolean +table_interface_is_column_selected (AtkTable *table, + gint column) +{ + return FALSE; +} + +static gint +table_interface_get_selected_rows (AtkTable *table, + gint **rows_selected) +{ + *rows_selected = NULL; + return -1; +} + +static gint +table_interface_get_selected_columns (AtkTable *table, + gint **columns_selected) +{ + *columns_selected = NULL; + return -1; +} + +static gboolean +table_interface_add_row_selection (AtkTable *table, + gint row) +{ + return FALSE; +} + +static gboolean +table_interface_remove_row_selection (AtkTable *table, + gint row) +{ + return FALSE; +} + +static gboolean +table_interface_add_column_selection (AtkTable *table, + gint column) +{ + return FALSE; +} + +static gboolean +table_interface_remove_column_selection (AtkTable *table, + gint column) +{ + /* FIXME: NOT IMPLEMENTED */ + return FALSE; +} + +static AtkObject* +table_interface_get_row_header (AtkTable *table, + gint row) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_column_header (AtkTable *table, + gint in_col) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static AtkObject* +table_interface_get_caption (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +static G_CONST_RETURN gchar * +table_interface_get_column_description (AtkTable *table, gint in_col) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + const gchar *description = NULL; + EaCellTable *cell_data; + gint n_columns; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + n_columns = table_interface_get_n_columns (table); + if (in_col < 0 || in_col >= n_columns) + return NULL; + cell_data = ea_calendar_item_get_cell_data (ea_calitem); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_column_label (cell_data, in_col); + if (!description) { + gchar buffer[128] = "column description"; + ea_calendar_item_get_column_label (ea_calitem, in_col, + buffer, sizeof (buffer)); + ea_cell_table_set_column_label (cell_data, in_col, buffer); + description = ea_cell_table_get_column_label (cell_data, + in_col); + } + return description; +} + +static G_CONST_RETURN gchar * +table_interface_get_row_description (AtkTable *table, gint row) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (table); + const gchar *description = NULL; + EaCellTable *cell_data; + gint n_rows; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + n_rows = table_interface_get_n_rows (table); + if (row < 0 || row >= n_rows) + return NULL; + cell_data = ea_calendar_item_get_cell_data (ea_calitem); + if (!cell_data) + return NULL; + + description = ea_cell_table_get_row_label (cell_data, row); + if (!description) { + gchar buffer[128] = "row description"; + ea_calendar_item_get_row_label (ea_calitem, row, + buffer, sizeof (buffer)); + ea_cell_table_set_row_label (cell_data, row, buffer); + description = ea_cell_table_get_row_label (cell_data, + row); + } + return description; +} + +static AtkObject* +table_interface_get_summary (AtkTable *table) +{ + /* FIXME: NOT IMPLEMENTED */ + return NULL; +} + +/* atkselection interface */ + +static void +atk_selection_interface_init (AtkSelectionIface *iface) +{ + g_return_if_fail (iface != NULL); + + iface->add_selection = selection_interface_add_selection; + iface->clear_selection = selection_interface_clear_selection; + iface->ref_selection = selection_interface_ref_selection; + iface->get_selection_count = selection_interface_get_selection_count; + iface->is_child_selected = selection_interface_is_child_selected; +} + +static gboolean +selection_interface_add_selection (AtkSelection *selection, gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); + gint year, month, day; + GDate start_date, end_date; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + calitem = E_CALENDAR_ITEM (g_obj); + if (!e_calendar_item_get_date_for_offset (calitem, index, + &year, &month, &day)) + return FALSE; + + /* FIXME: not support mulit-selection */ + g_date_set_dmy (&start_date, day, month + 1, year); + end_date = start_date; + e_calendar_item_set_selection (calitem, &start_date, &end_date); + return TRUE; +} + +static gboolean +selection_interface_clear_selection (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + calitem = E_CALENDAR_ITEM (g_obj); + e_calendar_item_set_selection (calitem, NULL, NULL); + + return TRUE; +} + +static AtkObject* +selection_interface_ref_selection (AtkSelection *selection, gint i) +{ + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); + gint count, sel_offset; + GDate start_date, end_date; + + count = selection_interface_get_selection_count (selection); + if (i < 0 || i >= count) + return NULL; + + g_obj = atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_calitem)); + + calitem = E_CALENDAR_ITEM (g_obj); + if (!e_calendar_item_get_selection (calitem, &start_date, &end_date)) + return NULL; + if (!e_calendar_item_get_offset_for_date (calitem, + g_date_get_year (&start_date), + g_date_get_month (&start_date) - 1, + g_date_get_day (&start_date), + &sel_offset)) + return NULL; + + return ea_calendar_item_ref_child (ATK_OBJECT (selection), sel_offset + i); +} + +static gint +selection_interface_get_selection_count (AtkSelection *selection) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); + GDate start_date, end_date; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return 0; + + calitem = E_CALENDAR_ITEM (g_obj); + if (e_calendar_item_get_selection (calitem, &start_date, &end_date)) + return g_date_days_between (&start_date, &end_date) + 1; + else + return 0; +} + +static gboolean +selection_interface_is_child_selected (AtkSelection *selection, gint index) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCalendarItem* ea_calitem = EA_CALENDAR_ITEM (selection); + gint row, column, n_children; + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + n_children = atk_object_get_n_accessible_children (ATK_OBJECT (selection)); + if (index < 0 || index >= n_children) + return FALSE; + + row = index / EA_CALENDAR_COLUMN_NUM; + column = index % EA_CALENDAR_COLUMN_NUM; + + return table_interface_is_selected (ATK_TABLE (selection), row, column); +} + +/* callbacks */ + +static void +selection_preview_change_cb (ECalendarItem *calitem) +{ + AtkObject *atk_obj; + AtkObject *item_cell; + + g_return_if_fail (E_IS_CALENDAR_ITEM (calitem)); + atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); + ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj)); + + /* only deal with the first selected child, for now */ + item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_obj), + 0); + + if (item_cell) + ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj), item_cell); + + g_signal_emit_by_name (atk_obj, + "active-descendant-changed", + item_cell); + g_signal_emit_by_name (atk_obj, "selection_changed"); +} + +static void +date_range_changed_cb (ECalendarItem *calitem) +{ + AtkObject *atk_obj; + AtkObject *item_cell; + + g_return_if_fail (E_IS_CALENDAR_ITEM (calitem)); + atk_obj = atk_gobject_accessible_for_object (G_OBJECT (calitem)); + ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj)); + + item_cell = atk_selection_ref_selection (ATK_SELECTION (atk_obj), + 0); + if (item_cell) + ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj), item_cell); + + g_signal_emit_by_name (atk_obj, "model_changed"); +} + +/* helpers */ + +static EaCellTable * +ea_calendar_item_get_cell_data (EaCalendarItem *ea_calitem) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + EaCellTable *cell_data; + + g_return_val_if_fail (ea_calitem, NULL); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return NULL; + + cell_data = g_object_get_data (G_OBJECT(ea_calitem), + "ea-calendar-cell-table"); + + if (!cell_data) { + gint n_cells = ea_calendar_item_get_n_children (ATK_OBJECT(ea_calitem)); + cell_data = ea_cell_table_create (n_cells/EA_CALENDAR_COLUMN_NUM, + EA_CALENDAR_COLUMN_NUM, + FALSE); + g_object_set_data (G_OBJECT(ea_calitem), + "ea-calendar-cell-table", cell_data); + } + return cell_data; +} + +static void +ea_calendar_item_destory_cell_data (EaCalendarItem *ea_calitem) +{ + EaCellTable *cell_data; + + g_return_if_fail (ea_calitem); + + cell_data = g_object_get_data (G_OBJECT(ea_calitem), + "ea-calendar-cell-table"); + if (cell_data) { + g_object_set_data (G_OBJECT(ea_calitem), + "ea-calendar-cell-table", NULL); + ea_cell_table_destroy (cell_data); + } +} + +static gboolean +ea_calendar_item_get_row_label (EaCalendarItem *ea_calitem, gint row, + gchar *buffer, gint buffer_size) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + gint index, week_num; + gint year, month, day; + + g_return_val_if_fail (ea_calitem, FALSE); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + calitem = E_CALENDAR_ITEM (g_obj); + + index = atk_table_get_index_at (ATK_TABLE (ea_calitem), row, 0); + if (!e_calendar_item_get_date_for_offset (calitem, index, + &year, &month, &day)) + return FALSE; + + week_num = e_calendar_item_get_week_number (calitem, + day, month, year); + + g_snprintf (buffer, buffer_size, "week number : %d", week_num); + return TRUE; +} + +static gboolean +ea_calendar_item_get_column_label (EaCalendarItem *ea_calitem, gint column, + gchar *buffer, gint buffer_size) +{ + AtkGObjectAccessible *atk_gobj; + GObject *g_obj; + ECalendarItem *calitem; + const gchar *abbr_name; + + g_return_val_if_fail (ea_calitem, FALSE); + + atk_gobj = ATK_GOBJECT_ACCESSIBLE (ea_calitem); + g_obj = atk_gobject_accessible_get_object (atk_gobj); + if (!g_obj) + return FALSE; + + /* Columns are 0 = Monday ... 6 = Sunday */ + calitem = E_CALENDAR_ITEM (g_obj); + abbr_name = e_get_weekday_name (column + 1, TRUE); + g_strlcpy (buffer, abbr_name, buffer_size); + + return TRUE; +} + +/* the coordinate the e-calendar canvas coord */ +gboolean +e_calendar_item_get_day_extents (ECalendarItem *calitem, + gint year, gint month, gint date, + gint *x, gint *y, + gint *width, gint *height) +{ + GnomeCanvasItem *item; + GtkWidget *widget; + GtkStyle *style; + PangoFontDescription *font_desc; + PangoContext *pango_context; + PangoFontMetrics *font_metrics; + gint char_height, xthickness, ythickness, text_y; + gint new_year, new_month, num_months, months_offset; + gint month_x, month_y, month_cell_x, month_cell_y; + gint month_row, month_col; + gint day_row, day_col; + gint days_from_week_start; + + g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); + + item = GNOME_CANVAS_ITEM (calitem); + widget = GTK_WIDGET (item->canvas); + style = widget->style; + + /* Set up Pango prerequisites */ + font_desc = calitem->font_desc; + if (!font_desc) + font_desc = style->font_desc; + pango_context = gtk_widget_get_pango_context (widget); + font_metrics = pango_context_get_metrics (pango_context, font_desc, + pango_context_get_language (pango_context)); + + char_height = + PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics)) + + PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)); + + xthickness = style->xthickness; + ythickness = style->ythickness; + + new_year = year; + new_month = month; + e_calendar_item_normalize_date (calitem, &new_year, &new_month); + num_months = calitem->rows * calitem->cols; + months_offset = (new_year - calitem->year) * 12 + + new_month - calitem->month; + + if (months_offset > num_months || months_offset < 0) + return FALSE; + + month_row = months_offset / calitem->cols; + month_col = months_offset % calitem->cols; + + month_x = item->x1 + xthickness + calitem->x_offset + + month_col * calitem->month_width; + month_y = item->y1 + ythickness + month_row * calitem->month_height; + + month_cell_x = month_x + E_CALENDAR_ITEM_XPAD_BEFORE_WEEK_NUMBERS + + calitem->month_lpad + E_CALENDAR_ITEM_XPAD_BEFORE_CELLS; + text_y = month_y + ythickness * 2 + + E_CALENDAR_ITEM_YPAD_ABOVE_MONTH_NAME + + char_height + E_CALENDAR_ITEM_YPAD_BELOW_MONTH_NAME + + E_CALENDAR_ITEM_YPAD_ABOVE_DAY_LETTERS + calitem->month_tpad; + + month_cell_y = text_y + char_height + + E_CALENDAR_ITEM_YPAD_BELOW_DAY_LETTERS + 1 + + E_CALENDAR_ITEM_YPAD_ABOVE_CELLS; + + days_from_week_start = + e_calendar_item_get_n_days_from_week_start (calitem, new_year, + new_month); + day_row = (date + days_from_week_start - 1) / EA_CALENDAR_COLUMN_NUM; + day_col = (date + days_from_week_start - 1) % EA_CALENDAR_COLUMN_NUM; + + *x = month_cell_x + day_col * calitem->cell_width; + *y = month_cell_y + day_row * calitem->cell_height; + *width = calitem->cell_width; + *height = calitem->cell_height; + + return TRUE; +} + +/* month is from 0 to 11 */ +gboolean +e_calendar_item_get_date_for_offset (ECalendarItem *calitem, gint day_offset, + gint *year, gint *month, gint *day) +{ + gint start_year, start_month, start_day; + gint end_year, end_month, end_day; + GDate *start_date; + + g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); + + if (!e_calendar_item_get_date_range (calitem, &start_year, + &start_month, &start_day, + &end_year, &end_month, + &end_day)) + return FALSE; + + start_date = g_date_new_dmy (start_day, start_month + 1, start_year); + + g_date_add_days (start_date, day_offset); + + *year = g_date_get_year (start_date); + *month = g_date_get_month (start_date) - 1; + *day = g_date_get_day (start_date); + + return TRUE; +} + +/* the arg month is from 0 to 11 */ +static gboolean +e_calendar_item_get_offset_for_date (ECalendarItem *calitem, + gint year, gint month, gint day, + gint *offset) +{ + gint start_year, start_month, start_day; + gint end_year, end_month, end_day; + GDate *start_date, *end_date; + + *offset = 0; + g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem), FALSE); + + if (!e_calendar_item_get_date_range (calitem, &start_year, + &start_month, &start_day, + &end_year, &end_month, + &end_day)) + return FALSE; + + start_date = g_date_new_dmy (start_day, start_month + 1, start_year); + end_date = g_date_new_dmy (day, month + 1, year); + + *offset = g_date_days_between (start_date, end_date); + g_free (start_date); + g_free (end_date); + + return TRUE; +} + +gint +e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem, + gint year, gint month) +{ + struct tm tmp_tm; + gint start_weekday, days_from_week_start; + + memset (&tmp_tm, 0, sizeof (tmp_tm)); + tmp_tm.tm_year = year - 1900; + tmp_tm.tm_mon = month; + tmp_tm.tm_mday = 1; + tmp_tm.tm_isdst = -1; + mktime (&tmp_tm); + start_weekday = (tmp_tm.tm_wday + 6) % 7; /* 0 to 6 */ + days_from_week_start = (start_weekday + 7 - calitem->week_start_day) + % 7; + return days_from_week_start; +} + +static void +ea_calendar_set_focus_object (EaCalendarItem *ea_calitem, AtkObject *item_cell) +{ + AtkStateSet *state_set, *old_state_set; + AtkObject *old_cell; + + old_cell = (AtkObject *)g_object_get_data (G_OBJECT(ea_calitem), "gail-focus-object"); + if (old_cell && EA_IS_CALENDAR_CELL (old_cell)) { + old_state_set = atk_object_ref_state_set (old_cell); + atk_state_set_remove_state (old_state_set, ATK_STATE_FOCUSED); + g_object_unref (old_state_set); + } + if (old_cell) + g_object_unref (old_cell); + + state_set = atk_object_ref_state_set (item_cell); + atk_state_set_add_state (state_set, ATK_STATE_FOCUSED); + g_object_set_data (G_OBJECT(ea_calitem), "gail-focus-object", item_cell); + g_object_unref (state_set); +} diff --git a/widgets/misc/ea-calendar-item.h b/widgets/misc/ea-calendar-item.h new file mode 100644 index 0000000000..36cc671a3b --- /dev/null +++ b/widgets/misc/ea-calendar-item.h @@ -0,0 +1,68 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#ifndef __EA_CALENDAR_ITEM_H__ +#define __EA_CALENDAR_ITEM_H__ + +#include +#include + +G_BEGIN_DECLS + +#define EA_TYPE_CALENDAR_ITEM (ea_calendar_item_get_type ()) +#define EA_CALENDAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), EA_TYPE_CALENDAR_ITEM, EaCalendarItem)) +#define EA_CALENDAR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), EA_TYPE_CALENDAR_ITEM, EaCalendarItemClass)) +#define EA_IS_CALENDAR_ITEM(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), EA_TYPE_CALENDAR_ITEM)) +#define EA_IS_CALENDAR_ITEM_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), EA_TYPE_CALENDAR_ITEM)) +#define EA_CALENDAR_ITEM_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), EA_TYPE_CALENDAR_ITEM, EaCalendarItemClass)) + +typedef struct _EaCalendarItem EaCalendarItem; +typedef struct _EaCalendarItemClass EaCalendarItemClass; + +struct _EaCalendarItem +{ + AtkGObjectAccessible parent; +}; + +GType ea_calendar_item_get_type (void); + +struct _EaCalendarItemClass +{ + AtkGObjectAccessibleClass parent_class; +}; + +AtkObject *ea_calendar_item_new (GObject *obj); +gboolean e_calendar_item_get_day_extents (ECalendarItem *calitem, + gint year, gint month, gint date, + gint *x, gint *y, + gint *width, gint *height); +gboolean e_calendar_item_get_date_for_offset (ECalendarItem *calitem, + gint day_offset, + gint *year, gint *month, + gint *day); +gint e_calendar_item_get_n_days_from_week_start (ECalendarItem *calitem, + gint year, gint month); + +G_END_DECLS + + +#endif /* __EA_CALENDAR_ITEM_H__ */ diff --git a/widgets/misc/ea-widgets.c b/widgets/misc/ea-widgets.c new file mode 100644 index 0000000000..9deede235e --- /dev/null +++ b/widgets/misc/ea-widgets.c @@ -0,0 +1,32 @@ +/* + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +#include "a11y/ea-factory.h" +#include "ea-calendar-item.h" +#include "ea-widgets.h" + +EA_FACTORY_GOBJECT (EA_TYPE_CALENDAR_ITEM, ea_calendar_item, ea_calendar_item_new) + +void e_calendar_item_a11y_init (void) +{ + EA_SET_FACTORY (e_calendar_item_get_type (), ea_calendar_item); +} diff --git a/widgets/misc/ea-widgets.h b/widgets/misc/ea-widgets.h new file mode 100644 index 0000000000..495222ae05 --- /dev/null +++ b/widgets/misc/ea-widgets.h @@ -0,0 +1,32 @@ +/* + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + * + * Authors: + * Bolian Yin + * + * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com) + * + */ + +/* Evolution Accessibility +*/ + +#ifndef _EA_WIDGETS_H__ +#define _EA_WIDGETS_H__ + +void e_calendar_item_a11y_init (void); + +#endif /* _EA_WIDGETS_H__ */ -- cgit