2
* Authors: Rodney Dawes <dobey.pwns@gmail.com>
4
* Copyright 2008 Rodney Dawes
12
#include "calview-month.h"
14
#include <glib/gi18n.h>
17
struct _CalViewMonthPrivate {
21
static void cal_view_month_finalize (GObject * object);
23
/* CalViewModel methods */
24
static void cal_view_month_expose (CalViewModel * model,
26
GdkEventExpose * event);
28
G_DEFINE_TYPE (CalViewMonth, cal_view_month, CAL_TYPE_VIEW_MODEL)
30
static void cal_view_month_class_init (CalViewMonthClass * klass) {
31
GObjectClass * o_class;
32
CalViewModelClass * parent_class;
34
o_class = (GObjectClass *) klass;
35
parent_class = (CalViewModelClass *) klass;
38
o_class->finalize = cal_view_month_finalize;
40
/* CalViewModel methods */
41
parent_class->expose_event = cal_view_month_expose;
44
static void cal_view_month_init (CalViewMonth * model) {
45
CalViewMonthPrivate * priv;
47
priv = g_new0 (CalViewMonthPrivate, 1);
51
static void cal_view_month_finalize (GObject * object) {
52
CalViewMonth * model = CAL_VIEW_MONTH (object);
58
static void cal_view_month_expose (CalViewModel * model,
60
GdkEventExpose * event) {
62
cairo_text_extents_t text;
67
int daysinmonth[12] = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
73
gboolean use_abbr = FALSE;
78
tmnow = localtime (&tnow);
80
wx = 0 + 1; //widget->allocation.x;
81
wy = widget->allocation.y + 1;
82
ww = widget->allocation.width - 2;
83
wh = widget->allocation.height - 2;
85
days = daysinmonth[tmnow->tm_mon];
86
/* If February in leap year, add a day */
87
if (tmnow->tm_mon == 1 && ((tmnow->tm_year + 1900) % 4) == 0)
90
context = gdk_cairo_create (widget->window);
92
cairo_set_tolerance (context, 0.0f);
93
cairo_set_operator (context, CAIRO_OPERATOR_OVER);
94
cairo_set_line_width (context, 1.0f);
96
cairo_rectangle (context, event->area.x, event->area.y,
97
event->area.width, event->area.height);
100
cairo_set_source_rgba (context, 1.0f, 1.0f, 1.0f, 1.0f);
101
cairo_rectangle (context, wx, wy, ww, wh);
102
cairo_fill (context);
104
cairo_text_extents (context, "Wednesday", &text);
107
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.05f);
108
cairo_rectangle (context, wx, wy, ww, th + 6.5);
109
cairo_fill (context);
111
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.2f);
112
cairo_move_to (context, wx, th + 6.5);
113
cairo_line_to (context, wx + ww, th + 6.5);
114
cairo_stroke (context);
116
bw = widget->allocation.width / 7;
117
bh = (widget->allocation.height - 6 - th) / 6;
119
if (bw < text.width + 12)
122
for (i = 1; i < 8; i++) {
124
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.2f);
125
cairo_move_to (context, (bw * i) + 0.5 + wx, th + 6);
126
cairo_line_to (context, (bw * i) + 0.5 + wx, wh);
127
cairo_stroke (context);
130
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 1.0f);
133
cairo_text_extents (context, use_abbr ? _("Sun") : _("Sunday"), &text);
134
cairo_move_to (context, (bw / 2) - (text.width / 2) + 0.5 + wx,
136
cairo_show_text (context, use_abbr ? _("Sun") : _("Sunday"));
139
cairo_text_extents (context, use_abbr ? _("Mon") : _("Monday"), &text);
140
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
142
cairo_show_text (context, use_abbr ? _("Mon") : _("Monday"));
145
cairo_text_extents (context, use_abbr ? _("Tue") : _("Tuesday"), &text);
146
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
148
cairo_show_text (context, use_abbr ? _("Tue") : _("Tuesday"));
151
cairo_text_extents (context, use_abbr ? _("Wed") : _("Wednesday"), &text);
152
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
154
cairo_show_text (context, use_abbr ? _("Wed") : _("Wednesday"));
157
cairo_text_extents (context, use_abbr ? _("Thu") : _("Thursday"), &text);
158
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
160
cairo_show_text (context, use_abbr ? _("Thu") : _("Thursday"));
163
cairo_text_extents (context, use_abbr ? _("Fri") : _("Friday"), &text);
164
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
166
cairo_show_text (context, use_abbr ? _("Fri") : _("Friday"));
169
cairo_text_extents (context, use_abbr ? _("Sat") : _("Saturday"), &text);
170
cairo_move_to (context, bw * (i - 1) + (bw / 2) - (text.width / 2) + 0.5 + wx,
172
cairo_show_text (context, use_abbr ? _("Sat") : _("Saturday"));
177
for (i = 1; i < 7; i++) {
179
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.2f);
180
cairo_move_to (context, wx, (bh * i) + (th + 6) + 0.5);
181
cairo_line_to (context, wx + ww, (bh * i) + (th + 6) + 0.5);
182
cairo_stroke (context);
184
cairo_set_source_rgba (context, 0.0f, 0.0f, 1.0f, 0.1f);
185
cairo_move_to (context, wx, (bh * (i - 1)) + (th + 6) + 0.5);
186
cairo_rectangle (context, wx, (bh * (i - 1)) + (th + 6) + 0.5,
188
cairo_fill (context);
192
wday = tmnow->tm_wday;
194
for (i = tmnow->tm_mday; i > 0; i--) {
202
if (tmnow->tm_wday == 6)
207
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.215f);
208
cairo_rectangle (context,
209
tmnow->tm_wday * bw + wx,
210
(th + 6) + (bh * tweek),
212
cairo_fill (context);
215
wday = tmnow->tm_wday;
217
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 1.0f);
218
for (i = tmnow->tm_mday; i > 0; i--) {
221
label = g_strdup_printf ("%d", i);
222
cairo_text_extents (context, label, &text);
223
cairo_move_to (context, bw * wday + (bw - text.width - 6) + wx,
224
(th + 16) + (bh * week) + (th + 6) / 2 + 0.5);
225
cairo_show_text (context, label);
236
if (wday != 0 || week == 0) {
237
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.08f);
238
cairo_rectangle (context, wx, (th + 6.5),
239
bw * (wday + 1), bh);
240
cairo_fill (context);
244
wday = tmnow->tm_wday + 1;
251
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 1.0f);
252
for (i = tmnow->tm_mday + 1; i <= days; i++) {
255
label = g_strdup_printf ("%d", i);
256
cairo_text_extents (context, label, &text);
257
cairo_move_to (context, bw * wday + (bw - text.width - 6) + wx,
258
(th + 16) + (bh * week) + (th + 6) / 2 + 0.5);
259
cairo_show_text (context, label);
271
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.08f);
273
cairo_set_source_rgba (context, 0.0f, 0.0f, 0.0f, 0.08f);
274
cairo_rectangle (context, bw * wday + wx,
275
(th + 6) + bh * week,
277
cairo_fill (context);
280
cairo_rectangle (context, wx, (th + 6) + bh * 5,
282
cairo_fill (context);
285
cairo_destroy (context);
287
/* Just Temporary - Will get a shadow from the ScrolledWindow instead */
288
gtk_paint_shadow (widget->style, widget->window, GTK_STATE_NORMAL,
289
GTK_SHADOW_IN, &event->area, widget, "calview",
290
0, 0, widget->allocation.width, widget->allocation.height);
294
CalViewModel * cal_view_month_new (void) {
295
return CAL_VIEW_MODEL (g_object_new (CAL_TYPE_VIEW_MONTH, NULL));