1 /* GTK - The GIMP Toolkit
2  * Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
3  *
4  * GTK Calendar Widget
5  * Copyright (C) 1998 Cesar Miquel and Shawn T. Amundson
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free
19  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20  */
21 
22 /*
23  * Modified by the GTK+ Team and others 1997-2000.  See the AUTHORS
24  * file for a list of people on the GTK+ Team.  See the ChangeLog
25  * files for a list of changes.  These files are distributed with
26  * GTK+ at ftp://ftp.gtk.org/pub/gtk/.
27  */
28 
29 /*
30  * Some minor modifications and adaptation to OSMO - a handy personal
31  * manager by pasp@users.sourceforge.net
32  */
33 
34 #ifndef _CALENDAR_WIDGET_H
35 #define _CALENDAR_WIDGET_H
36 
37 #include <glib-object.h>
38 #include <gtk/gtk.h>
39 
40 G_BEGIN_DECLS
41 
42 /* Spacing around day/week headers and main area, inside those windows */
43 #define CALENDAR_MARGIN      0
44 /* Spacing around day/week headers and main area, outside those windows */
45 #define INNER_BORDER         2
46 /* Separation between day headers and main area */
47 #define CALENDAR_YSEP        4
48 /* Separation between week headers and main area */
49 #define CALENDAR_XSEP        4
50 
51 #define DAY_XSEP             0  /* not really good for small calendar */
52 #define DAY_YSEP             0  /* not really good for small calendar */
53 
54 #define SCROLL_DELAY_FACTOR  5
55 
56 #define GUI_TYPE_CALENDAR                  (gui_calendar_get_type ())
57 #define GUI_CALENDAR(obj)                  (G_TYPE_CHECK_INSTANCE_CAST ((obj), GUI_TYPE_CALENDAR, GuiCalendar))
58 #define GUI_CALENDAR_CLASS(klass)          (G_TYPE_CHECK_CLASS_CAST ((klass), GUI_TYPE_CALENDAR, GuiCalendarClass))
59 #define GUI_IS_CALENDAR(obj)               (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GUI_TYPE_CALENDAR))
60 #define GUI_IS_CALENDAR_CLASS(klass)       (G_TYPE_CHECK_CLASS_TYPE ((klass), GUI_TYPE_CALENDAR))
61 #define GUI_CALENDAR_GET_CLASS(obj)        (G_TYPE_INSTANCE_GET_CLASS ((obj), GUI_TYPE_CALENDAR, GuiCalendarClass))
62 
63 typedef struct _GuiCalendar             GuiCalendar;
64 typedef struct _GuiCalendarClass       GuiCalendarClass;
65 
66 typedef struct _GuiCalendarPrivate     GuiCalendarPrivate;
67 
68 typedef enum {
69     GUI_CALENDAR_SHOW_HEADING       = 1 << 0,
70     GUI_CALENDAR_SHOW_DAY_NAMES     = 1 << 1,
71     GUI_CALENDAR_NO_MONTH_CHANGE    = 1 << 2,
72     GUI_CALENDAR_SHOW_WEEK_NUMBERS  = 1 << 3,
73     GUI_CALENDAR_WEEK_START_MONDAY  = 1 << 4
74 } GuiCalendarDisplayOptions;
75 
76 enum {
77     ARROW_YEAR_LEFT,
78     ARROW_YEAR_RIGHT,
79     ARROW_MONTH_LEFT,
80     ARROW_MONTH_RIGHT
81 };
82 
83 enum {
84     MONTH_PREV,
85     MONTH_CURRENT,
86     MONTH_NEXT
87 };
88 
89 enum {
90     MONTH_CHANGED_SIGNAL,
91     DAY_SELECTED_SIGNAL,
92     DAY_SELECTED_DOUBLE_CLICK_SIGNAL,
93     PREV_MONTH_SIGNAL,
94     NEXT_MONTH_SIGNAL,
95     PREV_YEAR_SIGNAL,
96     NEXT_YEAR_SIGNAL,
97     LAST_SIGNAL
98 };
99 
100 enum {
101     PROP_0,
102     PROP_YEAR,
103     PROP_MONTH,
104     PROP_DAY,
105     PROP_SHOW_HEADING,
106     PROP_SHOW_DAY_NAMES,
107     PROP_NO_MONTH_CHANGE,
108     PROP_SHOW_WEEK_NUMBERS,
109     PROP_WEEK_START_MONDAY,
110     PROP_LAST
111 };
112 
113 enum {
114     CURSOR_BLOCK = 0,
115     CURSOR_FRAME
116 };
117 
118 enum {
119 	EVENT_MARKER_CIRCLE = 0,
120 	EVENT_MARKER_ELLIPSE,
121 	EVENT_MARKER_WAVE
122 };
123 
124 enum {
125 	TODAY_MARKER_ARROW = 0,
126 	TODAY_MARKER_FREEHAND_CIRCLE
127 };
128 
129 enum {
130 	TODAY_MARKER =0,
131 	EVENT_MARKER
132 };
133 
134 enum {
135 	DAY_NOTE_MARK =0,
136 	EVENT_MARK,
137 	BIRTHDAY_MARK
138 };
139 
140 enum {
141 	HEADER_BG_COLOR = 0,
142 	HEADER_FG_COLOR,
143 	WEEKEND_COLOR,
144 	SELECTOR_COLOR,
145 	EVENT_MARKER_COLOR,
146 	TODAY_MARKER_COLOR,
147 	BIRTHDAY_MARKER_COLOR,
148 	DAY_COLOR,
149 	PF_DAY_COLOR,
150 	BACKGROUND_COLOR
151 };
152 
153 struct _GuiCalendarPrivate {
154     GdkWindow *header_win;
155     GdkWindow *day_name_win;
156     GdkWindow *main_win;
157     GdkWindow *week_win;
158     GdkWindow *arrow_win[4];
159 
160     guint header_h;
161     guint day_name_h;
162     guint main_h;
163 
164     GtkStateFlags arrow_state[4];
165     guint arrow_width;
166     guint max_month_width;
167     guint max_year_width;
168 
169     guint day_width;
170     guint week_width;
171 
172     guint min_day_width;
173     guint max_day_char_width;
174     guint max_day_char_ascent;
175     guint max_day_char_descent;
176     guint max_label_char_ascent;
177     guint max_label_char_descent;
178     guint max_week_char_width;
179 
180     /* flags */
181 	guint year_before : 1;
182 	guint need_timer  : 1;
183 	guint in_drag : 1;
184 	guint drag_highlight : 1;
185 
186     guint32 timer;
187     gint click_child;
188 
189     gint week_start;
190 
191     gint drag_start_x;
192     gint drag_start_y;
193 };
194 
195 #define GUI_CALENDAR_GET_PRIVATE(widget)  (GUI_CALENDAR (widget)->priv)
196 
197 struct _GuiCalendar {
198     GtkWidget widget;
199 
200     GtkStyle  *header_style;
201     GtkStyle  *label_style;
202 
203     gint month;
204     gint year;
205     gint selected_day;
206 
207     gint day_month[6][7];
208     gint day[6][7];
209 
210 	/* day notes */
211     gint num_marked_dates;
212     gint marked_date[31];
213 	/* events */
214 	gint event_num_marked_dates;
215     gint event_marked_date[31];
216 	/* birthdays */
217 	gint birthday_num_marked_dates;
218     gint birthday_marked_date[31];
219 
220     GuiCalendarDisplayOptions  display_flags;
221     GdkRGBA marked_date_color[31];
222 
223     GdkRGBA background_color;
224     GdkRGBA header_bg_color;
225     GdkRGBA header_fg_color;
226     GdkRGBA weekend_color;
227     GdkRGBA selector_color;
228     GdkRGBA event_marker_color;
229     GdkRGBA today_marker_color;
230     GdkRGBA birthday_marker_color;
231     GdkRGBA day_color;
232     GdkRGBA pf_day_color;
233 
234     gunichar mark_sign;
235     gint cursor_type;
236     gint frame_cursor_thickness;
237 	gint event_marker_type;
238 	gint today_marker_type;
239 
240     gboolean enable_cursor;
241 
242     gint focus_row;
243     gint focus_col;
244 
245     gint highlight_row;
246     gint highlight_col;
247 
248     GuiCalendarPrivate *priv;
249     gchar grow_space [32];
250 
251     /* Padding for future expansion */
252     void (*_gtk_reserved1) (void);
253     void (*_gtk_reserved2) (void);
254     void (*_gtk_reserved3) (void);
255     void (*_gtk_reserved4) (void);
256 };
257 
258 struct _GuiCalendarClass {
259     GtkWidgetClass parent_class;
260 
261     /* Signal handlers */
262     void (* month_changed)                  (GuiCalendar *calendar);
263     void (* day_selected)                       (GuiCalendar *calendar);
264     void (* day_selected_double_click)      (GuiCalendar *calendar);
265     void (* prev_month)                     (GuiCalendar *calendar);
266     void (* next_month)                     (GuiCalendar *calendar);
267     void (* prev_year)                      (GuiCalendar *calendar);
268     void (* next_year)                      (GuiCalendar *calendar);
269 
270 };
271 
272 GType      gui_calendar_get_type            (void) G_GNUC_CONST;
273 GtkWidget* gui_calendar_new                 (void);
274 
275 gboolean   gui_calendar_select_month        (GuiCalendar *calendar, guint month, guint year);
276 void       gui_calendar_select_day          (GuiCalendar *calendar, guint day);
277 
278 gboolean   gui_calendar_mark_day            (GuiCalendar *calendar, guint day, gint mark_type);
279 gboolean   gui_calendar_unmark_day          (GuiCalendar *calendar, guint day, gint mark_type);
280 void       gui_calendar_clear_marks         (GuiCalendar *calendar, gint mark_type);
281 gboolean   gui_calendar_set_day_color       (GuiCalendar *calendar, guint day, gchar *color_str);
282 
283 void       gui_calendar_set_display_options (GuiCalendar *calendar, GuiCalendarDisplayOptions flags);
284 GuiCalendarDisplayOptions
285 		   gui_calendar_get_display_options (GuiCalendar *calendar);
286 
287 void       gui_calendar_get_date            (GuiCalendar *calendar, guint *year, guint *month, guint *day);
288 void       gui_calendar_get_gdate           (GuiCalendar *calendar, GDate *cdate);
289 
290 void       gui_calendar_set_marker                  (GuiCalendar *calendar, gint marker_type, gint marker);
291 void       gui_calendar_set_day_note_marker_symbol  (GuiCalendar *calendar, gchar *symbol);
292 void       gui_calendar_set_color                   (GuiCalendar *calendar, const gchar *color,
293 											         gint alpha_value, gint color_type);
294 
295 void       gui_calendar_enable_cursor              (GuiCalendar *calendar, gboolean state);
296 void       gui_calendar_set_cursor_type            (GuiCalendar *calendar, gint cursor_type);
297 void       gui_calendar_set_frame_cursor_thickness (GuiCalendar *calendar, gint thickness);
298 
299 G_END_DECLS
300 
301 #endif /* _CALENDAR_WIDGET_H */
302 
303