2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU Lesser General Public License as published by
4 * the Free Software Foundation.
6 * This program is distributed in the hope that it will be useful, but
7 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
8 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
11 * You should have received a copy of the GNU Lesser General Public License
12 * along with this program; if not, see <http://www.gnu.org/licenses/>.
16 * Bolian Yin <bolian.yin@sun.com>
18 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
29 #include <libgnomecanvas/gnome-canvas.h>
30 #include <glib/gi18n.h>
32 #include <libedataserver/libedataserver.h>
34 #include "ea-calendar-item.h"
35 #include "ea-calendar-cell.h"
36 #include "ea-cell-table.h"
38 #include "e-misc-utils.h"
40 #define EA_CALENDAR_COLUMN_NUM E_CALENDAR_COLS_PER_MONTH
43 static void ea_calendar_item_class_init (EaCalendarItemClass
*class);
44 static void ea_calendar_item_finalize (GObject
*object
);
46 static const gchar
* ea_calendar_item_get_name (AtkObject
*accessible
);
47 static const gchar
* ea_calendar_item_get_description (AtkObject
*accessible
);
48 static gint
ea_calendar_item_get_n_children (AtkObject
*accessible
);
49 static AtkObject
*ea_calendar_item_ref_child (AtkObject
*accessible
, gint index
);
50 static AtkStateSet
* ea_calendar_item_ref_state_set (AtkObject
*accessible
);
52 /* atk table interface */
53 static void atk_table_interface_init (AtkTableIface
*iface
);
54 static gint
table_interface_get_index_at (AtkTable
*table
,
57 static gint
table_interface_get_column_at_index (AtkTable
*table
,
59 static gint
table_interface_get_row_at_index (AtkTable
*table
,
61 static AtkObject
* table_interface_ref_at (AtkTable
*table
,
64 static gint
table_interface_get_n_rows (AtkTable
*table
);
65 static gint
table_interface_get_n_columns (AtkTable
*table
);
66 static gint
table_interface_get_column_extent_at (AtkTable
*table
,
69 static gint
table_interface_get_row_extent_at (AtkTable
*table
,
73 static gboolean
table_interface_is_row_selected (AtkTable
*table
,
75 static gboolean
table_interface_is_column_selected (AtkTable
*table
,
77 static gboolean
table_interface_is_selected (AtkTable
*table
,
80 static gint
table_interface_get_selected_rows (AtkTable
*table
,
81 gint
**rows_selected
);
82 static gint
table_interface_get_selected_columns (AtkTable
*table
,
83 gint
**columns_selected
);
84 static gboolean
table_interface_add_row_selection (AtkTable
*table
, gint row
);
85 static gboolean
table_interface_remove_row_selection (AtkTable
*table
,
87 static gboolean
table_interface_add_column_selection (AtkTable
*table
,
89 static gboolean
table_interface_remove_column_selection (AtkTable
*table
,
91 static AtkObject
* table_interface_get_row_header (AtkTable
*table
, gint row
);
92 static AtkObject
* table_interface_get_column_header (AtkTable
*table
,
94 static AtkObject
* table_interface_get_caption (AtkTable
*table
);
97 table_interface_get_column_description (AtkTable
*table
,
101 table_interface_get_row_description (AtkTable
*table
,
104 static AtkObject
*table_interface_get_summary (AtkTable
*table
);
106 /* atk selection interface */
107 static void atk_selection_interface_init (AtkSelectionIface
*iface
);
108 static gboolean
selection_interface_add_selection (AtkSelection
*selection
,
110 static gboolean
selection_interface_clear_selection (AtkSelection
*selection
);
111 static AtkObject
*selection_interface_ref_selection (AtkSelection
*selection
,
113 static gint
selection_interface_get_selection_count (AtkSelection
*selection
);
114 static gboolean
selection_interface_is_child_selected (AtkSelection
*selection
,
118 static void selection_preview_change_cb (ECalendarItem
*calitem
);
119 static void date_range_changed_cb (ECalendarItem
*calitem
);
122 static EaCellTable
*ea_calendar_item_get_cell_data (EaCalendarItem
*ea_calitem
);
123 static void ea_calendar_item_destory_cell_data (EaCalendarItem
*ea_calitem
);
124 static gboolean
ea_calendar_item_get_column_label (EaCalendarItem
*ea_calitem
,
128 static gboolean
ea_calendar_item_get_row_label (EaCalendarItem
*ea_calitem
,
132 static gboolean
e_calendar_item_get_offset_for_date (ECalendarItem
*calitem
,
137 static void ea_calendar_set_focus_object (EaCalendarItem
*ea_calitem
,
138 AtkObject
*item_cell
);
141 static gint n_ea_calendar_item_created
= 0;
142 static gint n_ea_calendar_item_destroyed
= 0;
145 static gpointer parent_class
= NULL
;
148 ea_calendar_item_get_type (void)
150 static GType type
= 0;
151 AtkObjectFactory
*factory
;
153 GType derived_atk_type
;
156 static GTypeInfo tinfo
= {
157 sizeof (EaCalendarItemClass
),
158 (GBaseInitFunc
) NULL
, /* base init */
159 (GBaseFinalizeFunc
) NULL
, /* base finalize */
160 (GClassInitFunc
) ea_calendar_item_class_init
, /* class init */
161 (GClassFinalizeFunc
) NULL
, /* class finalize */
162 NULL
, /* class data */
163 sizeof (EaCalendarItem
), /* instance size */
164 0, /* nb preallocs */
165 (GInstanceInitFunc
) NULL
, /* instance init */
166 NULL
/* value table */
169 static const GInterfaceInfo atk_table_info
= {
170 (GInterfaceInitFunc
) atk_table_interface_init
,
171 (GInterfaceFinalizeFunc
) NULL
,
174 static const GInterfaceInfo atk_selection_info
= {
175 (GInterfaceInitFunc
) atk_selection_interface_init
,
176 (GInterfaceFinalizeFunc
) NULL
,
181 * Figure out the size of the class and instance
182 * we are run-time deriving from (GailCanvasItem, in this case)
185 factory
= atk_registry_get_factory (
186 atk_get_default_registry (),
187 GNOME_TYPE_CANVAS_ITEM
);
188 derived_atk_type
= atk_object_factory_get_accessible_type (factory
);
189 g_type_query (derived_atk_type
, &query
);
191 tinfo
.class_size
= query
.class_size
;
192 tinfo
.instance_size
= query
.instance_size
;
194 type
= g_type_register_static (
196 "EaCalendarItem", &tinfo
, 0);
197 g_type_add_interface_static (
198 type
, ATK_TYPE_TABLE
,
200 g_type_add_interface_static (
201 type
, ATK_TYPE_SELECTION
,
202 &atk_selection_info
);
209 ea_calendar_item_class_init (EaCalendarItemClass
*klass
)
211 GObjectClass
*gobject_class
= G_OBJECT_CLASS (klass
);
212 AtkObjectClass
*class = ATK_OBJECT_CLASS (klass
);
214 gobject_class
->finalize
= ea_calendar_item_finalize
;
215 parent_class
= g_type_class_peek_parent (klass
);
217 class->get_name
= ea_calendar_item_get_name
;
218 class->get_description
= ea_calendar_item_get_description
;
219 class->ref_state_set
= ea_calendar_item_ref_state_set
;
221 class->get_n_children
= ea_calendar_item_get_n_children
;
222 class->ref_child
= ea_calendar_item_ref_child
;
226 ea_calendar_item_new (GObject
*obj
)
229 AtkObject
*atk_object
;
230 AtkObject
*item_cell
;
232 g_return_val_if_fail (E_IS_CALENDAR_ITEM (obj
), NULL
);
233 object
= g_object_new (EA_TYPE_CALENDAR_ITEM
, NULL
);
234 atk_object
= ATK_OBJECT (object
);
235 atk_object_initialize (atk_object
, obj
);
236 atk_object
->role
= ATK_ROLE_CALENDAR
;
238 item_cell
= atk_selection_ref_selection (
239 ATK_SELECTION (atk_object
), 0);
241 ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_object
), item_cell
);
244 ++n_ea_calendar_item_created
;
246 "ACC_DEBUG: n_ea_calendar_item_created = %d\n",
247 n_ea_calendar_item_created
);
249 /* connect signal handlers */
251 obj
, "selection_preview_changed",
252 G_CALLBACK (selection_preview_change_cb
), atk_object
);
254 obj
, "date_range_changed",
255 G_CALLBACK (date_range_changed_cb
), atk_object
);
261 ea_calendar_item_finalize (GObject
*object
)
263 EaCalendarItem
*ea_calitem
;
265 g_return_if_fail (EA_IS_CALENDAR_ITEM (object
));
267 ea_calitem
= EA_CALENDAR_ITEM (object
);
269 /* Free the allocated cell data */
270 ea_calendar_item_destory_cell_data (ea_calitem
);
272 G_OBJECT_CLASS (parent_class
)->finalize (object
);
274 ++n_ea_calendar_item_destroyed
;
276 "ACC_DEBUG: n_ea_calendar_item_destroyed = %d\n",
277 n_ea_calendar_item_destroyed
);
282 ea_calendar_item_get_name (AtkObject
*accessible
)
285 ECalendarItem
*calitem
;
286 gint start_year
, start_month
, start_day
;
287 gint end_year
, end_month
, end_day
;
288 gchar
*name_str
= NULL
;
289 gchar buffer_start
[128] = "";
290 gchar buffer_end
[128] = "";
291 struct tm day_start
= { 0 };
292 struct tm day_end
= { 0 };
294 g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible
), NULL
);
296 g_obj
= atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (accessible
));
299 g_return_val_if_fail (E_IS_CALENDAR_ITEM (g_obj
), NULL
);
301 calitem
= E_CALENDAR_ITEM (g_obj
);
302 if (e_calendar_item_get_date_range (
304 &start_year
, &start_month
, &start_day
,
305 &end_year
, &end_month
, &end_day
)) {
307 day_start
.tm_year
= start_year
- 1900;
308 day_start
.tm_mon
= start_month
;
309 day_start
.tm_mday
= start_day
;
310 day_start
.tm_isdst
= -1;
313 buffer_start
, sizeof (buffer_start
),
314 _("%d %B %Y"), &day_start
);
316 day_end
.tm_year
= end_year
- 1900;
317 day_end
.tm_mon
= end_month
;
318 day_end
.tm_mday
= end_day
;
319 day_end
.tm_isdst
= -1;
322 buffer_end
, sizeof (buffer_end
),
323 _("%d %B %Y"), &day_end
);
325 name_str
= g_strdup_printf (
326 _("Calendar: from %s to %s"),
327 buffer_start
, buffer_end
);
331 if (e_calendar_item_get_selection (calitem
, &select_start
, &select_end
)) {
332 GDate select_start
, select_end
;
333 gint year1
, year2
, month1
, month2
, day1
, day2
;
335 year1
= g_date_get_year (&select_start
);
336 month1
= g_date_get_month (&select_start
);
337 day1
= g_date_get_day (&select_start
);
339 year2
= g_date_get_year (&select_end
);
340 month2
= g_date_get_month (&select_end
);
341 day2
= g_date_get_day (&select_end
);
344 new_name
+ strlen (new_name
),
345 " : current selection: from %d-%d-%d to %d-%d-%d.",
347 year2
, month2
, day2
);
351 ATK_OBJECT_CLASS (parent_class
)->set_name (accessible
, name_str
);
354 return accessible
->name
;
358 ea_calendar_item_get_description (AtkObject
*accessible
)
360 if (accessible
->description
)
361 return accessible
->description
;
363 return _("evolution calendar item");
367 ea_calendar_item_ref_state_set (AtkObject
*accessible
)
369 AtkStateSet
*state_set
;
372 state_set
= ATK_OBJECT_CLASS (parent_class
)->ref_state_set (accessible
);
373 g_obj
= atk_gobject_accessible_get_object (
374 ATK_GOBJECT_ACCESSIBLE (accessible
));
378 atk_state_set_add_state (state_set
, ATK_STATE_ENABLED
);
379 atk_state_set_add_state (state_set
, ATK_STATE_SENSITIVE
);
385 ea_calendar_item_get_n_children (AtkObject
*accessible
)
387 AtkGObjectAccessible
*atk_gobj
;
389 ECalendarItem
*calitem
;
391 gint start_year
, start_month
, start_day
;
392 gint end_year
, end_month
, end_day
;
393 GDate
*start_date
, *end_date
;
395 g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible
), -1);
397 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (accessible
);
398 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
402 calitem
= E_CALENDAR_ITEM (g_obj
);
403 if (!e_calendar_item_get_date_range (calitem
, &start_year
,
404 &start_month
, &start_day
,
405 &end_year
, &end_month
,
409 start_date
= g_date_new_dmy (start_day
, start_month
+ 1, start_year
);
410 end_date
= g_date_new_dmy (end_day
, end_month
+ 1, end_year
);
412 n_children
= g_date_days_between (start_date
, end_date
) + 1;
419 ea_calendar_item_ref_child (AtkObject
*accessible
,
422 AtkGObjectAccessible
*atk_gobj
;
424 ECalendarItem
*calitem
;
427 EaCellTable
*cell_data
;
428 EaCalendarItem
*ea_calitem
;
430 g_return_val_if_fail (EA_IS_CALENDAR_ITEM (accessible
), NULL
);
432 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (accessible
);
433 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
437 calitem
= E_CALENDAR_ITEM (g_obj
);
439 n_children
= ea_calendar_item_get_n_children (accessible
);
440 if (index
< 0 || index
>= n_children
)
443 ea_calitem
= EA_CALENDAR_ITEM (accessible
);
444 cell_data
= ea_calendar_item_get_cell_data (ea_calitem
);
448 cell
= ea_cell_table_get_cell_at_index (cell_data
, index
);
450 cell
= e_calendar_cell_new (
452 index
/ EA_CALENDAR_COLUMN_NUM
,
453 index
% EA_CALENDAR_COLUMN_NUM
);
454 ea_cell_table_set_cell_at_index (cell_data
, index
, cell
);
455 g_object_unref (cell
);
460 "AccDebug: ea_calendar_item children[%d]=%p\n", index
,
463 return g_object_ref (atk_gobject_accessible_for_object (G_OBJECT (cell
)));
466 /* atk table interface */
469 atk_table_interface_init (AtkTableIface
*iface
)
471 g_return_if_fail (iface
!= NULL
);
473 iface
->ref_at
= table_interface_ref_at
;
475 iface
->get_n_rows
= table_interface_get_n_rows
;
476 iface
->get_n_columns
= table_interface_get_n_columns
;
477 iface
->get_index_at
= table_interface_get_index_at
;
478 iface
->get_column_at_index
= table_interface_get_column_at_index
;
479 iface
->get_row_at_index
= table_interface_get_row_at_index
;
480 iface
->get_column_extent_at
= table_interface_get_column_extent_at
;
481 iface
->get_row_extent_at
= table_interface_get_row_extent_at
;
483 iface
->is_selected
= table_interface_is_selected
;
484 iface
->get_selected_rows
= table_interface_get_selected_rows
;
485 iface
->get_selected_columns
= table_interface_get_selected_columns
;
486 iface
->is_row_selected
= table_interface_is_row_selected
;
487 iface
->is_column_selected
= table_interface_is_column_selected
;
488 iface
->add_row_selection
= table_interface_add_row_selection
;
489 iface
->remove_row_selection
= table_interface_remove_row_selection
;
490 iface
->add_column_selection
= table_interface_add_column_selection
;
491 iface
->remove_column_selection
= table_interface_remove_column_selection
;
493 iface
->get_row_header
= table_interface_get_row_header
;
494 iface
->get_column_header
= table_interface_get_column_header
;
495 iface
->get_caption
= table_interface_get_caption
;
496 iface
->get_summary
= table_interface_get_summary
;
497 iface
->get_row_description
= table_interface_get_row_description
;
498 iface
->get_column_description
= table_interface_get_column_description
;
502 table_interface_ref_at (AtkTable
*table
,
508 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
509 index
= EA_CALENDAR_COLUMN_NUM
* row
+ column
;
510 return ea_calendar_item_ref_child (ATK_OBJECT (ea_calitem
), index
);
514 table_interface_get_n_rows (AtkTable
*table
)
516 AtkGObjectAccessible
*atk_gobj
;
518 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
521 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
522 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
526 n_children
= ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem
));
527 return (n_children
- 1) / EA_CALENDAR_COLUMN_NUM
+ 1;
531 table_interface_get_n_columns (AtkTable
*table
)
533 AtkGObjectAccessible
*atk_gobj
;
535 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
537 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
538 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
542 return EA_CALENDAR_COLUMN_NUM
;
546 table_interface_get_index_at (AtkTable
*table
,
550 AtkGObjectAccessible
*atk_gobj
;
552 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
554 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
555 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
559 return row
* EA_CALENDAR_COLUMN_NUM
+ column
;
563 table_interface_get_column_at_index (AtkTable
*table
,
566 AtkGObjectAccessible
*atk_gobj
;
568 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
571 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
572 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
576 n_children
= ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem
));
577 if (index
>= 0 && index
< n_children
)
578 return index
% EA_CALENDAR_COLUMN_NUM
;
583 table_interface_get_row_at_index (AtkTable
*table
,
586 AtkGObjectAccessible
*atk_gobj
;
588 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
591 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
592 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
596 n_children
= ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem
));
597 if (index
>= 0 && index
< n_children
)
598 return index
/ EA_CALENDAR_COLUMN_NUM
;
603 table_interface_get_column_extent_at (AtkTable
*table
,
607 AtkGObjectAccessible
*atk_gobj
;
609 ECalendarItem
*calitem
;
610 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
612 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
613 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
617 calitem
= E_CALENDAR_ITEM (g_obj
);
618 return calitem
->cell_width
;
622 table_interface_get_row_extent_at (AtkTable
*table
,
626 AtkGObjectAccessible
*atk_gobj
;
628 ECalendarItem
*calitem
;
629 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
631 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
632 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
636 calitem
= E_CALENDAR_ITEM (g_obj
);
637 return calitem
->cell_height
;
640 /* any day in the row is selected, the row is selected */
642 table_interface_is_row_selected (AtkTable
*table
,
645 AtkGObjectAccessible
*atk_gobj
;
648 ECalendarItem
*calitem
;
649 gint row_index_start
, row_index_end
;
650 gint sel_index_start
, sel_index_end
;
652 GDate start_date
, end_date
;
654 g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table
), FALSE
);
656 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (table
);
657 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
661 n_rows
= table_interface_get_n_rows (table
);
662 if (row
< 0 || row
>= n_rows
)
665 row_index_start
= row
* EA_CALENDAR_COLUMN_NUM
;
666 row_index_end
= row_index_start
+ EA_CALENDAR_COLUMN_NUM
- 1;
668 calitem
= E_CALENDAR_ITEM (g_obj
);
669 if (!e_calendar_item_get_selection (calitem
, &start_date
, &end_date
))
672 e_calendar_item_get_offset_for_date (calitem
,
673 g_date_get_year (&start_date
),
674 g_date_get_month (&start_date
),
675 g_date_get_day (&start_date
),
677 e_calendar_item_get_offset_for_date (calitem
,
678 g_date_get_year (&end_date
),
679 g_date_get_month (&end_date
),
680 g_date_get_day (&end_date
),
683 if ((sel_index_start
< row_index_start
&&
684 sel_index_end
>= row_index_start
) ||
685 (sel_index_start
>= row_index_start
&&
686 sel_index_start
<= row_index_end
))
692 table_interface_is_selected (AtkTable
*table
,
696 AtkGObjectAccessible
*atk_gobj
;
698 gint n_rows
, n_columns
;
699 ECalendarItem
*calitem
;
701 gint sel_index_start
, sel_index_end
;
703 GDate start_date
, end_date
;
705 g_return_val_if_fail (EA_IS_CALENDAR_ITEM (table
), FALSE
);
707 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (table
);
708 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
712 n_rows
= table_interface_get_n_rows (table
);
713 if (row
< 0 || row
>= n_rows
)
715 n_columns
= table_interface_get_n_columns (table
);
716 if (column
< 0 || column
>= n_columns
)
719 index
= table_interface_get_index_at (table
, row
, column
);
721 calitem
= E_CALENDAR_ITEM (g_obj
);
722 if (!e_calendar_item_get_selection (calitem
, &start_date
, &end_date
))
725 e_calendar_item_get_offset_for_date (calitem
,
726 g_date_get_year (&start_date
),
727 g_date_get_month (&start_date
),
728 g_date_get_day (&start_date
),
730 e_calendar_item_get_offset_for_date (calitem
,
731 g_date_get_year (&end_date
),
732 g_date_get_month (&end_date
),
733 g_date_get_day (&end_date
), &sel_index_end
);
735 if (sel_index_start
<= index
&& sel_index_end
>= index
)
741 table_interface_is_column_selected (AtkTable
*table
,
748 table_interface_get_selected_rows (AtkTable
*table
,
749 gint
**rows_selected
)
751 *rows_selected
= NULL
;
756 table_interface_get_selected_columns (AtkTable
*table
,
757 gint
**columns_selected
)
759 *columns_selected
= NULL
;
764 table_interface_add_row_selection (AtkTable
*table
,
771 table_interface_remove_row_selection (AtkTable
*table
,
778 table_interface_add_column_selection (AtkTable
*table
,
785 table_interface_remove_column_selection (AtkTable
*table
,
788 /* FIXME: NOT IMPLEMENTED */
793 table_interface_get_row_header (AtkTable
*table
,
796 /* FIXME: NOT IMPLEMENTED */
801 table_interface_get_column_header (AtkTable
*table
,
804 /* FIXME: NOT IMPLEMENTED */
809 table_interface_get_caption (AtkTable
*table
)
811 /* FIXME: NOT IMPLEMENTED */
816 table_interface_get_column_description (AtkTable
*table
,
819 AtkGObjectAccessible
*atk_gobj
;
821 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
822 const gchar
*description
= NULL
;
823 EaCellTable
*cell_data
;
826 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
827 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
831 n_columns
= table_interface_get_n_columns (table
);
832 if (in_col
< 0 || in_col
>= n_columns
)
834 cell_data
= ea_calendar_item_get_cell_data (ea_calitem
);
838 description
= ea_cell_table_get_column_label (cell_data
, in_col
);
840 gchar buffer
[128] = "column description";
841 ea_calendar_item_get_column_label (
843 buffer
, sizeof (buffer
));
844 ea_cell_table_set_column_label (cell_data
, in_col
, buffer
);
845 description
= ea_cell_table_get_column_label (
852 table_interface_get_row_description (AtkTable
*table
,
855 AtkGObjectAccessible
*atk_gobj
;
857 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (table
);
858 const gchar
*description
= NULL
;
859 EaCellTable
*cell_data
;
862 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
863 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
867 n_rows
= table_interface_get_n_rows (table
);
868 if (row
< 0 || row
>= n_rows
)
870 cell_data
= ea_calendar_item_get_cell_data (ea_calitem
);
874 description
= ea_cell_table_get_row_label (cell_data
, row
);
876 gchar buffer
[128] = "row description";
877 ea_calendar_item_get_row_label (
879 buffer
, sizeof (buffer
));
880 ea_cell_table_set_row_label (cell_data
, row
, buffer
);
881 description
= ea_cell_table_get_row_label (
889 table_interface_get_summary (AtkTable
*table
)
891 /* FIXME: NOT IMPLEMENTED */
895 /* atkselection interface */
898 atk_selection_interface_init (AtkSelectionIface
*iface
)
900 g_return_if_fail (iface
!= NULL
);
902 iface
->add_selection
= selection_interface_add_selection
;
903 iface
->clear_selection
= selection_interface_clear_selection
;
904 iface
->ref_selection
= selection_interface_ref_selection
;
905 iface
->get_selection_count
= selection_interface_get_selection_count
;
906 iface
->is_child_selected
= selection_interface_is_child_selected
;
910 selection_interface_add_selection (AtkSelection
*selection
,
913 AtkGObjectAccessible
*atk_gobj
;
915 ECalendarItem
*calitem
;
916 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (selection
);
917 gint year
, month
, day
;
918 GDate start_date
, end_date
;
920 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
921 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
925 calitem
= E_CALENDAR_ITEM (g_obj
);
926 if (!e_calendar_item_get_date_for_offset (calitem
, index
,
927 &year
, &month
, &day
))
930 /* FIXME: not support mulit-selection */
931 g_date_set_dmy (&start_date
, day
, month
+ 1, year
);
932 end_date
= start_date
;
933 e_calendar_item_set_selection (calitem
, &start_date
, &end_date
);
938 selection_interface_clear_selection (AtkSelection
*selection
)
940 AtkGObjectAccessible
*atk_gobj
;
942 ECalendarItem
*calitem
;
943 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (selection
);
945 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
946 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
950 calitem
= E_CALENDAR_ITEM (g_obj
);
951 e_calendar_item_set_selection (calitem
, NULL
, NULL
);
957 selection_interface_ref_selection (AtkSelection
*selection
,
961 ECalendarItem
*calitem
;
962 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (selection
);
963 gint count
, sel_offset
;
964 GDate start_date
, end_date
;
966 count
= selection_interface_get_selection_count (selection
);
967 if (i
< 0 || i
>= count
)
970 g_obj
= atk_gobject_accessible_get_object (ATK_GOBJECT_ACCESSIBLE (ea_calitem
));
972 calitem
= E_CALENDAR_ITEM (g_obj
);
973 if (!e_calendar_item_get_selection (calitem
, &start_date
, &end_date
))
975 if (!e_calendar_item_get_offset_for_date (calitem
,
976 g_date_get_year (&start_date
),
977 g_date_get_month (&start_date
) - 1,
978 g_date_get_day (&start_date
),
982 return ea_calendar_item_ref_child (ATK_OBJECT (selection
), sel_offset
+ i
);
986 selection_interface_get_selection_count (AtkSelection
*selection
)
988 AtkGObjectAccessible
*atk_gobj
;
990 ECalendarItem
*calitem
;
991 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (selection
);
992 GDate start_date
, end_date
;
994 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
995 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
999 calitem
= E_CALENDAR_ITEM (g_obj
);
1000 if (e_calendar_item_get_selection (calitem
, &start_date
, &end_date
))
1001 return g_date_days_between (&start_date
, &end_date
) + 1;
1007 selection_interface_is_child_selected (AtkSelection
*selection
,
1010 AtkGObjectAccessible
*atk_gobj
;
1012 EaCalendarItem
* ea_calitem
= EA_CALENDAR_ITEM (selection
);
1013 gint row
, column
, n_children
;
1015 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
1016 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
1020 n_children
= atk_object_get_n_accessible_children (ATK_OBJECT (selection
));
1021 if (index
< 0 || index
>= n_children
)
1024 row
= index
/ EA_CALENDAR_COLUMN_NUM
;
1025 column
= index
% EA_CALENDAR_COLUMN_NUM
;
1027 return table_interface_is_selected (ATK_TABLE (selection
), row
, column
);
1033 selection_preview_change_cb (ECalendarItem
*calitem
)
1036 AtkObject
*item_cell
;
1038 g_return_if_fail (E_IS_CALENDAR_ITEM (calitem
));
1039 atk_obj
= atk_gobject_accessible_for_object (G_OBJECT (calitem
));
1040 ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj
));
1042 /* only deal with the first selected child, for now */
1043 item_cell
= atk_selection_ref_selection (
1044 ATK_SELECTION (atk_obj
), 0);
1047 ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj
), item_cell
);
1049 g_signal_emit_by_name (
1051 "active-descendant-changed",
1053 g_signal_emit_by_name (atk_obj
, "selection_changed");
1057 date_range_changed_cb (ECalendarItem
*calitem
)
1060 AtkObject
*item_cell
;
1062 g_return_if_fail (E_IS_CALENDAR_ITEM (calitem
));
1063 atk_obj
= atk_gobject_accessible_for_object (G_OBJECT (calitem
));
1064 ea_calendar_item_destory_cell_data (EA_CALENDAR_ITEM (atk_obj
));
1066 item_cell
= atk_selection_ref_selection (
1067 ATK_SELECTION (atk_obj
), 0);
1069 ea_calendar_set_focus_object (EA_CALENDAR_ITEM (atk_obj
), item_cell
);
1071 g_signal_emit_by_name (atk_obj
, "model_changed");
1076 static EaCellTable
*
1077 ea_calendar_item_get_cell_data (EaCalendarItem
*ea_calitem
)
1079 AtkGObjectAccessible
*atk_gobj
;
1081 EaCellTable
*cell_data
;
1083 g_return_val_if_fail (ea_calitem
, NULL
);
1085 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
1086 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
1090 cell_data
= g_object_get_data (
1091 G_OBJECT (ea_calitem
),
1092 "ea-calendar-cell-table");
1095 gint n_cells
= ea_calendar_item_get_n_children (ATK_OBJECT (ea_calitem
));
1096 cell_data
= ea_cell_table_create (
1097 n_cells
/ EA_CALENDAR_COLUMN_NUM
,
1098 EA_CALENDAR_COLUMN_NUM
,
1100 g_object_set_data_full (
1101 G_OBJECT (ea_calitem
),
1102 "ea-calendar-cell-table", cell_data
,
1103 (GDestroyNotify
) ea_cell_table_destroy
);
1109 ea_calendar_item_destory_cell_data (EaCalendarItem
*ea_calitem
)
1111 g_return_if_fail (ea_calitem
);
1114 G_OBJECT (ea_calitem
),
1115 "ea-calendar-cell-table", NULL
);
1119 ea_calendar_item_get_row_label (EaCalendarItem
*ea_calitem
,
1124 AtkGObjectAccessible
*atk_gobj
;
1126 ECalendarItem
*calitem
;
1127 gint index
, week_num
;
1128 gint year
, month
, day
;
1130 g_return_val_if_fail (ea_calitem
, FALSE
);
1132 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
1133 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
1137 calitem
= E_CALENDAR_ITEM (g_obj
);
1139 index
= table_interface_get_index_at (ATK_TABLE (ea_calitem
), row
, 0);
1140 if (!e_calendar_item_get_date_for_offset (calitem
, index
,
1141 &year
, &month
, &day
))
1144 week_num
= e_calendar_item_get_week_number (
1145 calitem
, day
, month
, year
);
1147 g_snprintf (buffer
, buffer_size
, "week number : %d", week_num
);
1152 ea_calendar_item_get_column_label (EaCalendarItem
*ea_calitem
,
1157 AtkGObjectAccessible
*atk_gobj
;
1159 const gchar
*abbr_name
;
1161 g_return_val_if_fail (ea_calitem
, FALSE
);
1163 atk_gobj
= ATK_GOBJECT_ACCESSIBLE (ea_calitem
);
1164 g_obj
= atk_gobject_accessible_get_object (atk_gobj
);
1168 /* Columns are 0 = Monday ... 6 = Sunday */
1169 abbr_name
= e_get_weekday_name (column
+ 1, TRUE
);
1170 g_strlcpy (buffer
, abbr_name
, buffer_size
);
1175 /* the coordinate the e-calendar canvas coord */
1177 e_calendar_item_get_day_extents (ECalendarItem
*calitem
,
1186 GnomeCanvasItem
*item
;
1189 PangoContext
*pango_context
;
1190 PangoFontMetrics
*font_metrics
;
1191 gint char_height
, xthickness
, ythickness
, text_y
;
1192 gint new_year
, new_month
, num_months
, months_offset
;
1193 gint month_x
, month_y
, month_cell_x
, month_cell_y
;
1194 gint month_row
, month_col
;
1195 gint day_row
, day_col
;
1196 gint days_from_week_start
;
1198 g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem
), FALSE
);
1200 item
= GNOME_CANVAS_ITEM (calitem
);
1201 widget
= GTK_WIDGET (item
->canvas
);
1202 gtk_style_context_get_padding (gtk_widget_get_style_context (widget
), 0, &padding
);
1204 /* Set up Pango prerequisites */
1205 pango_context
= gtk_widget_get_pango_context (widget
);
1206 font_metrics
= pango_context_get_metrics (
1207 pango_context
, calitem
->font_desc
,
1208 pango_context_get_language (pango_context
));
1211 PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics
)) +
1212 PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics
));
1214 xthickness
= padding
.left
;
1215 ythickness
= padding
.top
;
1219 e_calendar_item_normalize_date (calitem
, &new_year
, &new_month
);
1220 num_months
= calitem
->rows
* calitem
->cols
;
1221 months_offset
= (new_year
- calitem
->year
) * 12
1222 + new_month
- calitem
->month
;
1224 if (months_offset
> num_months
|| months_offset
< 0)
1227 month_row
= months_offset
/ calitem
->cols
;
1228 month_col
= months_offset
% calitem
->cols
;
1230 month_x
= item
->x1
+ xthickness
+ calitem
->x_offset
1231 + month_col
* calitem
->month_width
;
1232 month_y
= item
->y1
+ ythickness
+ month_row
* calitem
->month_height
;
1234 month_cell_x
= month_x
+ E_CALENDAR_ITEM_XPAD_BEFORE_WEEK_NUMBERS
1235 + calitem
->month_lpad
+ E_CALENDAR_ITEM_XPAD_BEFORE_CELLS
;
1236 text_y
= month_y
+ ythickness
* 2
1237 + E_CALENDAR_ITEM_YPAD_ABOVE_MONTH_NAME
1238 + char_height
+ E_CALENDAR_ITEM_YPAD_BELOW_MONTH_NAME
1239 + E_CALENDAR_ITEM_YPAD_ABOVE_DAY_LETTERS
+ calitem
->month_tpad
;
1241 month_cell_y
= text_y
+ char_height
1242 + E_CALENDAR_ITEM_YPAD_BELOW_DAY_LETTERS
+ 1
1243 + E_CALENDAR_ITEM_YPAD_ABOVE_CELLS
;
1245 days_from_week_start
= e_calendar_item_get_n_days_from_week_start (
1246 calitem
, new_year
, new_month
);
1247 day_row
= (date
+ days_from_week_start
- 1) / EA_CALENDAR_COLUMN_NUM
;
1248 day_col
= (date
+ days_from_week_start
- 1) % EA_CALENDAR_COLUMN_NUM
;
1250 *x
= month_cell_x
+ day_col
* calitem
->cell_width
;
1251 *y
= month_cell_y
+ day_row
* calitem
->cell_height
;
1252 *width
= calitem
->cell_width
;
1253 *height
= calitem
->cell_height
;
1258 /* month is from 0 to 11 */
1260 e_calendar_item_get_date_for_offset (ECalendarItem
*calitem
,
1266 gint start_year
, start_month
, start_day
;
1267 gint end_year
, end_month
, end_day
;
1270 g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem
), FALSE
);
1272 if (!e_calendar_item_get_date_range (calitem
, &start_year
,
1273 &start_month
, &start_day
,
1274 &end_year
, &end_month
,
1278 start_date
= g_date_new_dmy (start_day
, start_month
+ 1, start_year
);
1280 g_date_add_days (start_date
, day_offset
);
1282 *year
= g_date_get_year (start_date
);
1283 *month
= g_date_get_month (start_date
) - 1;
1284 *day
= g_date_get_day (start_date
);
1290 e_calendar_item_get_date_for_cell (ECalendarItem
*calitem
,
1297 gint index
= table_interface_get_index_at (ATK_TABLE (calitem
), row
, column
);
1299 return e_calendar_item_get_date_for_offset (calitem
, index
, year
, month
, day
);
1302 /* the arg month is from 0 to 11 */
1304 e_calendar_item_get_offset_for_date (ECalendarItem
*calitem
,
1310 gint start_year
, start_month
, start_day
;
1311 gint end_year
, end_month
, end_day
;
1312 GDate
*start_date
, *end_date
;
1315 g_return_val_if_fail (E_IS_CALENDAR_ITEM (calitem
), FALSE
);
1317 if (!e_calendar_item_get_date_range (calitem
, &start_year
,
1318 &start_month
, &start_day
,
1319 &end_year
, &end_month
,
1323 start_date
= g_date_new_dmy (start_day
, start_month
+ 1, start_year
);
1324 end_date
= g_date_new_dmy (day
, month
+ 1, year
);
1326 *offset
= g_date_days_between (start_date
, end_date
);
1327 g_free (start_date
);
1334 e_calendar_item_get_n_days_from_week_start (ECalendarItem
*calitem
,
1338 GDateWeekday weekday
;
1341 memset (&tmp_tm
, 0, sizeof (tmp_tm
));
1342 tmp_tm
.tm_year
= year
- 1900;
1343 tmp_tm
.tm_mon
= month
;
1345 tmp_tm
.tm_isdst
= -1;
1348 weekday
= e_weekday_from_tm_wday (tmp_tm
.tm_wday
);
1350 return e_weekday_get_days_between (calitem
->week_start_day
, weekday
);
1354 ea_calendar_set_focus_object (EaCalendarItem
*ea_calitem
,
1355 AtkObject
*item_cell
)
1357 AtkStateSet
*state_set
, *old_state_set
;
1358 AtkObject
*old_cell
;
1360 old_cell
= (AtkObject
*) g_object_get_data (
1361 G_OBJECT (ea_calitem
), "gail-focus-object");
1362 if (old_cell
&& EA_IS_CALENDAR_CELL (old_cell
)) {
1363 old_state_set
= atk_object_ref_state_set (old_cell
);
1364 atk_state_set_remove_state (old_state_set
, ATK_STATE_FOCUSED
);
1365 g_object_unref (old_state_set
);
1368 g_object_unref (old_cell
);
1370 state_set
= atk_object_ref_state_set (item_cell
);
1371 atk_state_set_add_state (state_set
, ATK_STATE_FOCUSED
);
1372 g_object_set_data (G_OBJECT (ea_calitem
), "gail-focus-object", item_cell
);
1373 g_object_unref (state_set
);