aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
authorFederico Mena Quintero <federico@nuclecu.unam.mx>1998-08-30 09:29:19 +0800
committerArturo Espinosa <unammx@src.gnome.org>1998-08-30 09:29:19 +0800
commite0d99122ab17d9bf356cf793b41aec6b6d6016b1 (patch)
treeb2f202ce6ea0b927a8fa4929034c84af223ef782 /calendar/gui
parent9b6991077bd564348e9dd229ca523bdaa8239ed1 (diff)
downloadgsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.tar.gz
gsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.tar.zst
gsoc2013-evolution-e0d99122ab17d9bf356cf793b41aec6b6d6016b1.zip
Centralized marking of month items. We now have a little utility function
Centralized marking of month items. We now have a little utility function to colorify the days in a month item that have events scheduled for them. This is currently used by the year view and the go-to dialog. Fixed buglets here and there. 1998-08-29 Federico Mena Quintero <federico@nuclecu.unam.mx> * mark.[ch]: New files with utility functions to mark calendars with their events. * mark.c (mark_month_item): New public function to mark a month item with events. (unmark_month_item): New public function to unmark all the days in a month item to their default appearance. * year-view.c (year_view_set): Use the new unmark_month_item() and mark_month_item() to mark the months with events. * goto.c (update): New function that updates the calendar in the Go-to dialog by marking the days. * timeutil.c (time_year_begin): Modified to take a time_t value. (time_year_end): Likewise. (time_month_begin): Actually implemented this function, which was in the header file but not here. (time_days_in_month): New public function that returns the number of days in a month. * Makefile.am (gnomecal_SOURCES): Added mark.[ch] to the sources. * year-view.c (unmark_days): Use unmark_month_item(). * gncal-full-day.c (gncal_full_day_destroy): Fixed crash when destroying the full day view. The full day's destroy method is unusual in that it destroys the list of child widgets itself, as it does not have a remove method, so it needs to reset the list to NULL. svn path=/trunk/; revision=351
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/Makefile.am2
-rw-r--r--calendar/gui/gncal-full-day.c2
-rw-r--r--calendar/gui/gnome-month-item.c4
-rw-r--r--calendar/gui/goto.c39
-rw-r--r--calendar/gui/year-view.c113
5 files changed, 26 insertions, 134 deletions
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am
index dfd034e433..9e4163c932 100644
--- a/calendar/gui/Makefile.am
+++ b/calendar/gui/Makefile.am
@@ -38,6 +38,8 @@ gnomecal_SOURCES = \
goto.c \
main.c \
main.h \
+ mark.c \
+ mark.h \
month-view.c \
month-view.h \
popup-menu.c \
diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c
index 64e5ec6ef4..ecc2a0d0cb 100644
--- a/calendar/gui/gncal-full-day.c
+++ b/calendar/gui/gncal-full-day.c
@@ -1028,6 +1028,8 @@ gncal_full_day_destroy (GtkObject *object)
}
g_list_free (fullday->children);
+ fullday->children = NULL;
+
g_free (fullday->drag_info);
if (GTK_OBJECT_CLASS (parent_class)->destroy)
diff --git a/calendar/gui/gnome-month-item.c b/calendar/gui/gnome-month-item.c
index eb0c5eb469..289664e535 100644
--- a/calendar/gui/gnome-month-item.c
+++ b/calendar/gui/gnome-month-item.c
@@ -15,7 +15,7 @@
/* Number of days in a month, for normal and leap years */
-static int days_in_month[2][12] = {
+static const int days_in_month[2][12] = {
{ 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 },
{ 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }
};
@@ -23,7 +23,7 @@ static int days_in_month[2][12] = {
/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the
* Gregorian reformation.
*/
-static int sept_1752[42] = {
+static const int sept_1752[42] = {
0, 0, 1, 2, 14, 15, 16,
17, 18, 19, 20, 21, 22, 23,
24, 25, 26, 27, 28, 29, 30,
diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c
index c3ac3a157e..c312189ce7 100644
--- a/calendar/gui/goto.c
+++ b/calendar/gui/goto.c
@@ -10,38 +10,21 @@
#include "gnome-cal.h"
#include "gnome-month-item.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
+/* Updates the specified month item by marking it appropriately from the calendar the dialog refers
+ * to. */
static void
-highlight_current_day (GnomeMonthItem *mitem)
+update (GnomeMonthItem *mitem, GtkWidget *dialog)
{
- struct tm *tm;
- time_t t;
- GnomeCanvasItem *label;
- int i;
-
- t = time (NULL);
- tm = localtime (&t);
-
- /* First clear all the days to normal */
-
- for (i = 0; i < 42; i++) {
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "black",
- NULL);
- }
+ GnomeCalendar *gcal;
- /* Highlight the current day, if appropriate */
+ gcal = GNOME_CALENDAR (gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar"));
- if ((mitem->year == (tm->tm_year + 1900)) && (mitem->month == tm->tm_mon)) {
- i = gnome_month_item_day2index (mitem, tm->tm_mday);
- label = gnome_month_item_num2child (mitem, i + GNOME_MONTH_ITEM_DAY_LABEL);
- gnome_canvas_item_set (label,
- "fill_color", "blue",
- NULL);
- }
+ unmark_month_item (mitem);
+ mark_month_item (mitem, gcal->cal);
}
/* Callback used when the year adjustment is changed */
@@ -54,7 +37,7 @@ year_changed (GtkAdjustment *adj, GtkWidget *dialog)
gnome_canvas_item_set (mitem,
"year", (int) adj->value,
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the year control with its adjustment */
@@ -99,7 +82,7 @@ month_toggled (GtkToggleButton *toggle, gpointer data)
gnome_canvas_item_set (mitem,
"month", GPOINTER_TO_INT (data),
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
}
/* Creates the months control */
@@ -236,7 +219,7 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
"start_on_monday", week_starts_on_monday,
"heading_color", "white",
NULL);
- highlight_current_day (GNOME_MONTH_ITEM (mitem));
+ update (GNOME_MONTH_ITEM (mitem), dialog);
gtk_object_set_data (GTK_OBJECT (dialog), "month_item", mitem);
diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c
index bb3a38ecab..a09862f5f0 100644
--- a/calendar/gui/year-view.c
+++ b/calendar/gui/year-view.c
@@ -10,6 +10,7 @@
#include <libgnomeui/gnome-canvas-text.h>
#include "year-view.h"
#include "main.h"
+#include "mark.h"
#include "timeutil.h"
@@ -284,107 +285,7 @@ year_view_update (YearView *yv, iCalObject *object, int flags)
if (object && ((flags & CHANGE_SUMMARY) == flags))
return;
- year_view_set (yv, time_year_begin (yv->year));
-}
-
-/* Unmarks all the days in the year view by setting their boxes and labels to the default colors */
-static void
-unmark_days (YearView *yv)
-{
- GnomeCanvasItem *item;
- int i, j;
-
- for (i = 0; i < 12; i++)
- for (j = 0; j < 42; j++) {
- /* Box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_BOX + j);
- gnome_canvas_item_set (item,
- "fill_color", "#d6d6d6d6d6d6",
- NULL);
-
- /* Label */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[i]),
- GNOME_MONTH_ITEM_DAY_LABEL + j);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-}
-
-/* Marks all the days that fall into the specified time span */
-static void
-mark_event (YearView *yv, time_t start, time_t end)
-{
- time_t t;
- struct tm tm;
- int day_index;
- GnomeCanvasItem *mitem, *item;
-
- tm = *localtime (&start);
- end = time_end_of_day (end);
-
- for (t = start; t < end; t += 60 * 60 * 24) {
- mktime (&tm); /* normalize the time */
-
- /* We need this comparison because an event may span more than one year (!).
- * Yes, this is not the most efficient way of doing this (we could just clip
- * the event to the current year), but it will do for now.
- */
-
- if ((tm.tm_year + 1900) == yv->year) {
- /* Figure out the month item and day index that correspond to this time */
-
- mitem = yv->mitems[tm.tm_mon];
- day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mitem), tm.tm_mday);
- g_assert (day_index != -1);
-
- /* Mark the day box */
-
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (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 (GNOME_MONTH_ITEM (mitem),
- GNOME_MONTH_ITEM_DAY_LABEL + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
-
- /* Next day */
-
- tm.tm_mday++;
- }
-}
-
-/* Queries the calendar for all the events in the current year and marks the days that have at least
- * one event in them.
- */
-static void
-mark_days (YearView *yv)
-{
- time_t year_begin, year_end;
- GList *list, *l;
- CalendarObject *co;
-
- year_begin = time_year_begin (yv->year);
- year_end = time_year_end (yv->year);
-
- list = calendar_get_events_in_range (yv->calendar->cal, year_begin, year_end);
-
- for (l = list; l; l = l->next) {
- co = l->data;
- mark_event (yv, co->ev_start, co->ev_end);
- }
-
- calendar_destroy_event_list (list);
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
void
@@ -415,8 +316,12 @@ year_view_set (YearView *yv, time_t year)
"month", i,
NULL);
- unmark_days (yv);
- mark_days (yv);
+ /* Unmark and re-mark all the months */
+
+ for (i = 0; i < 12; i++) {
+ unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]));
+ mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal);
+ }
}
void
@@ -432,5 +337,5 @@ year_view_time_format_changed (YearView *yv)
"start_on_monday", week_starts_on_monday,
NULL);
- year_view_set (yv, time_year_begin (yv->year));
+ year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}