No issues found
1 /*
2 *
3 * This program is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2 of the License, or (at your option) version 3.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with the program; if not, see <http://www.gnu.org/licenses/>
15 *
16 *
17 * Authors:
18 * Bolian Yin <bolian.yin@sun.com>
19 *
20 * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
21 *
22 */
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include "ea-calendar-helpers.h"
29 #include "ea-cal-view-event.h"
30 #include "ea-jump-button.h"
31 #include "e-day-view.h"
32 #include "e-week-view.h"
33
34 #include <text/e-text.h>
35 #include <libgnomecanvas/libgnomecanvas.h>
36
37 /**
38 * ea_calendar_helpers_get_accessible_for
39 * @canvas_item: the canvas item for a event or a jump button
40 *
41 * Returns: the atk object for the canvas_item
42 **/
43 AtkObject *
44 ea_calendar_helpers_get_accessible_for (GnomeCanvasItem *canvas_item)
45 {
46 AtkObject *atk_obj = NULL;
47 GObject *g_obj;
48
49 g_return_val_if_fail ((E_IS_TEXT (canvas_item)) ||
50 (GNOME_IS_CANVAS_ITEM (canvas_item)), NULL);
51
52 g_obj = G_OBJECT (canvas_item);
53 /* we cannot use atk_gobject_accessible_for_object here,
54 * EaDayViewEvent/EaWeekViewEvent cannot be created by the
55 * registered facotry of E_TEXT
56 */
57 atk_obj = g_object_get_data (g_obj, "accessible-object");
58 if (!atk_obj) {
59 if (E_IS_TEXT (canvas_item)) {
60 atk_obj = ea_cal_view_event_new (g_obj);
61 }
62 else if (GNOME_IS_CANVAS_PIXBUF (canvas_item)) {
63 atk_obj = ea_jump_button_new (g_obj);
64 }
65 else
66 return NULL;
67 }
68 return atk_obj;
69 }
70
71 /**
72 * ea_calendar_helpers_get_view_widget_from:
73 * @canvas_item: the canvas item for a event or a jump button
74 *
75 * Get the cal view widget contains the canvas_item.
76 *
77 * Returns: the cal view widget if exists
78 **/
79 ECalendarView *
80 ea_calendar_helpers_get_cal_view_from (GnomeCanvasItem *canvas_item)
81 {
82 GnomeCanvas *canvas;
83 GtkWidget *view_widget = NULL;
84
85 g_return_val_if_fail (canvas_item, NULL);
86 g_return_val_if_fail ((E_IS_TEXT (canvas_item)) ||
87 (GNOME_IS_CANVAS_ITEM (canvas_item)), NULL);
88
89 /* canvas_item is the e_text for the event */
90 /* canvas_item->canvas is the ECanvas for day view */
91 /* parent of canvas_item->canvas is the EDayView or EWeekView widget */
92 canvas = canvas_item->canvas;
93 view_widget = gtk_widget_get_parent (GTK_WIDGET (canvas));
94 if (!view_widget || !E_IS_CALENDAR_VIEW (view_widget))
95 return NULL;
96
97 return E_CALENDAR_VIEW (view_widget);
98 }
99
100 /**
101 * ea_calendar_helpers_get_cal_view_event_from
102 * @canvas_item: the cavas_item (e_text) for the event
103 *
104 * Get the ECalendarViewEvent for the canvas_item.
105 *
106 * Returns: the ECalendarViewEvent
107 **/
108 ECalendarViewEvent *
109 ea_calendar_helpers_get_cal_view_event_from (GnomeCanvasItem *canvas_item)
110 {
111 ECalendarView *cal_view;
112 gboolean event_found;
113 ECalendarViewEvent *cal_view_event;
114
115 g_return_val_if_fail (E_IS_TEXT (canvas_item), NULL);
116
117 cal_view = ea_calendar_helpers_get_cal_view_from (canvas_item);
118
119 if (!cal_view)
120 return NULL;
121
122 if (E_IS_DAY_VIEW (cal_view)) {
123 gint event_day, event_num;
124 EDayViewEvent *day_view_event;
125 EDayView *day_view = E_DAY_VIEW (cal_view);
126 event_found = e_day_view_find_event_from_item (
127 day_view, canvas_item,
128 &event_day, &event_num);
129 if (!event_found)
130 return NULL;
131 if (event_day == E_DAY_VIEW_LONG_EVENT) {
132 /* a long event */
133 day_view_event = &g_array_index (day_view->long_events,
134 EDayViewEvent, event_num);
135 }
136 else {
137 /* a main canvas event */
138 day_view_event = &g_array_index (day_view->events[event_day],
139 EDayViewEvent, event_num);
140 }
141 cal_view_event = (ECalendarViewEvent *) day_view_event;
142 }
143 else if (E_IS_WEEK_VIEW (cal_view)) {
144 gint event_num, span_num;
145 EWeekViewEvent *week_view_event;
146 EWeekView *week_view = E_WEEK_VIEW (cal_view);
147 event_found = e_week_view_find_event_from_item (
148 week_view,
149 canvas_item,
150 &event_num,
151 &span_num);
152 if (!event_found)
153 return NULL;
154
155 week_view_event = &g_array_index (
156 week_view->events, EWeekViewEvent, event_num);
157
158 cal_view_event = (ECalendarViewEvent *) week_view_event;
159 }
160 else {
161 g_return_val_if_reached (NULL);
162 }
163 return cal_view_event;
164 }