aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
Diffstat (limited to 'calendar')
-rw-r--r--calendar/gui/mark.c122
-rw-r--r--calendar/gui/mark.h24
-rw-r--r--calendar/mark.c122
-rw-r--r--calendar/mark.h24
4 files changed, 292 insertions, 0 deletions
diff --git a/calendar/gui/mark.c b/calendar/gui/mark.c
new file mode 100644
index 0000000000..b1c6df8fa3
--- /dev/null
+++ b/calendar/gui/mark.c
@@ -0,0 +1,122 @@
+/* Functions to mark calendars
+ *
+ * Copyright (C) 1998 Red Hat Software, Inc.
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#include <config.h>
+#include "mark.h"
+#include "timeutil.h"
+
+
+/* In the month item, marks all the days that are touched by the specified time span. Assumes that
+ * the time span is completely contained within the month.
+ */
+static void
+mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
+{
+ struct tm tm;
+ GnomeCanvasItem *item;
+ int day_index;
+
+ tm = *localtime (&start);
+
+ for (; start <= end; start += 60 * 60 * 24) {
+ mktime (&tm); /* normalize the time */
+
+ /* Figure out the day index that corresponds to this time */
+
+ day_index = gnome_month_item_day2index (mitem, tm.tm_mday);
+ g_assert (day_index >= 0);
+
+ /* Mark the day box */
+
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "tan",
+ NULL);
+
+ /* Mark the day label */
+
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "black",
+ NULL);
+
+ /* Next day */
+
+ tm.tm_mday++;
+ }
+}
+
+static void
+mark_current_day (GnomeMonthItem *mitem)
+{
+ struct tm *tm;
+ time_t t;
+ int day_index;
+ GnomeCanvasItem *item;
+
+ t = time (NULL);
+ tm = localtime (&t);
+
+ if (((tm->tm_year + 1900) == mitem->year) && (tm->tm_mon == mitem->month)) {
+ day_index = gnome_month_item_day2index (mitem, tm->tm_mday);
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "blue",
+ NULL);
+ }
+}
+
+void
+mark_month_item (GnomeMonthItem *mitem, Calendar *cal)
+{
+ time_t month_begin, month_end;
+ GList *list, *l;
+ CalendarObject *co;
+
+ month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1));
+ month_end = time_month_end (month_begin);
+
+ list = calendar_get_events_in_range (cal, month_begin, month_end);
+
+ for (l = list; l; l = l->next) {
+ co = l->data;
+
+ /* We clip the event's start and end times to the month's limits */
+
+ mark_event_in_month (mitem, MAX (co->ev_start, month_begin), MIN (co->ev_end, month_end));
+ }
+
+ calendar_destroy_event_list (list);
+
+ mark_current_day (mitem);
+}
+
+void
+unmark_month_item (GnomeMonthItem *mitem)
+{
+ int i;
+ GnomeCanvasItem *item;
+
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+
+ for (i = 0; i < 42; i++) {
+ /* Box */
+
+ item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_BOX + i);
+ gnome_canvas_item_set (item,
+ "fill_color", "#d6d6d6d6d6d6",
+ NULL);
+
+ /* Label */
+
+ item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_LABEL + i);
+ gnome_canvas_item_set (item,
+ "fill_color", "black",
+ NULL);
+ }
+}
diff --git a/calendar/gui/mark.h b/calendar/gui/mark.h
new file mode 100644
index 0000000000..9ffafe20a7
--- /dev/null
+++ b/calendar/gui/mark.h
@@ -0,0 +1,24 @@
+/* Functions to mark calendars
+ *
+ * Copyright (C) 1998 Red Hat Software, Inc.
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#ifndef MARK_H
+#define MARK_H
+
+#include "calendar.h"
+#include "gnome-month-item.h"
+
+
+/* Takes a monthly calendar item and marks the days that have events scheduled for them in the
+ * specified calendar. It also highlights the current day.
+ */
+void mark_month_item (GnomeMonthItem *mitem, Calendar *cal);
+
+/* Unmarks all the days in the specified month item */
+void unmark_month_item (GnomeMonthItem *mitem);
+
+
+#endif
diff --git a/calendar/mark.c b/calendar/mark.c
new file mode 100644
index 0000000000..b1c6df8fa3
--- /dev/null
+++ b/calendar/mark.c
@@ -0,0 +1,122 @@
+/* Functions to mark calendars
+ *
+ * Copyright (C) 1998 Red Hat Software, Inc.
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#include <config.h>
+#include "mark.h"
+#include "timeutil.h"
+
+
+/* In the month item, marks all the days that are touched by the specified time span. Assumes that
+ * the time span is completely contained within the month.
+ */
+static void
+mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
+{
+ struct tm tm;
+ GnomeCanvasItem *item;
+ int day_index;
+
+ tm = *localtime (&start);
+
+ for (; start <= end; start += 60 * 60 * 24) {
+ mktime (&tm); /* normalize the time */
+
+ /* Figure out the day index that corresponds to this time */
+
+ day_index = gnome_month_item_day2index (mitem, tm.tm_mday);
+ g_assert (day_index >= 0);
+
+ /* Mark the day box */
+
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "tan",
+ NULL);
+
+ /* Mark the day label */
+
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "black",
+ NULL);
+
+ /* Next day */
+
+ tm.tm_mday++;
+ }
+}
+
+static void
+mark_current_day (GnomeMonthItem *mitem)
+{
+ struct tm *tm;
+ time_t t;
+ int day_index;
+ GnomeCanvasItem *item;
+
+ t = time (NULL);
+ tm = localtime (&t);
+
+ if (((tm->tm_year + 1900) == mitem->year) && (tm->tm_mon == mitem->month)) {
+ day_index = gnome_month_item_day2index (mitem, tm->tm_mday);
+ item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
+ gnome_canvas_item_set (item,
+ "fill_color", "blue",
+ NULL);
+ }
+}
+
+void
+mark_month_item (GnomeMonthItem *mitem, Calendar *cal)
+{
+ time_t month_begin, month_end;
+ GList *list, *l;
+ CalendarObject *co;
+
+ month_begin = time_month_begin (time_from_day (mitem->year, mitem->month, 1));
+ month_end = time_month_end (month_begin);
+
+ list = calendar_get_events_in_range (cal, month_begin, month_end);
+
+ for (l = list; l; l = l->next) {
+ co = l->data;
+
+ /* We clip the event's start and end times to the month's limits */
+
+ mark_event_in_month (mitem, MAX (co->ev_start, month_begin), MIN (co->ev_end, month_end));
+ }
+
+ calendar_destroy_event_list (list);
+
+ mark_current_day (mitem);
+}
+
+void
+unmark_month_item (GnomeMonthItem *mitem)
+{
+ int i;
+ GnomeCanvasItem *item;
+
+ g_return_if_fail (mitem != NULL);
+ g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
+
+ for (i = 0; i < 42; i++) {
+ /* Box */
+
+ item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_BOX + i);
+ gnome_canvas_item_set (item,
+ "fill_color", "#d6d6d6d6d6d6",
+ NULL);
+
+ /* Label */
+
+ item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_LABEL + i);
+ gnome_canvas_item_set (item,
+ "fill_color", "black",
+ NULL);
+ }
+}
diff --git a/calendar/mark.h b/calendar/mark.h
new file mode 100644
index 0000000000..9ffafe20a7
--- /dev/null
+++ b/calendar/mark.h
@@ -0,0 +1,24 @@
+/* Functions to mark calendars
+ *
+ * Copyright (C) 1998 Red Hat Software, Inc.
+ *
+ * Author: Federico Mena <federico@nuclecu.unam.mx>
+ */
+
+#ifndef MARK_H
+#define MARK_H
+
+#include "calendar.h"
+#include "gnome-month-item.h"
+
+
+/* Takes a monthly calendar item and marks the days that have events scheduled for them in the
+ * specified calendar. It also highlights the current day.
+ */
+void mark_month_item (GnomeMonthItem *mitem, Calendar *cal);
+
+/* Unmarks all the days in the specified month item */
+void unmark_month_item (GnomeMonthItem *mitem);
+
+
+#endif