2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU Lesser General Public
4 * License as published by the Free Software Foundation; either
5 * version 2 of the License, or (at your option) version 3.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * Lesser General Public License for more details.
12 * You should have received a copy of the GNU Lesser General Public
13 * License along with the program; if not, see <http://www.gnu.org/licenses/>
17 * Bolian Yin <bolian.yin@sun.com>
19 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
23 #include "ea-week-view.h"
24 #include "ea-cal-view-event.h"
25 #include "ea-calendar-helpers.h"
26 #include "ea-gnome-calendar.h"
27 #include <text/e-text.h>
28 #include <glib/gi18n.h>
30 /* backward-compatibility cruft */
31 #include <e-util/gtk-compat.h>
33 static void ea_week_view_class_init (EaWeekViewClass
*klass
);
35 static G_CONST_RETURN gchar
* ea_week_view_get_name (AtkObject
*accessible
);
36 static G_CONST_RETURN gchar
* ea_week_view_get_description (AtkObject
*accessible
);
37 static gint
ea_week_view_get_n_children (AtkObject
*obj
);
38 static AtkObject
* ea_week_view_ref_child (AtkObject
*obj
,
41 static gpointer parent_class
= NULL
;
44 ea_week_view_get_type (void)
46 static GType type
= 0;
47 AtkObjectFactory
*factory
;
49 GType derived_atk_type
;
52 static GTypeInfo tinfo
= {
53 sizeof (EaWeekViewClass
),
54 (GBaseInitFunc
) NULL
, /* base init */
55 (GBaseFinalizeFunc
) NULL
, /* base finalize */
56 (GClassInitFunc
) ea_week_view_class_init
, /* class init */
57 (GClassFinalizeFunc
) NULL
, /* class finalize */
58 NULL
, /* class data */
59 sizeof (EaWeekView
), /* instance size */
61 (GInstanceInitFunc
) NULL
, /* instance init */
62 NULL
/* value table */
66 * Figure out the size of the class and instance
67 * we are run-time deriving from (EaCalView, in this case)
69 * Note: we must still use run-time deriving here, because
70 * our parent class EaCalView is run-time deriving.
73 factory
= atk_registry_get_factory (atk_get_default_registry (),
74 e_calendar_view_get_type ());
75 derived_atk_type
= atk_object_factory_get_accessible_type (factory
);
76 g_type_query (derived_atk_type
, &query
);
78 tinfo
.class_size
= query
.class_size
;
79 tinfo
.instance_size
= query
.instance_size
;
81 type
= g_type_register_static (derived_atk_type
,
82 "EaWeekView", &tinfo
, 0);
90 ea_week_view_class_init (EaWeekViewClass
*klass
)
92 AtkObjectClass
*class = ATK_OBJECT_CLASS (klass
);
94 parent_class
= g_type_class_peek_parent (klass
);
96 class->get_name
= ea_week_view_get_name
;
97 class->get_description
= ea_week_view_get_description
;
99 class->get_n_children
= ea_week_view_get_n_children
;
100 class->ref_child
= ea_week_view_ref_child
;
104 ea_week_view_new (GtkWidget
*widget
)
107 AtkObject
*accessible
;
109 g_return_val_if_fail (GTK_IS_WIDGET (widget
), NULL
);
111 object
= g_object_new (EA_TYPE_WEEK_VIEW
, NULL
);
113 accessible
= ATK_OBJECT (object
);
114 atk_object_initialize (accessible
, widget
);
117 printf ("EvoAcc: ea_week_view created %p\n", (gpointer
)accessible
);
123 static G_CONST_RETURN gchar
*
124 ea_week_view_get_name (AtkObject
*accessible
)
126 EWeekView
*week_view
;
128 const gchar
*label_text
;
129 GnomeCalendarViewType view_type
;
132 gchar
*event_str
, *name_str
;
134 g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible
), NULL
);
136 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
140 week_view
= E_WEEK_VIEW (widget
);
141 gcal
= e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view
));
143 label_text
= ea_gnome_calendar_get_label_description (gcal
);
145 n_events
= atk_object_get_n_accessible_children (accessible
);
146 /* the child main item is always there */
149 event_str
= g_strdup_printf (
150 ngettext ("It has %d event.", "It has %d events.",
151 n_events
), n_events
);
153 event_str
= g_strdup (_("It has no events."));
155 view_type
= gnome_calendar_get_view (gcal
);
157 if (view_type
== GNOME_CAL_MONTH_VIEW
)
158 name_str
= g_strdup_printf (_("Month View: %s. %s"),
159 label_text
, event_str
);
162 name_str
= g_strdup_printf (_("Week View: %s. %s"),
163 label_text
, event_str
);
165 ATK_OBJECT_CLASS (parent_class
)->set_name (accessible
, name_str
);
169 return accessible
->name
;
172 static G_CONST_RETURN gchar
*
173 ea_week_view_get_description (AtkObject
*accessible
)
175 EWeekView
*week_view
;
178 g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible
), NULL
);
180 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
184 week_view
= E_WEEK_VIEW (widget
);
186 if (accessible
->description
)
187 return accessible
->description
;
190 GnomeCalendarViewType view_type
;
192 gcal
= e_calendar_view_get_calendar (E_CALENDAR_VIEW (week_view
));
193 view_type
= gnome_calendar_get_view (gcal
);
195 if (view_type
== GNOME_CAL_MONTH_VIEW
)
196 return _("calendar view for a month");
198 return _("calendar view for one or more weeks");
203 ea_week_view_get_n_children (AtkObject
*accessible
)
205 EWeekView
*week_view
;
210 g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible
), -1);
212 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
216 week_view
= E_WEEK_VIEW (widget
);
218 for (event_index
= 0; event_index
< week_view
->events
->len
;
220 EWeekViewEvent
*event
;
221 EWeekViewEventSpan
*span
;
223 /* If week_view->spans == NULL, there is no visible events. */
224 if (!week_view
->spans
)
227 event
= &g_array_index (week_view
->events
,
228 EWeekViewEvent
, event_index
);
231 span
= &g_array_index (week_view
->spans
, EWeekViewEventSpan
,
232 event
->spans_index
+ 0);
237 /* at least one of the event spans is visible, count it */
242 /* add the number of visible jump buttons */
243 for (i
= 0; i
< E_WEEK_VIEW_MAX_WEEKS
* 7; i
++) {
244 if (week_view
->jump_buttons
[i
]->flags
& GNOME_CANVAS_ITEM_VISIBLE
)
248 /* "+1" for the main item */
252 printf("AccDebug: week view %p has %d children\n", (gpointer
)week_view
, count
);
258 ea_week_view_ref_child (AtkObject
*accessible
, gint index
)
260 EWeekView
*week_view
;
261 gint child_num
, max_count
;
262 AtkObject
*atk_object
= NULL
;
265 gint jump_button
= -1;
269 g_return_val_if_fail (EA_IS_WEEK_VIEW (accessible
), NULL
);
271 child_num
= atk_object_get_n_accessible_children (accessible
);
272 if (child_num
<= 0 || index
< 0 || index
>= child_num
)
275 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
279 week_view
= E_WEEK_VIEW (widget
);
280 max_count
= week_view
->events
->len
;
283 /* index == 0 is the main item */
284 atk_object
= atk_gobject_accessible_for_object (
285 G_OBJECT (week_view
->main_canvas_item
));
286 g_object_ref (atk_object
);
288 for (event_index
= 0; event_index
< max_count
; ++event_index
) {
289 EWeekViewEvent
*event
;
290 EWeekViewEventSpan
*span
;
293 event
= &g_array_index (week_view
->events
,
294 EWeekViewEvent
, event_index
);
298 span
= &g_array_index (week_view
->spans
, EWeekViewEventSpan
,
299 event
->spans_index
+ span_num
);
304 current_day
= span
->start_day
;
307 else if (current_day
!= jump_button
) {
308 /* we should go to the jump button */
309 jump_button
= current_day
;
315 if (count
== index
) {
316 if (span
->text_item
) {
317 /* Not use atk_gobject_accessible_for_object for event
318 * text_item we need to do special thing here
320 atk_object
= ea_calendar_helpers_get_accessible_for (span
->text_item
);
325 index
= (current_day
!= -1) ? current_day
: 0;
326 atk_object
= ea_calendar_helpers_get_accessible_for (
327 week_view
->jump_buttons
[index
]);
329 g_object_ref (atk_object
);
335 printf ("EvoAcc: ea_week_view_ref_child [%d]=%p\n",
336 index
, (gpointer
)atk_object
);