1 /*
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.
5  *
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
9  * for more details.
10  *
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/>.
13  *
14  *
15  * Authors:
16  *		Rodrigo Moya <rodrigo@ximian.com>
17  *
18  * Copyright (C) 1999-2008 Novell, Inc. (www.novell.com)
19  *
20  */
21 
22 #ifndef E_CALENDAR_VIEW_H
23 #define E_CALENDAR_VIEW_H
24 
25 #include <gtk/gtk.h>
26 #include <libecal/libecal.h>
27 
28 #include <calendar/gui/e-cal-model.h>
29 #include <calendar/gui/e-comp-editor.h>
30 
31 /* Standard GObject macros */
32 #define E_TYPE_CALENDAR_VIEW \
33 	(e_calendar_view_get_type ())
34 #define E_CALENDAR_VIEW(obj) \
35 	(G_TYPE_CHECK_INSTANCE_CAST \
36 	((obj), E_TYPE_CALENDAR_VIEW, ECalendarView))
37 #define E_CALENDAR_VIEW_CLASS(cls) \
38 	(G_TYPE_CHECK_CLASS_CAST \
39 	((cls), E_TYPE_CALENDAR_VIEW, ECalendarViewClass))
40 #define E_IS_CALENDAR_VIEW(obj) \
41 	(G_TYPE_CHECK_INSTANCE_TYPE \
42 	((obj), E_TYPE_CALENDAR_VIEW))
43 #define E_IS_CALENDAR_VIEW_CLASS(cls) \
44 	(G_TYPE_CHECK_CLASS_TYPE \
45 	((cls), E_TYPE_CALENDAR_VIEW))
46 #define E_CALENDAR_VIEW_GET_CLASS(obj) \
47 	(G_TYPE_INSTANCE_GET_CLASS \
48 	((obj), E_TYPE_CALENDAR_VIEW, ECalendarViewClass))
49 
50 G_BEGIN_DECLS
51 
52 #define E_CALENDAR_VIEW_TOOLTIP_OFFSET 16
53 
54 typedef enum {
55 	E_CALENDAR_VIEW_POS_OUTSIDE,
56 	E_CALENDAR_VIEW_POS_NONE,
57 	E_CALENDAR_VIEW_POS_EVENT,
58 	E_CALENDAR_VIEW_POS_LEFT_EDGE,
59 	E_CALENDAR_VIEW_POS_RIGHT_EDGE,
60 	E_CALENDAR_VIEW_POS_TOP_EDGE,
61 	E_CALENDAR_VIEW_POS_BOTTOM_EDGE
62 } ECalendarViewPosition;
63 
64 typedef enum {
65 	E_CAL_VIEW_MOVE_UP,
66 	E_CAL_VIEW_MOVE_DOWN,
67 	E_CAL_VIEW_MOVE_LEFT,
68 	E_CAL_VIEW_MOVE_RIGHT,
69 	E_CAL_VIEW_MOVE_PAGE_UP,
70 	E_CAL_VIEW_MOVE_PAGE_DOWN
71 } ECalViewMoveDirection;
72 
73 #define E_CALENDAR_VIEW_EVENT_FIELDS \
74 	GnomeCanvasItem *canvas_item; \
75 	ECalModelComponent *comp_data; \
76 	time_t start; \
77 	time_t end; \
78 	guint16 start_minute; \
79 	guint16 end_minute; \
80 	guint different_timezone : 1; \
81 	gboolean is_editable; \
82 	GtkWidget *tooltip; \
83 	gint	timeout; \
84 	GdkColor *color; \
85 	gint x,y;
86 
87 typedef struct {
88 	E_CALENDAR_VIEW_EVENT_FIELDS
89 } ECalendarViewEvent;
90 
91 /* checks if event->comp_data is not NULL, returns FALSE
92  * when it is and prints a warning on a console */
93 gboolean	is_comp_data_valid_func		(ECalendarViewEvent *event,
94 						 const gchar *location);
95 #define is_comp_data_valid(_event) \
96 	is_comp_data_valid_func ((ECalendarViewEvent *) (_event), G_STRFUNC)
97 
98 /* checks if index is within bounds for the array; returns
99  * FALSE when not, and prints a warning on a console */
100 gboolean	is_array_index_in_bounds_func	(GArray *array,
101 						 gint index,
102 						 const gchar *location);
103 #define is_array_index_in_bounds(_array, _index) \
104 	is_array_index_in_bounds_func (_array, _index, G_STRFUNC)
105 
106 typedef struct _ECalendarView ECalendarView;
107 typedef struct _ECalendarViewClass ECalendarViewClass;
108 typedef struct _ECalendarViewPrivate ECalendarViewPrivate;
109 
110 struct _ECalendarView {
111 	GtkGrid parent;
112 	gboolean in_focus;
113 	ECalendarViewPrivate *priv;
114 };
115 
116 typedef struct {
117 	ECalendarViewEvent * (*get_view_event)	(ECalendarView *view,
118 						 gint day,
119 						 gint event_num);
120 	ECalendarView *cal_view;
121 	gint day;
122 	gint event_num;
123 } ECalendarViewEventData;
124 
125 typedef enum {
126 	EDIT_EVENT_AUTODETECT,
127 	EDIT_EVENT_FORCE_MEETING,
128 	EDIT_EVENT_FORCE_APPOINTMENT
129 } EEditEventMode;
130 
131 typedef enum {
132 	E_CALENDAR_VIEW_MOVE_PREVIOUS,
133 	E_CALENDAR_VIEW_MOVE_NEXT,
134 	E_CALENDAR_VIEW_MOVE_TO_TODAY,
135 	E_CALENDAR_VIEW_MOVE_TO_EXACT_DAY
136 } ECalendarViewMoveType;
137 
138 typedef enum {
139 	E_NEW_APPOINTMENT_FLAG_NONE		  = 0,
140 	E_NEW_APPOINTMENT_FLAG_ALL_DAY		  = 1 << 0,
141 	E_NEW_APPOINTMENT_FLAG_MEETING		  = 1 << 1,
142 	E_NEW_APPOINTMENT_FLAG_NO_PAST_DATE	  = 1 << 2,
143 	E_NEW_APPOINTMENT_FLAG_FORCE_CURRENT_TIME = 1 << 3
144 } ENewAppointmentFlags;
145 
146 struct _ECalendarViewClass {
147 	GtkGridClass parent_class;
148 
149 	/* Notification signals */
150 	void		(*popup_event)		(ECalendarView *cal_view,
151 						 GdkEvent *button_event);
152 	void		(*selection_changed)	(ECalendarView *cal_view);
153 	void		(*selected_time_changed)(ECalendarView *cal_view);
154 	void		(*timezone_changed)	(ECalendarView *cal_view,
155 						 ICalTimezone *old_zone,
156 						 ICalTimezone *new_zone);
157 	void		(*event_changed)	(ECalendarView *day_view,
158 						 ECalendarViewEvent *event);
159 	void		(*event_added)		(ECalendarView *day_view,
160 						 ECalendarViewEvent *event);
161 	void		(*move_view_range)	(ECalendarView *cal_view,
162 						 ECalendarViewMoveType move_type,
163 						 gint64 exact_date);
164 
165 	/* Virtual methods */
166 	GList *		(*get_selected_events)	(ECalendarView *cal_view);
167 	gboolean	(*get_selected_time_range)
168 						(ECalendarView *cal_view,
169 						 time_t *start_time,
170 						 time_t *end_time);
171 	void		(*set_selected_time_range)
172 						(ECalendarView *cal_view,
173 						 time_t start_time,
174 						 time_t end_time);
175 	gboolean	(*get_visible_time_range)
176 						(ECalendarView *cal_view,
177 						 time_t *start_time,
178 						 time_t *end_time);
179 	void		(*precalc_visible_time_range)
180 						(ECalendarView *cal_view,
181 						 time_t in_start_time,
182 						 time_t in_end_time,
183 						 time_t *out_start_time,
184 						 time_t *out_end_time);
185 	void		(*update_query)		(ECalendarView *cal_view);
186 	void		(*open_event)		(ECalendarView *cal_view);
187 	void		(*paste_text)		(ECalendarView *cal_view);
188 	gchar *		(*get_description_text)	(ECalendarView *cal_view);
189 };
190 
191 GType		e_calendar_view_get_type	(void);
192 ECalModel *	e_calendar_view_get_model	(ECalendarView *cal_view);
193 ICalTimezone *	e_calendar_view_get_timezone	(ECalendarView *cal_view);
194 void		e_calendar_view_set_timezone	(ECalendarView *cal_view,
195 						 const ICalTimezone *zone);
196 gint		e_calendar_view_get_time_divisions
197 						(ECalendarView *cal_view);
198 void		e_calendar_view_set_time_divisions
199 						(ECalendarView *cal_view,
200 						 gint time_divisions);
201 GtkTargetList *	e_calendar_view_get_copy_target_list
202 						(ECalendarView *cal_view);
203 GtkTargetList *	e_calendar_view_get_paste_target_list
204 						(ECalendarView *cal_view);
205 
206 GList *		e_calendar_view_get_selected_events
207 						(ECalendarView *cal_view);
208 gboolean	e_calendar_view_get_selected_time_range
209 						(ECalendarView *cal_view,
210 						 time_t *start_time,
211 						 time_t *end_time);
212 void		e_calendar_view_set_selected_time_range
213 						(ECalendarView *cal_view,
214 						 time_t start_time,
215 						 time_t end_time);
216 gboolean	e_calendar_view_get_visible_time_range
217 						(ECalendarView *cal_view,
218 						 time_t *start_time,
219 						 time_t *end_time);
220 void		e_calendar_view_precalc_visible_time_range
221 						(ECalendarView *cal_view,
222 						 time_t in_start_time,
223 						 time_t in_end_time,
224 						 time_t *out_start_time,
225 						 time_t *out_end_time);
226 void		e_calendar_view_update_query	(ECalendarView *cal_view);
227 
228 void		e_calendar_view_delete_selected_occurrence
229 						(ECalendarView *cal_view,
230 						 ECalObjModType mod);
231 ECompEditor *	e_calendar_view_open_event_with_flags
232 						(ECalendarView *cal_view,
233 						 ECalClient *client,
234 						 ICalComponent *icomp,
235 						 guint32 flags);
236 
237 void		e_calendar_view_popup_event	(ECalendarView *cal_view,
238 						 GdkEvent *button_event);
239 
240 void		e_calendar_view_add_event	(ECalendarView *cal_view,
241 						 ECalClient *client,
242 						 time_t dtstart,
243 						 ICalTimezone *default_zone,
244 						 ICalComponent *icomp,
245 						 gboolean in_top_canvas);
246 void		e_calendar_view_new_appointment	(ECalendarView *cal_view,
247 						 guint32 flags); /* bit-or of ENewAppointmentFlags */
248 void		e_calendar_view_edit_appointment
249 						(ECalendarView *cal_view,
250 						 ECalClient *client,
251 						 ICalComponent *icomp,
252 						 EEditEventMode mode);
253 void		e_calendar_view_open_event	(ECalendarView *cal_view);
254 gchar *		e_calendar_view_get_description_text
255 						(ECalendarView *cal_view);
256 void		e_calendar_view_move_view_range	(ECalendarView *cal_view,
257 						 ECalendarViewMoveType mode_type,
258 						 time_t exact_date);
259 gboolean	e_calendar_view_get_tooltips	(const ECalendarViewEventData *data);
260 
261 void		e_calendar_view_move_tip	(GtkWidget *widget,
262 						 gint x,
263 						 gint y);
264 void		e_calendar_view_destroy_tooltip	(ECalendarView *cal_view);
265 
266 gchar *		e_calendar_view_dup_component_summary
267 						(ICalComponent *icomp);
268 
269 void		e_calendar_view_component_created_cb
270 						(ECalModel *model,
271 						 ECalClient *client,
272 						 ICalComponent *original_icomp,
273 						 const gchar *new_uid,
274 						 gpointer user_data);
275 
276 void		draw_curved_rectangle		(cairo_t *cr,
277 						 gdouble x0,
278 						 gdouble y0,
279 						 gdouble rect_width,
280 						 gdouble rect_height,
281 						 gdouble radius);
282 
283 GdkColor	get_today_background		(GdkColor event_background);
284 
285 gboolean	e_calendar_view_is_editing	(ECalendarView *cal_view);
286 gboolean	e_calendar_view_get_allow_direct_summary_edit
287 						(ECalendarView *cal_view);
288 void		e_calendar_view_set_allow_direct_summary_edit
289 						(ECalendarView *cal_view,
290 						 gboolean allow);
291 
292 G_END_DECLS
293 
294 #endif /* E_CALENDAR_VIEW_H */
295