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-day-view.h"
24 #include "ea-cal-view-event.h"
26 #include "ea-calendar-helpers.h"
27 #include "ea-gnome-calendar.h"
29 #include <glib/gi18n.h>
31 /* backward-compatibility cruft */
32 #include <e-util/gtk-compat.h>
34 static void ea_day_view_class_init (EaDayViewClass
*klass
);
36 static G_CONST_RETURN gchar
* ea_day_view_get_name (AtkObject
*accessible
);
37 static G_CONST_RETURN gchar
* ea_day_view_get_description (AtkObject
*accessible
);
38 static gint
ea_day_view_get_n_children (AtkObject
*obj
);
39 static AtkObject
* ea_day_view_ref_child (AtkObject
*obj
,
41 static gpointer parent_class
= NULL
;
44 ea_day_view_get_type (void)
46 static GType type
= 0;
47 AtkObjectFactory
*factory
;
49 GType derived_atk_type
;
52 static GTypeInfo tinfo
= {
53 sizeof (EaDayViewClass
),
54 (GBaseInitFunc
) NULL
, /* base init */
55 (GBaseFinalizeFunc
) NULL
, /* base finalize */
56 (GClassInitFunc
) ea_day_view_class_init
, /* class init */
57 (GClassFinalizeFunc
) NULL
, /* class finalize */
58 NULL
, /* class data */
59 sizeof (EaDayView
), /* 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 "EaDayView", &tinfo
, 0);
89 ea_day_view_class_init (EaDayViewClass
*klass
)
91 AtkObjectClass
*class = ATK_OBJECT_CLASS (klass
);
93 parent_class
= g_type_class_peek_parent (klass
);
95 class->get_name
= ea_day_view_get_name
;
96 class->get_description
= ea_day_view_get_description
;
98 class->get_n_children
= ea_day_view_get_n_children
;
99 class->ref_child
= ea_day_view_ref_child
;
103 ea_day_view_new (GtkWidget
*widget
)
106 AtkObject
*accessible
;
108 g_return_val_if_fail (E_IS_DAY_VIEW (widget
), NULL
);
110 object
= g_object_new (EA_TYPE_DAY_VIEW
, NULL
);
112 accessible
= ATK_OBJECT (object
);
113 atk_object_initialize (accessible
, widget
);
116 printf ("EvoAcc: ea_day_view created %p\n", (gpointer
)accessible
);
122 static G_CONST_RETURN gchar
*
123 ea_day_view_get_name (AtkObject
*accessible
)
127 const gchar
*label_text
;
128 GnomeCalendarViewType view_type
;
131 gchar
*event_str
, *name_str
;
133 g_return_val_if_fail (EA_IS_DAY_VIEW (accessible
), NULL
);
135 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
139 day_view
= E_DAY_VIEW (widget
);
140 gcal
= e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view
));
142 label_text
= ea_gnome_calendar_get_label_description (gcal
);
144 n_events
= atk_object_get_n_accessible_children (accessible
);
145 /* the child main item is always there */
148 /* To translators: Here, "It" is either like "Work Week View: July
149 10th - July 14th, 2006." or "Day View: Thursday July 13th, 2006." */
150 event_str
= g_strdup_printf (
151 ngettext ("It has %d event.",
152 "It has %d events.", n_events
), n_events
);
154 /* To translators: Here, "It" is either like "Work Week View: July
155 10th - July 14th, 2006." or "Day View: Thursday July 13th, 2006." */
156 event_str
= g_strdup (_("It has no events."));
158 view_type
= gnome_calendar_get_view (gcal
);
159 if (view_type
== GNOME_CAL_WORK_WEEK_VIEW
)
160 /* To translators: First %s is the week, for example "July 10th -
161 July 14th, 2006". Second %s is the number of events in this work
162 week, for example "It has %d event/events." or "It has no events." */
163 name_str
= g_strdup_printf (_("Work Week View: %s. %s"),
164 label_text
, event_str
);
166 /* To translators: First %s is the day, for example "Thursday July
167 13th, 2006". Second %s is the number of events on this day, for
168 example "It has %d event/events." or "It has no events." */
169 name_str
= g_strdup_printf (_("Day View: %s. %s"),
170 label_text
, event_str
);
172 ATK_OBJECT_CLASS (parent_class
)->set_name (accessible
, name_str
);
176 return accessible
->name
;
179 static G_CONST_RETURN gchar
*
180 ea_day_view_get_description (AtkObject
*accessible
)
185 g_return_val_if_fail (EA_IS_DAY_VIEW (accessible
), NULL
);
187 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
191 day_view
= E_DAY_VIEW (widget
);
193 if (accessible
->description
)
194 return accessible
->description
;
197 GnomeCalendarViewType view_type
;
199 gcal
= e_calendar_view_get_calendar (E_CALENDAR_VIEW (day_view
));
200 view_type
= gnome_calendar_get_view (gcal
);
202 if (view_type
== GNOME_CAL_WORK_WEEK_VIEW
)
203 return _("calendar view for a work week");
205 return _("calendar view for one or more days");
210 ea_day_view_get_n_children (AtkObject
*accessible
)
217 g_return_val_if_fail (EA_IS_DAY_VIEW (accessible
), -1);
219 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
223 day_view
= E_DAY_VIEW (widget
);
225 child_num
+= day_view
->long_events
->len
;
227 for (day
= 0; day
< day_view
->days_shown
; day
++) {
228 child_num
+= day_view
->events
[day
]->len
;
231 /* "+1" for the main item */
232 return child_num
+ 1;
236 ea_day_view_ref_child (AtkObject
*accessible
, gint index
)
241 AtkObject
*atk_object
= NULL
;
242 EDayViewEvent
*event
= NULL
;
245 g_return_val_if_fail (EA_IS_DAY_VIEW (accessible
), NULL
);
247 child_num
= atk_object_get_n_accessible_children (accessible
);
248 if (child_num
<= 0 || index
< 0 || index
>= child_num
)
251 widget
= gtk_accessible_get_widget (GTK_ACCESSIBLE (accessible
));
255 day_view
= E_DAY_VIEW (widget
);
258 /* index == 0 is the main item */
259 atk_object
= atk_gobject_accessible_for_object (
260 G_OBJECT (day_view
->main_canvas_item
));
261 g_object_ref (atk_object
);
266 if (index
< day_view
->long_events
->len
) {
267 event
= &g_array_index (day_view
->long_events
,
268 EDayViewEvent
, index
);
271 index
-= day_view
->long_events
->len
;
273 while (index
>= day_view
->events
[day
]->len
) {
274 index
-= day_view
->events
[day
]->len
;
278 event
= &g_array_index (day_view
->events
[day
],
279 EDayViewEvent
, index
);
281 if (event
&& event
->canvas_item
) {
282 /* Not use atk_gobject_accessible_for_object here,
283 * we need to do special thing here
285 atk_object
= ea_calendar_helpers_get_accessible_for (event
->canvas_item
);
286 g_object_ref (atk_object
);