diff options
Diffstat (limited to 'calendar/gui')
52 files changed, 0 insertions, 14725 deletions
diff --git a/calendar/gui/Makefile.am b/calendar/gui/Makefile.am deleted file mode 100644 index 8f10c2a1c8..0000000000 --- a/calendar/gui/Makefile.am +++ /dev/null @@ -1,83 +0,0 @@ -help_base = $(datadir)/gnome/help/cal - -CFLAGS += -Wall - -INCLUDES = \ - -I$(includedir) \ - $(GNOME_INCLUDEDIR) \ - -DGNOMELOCALEDIR=\""$(datadir)/locale"\" - -bin_PROGRAMS = gnomecal - -gnomecal_SOURCES = \ - alarm.c \ - alarm.h \ - calendar.c \ - calendar.h \ - calobj.c \ - calobj.h \ - eventedit.c \ - eventedit.h \ - getdate.y \ - gncal-day-panel.c \ - gncal-day-panel.h \ - gncal-day-view.c \ - gncal-day-view.h \ - gncal-full-day.c \ - gncal-full-day.h \ - gncal-week-view.c \ - gncal-week-view.h \ - gncal-todo.c \ - gncal-todo.h \ - gnome-month-item.c \ - gnome-month-item.h \ - gnome-cal.c \ - gnome-cal.h \ - goto.c \ - layout.c \ - layout.h \ - main.c \ - main.h \ - mark.c \ - mark.h \ - month-view.c \ - month-view.h \ - popup-menu.c \ - popup-menu.h \ - prop.c \ - quick-view.c \ - quick-view.h \ - timeutil.c \ - timeutil.h \ - view-utils.h \ - view-utils.c \ - year-view.c \ - year-view.h - -LINK_FLAGS = \ - $(GNOME_LIBDIR) \ - $(GNOMEGNORBA_LIBS) \ - $(INTLLIBS) ../libversit/libversit.a - - -#gncal_LDADD = $(LINK_FLAGS) - -gnomecal_LDADD = $(LINK_FLAGS) - -EXTRA_DIST = \ - gncal.desktop \ - topic.dat \ - gnome-cal.html \ - bell.xpm \ - recur.xpm - - -Productivitydir = $(datadir)/apps/Productivity - -Productivity_DATA = gncal.desktop - -install-data-local: - $(mkinstalldirs) $(help_base)/C - $(INSTALL_DATA) $(srcdir)/topic.dat $(help_base)/C/topic.dat - $(INSTALL_DATA) $(srcdir)/gnome-cal.html $(help_base)/C/gnome-cal.html - cd $(help_base)/C; rm -f index.html ; $(LN_S) gnome-cal.html index.html diff --git a/calendar/gui/alarm-notify/alarm.c b/calendar/gui/alarm-notify/alarm.c deleted file mode 100644 index 3848fb87fd..0000000000 --- a/calendar/gui/alarm-notify/alarm.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Alarm handling for the GNOME Calendar. - * - * (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ -#include <config.h> -#include <time.h> -#include <gnome.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/time.h> -#include "calobj.h" -#include "alarm.h" - -/* The pipes used to notify about an alarm */ -int alarm_pipes [2]; - -/* The list of pending alarms */ -static GList *alarms; - -static void *head_alarm; - -typedef struct { - time_t activation_time; - AlarmFunction fn; - void *closure; - CalendarAlarm *alarm; -} AlarmRecord; - -/* - * SIGALRM handler. Notifies the callback about the alarm - */ -static void -alarm_activate () -{ - char c = 0; - - write (alarm_pipes [1], &c, 1); -} - -static void -alarm_ready (void *closure, int fd, GdkInputCondition cond) -{ - AlarmRecord *ar = head_alarm; - time_t now = time (NULL); - char c; - - if (read (alarm_pipes [0], &c, 1) != 1) - return; - - if (ar == NULL){ - g_warning ("Empty events. This should not happen\n"); - return; - } - - while (head_alarm){ - (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); - alarms = g_list_remove (alarms, head_alarm); - - /* Schedule next alarm */ - if (alarms){ - AlarmRecord *next; - - head_alarm = alarms->data; - next = head_alarm; - - if (next->activation_time > now){ - struct itimerval itimer; - - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = next->activation_time - now; - itimer.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &itimer, NULL); - break; - } else { - g_free (ar); - ar = next; - } - } else - head_alarm = NULL; - } - g_free (ar); -} - -static int -alarm_compare_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->activation_time - arb->activation_time; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/** - * alarm_add: - * - * Tries to schedule @alarm. - * - * Returns TRUE if the alarm was scheduled. - */ -gboolean -alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) -{ - time_t now = time (NULL); - AlarmRecord *ar; - time_t alarm_time = alarm->trigger; - - /* If it already expired, do not add it */ - if (alarm_time < now) - return FALSE; - - ar = g_new0 (AlarmRecord, 1); - ar->activation_time = alarm_time; - ar->fn = fn; - ar->closure = closure; - ar->alarm = alarm; - - alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); - - /* If first alarm is not the previous first alarm, reschedule SIGALRM */ - if (head_alarm != alarms->data){ - struct itimerval itimer; - int v; - - /* Set the timer to disable upon activation */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = alarm_time - now; - itimer.it_value.tv_usec = 0; - v = setitimer (ITIMER_REAL, &itimer, NULL); - head_alarm = alarms->data; - } - - return TRUE; -} - -int -alarm_kill (void *closure_key) -{ - GList *p; - - for (p = alarms; p; p = p->next){ - AlarmRecord *ar = p->data; - - if (ar->closure == closure_key){ - alarms = g_list_remove (alarms, p->data); - if (alarms) - head_alarm = alarms->data; - else - head_alarm = NULL; - return 1; - } - } - return 0; -} - -void -alarm_init (void) -{ - struct sigaction sa; - int flags; - - pipe (alarm_pipes); - - /* set non blocking mode */ - fcntl (alarm_pipes [0], F_GETFL, &flags); - fcntl (alarm_pipes [0], F_SETFL, flags | O_NONBLOCK); - gdk_input_add (alarm_pipes [0], GDK_INPUT_READ, alarm_ready, 0); - - /* Setup the signal handler */ - sa.sa_handler = alarm_activate; - sigemptyset (&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction (SIGALRM, &sa, NULL); -} - diff --git a/calendar/gui/alarm-notify/alarm.h b/calendar/gui/alarm-notify/alarm.h deleted file mode 100644 index 81710bda5e..0000000000 --- a/calendar/gui/alarm-notify/alarm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ALARM_H -#define ALARM_H - -#include <time.h> - -typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse); - -void alarm_init (void); -gboolean alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure); -int alarm_kill (void *closure); - -#endif diff --git a/calendar/gui/alarm.c b/calendar/gui/alarm.c deleted file mode 100644 index 3848fb87fd..0000000000 --- a/calendar/gui/alarm.c +++ /dev/null @@ -1,181 +0,0 @@ -/* - * Alarm handling for the GNOME Calendar. - * - * (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ -#include <config.h> -#include <time.h> -#include <gnome.h> -#include <fcntl.h> -#include <signal.h> -#include <sys/time.h> -#include "calobj.h" -#include "alarm.h" - -/* The pipes used to notify about an alarm */ -int alarm_pipes [2]; - -/* The list of pending alarms */ -static GList *alarms; - -static void *head_alarm; - -typedef struct { - time_t activation_time; - AlarmFunction fn; - void *closure; - CalendarAlarm *alarm; -} AlarmRecord; - -/* - * SIGALRM handler. Notifies the callback about the alarm - */ -static void -alarm_activate () -{ - char c = 0; - - write (alarm_pipes [1], &c, 1); -} - -static void -alarm_ready (void *closure, int fd, GdkInputCondition cond) -{ - AlarmRecord *ar = head_alarm; - time_t now = time (NULL); - char c; - - if (read (alarm_pipes [0], &c, 1) != 1) - return; - - if (ar == NULL){ - g_warning ("Empty events. This should not happen\n"); - return; - } - - while (head_alarm){ - (*ar->fn)(ar->activation_time, ar->alarm, ar->closure); - alarms = g_list_remove (alarms, head_alarm); - - /* Schedule next alarm */ - if (alarms){ - AlarmRecord *next; - - head_alarm = alarms->data; - next = head_alarm; - - if (next->activation_time > now){ - struct itimerval itimer; - - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = next->activation_time - now; - itimer.it_value.tv_usec = 0; - setitimer (ITIMER_REAL, &itimer, NULL); - break; - } else { - g_free (ar); - ar = next; - } - } else - head_alarm = NULL; - } - g_free (ar); -} - -static int -alarm_compare_by_time (gconstpointer a, gconstpointer b) -{ - const AlarmRecord *ara = a; - const AlarmRecord *arb = b; - time_t diff; - - diff = ara->activation_time - arb->activation_time; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -/** - * alarm_add: - * - * Tries to schedule @alarm. - * - * Returns TRUE if the alarm was scheduled. - */ -gboolean -alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure) -{ - time_t now = time (NULL); - AlarmRecord *ar; - time_t alarm_time = alarm->trigger; - - /* If it already expired, do not add it */ - if (alarm_time < now) - return FALSE; - - ar = g_new0 (AlarmRecord, 1); - ar->activation_time = alarm_time; - ar->fn = fn; - ar->closure = closure; - ar->alarm = alarm; - - alarms = g_list_insert_sorted (alarms, ar, alarm_compare_by_time); - - /* If first alarm is not the previous first alarm, reschedule SIGALRM */ - if (head_alarm != alarms->data){ - struct itimerval itimer; - int v; - - /* Set the timer to disable upon activation */ - itimer.it_interval.tv_sec = 0; - itimer.it_interval.tv_usec = 0; - itimer.it_value.tv_sec = alarm_time - now; - itimer.it_value.tv_usec = 0; - v = setitimer (ITIMER_REAL, &itimer, NULL); - head_alarm = alarms->data; - } - - return TRUE; -} - -int -alarm_kill (void *closure_key) -{ - GList *p; - - for (p = alarms; p; p = p->next){ - AlarmRecord *ar = p->data; - - if (ar->closure == closure_key){ - alarms = g_list_remove (alarms, p->data); - if (alarms) - head_alarm = alarms->data; - else - head_alarm = NULL; - return 1; - } - } - return 0; -} - -void -alarm_init (void) -{ - struct sigaction sa; - int flags; - - pipe (alarm_pipes); - - /* set non blocking mode */ - fcntl (alarm_pipes [0], F_GETFL, &flags); - fcntl (alarm_pipes [0], F_SETFL, flags | O_NONBLOCK); - gdk_input_add (alarm_pipes [0], GDK_INPUT_READ, alarm_ready, 0); - - /* Setup the signal handler */ - sa.sa_handler = alarm_activate; - sigemptyset (&sa.sa_mask); - sa.sa_flags = SA_RESTART; - sigaction (SIGALRM, &sa, NULL); -} - diff --git a/calendar/gui/alarm.h b/calendar/gui/alarm.h deleted file mode 100644 index 81710bda5e..0000000000 --- a/calendar/gui/alarm.h +++ /dev/null @@ -1,12 +0,0 @@ -#ifndef ALARM_H -#define ALARM_H - -#include <time.h> - -typedef void (*AlarmFunction)(time_t time, CalendarAlarm *which, void *closuse); - -void alarm_init (void); -gboolean alarm_add (CalendarAlarm *alarm, AlarmFunction fn, void *closure); -int alarm_kill (void *closure); - -#endif diff --git a/calendar/gui/bell.xpm b/calendar/gui/bell.xpm deleted file mode 100644 index b1ab537a17..0000000000 --- a/calendar/gui/bell.xpm +++ /dev/null @@ -1,83 +0,0 @@ -/* XPM */ -static char * bell_xpm[] = { -"16 16 64 1", -" c None", -". c #000000", -"+ c #E3BB43", -"@ c #E6C049", -"# c #EED275", -"$ c #F4E193", -"% c #F4DF8C", -"& c #EAC95C", -"* c #EFD57A", -"= c #FAEFBB", -"- c #FDF6D3", -"; c #FDF5C6", -"> c #F4E18F", -", c #E4BD43", -"' c #F6E295", -") c #FEF9D8", -"! c #FFFFFF", -"~ c #FFFADA", -"{ c #FCEEAA", -"] c #EBCA5A", -"^ c #E9C550", -"/ c #FAEA9C", -"( c #FEF7CB", -"_ c #FFF8CC", -": c #FDF1A8", -"< c #EED060", -"[ c #D39D12", -"} c #F2D55D", -"| c #FCEC91", -"1 c #FFF4AE", -"2 c #FFF5B6", -"3 c #FEEF97", -"4 c #F3D65E", -"5 c #D5A216", -"6 c #FAE05C", -"7 c #FFED7C", -"8 c #FFEF8C", -"9 c #FFF092", -"0 c #FDEB7A", -"a c #F4D750", -"b c #D8A717", -"c c #EAC01D", -"d c #F6D83E", -"e c #FAE255", -"f c #FAE362", -"g c #F9E161", -"h c #F6DE5B", -"i c #F1D145", -"j c #E6BE28", -"k c #D09B09", -"l c #B67E00", -"m c #CE9100", -"n c #D69F04", -"o c #E0B011", -"p c #E6BA1D", -"q c #E3B721", -"r c #E0B21E", -"s c #DCAB16", -"t c #D7A20D", -"u c #CC9303", -"v c #BE8400", -"w c #AC7500", -"x c #A06B00", -"y c #FFDD00", -" ", -" .. ", -" .+@. ", -" .#$%&. ", -" .*=-;>,. ", -" .')!~{]. ", -" .^/(~_:<[. ", -" .}|121345. ", -" .678980ab. ", -" .cdefghijkl. ", -" .mnopqrstuvwx. ", -" .............. ", -" .8y. ", -" .. ", -" ", -" "}; diff --git a/calendar/gui/cal_struct.h b/calendar/gui/cal_struct.h deleted file mode 100644 index 411036c7aa..0000000000 --- a/calendar/gui/cal_struct.h +++ /dev/null @@ -1,27 +0,0 @@ -#define MAX_SZ 30 - -enum RepeatType { - Single, - Days, - Months, - WeekDays, - MonthDays -}; - - -struct actionitem { - char date[MAX_SZ]; - int time; /* Minutes past midnight */ -}; - -struct event { - struct actionitem start; - struct actionitem end; - - enum RepeatType repeat; - int repeatcount; - char description[MAX_SZ]; - char subtype[MAX_SZ]; - GList *properties; -}; - diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c deleted file mode 100644 index b451703e8a..0000000000 --- a/calendar/gui/calendar.c +++ /dev/null @@ -1,457 +0,0 @@ -/* - * Calendar manager object - * - * This keeps track of a given calendar. Eventually this will abtract everything - * related to getting calendars/saving calendars locally or to a remote Calendar Service - * - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (quartic@gimp.org) - * - */ - -#include <config.h> -#include <unistd.h> -#include <sys/stat.h> -#include "calendar.h" -#include "alarm.h" -#include "timeutil.h" -#include "../libversit/vcc.h" - -/* Our day range */ -time_t calendar_day_begin, calendar_day_end; - -static void calendar_init_alarms (Calendar *cal); - -Calendar * -calendar_new (char *title) -{ - Calendar *cal; - - cal = g_new0 (Calendar, 1); - - cal->title = g_strdup (title); - - calendar_init_alarms (cal); - - return cal; -} - -static void -try_add (iCalObject *ico, CalendarAlarm *alarm, time_t start, time_t end) -{ - alarm->trigger = start-alarm->offset; - - if (alarm->trigger < calendar_day_begin) - return; - if (alarm->trigger > calendar_day_end) - return; - alarm_add (alarm, &calendar_notify, ico); -} - -static int -add_object_alarms (iCalObject *obj, time_t start, time_t end, void *closure) -{ - if (obj->aalarm.enabled) - try_add (obj, &obj->aalarm, start, end); - if (obj->dalarm.enabled) - try_add (obj, &obj->dalarm, start, end); - if (obj->palarm.enabled) - try_add (obj,&obj->palarm, start, end); - if (obj->malarm.enabled) - try_add (obj, &obj->malarm, start, end); - - return TRUE; -} - -#define max(a,b) ((a > b) ? a : b) - -void -ical_object_try_alarms (iCalObject *obj) -{ - int ao, po, od, mo; - int max_o; - - ao = alarm_compute_offset (&obj->aalarm); - po = alarm_compute_offset (&obj->palarm); - od = alarm_compute_offset (&obj->dalarm); - mo = alarm_compute_offset (&obj->malarm); - - max_o = max (ao, max (po, max (od, mo))); - if (max_o == -1) - return; - - ical_object_generate_events (obj, calendar_day_begin, calendar_day_end + max_o, add_object_alarms, obj); -} - -void -calendar_add_object (Calendar *cal, iCalObject *obj) -{ - obj->new = 0; - switch (obj->type){ - case ICAL_EVENT: - cal->events = g_list_prepend (cal->events, obj); - ical_object_try_alarms (obj); -#ifdef DEBUGGING_MAIL_ALARM - obj->malarm.trigger = 0; - calendar_notify (0, obj); -#endif - break; - - case ICAL_TODO: - cal->todo = g_list_prepend (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_prepend (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - if (!obj->uid){ - char buffer [80]; - - snprintf (buffer, sizeof (buffer), "GnomeCalendar-%ld\n", time (NULL)); - } - - cal->modified = TRUE; - - /* FIXME: do we have to set the last_mod field in the object? */ -} - -void -calendar_remove_object (Calendar *cal, iCalObject *obj) -{ - switch (obj->type){ - case ICAL_EVENT: - cal->events = g_list_remove (cal->events, obj); - break; - - case ICAL_TODO: - cal->todo = g_list_remove (cal->todo, obj); - break; - - case ICAL_JOURNAL: - cal->journal = g_list_remove (cal->journal, obj); - break; - default: - g_assert_not_reached (); - } - - cal->modified = TRUE; -} - -void -calendar_destroy (Calendar *cal) -{ - g_list_foreach (cal->events, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->events); - - g_list_foreach (cal->todo, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->todo); - - g_list_foreach (cal->journal, (GFunc) ical_object_destroy, NULL); - g_list_free (cal->journal); - - if (cal->title) - g_free (cal->title); - if (cal->filename) - g_free (cal->filename); - - g_free (cal); -} - -char * -ice (time_t t) -{ - static char buffer [100]; - struct tm *tm; - - tm = localtime (&t); - sprintf (buffer, "%d/%d/%d", tm->tm_mday, tm->tm_mon, tm->tm_year); - return buffer; -} - -void -calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure) -{ - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - ical_object_generate_events (object, start, end, cb, closure); - } -} - -void -calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure) -{ - calendar_iterate_on_objects (cal->events, start, end, cb, closure); -} - -GList * -calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func) -{ - GList *new_events = 0; - - for (; objects; objects = objects->next){ - iCalObject *object = objects->data; - - if ((start <= object->dtstart) && (object->dtend <= end)){ - if (sort_func) - new_events = g_list_insert_sorted (new_events, object, sort_func); - else - new_events = g_list_prepend (new_events, object); - } - } - - /* Put the list in increasing order if no sort function was specified */ - - if (!sort_func) - new_events = g_list_reverse (new_events); - - return new_events; -} - -GList * -calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->todo, start, end, sort_func); -} - -GList * -calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func) -{ - return calendar_get_objects_in_range (cal->journal, start, end, sort_func); -} - -gint -calendar_compare_by_dtstart (gpointer a, gpointer b) -{ - iCalObject *obj1, *obj2; - time_t diff; - - obj1 = a; - obj2 = b; - - diff = obj1->dtstart - obj2->dtstart; - - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -#define str_val(obj) (char *) vObjectUStringZValue (obj) - -/* Loads our calendar contents from a vObject */ -void -calendar_load_from_vobject (Calendar *cal, VObject *vcal) -{ - VObjectIterator i; - - initPropIterator (&i, vcal); - - while (moreIteration (&i)){ - VObject *this = nextVObject (&i); - iCalObject *ical; - const char *object_name = vObjectName (this); - - if (strcmp (object_name, VCDCreatedProp) == 0){ - cal->created = time_from_isodate (str_val (this)); - continue; - } - - if (strcmp (object_name, VCLocationProp) == 0) - continue; /* FIXME: imlement */ - - if (strcmp (object_name, VCProdIdProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCVersionProp) == 0) - continue; /* FIXME: implement */ - - if (strcmp (object_name, VCTimeZoneProp) == 0) - continue; /* FIXME: implement */ - - ical = ical_object_create_from_vobject (this, object_name); - - if (ical) - calendar_add_object (cal, ical); - } -} - -static void -calendar_set_day (void) -{ - time_t calendar_today; - - calendar_today = time (NULL); - calendar_day_begin = time_day_begin (calendar_today); - calendar_day_end = time_day_end (calendar_today); -} - -/* Loads a calendar from a file */ -char * -calendar_load (Calendar *cal, char *fname) -{ - VObject *vcal; - struct stat s; - - if (cal->filename){ - g_warning ("Calendar load called again\n"); - return "Internal error"; - } - - cal->filename = g_strdup (fname); - vcal = Parse_MIME_FromFileName (fname); - if (!vcal) - return "Could not load the calendar"; - - stat (fname, &s); - cal->file_time = s.st_mtime; - - calendar_set_day (); - - calendar_load_from_vobject (cal, vcal); - cleanVObject (vcal); - cleanStrTbl (); - return NULL; -} - -void -calendar_save (Calendar *cal, char *fname) -{ - VObject *vcal; - GList *l; - time_t now = time (NULL); - struct stat s; - - if (fname == NULL) - fname = cal->filename; - - /* WE call localtime for the side effect of setting tzname */ - localtime (&now); - - vcal = newVObject (VCCalProp); - addPropValue (vcal, VCProdIdProp, "-//GNOME//NONSGML GnomeCalendar//EN"); - addPropValue (vcal, VCTimeZoneProp, tzname [0]); - addPropValue (vcal, VCVersionProp, VERSION); - cal->temp = vcal; - - /* Events */ - - for (l = cal->events; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - /* To-do entries */ - - for (l = cal->todo; l; l = l->next) { - VObject *obj; - - obj = ical_object_to_vobject ((iCalObject *) l->data); - addVObjectProp (vcal, obj); - } - - if (g_file_exists (fname)){ - char *backup_name = g_strconcat (fname, "~", NULL); - - if (g_file_exists (backup_name)){ - unlink (backup_name); - } - rename (fname, backup_name); - g_free (backup_name); - } - writeVObjectToFile (fname, vcal); - - stat (fname, &s); - cal->file_time = s.st_mtime; - - cleanVObject (vcal); - cleanStrTbl (); -} - -static gint -calendar_object_compare_by_start (gconstpointer a, gconstpointer b) -{ - const CalendarObject *ca = a; - const CalendarObject *cb = b; - time_t diff; - - diff = ca->ev_start - cb->ev_start; - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -static int -assemble_event_list (iCalObject *obj, time_t start, time_t end, void *c) -{ - CalendarObject *co; - GList **l = c; - - co = g_new (CalendarObject, 1); - co->ev_start = start; - co->ev_end = end; - co->ico = obj; - *l = g_list_insert_sorted (*l, co, calendar_object_compare_by_start); - - return 1; -} - -void -calendar_destroy_event_list (GList *l) -{ - GList *p; - - for (p = l; p; p = p->next) - g_free (p->data); - g_list_free (l); -} - -GList * -calendar_get_events_in_range (Calendar *cal, time_t start, time_t end) -{ - GList *l = 0; - - calendar_iterate (cal, start, end, assemble_event_list, &l); - return l; -} - -void -calendar_object_changed (Calendar *cal, iCalObject *obj, int flags) -{ - if (!(flags & CHANGE_DATES)) - return; - - /* Remove any alarms on the alarm list for this object */ - while (alarm_kill (obj)) - ; - ical_object_try_alarms (obj); -} - -static void -calendar_day_change (time_t time, CalendarAlarm *which, void *closure) -{ - GList *events; - Calendar *cal = closure; - - calendar_set_day (); - - for (events = cal->events; events; events = events->next){ - iCalObject *obj = events->data; - - ical_object_try_alarms (obj); - } -} - -static void -calendar_init_alarms (Calendar *cal) -{ - CalendarAlarm day_change_alarm; - - day_change_alarm.trigger = calendar_day_end; - alarm_add (&day_change_alarm, calendar_day_change, cal); -} - diff --git a/calendar/gui/calendar.h b/calendar/gui/calendar.h deleted file mode 100644 index 8dc0c517c3..0000000000 --- a/calendar/gui/calendar.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef CALENDAR_H -#define CALENDAR_H - -#include "calobj.h" - -BEGIN_GNOME_DECLS - -typedef struct { - /* This calendar's title */ - char *title; - - /* backing store for this calendar object */ - char *filename; - - /* The list of events; todo's and journal entries */ - GList *events; - GList *todo; - GList *journal; - - /* Time at which the calendar was created */ - time_t created; - - /* Timestamp in the filename */ - time_t file_time; - - /* If the calendar was last modified */ - int modified; - void *temp; -} Calendar; - -/* This is only used by the calendar_get_events_in_range routine to get - * a list of objects that recur on a specific date - */ -typedef struct { - time_t ev_start; - time_t ev_end; - iCalObject *ico; -} CalendarObject; - -Calendar *calendar_new (char *title); -char *calendar_load (Calendar *cal, char *fname); -void calendar_save (Calendar *cal, char *fname); -void calendar_add_object (Calendar *cal, iCalObject *obj); -void calendar_remove_object (Calendar *cal, iCalObject *obj); -void calendar_destroy (Calendar *cal); -GList *calendar_get_objects_in_range (GList *objects, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_todo_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -GList *calendar_get_journal_in_range (Calendar *cal, time_t start, time_t end, GCompareFunc sort_func); -gint calendar_compare_by_dtstart (gpointer a, gpointer b); - -void calendar_iterate_on_objects (GList *objects, time_t start, time_t end, calendarfn cb, void *closure); -void calendar_iterate (Calendar *cal, time_t start, time_t end, calendarfn cb, void *closure); - -/* Returns a list of CalendarObject structures. These represent the events in the calendar that are - * in the specified range. - */ -GList *calendar_get_events_in_range (Calendar *cal, time_t start, time_t end); - -/* Destroy list returned by calendar_get_events_in_range() with this function */ -void calendar_destroy_event_list (GList *l); - -/* Informs the calendar that obj information has changed */ -void calendar_object_changed (Calendar *cal, iCalObject *obj, int flags); - -void calendar_notify (time_t time, CalendarAlarm *which, void *data); -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/eventedit.c b/calendar/gui/eventedit.c deleted file mode 100644 index 1d0236cb1c..0000000000 --- a/calendar/gui/eventedit.c +++ /dev/null @@ -1,1540 +0,0 @@ -/* - * EventEditor widget - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: Miguel de Icaza (miguel@kernel.org) - * Federico Mena (quartic@gimp.org) - */ -#include <config.h> -#include <gnome.h> -#include <string.h> -#include "calendar.h" -#include "eventedit.h" -#include "main.h" -#include "timeutil.h" - - -static void event_editor_class_init (EventEditorClass *class); -static void event_editor_init (EventEditor *ee); -static void event_editor_destroy (GtkObject *object); - -/* Note: do not i18n these strings, they are part of the vCalendar protocol */ -static char *class_names [] = { "PUBLIC", "PRIVATE", "CONFIDENTIAL" }; - -static GnomeDialogClass *parent_class; - -struct numbered_item { - char *text; - int num; -}; - - -guint -event_editor_get_type (void) -{ - static guint event_editor_type = 0; - - if(!event_editor_type) { - GtkTypeInfo event_editor_info = { - "EventEditor", - sizeof(EventEditor), - sizeof(EventEditorClass), - (GtkClassInitFunc) event_editor_class_init, - (GtkObjectInitFunc) event_editor_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL, - }; - event_editor_type = gtk_type_unique (gnome_dialog_get_type (), &event_editor_info); - } - return event_editor_type; -} - -static void -event_editor_class_init (EventEditorClass *class) -{ - GtkObjectClass *object_class; - - parent_class = gtk_type_class (gnome_dialog_get_type ()); - object_class = (GtkObjectClass*) class; - object_class->destroy = event_editor_destroy; -} - -GtkWidget * -adjust (GtkWidget *w, gfloat x, gfloat y, gfloat xs, gfloat ys) -{ - GtkWidget *a = gtk_alignment_new (x, y, xs, ys); - - gtk_container_add (GTK_CONTAINER (a), w); - return a; -} - -static GtkWidget * -make_spin_button (int val, int low, int high) -{ - GtkAdjustment *adj; - GtkWidget *spin; - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (val, low, high, 1, 10, 10)); - spin = gtk_spin_button_new (adj, 0.5, 0); - gtk_widget_set_usize (spin, 60, 0); - - return spin; -} - -/* - * Checks if the day range occupies all the day, and if so, check the - * box accordingly - */ -static void -ee_check_all_day (EventEditor *ee) -{ - time_t ev_start, ev_end; - - ev_start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - ev_end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (get_time_t_hour (ev_start) <= day_begin && get_time_t_hour (ev_end) >= day_end) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->general_allday), 1); - else - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->general_allday), 0); -} - -/* - * Callback: checks that the dates are start < end - */ -static void -check_dates (GnomeDateEdit *gde, EventEditor *ee) -{ - time_t start, end; - struct tm tm_start, tm_end; - - start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (start > end) { - tm_start = *localtime (&start); - tm_end = *localtime (&end); - - if (GTK_WIDGET (gde) == ee->start_time) { - tm_end.tm_year = tm_start.tm_year; - tm_end.tm_mon = tm_start.tm_mon; - tm_end.tm_mday = tm_start.tm_mday; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (&tm_end)); - } else if (GTK_WIDGET (gde) == ee->end_time) { - tm_start.tm_year = tm_end.tm_year; - tm_start.tm_mon = tm_end.tm_mon; - tm_start.tm_mday = tm_end.tm_mday; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (&tm_start)); - } - } -} - -/* - * Callback: checks that start_time < end_time and whether the - * selected hour range spans all of the day - */ -static void -check_times (GnomeDateEdit *gde, EventEditor *ee) -{ - time_t start, end; - struct tm tm_start, tm_end; - - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_flush (); - - start = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - end = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (start >= end) { - tm_start = *localtime (&start); - tm_end = *localtime (&end); - - if (GTK_WIDGET (gde) == ee->start_time) { - tm_end.tm_min = tm_start.tm_min; - tm_end.tm_sec = tm_start.tm_sec; - - tm_end.tm_hour = tm_start.tm_hour + 1; - - if (tm_end.tm_hour >= 24) { - tm_end.tm_hour = 24; /* mktime() will bump the day */ - tm_end.tm_min = 0; - tm_end.tm_sec = 0; - } - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (&tm_end)); - } else if (GTK_WIDGET (gde) == ee->end_time) { - tm_start.tm_min = tm_end.tm_min; - tm_start.tm_sec = tm_end.tm_sec; - - tm_start.tm_hour = tm_end.tm_hour - 1; - - if (tm_start.tm_hour < 0) { - tm_start.tm_hour = 0; - tm_start.tm_min = 0; - tm_start.tm_min = 0; - } - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (&tm_start)); - } - } - - /* Check whether the event spans the whole day */ - - ee_check_all_day (ee); -} - -/* - * Callback: all day event box clicked - */ -static void -set_all_day (GtkToggleButton *toggle, EventEditor *ee) -{ - struct tm *tm; - time_t start_t; - - start_t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - tm = localtime (&start_t); - tm->tm_hour = day_begin; - tm->tm_min = 0; - tm->tm_sec = 0; - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->start_time), mktime (tm)); - - if (toggle->active) - tm->tm_hour = day_end; - else - tm->tm_hour++; - - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (tm)); -} - -/* Convenience function to create a properly-configured date editor widget */ -static GtkWidget * -date_edit_new (time_t the_time, int show_time) -{ - return gnome_date_edit_new_flags (the_time, - ((show_time ? GNOME_DATE_EDIT_SHOW_TIME : 0) - | (am_pm_flag ? 0 : GNOME_DATE_EDIT_24_HR) - | (week_starts_on_monday - ? GNOME_DATE_EDIT_WEEK_STARTS_ON_MONDAY - : 0))); -} - -static GtkWidget * -event_editor_setup_time_frame (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *start_time, *end_time; - GtkTable *t; - - frame = gtk_frame_new (_("Time")); - t = GTK_TABLE (ee->general_time_table = gtk_table_new (1, 1, 0)); - gtk_container_border_width (GTK_CONTAINER (t), 4); - gtk_table_set_row_spacings (t, 4); - gtk_table_set_col_spacings (t, 4); - gtk_container_add (GTK_CONTAINER (frame), ee->general_time_table); - - /* 1. Start time */ - if (ee->ical->dtstart == 0){ - ee->ical->dtstart = time (NULL); - ee->ical->dtend = time_add_minutes (ee->ical->dtstart, 30); - } - ee->start_time = start_time = date_edit_new (ee->ical->dtstart, TRUE); - gnome_date_edit_set_popup_range ((GnomeDateEdit *) start_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (start_time), "date_changed", - GTK_SIGNAL_FUNC (check_dates), ee); - gtk_signal_connect (GTK_OBJECT (start_time), "time_changed", - GTK_SIGNAL_FUNC (check_times), ee); - gtk_table_attach (t, gtk_label_new (_("Start time:")), 1, 2, 1, 2, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_table_attach (t, start_time, 2, 3, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - /* 2. End time */ - ee->end_time = end_time = date_edit_new (ee->ical->dtend, TRUE); - gnome_date_edit_set_popup_range ((GnomeDateEdit *) end_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (end_time), "date_changed", - GTK_SIGNAL_FUNC (check_dates), ee); - gtk_signal_connect (GTK_OBJECT (end_time), "time_changed", - GTK_SIGNAL_FUNC (check_times), ee); - gtk_table_attach (t, gtk_label_new (_("End time:")), 1, 2, 2, 3, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_table_attach (t, end_time, 2, 3, 2, 3, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - /* 3. All day checkbox */ - ee->general_allday = gtk_check_button_new_with_label (_("All day event")); - gtk_signal_connect (GTK_OBJECT (ee->general_allday), "toggled", - GTK_SIGNAL_FUNC (set_all_day), ee); - gtk_table_attach (t, ee->general_allday, 3, 4, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 4, 0); - ee_check_all_day (ee); - - return frame; -} - -static GtkWidget * -timesel_new (void) -{ - GtkWidget *menu, *option_menu; - char *items [] = { N_("Minutes"), N_("Hours"), N_("Days") }; - int i; - - option_menu = gtk_option_menu_new (); - menu = gtk_menu_new (); - for (i = 0; i < 3; i++){ - GtkWidget *item; - - item = gtk_menu_item_new_with_label (_(items [i])); - gtk_menu_append (GTK_MENU (menu), item); - gtk_widget_show (item); - } - gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); - return option_menu; -} - -/* - * Set the sensitive state depending on whether the alarm enabled flag. - */ -static void -ee_alarm_setting (CalendarAlarm *alarm, int sensitive) -{ - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_count), sensitive); - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_timesel), sensitive); - - if (alarm->type == ALARM_PROGRAM || alarm->type == ALARM_MAIL){ - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_entry), sensitive); - gtk_widget_set_sensitive (GTK_WIDGET (alarm->w_label), sensitive); - } -} - -static void -alarm_toggle (GtkToggleButton *toggle, CalendarAlarm *alarm) -{ - ee_alarm_setting (alarm, toggle->active); -} - -#define FXS (GTK_FILL | GTK_EXPAND | GTK_SHRINK) -#define FS (GTK_FILL | GTK_SHRINK) - -static void -ee_create_ae (GtkTable *table, char *str, CalendarAlarm *alarm, enum AlarmType type, int y) -{ - GtkWidget *entry; - - alarm->w_enabled = gtk_check_button_new_with_label (str); - gtk_signal_connect (GTK_OBJECT (alarm->w_enabled), "toggled", - GTK_SIGNAL_FUNC (alarm_toggle), alarm); - gtk_table_attach (table, alarm->w_enabled, 0, 1, y, y+1, FS, FS, 0, 0); - - alarm->w_count = make_spin_button (alarm->count, 0, 10000); - gtk_table_attach (table, alarm->w_count, 1, 2, y, y+1, FS, FS, 0, 0); - - alarm->w_timesel = timesel_new (); - gtk_option_menu_set_history (GTK_OPTION_MENU (alarm->w_timesel), alarm->units); - gtk_table_attach (table, alarm->w_timesel, 2, 3, y, y+1, FS, FS, 0, 0); - - switch (type){ - case ALARM_MAIL: - alarm->w_label = gtk_label_new (_("Mail to:")); - gtk_misc_set_alignment (GTK_MISC (alarm->w_label), 1.0, 0.5); - gtk_table_attach (table, alarm->w_label, 3, 4, y, y+1, FS, FS, 0, 0); - alarm->w_entry = gtk_entry_new (); - gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); - gtk_entry_set_text (GTK_ENTRY (alarm->w_entry), alarm->data ? alarm->data : ""); - break; - - case ALARM_PROGRAM: - alarm->w_label = gtk_label_new (_("Run program:")); - gtk_misc_set_alignment (GTK_MISC (alarm->w_label), 1.0, 0.5); - gtk_table_attach (table, alarm->w_label, 3, 4, y, y+1, FS, FS, 0, 0); - alarm->w_entry = gnome_file_entry_new ("alarm-program", _("Select program to run at alarm time")); - entry = gnome_file_entry_gtk_entry (GNOME_FILE_ENTRY (alarm->w_entry)); - gtk_entry_set_text (GTK_ENTRY (entry), alarm->data ? alarm->data : ""); - gtk_table_attach (table, alarm->w_entry, 4, 5, y, y+1, FXS, FS, 0, 0); - break; - - default: - break; - } - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (alarm->w_enabled), alarm->enabled); - ee_alarm_setting (alarm, alarm->enabled); -} - -static GtkWidget * -ee_alarm_widgets (EventEditor *ee) -{ - GtkWidget *table, *mailto, *mailte, *l; - - l = gtk_frame_new (_("Alarms")); - - table = gtk_table_new (1, 1, 0); - gtk_container_border_width (GTK_CONTAINER (table), 4); - gtk_table_set_row_spacings (GTK_TABLE (table), 4); - gtk_table_set_col_spacings (GTK_TABLE (table), 4); - gtk_container_add (GTK_CONTAINER (l), table); - - mailto = gtk_label_new (_("Mail to:")); - mailte = gtk_entry_new (); - - ee_create_ae (GTK_TABLE (table), _("Display"), &ee->ical->dalarm, ALARM_DISPLAY, 1); - ee_create_ae (GTK_TABLE (table), _("Audio"), &ee->ical->aalarm, ALARM_AUDIO, 2); - ee_create_ae (GTK_TABLE (table), _("Program"), &ee->ical->palarm, ALARM_PROGRAM, 3); - ee_create_ae (GTK_TABLE (table), _("Mail"), &ee->ical->malarm, ALARM_MAIL, 4); - - return l; -} - -static GtkWidget * -ee_classification_widgets (EventEditor *ee) -{ - GtkWidget *rpub, *rpriv, *rconf; - GtkWidget *frame, *hbox; - - frame = gtk_frame_new (_("Classification")); - - hbox = gtk_hbox_new (TRUE, 0); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - rpub = gtk_radio_button_new_with_label (NULL, _("Public")); - rpriv = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rpub), _("Private")); - rconf = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (rpub), _("Confidential")); - - gtk_box_pack_start (GTK_BOX (hbox), rpub, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), rpriv, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (hbox), rconf, FALSE, FALSE, 0); - - if (strcmp (ee->ical->class, class_names[0]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rpub), TRUE); - else if (strcmp (ee->ical->class, class_names[1]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rpriv), TRUE); - else if (strcmp (ee->ical->class, class_names[2]) == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (rconf), TRUE); - - ee->general_radios = rpub; - - return frame; -} - -/* - * Retrieves the information from the CalendarAlarm widgets and stores them - * on the CalendarAlarm generic values - */ -void -ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type) -{ - GtkWidget *item; - GtkMenu *menu; - GList *child; - int idx; - - if (alarm->data){ - g_free (alarm->data); - alarm->data = 0; - } - - alarm->enabled = GTK_TOGGLE_BUTTON (alarm->w_enabled)->active; - - if (!alarm->enabled) - return; - - if (type == ALARM_PROGRAM) - alarm->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (gnome_file_entry_gtk_entry (alarm->w_entry)))); - if (type == ALARM_MAIL) - alarm->data = g_strdup (gtk_entry_get_text (GTK_ENTRY (alarm->w_entry))); - - /* Find out the index */ - menu = GTK_MENU (GTK_OPTION_MENU (alarm->w_timesel)->menu); - - item = gtk_menu_get_active (menu); - - for (idx = 0, child = GTK_MENU_SHELL (menu)->children; child->data != item; child = child->next) - idx++; - - alarm->units = idx; - alarm->count = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (alarm->w_count)); -} - -static void -ee_store_general_values_to_ical (EventEditor *ee) -{ - GtkRadioButton *radio = GTK_RADIO_BUTTON (ee->general_radios); - iCalObject *ical = ee->ical; - GSList *list = radio->group; - int idx; - time_t now; - - now = time (NULL); - ical->dtstart = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->start_time)); - ical->dtend = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->end_time)); - - if (ical->summary) - g_free (ical->summary); - - ical->summary = gtk_editable_get_chars (GTK_EDITABLE (ee->general_summary), 0, -1); - - ee_store_alarm (&ical->dalarm, ALARM_DISPLAY); - ee_store_alarm (&ical->aalarm, ALARM_AUDIO); - ee_store_alarm (&ical->palarm, ALARM_PROGRAM); - ee_store_alarm (&ical->malarm, ALARM_MAIL); - - for (idx = 2; list; list = list->next) { - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - idx--; /* The group is stored in reverse order of insertion */ - } - - g_free (ical->class); - ical->class = g_strdup (class_names [idx]); -} - -static int -option_menu_active_number (GtkWidget *omenu) -{ - GtkWidget *menu; - GtkWidget *item; - struct numbered_item *ni; - - menu = gtk_option_menu_get_menu (GTK_OPTION_MENU (omenu)); - item = gtk_menu_get_active (GTK_MENU (menu)); - - ni = gtk_object_get_user_data (GTK_OBJECT (item)); - - return ni->num; -} - -static int -ee_store_recur_rule_to_ical (EventEditor *ee) -{ - iCalObject *ical; - int i, j; - GSList *list; - - ical = ee->ical; - - for (i = 0, list = ee->recur_rr_group; list; i++, list = list->next) - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - - i = g_slist_length (ee->recur_rr_group) - i - 1; /* buttons are stored in reverse order of insertion */ - - /* None selected, no rule to be stored */ - if (i == 0) - return 0; - - if (!ical->recur) - ical->recur = g_new0 (Recurrence, 1); - - switch (i) { - case 1: - /* Daily */ - ical->recur->type = RECUR_DAILY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_day_period)); - break; - - case 2: - /* Weekly */ - ical->recur->type = RECUR_WEEKLY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_week_period)); - ical->recur->weekday = 0; - - for (j = 0; j < 7; j++) - if (GTK_TOGGLE_BUTTON (ee->recur_rr_week_days[j])->active) { - if (j == 6) - ical->recur->weekday |= 1 << 0; /* sunday is at bit 0 */ - else - ical->recur->weekday |= 1 << (j + 1); - } - - break; - - case 3: - /* Monthly */ - - if (GTK_WIDGET_SENSITIVE (ee->recur_rr_month_date)) { - /* by day */ - - ical->recur->type = RECUR_MONTHLY_BY_DAY; - ical->recur->u.month_day = - gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (ee->recur_rr_month_date)); - } else { - /* by position */ - - ical->recur->type = RECUR_MONTHLY_BY_POS; - - ical->recur->u.month_pos = - option_menu_active_number (ee->recur_rr_month_day); - ical->recur->u.month_day = - option_menu_active_number (ee->recur_rr_month_weekday); - ical->recur->interval = - gtk_spin_button_get_value_as_int ( - GTK_SPIN_BUTTON (ee->recur_rr_month_period)); - } - - break; - - case 4: - /* Yearly */ - ical->recur->type = RECUR_YEARLY_BY_DAY; - ical->recur->interval = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_rr_year_period)); - /* FIXME: need to specify anything else? I am assuming the code will look at the dtstart - * to figure out when to recur. - Federico - */ - break; - - default: - g_assert_not_reached (); - } - return 1; -} - -static void -ee_store_recur_end_to_ical (EventEditor *ee) -{ - iCalObject *ical; - GSList *list; - int i; - - /* Ending date of recurrence */ - - ical = ee->ical; - - for (i = 0, list = ee->recur_ed_group; list; i++, list = list->next) - if (GTK_TOGGLE_BUTTON (list->data)->active) - break; - - i = g_slist_length (ee->recur_ed_group) - i - 1; /* the list is stored in reverse order of insertion */ - - switch (i) { - case 0: - /* repeat forever */ - ical->recur->_enddate = 0; - ical->recur->enddate = 0; - ical->recur->duration = 0; - break; - - case 1: - /* end date */ - ical->recur->_enddate = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ed_end_on)); - ical->recur->enddate = ical->recur->_enddate; - ical->recur->duration = 0; - break; - - case 2: - /* end after n occurrences */ - ical->recur->duration = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (ee->recur_ed_end_after)); - ical_object_compute_end (ical); - break; - - default: - g_assert_not_reached (); - break; - } -} - -static void -free_exdate (iCalObject *ical) -{ - GList *list; - - if (!ical->exdate) - return; - - for (list = ical->exdate; list; list = list->next) - g_free (list->data); - - g_list_free (ical->exdate); - ical->exdate = NULL; -} - -static void -ee_store_recur_exceptions_to_ical (EventEditor *ee) -{ - iCalObject *ical; - GtkCList *clist; - int i; - time_t *t; - - ical = ee->ical; - clist = GTK_CLIST (ee->recur_ex_clist); - - free_exdate (ical); - - for (i = 0; i < clist->rows; i++) { - t = gtk_clist_get_row_data (clist, i); - ical->exdate = g_list_prepend (ical->exdate, t); - } -} - -static void -ee_store_recur_values_to_ical (EventEditor *ee) -{ - if (ee_store_recur_rule_to_ical (ee)){ - ee_store_recur_exceptions_to_ical (ee); - ee_store_recur_end_to_ical (ee); - } else if (ee->ical->recur) { - g_free (ee->ical->recur); - ee->ical->recur = NULL; - if (ee->ical->exdate){ - GList *l = ee->ical->exdate; - - for (; l; l = l->next) - g_free (l->data); - g_list_free (l); - } - } -} - -/* - * Retrieves all of the information from the different widgets and updates - * the iCalObject accordingly. - */ -static void -ee_store_dlg_values_to_ical (EventEditor *ee) -{ - time_t now; - - ee_store_general_values_to_ical (ee); - ee_store_recur_values_to_ical (ee); - - now = time (NULL); - - /* FIXME: This is not entirely correct; we should check if the values actually changed */ - ee->ical->last_mod = now; - - if (ee->ical->new) - ee->ical->created = now; -} - -static void -ee_ok (GtkWidget *widget, EventEditor *ee) -{ - ee_store_dlg_values_to_ical (ee); - - if (ee->ical->new) - gnome_calendar_add_object (ee->gnome_cal, ee->ical); - else - gnome_calendar_object_changed (ee->gnome_cal, ee->ical, CHANGE_ALL); - - ee->ical->new = 0; -} - -static void -ee_cancel (GtkWidget *widget, EventEditor *ee) -{ - if (ee->ical->new) { - ical_object_destroy (ee->ical); - ee->ical = NULL; - } - -} - -static void -ee_create_buttons (EventEditor *ee) -{ - gnome_dialog_append_buttons(GNOME_DIALOG(ee), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, NULL); - - gnome_dialog_button_connect (GNOME_DIALOG (ee), 0, GTK_SIGNAL_FUNC(ee_ok), ee); - gnome_dialog_button_connect (GNOME_DIALOG (ee), 1, GTK_SIGNAL_FUNC(ee_cancel), ee); - - return; -} - -/* - * Load the contents in a delayed fashion, as the GtkText widget needs it - */ -static void -ee_fill_summary (GtkWidget *widget, EventEditor *ee) -{ - int pos = 0; - - gtk_editable_insert_text (GTK_EDITABLE (ee->general_summary), ee->ical->summary, - strlen (ee->ical->summary), &pos); - gtk_text_thaw (GTK_TEXT (ee->general_summary)); -} - -enum { - OWNER_LINE, - DESC_LINE, - SUMMARY_LINE, - TIME_LINE, - ALARM_LINE, - CLASS_LINE -}; - -/* Create/setup the general page */ -static void -ee_init_general_page (EventEditor *ee) -{ - GtkWidget *l; - GtkWidget *hbox; - - ee->general_table = gtk_table_new (1, 1, FALSE); - gtk_container_border_width (GTK_CONTAINER (ee->general_table), 4); - gtk_table_set_row_spacings (GTK_TABLE (ee->general_table), 4); - gtk_table_set_col_spacings (GTK_TABLE (ee->general_table), 4); - gtk_notebook_append_page (GTK_NOTEBOOK (ee->notebook), GTK_WIDGET (ee->general_table), - gtk_label_new (_("General"))); - - hbox = gtk_hbox_new (FALSE, 0); - gtk_table_attach (GTK_TABLE (ee->general_table), hbox, - 0, 1, OWNER_LINE, OWNER_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 4); - - l = gtk_label_new (_("Owner:")); - gtk_box_pack_start (GTK_BOX (hbox), l, FALSE, FALSE, 0); - - ee->general_owner = gtk_label_new (ee->ical->organizer ? ee->ical->organizer : _("?")); - gtk_misc_set_alignment (GTK_MISC (ee->general_owner), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (hbox), ee->general_owner, TRUE, TRUE, 4); - - l = gtk_label_new (_("Summary:")); - gtk_misc_set_alignment (GTK_MISC (l), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, DESC_LINE, DESC_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - ee->general_summary = gtk_text_new (NULL, NULL); - gtk_text_freeze (GTK_TEXT (ee->general_summary)); - gtk_signal_connect (GTK_OBJECT (ee->general_summary), "realize", - GTK_SIGNAL_FUNC (ee_fill_summary), ee); - gtk_widget_set_usize (ee->general_summary, 0, 60); - gtk_text_set_editable (GTK_TEXT (ee->general_summary), 1); - gtk_table_attach (GTK_TABLE (ee->general_table), ee->general_summary, - 0, 1, SUMMARY_LINE, SUMMARY_LINE+1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = ee_alarm_widgets (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, ALARM_LINE, ALARM_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = event_editor_setup_time_frame (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, TIME_LINE, TIME_LINE + 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - - l = ee_classification_widgets (ee); - gtk_table_attach (GTK_TABLE (ee->general_table), l, - 0, 1, CLASS_LINE, CLASS_LINE + 1, - GTK_EXPAND | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); -} - -static void -ee_init_summary_page (EventEditor *ee) -{ -} - -struct { - char *name; -} recurrence_types [] = { - { N_("None") }, - { N_("Daily") }, - { N_("Weekly") }, - { N_("Monthly") }, - { N_("Yearly") }, - { 0 } -}; - -static void -recurrence_toggled (GtkRadioButton *radio, EventEditor *ee) -{ - GSList *list = ee->recur_rr_group; - int which; - - if (!GTK_TOGGLE_BUTTON (radio)->active) - return; - - for (which = 0; list; list = list->next, which++) { - if (list->data == radio) { - gtk_notebook_set_page (GTK_NOTEBOOK (ee->recur_rr_notebook), 4 - which); - return; - } - } -} - -static struct numbered_item weekday_positions[] = { - { N_("1st"), 1 }, - { N_("2nd"), 2 }, - { N_("3rd"), 3 }, - { N_("4th"), 4 }, - { N_("5th"), 5 }, - { 0 } -}; - -static struct numbered_item weekday_names[] = { - { N_("Monday"), 1 }, - { N_("Tuesday"), 2 }, - { N_("Wednesday"), 3 }, - { N_("Thursday"), 4 }, - { N_("Friday"), 5 }, - { N_("Saturday"), 6 }, - { N_("Sunday"), 0 }, /* on the spec, Sunday is zero */ - { 0 } -}; - -static GtkWidget * -make_numbered_menu (struct numbered_item *items, int sel) -{ - GtkWidget *option_menu, *menu; - int i; - - option_menu = gtk_option_menu_new (); - menu = gtk_menu_new (); - - for (i = 0; items[i].text; i++) { - GtkWidget *item; - - item = gtk_menu_item_new_with_label (_(items[i].text)); - gtk_object_set_user_data (GTK_OBJECT (item), &items[i]); - gtk_menu_append (GTK_MENU (menu), item); - gtk_widget_show (item); - } - - gtk_option_menu_set_menu (GTK_OPTION_MENU (option_menu), menu); - gtk_option_menu_set_history (GTK_OPTION_MENU (option_menu), sel); - - return option_menu; -} - -static void -month_sensitize (EventEditor *ee, int state) -{ - gtk_widget_set_sensitive (ee->recur_rr_month_date, state); - gtk_widget_set_sensitive (ee->recur_rr_month_date_label, state); - - gtk_widget_set_sensitive (ee->recur_rr_month_day, !state); - gtk_widget_set_sensitive (ee->recur_rr_month_weekday, !state); -} - -static void -recur_month_enable_date (GtkToggleButton *button, EventEditor *ee) -{ - month_sensitize (ee, button->active); -} - -static void -desensitize_on_toggle (GtkToggleButton *toggle, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), !toggle->active); -} - -static void -ee_rp_init_rule (EventEditor *ee) -{ - static char *day_names [] = { N_("Mon"), N_("Tue"), N_("Wed"), N_("Thu"), N_("Fri"), N_("Sat"), N_("Sun") }; - GtkWidget *r, *re, *r1, *f, *vbox, *hbox, *b, *week_hbox, *week_day, *w; - GtkWidget *none, *daily, *weekly, *monthly, *yearly; - GtkNotebook *notebook; - GSList *group; - int i, page, day_period, week_period, month_period, year_period; - int week_vector, default_day, def_pos, def_off; - struct tm *tm; - - tm = localtime (&ee->ical->dtstart); - - f = gtk_frame_new (_("Recurrence rule")); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (f), hbox); - - vbox = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); - - gtk_box_pack_start (GTK_BOX (hbox), gtk_vseparator_new (), FALSE, FALSE, 0); - - ee->recur_rr_notebook = gtk_notebook_new (); - notebook = GTK_NOTEBOOK (ee->recur_rr_notebook); - gtk_box_pack_start (GTK_BOX (hbox), ee->recur_rr_notebook, TRUE, TRUE, 0); - - day_period = 1; - week_period = 1; - month_period = 1; - year_period = 1; - - /* Default to today */ - - week_vector = 1 << tm->tm_wday; - default_day = tm->tm_mday; - def_pos = 0; - def_off = 0; - - /* Determine which should be the default selection */ - - page = 0; - if (ee->ical->recur) { - enum RecurType type = ee->ical->recur->type; - int interval = ee->ical->recur->interval; - - switch (type) { - case RECUR_DAILY: - page = 1; - day_period = interval; - break; - - case RECUR_WEEKLY: - page = 2; - week_period = interval; - week_vector = ee->ical->recur->weekday; - break; - - case RECUR_MONTHLY_BY_POS: - page = 3; - month_period = interval; - def_pos = ee->ical->recur->u.month_pos; - default_day = ee->ical->recur->u.month_day; - break; - - case RECUR_MONTHLY_BY_DAY: - page = 3; - month_period = interval; - default_day = ee->ical->recur->u.month_day; - break; - - case RECUR_YEARLY_BY_MONTH: - page = 4; - year_period = interval; - break; - - case RECUR_YEARLY_BY_DAY: - page = 4; - year_period = interval; - break; - } - } else - page = 0; - - /* The recurrency selector */ - - for (i = 0, group = NULL; recurrence_types [i].name; i++) { - r = gtk_radio_button_new_with_label (group, _(recurrence_types [i].name)); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (r)); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (r), i == page); - gtk_signal_connect (GTK_OBJECT (r), "toggled", GTK_SIGNAL_FUNC (recurrence_toggled), ee); - gtk_box_pack_start (GTK_BOX (vbox), r, FALSE, FALSE, 0); - - if (i == 0) - gtk_signal_connect (GTK_OBJECT (r), "toggled", - (GtkSignalFunc) desensitize_on_toggle, - ee->recur_hbox); - } - - ee->recur_rr_group = group; - - /* 0. No recurrence */ - none = gtk_label_new (""); - - /* 1. The daily recurrence */ - - daily = gtk_vbox_new (FALSE, 0); - - b = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (daily), b, FALSE, FALSE, 0); - - ee->recur_rr_day_period = make_spin_button (day_period, 1, 10000); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("Every")), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), ee->recur_rr_day_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("day(s)")), FALSE, FALSE, 0); - - /* 2. The weekly recurrence */ - - weekly = gtk_vbox_new (FALSE, 4); - - week_hbox = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (weekly), week_hbox, FALSE, FALSE, 0); - - /* 2.1 The week period selector */ - - ee->recur_rr_week_period = make_spin_button (week_period, 1, 10000); - gtk_box_pack_start (GTK_BOX (week_hbox), gtk_label_new (_("Every")), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (week_hbox), ee->recur_rr_week_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (week_hbox), gtk_label_new (_("week(s)")), FALSE, FALSE, 0); - - /* 2.2 The week day selector */ - - week_day = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (weekly), week_day, FALSE, FALSE, 0); - - for (i = 0; i < 7; i++) { - ee->recur_rr_week_days [i] = gtk_check_button_new_with_label (_(day_names [i])); - gtk_box_pack_start (GTK_BOX (week_day), ee->recur_rr_week_days [i], FALSE, FALSE, 0); - - if (week_vector & (1 << ((i + 1) % 7))) /* on the spec, Sunday is 0 */ - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (ee->recur_rr_week_days [i]), TRUE); - } - - /* 3. The monthly recurrence */ - - monthly = gtk_table_new (0, 0, FALSE); - gtk_table_set_row_spacings (GTK_TABLE (monthly), 4); - gtk_table_set_col_spacings (GTK_TABLE (monthly), 4); - - re = gtk_radio_button_new_with_label (NULL, _("Recur on the")); - ee->recur_rr_month_date = make_spin_button (default_day, 1, 31); - ee->recur_rr_month_date_label = w = gtk_label_new (_("th day of the month")); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (monthly), re, - 0, 1, 0, 1, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_date, - 1, 2, 0, 1, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), w, - 2, 3, 0, 1, FS, FS, 0, 0); - gtk_signal_connect (GTK_OBJECT (re), "toggled", GTK_SIGNAL_FUNC (recur_month_enable_date), ee); - - r1 = gtk_radio_button_new_with_label (gtk_radio_button_group (GTK_RADIO_BUTTON (re)), _("Recur on the")); - ee->recur_rr_month_day = make_numbered_menu (weekday_positions, def_pos); - ee->recur_rr_month_weekday = make_numbered_menu (weekday_names, default_day); - gtk_table_attach (GTK_TABLE (monthly), r1, - 0, 1, 1, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_day, - 1, 2, 1, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_weekday, - 2, 3, 1, 2, FS, FS, 0, 0); - - gtk_table_attach (GTK_TABLE (monthly), gtk_label_new (_("Every")), - 3, 4, 0, 2, FS, FS, 0, 0); - ee->recur_rr_month_period = make_spin_button (month_period, 1, 10000); - gtk_table_attach (GTK_TABLE (monthly), ee->recur_rr_month_period, - 4, 5, 0, 2, FS, FS, 0, 0); - gtk_table_attach (GTK_TABLE (monthly), gtk_label_new (_("month(s)")), - 5, 6, 0, 2, FS, FS, 0, 0); - - if (ee->ical->recur) { - if (ee->ical->recur->type == RECUR_MONTHLY_BY_POS) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (r1), 1); - } else - recur_month_enable_date (GTK_TOGGLE_BUTTON (re), ee); - - /* 4. The yearly recurrence */ - - yearly = gtk_vbox_new (FALSE, 0); - - b = gtk_hbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (yearly), b, FALSE, FALSE, 0); - - ee->recur_rr_year_period = make_spin_button (year_period, 1, 10000); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("Every")), FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), ee->recur_rr_year_period, FALSE, FALSE, 0); - gtk_box_pack_start (GTK_BOX (b), gtk_label_new (_("year(s)")), FALSE, FALSE, 0); - - /* Finish setting this up */ - - gtk_notebook_append_page (notebook, none, gtk_label_new ("")); - gtk_notebook_append_page (notebook, daily, gtk_label_new ("")); - gtk_notebook_append_page (notebook, weekly, gtk_label_new ("")); - gtk_notebook_append_page (notebook, monthly, gtk_label_new ("")); - gtk_notebook_append_page (notebook, yearly, gtk_label_new ("")); - gtk_notebook_set_show_tabs (notebook, FALSE); - gtk_notebook_set_show_border (notebook, FALSE); - - gtk_notebook_set_page (notebook, page); - - /* Attach to the main box */ - - gtk_box_pack_start (GTK_BOX (ee->recur_vbox), f, FALSE, FALSE, 0); -} - -static void -sensitize_on_toggle (GtkToggleButton *toggle, gpointer data) -{ - gtk_widget_set_sensitive (GTK_WIDGET (data), toggle->active); -} - -static void -ee_rp_init_ending_date (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *vbox; - GSList *group; - GtkWidget *radio0, *radio1, *radio2; - GtkWidget *hbox; - GtkWidget *ihbox; - GtkWidget *widget; - time_t enddate; - int repeat; - - frame = gtk_frame_new (_("Ending date")); - - vbox = gtk_vbox_new (TRUE, 4); - gtk_container_border_width (GTK_CONTAINER (vbox), 4); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - group = NULL; - - /* repeat forever */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio0 = gtk_radio_button_new_with_label (group, _("Repeat forever")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio0)); - gtk_box_pack_start (GTK_BOX (hbox), radio0, FALSE, FALSE, 0); - - /* end on date */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio1 = gtk_radio_button_new_with_label (group, _("End on")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio1)); - gtk_box_pack_start (GTK_BOX (hbox), radio1, FALSE, FALSE, 0); - - ihbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ihbox, FALSE); - gtk_box_pack_start (GTK_BOX (hbox), ihbox, FALSE, FALSE, 0); - - if (ee->ical->recur) - enddate = ee->ical->recur->enddate; - else - enddate = ee->ical->dtend; - - ee->recur_ed_end_on = widget = date_edit_new (enddate, FALSE); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - gtk_signal_connect (GTK_OBJECT (radio1), "toggled", - (GtkSignalFunc) sensitize_on_toggle, - ihbox); - - /* end after n occurrences */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - - radio2 = gtk_radio_button_new_with_label (group, _("End after")); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (radio2)); - gtk_box_pack_start (GTK_BOX (hbox), radio2, FALSE, FALSE, 0); - - ihbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ihbox, FALSE); - gtk_box_pack_start (GTK_BOX (hbox), ihbox, FALSE, FALSE, 0); - - if (ee->ical->recur && ee->ical->recur->duration) - repeat = ee->ical->recur->duration; - else - repeat = 2; - - ee->recur_ed_end_after = widget = make_spin_button (repeat, 1, 10000); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - widget = gtk_label_new (_("occurrence(s)")); - gtk_box_pack_start (GTK_BOX (ihbox), widget, FALSE, FALSE, 0); - - gtk_signal_connect (GTK_OBJECT (radio2), "toggled", - (GtkSignalFunc) sensitize_on_toggle, - ihbox); - - /* Activate appropriate item */ - - if (ee->ical->recur) { - if (ee->ical->recur->_enddate == 0) { - if (ee->ical->recur->duration == 0) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio0), TRUE); - else { - gtk_spin_button_set_value (GTK_SPIN_BUTTON (ee->recur_ed_end_after), - ee->ical->recur->duration); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio2), TRUE); - } - } else { - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->recur_ed_end_on), ee->ical->recur->enddate); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (radio1), TRUE); - } - } - - /* Done, add to main table */ - - ee->recur_ed_group = group; - - gtk_box_pack_start (GTK_BOX (ee->recur_hbox), frame, FALSE, FALSE, 0); -} - -static char * -get_exception_string (time_t t) -{ - static char buf[256]; - - strftime (buf, sizeof(buf), "%a %b %d %Y", localtime (&t)); /* FIXME: how to i18n this? */ - return buf; -} - -static void -append_exception (EventEditor *ee, time_t t) -{ - time_t *tt; - char *c[1]; - int i; - - c[0] = get_exception_string (t); - - tt = g_new (time_t, 1); - *tt = t; - - i = gtk_clist_append (GTK_CLIST (ee->recur_ex_clist), c); - gtk_clist_set_row_data (GTK_CLIST (ee->recur_ex_clist), i, tt); - gtk_clist_select_row (GTK_CLIST (ee->recur_ex_clist), i, 0); - - gtk_widget_set_sensitive (ee->recur_ex_vbox, TRUE); -} - -static void -fill_exception_clist (EventEditor *ee) -{ - GList *list; - - for (list = ee->ical->exdate; list; list = list->next) - append_exception (ee, *((time_t *) list->data)); -} - -static void -add_exception (GtkWidget *widget, EventEditor *ee) -{ - time_t t; - - t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ex_date)); - append_exception (ee, t); -} - -static void -change_exception (GtkWidget *widget, EventEditor *ee) -{ - GtkCList *clist; - time_t *t; - int sel; - - clist = GTK_CLIST (ee->recur_ex_clist); - sel = GPOINTER_TO_INT(clist->selection->data); - - t = gtk_clist_get_row_data (clist, sel); - *t = gnome_date_edit_get_date (GNOME_DATE_EDIT (ee->recur_ex_date)); - - gtk_clist_set_text (clist, sel, 0, get_exception_string (*t)); -} - -static void -delete_exception (GtkWidget *widget, EventEditor *ee) -{ - GtkCList *clist; - int sel, length; - - clist = GTK_CLIST (ee->recur_ex_clist); - sel = GPOINTER_TO_INT(clist->selection->data); - - g_free (gtk_clist_get_row_data (clist, sel)); /* free the time_t stored there */ - - gtk_clist_remove (clist, sel); - length = g_list_length(clist->row_list); - if (sel >= length) - sel--; - gtk_clist_select_row (GTK_CLIST (ee->recur_ex_clist), sel, 0); - - if (clist->rows == 0) - gtk_widget_set_sensitive (ee->recur_ex_vbox, FALSE); -} - -static void -ee_rp_init_exceptions (EventEditor *ee) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *vbox; - GtkWidget *ivbox; - GtkWidget *widget; - GtkWidget *sw; - - frame = gtk_frame_new (_("Exceptions")); - - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - vbox = gtk_vbox_new (FALSE, 4); - gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0); - - ee->recur_ex_date = widget = date_edit_new (time (NULL), FALSE); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Add exception")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) add_exception, - ee); - gtk_box_pack_start (GTK_BOX (vbox), widget, FALSE, FALSE, 0); - - ee->recur_ex_vbox = ivbox = gtk_vbox_new (FALSE, 4); - gtk_widget_set_sensitive (ivbox, FALSE); /* at first there are no items to change or delete */ - gtk_box_pack_start (GTK_BOX (vbox), ivbox, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Change selected")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) change_exception, - ee); - gtk_box_pack_start (GTK_BOX (ivbox), widget, FALSE, FALSE, 0); - - widget = gtk_button_new_with_label (_("Delete selected")); - gtk_signal_connect (GTK_OBJECT (widget), "clicked", - (GtkSignalFunc) delete_exception, - ee); - gtk_box_pack_start (GTK_BOX (ivbox), widget, FALSE, FALSE, 0); - - ee->recur_ex_clist = widget = gtk_clist_new (1); - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_container_add (GTK_CONTAINER (sw), widget); - gtk_clist_set_selection_mode (GTK_CLIST (widget), GTK_SELECTION_BROWSE); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), - GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - fill_exception_clist (ee); - gtk_box_pack_start (GTK_BOX (hbox), sw, TRUE, TRUE, 0); - - /* Done, add to main table */ - - gtk_box_pack_start (GTK_BOX (ee->recur_hbox), frame, TRUE, TRUE, 0); -} - -static void -ee_init_recurrence_page (EventEditor *ee) -{ - ee->recur_vbox = gtk_vbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (ee->recur_vbox), 4); - - ee->recur_hbox = gtk_hbox_new (FALSE, 4); - gtk_widget_set_sensitive (ee->recur_hbox, FALSE); - - ee->recur_page_label = gtk_label_new (_("Recurrence")); - - gtk_notebook_append_page (GTK_NOTEBOOK (ee->notebook), ee->recur_vbox, - ee->recur_page_label); - - ee_rp_init_rule (ee); - - /* pack here so that the box gets inserted after the recurrence rule frame */ - gtk_box_pack_start (GTK_BOX (ee->recur_vbox), ee->recur_hbox, FALSE, FALSE, 0); - - ee_rp_init_ending_date (ee); - ee_rp_init_exceptions (ee); -} - -static void -event_editor_init_widgets (EventEditor *ee) -{ - ee->notebook = gtk_notebook_new (); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG(ee)->vbox), ee->notebook, 1, 1, 0); - - /* Init the various configuration pages */ - ee_init_general_page (ee); - ee_init_summary_page (ee); - ee_init_recurrence_page (ee); - - /* Buttons */ - ee_create_buttons(ee); - - /* We show all of the contained widgets */ - gtk_widget_show_all (GTK_BIN (ee)->child); -} - -static void -event_editor_init (EventEditor *ee) -{ - ee->ical = 0; - gtk_window_set_title (GTK_WINDOW (ee), _("Create new appointment")); - gnome_dialog_set_close (GNOME_DIALOG(ee), TRUE); -} - -static void -event_editor_destroy (GtkObject *object) -{ - EventEditor *ee; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_EVENT_EDITOR (object)); - - ee = EVENT_EDITOR (object); - - if (ee->ical) - ee->ical->user_data = NULL; /* we are no longer editing it */ -} - -GtkWidget * -event_editor_new (GnomeCalendar *gcal, iCalObject *ical) -{ - GtkWidget *retval; - EventEditor *ee; - - gdk_pointer_ungrab (GDK_CURRENT_TIME); - gdk_flush (); - - retval = gtk_type_new (event_editor_get_type ()); - ee = EVENT_EDITOR (retval); - - if (ical == 0){ - ical = ical_new ("", user_name, ""); - ical->new = 1; - } - - ical->user_data = ee; /* so that the world can know we are editing it */ - - ee->ical = ical; - ee->gnome_cal = gcal; - event_editor_init_widgets (ee); - - return retval; -} - -void -event_editor_new_whole_day (GnomeCalendar *owner, time_t day) -{ - struct tm tm; - iCalObject *ico; - GtkWidget *ee; - - g_return_if_fail (owner != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (owner)); - - ico = ical_new ("", user_name, ""); - ico->new = TRUE; - - tm = *localtime (&day); - - /* Set the start time of the event to the beginning of the day */ - - tm.tm_hour = day_begin; - tm.tm_min = 0; - tm.tm_sec = 0; - ico->dtstart = mktime (&tm); - - /* Set the end time of the event to the end of the day */ - - tm.tm_hour = day_end; - ico->dtend = mktime (&tm); - - /* Launch the event editor */ - - ee = event_editor_new (owner, ico); - gtk_widget_show (ee); -} diff --git a/calendar/gui/eventedit.h b/calendar/gui/eventedit.h deleted file mode 100644 index 15ef540333..0000000000 --- a/calendar/gui/eventedit.h +++ /dev/null @@ -1,83 +0,0 @@ -/* - * EventEditor widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ - -#ifndef EVENT_EDITOR_H -#define EVENT_EDITOR_H - -#include "gnome-cal.h" -#include <libgnomeui/gnome-dialog.h> - -BEGIN_GNOME_DECLS - - -#define EVENT_EDITOR(obj) GTK_CHECK_CAST(obj, event_editor_get_type(), EventEditor) -#define EVENT_EDITOR_CLASS(class) GTK_CHECK_CAST_CLASS(class, event_editor_get_type(), EventEditorClass) -#define IS_EVENT_EDITOR(obj) GTK_CHECK_TYPE(obj, event_editor_get_type()) - - -typedef struct { - GnomeDialog dialog; - GtkWidget *notebook; - - GtkWidget *general; - GtkWidget *general_table; - GtkWidget *general_time_table; - GtkWidget *general_allday; - GtkWidget *general_owner; - GtkWidget *general_summary; - GtkWidget *start_time, *end_time; - GtkWidget *general_radios; - - GtkWidget *recur_page_label; - GtkWidget *recur_vbox; - GtkWidget *recur_hbox; - - GSList *recur_rr_group; - GtkWidget *recur_rr_notebook; - GtkWidget *recur_rr_day_period; - GtkWidget *recur_rr_week_period; - GtkWidget *recur_rr_week_days [7]; - GtkWidget *recur_rr_month_date; - GtkWidget *recur_rr_month_date_label; - GtkWidget *recur_rr_month_day; - GtkWidget *recur_rr_month_weekday; - GtkWidget *recur_rr_month_period; - GtkWidget *recur_rr_year_period; - - GSList *recur_ed_group; - GtkWidget *recur_ed_end_on; - GtkWidget *recur_ed_end_after; - - GtkWidget *recur_ex_date; - GtkWidget *recur_ex_vbox; - GtkWidget *recur_ex_clist; - - /* The associated ical object */ - iCalObject *ical; - - /* The calendar owner of this event */ - GnomeCalendar *gnome_cal; -} EventEditor; - -typedef struct { - GnomeDialogClass parent_class; -} EventEditorClass; - - -guint event_editor_get_type (void); -GtkWidget *event_editor_new (GnomeCalendar *owner, iCalObject *); - -/* Convenience function to create and show a new event editor for an event that goes from day_begin - * to day_end of the specified day. - */ -void event_editor_new_whole_day (GnomeCalendar *owner, time_t day); - - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/getdate.y b/calendar/gui/getdate.y deleted file mode 100644 index 6df71bddda..0000000000 --- a/calendar/gui/getdate.y +++ /dev/null @@ -1,1001 +0,0 @@ -%{ -/* -** Originally) written by Steven M. Bellovin <smb@research.att.com> while -** at the University of North Carolina at Chapel Hill. Later tweaked by -** a couple of people on Usenet. Completely overhauled by Rich $alz -** <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990; -** send any email to Rich. -** -** This grammar has 10 shift/reduce conflicts. -** -** This code is in the public domain and has no copyright. -*/ -/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */ -/* SUPPRESS 288 on yyerrlab *//* Label unused */ - -#include <config.h> -#include <gnome.h> - -/* Since the code of getdate.y is not included in the Emacs executable - itself, there is no need to #define static in this file. Even if - the code were included in the Emacs executable, it probably - wouldn't do any harm to #undef it here; this will only cause - problems if we try to write to a static variable, which I don't - think this code needs to do. */ -#ifdef emacs -#undef static -#endif - -#include <stdio.h> -#include <ctype.h> - -/* The code at the top of get_date which figures out the offset of the - current time zone checks various CPP symbols to see if special - tricks are need, but defaults to using the gettimeofday system call. - Include <sys/time.h> if that will be used. */ - -#if defined(vms) - -#include <types.h> -#include <time.h> - -#else - -#include <sys/types.h> - -#ifdef TIME_WITH_SYS_TIME -#include <sys/time.h> -#include <time.h> -#else -#ifdef HAVE_SYS_TIME_H -#include <sys/time.h> -#else -#include <time.h> -#endif -#endif - -#ifdef timezone -#undef timezone /* needed for sgi */ -#endif - -#if defined(HAVE_SYS_TIMEB_H) -#include <sys/timeb.h> -#else -/* -** We use the obsolete `struct timeb' as part of our interface! -** Since the system doesn't have it, we define it here; -** our callers must do likewise. -*/ -struct timeb { - time_t time; /* Seconds since the epoch */ - unsigned short millitm; /* Field not used */ - short timezone; /* Minutes west of GMT */ - short dstflag; /* Field not used */ -}; -#endif /* defined(HAVE_SYS_TIMEB_H) */ - -#endif /* defined(vms) */ - -#if defined (STDC_HEADERS) || defined (USG) -#include <string.h> -#endif - -/* Some old versions of bison generate parsers that use bcopy. - That loses on systems that don't provide the function, so we have - to redefine it here. */ -#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy) -#define bcopy(from, to, len) memcpy ((to), (from), (len)) -#endif - -#if defined (STDC_HEADERS) -#include <stdlib.h> -#endif - -/* NOTES on rebuilding getdate.c (particularly for inclusion in CVS - releases): - - We don't want to mess with all the portability hassles of alloca. - In particular, most (all?) versions of bison will use alloca in - their parser. If bison works on your system (e.g. it should work - with gcc), then go ahead and use it, but the more general solution - is to use byacc instead of bison, which should generate a portable - parser. I played with adding "#define alloca dont_use_alloca", to - give an error if the parser generator uses alloca (and thus detect - unportable getdate.c's), but that seems to cause as many problems - as it solves. */ - -extern struct tm *gmtime(); -extern struct tm *localtime(); - -#define yyparse getdate_yyparse -#define yylex getdate_yylex -#define yyerror getdate_yyerror - -static int yylex (); -static int yyerror (); - -#define EPOCH 1970 -#define HOUR(x) ((time_t)(x) * 60) -#define SECSPERDAY (24L * 60L * 60L) - - -/* -** An entry in the lexical lookup table. -*/ -typedef struct _TABLE { - char *name; - int type; - time_t value; -} TABLE; - - -/* -** Daylight-savings mode: on, off, or not yet known. -*/ -typedef enum _DSTMODE { - DSTon, DSToff, DSTmaybe -} DSTMODE; - -/* -** Meridian: am, pm, or 24-hour style. -*/ -typedef enum _MERIDIAN { - MERam, MERpm, MER24 -} MERIDIAN; - - -/* -** Global variables. We could get rid of most of these by using a good -** union as the yacc stack. (This routine was originally written before -** yacc had the %union construct.) Maybe someday; right now we only use -** the %union very rarely. -*/ -static char *yyInput; -static DSTMODE yyDSTmode; -static time_t yyDayOrdinal; -static time_t yyDayNumber; -static int yyHaveDate; -static int yyHaveDay; -static int yyHaveRel; -static int yyHaveTime; -static int yyHaveZone; -static time_t yyTimezone; -static time_t yyDay; -static time_t yyHour; -static time_t yyMinutes; -static time_t yyMonth; -static time_t yySeconds; -static time_t yyYear; -static MERIDIAN yyMeridian; -static time_t yyRelMonth; -static time_t yyRelSeconds; - -%} - -%union { - time_t Number; - enum _MERIDIAN Meridian; -} - -%token tAGO tDAY tDAYZONE tID tMERIDIAN tMINUTE_UNIT tMONTH tMONTH_UNIT -%token tSEC_UNIT tSNUMBER tUNUMBER tZONE tDST - -%type <Number> tDAY tDAYZONE tMINUTE_UNIT tMONTH tMONTH_UNIT -%type <Number> tSEC_UNIT tSNUMBER tUNUMBER tZONE -%type <Meridian> tMERIDIAN o_merid - -%% - -spec : /* NULL */ - | spec item - ; - -item : time { - yyHaveTime++; - } - | zone { - yyHaveZone++; - } - | date { - yyHaveDate++; - } - | day { - yyHaveDay++; - } - | rel { - yyHaveRel++; - } - | number - ; - -time : tUNUMBER tMERIDIAN { - yyHour = $1; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = $2; - } - | tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = 0; - yyMeridian = $4; - } - | tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($4 % 100 + ($4 / 100) * 60); - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER o_merid { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = $6; - } - | tUNUMBER ':' tUNUMBER ':' tUNUMBER tSNUMBER { - yyHour = $1; - yyMinutes = $3; - yySeconds = $5; - yyMeridian = MER24; - yyDSTmode = DSToff; - yyTimezone = - ($6 % 100 + ($6 / 100) * 60); - } - ; - -zone : tZONE { - yyTimezone = $1; - yyDSTmode = DSToff; - } - | tDAYZONE { - yyTimezone = $1; - yyDSTmode = DSTon; - } - | - tZONE tDST { - yyTimezone = $1; - yyDSTmode = DSTon; - } - ; - -day : tDAY { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tDAY ',' { - yyDayOrdinal = 1; - yyDayNumber = $1; - } - | tUNUMBER tDAY { - yyDayOrdinal = $1; - yyDayNumber = $2; - } - ; - -date : tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - } - | tUNUMBER '/' tUNUMBER '/' tUNUMBER { - yyMonth = $1; - yyDay = $3; - yyYear = $5; - } - | tUNUMBER tSNUMBER tSNUMBER { - /* ISO 8601 format. yyyy-mm-dd. */ - yyYear = $1; - yyMonth = -$2; - yyDay = -$3; - } - | tUNUMBER tMONTH tSNUMBER { - /* e.g. 17-JUN-1992. */ - yyDay = $1; - yyMonth = $2; - yyYear = -$3; - } - | tMONTH tUNUMBER { - yyMonth = $1; - yyDay = $2; - } - | tMONTH tUNUMBER ',' tUNUMBER { - yyMonth = $1; - yyDay = $2; - yyYear = $4; - } - | tUNUMBER tMONTH { - yyMonth = $2; - yyDay = $1; - } - | tUNUMBER tMONTH tUNUMBER { - yyMonth = $2; - yyDay = $1; - yyYear = $3; - } - ; - -rel : relunit tAGO { - yyRelSeconds = -yyRelSeconds; - yyRelMonth = -yyRelMonth; - } - | relunit - ; - -relunit : tUNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tSNUMBER tMINUTE_UNIT { - yyRelSeconds += $1 * $2 * 60L; - } - | tMINUTE_UNIT { - yyRelSeconds += $1 * 60L; - } - | tSNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tUNUMBER tSEC_UNIT { - yyRelSeconds += $1; - } - | tSEC_UNIT { - yyRelSeconds++; - } - | tSNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tUNUMBER tMONTH_UNIT { - yyRelMonth += $1 * $2; - } - | tMONTH_UNIT { - yyRelMonth += $1; - } - ; - -number : tUNUMBER { - if (yyHaveTime && yyHaveDate && !yyHaveRel) - yyYear = $1; - else { - if($1>10000) { - yyHaveDate++; - yyDay= ($1)%100; - yyMonth= ($1/100)%100; - yyYear = $1/10000; - } - else { - yyHaveTime++; - if ($1 < 100) { - yyHour = $1; - yyMinutes = 0; - } - else { - yyHour = $1 / 100; - yyMinutes = $1 % 100; - } - yySeconds = 0; - yyMeridian = MER24; - } - } - } - ; - -o_merid : /* NULL */ { - $$ = MER24; - } - | tMERIDIAN { - $$ = $1; - } - ; - -%% - -/* Month and day table. */ -static TABLE const MonthDayTable[] = { - { N_("january"), tMONTH, 1 }, - { N_("february"), tMONTH, 2 }, - { N_("march"), tMONTH, 3 }, - { N_("april"), tMONTH, 4 }, - { N_("may"), tMONTH, 5 }, - { N_("june"), tMONTH, 6 }, - { N_("july"), tMONTH, 7 }, - { N_("august"), tMONTH, 8 }, - { N_("september"), tMONTH, 9 }, - { N_("sept"), tMONTH, 9 }, - { N_("october"), tMONTH, 10 }, - { N_("november"), tMONTH, 11 }, - { N_("december"), tMONTH, 12 }, - { N_("sunday"), tDAY, 0 }, - { N_("monday"), tDAY, 1 }, - { N_("tuesday"), tDAY, 2 }, - { N_("tues"), tDAY, 2 }, - { N_("wednesday"), tDAY, 3 }, - { N_("wednes"), tDAY, 3 }, - { N_("thursday"), tDAY, 4 }, - { N_("thur"), tDAY, 4 }, - { N_("thurs"), tDAY, 4 }, - { N_("friday"), tDAY, 5 }, - { N_("saturday"), tDAY, 6 }, - { NULL } -}; - -/* Time units table. */ -static TABLE const UnitsTable[] = { - { N_("year"), tMONTH_UNIT, 12 }, - { N_("month"), tMONTH_UNIT, 1 }, - { N_("fortnight"), tMINUTE_UNIT, 14 * 24 * 60 }, - { N_("week"), tMINUTE_UNIT, 7 * 24 * 60 }, - { N_("day"), tMINUTE_UNIT, 1 * 24 * 60 }, - { N_("hour"), tMINUTE_UNIT, 60 }, - { N_("minute"), tMINUTE_UNIT, 1 }, - { N_("min"), tMINUTE_UNIT, 1 }, - { N_("second"), tSEC_UNIT, 1 }, - { N_("sec"), tSEC_UNIT, 1 }, - { NULL } -}; - -/* Assorted relative-time words. */ -static TABLE const OtherTable[] = { - { N_("tomorrow"), tMINUTE_UNIT, 1 * 24 * 60 }, - { N_("yesterday"), tMINUTE_UNIT, -1 * 24 * 60 }, - { N_("today"), tMINUTE_UNIT, 0 }, - { N_("now"), tMINUTE_UNIT, 0 }, - { N_("last"), tUNUMBER, -1 }, - { N_("this"), tMINUTE_UNIT, 0 }, - { N_("next"), tUNUMBER, 2 }, - { N_("first"), tUNUMBER, 1 }, -/* { N_("second"), tUNUMBER, 2 }, */ - { N_("third"), tUNUMBER, 3 }, - { N_("fourth"), tUNUMBER, 4 }, - { N_("fifth"), tUNUMBER, 5 }, - { N_("sixth"), tUNUMBER, 6 }, - { N_("seventh"), tUNUMBER, 7 }, - { N_("eighth"), tUNUMBER, 8 }, - { N_("ninth"), tUNUMBER, 9 }, - { N_("tenth"), tUNUMBER, 10 }, - { N_("eleventh"), tUNUMBER, 11 }, - { N_("twelfth"), tUNUMBER, 12 }, - { N_("ago"), tAGO, 1 }, - { NULL } -}; - -/* The timezone table. */ -/* Some of these are commented out because a time_t can't store a float. */ -static TABLE const TimezoneTable[] = { - { "gmt", tZONE, HOUR( 0) }, /* Greenwich Mean */ - { "ut", tZONE, HOUR( 0) }, /* Universal (Coordinated) */ - { "utc", tZONE, HOUR( 0) }, - { "wet", tZONE, HOUR( 0) }, /* Western European */ - { "bst", tDAYZONE, HOUR( 0) }, /* British Summer */ - { "wat", tZONE, HOUR( 1) }, /* West Africa */ - { "at", tZONE, HOUR( 2) }, /* Azores */ -#if 0 - /* For completeness. BST is also British Summer, and GST is - * also Guam Standard. */ - { "bst", tZONE, HOUR( 3) }, /* Brazil Standard */ - { "gst", tZONE, HOUR( 3) }, /* Greenland Standard */ -#endif -#if 0 - { "nft", tZONE, HOUR(3.5) }, /* Newfoundland */ - { "nst", tZONE, HOUR(3.5) }, /* Newfoundland Standard */ - { "ndt", tDAYZONE, HOUR(3.5) }, /* Newfoundland Daylight */ -#endif - { "ast", tZONE, HOUR( 4) }, /* Atlantic Standard */ - { "adt", tDAYZONE, HOUR( 4) }, /* Atlantic Daylight */ - { "est", tZONE, HOUR( 5) }, /* Eastern Standard */ - { "edt", tDAYZONE, HOUR( 5) }, /* Eastern Daylight */ - { "cst", tZONE, HOUR( 6) }, /* Central Standard */ - { "cdt", tDAYZONE, HOUR( 6) }, /* Central Daylight */ - { "mst", tZONE, HOUR( 7) }, /* Mountain Standard */ - { "mdt", tDAYZONE, HOUR( 7) }, /* Mountain Daylight */ - { "pst", tZONE, HOUR( 8) }, /* Pacific Standard */ - { "pdt", tDAYZONE, HOUR( 8) }, /* Pacific Daylight */ - { "yst", tZONE, HOUR( 9) }, /* Yukon Standard */ - { "ydt", tDAYZONE, HOUR( 9) }, /* Yukon Daylight */ - { "hst", tZONE, HOUR(10) }, /* Hawaii Standard */ - { "hdt", tDAYZONE, HOUR(10) }, /* Hawaii Daylight */ - { "cat", tZONE, HOUR(10) }, /* Central Alaska */ - { "ahst", tZONE, HOUR(10) }, /* Alaska-Hawaii Standard */ - { "nt", tZONE, HOUR(11) }, /* Nome */ - { "idlw", tZONE, HOUR(12) }, /* International Date Line West */ - { "cet", tZONE, -HOUR(1) }, /* Central European */ - { "met", tZONE, -HOUR(1) }, /* Middle European */ - { "mewt", tZONE, -HOUR(1) }, /* Middle European Winter */ - { "mest", tDAYZONE, -HOUR(1) }, /* Middle European Summer */ - { "swt", tZONE, -HOUR(1) }, /* Swedish Winter */ - { "sst", tDAYZONE, -HOUR(1) }, /* Swedish Summer */ - { "fwt", tZONE, -HOUR(1) }, /* French Winter */ - { "fst", tDAYZONE, -HOUR(1) }, /* French Summer */ - { "eet", tZONE, -HOUR(2) }, /* Eastern Europe, USSR Zone 1 */ - { "bt", tZONE, -HOUR(3) }, /* Baghdad, USSR Zone 2 */ -#if 0 - { "it", tZONE, -HOUR(3.5) },/* Iran */ -#endif - { "zp4", tZONE, -HOUR(4) }, /* USSR Zone 3 */ - { "zp5", tZONE, -HOUR(5) }, /* USSR Zone 4 */ -#if 0 - { "ist", tZONE, -HOUR(5.5) },/* Indian Standard */ -#endif - { "zp6", tZONE, -HOUR(6) }, /* USSR Zone 5 */ -#if 0 - /* For completeness. NST is also Newfoundland Stanard, and SST is - * also Swedish Summer. */ - { "nst", tZONE, -HOUR(6.5) },/* North Sumatra */ - { "sst", tZONE, -HOUR(7) }, /* South Sumatra, USSR Zone 6 */ -#endif /* 0 */ - { "wast", tZONE, -HOUR(7) }, /* West Australian Standard */ - { "wadt", tDAYZONE, -HOUR(7) }, /* West Australian Daylight */ -#if 0 - { "jt", tZONE, -HOUR(7.5) },/* Java (3pm in Cronusland!) */ -#endif - { "cct", tZONE, -HOUR(8) }, /* China Coast, USSR Zone 7 */ - { "jst", tZONE, -HOUR(9) }, /* Japan Standard, USSR Zone 8 */ -#if 0 - { "cast", tZONE, -HOUR(9.5) },/* Central Australian Standard */ - { "cadt", tDAYZONE, -HOUR(9.5) },/* Central Australian Daylight */ -#endif - { "east", tZONE, -HOUR(10) }, /* Eastern Australian Standard */ - { "eadt", tDAYZONE, -HOUR(10) }, /* Eastern Australian Daylight */ - { "gst", tZONE, -HOUR(10) }, /* Guam Standard, USSR Zone 9 */ - { "nzt", tZONE, -HOUR(12) }, /* New Zealand */ - { "nzst", tZONE, -HOUR(12) }, /* New Zealand Standard */ - { "nzdt", tDAYZONE, -HOUR(12) }, /* New Zealand Daylight */ - { "idle", tZONE, -HOUR(12) }, /* International Date Line East */ - { NULL } -}; - -/* Military timezone table. */ -static TABLE const MilitaryTable[] = { - { "a", tZONE, HOUR( 1) }, - { "b", tZONE, HOUR( 2) }, - { "c", tZONE, HOUR( 3) }, - { "d", tZONE, HOUR( 4) }, - { "e", tZONE, HOUR( 5) }, - { "f", tZONE, HOUR( 6) }, - { "g", tZONE, HOUR( 7) }, - { "h", tZONE, HOUR( 8) }, - { "i", tZONE, HOUR( 9) }, - { "k", tZONE, HOUR( 10) }, - { "l", tZONE, HOUR( 11) }, - { "m", tZONE, HOUR( 12) }, - { "n", tZONE, HOUR(- 1) }, - { "o", tZONE, HOUR(- 2) }, - { "p", tZONE, HOUR(- 3) }, - { "q", tZONE, HOUR(- 4) }, - { "r", tZONE, HOUR(- 5) }, - { "s", tZONE, HOUR(- 6) }, - { "t", tZONE, HOUR(- 7) }, - { "u", tZONE, HOUR(- 8) }, - { "v", tZONE, HOUR(- 9) }, - { "w", tZONE, HOUR(-10) }, - { "x", tZONE, HOUR(-11) }, - { "y", tZONE, HOUR(-12) }, - { "z", tZONE, HOUR( 0) }, - { NULL } -}; - - - - -/* ARGSUSED */ -static int -yyerror(s) - char *s; -{ - return 0; -} - - -static time_t -ToSeconds(Hours, Minutes, Seconds, Meridian) - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; -{ - if (Minutes < 0 || Minutes > 59 || Seconds < 0 || Seconds > 59) - return -1; - switch (Meridian) { - case MER24: - if (Hours < 0 || Hours > 23) - return -1; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERam: - if (Hours < 1 || Hours > 12) - return -1; - return (Hours * 60L + Minutes) * 60L + Seconds; - case MERpm: - if (Hours < 1 || Hours > 12) - return -1; - return ((Hours + 12) * 60L + Minutes) * 60L + Seconds; - default: - abort (); - } - /* NOTREACHED */ -} - - -static time_t -Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode) - time_t Month; - time_t Day; - time_t Year; - time_t Hours; - time_t Minutes; - time_t Seconds; - MERIDIAN Meridian; - DSTMODE DSTmode; -{ - static int DaysInMonth[12] = { - 31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 - }; - time_t tod; - time_t Julian; - int i; - - if (Year < 0) - Year = -Year; - if (Year < 100) - Year += 1900; - DaysInMonth[1] = Year % 4 == 0 && (Year % 100 != 0 || Year % 400 == 0) - ? 29 : 28; - if (Year < EPOCH || Year > 1999 - || Month < 1 || Month > 12 - /* Lint fluff: "conversion from long may lose accuracy" */ - || Day < 1 || Day > DaysInMonth[(int)--Month]) - return -1; - - for (Julian = Day - 1, i = 0; i < Month; i++) - Julian += DaysInMonth[i]; - for (i = EPOCH; i < Year; i++) - Julian += 365 + (i % 4 == 0); - Julian *= SECSPERDAY; - Julian += yyTimezone * 60L; - if ((tod = ToSeconds(Hours, Minutes, Seconds, Meridian)) < 0) - return -1; - Julian += tod; - if (DSTmode == DSTon - || (DSTmode == DSTmaybe && localtime(&Julian)->tm_isdst)) - Julian -= 60 * 60; - return Julian; -} - - -static time_t -DSTcorrect(Start, Future) - time_t Start; - time_t Future; -{ - time_t StartDay; - time_t FutureDay; - - StartDay = (localtime(&Start)->tm_hour + 1) % 24; - FutureDay = (localtime(&Future)->tm_hour + 1) % 24; - return (Future - Start) + (StartDay - FutureDay) * 60L * 60L; -} - - -static time_t -RelativeDate(Start, DayOrdinal, DayNumber) - time_t Start; - time_t DayOrdinal; - time_t DayNumber; -{ - struct tm *tm; - time_t now; - - now = Start; - tm = localtime(&now); - now += SECSPERDAY * ((DayNumber - tm->tm_wday + 7) % 7); - now += 7 * SECSPERDAY * (DayOrdinal <= 0 ? DayOrdinal : DayOrdinal - 1); - return DSTcorrect(Start, now); -} - - -static time_t -RelativeMonth(Start, RelMonth) - time_t Start; - time_t RelMonth; -{ - struct tm *tm; - time_t Month; - time_t Year; - - if (RelMonth == 0) - return 0; - tm = localtime(&Start); - Month = 12 * tm->tm_year + tm->tm_mon + RelMonth; - Year = Month / 12; - Month = Month % 12 + 1; - return DSTcorrect(Start, - Convert(Month, (time_t)tm->tm_mday, Year, - (time_t)tm->tm_hour, (time_t)tm->tm_min, (time_t)tm->tm_sec, - MER24, DSTmaybe)); -} - - -static int -LookupWord(buff) - char *buff; -{ - register char *p; - register char *q; - register const TABLE *tp; - int i; - int abbrev; - - /* Make it lowercase. */ - for (p = buff; *p; p++) - if (isupper(*p)) - *p = tolower(*p); - - if (strcmp(buff, "am") == 0 || strcmp(buff, "a.m.") == 0) { - yylval.Meridian = MERam; - return tMERIDIAN; - } - if (strcmp(buff, "pm") == 0 || strcmp(buff, "p.m.") == 0) { - yylval.Meridian = MERpm; - return tMERIDIAN; - } - - /* See if we have an abbreviation for a month. */ - if (strlen(buff) == 3) - abbrev = 1; - else if (strlen(buff) == 4 && buff[3] == '.') { - abbrev = 1; - buff[3] = '\0'; - } - else - abbrev = 0; - - for (tp = MonthDayTable; tp->name; tp++) { - if (abbrev) { - if (strncmp(buff, tp->name, 3) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - else if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - if (strcmp(buff, "dst") == 0) - return tDST; - - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Strip off any plural and try the units table again. */ - i = strlen(buff) - 1; - if (buff[i] == 's') { - buff[i] = '\0'; - for (tp = UnitsTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - buff[i] = 's'; /* Put back for "this" in OtherTable. */ - } - - for (tp = OtherTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - /* Military timezones. */ - if (buff[1] == '\0' && isalpha(*buff)) { - for (tp = MilitaryTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - } - - /* Drop out any periods and try the timezone table again. */ - for (i = 0, p = q = buff; *q; q++) - if (*q != '.') - *p++ = *q; - else - i++; - *p = '\0'; - if (i) - for (tp = TimezoneTable; tp->name; tp++) - if (strcmp(buff, tp->name) == 0) { - yylval.Number = tp->value; - return tp->type; - } - - return tID; -} - - -static int -yylex() -{ - register char c; - register char *p; - char buff[20]; - int Count; - int sign; - - for ( ; ; ) { - while (isspace(*yyInput)) - yyInput++; - - if (isdigit(c = *yyInput) || c == '-' || c == '+') { - if (c == '-' || c == '+') { - sign = c == '-' ? -1 : 1; - if (!isdigit(*++yyInput)) - /* skip the '-' sign */ - continue; - } - else - sign = 0; - for (yylval.Number = 0; isdigit(c = *yyInput++); ) - yylval.Number = 10 * yylval.Number + c - '0'; - yyInput--; - if (sign < 0) - yylval.Number = -yylval.Number; - return sign ? tSNUMBER : tUNUMBER; - } - if (isalpha(c)) { - for (p = buff; isalpha(c = *yyInput++) || c == '.'; ) - if (p < &buff[sizeof buff - 1]) - *p++ = c; - *p = '\0'; - yyInput--; - return LookupWord(buff); - } - if (c != '(') - return *yyInput++; - Count = 0; - do { - c = *yyInput++; - if (c == '\0') - return c; - if (c == '(') - Count++; - else if (c == ')') - Count--; - } while (Count > 0); - } -} - -#define TM_YEAR_ORIGIN 1900 - -/* Yield A - B, measured in seconds. */ -static long -difftm (a, b) - struct tm *a, *b; -{ - int ay = a->tm_year + (TM_YEAR_ORIGIN - 1); - int by = b->tm_year + (TM_YEAR_ORIGIN - 1); - int days = ( - /* difference in day of year */ - a->tm_yday - b->tm_yday - /* + intervening leap days */ - + ((ay >> 2) - (by >> 2)) - - (ay/100 - by/100) - + ((ay/100 >> 2) - (by/100 >> 2)) - /* + difference in years * 365 */ - + (long)(ay-by) * 365 - ); - return (60*(60*(24*days + (a->tm_hour - b->tm_hour)) - + (a->tm_min - b->tm_min)) - + (a->tm_sec - b->tm_sec)); -} - -time_t -get_date(p, now) - char *p; - struct timeb *now; -{ - struct tm *tm, gmt; - struct timeb ftz; - time_t Start; - time_t tod; - time_t nowtime; - - yyInput = p; - if (now == NULL) { - now = &ftz; - (void)time (&nowtime); - - if (! (tm = gmtime (&nowtime))) - return -1; - gmt = *tm; /* Make a copy, in case localtime modifies *tm. */ - - if (! (tm = localtime (&nowtime))) - return -1; - - ftz.timezone = difftm (&gmt, tm) / 60; - if(tm->tm_isdst) - ftz.timezone += 60; - } - else - { - nowtime = now->time; - } - - tm = localtime(&nowtime); - yyYear = tm->tm_year; - yyMonth = tm->tm_mon + 1; - yyDay = tm->tm_mday; - yyTimezone = now->timezone; - yyDSTmode = DSTmaybe; - yyHour = 0; - yyMinutes = 0; - yySeconds = 0; - yyMeridian = MER24; - yyRelSeconds = 0; - yyRelMonth = 0; - yyHaveDate = 0; - yyHaveDay = 0; - yyHaveRel = 0; - yyHaveTime = 0; - yyHaveZone = 0; - - if (yyparse() - || yyHaveTime > 1 || yyHaveZone > 1 || yyHaveDate > 1 || yyHaveDay > 1) - return -1; - - if (yyHaveDate || yyHaveTime || yyHaveDay) { - Start = Convert(yyMonth, yyDay, yyYear, yyHour, yyMinutes, yySeconds, - yyMeridian, yyDSTmode); - if (Start < 0) - return -1; - } - else { - Start = nowtime; - if (!yyHaveRel) - Start -= ((tm->tm_hour * 60L + tm->tm_min) * 60L) + tm->tm_sec; - } - - Start += yyRelSeconds; - Start += RelativeMonth(Start, yyRelMonth); - - if (yyHaveDay && !yyHaveDate) { - tod = RelativeDate(Start, yyDayOrdinal, yyDayNumber); - Start += tod; - } - - /* Have to do *something* with a legitimate -1 so it's distinguishable - * from the error return value. (Alternately could set errno on error.) */ - return Start == -1 ? 0 : Start; -} - - -#if defined(TEST) - -/* ARGSUSED */ -int -main(ac, av) - int ac; - char *av[]; -{ - char buff[128]; - time_t d; - - (void)printf("Enter date, or blank line to exit.\n\t> "); - (void)fflush(stdout); - while (gets(buff) && buff[0]) { - d = get_date(buff, (struct timeb *)NULL); - if (d == -1) - (void)printf("Bad format - couldn't convert.\n"); - else - (void)printf("%s", ctime(&d)); - (void)printf("\t> "); - (void)fflush(stdout); - } - exit(0); - /* NOTREACHED */ -} -#endif /* defined(TEST) */ diff --git a/calendar/gui/gncal-day-panel.c b/calendar/gui/gncal-day-panel.c deleted file mode 100644 index b847cf8168..0000000000 --- a/calendar/gui/gncal-day-panel.c +++ /dev/null @@ -1,264 +0,0 @@ -/* Day view notebook panel for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <gtk/gtkhseparator.h> -#include "gncal-day-panel.h" -#include "main.h" -#include "timeutil.h" - - -guint -gncal_day_panel_get_type (void) -{ - static guint day_panel_type = 0; - - if (!day_panel_type) { - GtkTypeInfo day_panel_info = { - "GncalDayPanel", - sizeof (GncalDayPanel), - sizeof (GncalDayPanelClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) NULL, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - day_panel_type = gtk_type_unique (gtk_table_get_type (), &day_panel_info); - } - - return day_panel_type; -} - -static void -day_view_range_activated (GncalFullDay *fullday, GncalDayPanel *dpanel) -{ - iCalObject *ical; - - ical = ical_new ("", user_name, ""); - ical->new = 1; - - gncal_full_day_selection_range (fullday, &ical->dtstart, &ical->dtend); - - gnome_calendar_add_object (dpanel->calendar, ical); - gncal_full_day_focus_child (fullday, ical); -} - -static void -full_day_size_allocated (GtkWidget *widget, GtkAllocation *allocation, GncalDayPanel *dpanel) -{ - GtkAdjustment *adj; - int yoffset; - gfloat newval; - - adj = gtk_scrolled_window_get_vadjustment (dpanel->fullday_sw); - - yoffset = gncal_full_day_get_day_start_yoffset (GNCAL_FULL_DAY (widget)); - - newval = adj->lower + (adj->upper - adj->lower) * (double) yoffset / allocation->height; - if (newval != adj->value) - gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); -} - -static void -calendar_day_selected (GtkCalendar *calendar, GncalDayPanel *dpanel) -{ - gint y, m, d; - struct tm tm; - - gtk_calendar_get_date (calendar, &y, &m, &d); - - tm.tm_year = y - 1900; - tm.tm_mon = m; - tm.tm_mday = d; - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - - gnome_calendar_goto (dpanel->calendar, mktime (&tm)); -} - -static void -retag_calendar (GtkCalendar *calendar, GncalDayPanel *dpanel) -{ - gnome_calendar_tag_calendar (dpanel->calendar, GTK_CALENDAR (dpanel->gtk_calendar)); -} - -GtkWidget * -gncal_day_panel_new (GnomeCalendar *calendar, time_t start_of_day) -{ - GncalDayPanel *dpanel; - GtkWidget *w; - struct tm *tm; - - g_return_val_if_fail (calendar != NULL, NULL); - - dpanel = gtk_type_new (gncal_day_panel_get_type ()); - - gtk_container_border_width (GTK_CONTAINER (dpanel), 4); - gtk_table_set_row_spacings (GTK_TABLE (dpanel), 4); - gtk_table_set_col_spacings (GTK_TABLE (dpanel), 4); - - dpanel->calendar = calendar; - - /* Date label */ - - w = gtk_label_new (""); - dpanel->date_label = GTK_LABEL (w); - gtk_table_attach (GTK_TABLE (dpanel), w, - 0, 1, 0, 1, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - /* Full day */ - - w = gtk_scrolled_window_new (NULL, NULL); - dpanel->fullday_sw = GTK_SCROLLED_WINDOW (w); - gtk_scrolled_window_set_policy (dpanel->fullday_sw, - GTK_POLICY_AUTOMATIC, - GTK_POLICY_AUTOMATIC); - gtk_table_attach (GTK_TABLE (dpanel), w, - 0, 1, 1, 4, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - w = gncal_full_day_new (calendar, time_day_begin (start_of_day), time_day_end (start_of_day)); - dpanel->fullday = GNCAL_FULL_DAY (w); - gtk_signal_connect (GTK_OBJECT (dpanel->fullday), "range_activated", - (GtkSignalFunc) day_view_range_activated, - dpanel); - gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (dpanel->fullday_sw), w); - gtk_widget_show (w); - - /* We'll scroll the list to the proper initial position */ - - gtk_signal_connect (GTK_OBJECT (dpanel->fullday), "size_allocate", - (GtkSignalFunc) full_day_size_allocated, - dpanel); - - /* Gtk calendar */ - - tm = localtime (&start_of_day); - - w = gtk_calendar_new (); - dpanel->gtk_calendar = GTK_CALENDAR (w); - gtk_calendar_display_options (dpanel->gtk_calendar, - (GTK_CALENDAR_SHOW_HEADING - | GTK_CALENDAR_SHOW_DAY_NAMES - | (week_starts_on_monday - ? GTK_CALENDAR_WEEK_START_MONDAY : 0))); - gtk_calendar_select_month (dpanel->gtk_calendar, tm->tm_mon, tm->tm_year + 1900); - gtk_calendar_select_day (dpanel->gtk_calendar, tm->tm_mday); - dpanel->day_selected_id = gtk_signal_connect (GTK_OBJECT (dpanel->gtk_calendar), - "day_selected_double_click", - (GtkSignalFunc) calendar_day_selected, - dpanel); - gtk_signal_connect (GTK_OBJECT (dpanel->gtk_calendar), "month_changed", - GTK_SIGNAL_FUNC (retag_calendar), dpanel); - gtk_table_attach (GTK_TABLE (dpanel), w, - 1, 2, 1, 2, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - /* Separator */ - - w = gtk_hseparator_new (); - gtk_table_attach (GTK_TABLE (dpanel), w, - 1, 2, 2, 3, - GTK_FILL | GTK_SHRINK, - GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - /* To-do */ - - w = gncal_todo_new (calendar); - dpanel->todo = GNCAL_TODO (w); - gtk_table_attach (GTK_TABLE (dpanel), w, - 1, 2, 3, 4, - GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - gtk_widget_show (w); - - /* Done */ - - gncal_day_panel_set (dpanel, start_of_day); - - return GTK_WIDGET (dpanel); -} - -static void -update (GncalDayPanel *dpanel, int update_fullday, iCalObject *ico, int flags) -{ - char buf [80]; - - if (update_fullday){ - gncal_full_day_update (dpanel->fullday, ico, flags); - retag_calendar (dpanel->gtk_calendar, dpanel); - } - gncal_todo_update (dpanel->todo, ico, flags); - - strftime (buf, sizeof (buf), "%a %b %d %Y", localtime (&dpanel->start_of_day)); - gtk_label_set (GTK_LABEL (dpanel->date_label), buf); -} - -void -gncal_day_panel_update (GncalDayPanel *dpanel, iCalObject *ico, int flags) -{ - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - update (dpanel, TRUE, ico, flags); -} - -void -gncal_day_panel_set (GncalDayPanel *dpanel, time_t start_of_day) -{ - char buf[80]; - struct tm tm; - - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - dpanel->start_of_day = time_day_begin (start_of_day); - if (dpanel->fullday->lower == dpanel->start_of_day) - return; - - tm = *localtime (&dpanel->start_of_day); - strftime (buf, sizeof (buf), "%a %b %d %Y", &tm); - gtk_label_set (GTK_LABEL (dpanel->date_label), buf); - - gncal_full_day_set_bounds (dpanel->fullday, dpanel->start_of_day, time_day_end (dpanel->start_of_day)); - - gtk_calendar_select_month (dpanel->gtk_calendar, tm.tm_mon, tm.tm_year + 1900); - - gtk_signal_handler_block (GTK_OBJECT (dpanel->gtk_calendar), dpanel->day_selected_id); - gtk_calendar_select_day (dpanel->gtk_calendar, tm.tm_mday); - gtk_signal_handler_unblock (GTK_OBJECT (dpanel->gtk_calendar), dpanel->day_selected_id); - - update (dpanel, FALSE, NULL, 0); -} - -void -gncal_day_panel_time_format_changed (GncalDayPanel *dpanel) -{ - g_return_if_fail (dpanel != NULL); - g_return_if_fail (GNCAL_IS_DAY_PANEL (dpanel)); - - gtk_calendar_display_options (dpanel->gtk_calendar, - (week_starts_on_monday - ? (dpanel->gtk_calendar->display_flags - | GTK_CALENDAR_WEEK_START_MONDAY) - : (dpanel->gtk_calendar->display_flags - & ~GTK_CALENDAR_WEEK_START_MONDAY))); -} diff --git a/calendar/gui/gncal-day-panel.h b/calendar/gui/gncal-day-panel.h deleted file mode 100644 index 48ba6f38b1..0000000000 --- a/calendar/gui/gncal-day-panel.h +++ /dev/null @@ -1,62 +0,0 @@ -/* Day view notebook panel for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_DAY_PANEL_H -#define GNCAL_DAY_PANEL_H - -#include <gtk/gtklabel.h> -#include <gtk/gtkscrolledwindow.h> -#include <gtk/gtktable.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gncal-full-day.h" -#include "gncal-todo.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_DAY_PANEL(obj) GTK_CHECK_CAST (obj, gncal_day_panel_get_type (), GncalDayPanel) -#define GNCAL_DAY_PANEL_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_panel_get_type (), GncalDayPanelClass) -#define GNCAL_IS_DAY_PANEL(obj) GTK_CHECK_TYPE (obj, gncal_day_panel_get_type ()) - - -typedef struct _GncalDayPanel GncalDayPanel; -typedef struct _GncalDayPanelClass GncalDayPanelClass; - -struct _GncalDayPanel { - GtkTable table; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - time_t start_of_day; - - GtkLabel *date_label; - GncalFullDay *fullday; - GtkScrolledWindow *fullday_sw; - GtkCalendar *gtk_calendar; - GncalTodo *todo; - - guint day_selected_id; -}; - -struct _GncalDayPanelClass { - GtkTableClass parent_class; -}; - - -guint gncal_day_panel_get_type (void); -GtkWidget *gncal_day_panel_new (GnomeCalendar *calendar, time_t start_of_day); - -void gncal_day_panel_update (GncalDayPanel *dpanel, iCalObject *ico, int flags); -void gncal_day_panel_set (GncalDayPanel *dpanel, time_t start_of_day); -void gncal_day_panel_time_format_changed (GncalDayPanel *dpanel); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gncal-day-view.c b/calendar/gui/gncal-day-view.c deleted file mode 100644 index 76cd00e90f..0000000000 --- a/calendar/gui/gncal-day-view.c +++ /dev/null @@ -1,401 +0,0 @@ -/* Day view widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <gnome.h> -#include "gncal-day-view.h" -#include "timeutil.h" -#include "view-utils.h" -#include "main.h" -#include "eventedit.h" -#include "popup-menu.h" - - -#define TEXT_BORDER 2 -#define MIN_INFO_WIDTH 50 - - -static void gncal_day_view_class_init (GncalDayViewClass *class); -static void gncal_day_view_init (GncalDayView *dview); -static void gncal_day_view_destroy (GtkObject *object); -static void gncal_day_view_realize (GtkWidget *widget); -static void gncal_day_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static gint gncal_day_view_expose (GtkWidget *widget, - GdkEventExpose *event); -static gint gncal_day_view_button_press (GtkWidget *widget, - GdkEventButton *event); - - -static GtkWidgetClass *parent_class; - - -guint -gncal_day_view_get_type (void) -{ - static guint day_view_type = 0; - - if (!day_view_type) { - GtkTypeInfo day_view_info = { - "GncalDayView", - sizeof (GncalDayView), - sizeof (GncalDayViewClass), - (GtkClassInitFunc) gncal_day_view_class_init, - (GtkObjectInitFunc) gncal_day_view_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - day_view_type = gtk_type_unique (gtk_widget_get_type (), &day_view_info); - } - - return day_view_type; -} - -static void -gncal_day_view_class_init (GncalDayViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gtk_widget_get_type ()); - - object_class->destroy = gncal_day_view_destroy; - - widget_class->realize = gncal_day_view_realize; - widget_class->size_request = gncal_day_view_size_request; - widget_class->expose_event = gncal_day_view_expose; - widget_class->button_press_event = gncal_day_view_button_press; -} - -static void -gncal_day_view_init (GncalDayView *dview) -{ - GTK_WIDGET_UNSET_FLAGS (dview, GTK_NO_WINDOW); - - dview->calendar = NULL; - - dview->lower = 0; - dview->upper = 0; - - dview->shadow_type = GTK_SHADOW_ETCHED_IN; -} - -static void -gncal_day_view_destroy (GtkObject *object) -{ - GncalDayView *dview; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (object)); - - dview = GNCAL_DAY_VIEW (object); - - if (dview->day_str) - g_free (dview->day_str); - if (dview->events) - calendar_destroy_event_list (dview->events); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static int -new_appointment (GtkWidget *widget, gpointer data) -{ - GncalDayView *dayview = GNCAL_DAY_VIEW (data); - iCalObject *ico; - GtkWidget *ee; - struct tm tm; - - ico = ical_new ("", user_name, ""); - ico->new = 1; - - tm = *localtime (&dayview->lower); - tm.tm_hour = day_begin; - ico->dtstart = mktime (&tm); - tm.tm_hour++; - ico->dtend = mktime (&tm); - ee = event_editor_new (dayview->calendar, ico); - gtk_widget_show (ee); - return 1; -} - -static void -context_menu (GncalDayView *dayview, GdkEventButton *event) -{ - static struct menu_item main_items[] = { - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - main_items [0].data = dayview; - popup_menu (main_items, 1, event); -} - -static void -switch_to_day (GncalDayView *dayview) -{ -} - -static gint -gncal_day_view_button_press (GtkWidget *widget, GdkEventButton *event) -{ - GncalDayView *dayview; - - dayview = GNCAL_DAY_VIEW (widget); - - if (event->button == 3) - context_menu (dayview, event); - - if (event->button == 1 && event->type == GDK_2BUTTON_PRESS) - gnome_calendar_dayjump (dayview->calendar, dayview->lower); - - return TRUE; -} - -GtkWidget * -gncal_day_view_new (GnomeCalendar *calendar, time_t lower, time_t upper) -{ - GncalDayView *dview; - - g_return_val_if_fail (calendar != NULL, NULL); - - dview = gtk_type_new (gncal_day_view_get_type ()); - - dview->calendar = calendar; - dview->lower = lower; - dview->upper = upper; - dview->events = 0; - - gncal_day_view_update (dview, NULL, 0); - - return GTK_WIDGET (dview); -} - -static void -gncal_day_view_realize (GtkWidget *widget) -{ - GdkWindowAttr attributes; - gint attributes_mask; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = (gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - - gdk_window_set_background (widget->window, &widget->style->bg[GTK_STATE_PRELIGHT]); -} - -static void -gncal_day_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GncalDayView *dview; - int str_width, width; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - dview = GNCAL_DAY_VIEW (widget); - - /* border and min width */ - - str_width = gdk_string_width (widget->style->font, dview->day_str); - - width = MAX (MIN_INFO_WIDTH, str_width); - - requisition->width = 2 * (widget->style->klass->xthickness + TEXT_BORDER) + width; - requisition->height = 2 * (widget->style->klass->ythickness + TEXT_BORDER); - - /* division line */ - - requisition->height += 2 * TEXT_BORDER + widget->style->klass->ythickness; - - /* title and at least one line of text */ - - requisition->height += 2 * (widget->style->font->ascent + widget->style->font->descent); -} - -static gint -gncal_day_view_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GncalDayView *dview; - int x1, y1, width, height; - GdkRectangle rect, dest; - GdkFont *font; - int str_width; - GdkGC *gc; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_DAY_VIEW (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return FALSE; - - gc = widget->style->fg_gc [GTK_STATE_NORMAL]; - dview = GNCAL_DAY_VIEW (widget); - - x1 = widget->style->klass->xthickness; - y1 = widget->style->klass->ythickness; - width = widget->allocation.width - 2 * x1; - height = widget->allocation.height - 2 * y1; - - /* Clear and paint frame shadow */ - - gdk_window_clear_area (widget->window, - event->area.x, event->area.y, - event->area.width, event->area.height); - - gtk_draw_shadow (widget->style, widget->window, - GTK_STATE_NORMAL, dview->shadow_type, - 0, 0, - widget->allocation.width, - widget->allocation.height); - - /* Clear and paint title */ - - font = widget->style->font; - - rect.x = x1; - rect.y = y1; - rect.width = width; - rect.height = 2 * TEXT_BORDER + font->ascent + font->descent; - - if (gdk_rectangle_intersect (&rect, &event->area, &dest)) { - gdk_draw_rectangle (widget->window, - widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - dest = rect; - - dest.x += TEXT_BORDER; - dest.y += TEXT_BORDER; - dest.width -= 2 * TEXT_BORDER; - dest.height -= 2 * TEXT_BORDER; - - gdk_gc_set_clip_rectangle (gc, &dest); - - str_width = gdk_string_width (font, dview->day_str); - - gdk_draw_string (widget->window, font, gc, - dest.x + (dest.width - str_width) / 2, - dest.y + font->ascent, - dview->day_str); - - gdk_gc_set_clip_rectangle (gc, NULL); - } - - /* Division line */ - - gtk_draw_hline (widget->style, - widget->window, - GTK_STATE_NORMAL, - rect.x, - rect.x + rect.width - 1, - rect.y + rect.height); - - /* Text */ - - if (dview->events != NULL){ - rect.x = x1 + TEXT_BORDER; - rect.y = y1 + 3 * TEXT_BORDER + - font->ascent + font->descent + - widget->style->klass->ythickness; - rect.width = width - 2 * TEXT_BORDER; - rect.height = height - (rect.y - y1) - TEXT_BORDER; - - if (gdk_rectangle_intersect (&rect, &event->area, &dest)) - view_utils_draw_events ( - widget, widget->window, gc, - &rect, - VIEW_UTILS_DRAW_END | VIEW_UTILS_DRAW_SPLIT, - dview->events, - dview->lower, - dview->upper); - } - - return FALSE; -} - -void -gncal_day_view_update (GncalDayView *dview, iCalObject *ico, int flags) -{ - struct tm tm; - char buf[256]; - - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - g_return_if_fail (dview->calendar->cal); - - if (dview->day_str) - g_free (dview->day_str); - - tm = *localtime (&dview->lower); - strftime (buf, sizeof (buf)-1, "%A %d", &tm); - dview->day_str = g_strdup (buf); - - if (dview->events) - calendar_destroy_event_list (dview->events); - - dview->events = calendar_get_events_in_range (dview->calendar->cal, - dview->lower, - dview->upper); - - gtk_widget_draw (GTK_WIDGET (dview), NULL); -} - -void -gncal_day_view_set_bounds (GncalDayView *dview, time_t lower, time_t upper) -{ - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - - if ((lower != dview->lower) || (upper != dview->upper)) { - dview->lower = lower; - dview->upper = upper; - - gncal_day_view_update (dview, NULL, 0); - } -} - -void -gncal_day_view_set_shadow (GncalDayView *dview, GtkShadowType shadow_type) -{ - g_return_if_fail (dview != NULL); - g_return_if_fail (GNCAL_IS_DAY_VIEW (dview)); - - if (shadow_type != dview->shadow_type) { - dview->shadow_type = shadow_type; - - gtk_widget_draw (GTK_WIDGET (dview), NULL); - } -} diff --git a/calendar/gui/gncal-day-view.h b/calendar/gui/gncal-day-view.h deleted file mode 100644 index dae1897fb6..0000000000 --- a/calendar/gui/gncal-day-view.h +++ /dev/null @@ -1,56 +0,0 @@ -/* Day view widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_DAY_VIEW_H -#define GNCAL_DAY_VIEW_H - - -#include <gtk/gtkwidget.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - -BEGIN_GNOME_DECLS - - -#define GNCAL_DAY_VIEW(obj) GTK_CHECK_CAST (obj, gncal_day_view_get_type (), GncalDayView) -#define GNCAL_DAY_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_day_view_get_type (), GncalDayViewClass) -#define GNCAL_IS_DAY_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_day_view_get_type ()) - - -typedef struct _GncalDayView GncalDayView; -typedef struct _GncalDayViewClass GncalDayViewClass; - -struct _GncalDayView { - GtkWidget widget; - - GnomeCalendar *calendar;/* the calendar we are associated to */ - - time_t lower; /* lower and upper times to display */ - time_t upper; /* these include the full day */ - - char *day_str; /* what day is it? */ - GList *events; /* the events for the this day */ - GtkShadowType shadow_type; -}; - -struct _GncalDayViewClass { - GtkWidgetClass parent_class; -}; - - -guint gncal_day_view_get_type (void); -GtkWidget *gncal_day_view_new (GnomeCalendar *calendar, time_t lower, time_t upper); - -void gncal_day_view_update (GncalDayView *dview, iCalObject *ico, int flags); -void gncal_day_view_set_bounds (GncalDayView *dview, time_t lower, time_t upper); - -void gncal_day_view_set_shadow (GncalDayView *dview, GtkShadowType shadow_type); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c deleted file mode 100644 index c33cb2ed31..0000000000 --- a/calendar/gui/gncal-full-day.c +++ /dev/null @@ -1,2267 +0,0 @@ -/* Full day widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ -#include <config.h> -#include <string.h> -#include <gdk/gdkkeysyms.h> -#include <gnome.h> -#include "eventedit.h" -#include "gncal-full-day.h" -#include "view-utils.h" -#include "layout.h" -#include "main.h" -#include "popup-menu.h" - -/* Images */ -#include "bell.xpm" -#include "recur.xpm" - -#define TEXT_BORDER 2 -#define HANDLE_SIZE 8 -#define MIN_WIDTH 200 -#define XOR_RECT_WIDTH 2 -#define UNSELECT_TIMEOUT 0 /* ms */ - -/* Size of the pixmaps */ -#define DECOR_WIDTH 16 -#define DECOR_HEIGHT 16 - -typedef struct { - iCalObject *ico; - GtkWidget *widget; - GdkWindow *window; - GdkWindow *decor_window; - guint focus_out_id; - int lower_row; /* zero is first displayed row */ - int rows_used; - int x; /* coords of child's window */ - int y; - int width; - int height; - int decor_width; - int decor_height; - int items; /* number of decoration bitmaps */ - time_t start, end; -} Child; - -struct drag_info { - enum { - DRAG_NONE, - DRAG_SELECT, /* selecting a range in the main window */ - DRAG_MOVE, /* moving a child */ - DRAG_SIZE_TOP, /* resizing a child */ - DRAG_SIZE_BOTTOM - } drag_mode; - - Child *child; - int child_click_y; - int child_start_row; - int child_rows_used; - - int sel_click_row; - int sel_start_row; - int sel_rows_used; - guint32 click_time; -}; - - -enum { - RANGE_ACTIVATED, - LAST_SIGNAL -}; - - -static void gncal_full_day_class_init (GncalFullDayClass *class); -static void gncal_full_day_init (GncalFullDay *fullday); -static void gncal_full_day_destroy (GtkObject *object); -static void gncal_full_day_map (GtkWidget *widget); -static void gncal_full_day_unmap (GtkWidget *widget); -static void gncal_full_day_realize (GtkWidget *widget); -static void gncal_full_day_unrealize (GtkWidget *widget); -static void gncal_full_day_draw (GtkWidget *widget, - GdkRectangle *area); -static void gncal_full_day_draw_focus (GtkWidget *widget); -static void gncal_full_day_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void gncal_full_day_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); -static gint gncal_full_day_button_press (GtkWidget *widget, - GdkEventButton *event); -static gint gncal_full_day_button_release (GtkWidget *widget, - GdkEventButton *event); -static gint gncal_full_day_motion (GtkWidget *widget, - GdkEventMotion *event); -static gint gncal_full_day_expose (GtkWidget *widget, - GdkEventExpose *event); -static gint gncal_full_day_key_press (GtkWidget *widget, - GdkEventKey *event); -static gint gncal_full_day_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint gncal_full_day_focus_out (GtkWidget *widget, - GdkEventFocus *event); -static void gncal_full_day_forall (GtkContainer *container, - gboolean include_internals, - GtkCallback callback, - gpointer callback_data); - -static void range_activated (GncalFullDay *fullday); - -static GtkContainerClass *parent_class; - -static int fullday_signals[LAST_SIGNAL] = { 0 }; - -/* The little images */ -static GdkPixmap *pixmap_bell, *pixmap_recur; - -static void -get_tm_range (GncalFullDay *fullday, - time_t time_lower, time_t time_upper, - struct tm *lower, struct tm *upper, - int *lower_row, int *rows_used) -{ - struct tm tm_lower, tm_upper; - int lmin, umin; - int lrow; - - /* Lower */ - - tm_lower = *localtime (&time_lower); - - if ((tm_lower.tm_min % fullday->interval) != 0) { - tm_lower.tm_min -= tm_lower.tm_min % fullday->interval; /* round down */ - mktime (&tm_lower); - } - - /* Upper */ - - tm_upper = *localtime (&time_upper); - - if ((tm_upper.tm_min % fullday->interval) != 0) { - tm_upper.tm_min += fullday->interval - (tm_upper.tm_min % fullday->interval); /* round up */ - mktime (&tm_upper); - } - - if (lower) - *lower = tm_lower; - - if (upper) - *upper = tm_upper; - - lmin = 60 * tm_lower.tm_hour + tm_lower.tm_min; - umin = 60 * tm_upper.tm_hour + tm_upper.tm_min; - - if (umin == 0) /* midnight of next day? */ - umin = 60 * 24; - - lrow = lmin / fullday->interval; - - if (lower_row) - *lower_row = lrow; - - if (rows_used) - *rows_used = (umin - lmin) / fullday->interval; -} - -static void -child_map (GncalFullDay *fullday, Child *child) -{ - gdk_window_show (child->window); - if (child->decor_width) - gdk_window_show (child->decor_window); - gtk_widget_show (child->widget); /* OK, not just a map... */ -} - -static void -child_unmap (GncalFullDay *fullday, Child *child) -{ - gdk_window_hide (child->window); - gdk_window_hide (child->decor_window); - if (GTK_WIDGET_MAPPED (child->widget)) - gtk_widget_unmap (child->widget); -} - -static void -child_set_text_pos (Child *child) -{ - GtkAllocation allocation; - int has_focus; - int handle_size; - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - handle_size = (child->ico->recur) ? 0 : HANDLE_SIZE; - - allocation.x = handle_size; - allocation.y = has_focus ? handle_size : 0; - allocation.width = child->width - handle_size - child->decor_width; - allocation.height = child->height - (has_focus ? (2 * handle_size) : 0); - - gtk_widget_size_request (child->widget, &child->widget->requisition); /* FIXME: is this needed? */ - gtk_widget_size_allocate (child->widget, &allocation); -} - -static void -child_realize (GncalFullDay *fullday, Child *child) -{ - GdkWindowAttr attributes; - gint attributes_mask; - GtkWidget *widget; - GdkColor c; - - widget = GTK_WIDGET (fullday); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = child->x; - attributes.y = child->y; - attributes.width = child->width - child->decor_width;; - attributes.height = child->height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.cursor = fullday->up_down_cursor; - attributes.event_mask = (GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_KEY_PRESS_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP | GDK_WA_CURSOR; - child->window = gdk_window_new (widget->window, &attributes, attributes_mask); - gdk_window_set_user_data (child->window, widget); - gtk_style_set_background (widget->style, child->window, GTK_STATE_NORMAL); - gtk_widget_set_parent_window (child->widget, child->window); - - /* Create the decoration window */ - attributes.x = child->x + child->width - child->decor_width; - attributes.width = child->decor_width ? child->decor_width : 1; - attributes.height = child->decor_height ? child->decor_height : 1; - attributes.visual = gdk_imlib_get_visual (); - attributes.colormap = gdk_imlib_get_colormap (); - attributes.event_mask = (GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK); - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - child->decor_window = gdk_window_new (widget->window, &attributes, attributes_mask); - gdk_color_white (gdk_imlib_get_colormap (), &c); - gdk_window_set_background (child->decor_window, &c); - gdk_window_set_user_data (child->decor_window, widget); - - if (!pixmap_bell){ - GdkImlibImage *imlib_bell, *imlib_recur; - GdkPixmap *mask; - - imlib_bell = gdk_imlib_create_image_from_xpm_data (bell_xpm); - gdk_imlib_render (imlib_bell, DECOR_WIDTH, DECOR_HEIGHT); - pixmap_bell = gdk_imlib_move_image (imlib_bell); - mask = gdk_imlib_move_mask (imlib_bell); - gdk_imlib_destroy_image (imlib_bell); - fullday->bell_gc = gdk_gc_new (child->decor_window); - if (mask) - gdk_gc_set_clip_mask (fullday->bell_gc, mask); - - imlib_recur = gdk_imlib_create_image_from_xpm_data (recur_xpm); - gdk_imlib_render (imlib_recur, DECOR_WIDTH, DECOR_HEIGHT); - pixmap_recur = gdk_imlib_move_image (imlib_recur); - mask = gdk_imlib_move_mask (imlib_recur); - gdk_imlib_destroy_image (imlib_recur); - fullday->recur_gc = gdk_gc_new (child->decor_window); - if (mask) - gdk_gc_set_clip_mask (fullday->recur_gc, mask); - } - child_set_text_pos (child); -} - -static void -child_unrealize (GncalFullDay *fullday, Child *child) -{ - if (GTK_WIDGET_REALIZED (child->widget)) - gtk_widget_unrealize (child->widget); - - gdk_window_set_user_data (child->window, NULL); - gdk_window_destroy (child->window); - child->window = NULL; -} - -static void -child_draw_decor (GncalFullDay *fullday, Child *child) -{ - iCalObject *ico = child->ico; - int ry = 0; - - if (ico->recur) { - gdk_gc_set_clip_origin (fullday->recur_gc, 0, ry); - gdk_draw_pixmap (child->decor_window, - fullday->recur_gc, - pixmap_recur, - 0, 0, - 0, ry, - DECOR_WIDTH, DECOR_HEIGHT); - ry += DECOR_HEIGHT; - } - - if (ico->dalarm.enabled || ico->malarm.enabled || ico->palarm.enabled || ico->aalarm.enabled) { - gdk_gc_set_clip_origin (fullday->bell_gc, 0, ry); - gdk_draw_pixmap (child->decor_window, - fullday->bell_gc, - pixmap_bell, - 0, 0, - 0, ry, - DECOR_WIDTH, DECOR_HEIGHT); - ry += DECOR_HEIGHT; - } -} - -static void -child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, GdkWindow *window, int draw_child) -{ - GdkRectangle arect, rect, dest; - int has_focus; - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - if (!window || (window == child->window)) { - if (!area) { - arect.x = 0; - arect.y = 0; - arect.width = child->width; - arect.height = child->height; - - area = &arect; - } - - /* Left handle */ - - rect.x = 0; - rect.y = has_focus ? HANDLE_SIZE : 0; - rect.width = HANDLE_SIZE; - rect.height = has_focus ? (child->height - 2 * HANDLE_SIZE) : child->height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, &rect, GTK_SHADOW_OUT); - - if (has_focus) { - /* Top handle */ - - rect.x = 0; - rect.y = 0; - rect.width = child->width - child->decor_width; - rect.height = HANDLE_SIZE; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, - &rect, GTK_SHADOW_OUT); - - /* Bottom handle */ - - rect.y = child->height - HANDLE_SIZE; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - view_utils_draw_textured_frame (GTK_WIDGET (fullday), child->window, - &rect, GTK_SHADOW_OUT); - } - - } else if (!window || (window == child->decor_window)) { - if (!area) { - arect.x = 0; - arect.y = 0; - arect.width = child->decor_width; - arect.height = child->decor_height; - - area = &arect; - } - - child_draw_decor (fullday, child); - } - - if (draw_child) - gtk_widget_draw (child->widget, NULL); -} - -static void -child_range_changed (GncalFullDay *fullday, Child *child) -{ - struct tm start, end; - int lower_row, rows_used; - int f_lower_row; - - /* Calc display range for event */ - - get_tm_range (fullday, child->start, child->end, &start, &end, &lower_row, &rows_used); - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, &f_lower_row, NULL); - - child->lower_row = lower_row - f_lower_row; - child->rows_used = rows_used; -} - -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - GncalFullDay *fullday; - GtkWidget *ee; - iCalObject *ico; - - fullday = GNCAL_FULL_DAY (data); - - ico = ical_new ("", user_name, ""); - ico->new = 1; - - gncal_full_day_selection_range (fullday, &ico->dtstart, &ico->dtend); - ee = event_editor_new (fullday->calendar, ico); - gtk_widget_show (ee); -} - -static void -edit_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GtkWidget *ee; - - child = data; - - ee = event_editor_new (GNCAL_FULL_DAY (child->widget->parent)->calendar, child->ico); - gtk_widget_show (ee); -} - -static void -delete_occurance (GtkWidget *widget, gpointer data) -{ - Child *child; - iCalObject *ical; - time_t *t; - - child = data; - ical = child->ico; - t = g_new(time_t, 1); - *t = child->start; - ical->exdate = g_list_prepend(ical->exdate, t); - gnome_calendar_object_changed(GNCAL_FULL_DAY (child->widget->parent)->calendar, child->ico, CHANGE_DATES); - -} - -static void -delete_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - child = data; - - fullday = GNCAL_FULL_DAY (child->widget->parent); - - gnome_calendar_remove_object (fullday->calendar, child->ico); -} - -static void -unrecur_appointment (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - iCalObject *new; - - child = data; - fullday = GNCAL_FULL_DAY (child->widget->parent); - - /* New object */ - new = ical_object_duplicate (child->ico); - g_free (new->recur); - new->recur = 0; - new->dtstart = child->start; - new->dtend = child->end; - - /* Duplicate, and eliminate the recurrency fields */ - ical_object_add_exdate (child->ico, child->start); - gnome_calendar_object_changed (fullday->calendar, child->ico, CHANGE_ALL); - - gnome_calendar_add_object (fullday->calendar, new); -} - -static void -child_popup_menu (GncalFullDay *fullday, Child *child, GdkEventButton *event) -{ - int sensitive, items; - struct menu_item *context_menu; - - static struct menu_item child_items[] = { - { N_("Edit this appointment..."), (GtkSignalFunc) edit_appointment, NULL, TRUE }, - { N_("Delete this appointment"), (GtkSignalFunc) delete_appointment, NULL, TRUE }, - { NULL, NULL, NULL, TRUE }, - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - static struct menu_item recur_child_items[] = { - { N_("Make this appointment movable"), (GtkSignalFunc) unrecur_appointment, NULL, TRUE }, - { N_("Edit this appointment..."), (GtkSignalFunc) edit_appointment, NULL, TRUE }, - { N_("Delete this occurance"), (GtkSignalFunc) delete_occurance, NULL, TRUE }, - { N_("Delete all occurances"), (GtkSignalFunc) delete_appointment, NULL, TRUE }, - { NULL, NULL, NULL, TRUE }, - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - sensitive = (child->ico->user_data == NULL); - - if (child->ico->recur){ - items = 6; - context_menu = &recur_child_items[0]; - context_menu[2].data = child; - context_menu[3].data = child; - context_menu[4].data = fullday; - context_menu[3].sensitive = sensitive; - } else { - items = 4; - context_menu = &child_items[0]; - context_menu[3].data = fullday; - } - /* These settings are common for each context sensitive menu */ - context_menu[0].data = child; - context_menu[1].data = child; - context_menu[0].sensitive = sensitive; - context_menu[1].sensitive = sensitive; - context_menu[2].sensitive = sensitive; - - popup_menu (context_menu, items, event); -} - -static void -child_realized_setup (GtkWidget *widget, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - child = data; - fullday = GNCAL_FULL_DAY (widget->parent); - - gdk_window_set_cursor (widget->window, fullday->beam_cursor); -} - -static void -child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) -{ - const int decor_width = child->decor_width; - - child->x = x; - child->y = y; - child->width = width; - child->height = height; - - if (!child->window) /* realized? */ - return; - - child_set_text_pos (child); - gdk_window_move_resize (child->window, x, y, width - decor_width, height); - - if (decor_width){ - gdk_window_move_resize (child->decor_window, x + width - decor_width, y, - decor_width, child->decor_height); - } -} - -static int -calc_row_height (GncalFullDay *fullday) -{ - int f_rows; - GtkWidget *widget; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - widget = GTK_WIDGET (fullday); - - return (widget->allocation.height - 2 * widget->style->klass->ythickness) / f_rows; -} - -static void -child_set_size (Child *child) -{ - int row_height; - int x, y, width, height; - GncalFullDay *fullday; - - fullday = GNCAL_FULL_DAY (child->widget->parent); - - row_height = calc_row_height (fullday); - - x = child->x; - y = child->lower_row * row_height + GTK_WIDGET (fullday)->style->klass->ythickness; - width = child->width; - height = child->rows_used * row_height; - - if (GTK_WIDGET_HAS_FOCUS (child->widget) && !child->ico->recur) { - y -= HANDLE_SIZE; - height += 2 * HANDLE_SIZE; - } - - child_set_pos (fullday, child, x, y, width, height); -} - -static gint -child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - child_set_size (data); - return FALSE; -} - -static gint -child_focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - char *text; - - child = data; - - child_set_size (child); - - /* Update summary in calendar object */ - - text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); - if (child->ico->summary && strcmp (text, child->ico->summary) == 0) - return FALSE; - - if (child->ico->summary) - g_free (child->ico->summary); - - child->ico->summary = text; - - /* Notify calendar of change */ - - fullday = GNCAL_FULL_DAY (widget->parent); - - gnome_calendar_object_changed (fullday->calendar, child->ico, CHANGE_SUMMARY); - - return FALSE; -} - -static gint -child_key_press (GtkWidget *widget, GdkEventKey *event, gpointer data) -{ - if (event->keyval != GDK_Escape) - return FALSE; - - /* If user pressed Esc, un-focus the child by focusing the fullday widget */ - - gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "key_press_event"); - gtk_widget_grab_focus (widget->parent); - - return FALSE; -} - -static gint -child_button_press (GtkWidget *widget, GdkEventButton *event, gpointer data) -{ - Child *child; - GncalFullDay *fullday; - - if (event->button != 3) - return FALSE; - - child = data; - fullday = GNCAL_FULL_DAY (widget->parent); - - gtk_signal_emit_stop_by_name (GTK_OBJECT (widget), "button_press_event"); - gtk_widget_grab_focus (widget); - child_popup_menu (fullday, child, event); - - return TRUE; -} - -/* - * compute the space required to display the decorations - */ -static void -child_compute_decor (Child *child) -{ - iCalObject *ico = child->ico; - int rows_used; - - child->items = 0; - rows_used = (child->rows_used < 1) ? 1 : child->rows_used; - if (ico->recur) - child->items++; - if (ico->dalarm.enabled || ico->aalarm.enabled || ico->palarm.enabled || ico->malarm.enabled) - child->items++; - - if (child->items > rows_used){ - child->decor_width = DECOR_WIDTH * 2; - child->decor_height = DECOR_HEIGHT; - } else { - child->decor_width = DECOR_WIDTH * (child->items ? 1 : 0); - child->decor_height = DECOR_HEIGHT * child->items; - } -} - -static Child * -child_new (GncalFullDay *fullday, time_t start, time_t end, iCalObject *ico) -{ - Child *child; - - child = g_new (Child, 1); - - child->ico = ico; - child->widget = gtk_text_new (NULL, NULL); - child->window = NULL; - child->x = 0; - child->y = 0; - child->width = 0; - child->height = 0; - child->start = start; - child->end = end; - child_range_changed (fullday, child); - child_compute_decor (child); - - if (ico->summary) - gtk_text_insert (GTK_TEXT (child->widget), NULL, NULL, NULL, - ico->summary, - strlen (ico->summary)); - - /* We set the i-beam cursor of the text widget upon realization */ - - gtk_signal_connect (GTK_OBJECT (child->widget), "realize", - (GtkSignalFunc) child_realized_setup, - child); - - gtk_signal_connect_after (GTK_OBJECT (child->widget), "focus_in_event", - (GtkSignalFunc) child_focus_in, - child); - - child->focus_out_id = gtk_signal_connect_after (GTK_OBJECT (child->widget), "focus_out_event", - (GtkSignalFunc) child_focus_out, - child); - - gtk_signal_connect (GTK_OBJECT (child->widget), "key_press_event", - (GtkSignalFunc) child_key_press, - child); - - gtk_signal_connect (GTK_OBJECT (child->widget), "button_press_event", - (GtkSignalFunc) child_button_press, - child); - - /* Finish setup */ - - gtk_text_set_editable (GTK_TEXT (child->widget), TRUE); - gtk_text_set_word_wrap (GTK_TEXT (child->widget), TRUE); - - gtk_widget_set_parent (child->widget, GTK_WIDGET (fullday)); - - return child; -} - -static void -squick (GtkWidget *widget, gpointer data) -{ -} - -static void -child_destroy (GncalFullDay *fullday, Child *child) -{ - /* Disconnect the focus_out_event signal since we will get such an event - * from the destroy call. - */ - gtk_signal_disconnect (GTK_OBJECT (child->widget), child->focus_out_id); - - if (GTK_WIDGET_MAPPED (fullday)) - child_unmap (fullday, child); - - if (GTK_WIDGET_REALIZED (fullday)) - child_unrealize (fullday, child); - - /* Unparent the child widget manually as we don't have a remove method */ - - gtk_signal_connect (GTK_OBJECT (child->widget), "destroy", - (GtkSignalFunc) squick, - NULL); - - gtk_widget_unparent (child->widget); - g_free (child); -} - -static int -calc_labels_width (GncalFullDay *fullday) -{ - struct tm cur, upper; - time_t tim, time_upper; - int width, max_w; - char buf[40]; - - get_tm_range (fullday, fullday->lower, fullday->upper, &cur, &upper, NULL, NULL); - - max_w = 0; - - tim = mktime (&cur); - time_upper = mktime (&upper); - - while (tim < time_upper) { - if (am_pm_flag) - strftime (buf, sizeof (buf), "%I:%M%p", &cur); - else - strftime (buf, sizeof (buf), "%H:%M", &cur); - - - width = gdk_string_width (GTK_WIDGET (fullday)->style->font, buf); - - if (width > max_w) - max_w = width; - - cur.tm_min += fullday->interval; - tim = mktime (&cur); - } - - return max_w; -} - -/* Used with layout_events(), takes in a list element and returns the start and end times for the - * event corresponding to that element. - */ -static void -child_layout_query_func (GList *event, time_t *start, time_t *end) -{ - Child *child; - - child = event->data; - - *start = child->start; - *end = child->end; -} - -/* Takes the list of children in the full day view and lays them out nicely without overlapping. - * Basically it calls the layout_events() function in layout.c and resizes the fullday's children. - */ -static void -layout_children (GncalFullDay *fullday) -{ - GtkWidget *widget; - GList *children; - Child *child; - int num_slots; - int *allocations; - int *slots; - int left_x; - int usable_pixels, pixels_per_col, extra_pixels; - int i; - - if (!fullday->children) - return; - - layout_events (fullday->children, child_layout_query_func, &num_slots, &allocations, &slots); - - /* Set the size and position of each child */ - - widget = GTK_WIDGET (fullday); - left_x = 2 * (widget->style->klass->xthickness + TEXT_BORDER) + calc_labels_width (fullday); - - usable_pixels = widget->allocation.width - left_x - widget->style->klass->xthickness; - pixels_per_col = usable_pixels / num_slots; - extra_pixels = usable_pixels % num_slots; - - for (children = fullday->children, i = 0; children; children = children->next, i++) { - child = children->data; - - child->x = left_x + pixels_per_col * allocations[i]; - child->width = pixels_per_col * slots[i]; - - if ((allocations[i] + slots[i]) == num_slots) - child->width += extra_pixels; - - child_set_size (child); - } - - g_free (allocations); - g_free (slots); -} - -guint -gncal_full_day_get_type (void) -{ - static guint full_day_type = 0; - - if (!full_day_type) { - GtkTypeInfo full_day_info = { - "GncalFullDay", - sizeof (GncalFullDay), - sizeof (GncalFullDayClass), - (GtkClassInitFunc) gncal_full_day_class_init, - (GtkObjectInitFunc) gncal_full_day_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - full_day_type = gtk_type_unique (gtk_container_get_type (), &full_day_info); - } - - return full_day_type; -} - -static void -gncal_full_day_class_init (GncalFullDayClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - GtkContainerClass *container_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - container_class = (GtkContainerClass *) class; - - parent_class = gtk_type_class (gtk_container_get_type ()); - - fullday_signals[RANGE_ACTIVATED] = - gtk_signal_new ("range_activated", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (GncalFullDayClass, range_activated), - gtk_signal_default_marshaller, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, fullday_signals, LAST_SIGNAL); - - object_class->destroy = gncal_full_day_destroy; - - widget_class->map = gncal_full_day_map; - widget_class->unmap = gncal_full_day_unmap; - widget_class->realize = gncal_full_day_realize; - widget_class->unrealize = gncal_full_day_unrealize; - widget_class->draw = gncal_full_day_draw; - widget_class->draw_focus = gncal_full_day_draw_focus; - widget_class->size_request = gncal_full_day_size_request; - widget_class->size_allocate = gncal_full_day_size_allocate; - widget_class->button_press_event = gncal_full_day_button_press; - widget_class->button_release_event = gncal_full_day_button_release; - widget_class->motion_notify_event = gncal_full_day_motion; - widget_class->expose_event = gncal_full_day_expose; - widget_class->key_press_event = gncal_full_day_key_press; - widget_class->focus_in_event = gncal_full_day_focus_in; - widget_class->focus_out_event = gncal_full_day_focus_out; - - container_class->forall = gncal_full_day_forall; - - class->range_activated = range_activated; -} - -static void -gncal_full_day_init (GncalFullDay *fullday) -{ - GTK_WIDGET_UNSET_FLAGS (fullday, GTK_NO_WINDOW); - GTK_WIDGET_SET_FLAGS (fullday, GTK_CAN_FOCUS); - - fullday->calendar = NULL; - - fullday->lower = 0; - fullday->upper = 0; - fullday->interval = 30; /* 30 minutes by default */ - - fullday->children = NULL; - fullday->drag_info = g_new0 (struct drag_info, 1); - - fullday->up_down_cursor = NULL; - fullday->beam_cursor = NULL; - fullday->recur_gc = NULL; - fullday->bell_gc = NULL; -} - -/* Destroys all the children in the full day widget */ -static void -destroy_children (GncalFullDay *fullday) -{ - GList *children; - - for (children = fullday->children; children; children = children->next) - child_destroy (fullday, children->data); - - g_list_free (fullday->children); - fullday->children = NULL; -} - -static void -gncal_full_day_destroy (GtkObject *object) -{ - GncalFullDay *fullday; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (object)); - - fullday = GNCAL_FULL_DAY (object); - - destroy_children (fullday); - - g_free (fullday->drag_info); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -GtkWidget * -gncal_full_day_new (GnomeCalendar *calendar, time_t lower, time_t upper) -{ - GncalFullDay *fullday; - - g_return_val_if_fail (calendar != NULL, NULL); - - fullday = gtk_type_new (gncal_full_day_get_type ()); - - fullday->calendar = calendar; - - gncal_full_day_set_bounds (fullday, lower, upper); - - return GTK_WIDGET (fullday); -} - -static void -gncal_full_day_map (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_MAPPED); - - fullday = GNCAL_FULL_DAY (widget); - - gdk_window_show (widget->window); - - for (children = fullday->children; children; children = children->next) - child_map (fullday, children->data); -} - -static void -gncal_full_day_unmap (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_MAPPED); - - fullday = GNCAL_FULL_DAY (widget); - - gdk_window_hide (widget->window); - - for (children = fullday->children; children; children = children->next) - child_unmap (fullday, children->data); -} - -static void -gncal_full_day_realize (GtkWidget *widget) -{ - GncalFullDay *fullday; - GdkWindowAttr attributes; - gint attributes_mask; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); - - fullday = GNCAL_FULL_DAY (widget); - - attributes.window_type = GDK_WINDOW_CHILD; - attributes.x = widget->allocation.x; - attributes.y = widget->allocation.y; - attributes.width = widget->allocation.width; - attributes.height = widget->allocation.height; - attributes.wclass = GDK_INPUT_OUTPUT; - attributes.visual = gtk_widget_get_visual (widget); - attributes.colormap = gtk_widget_get_colormap (widget); - attributes.event_mask = (gtk_widget_get_events (widget) - | GDK_EXPOSURE_MASK - | GDK_BUTTON_PRESS_MASK - | GDK_BUTTON_RELEASE_MASK - | GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK); - - attributes_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; - - widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attributes, attributes_mask); - gdk_window_set_user_data (widget->window, widget); - - widget->style = gtk_style_attach (widget->style, widget->window); - gdk_window_set_background (widget->window, &widget->style->bg[GTK_STATE_PRELIGHT]); - - fullday->up_down_cursor = gdk_cursor_new (GDK_DOUBLE_ARROW); - fullday->beam_cursor = gdk_cursor_new (GDK_XTERM); - - for (children = fullday->children; children; children = children->next) - child_realize (fullday, children->data); - -} - -static void -gncal_full_day_unrealize (GtkWidget *widget) -{ - GncalFullDay *fullday; - GList *children; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - fullday = GNCAL_FULL_DAY (widget); - - for (children = fullday->children; children; children = children->next) - child_unrealize (fullday, children->data); - - gdk_cursor_destroy (fullday->up_down_cursor); - fullday->up_down_cursor = NULL; - - gdk_cursor_destroy (fullday->beam_cursor); - fullday->beam_cursor = NULL; - - if (fullday->bell_gc) - gdk_gc_destroy (fullday->bell_gc); - if (fullday->recur_gc) - gdk_gc_destroy (fullday->recur_gc); - - if (pixmap_bell){ - gdk_pixmap_unref (pixmap_bell); - pixmap_bell = NULL; - } - - if (pixmap_recur){ - gdk_pixmap_unref (pixmap_recur); - pixmap_recur = NULL; - } - - if (GTK_WIDGET_CLASS (parent_class)->unrealize) - (* GTK_WIDGET_CLASS (parent_class)->unrealize) (widget); -} - -struct paint_info { - GtkWidget *widget; - struct drag_info *di; - GdkRectangle *area; - int x1, y1, width, height; - int labels_width; - int row_height; - struct tm start_tm; -}; - -static void -paint_row (GncalFullDay *fullday, int row, struct paint_info *p) -{ - GdkRectangle rect, dest; - GdkGC *left_gc, *right_gc, *text_gc; - int begin_row, end_row; - struct tm tm; - char buf[40]; - - begin_row = (day_begin * 60) / fullday->interval; - end_row = (day_end * 60) / fullday->interval; - - /* See which GCs we will use */ - - if ((p->di->sel_rows_used != 0) - && (row >= p->di->sel_start_row) - && (row < (p->di->sel_start_row + p->di->sel_rows_used))) { - left_gc = p->widget->style->bg_gc[GTK_STATE_SELECTED]; - right_gc = left_gc; - text_gc = p->widget->style->fg_gc[GTK_STATE_SELECTED]; - } else if ((row < begin_row) || (row >= end_row)) { - left_gc = p->widget->style->bg_gc[GTK_STATE_NORMAL]; - right_gc = p->widget->style->bg_gc[GTK_STATE_ACTIVE]; - text_gc = p->widget->style->fg_gc[GTK_STATE_NORMAL]; - } else { - left_gc = p->widget->style->bg_gc[GTK_STATE_NORMAL]; - right_gc = p->widget->style->bg_gc[GTK_STATE_PRELIGHT]; - text_gc = p->widget->style->fg_gc[GTK_STATE_NORMAL]; - } - - /* Left background and text */ - - rect.x = p->x1; - rect.y = p->y1 + row * p->row_height; - rect.width = 2 * TEXT_BORDER + p->labels_width; - rect.height = p->row_height - 1; - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) { - gdk_draw_rectangle (p->widget->window, - left_gc, - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - tm = p->start_tm; - tm.tm_min += row * fullday->interval; - mktime (&tm); - - if (am_pm_flag) - strftime (buf, sizeof (buf), "%I:%M%p", &tm); - else - strftime (buf, sizeof (buf), "%H:%M", &tm); - - gdk_draw_string (p->widget->window, - p->widget->style->font, - text_gc, - rect.x + TEXT_BORDER, - rect.y + TEXT_BORDER + p->widget->style->font->ascent, - buf); - } - - /* Right background */ - - rect.x += rect.width + p->widget->style->klass->xthickness; - rect.width = p->width - (rect.x - p->x1); - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) - gdk_draw_rectangle (p->widget->window, - right_gc, - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - /* Horizontal division at bottom of row */ - - rect.x = p->x1; - rect.y += rect.height; - rect.width = p->width; - rect.height = 1; - - if (gdk_rectangle_intersect (&rect, p->area, &dest)) - gdk_draw_line (p->widget->window, - p->widget->style->black_gc, - rect.x, rect.y, - rect.x + rect.width - 1, rect.y); -} - -static void -paint_back (GncalFullDay *fullday, GdkRectangle *area) -{ - struct paint_info p; - int start_row, end_row; - int i; - GdkRectangle rect, dest, aarea; - int f_rows; - int draw_focus; - - p.widget = GTK_WIDGET (fullday); - p.di = fullday->drag_info; - - if (!area) { - area = &aarea; - - area->x = 0; - area->y = 0; - area->width = p.widget->allocation.width; - area->height = p.widget->allocation.height; - } - p.area = area; - - p.x1 = p.widget->style->klass->xthickness; - p.y1 = p.widget->style->klass->ythickness; - p.width = p.widget->allocation.width - 2 * p.x1; - p.height = p.widget->allocation.height - 2 * p.y1; - - p.labels_width = calc_labels_width (fullday); - p.row_height = calc_row_height (fullday); - get_tm_range (fullday, fullday->lower, fullday->upper, &p.start_tm, NULL, NULL, &f_rows); - - /* Frame shadow */ - - rect.x = 0; - rect.y = 0; - rect.width = p.widget->allocation.width; - rect.height = p.widget->style->klass->ythickness; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - - if (!draw_focus) { - rect.y = p.widget->allocation.height - rect.height; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (!draw_focus) { - rect.y = p.widget->style->klass->ythickness; - rect.width = p.widget->style->klass->xthickness; - rect.height = p.widget->allocation.height - 2 * rect.y; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (!draw_focus) { - rect.x = p.widget->allocation.width - rect.width; - - draw_focus = gdk_rectangle_intersect (&rect, area, &dest); - } - - if (draw_focus) - gtk_widget_draw_focus (p.widget); - - /* Rows */ - - start_row = (area->y - p.y1) / p.row_height; - end_row = (area->y + area->height - 1 - p.y1) / p.row_height; - - if (end_row >= f_rows) - end_row = f_rows - 1; - - for (i = start_row; i <= end_row; i++) - paint_row (fullday, i, &p); - - /* Slack area at bottom of widget */ - - rect.x = p.x1; - rect.y = p.y1 + f_rows * p.row_height; - rect.width = p.width; - rect.height = p.height - (rect.y - p.y1); - - if (gdk_rectangle_intersect (&rect, area, &dest)) - gdk_draw_rectangle (p.widget->window, - p.widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - dest.x, dest.y, - dest.width, dest.height); - - /* Vertical division */ - - rect.x = p.x1 + 2 * TEXT_BORDER + p.labels_width; - rect.y = p.y1; - rect.width = p.widget->style->klass->xthickness; - rect.height = p.height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) - gtk_draw_vline (p.widget->style, p.widget->window, - GTK_STATE_NORMAL, - rect.y, - rect.y + rect.height - 1, - rect.x); -} - -static void -paint_back_rows (GncalFullDay *fullday, int start_row, int rows_used) -{ - int row_height; - int xthickness, ythickness; - GtkWidget *widget; - GdkRectangle area; - - widget = GTK_WIDGET (fullday); - - row_height = calc_row_height (fullday); - - xthickness = widget->style->klass->xthickness; - ythickness = widget->style->klass->ythickness; - - area.x = xthickness; - area.y = ythickness + start_row * row_height; - area.width = widget->allocation.width - 2 * xthickness; - area.height = rows_used * row_height; - - paint_back (fullday, &area); -} - -static void -gncal_full_day_draw (GtkWidget *widget, GdkRectangle *area) -{ - GncalFullDay *fullday; - GList *children; - Child *child; - GdkRectangle rect, dest; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (area != NULL); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return; - - fullday = GNCAL_FULL_DAY (widget); - - paint_back (fullday, area); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - rect.x = child->x; - rect.y = child->y; - rect.width = child->width; - rect.height = child->height; - - if (gdk_rectangle_intersect (&rect, area, &dest)) { - child_draw (fullday, child, NULL, NULL, TRUE); - } - } -} - -static void -gncal_full_day_draw_focus (GtkWidget *widget) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return; - - gtk_draw_shadow (widget->style, widget->window, - GTK_STATE_NORMAL, GTK_SHADOW_ETCHED_IN, - 0, 0, - widget->allocation.width, - widget->allocation.height); - - if (GTK_WIDGET_HAS_FOCUS (widget)) - gdk_draw_rectangle (widget->window, - widget->style->black_gc, - FALSE, - 0, 0, - widget->allocation.width - 1, - widget->allocation.height - 1); -} - -static void -gncal_full_day_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - GncalFullDay *fullday; - int labels_width; - int rows; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (requisition != NULL); - - fullday = GNCAL_FULL_DAY (widget); - - /* Border and min width */ - - labels_width = calc_labels_width (fullday); - - requisition->width = 2 * widget->style->klass->xthickness + 4 * TEXT_BORDER + labels_width + MIN_WIDTH; - requisition->height = 2 * widget->style->klass->ythickness; - - /* Rows */ - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &rows); - - requisition->height += (rows * (2 * TEXT_BORDER + widget->style->font->ascent + widget->style->font->descent) - + (rows - 1)); /* division lines */ -} - -static void -gncal_full_day_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - GncalFullDay *fullday; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (widget)); - g_return_if_fail (allocation != NULL); - - widget->allocation = *allocation; - - fullday = GNCAL_FULL_DAY (widget); - - if (GTK_WIDGET_REALIZED (widget)) - gdk_window_move_resize (widget->window, - allocation->x, allocation->y, - allocation->width, allocation->height); - - layout_children (fullday); -} - -static Child * -find_child_by_window (GncalFullDay *fullday, GdkWindow *window, int *on_text) -{ - GList *children; - Child *child; - GtkWidget *owner; - - *on_text = FALSE; - - gdk_window_get_user_data (window, (gpointer *) &owner); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->window == window || child->decor_window == window) - return child; - - if (child->widget == owner) { - *on_text = TRUE; - return child; - } - } - - return NULL; -} - -static void -draw_xor_rect (GncalFullDay *fullday) -{ - GtkWidget *widget; - struct drag_info *di; - int i; - int row_height; - int ythickness; - - widget = GTK_WIDGET (fullday); - - gdk_gc_set_function (widget->style->white_gc, GDK_INVERT); - gdk_gc_set_subwindow (widget->style->white_gc, GDK_INCLUDE_INFERIORS); - - ythickness = widget->style->klass->ythickness; - - di = fullday->drag_info; - - row_height = calc_row_height (fullday); - - for (i = 0; i < XOR_RECT_WIDTH; i++) - gdk_draw_rectangle (widget->window, - widget->style->white_gc, - FALSE, - di->child->x + i, - di->child_start_row * row_height + ythickness + i, - di->child->width - 2 * i - 1, - di->child_rows_used * row_height - 2 - 2 * i); - - gdk_gc_set_function (widget->style->white_gc, GDK_COPY); - gdk_gc_set_subwindow (widget->style->white_gc, GDK_CLIP_BY_CHILDREN); -} - -static int -get_row_from_y (GncalFullDay *fullday, int y, int round) -{ - GtkWidget *widget; - int row_height; - int f_rows; - int ythickness; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - row_height = calc_row_height (fullday); - - widget = GTK_WIDGET (fullday); - - ythickness = widget->style->klass->ythickness; - - y -= ythickness; - - if (y < 0) - y = 0; - else if (y >= (f_rows * row_height)) - y = f_rows * row_height - 1; - - if (round) - y += row_height / 2; - - y /= row_height; - - if (y > f_rows) - y = f_rows; /* note that this is 1 more than the last row's index */ - - return y; -} - -static int -button_1 (GncalFullDay *fullday, GdkEventButton *event) -{ - GtkWidget *widget; - Child *child; - int on_text; - struct drag_info *di; - gint y; - int row_height; - int has_focus; - int old_start_row, old_rows_used; - int old_max; - int paint_start_row, paint_rows_used; - - widget = GTK_WIDGET (fullday); - - if (event->window == widget->window) { - /* Clicked on main window */ - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - /* Prepare for drag */ - - di = fullday->drag_info; - - di->drag_mode = DRAG_SELECT; - - old_start_row = di->sel_start_row; - old_rows_used = di->sel_rows_used; - - di->sel_click_row = get_row_from_y (fullday, event->y, FALSE); - di->sel_start_row = di->sel_click_row; - di->sel_rows_used = 1; - - di->click_time = event->time; - - gdk_pointer_grab (widget->window, FALSE, - (GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_RELEASE_MASK), - NULL, - fullday->up_down_cursor, - event->time); - - if (old_rows_used == 0) { - paint_start_row = di->sel_start_row; - paint_rows_used = di->sel_rows_used; - } else { - paint_start_row = MIN (old_start_row, di->sel_start_row); - old_max = old_start_row + old_rows_used - 1; - paint_rows_used = MAX (old_max, di->sel_start_row) - paint_start_row + 1; - } - - paint_back_rows (fullday, paint_start_row, paint_rows_used); - - return TRUE; - } else { - /* Clicked on a child? */ - - child = find_child_by_window (fullday, event->window, &on_text); - - if (!child || on_text || child->ico->recur) - return FALSE; - - /* Prepare for drag */ - - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - has_focus = GTK_WIDGET_HAS_FOCUS (child->widget); - - if (has_focus) { - if (event->y < HANDLE_SIZE) - di->drag_mode = DRAG_SIZE_TOP; - else if (event->y >= (child->height - HANDLE_SIZE)) - di->drag_mode = DRAG_SIZE_BOTTOM; - else - di->drag_mode = DRAG_MOVE; - } else - di->drag_mode = DRAG_MOVE; - - row_height = calc_row_height (fullday); - - di->child = child; - - di->child_click_y = event->y; - di->child_start_row = child->lower_row; - di->child_rows_used = child->rows_used; - - gdk_pointer_grab (child->window, FALSE, - (GDK_BUTTON_MOTION_MASK - | GDK_POINTER_MOTION_HINT_MASK - | GDK_BUTTON_RELEASE_MASK), - NULL, - fullday->up_down_cursor, - event->time); - - draw_xor_rect (fullday); - - return TRUE; - } - - return FALSE; -} - -static int -button_3 (GncalFullDay *fullday, GdkEventButton *event) -{ - static struct menu_item main_items[] = { - { N_("New appointment..."), (GtkSignalFunc) new_appointment, NULL, TRUE } - }; - - GtkWidget *widget; - Child *child; - int on_text; - - widget = GTK_WIDGET (fullday); - - if (event->window == widget->window) { - /* Clicked on main window */ - - if (!GTK_WIDGET_HAS_FOCUS (widget)) - gtk_widget_grab_focus (widget); - - main_items[0].data = fullday; - - popup_menu (main_items, sizeof (main_items) / sizeof (main_items[0]), event); - - return TRUE; - } else { - child = find_child_by_window (fullday, event->window, &on_text); - - if (!child || on_text) - return FALSE; - - child_popup_menu (fullday, child, event); - - return TRUE; - } - - return FALSE; -} - -static gint -gncal_full_day_button_press (GtkWidget *widget, GdkEventButton *event) -{ - GncalFullDay *fullday; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - switch (event->button) { - case 1: - return button_1 (fullday, event); - - case 3: - return button_3 (fullday, event); - - default: - break; - } - - return FALSE; -} - -static void -recompute_motion (GncalFullDay *fullday, int y) -{ - struct drag_info *di; - int f_rows; - int row; - int has_focus; - - di = fullday->drag_info; - - get_tm_range (fullday, fullday->lower, fullday->upper, NULL, NULL, NULL, &f_rows); - - switch (di->drag_mode) { - case DRAG_SELECT: - row = get_row_from_y (fullday, y, FALSE); - - if (row >= f_rows) - row = f_rows - 1; - - if (row < di->sel_click_row) { - di->sel_start_row = row; - di->sel_rows_used = di->sel_click_row - row + 1; - } else { - di->sel_start_row = di->sel_click_row; - di->sel_rows_used = row - di->sel_start_row + 1; - } - - break; - - case DRAG_MOVE: - has_focus = GTK_WIDGET_HAS_FOCUS (di->child->widget); - - row = get_row_from_y (fullday, y - di->child_click_y + (has_focus ? HANDLE_SIZE : 0), TRUE); - - if (row > (f_rows - di->child_rows_used)) - row = f_rows - di->child_rows_used; - - di->child_start_row = row; - - break; - - case DRAG_SIZE_TOP: - row = get_row_from_y (fullday, y + HANDLE_SIZE, TRUE); - - if (row > (di->child_start_row + di->child_rows_used - 1)) - row = di->child_start_row + di->child_rows_used - 1; - - di->child_rows_used = (di->child_start_row + di->child_rows_used) - row; - di->child_start_row = row; - - break; - - case DRAG_SIZE_BOTTOM: - row = get_row_from_y (fullday, y - HANDLE_SIZE, TRUE); - - if (row <= di->child_start_row) - row = di->child_start_row + 1; - else if (row > f_rows) - row = f_rows; - - di->child_rows_used = row - di->child_start_row; - - break; - - default: - g_assert_not_reached (); - } -} - -static void -get_time_from_rows (GncalFullDay *fullday, int start_row, int rows_used, time_t *t_lower, time_t *t_upper) -{ - struct tm tm; - int row_height; - - get_tm_range (fullday, fullday->lower, fullday->upper, &tm, NULL, NULL, NULL); - - row_height = calc_row_height (fullday); - - tm.tm_min += fullday->interval * start_row; - *t_lower = mktime (&tm); - - tm.tm_min += fullday->interval * rows_used; - *t_upper = mktime (&tm); -} - -static void -update_from_drag_info (GncalFullDay *fullday) -{ - struct drag_info *di; - GtkWidget *widget; - - di = fullday->drag_info; - - widget = GTK_WIDGET (fullday); - - get_time_from_rows (fullday, di->child_start_row, di->child_rows_used, - &di->child->ico->dtstart, - &di->child->ico->dtend); - - child_range_changed (fullday, di->child); - - /* Notify calendar of change */ - - gnome_calendar_object_changed (fullday->calendar, di->child->ico, CHANGE_DATES); -} - -static gint -gncal_full_day_button_release (GtkWidget *widget, GdkEventButton *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - gint y; - int retval; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - retval = FALSE; - - switch (di->drag_mode) { - case DRAG_NONE: - break; - - case DRAG_SELECT: - if ((event->time - di->click_time) < UNSELECT_TIMEOUT) - di->sel_rows_used = 0; - else - recompute_motion (fullday, y); - - gdk_pointer_ungrab (event->time); - - paint_back_rows (fullday, di->sel_start_row, MAX (di->sel_rows_used, 1)); - - retval = TRUE; - break; - - case DRAG_MOVE: - case DRAG_SIZE_TOP: - case DRAG_SIZE_BOTTOM: - draw_xor_rect (fullday); - recompute_motion (fullday, y); - gdk_pointer_ungrab (event->time); - - update_from_drag_info (fullday); - - di->child_rows_used = 0; - - retval = TRUE; - break; - - default: - g_assert_not_reached (); - } - - di->drag_mode = DRAG_NONE; - di->child = NULL; - - return retval; -} - -static gint -gncal_full_day_motion (GtkWidget *widget, GdkEventMotion *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - gint y; - int old_min, old_max; - int new_min, new_max; - int new_start_row, new_rows_used; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - di = fullday->drag_info; - - gtk_widget_get_pointer (widget, NULL, &y); - - switch (di->drag_mode) { - case DRAG_NONE: - break; - - case DRAG_SELECT: - old_min = di->sel_start_row; - old_max = di->sel_start_row + di->sel_rows_used - 1; - - recompute_motion (fullday, y); - - new_min = di->sel_start_row; - new_max = di->sel_start_row + di->sel_rows_used - 1; - - new_start_row = MIN (old_min, new_min); - new_rows_used = MAX (old_max, new_max) - new_start_row + 1; - - paint_back_rows (fullday, new_start_row, new_rows_used); - - return TRUE; - - case DRAG_MOVE: - case DRAG_SIZE_TOP: - case DRAG_SIZE_BOTTOM: - draw_xor_rect (fullday); - recompute_motion (fullday, y); - draw_xor_rect (fullday); - - return TRUE; - - default: - g_assert_not_reached (); - } - - return FALSE; -} - -static gint -gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) -{ - GncalFullDay *fullday; - Child *child; - int on_text; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - if (!GTK_WIDGET_DRAWABLE (widget)) - return FALSE; - - fullday = GNCAL_FULL_DAY (widget); - - if (event->window == widget->window) - paint_back (fullday, &event->area); - else { - child = find_child_by_window (fullday, event->window, &on_text); - - if (child && !on_text) - child_draw (fullday, child, &event->area, event->window, FALSE); - } - - return FALSE; -} - -static gint -gncal_full_day_key_press (GtkWidget *widget, GdkEventKey *event) -{ - GncalFullDay *fullday; - struct drag_info *di; - GList *children; - Child *child; - gint pos; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - fullday = GNCAL_FULL_DAY (widget); - - di = fullday->drag_info; - - if (di->sel_rows_used == 0) - return FALSE; - - if (event->keyval == GDK_Return) { - gtk_signal_emit (GTK_OBJECT (fullday), fullday_signals[RANGE_ACTIVATED]); - return TRUE; - } - - /* - * If a non-printable key was pressed, bail. Otherwise, begin - * editing the appointment. - */ - if ((event->keyval < 0x20) || (event->keyval > 0xFF) - || (event->length == 0) || (event->state & GDK_CONTROL_MASK) - || (event->state & GDK_MOD1_MASK)) - return FALSE; - - gtk_signal_emit (GTK_OBJECT (fullday), - fullday_signals[RANGE_ACTIVATED]); - - /* - * Find the new child, which should hopefully be focused, and - * insert the keypress. - */ - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (GTK_WIDGET_HAS_FOCUS (child->widget)) { - pos = gtk_text_get_length (GTK_TEXT (child->widget)); - - gtk_editable_insert_text (GTK_EDITABLE (child->widget), - event->string, - event->length, - &pos); - - return TRUE; - } - } - - return FALSE; -} - -static gint -gncal_full_day_focus_in (GtkWidget *widget, GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_SET_FLAGS (widget, GTK_HAS_FOCUS); - gtk_widget_draw_focus (widget); - - return FALSE; -} - -static gint -gncal_full_day_focus_out (GtkWidget *widget, GdkEventFocus *event) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - GTK_WIDGET_UNSET_FLAGS (widget, GTK_HAS_FOCUS); - gtk_widget_draw_focus (widget); - - return FALSE; -} - -static void -gncal_full_day_forall (GtkContainer *container, gboolean include_internals, GtkCallback callback, gpointer callback_data) -{ - GncalFullDay *fullday; - GList *children; - Child *child; - - g_return_if_fail (container != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (container)); - g_return_if_fail (callback != NULL); - - fullday = GNCAL_FULL_DAY (container); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - (*callback) (child->widget, callback_data); - } -} - -static gint -child_compare (gconstpointer a, gconstpointer b) -{ - const Child *ca = a; - const Child *cb = b; - time_t diff; - - diff = ca->start - cb->start; - - if (diff == 0) - diff = cb->end - ca->end; - - return (diff < 0) ? -1 : (diff > 0) ? 1 : 0; -} - -static int -fullday_add_children (iCalObject *obj, time_t start, time_t end, void *c) -{ - GncalFullDay *fullday = c; - Child *child; - - child = child_new (fullday, start, end, obj); - fullday->children = g_list_insert_sorted (fullday->children, child, child_compare); - - return 1; -} - -void -gncal_full_day_update (GncalFullDay *fullday, iCalObject *ico, int flags) -{ - GList *children; - Child *child; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - if (!fullday->calendar->cal) - return; - - /* Try to find child that changed */ - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->ico == ico) - break; - } - - /* If child was found and nothing but the summary changed, we can just paint the child and return */ - - if (children && !(flags & ~CHANGE_SUMMARY)) { - child_draw (fullday, child, NULL, NULL, TRUE); - return; - } - - /* We have to regenerate and layout our list of children */ - - destroy_children (fullday); - - calendar_iterate (fullday->calendar->cal, - fullday->lower, - fullday->upper, - fullday_add_children, - fullday); - - layout_children (fullday); - - /* Realize and map children */ - - for (children = fullday->children; children; children = children->next) { - if (GTK_WIDGET_REALIZED (fullday)) - child_realize (fullday, children->data); - - if (GTK_WIDGET_MAPPED (fullday)) - child_map (fullday, children->data); - } - - gtk_widget_draw (GTK_WIDGET (fullday), NULL); -} - -void -gncal_full_day_set_bounds (GncalFullDay *fullday, time_t lower, time_t upper) -{ - struct drag_info *di; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - if ((lower != fullday->lower) || (upper != fullday->upper)) { - fullday->lower = lower; - fullday->upper = upper; - - di = fullday->drag_info; - - di->sel_rows_used = 0; /* clear selection */ - - gncal_full_day_update (fullday, NULL, 0); - } -} - -int -gncal_full_day_selection_range (GncalFullDay *fullday, time_t *lower, time_t *upper) -{ - struct drag_info *di; - time_t alower, aupper; - - g_return_val_if_fail (fullday != NULL, FALSE); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (fullday), FALSE); - - di = fullday->drag_info; - - if (di->sel_rows_used == 0){ - time_t now = time (NULL); - struct tm tm = *localtime (&now); - struct tm thisd = *localtime (&fullday->lower); - - thisd.tm_hour = tm.tm_hour; - thisd.tm_min = tm.tm_min; - thisd.tm_sec = 0; - *lower = mktime (&thisd); - thisd.tm_hour++; - *upper = mktime (&thisd); - return FALSE; - } - - get_time_from_rows (fullday, di->sel_start_row, di->sel_rows_used, &alower, &aupper); - - if (lower) - *lower = alower; - - if (upper) - *upper= aupper; - - return TRUE; -} - -void -gncal_full_day_focus_child (GncalFullDay *fullday, iCalObject *ico) -{ - GList *children; - Child *child; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (ico != NULL); - - for (children = fullday->children; children; children = children->next) { - child = children->data; - - if (child->ico == ico) { - gtk_widget_grab_focus (child->widget); - break; - } - } -} - -int -gncal_full_day_get_day_start_yoffset (GncalFullDay *fullday) -{ - GtkWidget *widget; - int begin_row; - - g_return_val_if_fail (fullday != NULL, 0); - g_return_val_if_fail (GNCAL_IS_FULL_DAY (fullday), 0); - - widget = GTK_WIDGET (fullday); - - begin_row = (day_begin * 60) / fullday->interval; - - return widget->style->klass->ythickness + begin_row * calc_row_height (fullday); -} - -static void -range_activated (GncalFullDay *fullday) -{ - struct drag_info *di; - - g_return_if_fail (fullday != NULL); - g_return_if_fail (GNCAL_IS_FULL_DAY (fullday)); - - di = fullday->drag_info; - - /* Remove selection; at this point someone should already have added an appointment */ - - di->sel_rows_used = 0; - - paint_back (fullday, NULL); -} diff --git a/calendar/gui/gncal-full-day.h b/calendar/gui/gncal-full-day.h deleted file mode 100644 index 287c5f63f6..0000000000 --- a/calendar/gui/gncal-full-day.h +++ /dev/null @@ -1,74 +0,0 @@ -/* Full day widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_FULL_DAY_H -#define GNCAL_FULL_DAY_H - - -#include <gtk/gtkcontainer.h> -#include <libgnome/gnome-defs.h> -#include "calendar.h" -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_FULL_DAY(obj) GTK_CHECK_CAST (obj, gncal_full_day_get_type (), GncalFullDay) -#define GNCAL_FULL_DAY_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_full_day_get_type (), GncalFullDayClass) -#define GNCAL_IS_FULL_DAY(obj) GTK_CHECK_TYPE (obj, gncal_full_day_get_type ()) - - -typedef struct _GncalFullDay GncalFullDay; -typedef struct _GncalFullDayClass GncalFullDayClass; - -struct _GncalFullDay { - GtkContainer container; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - time_t lower; /* lower time to display */ - time_t upper; /* upper time to display */ - int interval; /* interval between rows in minutes */ - - GList *children; /* container children */ - gpointer drag_info; /* internal drag information */ - - GdkCursor *up_down_cursor; /* for dragging children */ - GdkCursor *beam_cursor; /* for the text widgets */ - GdkGC *recur_gc; /* The gc used to draw the recur image */ - GdkGC *bell_gc; /* The gc used to draw on imlib windows */ - -}; - -struct _GncalFullDayClass { - GtkContainerClass parent_class; - - void (* range_activated) (GncalFullDay *fullday); -}; - - -guint gncal_full_day_get_type (void); -GtkWidget *gncal_full_day_new (GnomeCalendar *calendar, time_t lower, time_t upper); - -void gncal_full_day_update (GncalFullDay *fullday, iCalObject *ico, int flags); -void gncal_full_day_set_bounds (GncalFullDay *fullday, time_t lower, time_t upper); - -/* Returns the selected range in lower and upper. If nothing is - * selected, return value is FALSE, otherwise it is TRUE. - * The lower and upper values are always set to proper values, regardless of - * the selection value - */ -int gncal_full_day_selection_range (GncalFullDay *fullday, time_t *lower, time_t *upper); - -void gncal_full_day_focus_child (GncalFullDay *fullday, iCalObject *ico); - -int gncal_full_day_get_day_start_yoffset (GncalFullDay *fullday); - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gncal-todo.c b/calendar/gui/gncal-todo.c deleted file mode 100644 index 33e596b203..0000000000 --- a/calendar/gui/gncal-todo.c +++ /dev/null @@ -1,363 +0,0 @@ -/* To-do widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <config.h> -#include <string.h> -#include <gnome.h> -#include "gncal-todo.h" -#include "main.h" -#include "popup-menu.h" - - -static void gncal_todo_init (GncalTodo *todo); - - -guint -gncal_todo_get_type (void) -{ - static guint todo_type = 0; - - if (!todo_type) { - GtkTypeInfo todo_info = { - "GncalTodo", - sizeof (GncalTodo), - sizeof (GncalTodoClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) gncal_todo_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - todo_type = gtk_type_unique (gtk_vbox_get_type (), &todo_info); - } - - return todo_type; -} - -static void -ok_button (GtkWidget *widget, GnomeDialog *dialog) -{ - iCalObject *ico; - GncalTodo *todo; - GtkEntry *entry; - - ico = gtk_object_get_user_data (GTK_OBJECT (dialog)); - - todo = GNCAL_TODO (gtk_object_get_data (GTK_OBJECT (dialog), "gncal_todo")); - entry = GTK_ENTRY (gtk_object_get_data (GTK_OBJECT (dialog), "summary_entry")); - - if (ico->summary) - g_free (ico->summary); - - ico->summary = g_strdup (gtk_entry_get_text (entry)); - ico->user_data = NULL; - - if (ico->new) { - gnome_calendar_add_object (todo->calendar, ico); - ico->new = FALSE; - } else - gnome_calendar_object_changed (todo->calendar, ico, CHANGE_ALL); /* ok, summary only... */ - - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -static void -cancel_button (GtkWidget *widget, GnomeDialog *dialog) -{ - iCalObject *ico; - - ico = gtk_object_get_user_data (GTK_OBJECT (dialog)); - - ico->user_data = NULL; - - if (ico->new) - ical_object_destroy (ico); - - gtk_widget_destroy (GTK_WIDGET (dialog)); -} - -static gint -delete_event (GtkWidget *widget, GdkEvent *event, GnomeDialog *dialog) -{ - cancel_button (NULL, dialog); - return TRUE; -} - -static void -simple_todo_editor (GncalTodo *todo, iCalObject *ico) -{ - GtkWidget *dialog; - GtkWidget *hbox; - GtkWidget *w; - GtkWidget *entry; - - dialog = gnome_dialog_new (ico->new ? _("Create to-do item") : _("Edit to-do item"), - GNOME_STOCK_BUTTON_OK, - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (todo->calendar)); - hbox = gtk_hbox_new (FALSE, 4); - gtk_container_border_width (GTK_CONTAINER (hbox), 4); - gtk_box_pack_start (GTK_BOX (GNOME_DIALOG (dialog)->vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - w = gtk_label_new (_("Summary:")); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - entry = gtk_entry_new (); - gtk_entry_set_text (GTK_ENTRY (entry), ico->summary); - gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); - gtk_widget_show (entry); - - ico->user_data = dialog; - - gtk_object_set_user_data (GTK_OBJECT (dialog), ico); - - gtk_object_set_data (GTK_OBJECT (dialog), "gncal_todo", todo); - gtk_object_set_data (GTK_OBJECT (dialog), "summary_entry", entry); - - gnome_dialog_button_connect (GNOME_DIALOG (dialog), 0, (GtkSignalFunc) ok_button, dialog); - gnome_dialog_button_connect (GNOME_DIALOG (dialog), 1, (GtkSignalFunc) cancel_button, dialog); - gtk_signal_connect (GTK_OBJECT (dialog), "delete_event", - (GtkSignalFunc) delete_event, - dialog); - - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE(entry)); - - gtk_window_position (GTK_WINDOW (dialog), GTK_WIN_POS_MOUSE); - gtk_widget_show (dialog); - gtk_widget_grab_focus (entry); -} - -static iCalObject * -get_clist_selected_ico (GtkCList *clist) -{ - gint sel; - - if (!clist->selection) - return NULL; - - sel = GPOINTER_TO_INT(clist->selection->data); - - return gtk_clist_get_row_data (clist, sel); -} - -static void -add_todo (GncalTodo *todo) -{ - iCalObject *ico; - - ico = ical_new ("", user_name, ""); - ico->type = ICAL_TODO; - ico->new = TRUE; - - simple_todo_editor (todo, ico); -} - -static void -edit_todo (GncalTodo *todo) -{ - simple_todo_editor (todo, get_clist_selected_ico (todo->clist)); -} - -static void -delete_todo (GncalTodo *todo) -{ - gnome_calendar_remove_object (todo->calendar, get_clist_selected_ico (todo->clist)); -} - -static void -add_activated (GtkWidget *widget, GncalTodo *todo) -{ - add_todo (todo); -} - -static void -edit_activated (GtkWidget *widget, GncalTodo *todo) -{ - edit_todo (todo); -} - -static void -delete_activated (GtkWidget *widget, GncalTodo *todo) -{ - delete_todo (todo); -} - -static void -clist_row_selected (GtkCList *clist, gint row, gint column, GdkEventButton *event, GncalTodo *todo) -{ - static struct menu_item items[] = { - { N_("Add to-do item..."), (GtkSignalFunc) add_activated, NULL, TRUE }, - { N_("Edit this item..."), (GtkSignalFunc) edit_activated, NULL, TRUE }, - { N_("Delete this item"), (GtkSignalFunc) delete_activated, NULL, TRUE } - }; - - int i; - - gtk_widget_set_sensitive (todo->edit_button, (todo->clist->selection != NULL)); - gtk_widget_set_sensitive (todo->delete_button, (todo->clist->selection != NULL)); - - if (!event) - return; - - switch (event->button) { - case 1: - if (event->type == GDK_2BUTTON_PRESS) - edit_todo (todo); - break; - - case 3: - for (i = 0; i < (sizeof (items) / sizeof (items[0])); i++) - items[i].data = todo; - - popup_menu (items, sizeof (items) / sizeof (items[0]), event); - break; - - default: - break; - } -} - -static void -gncal_todo_init (GncalTodo *todo) -{ - GtkWidget *w; - GtkWidget *sw; - GtkWidget *hbox; - - gtk_box_set_spacing (GTK_BOX (todo), 4); - - /* Label */ - - w = gtk_label_new (_("To-do list")); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_box_pack_start (GTK_BOX (todo), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Clist */ - - sw = gtk_scrolled_window_new (NULL, NULL); - gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - gtk_box_pack_start (GTK_BOX (todo), sw, TRUE, TRUE, 0); - gtk_widget_show (sw); - - w = gtk_clist_new (1); - todo->clist = GTK_CLIST (w); - gtk_clist_set_selection_mode (todo->clist, GTK_SELECTION_BROWSE); - - gtk_signal_connect (GTK_OBJECT (todo->clist), "select_row", - (GtkSignalFunc) clist_row_selected, - todo); - - gtk_container_add (GTK_CONTAINER (sw), w); - gtk_widget_show (w); - - /* Box for buttons */ - - hbox = gtk_hbox_new (TRUE, 4); - gtk_box_pack_start (GTK_BOX (todo), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - /* Add */ - - w = gtk_button_new_with_label (_("Add...")); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) add_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - /* Edit */ - - w = gtk_button_new_with_label (_("Edit...")); - todo->edit_button = w; - gtk_widget_set_sensitive (w, FALSE); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) edit_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); - - /* Delete */ - - w = gtk_button_new_with_label (_("Delete")); - todo->delete_button = w; - gtk_widget_set_sensitive (w, FALSE); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) delete_activated, - todo); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - gtk_widget_show (w); -} - -GtkWidget * -gncal_todo_new (GnomeCalendar *calendar) -{ - GncalTodo *todo; - - g_return_val_if_fail (calendar != NULL, NULL); - - todo = gtk_type_new (gncal_todo_get_type ()); - - todo->calendar = calendar; - - gncal_todo_update (todo, NULL, 0); - - return GTK_WIDGET (todo); -} - -static void -insert_in_clist (GncalTodo *todo, iCalObject *ico) -{ - int i; - char *text[1] = { ico->summary }; - iCalObject *row_ico; - - if (ico->priority == 0) - i = gtk_clist_append (todo->clist, text); /* items with undefined priority go to the end of the list */ - else { - - /* Find proper place in clist to insert object. Objects are sorted by priority. */ - - for (i = 0; i < todo->clist->rows; i++) { - row_ico = gtk_clist_get_row_data (todo->clist, i); - - if (ico->priority >= row_ico->priority) - break; - } - - gtk_clist_insert (todo->clist, i, text); - } - - /* Set the appropriate "done" icon and hook the object to the row */ - - gtk_clist_set_row_data (todo->clist, i, ico); -} - -void -gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags) -{ - GList *list; - - g_return_if_fail (todo != NULL); - g_return_if_fail (GNCAL_IS_TODO (todo)); - - gtk_clist_freeze (todo->clist); - - gtk_clist_clear (todo->clist); - - for (list = todo->calendar->cal->todo; list; list = list->next) - insert_in_clist (todo, list->data); - - gtk_clist_thaw (todo->clist); - - gtk_widget_set_sensitive (todo->edit_button, (todo->clist->selection != NULL)); - gtk_widget_set_sensitive (todo->delete_button, (todo->clist->selection != NULL)); -} diff --git a/calendar/gui/gncal-todo.h b/calendar/gui/gncal-todo.h deleted file mode 100644 index cb32c25421..0000000000 --- a/calendar/gui/gncal-todo.h +++ /dev/null @@ -1,52 +0,0 @@ -/* To-do widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef GNCAL_TODO_H -#define GNCAL_TODO_H - -#include <gtk/gtkclist.h> -#include <gtk/gtkvbox.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define GNCAL_TODO(obj) GTK_CHECK_CAST (obj, gncal_todo_get_type (), GncalTodo) -#define GNCAL_TODO_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_todo_get_type (), GncalTodoClass) -#define GNCAL_IS_TODO(obj) GTK_CHECK_TYPE (obj, gncal_todo_get_type ()) - - -typedef struct _GncalTodo GncalTodo; -typedef struct _GncalTodoClass GncalTodoClass; - -struct _GncalTodo { - GtkVBox vbox; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - GtkCList *clist; - - GtkWidget *edit_button; - GtkWidget *delete_button; -}; - -struct _GncalTodoClass { - GtkVBoxClass parent_class; -}; - - -guint gncal_todo_get_type (void); -GtkWidget *gncal_todo_new (GnomeCalendar *calendar); - -void gncal_todo_update (GncalTodo *todo, iCalObject *ico, int flags); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gncal-week-view.c b/calendar/gui/gncal-week-view.c deleted file mode 100644 index 41b2596016..0000000000 --- a/calendar/gui/gncal-week-view.c +++ /dev/null @@ -1,255 +0,0 @@ -/* Week view composite widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <config.h> -#include <string.h> -#include <gtk/gtk.h> -#include "gncal-week-view.h" -#include "main.h" -#include "timeutil.h" - -static void gncal_week_view_init (GncalWeekView *wview); - - -guint -gncal_week_view_get_type (void) -{ - static guint week_view_type = 0; - - if (!week_view_type) { - GtkTypeInfo week_view_info = { - "GncalWeekView", - sizeof (GncalWeekView), - sizeof (GncalWeekViewClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) gncal_week_view_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - week_view_type = gtk_type_unique (gtk_vbox_get_type (), &week_view_info); - } - - return week_view_type; -} - -static void -gncal_week_view_init (GncalWeekView *wview) -{ - int i; - - wview->calendar = NULL; - memset (&wview->start_of_week, 0, sizeof (wview->start_of_week)); - - for (i = 0; i < 7; i++) - wview->days[i] = NULL; - - wview->gtk_calendar = NULL; -} - -static void -jump_to_day (GtkCalendar *cal, GncalWeekView *wview, int day) -{ - struct tm tm; - time_t t; - static int inside; - - if (inside) - return; - inside = 1; - tm.tm_mday = day; - tm.tm_mon = cal->month; - tm.tm_year = cal->year - 1900; - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_isdst = -1; - t = mktime (&tm); - - gncal_week_view_set (wview, t); - inside = 0; -} - -static void -jump_to_day_click (GtkCalendar *cal, GncalWeekView *wview) -{ - jump_to_day (cal, wview, cal->selected_day); -} - -static void -sync_week (GtkCalendar *cal, GncalWeekView *wview) -{ - jump_to_day (cal, wview, wview->start_of_week.tm_mday + 7); - gnome_calendar_tag_calendar (wview->calendar, wview->gtk_calendar); -} - -static void -double_click_on_weekday (GtkWidget *widget, GdkEvent *e, GncalWeekView *wview) -{ -} - -GtkWidget * -gncal_week_view_new (GnomeCalendar *calendar, time_t start_of_week) -{ - GncalWeekView *wview; - GtkWidget *table; - int i; - - g_return_val_if_fail (calendar != NULL, NULL); - - wview = gtk_type_new (gncal_week_view_get_type ()); - - table = gtk_table_new (0, 0, 0); - gtk_table_set_homogeneous (GTK_TABLE (table), TRUE); - wview->label = gtk_label_new (""); - gtk_box_pack_start (GTK_BOX (wview), wview->label, 0, 0, 0); - gtk_box_pack_start (GTK_BOX (wview), table, 1, 1, 0); - wview->calendar = calendar; - for (i = 0; i < 7; i++) { - wview->days[i] = GNCAL_DAY_VIEW (gncal_day_view_new (calendar, 0, 0)); - gtk_signal_connect (GTK_OBJECT (wview->days [i]), "button_press_event", - GTK_SIGNAL_FUNC(double_click_on_weekday), wview); - - if (i < 5) - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->days[i]), - i, i + 1, - 0, 1, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - else - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->days[i]), - i - 2, i - 1, - 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 0, 0); - - gtk_widget_show (GTK_WIDGET (wview->days[i])); - } - - wview->gtk_calendar = GTK_CALENDAR (gtk_calendar_new ()); - - gtk_signal_connect (GTK_OBJECT (wview->gtk_calendar), "day_selected_double_click", - GTK_SIGNAL_FUNC(jump_to_day_click), wview); - gtk_signal_connect (GTK_OBJECT (wview->gtk_calendar), "month_changed", - GTK_SIGNAL_FUNC(sync_week), wview); - - gtk_calendar_display_options (wview->gtk_calendar, - (GTK_CALENDAR_SHOW_HEADING - | GTK_CALENDAR_SHOW_DAY_NAMES - | (week_starts_on_monday - ? GTK_CALENDAR_WEEK_START_MONDAY : 0))); - - gtk_table_attach (GTK_TABLE (table), GTK_WIDGET (wview->gtk_calendar), - 0, 3, - 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, - 4, 4); - gtk_widget_show (GTK_WIDGET (wview->gtk_calendar)); - - gncal_week_view_set (wview, start_of_week); - - return GTK_WIDGET (wview); -} - -static void -update (GncalWeekView *wview, int update_days, iCalObject *object, int flags) -{ - int i; - - if (update_days) - for (i = 0; i < 7; i++) - gncal_day_view_update (wview->days[i], object, flags); - - /* FIXME: update extra widgets */ -} - -void -gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags) -{ - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - update (wview, TRUE, ico, flags); -} - -void -gncal_week_view_set (GncalWeekView *wview, time_t start_of_week) -{ - struct tm tm; - time_t day_start, day_end, week_start, week_end; - int i; - - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - tm = *localtime (&start_of_week); - - /* back up to start of week (Monday) */ - - tm.tm_mday -= (tm.tm_wday == 0) ? 6 : (tm.tm_wday - 1); - - /* Start of day */ - - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - - day_start = week_start = mktime (&tm); - - /* Calendar */ - - gtk_calendar_select_month (wview->gtk_calendar, tm.tm_mon, tm.tm_year + 1900); - - /* Day views */ - - for (i = 0; i < 7; i++) { /* rest of days */ - tm.tm_mday++; - day_end = mktime (&tm); - - gncal_day_view_set_bounds (wview->days[i], day_start, day_end - 1); - - day_start = day_end; - } - - update (wview, FALSE, NULL, 0); - - /* The label */ - { - char buf [80]; - int len; - struct tm *t; - - week_end = time_add_day (week_start, 6); - t = localtime (&week_start); - - strftime (buf, sizeof (buf), "%a %b %d %Y - ", t); - len = strlen (buf); - - t = localtime (&week_end); - strftime (buf + len, sizeof (buf) - len, "%a %b %d %Y", t); - gtk_label_set (GTK_LABEL (wview->label), buf); - - } -} - -void -gncal_week_view_time_format_changed (GncalWeekView *wview) -{ - g_return_if_fail (wview != NULL); - g_return_if_fail (GNCAL_IS_WEEK_VIEW (wview)); - - gtk_calendar_display_options (wview->gtk_calendar, - (week_starts_on_monday - ? (wview->gtk_calendar->display_flags - | GTK_CALENDAR_WEEK_START_MONDAY) - : (wview->gtk_calendar->display_flags - & ~GTK_CALENDAR_WEEK_START_MONDAY))); -} diff --git a/calendar/gui/gncal-week-view.h b/calendar/gui/gncal-week-view.h deleted file mode 100644 index ab06161844..0000000000 --- a/calendar/gui/gncal-week-view.h +++ /dev/null @@ -1,57 +0,0 @@ -/* Week view composite widget for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef WEEK_VIEW_H -#define WEEK_VIEW_H - - -#include <gtk/gtkvbox.h> -#include <gtk/gtktable.h> -#include <gtk/gtkvbox.h> -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gncal-day-view.h" - -BEGIN_GNOME_DECLS - - -#define GNCAL_WEEK_VIEW(obj) GTK_CHECK_CAST (obj, gncal_week_view_get_type (), GncalWeekView) -#define GNCAL_WEEK_VIEW_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, gncal_week_view_get_type (), GncalWeekViewClass) -#define GNCAL_IS_WEEK_VIEW(obj) GTK_CHECK_TYPE (obj, gncal_week_view_get_type ()) - - -typedef struct _GncalWeekView GncalWeekView; -typedef struct _GncalWeekViewClass GncalWeekViewClass; - -struct _GncalWeekView { - GtkVBox box; - - GnomeCalendar *calendar; /* the calendar we are associated to */ - - struct tm start_of_week; - - GncalDayView *days[7]; /* the day view widgets */ - GtkCalendar *gtk_calendar; /* At least for now; see the FIXME comments in the .c file */ - GtkWidget *label; -}; - -struct _GncalWeekViewClass { - GtkVBoxClass parent_class; -}; - - -guint gncal_week_view_get_type (void); -GtkWidget *gncal_week_view_new (GnomeCalendar *calendar, time_t start_of_week); - -void gncal_week_view_update (GncalWeekView *wview, iCalObject *ico, int flags); -void gncal_week_view_set (GncalWeekView *wview, time_t start_of_week); -void gncal_week_view_time_format_changed (GncalWeekView *wview); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gncal.desktop b/calendar/gui/gncal.desktop deleted file mode 100644 index 9244f103fe..0000000000 --- a/calendar/gui/gncal.desktop +++ /dev/null @@ -1,19 +0,0 @@ -[Desktop Entry] -Name=Calendar -Name[es]=Calendario -Name[fr]=Calendrier -Name[de]=Kalender -Name[ko]=´Þ·Â -Name[no]=Kalender -Name[pt]=Agenda -Comment=Calendar application -Comment[es]=Calendario de Gnome -Comment[fr]=Calendrier GNOME -Comment[de]=Gnome Kalender -Comment[ko]=±×³ð ´Þ·Â -Comment[no]=Gnome Kalender -Comment[pt]=Agenda Gnome -Exec=gnomecal -Icon=gnome-calendar.png -Terminal=0 -Type=Application diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c deleted file mode 100644 index 5b59cb379c..0000000000 --- a/calendar/gui/gnome-cal.c +++ /dev/null @@ -1,486 +0,0 @@ -/* - * GnomeCalendar widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ -#include <config.h> -#include <gnome.h> -#include <unistd.h> -#include <signal.h> -#include <sys/wait.h> -#include <fcntl.h> -#include "calendar.h" -#include "gnome-cal.h" -#include "gncal-day-panel.h" -#include "gncal-week-view.h" -#include "month-view.h" -#include "year-view.h" -#include "timeutil.h" -#include "main.h" - -GnomeApp *parent_class; - -guint -gnome_calendar_get_type (void) -{ - static guint gnome_calendar_type = 0; - if(!gnome_calendar_type) { - GtkTypeInfo gnome_calendar_info = { - "GnomeCalendar", - sizeof(GnomeCalendar), - sizeof(GnomeCalendarClass), - (GtkClassInitFunc) NULL, - (GtkObjectInitFunc) NULL, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL, - }; - gnome_calendar_type = gtk_type_unique(gnome_app_get_type(), &gnome_calendar_info); - parent_class = gtk_type_class (gnome_app_get_type()); - } - return gnome_calendar_type; -} - -static void -setup_widgets (GnomeCalendar *gcal) -{ - time_t now; - - now = time (NULL); - - gcal->notebook = gtk_notebook_new (); - gcal->day_view = gncal_day_panel_new (gcal, now); - gcal->week_view = gncal_week_view_new (gcal, now); - gcal->month_view = month_view_new (gcal, now); - gcal->year_view = year_view_new (gcal, now); - - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->day_view, gtk_label_new (_("Day View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->week_view, gtk_label_new (_("Week View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->month_view, gtk_label_new (_("Month View"))); - gtk_notebook_append_page (GTK_NOTEBOOK (gcal->notebook), gcal->year_view, gtk_label_new (_("Year View"))); - - gtk_widget_show_all (gcal->notebook); - - gnome_app_set_contents (GNOME_APP (gcal), gcal->notebook); -} - -static GtkWidget * -get_current_page (GnomeCalendar *gcal) -{ - return GTK_NOTEBOOK (gcal->notebook)->cur_page->child; -} - -char * -gnome_calendar_get_current_view_name (GnomeCalendar *gcal) -{ - GtkWidget *page = get_current_page (gcal); - - if (page == gcal->day_view) - return "dayview"; - else if (page == gcal->week_view) - return "weekview"; - else if (page == gcal->month_view) - return "monthview"; - else if (page == gcal->year_view) - return "yearview"; - else - return "dayview"; -} - -void -gnome_calendar_goto (GnomeCalendar *gcal, time_t new_time) -{ - GtkWidget *current = get_current_page (gcal); - - g_return_if_fail (new_time != -1); - - new_time = time_day_begin (new_time); - - if (current == gcal->day_view) - gncal_day_panel_set (GNCAL_DAY_PANEL (gcal->day_view), new_time); - else if (current == gcal->week_view) - gncal_week_view_set (GNCAL_WEEK_VIEW (gcal->week_view), new_time); - else if (current == gcal->month_view) - month_view_set (MONTH_VIEW (gcal->month_view), new_time); - else if (current == gcal->year_view) - year_view_set (YEAR_VIEW (gcal->year_view), new_time); - else { - g_warning ("My penguin is gone!"); - g_assert_not_reached (); - } - - gcal->current_display = new_time; -} - -static void -gnome_calendar_direction (GnomeCalendar *gcal, int direction) -{ - GtkWidget *cp = get_current_page (gcal); - time_t new_time; - - if (cp == gcal->day_view) - new_time = time_add_day (time_day_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->week_view) - new_time = time_add_week (time_week_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->month_view) - new_time = time_add_month (time_month_begin (gcal->current_display), 1 * direction); - else if (cp == gcal->year_view) - new_time = time_add_year (time_year_begin (gcal->current_display), 1 * direction); - else { - g_warning ("Weee! Where did the penguin go?"); - g_assert_not_reached (); - new_time = 0; - } - - gnome_calendar_goto (gcal, new_time); -} - -void -gnome_calendar_next (GnomeCalendar *gcal) -{ - gnome_calendar_direction (gcal, 1); -} - -void -gnome_calendar_previous (GnomeCalendar *gcal) -{ - gnome_calendar_direction (gcal, -1); -} - -void -gnome_calendar_dayjump (GnomeCalendar *gcal, time_t time) -{ - gtk_notebook_set_page (GTK_NOTEBOOK (gcal->notebook), 0); - gnome_calendar_goto (gcal, time); -} - -void -gnome_calendar_goto_today (GnomeCalendar *gcal) -{ - gnome_calendar_goto (gcal, time (NULL)); -} - -void -gnome_calendar_set_view (GnomeCalendar *gcal, char *page_name) -{ - int page = 0; - - if (strcmp (page_name, "dayview") == 0) - page = 0; - else if (strcmp (page_name, "weekview") == 0) - page = 1; - else if (strcmp (page_name, "monthview") == 0) - page = 2; - else if (strcmp (page_name, "yearview") == 0) - page = 3; - gtk_notebook_set_page (GTK_NOTEBOOK (gcal->notebook), page); -} - -GtkWidget * -gnome_calendar_new (char *title) -{ - GtkWidget *retval; - GnomeCalendar *gcal; - GnomeApp *app; - - retval = gtk_type_new (gnome_calendar_get_type ()); - app = GNOME_APP (retval); - gcal = GNOME_CALENDAR (retval); - - app->name = g_strdup ("calendar"); - app->prefix = g_strconcat ("/", app->name, "/", NULL); - - gtk_window_set_title(GTK_WINDOW(retval), title); - - gcal->current_display = time_day_begin (time (NULL)); - gcal->cal = calendar_new (title); - setup_widgets (gcal); - return retval; -} - -static void -gnome_calendar_update_all (GnomeCalendar *cal, iCalObject *object, int flags) -{ - gncal_day_panel_update (GNCAL_DAY_PANEL (cal->day_view), object, flags); - gncal_week_view_update (GNCAL_WEEK_VIEW (cal->week_view), object, flags); - month_view_update (MONTH_VIEW (cal->month_view), object, flags); - year_view_update (YEAR_VIEW (cal->year_view), object, flags); -} - -int -gnome_calendar_load (GnomeCalendar *gcal, char *file) -{ - char *r; - - if ((r = calendar_load (gcal->cal, file)) != NULL){ - printf ("Error loading calendar: %s\n", r); - return 0; - } - gnome_calendar_update_all (gcal, NULL, 0); - return 1; -} - -void -gnome_calendar_add_object (GnomeCalendar *gcal, iCalObject *obj) -{ - calendar_add_object (gcal->cal, obj); - gnome_calendar_update_all (gcal, obj, CHANGE_NEW); -} - -void -gnome_calendar_remove_object (GnomeCalendar *gcal, iCalObject *obj) -{ - calendar_remove_object (gcal->cal, obj); - gnome_calendar_update_all (gcal, obj, CHANGE_ALL); -} - -void -gnome_calendar_object_changed (GnomeCalendar *gcal, iCalObject *obj, int flags) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - g_return_if_fail (obj != NULL); - - gcal->cal->modified = TRUE; - - gnome_calendar_update_all (gcal, obj, flags); - calendar_object_changed (gcal->cal, obj, flags); -} - -static int -max_open_files (void) -{ - static int files; - - if (files) - return files; - - files = sysconf (_SC_OPEN_MAX); - if (files != -1) - return files; -#ifdef OPEN_MAX - return files = OPEN_MAX; -#else - return files = 256; -#endif -} - -static void -execute (char *command, int close_standard) -{ - struct sigaction ignore, save_intr, save_quit; - int status = 0, i; - pid_t pid; - - ignore.sa_handler = SIG_IGN; - sigemptyset (&ignore.sa_mask); - ignore.sa_flags = 0; - - sigaction (SIGINT, &ignore, &save_intr); - sigaction (SIGQUIT, &ignore, &save_quit); - - if ((pid = fork ()) < 0){ - fprintf (stderr, "\n\nfork () = -1\n"); - return; - } - if (pid == 0){ - pid = fork (); - if (pid == 0){ - const int top = max_open_files (); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); - - for (i = (close_standard ? 0 : 3); i < top; i++) - close (i); - - /* FIXME: As an excercise to the reader, copy the - * code from mc to setup shell properly instead of - * /bin/sh. Yes, this comment is larger than a cut and paste. - */ - execl ("/bin/sh", "/bin/sh", "-c", command, (char *) 0); - - _exit (127); - } else { - _exit (127); - } - } - wait (&status); - sigaction (SIGINT, &save_intr, NULL); - sigaction (SIGQUIT, &save_quit, NULL); -} - -void -mail_notify (char *mail_address, char *text, time_t app_time) -{ - pid_t pid; - int p [2]; - char *command; - - pipe (p); - pid = fork (); - if (pid == 0){ - int dev_null; - - dev_null = open ("/dev/null", O_RDWR); - dup2 (p [0], 0); - dup2 (dev_null, 1); - dup2 (dev_null, 2); - execl ("/usr/lib/sendmail", "/usr/lib/sendmail", - mail_address, NULL); - _exit (127); - } - command = g_strconcat ("To: ", mail_address, "\n", - "Subject: ", _("Reminder of your appointment at "), - ctime (&app_time), "\n\n", text, "\n", NULL); - write (p [1], command, strlen (command)); - close (p [1]); - close (p [0]); - g_free (command); -} - -static void -stop_beeping (GtkObject *object, gpointer tagp) -{ - guint tag = GPOINTER_TO_INT (tagp); - - gtk_timeout_remove (tag); -} - -static gint -start_beeping (gpointer data) -{ - gdk_beep (); - - return TRUE; -} - -void -calendar_notify (time_t time, CalendarAlarm *which, void *data) -{ - iCalObject *ico = data; - guint tag; - - if (&ico->aalarm == which){ - time_t app = ico->dalarm.trigger + ico->dalarm.offset; - GtkWidget *w; - char *msg; - - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - - /* Idea: we need Snooze option :-) */ - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, "Ok", NULL); - tag = gtk_timeout_add (1000, start_beeping, NULL); - gtk_signal_connect (GTK_OBJECT (w), "destroy", stop_beeping, GINT_TO_POINTER (tag)); - gtk_widget_show (w); - - return; - } - - if (&ico->palarm == which){ - execute (ico->palarm.data, 0); - return; - } - - if (&ico->malarm == which){ - time_t app = ico->malarm.trigger + ico->malarm.offset; - - mail_notify (ico->malarm.data, ico->summary, app); - return; - } - - if (&ico->dalarm == which){ - time_t app = ico->dalarm.trigger + ico->dalarm.offset; - GtkWidget *w; - char *msg; - - msg = g_strconcat (_("Reminder of your appointment at "), - ctime (&app), "`", - ico->summary, "'", NULL); - w = gnome_message_box_new (msg, GNOME_MESSAGE_BOX_INFO, "Ok", NULL); - gtk_widget_show (w); - return; - } -} - -/* - * called from the calendar_iterate routine to mark the days of a GtkCalendar - */ -static int -mark_gtk_calendar_day (iCalObject *obj, time_t start, time_t end, void *c) -{ - GtkCalendar *gtk_cal = c; - struct tm tm_s; - time_t t, day_end; - - tm_s = *localtime (&start); - day_end = time_day_end (end); - - for (t = start; t <= day_end; t += 60*60*24){ - time_t new = mktime (&tm_s); - struct tm tm_day; - - tm_day = *localtime (&new); - gtk_calendar_mark_day (gtk_cal, tm_day.tm_mday); - tm_s.tm_mday++; - } - return TRUE; -} - -/* - * Tags the dates with appointments in a GtkCalendar based on the - * GnomeCalendar contents - */ -void -gnome_calendar_tag_calendar (GnomeCalendar *cal, GtkCalendar *gtk_cal) -{ - time_t month_begin, month_end; - struct tm tm; - - /* compute month_begin */ - tm.tm_hour = 0; - tm.tm_min = 0; - tm.tm_sec = 0; - tm.tm_mday = 0; - tm.tm_mon = gtk_cal->month; - tm.tm_year = gtk_cal->year - 1900; - tm.tm_isdst= -1; - - month_begin = mktime (&tm); - tm.tm_mon++; - month_end = mktime (&tm); - - gtk_calendar_freeze (gtk_cal); - gtk_calendar_clear_marks (gtk_cal); - calendar_iterate (cal->cal, month_begin, month_end, mark_gtk_calendar_day, gtk_cal); - gtk_calendar_thaw (gtk_cal); -} - -void -gnome_calendar_time_format_changed (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - /* FIXME: the queue resizes will do until we rewrite those views... */ - - gncal_day_panel_time_format_changed (GNCAL_DAY_PANEL (gcal->day_view)); - gtk_widget_queue_resize (gcal->day_view); - gncal_week_view_time_format_changed (GNCAL_WEEK_VIEW (gcal->week_view)); - gtk_widget_queue_resize (gcal->week_view); - month_view_time_format_changed (MONTH_VIEW (gcal->month_view)); - year_view_time_format_changed (YEAR_VIEW (gcal->year_view)); -} - -void -gnome_calendar_colors_changed (GnomeCalendar *gcal) -{ - g_return_if_fail (gcal != NULL); - g_return_if_fail (GNOME_IS_CALENDAR (gcal)); - - /* FIXME: add day and week view when they are done */ - - month_view_colors_changed (MONTH_VIEW (gcal->month_view)); - year_view_colors_changed (YEAR_VIEW (gcal->year_view)); -} diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h deleted file mode 100644 index ab4f5ff304..0000000000 --- a/calendar/gui/gnome-cal.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * GnomeCalendar widget - * Copyright (C) 1998 the Free Software Foundation - * - * Author: Miguel de Icaza (miguel@kernel.org) - */ - -#ifndef GNOME_CALENDAR_APP_H -#define GNOME_CALENDAR_APP_H - -#include <gnome.h> - -#include "calendar.h" - -BEGIN_GNOME_DECLS - -#define GNOME_CALENDAR(obj) GTK_CHECK_CAST(obj, gnome_calendar_get_type(), GnomeCalendar) -#define GNOME_CALENDAR_CLASS(class) GTK_CHECK_CAST_CLASS(class, gnome_calendar_get_type(), GnomeCalendarClass) -#define GNOME_IS_CALENDAR(obj) GTK_CHECK_TYPE(obj, gnome_calendar_get_type()) - -typedef struct { - GnomeApp gnome_app; - Calendar *cal; - time_t current_display; - - GtkWidget *notebook; - GtkWidget *day_view; - GtkWidget *week_view; - GtkWidget *month_view; - GtkWidget *year_view; - void *event_editor; -} GnomeCalendar; - -typedef struct { - GnomeAppClass parent_class; -} GnomeCalendarClass; - -guint gnome_calendar_get_type (void); -GtkWidget *gnome_calendar_new (char *title); -int gnome_calendar_load (GnomeCalendar *gcal, - char *file); -void gnome_calendar_add_object (GnomeCalendar *gcal, - iCalObject *obj); -void gnome_calendar_remove_object (GnomeCalendar *gcal, - iCalObject *obj); -void gnome_calendar_next (GnomeCalendar *gcal); -void gnome_calendar_previous (GnomeCalendar *gcal); -void gnome_calendar_goto (GnomeCalendar *gcal, - time_t new_time); -void gnome_calendar_dayjump (GnomeCalendar *gcal, - time_t time); -/* Jumps to the current day */ -void gnome_calendar_goto_today (GnomeCalendar *gcal); -void gnome_calendar_tag_calendar (GnomeCalendar *cal, - GtkCalendar *gtk_cal); -char *gnome_calendar_get_current_view_name (GnomeCalendar *gcal); -void gnome_calendar_set_view (GnomeCalendar *gcal, - char *page_name); - -/* Flags is a bitmask of CalObjectChange values */ -void gnome_calendar_object_changed (GnomeCalendar *gcal, - iCalObject *obj, - int flags); - -/* Notifies the calendar that the time format has changed and it must update all its views */ -void gnome_calendar_time_format_changed (GnomeCalendar *gcal); - -/* Notifies the calendar that the colors have changed and it must update all its views */ -void gnome_calendar_colors_changed (GnomeCalendar *gcal); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/gnome-cal.html b/calendar/gui/gnome-cal.html deleted file mode 100644 index eeb8d4e25e..0000000000 --- a/calendar/gui/gnome-cal.html +++ /dev/null @@ -1,42 +0,0 @@ -<!-- Some simple instructions on how to use the help browser --> -<BODY> -<!-- <TITLE>GNOME Calendar Documentation</TITLE> --> -<H2> GNOME Calendar Documentation </H2> -<p> -The GNOME calendar program is the calendaring program of the GNOME -system. It uses the vCalendar standard for transfering calendar -information (and is also the on-disk format used). - -<p> - -<a name="cmdline"> -<h2>Command line options</h2> - -Several options are available on the command line, they are: -<ul> - <li><tt>--events</tt> Displays the events for the date - specified (or today, if no date is specified). - - <li><tt>--from DATE</tt> Define the beginning of the range for - the event display, or the startup day on the calenday views. - By default, the event will span the whole day specified in - DATE. - - <li><tt>--to DATE</tt> Define the range end for the event - display. If this is not specified, it will default to the end - of the day specified by the <tt>--from</tt> option. - - <li><tt>--file FILE</tt> Set the calendar to the FILE - specified on the command line. -</ul> - -<p> - -DATE is interpreted as being in the local time- zone, unless a -specific timezone is specified. Examples of valid date specifications -include: "1 month ago", "2 hours ago", "400000 seconds ago", "last -year", "last Monday", "yesterday", "a fortnight ago", "3/31/92 -10:00:07 PST", "January 23, 1987 10:05pm", "22:00 GMT". - -</BODY> - diff --git a/calendar/gui/gnome-month-item.c b/calendar/gui/gnome-month-item.c deleted file mode 100644 index 1eb8412f5c..0000000000 --- a/calendar/gui/gnome-month-item.c +++ /dev/null @@ -1,1214 +0,0 @@ -/* General-purpose monthly calendar canvas item for GNOME - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <math.h> -#include <time.h> -#include <gnome.h> -#include "gnome-month-item.h" - - -#define DEFAULT_FONT "-*-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" - - -/* Number of days in a month, for normal and leap years */ -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 } -}; - -/* The weird month of September 1752, where 3 Sep through 13 Sep were eliminated due to the - * Gregorian reformation. - */ -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, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0 -}; - -#define REFORMATION_DAY 639787 /* First day of the reformation, counted from 1 Jan 1 */ -#define MISSING_DAYS 11 /* They corrected out 11 days */ -#define THURSDAY 4 /* First day of reformation */ -#define SATURDAY 6 /* Offset value; 1 Jan 1 was a Saturday */ -#define SEPT_1752_START 2 /* Start day within month */ -#define SEPT_1752_END 20 /* End day within month */ - - -enum { - ARG_0, - ARG_YEAR, - ARG_MONTH, - ARG_X, - ARG_Y, - ARG_WIDTH, - ARG_HEIGHT, - ARG_ANCHOR, - ARG_HEAD_PADDING, - ARG_DAY_PADDING, - ARG_DAY_NAMES, - ARG_HEADING_HEIGHT, - ARG_HEADING_ANCHOR, - ARG_DAY_ANCHOR, - ARG_START_ON_MONDAY, - ARG_HEAD_FONT, - ARG_HEAD_FONT_GDK, - ARG_DAY_FONT, - ARG_DAY_FONT_GDK, - ARG_HEAD_COLOR, - ARG_HEAD_COLOR_GDK, - ARG_OUTLINE_COLOR, - ARG_OUTLINE_COLOR_GDK, - ARG_DAY_BOX_COLOR, - ARG_DAY_BOX_COLOR_GDK, - ARG_DAY_COLOR, - ARG_DAY_COLOR_GDK -}; - - -static void gnome_month_item_class_init (GnomeMonthItemClass *class); -static void gnome_month_item_init (GnomeMonthItem *mitem); -static void gnome_month_item_destroy (GtkObject *object); -static void gnome_month_item_set_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); -static void gnome_month_item_get_arg (GtkObject *object, - GtkArg *arg, - guint arg_id); - - - -static GnomeCanvasGroupClass *parent_class; - - -GtkType -gnome_month_item_get_type (void) -{ - static GtkType month_item_type = 0; - - if (!month_item_type) { - GtkTypeInfo month_item_info = { - "GnomeMonthItem", - sizeof (GnomeMonthItem), - sizeof (GnomeMonthItemClass), - (GtkClassInitFunc) gnome_month_item_class_init, - (GtkObjectInitFunc) gnome_month_item_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - month_item_type = gtk_type_unique (gnome_canvas_group_get_type (), &month_item_info); - } - - return month_item_type; -} - -static void -gnome_month_item_class_init (GnomeMonthItemClass *class) -{ - GtkObjectClass *object_class; - GnomeCanvasItemClass *item_class; - - object_class = (GtkObjectClass *) class; - item_class = (GnomeCanvasItemClass *) class; - - parent_class = gtk_type_class (gnome_canvas_group_get_type ()); - - gtk_object_add_arg_type ("GnomeMonthItem::year", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_YEAR); - gtk_object_add_arg_type ("GnomeMonthItem::month", GTK_TYPE_UINT, GTK_ARG_READWRITE, ARG_MONTH); - gtk_object_add_arg_type ("GnomeMonthItem::x", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_X); - gtk_object_add_arg_type ("GnomeMonthItem::y", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_Y); - gtk_object_add_arg_type ("GnomeMonthItem::width", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_WIDTH); - gtk_object_add_arg_type ("GnomeMonthItem::height", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEIGHT); - gtk_object_add_arg_type ("GnomeMonthItem::anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::heading_padding", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEAD_PADDING); - gtk_object_add_arg_type ("GnomeMonthItem::day_padding", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_DAY_PADDING); - gtk_object_add_arg_type ("GnomeMonthItem::day_names", GTK_TYPE_POINTER, GTK_ARG_WRITABLE, ARG_DAY_NAMES); - gtk_object_add_arg_type ("GnomeMonthItem::heading_height", GTK_TYPE_DOUBLE, GTK_ARG_READWRITE, ARG_HEADING_HEIGHT); - gtk_object_add_arg_type ("GnomeMonthItem::heading_anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_HEADING_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_anchor", GTK_TYPE_ANCHOR_TYPE, GTK_ARG_READWRITE, ARG_DAY_ANCHOR); - gtk_object_add_arg_type ("GnomeMonthItem::start_on_monday", GTK_TYPE_BOOL, GTK_ARG_READWRITE, ARG_START_ON_MONDAY); - gtk_object_add_arg_type ("GnomeMonthItem::heading_font", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_FONT); - gtk_object_add_arg_type ("GnomeMonthItem::heading_font_gdk", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_HEAD_FONT_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_font", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_FONT); - gtk_object_add_arg_type ("GnomeMonthItem::day_font_gdk", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_DAY_FONT_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::heading_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::heading_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_HEAD_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::outline_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_OUTLINE_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::outline_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_OUTLINE_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_box_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_BOX_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_box_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_BOX_COLOR_GDK); - gtk_object_add_arg_type ("GnomeMonthItem::day_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_COLOR); - gtk_object_add_arg_type ("GnomeMonthItem::day_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_COLOR_GDK); - - object_class->destroy = gnome_month_item_destroy; - object_class->set_arg = gnome_month_item_set_arg; - object_class->get_arg = gnome_month_item_get_arg; -} - -/* Calculates the minimum heading height based on the heading font size and padding. It also - * calculates the minimum width of the month item based on the width of the headings. - */ -static void -check_heading_sizes (GnomeMonthItem *mitem) -{ - double m_height; - double m_width; - int width; - int max_width; - int i; - - /* Calculate minimum height */ - - m_height = mitem->head_font->ascent + mitem->head_font->descent + 2 * mitem->head_padding; - - if (mitem->head_height < m_height) - mitem->head_height = m_height; - - /* Go through each heading and remember the widest one */ - - max_width = 0; - - for (i = 0; i < 7; i++) { - width = gdk_string_width (mitem->head_font, mitem->day_names[i]); - if (max_width < width) - max_width = width; - } - - m_width = 7 * (max_width + 2 * mitem->head_padding); - - if (mitem->width < m_width) - mitem->width = m_width; -} - -/* Calculates the minimum width and height of the month item based on the day font size and padding. - * Assumes that the minimum heading height has already been computed. - */ -static void -check_day_sizes (GnomeMonthItem *mitem) -{ - double m_height; - double m_width; - int width; - int max_width; - char buf[100]; - int i; - - /* Calculate minimum height */ - - m_height = mitem->head_height + 6 * (mitem->day_font->ascent + mitem->day_font->descent + 2 * mitem->day_padding); - - if (mitem->height < m_height) - mitem->height = m_height; - - /* Calculate minimum width */ - - max_width = 0; - - for (i = 1; i < 32; i++) { - sprintf (buf, "%d", i); - width = gdk_string_width (mitem->day_font, buf); - if (max_width < width) - max_width = width; - } - - m_width = 7 * (max_width + 2 * mitem->day_padding); - - if (mitem->width < m_width) - mitem->width = m_width; -} - -/* Calculates the minimum size of the month item based on the font sizes and paddings. If the - * current size of the month item is smaller than the required minimum size, this function will - * change the size to the appropriate values. - */ -static void -check_sizes (GnomeMonthItem *mitem) -{ - check_heading_sizes (mitem); - check_day_sizes (mitem); -} - -/* Recalculates the position of the toplevel calendar group based on the logical position and anchor */ -static void -reanchor (GnomeMonthItem *mitem) -{ - double x, y; - - x = mitem->x; - y = mitem->y; - - switch (mitem->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - x -= mitem->width / 2; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - x -= mitem->width; - break; - } - - switch (mitem->anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - y -= mitem->height / 2; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - y -= mitem->height; - break; - } - - /* Explicitly use the canvas group class prefix since the month item class has x and y - * arguments as well. - */ - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "GnomeCanvasGroup::x", x, - "GnomeCanvasGroup::y", y, - NULL); -} - -/* Takes an anchor specification and the corners of a rectangle, and returns an anchored point with - * respect to that rectangle. - */ -static void -get_label_anchor (GtkAnchorType anchor, double x1, double y1, double x2, double y2, double *x, double *y) -{ - switch (anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_W: - case GTK_ANCHOR_SW: - *x = x1; - break; - - case GTK_ANCHOR_N: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_S: - *x = (x1 + x2) / 2.0; - break; - - case GTK_ANCHOR_NE: - case GTK_ANCHOR_E: - case GTK_ANCHOR_SE: - *x = x2; - break; - } - - switch (anchor) { - case GTK_ANCHOR_NW: - case GTK_ANCHOR_N: - case GTK_ANCHOR_NE: - *y = y1; - break; - - case GTK_ANCHOR_W: - case GTK_ANCHOR_CENTER: - case GTK_ANCHOR_E: - *y = (y1 + y2) / 2.0; - break; - - case GTK_ANCHOR_SW: - case GTK_ANCHOR_S: - case GTK_ANCHOR_SE: - *y = y2; - break; - } -} - -/* Resets the position of the day name headings in the calendar */ -static void -reshape_headings (GnomeMonthItem *mitem) -{ - double width; - int i; - double x, y; - - width = mitem->width / 7; - - for (i = 0; i < 7; i++) { - /* Group */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i], - "x", width * i, - "y", 0.0, - NULL); - - /* Box */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i], - "x1", 0.0, - "y1", 0.0, - "x2", width, - "y2", mitem->head_height, - NULL); - - /* Label */ - get_label_anchor (mitem->head_anchor, - mitem->head_padding, - mitem->head_padding, - width - mitem->head_padding, - mitem->head_height - mitem->head_padding, - &x, &y); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "x", x, - "y", y, - "anchor", mitem->head_anchor, - NULL); - } -} - -/* Resets the position of the days in the calendar */ -static void -reshape_days (GnomeMonthItem *mitem) -{ - double width, height; - double x, y; - int row, col; - int i; - - width = mitem->width / 7; - height = (mitem->height - mitem->head_height) / 6; - - i = 0; - - for (row = 0; row < 6; row++) - for (col = 0; col < 7; col++) { - /* Group */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i], - "x", width * col, - "y", mitem->head_height + height * row, - NULL); - - /* Box */ - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i], - "x1", 0.0, - "y1", 0.0, - "x2", width, - "y2", height, - NULL); - - /* Label */ - get_label_anchor (mitem->day_anchor, - mitem->day_padding, - mitem->day_padding, - width - mitem->day_padding, - height - mitem->day_padding, - &x, &y); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "x", x, - "y", y, - "anchor", mitem->day_anchor, - NULL); - - i++; - } -} - -/* Changes the positions and resizes the items in the calendar to match the new size of the - * calendar. - */ -static void -reshape (GnomeMonthItem *mitem) -{ - check_sizes (mitem); - reanchor (mitem); - reshape_headings (mitem); - reshape_days (mitem); -} - -/* Sets the font for all the day headings */ -static void -set_head_font (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 7; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "font_gdk", mitem->head_font, - NULL); -} - -/* Sets the color for all the headings */ -static void -set_head_color (GnomeMonthItem *mitem) -{ - int i; - GdkColor outline; - GdkColor head; - - outline.pixel = mitem->outline_pixel; - head.pixel = mitem->head_pixel; - - for (i = 0; i < 7; i++) { - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i], - "fill_color_gdk", &outline, - NULL); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "fill_color_gdk", &head, - NULL); - } -} - -/* Creates the items for the day name headings */ -static void -create_headings (GnomeMonthItem *mitem) -{ - int i; - - /* Just create the items; they will be positioned and configured by a call to reshape() */ - - for (i = 0; i < 7; i++) { - /* Group */ - mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), - gnome_canvas_group_get_type (), - NULL); - - /* Box */ - mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), - gnome_canvas_rect_get_type (), - NULL); - - /* Label */ - mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]), - gnome_canvas_text_get_type (), - NULL); - } - - set_head_font (mitem); - set_head_color (mitem); -} - -/* Returns the number of leap years since year 1 up to (but not including) the specified year */ -static int -leap_years_up_to (int year) -{ - return (year / 4 /* trivial leapness */ - - ((year > 1700) ? (year / 100 - 17) : 0) /* minus centuries since 1700 */ - + ((year > 1600) ? ((year - 1600) / 400) : 0)); /* plus centuries since 1700 divisible by 400 */ -} - -/* Returns whether the specified year is a leap year */ -static int -is_leap_year (int year) -{ - if (year <= 1752) - return !(year % 4); - else - return (!(year % 4) && (year % 100)) || !(year % 400); -} - -/* Returns the 1-based day number within the year of the specified date */ -static int -day_in_year (int day, int month, int year) -{ - int is_leap, i; - - is_leap = is_leap_year (year); - - for (i = 0; i < month; i++) - day += days_in_month [is_leap][i]; - - return day; -} - -/* Returns the day of the week (zero-based, zero is Sunday) for the specified date. For the days - * that were removed on the Gregorian reformation, it returns Thursday. - */ -static int -day_in_week (int day, int month, int year) -{ - int n; - - n = (year - 1) * 365 + leap_years_up_to (year - 1) + day_in_year (day, month, year); - - if (n < REFORMATION_DAY) - return (n - 1 + SATURDAY) % 7; - - if (n >= (REFORMATION_DAY + MISSING_DAYS)) - return (n - 1 + SATURDAY - MISSING_DAYS) % 7; - - return THURSDAY; -} - -/* Fills the 42-element days array with the day numbers for the specified month. Slots outside the - * bounds of the month are filled with zeros. The starting and ending indexes of the days are - * returned in the start and end arguments. - */ -static void -build_month (int month, int year, int start_on_monday, int *days, int *start, int *end) -{ - int i; - int d_month, d_week; - - /* Note that months are zero-based, so September is month 8 */ - - if ((year == 1752) && (month == 8)) { - memcpy (days, sept_1752, 42 * sizeof (int)); - - if (start) - *start = SEPT_1752_START; - - if (end) - *end = SEPT_1752_END; - - return; - } - - for (i = 0; i < 42; i++) - days[i] = 0; - - d_month = days_in_month[is_leap_year (year)][month]; - d_week = day_in_week (1, month, year); - - if (start_on_monday) - d_week = (d_week + 6) % 7; - - for (i = 0; i < d_month; i++) - days[d_week + i] = i + 1; - - if (start) - *start = d_week; - - if (end) - *end = d_week + d_month - 1; -} - -/* Set the day numbers in the monthly calendar */ -static void -set_days (GnomeMonthItem *mitem) -{ - int i; - int start, end; - char buf[100]; - - build_month (mitem->month, mitem->year, mitem->start_on_monday, mitem->day_numbers, &start, &end); - - /* Clear days before start of month */ - - for (i = 0; i < start; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", NULL, - NULL); - - /* Set days of month */ - - for (; start <= end; start++, i++) { - sprintf (buf, "%d", mitem->day_numbers[start]); - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", buf, - NULL); - } - - /* Clear days after end of month */ - - for (; i < 42; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "text", NULL, - NULL); -} - -/* Sets the font for all the day numbers */ -static void -set_day_font (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 42; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "font_gdk", mitem->day_font, - NULL); -} - -/* Sets the color for all the day items */ -static void -set_day_color (GnomeMonthItem *mitem) -{ - int i; - GdkColor outline; - GdkColor day_box; - GdkColor day; - - outline.pixel = mitem->outline_pixel; - day_box.pixel = mitem->day_box_pixel; - day.pixel = mitem->day_pixel; - - for (i = 0; i < 42; i++) { - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i], - "outline_color_gdk", &outline, - "fill_color_gdk", &day_box, - NULL); - - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i], - "fill_color_gdk", &day, - NULL); - } -} - -/* Creates the items for the days */ -static void -create_days (GnomeMonthItem *mitem) -{ - int i; - - /* Just create the items; they will be positioned and configured by a call to reshape() */ - - for (i = 0; i < 42; i++) { - /* Group */ - mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem), - gnome_canvas_group_get_type (), - NULL); - - /* Box */ - mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), - gnome_canvas_rect_get_type (), - NULL); - - /* Label */ - mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i] = - gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]), - gnome_canvas_text_get_type (), - NULL); - } - - set_day_font (mitem); - set_day_color (mitem); - set_days (mitem); -} - -/* Resets the text of the day name headings */ -static void -set_day_names (GnomeMonthItem *mitem) -{ - int i; - - for (i = 0; i < 7; i++) - gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i], - "text", mitem->day_names[mitem->start_on_monday ? ((i + 1) % 7) : i], - NULL); -} - -/* Creates all the canvas items that make up the calendar */ -static void -create_items (GnomeMonthItem *mitem) -{ - mitem->items = g_new (GnomeCanvasItem *, GNOME_MONTH_ITEM_LAST); - - create_headings (mitem); - create_days (mitem); - - /* Initialize by default to three-letter day names */ - - mitem->day_names[0] = g_strdup (_("Sun")); - mitem->day_names[1] = g_strdup (_("Mon")); - mitem->day_names[2] = g_strdup (_("Tue")); - mitem->day_names[3] = g_strdup (_("Wed")); - mitem->day_names[4] = g_strdup (_("Thu")); - mitem->day_names[5] = g_strdup (_("Fri")); - mitem->day_names[6] = g_strdup (_("Sat")); - - set_day_names (mitem); - reshape (mitem); -} - -static void -gnome_month_item_init (GnomeMonthItem *mitem) -{ - time_t t; - struct tm *tm; - - /* Initialize to the current month by default */ - - t = time (NULL); - tm = localtime (&t); - - mitem->year = tm->tm_year + 1900; - mitem->month = tm->tm_mon; - - mitem->x = 0.0; - mitem->y = 0.0; - mitem->width = 150.0; /* not unreasonable defaults, I hope */ - mitem->height = 100.0; - mitem->anchor = GTK_ANCHOR_NW; - mitem->head_padding = 0.0; - mitem->day_padding = 2.0; - mitem->head_height = 14.0; - mitem->head_anchor = GTK_ANCHOR_CENTER; - mitem->day_anchor = GTK_ANCHOR_CENTER; - - /* Load the default fonts */ - - mitem->head_font = gdk_font_load (DEFAULT_FONT); - if (!mitem->head_font) { - mitem->head_font = gdk_font_load ("fixed"); - g_assert (mitem->head_font != NULL); - } - - mitem->day_font = gdk_font_load (DEFAULT_FONT); - if (!mitem->day_font) { - mitem->day_font = gdk_font_load ("fixed"); - g_assert (mitem->day_font != NULL); - } -} - -GnomeCanvasItem * -gnome_month_item_new (GnomeCanvasGroup *parent) -{ - GnomeMonthItem *mitem; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CANVAS_GROUP (parent), NULL); - - mitem = GNOME_MONTH_ITEM (gnome_canvas_item_new (parent, - gnome_month_item_get_type (), - NULL)); - - gnome_month_item_construct (mitem); - - return GNOME_CANVAS_ITEM (mitem); -} - -void -gnome_month_item_construct (GnomeMonthItem *mitem) -{ - GdkColor color; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - - gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "#d6d6d6d6d6d6", &color); - mitem->head_pixel = color.pixel; - mitem->day_box_pixel = color.pixel; - - gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "black", &color); - mitem->outline_pixel = color.pixel; - mitem->day_pixel = color.pixel; - - create_items (mitem); -} - -static void -free_day_names (GnomeMonthItem *mitem) -{ - int i; - - if (mitem->day_names[0]) - for (i = 0; i < 7; i++) - g_free (mitem->day_names[i]); -} - -static void -gnome_month_item_destroy (GtkObject *object) -{ - GnomeMonthItem *mitem; - - g_return_if_fail (object != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (object)); - - mitem = GNOME_MONTH_ITEM (object); - - free_day_names (mitem); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -/* Sets the color of the specified pixel value to that of the specified argument, which must be in - * GdkColor format if format is TRUE, otherwise it must be in string format. - */ -static void -set_color_arg (GnomeMonthItem *mitem, gulong *pixel, GtkArg *arg, int gdk_format, int set_head, int set_day) -{ - GdkColor color; - - if (gdk_format) - *pixel = ((GdkColor *) GTK_VALUE_BOXED (*arg))->pixel; - else { - if (gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, GTK_VALUE_STRING (*arg), &color)) - *pixel = color.pixel; - else - *pixel = 0; - } - - if (set_head) - set_head_color (mitem); - - if (set_day) - set_day_color (mitem); -} - -static void -gnome_month_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeMonthItem *mitem; - char **day_names; - int i; - - mitem = GNOME_MONTH_ITEM (object); - - switch (arg_id) { - case ARG_YEAR: - mitem->year = GTK_VALUE_UINT (*arg); - set_days (mitem); - break; - - case ARG_MONTH: - mitem->month = GTK_VALUE_UINT (*arg); - set_days (mitem); - break; - - case ARG_X: - mitem->x = GTK_VALUE_DOUBLE (*arg); - reanchor (mitem); - break; - - case ARG_Y: - mitem->y = GTK_VALUE_DOUBLE (*arg); - reanchor (mitem); - break; - - case ARG_WIDTH: - mitem->width = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_HEIGHT: - mitem->height = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_ANCHOR: - mitem->anchor = GTK_VALUE_ENUM (*arg); - reanchor (mitem); - break; - - case ARG_HEAD_PADDING: - mitem->head_padding = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_DAY_PADDING: - mitem->day_padding = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_DAY_NAMES: - day_names = GTK_VALUE_POINTER (*arg); - - /* First, check that none of the names is null */ - - for (i = 0; i < 7; i++) - if (!day_names[i]) { - g_warning ("Day number %d was NULL; day names cannot be NULL!", i); - return; - } - - /* Set the new names */ - - free_day_names (mitem); - for (i = 0; i < 7; i++) - mitem->day_names[i] = g_strdup (day_names[i]); - - set_day_names (mitem); - reshape (mitem); - break; - - case ARG_HEADING_HEIGHT: - mitem->head_height = fabs (GTK_VALUE_DOUBLE (*arg)); - reshape (mitem); - break; - - case ARG_HEADING_ANCHOR: - mitem->head_anchor = GTK_VALUE_ENUM (*arg); - reshape (mitem); - break; - - case ARG_DAY_ANCHOR: - mitem->day_anchor = GTK_VALUE_ENUM (*arg); - reshape (mitem); - break; - - case ARG_START_ON_MONDAY: - mitem->start_on_monday = GTK_VALUE_BOOL (*arg); - set_day_names (mitem); - set_days (mitem); - break; - - case ARG_HEAD_FONT: - gdk_font_unref (mitem->head_font); - - mitem->head_font = gdk_font_load (GTK_VALUE_STRING (*arg)); - if (!mitem->head_font) { - mitem->head_font = gdk_font_load ("fixed"); - g_assert (mitem->head_font != NULL); - } - - set_head_font (mitem); - reshape (mitem); - break; - - case ARG_HEAD_FONT_GDK: - gdk_font_unref (mitem->head_font); - - mitem->head_font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (mitem->head_font); - set_head_font (mitem); - reshape (mitem); - break; - - case ARG_DAY_FONT: - gdk_font_unref (mitem->day_font); - - mitem->day_font = gdk_font_load (GTK_VALUE_STRING (*arg)); - if (!mitem->day_font) { - mitem->day_font = gdk_font_load ("fixed"); - g_assert (mitem->day_font != NULL); - } - - set_day_font (mitem); - reshape (mitem); - break; - - case ARG_DAY_FONT_GDK: - gdk_font_unref (mitem->day_font); - - mitem->day_font = GTK_VALUE_BOXED (*arg); - gdk_font_ref (mitem->day_font); - set_day_font (mitem); - reshape (mitem); - break; - - case ARG_HEAD_COLOR: - set_color_arg (mitem, &mitem->head_pixel, arg, FALSE, TRUE, FALSE); - break; - - case ARG_HEAD_COLOR_GDK: - set_color_arg (mitem, &mitem->head_pixel, arg, TRUE, TRUE, FALSE); - break; - - case ARG_OUTLINE_COLOR: - set_color_arg (mitem, &mitem->outline_pixel, arg, FALSE, TRUE, TRUE); - break; - - case ARG_OUTLINE_COLOR_GDK: - set_color_arg (mitem, &mitem->outline_pixel, arg, TRUE, TRUE, TRUE); - break; - - case ARG_DAY_BOX_COLOR: - set_color_arg (mitem, &mitem->day_box_pixel, arg, FALSE, FALSE, TRUE); - break; - - case ARG_DAY_BOX_COLOR_GDK: - set_color_arg (mitem, &mitem->day_box_pixel, arg, TRUE, FALSE, TRUE); - break; - - case ARG_DAY_COLOR: - set_color_arg (mitem, &mitem->day_pixel, arg, FALSE, FALSE, TRUE); - break; - - case ARG_DAY_COLOR_GDK: - set_color_arg (mitem, &mitem->day_pixel, arg, TRUE, FALSE, TRUE); - break; - - default: - break; - } -} - -/* Allocates a GdkColor structure filled with the specified pixel, and puts it into the specified - * arg for returning it in the get_arg method. - */ -static void -get_color_arg (GnomeMonthItem *mitem, gulong pixel, GtkArg *arg) -{ - GdkColor *color; - - color = g_new (GdkColor, 1); - color->pixel = pixel; - gdk_color_context_query_color (GNOME_CANVAS_ITEM (mitem)->canvas->cc, color); - GTK_VALUE_BOXED (*arg) = color; -} - -static void -gnome_month_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - GnomeMonthItem *mitem; - - mitem = GNOME_MONTH_ITEM (object); - - switch (arg_id) { - case ARG_YEAR: - GTK_VALUE_UINT (*arg) = mitem->year; - break; - - case ARG_MONTH: - GTK_VALUE_UINT (*arg) = mitem->month; - break; - - case ARG_X: - GTK_VALUE_DOUBLE (*arg) = mitem->x; - break; - - case ARG_Y: - GTK_VALUE_DOUBLE (*arg) = mitem->y; - break; - - case ARG_WIDTH: - GTK_VALUE_DOUBLE (*arg) = mitem->width; - break; - - case ARG_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = mitem->height; - break; - - case ARG_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->anchor; - break; - - case ARG_HEAD_PADDING: - GTK_VALUE_DOUBLE (*arg) = mitem->head_padding; - break; - - case ARG_DAY_PADDING: - GTK_VALUE_DOUBLE (*arg) = mitem->day_padding; - break; - - case ARG_HEADING_HEIGHT: - GTK_VALUE_DOUBLE (*arg) = mitem->head_height; - break; - - case ARG_HEADING_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->head_anchor; - break; - - case ARG_DAY_ANCHOR: - GTK_VALUE_ENUM (*arg) = mitem->day_anchor; - break; - - case ARG_START_ON_MONDAY: - GTK_VALUE_BOOL (*arg) = mitem->start_on_monday; - break; - - case ARG_HEAD_FONT_GDK: - GTK_VALUE_BOXED (*arg) = mitem->head_font; - break; - - case ARG_DAY_FONT_GDK: - GTK_VALUE_BOXED (*arg) = mitem->day_font; - break; - - case ARG_HEAD_COLOR_GDK: - get_color_arg (mitem, mitem->head_pixel, arg); - break; - - case ARG_OUTLINE_COLOR_GDK: - get_color_arg (mitem, mitem->outline_pixel, arg); - break; - - case ARG_DAY_BOX_COLOR_GDK: - get_color_arg (mitem, mitem->day_box_pixel, arg); - break; - - case ARG_DAY_COLOR_GDK: - get_color_arg (mitem, mitem->day_pixel, arg); - break; - - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} - -GnomeCanvasItem * -gnome_month_item_num2child (GnomeMonthItem *mitem, int child_num) -{ - g_return_val_if_fail (mitem != NULL, NULL); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), NULL); - - return mitem->items[child_num]; -} - -int -gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child) -{ - int i; - - g_return_val_if_fail (mitem != NULL, -1); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); - g_return_val_if_fail (child != NULL, -1); - g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (child), -1); - - for (i = 0; i < GNOME_MONTH_ITEM_LAST; i++) - if (mitem->items[i] == child) - return i; - - return -1; -} - -int -gnome_month_item_num2day (GnomeMonthItem *mitem, int child_num) -{ - g_return_val_if_fail (mitem != NULL, 0); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), 0); - - if ((child_num >= GNOME_MONTH_ITEM_DAY_GROUP) && (child_num < GNOME_MONTH_ITEM_LAST)) { - child_num = (child_num - GNOME_MONTH_ITEM_DAY_GROUP) % 42; - return mitem->day_numbers[child_num]; - } else - return 0; -} - -int -gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num) -{ - int i; - - g_return_val_if_fail (mitem != NULL, -1); - g_return_val_if_fail (GNOME_IS_MONTH_ITEM (mitem), -1); - g_return_val_if_fail (day_num >= 1, -1); - - /* Find first day of month */ - - for (i = 0; mitem->day_numbers[i] == 0; i++) - ; - - /* Find the specified day */ - - for (; (mitem->day_numbers[i] != 0) && (i < 42); i++) - if (mitem->day_numbers[i] == day_num) - return i; - - /* Bail out */ - - return -1; -} diff --git a/calendar/gui/gnome-month-item.h b/calendar/gui/gnome-month-item.h deleted file mode 100644 index 51487b1fc7..0000000000 --- a/calendar/gui/gnome-month-item.h +++ /dev/null @@ -1,163 +0,0 @@ -/* General-purpose monthly calendar canvas item for GNOME - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef GNOME_MONTH_ITEM_H -#define GNOME_MONTH_ITEM_H - -#include <libgnome/gnome-defs.h> -#include <gtk/gtkpacker.h> /* why the hell is GtkAnchorType here and not in gtkenums.h? */ -#include <libgnomeui/gnome-canvas.h> - - -BEGIN_GNOME_DECLS - - -/* These values are used to identify the canvas items that make up a complete GnomeMonthItem, which - * is made up of the following "pieces": - * - * Headings line: - * - 7 GnomeCanvasGroups: - * Each group contains one box (GnomeCanvasRectangle) and one label - * (GnomeCanvasText) - * - * Day slots: - * - 42 GnomeCanvasGroups: - * Each group contains one box (GnomeCanvasRectangle) and one label - * (GnomeCanvasText) - * - * The headings are organized from left to right. The day slots are organized as a table in - * row-major order. - * - * If you want to access the individual items of the GnomeMonthItem, you can use these numbers with - * the gnome_month_item_num2child() function. If you want to convert a number into the - * corresponding GnomeCanvasItem, you can use the gnome_month_item_child2num() function. - */ -typedef enum { - GNOME_MONTH_ITEM_HEAD_GROUP = 0, /* 7 groups for headings */ - GNOME_MONTH_ITEM_HEAD_BOX = 7, /* 7 boxes for headings */ - GNOME_MONTH_ITEM_HEAD_LABEL = 14, /* 7 labels for headings */ - GNOME_MONTH_ITEM_DAY_GROUP = 21, /* 42 groups for days */ - GNOME_MONTH_ITEM_DAY_BOX = 63, /* 42 boxes for days */ - GNOME_MONTH_ITEM_DAY_LABEL = 105, /* 42 labels for days */ - GNOME_MONTH_ITEM_LAST = 147 /* total number of items */ -} GnomeMonthItemChild; - -/* The MonthItem canvas item defines a simple monthly calendar. It is made out of a number of - * canvas items, which can be accessed using the functions provided. The monthly calendar is - * anchored with respect to a point. The following arguments are available: - * - * name type read/write description - * ------------------------------------------------------------------------------------------ - * year uint RW Full year (1-9999) - * month uint RW Number of month (0-11) - * x double RW X position of anchor point - * y double RW Y position of anchor point - * width double RW Width of calendar in canvas units - * height double RW Height of calendar in canvas units - * anchor GtkAnchorType RW Anchor side for calendar - * heading_padding double RW Padding inside heading boxes - * day_padding double RW Padding inside day boxes - * day_names char ** W Array of strings corresponding to the day names (sun-sat) - * heading_height double RW Height of headings bar in canvas units - * heading_anchor GtkAnchorType RW Anchor side for headings inside heading boxes - * day_anchor GtkAnchorType RW Anchor side for day numbers inside day boxes - * start_on_monday boolean RW Specifies whether the week starts on Monday or Sunday - * heading_font string W X logical font descriptor for the headings - * heading_font_gdk GdkFont * RW Pointer to GdkFont for the headings - * day_font string W X logical font descriptor for the day numbers - * day_font_gdk GdkFont * RW Pointer to GdkFont for the day numbers - * heading_color string W X color specification for heading labels - * heading_color_gdk GdkColor * RW Pointer to an allocated GdkColor for heading labels - * outline_color string W X color specification for outline (lines and fill of heading boxes) - * outline_color_gdk GdkColor * RW Pointer to an allocated GdkColor for outline - * day_box_color string W X color specification for day boxes - * day_box_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day boxes - * day_color string W X color specification for day number labels - * day_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day number labels - */ - -#define GNOME_TYPE_MONTH_ITEM (gnome_month_item_get_type ()) -#define GNOME_MONTH_ITEM(obj) (GTK_CHECK_CAST ((obj), GNOME_TYPE_MONTH_ITEM, GnomeMonthItem)) -#define GNOME_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), GNOME_TYPE_MONTH_ITEM, GnomeMonthItemClass)) -#define GNOME_IS_MONTH_ITEM(obj) (GTK_CHECK_TYPE ((obj), GNOME_TYPE_MONTH_ITEM)) -#define GNOME_IS_MONTH_ITEM_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), GNOME_TYPE_MONTH_ITEM)) - - -typedef struct _GnomeMonthItem GnomeMonthItem; -typedef struct _GnomeMonthItemClass GnomeMonthItemClass; - -struct _GnomeMonthItem { - GnomeCanvasGroup group; - - int year; /* Year to show (full, no two-digit crap) */ - int month; /* Month to show (0-11) */ - - double x, y; /* Position at anchor */ - double width, height; /* Size of calendar */ - GtkAnchorType anchor; /* Anchor side for calendar */ - - double head_padding; /* Padding to use between heading lines and text */ - double day_padding; /* Padding to use between day number lines and text */ - - char *day_names[7]; /* Names to use for the day labels, starting from Sunday */ - - double head_height; /* Height of the headings row */ - GtkAnchorType head_anchor; /* Anchor side for the heading labels */ - GtkAnchorType day_anchor; /* Anchor side for the day number labels */ - - GnomeCanvasItem **items; /* All the items that make up the calendar */ - int day_numbers[42]; /* The numbers of the days, as they are shown in the display */ - - GdkFont *head_font; /* Font for the headings */ - GdkFont *day_font; /* Font for the day numbers */ - - gulong head_pixel; /* Color for heading labels */ - gulong outline_pixel; /* Color for the outline (lines and heading boxes) */ - gulong day_box_pixel; /* Color for the day boxes */ - gulong day_pixel; /* Color for day number labels */ - - int start_on_monday : 1; /* Start the week on Monday? If false, then start from Sunday */ -}; - -struct _GnomeMonthItemClass { - GnomeCanvasGroupClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType gnome_month_item_get_type (void); - -/* Creates a new month item with the specified group as parent */ -GnomeCanvasItem *gnome_month_item_new (GnomeCanvasGroup *parent); - -/* Constructor function useful for derived classes */ -void gnome_month_item_construct (GnomeMonthItem *mitem); - -/* Returns the child item defined by the child number (as specified on the GnomeMonthItemChild - * enumeration above). - */ -GnomeCanvasItem *gnome_month_item_num2child (GnomeMonthItem *mitem, int child_num); - -/* Returns the number of the specified child item, as defined on the GnomeMonthItemChild enumeration - * above. If the specified object is not found, it returns -1. - */ -int gnome_month_item_child2num (GnomeMonthItem *mitem, GnomeCanvasItem *child); - -/* Returns the number of the day relevant to the specified child item. Day numbers are 1-based. If - * the specified child is outside the range of displayed days, then it returns 0. - */ -int gnome_month_item_num2day (GnomeMonthItem *mitem, int child_num); - -/* Returns the index (0-41) of the specified date within the table of days. If the day number is - * invalid for the current monthly calendar, then -1 is returned. - */ -int gnome_month_item_day2index (GnomeMonthItem *mitem, int day_num); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c deleted file mode 100644 index 0dd0a3f22e..0000000000 --- a/calendar/gui/goto.c +++ /dev/null @@ -1,323 +0,0 @@ -/* Go to date dialog for gnomecal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gnome.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" -#include "main.h" -#include "mark.h" -#include "timeutil.h" - - -static GtkWidget *goto_win; /* The goto dialog window */ -static GnomeMonthItem *month_item; /* The month item in the dialog */ -static GnomeCalendar *gnome_calendar; /* The gnome calendar the dialog refers to */ -static int current_index; /* The index of the day marked as current, or -1 if none */ - - -/* Updates the specified month item by marking it appropriately from the calendar the dialog refers - * to. Also marks the current day if appropriate. - */ -static void -update (void) -{ - GnomeCanvasItem *item; - time_t t; - struct tm *tm; - - unmark_month_item (month_item); - mark_month_item (month_item, gnome_calendar->cal); - - if (current_index != -1) { - item = gnome_month_item_num2child (month_item, - GNOME_MONTH_ITEM_DAY_LABEL + current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "font", NORMAL_DAY_FONT, - NULL); - current_index = -1; - } - - t = time (NULL); - tm = localtime (&t); - - if (((tm->tm_year + 1900) == month_item->year) && (tm->tm_mon == month_item->month)) { - current_index = gnome_month_item_day2index (month_item, tm->tm_mday); - g_assert (current_index != -1); - - item = gnome_month_item_num2child (month_item, - GNOME_MONTH_ITEM_DAY_LABEL + current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "font", CURRENT_DAY_FONT, - NULL); - } -} - -/* Callback used when the year adjustment is changed */ -static void -year_changed (GtkAdjustment *adj, gpointer data) -{ - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "year", (int) adj->value, - NULL); - update (); -} - -/* Creates the year control with its adjustment */ -static GtkWidget * -create_year (int year) -{ - GtkWidget *hbox; - GtkAdjustment *adj; - GtkWidget *w; - - hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - - w = gtk_label_new (_("Year:")); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - adj = GTK_ADJUSTMENT (gtk_adjustment_new (year, 1900, 9999, 1, 10, 10)); - gtk_signal_connect (GTK_OBJECT (adj), "value_changed", - (GtkSignalFunc) year_changed, - NULL); - - w = gtk_spin_button_new (adj, 1.0, 0); - gtk_widget_set_usize (w, 60, 0); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - return hbox; -} - -/* Callback used when a month button is toggled */ -static void -month_toggled (GtkToggleButton *toggle, gpointer data) -{ - if (!toggle->active) - return; - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "month", GPOINTER_TO_INT (data), - NULL); - update (); -} - -/* Creates the months control */ -static GtkWidget * -create_months (int month) -{ - GtkWidget *table; - GtkWidget *w; - GSList *group; - int i, row, col; - struct tm tm; - char buf[100]; - - tm = *localtime (&gnome_calendar->current_display); - - table = gtk_table_new (2, 6, TRUE); - - group = NULL; - - for (i = 0; i < 12; i++) { - row = i / 6; - col = i % 6; - - tm.tm_mon = i; - strftime (buf, 100, "%b", &tm); - - w = gtk_radio_button_new (group); - group = gtk_radio_button_group (GTK_RADIO_BUTTON (w)); - gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (w), FALSE); - - gtk_container_add (GTK_CONTAINER (w), gtk_label_new (buf)); - - if (i == month) - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (w), TRUE); - - gtk_signal_connect (GTK_OBJECT (w), "toggled", - (GtkSignalFunc) month_toggled, - GINT_TO_POINTER (i)); - gtk_table_attach (GTK_TABLE (table), w, - col, col + 1, - row, row + 1, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - gtk_widget_show_all (w); - } - - return table; -} - -/* Sets the scrolling region of the canvas to the allocation size */ -static void -set_scroll_region (GtkWidget *widget, GtkAllocation *allocation) -{ - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - 1), - NULL); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, - allocation->width, allocation->height); -} - -/* Event handler for day groups in the month item. A button press makes the calendar jump to the - * selected day and destroys the Go-to dialog box. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - int child_num, day; - - child_num = gnome_month_item_child2num (month_item, item); - day = gnome_month_item_num2day (month_item, child_num); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((event->button.button == 1) && (day != 0)) { - gnome_calendar_goto (gnome_calendar, - time_from_day (month_item->year, month_item->month, day)); - gtk_widget_destroy (goto_win); - } - break; - - default: - break; - } - - return FALSE; -} - -/* Creates the canvas with the month item for selecting days */ -static GtkWidget * -create_days (int day, int month, int year) -{ - GtkWidget *canvas; - int i; - GnomeCanvasItem *day_group; - - canvas = gnome_canvas_new (); - gtk_widget_set_usize (canvas, 150, 120); - - month_item = GNOME_MONTH_ITEM (gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)))); - gnome_canvas_item_set (GNOME_CANVAS_ITEM (month_item), - "month", month, - "year", year, - "start_on_monday", week_starts_on_monday, - NULL); - colorify_month_item (month_item, default_color_func, NULL); - month_item_prepare_prelight (month_item, default_color_func, NULL); - update (); - - /* Connect to size_allocate so that we can change the size of the month item and the - * scrolling region appropriately. - */ - - gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate", - (GtkSignalFunc) set_scroll_region, - NULL); - - /* Bind the day groups to our event handler */ - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (month_item, i + GNOME_MONTH_ITEM_DAY_GROUP); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - NULL); - } - - return canvas; -} - -static void -goto_today (GtkWidget *widget, gpointer data) -{ - gnome_calendar_goto_today (gnome_calendar); - gtk_widget_destroy (goto_win); -} - -/* Creates a "goto date" dialog and runs it */ -void -goto_dialog (GnomeCalendar *gcal) -{ - GtkWidget *vbox; - GtkWidget *hbox; - GtkWidget *w; - GtkWidget *days; - struct tm *tm; - - gnome_calendar = gcal; - current_index = -1; - - tm = localtime (&gnome_calendar->current_display); - - goto_win = gnome_dialog_new (_("Go to date"), - GNOME_STOCK_BUTTON_CANCEL, - NULL); - gnome_dialog_set_parent (GNOME_DIALOG (goto_win), GTK_WINDOW (gcal)); - - vbox = GNOME_DIALOG (goto_win)->vbox; - - /* Instructions */ - - w = gtk_label_new (_("Please select the date you want to go to.\n" - "When you click on a day, you will be taken\n" - "to that date.")); - gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Create month item before creating the year controls, since the latter ones need the - * month_item to be created. - */ - - days = create_days (tm->tm_mday, tm->tm_mon, tm->tm_year + 1900); - - /* Year */ - - w = create_year (tm->tm_year + 1900); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Month */ - - w = create_months (tm->tm_mon); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Days (canvas with month item) */ - - gtk_box_pack_start (GTK_BOX (vbox), days, TRUE, TRUE, 0); - gtk_widget_show (days); - - /* Today button */ - - hbox = gtk_hbox_new (FALSE, 0); - gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0); - gtk_widget_show (hbox); - - w = gtk_button_new_with_label (_("Go to today")); - gtk_signal_connect (GTK_OBJECT (w), "clicked", - (GtkSignalFunc) goto_today, - NULL); - gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0); - gtk_widget_show (w); - - /* Run! */ - - gtk_window_set_modal (GTK_WINDOW (goto_win), TRUE); - gnome_dialog_set_close (GNOME_DIALOG (goto_win), TRUE); - gnome_dialog_set_parent (GNOME_DIALOG (goto_win), GTK_WINDOW (gnome_calendar)); - gtk_widget_show (goto_win); -} diff --git a/calendar/gui/icalendar-types b/calendar/gui/icalendar-types deleted file mode 100644 index e11f4c1789..0000000000 --- a/calendar/gui/icalendar-types +++ /dev/null @@ -1,39 +0,0 @@ -evento todo journal fbrequest fbreply busytime timezone - attach attach attach - attendee attendee attendee attendee attendee attendee - categories categories categories - class class class - comment comment comment comment comment comment comment - completed - contact contact contact - created created created created - description description description - dtstamp dtstamp - dtend/duration due->dtend dtend [duration] dtend dtend - dtstart dtstart dtstart dtstart dtstart dtstart dtstart - exdate exdate exdate - exrule exrule exrule - geo geo - last-mod last-mod last-mod last-mod last-mod - location location - organizer organizer organizer - percent - priority priority - rstatus rstatus rstatus rstatus - related related related - resources resources - rdate rdate rdate [rdate/rrule] - rrule rrule rrule - dtstamp dtstamp dtstamp dtstamp - seq seq seq seq seq - status status - summary summary summary - transp - uid uid uid uid uid - url url url url url - recurid recurid recurid - freebusy freebusy - tzname - tzoffset-to - tzoffset-from - diff --git a/calendar/gui/layout.c b/calendar/gui/layout.c deleted file mode 100644 index 1367ae3f8f..0000000000 --- a/calendar/gui/layout.c +++ /dev/null @@ -1,287 +0,0 @@ -/* Event layout engine for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <stdlib.h> -#include "layout.h" - - -/* This structure is used to pass around layout information among the internal layout functions */ -struct layout_info { - GList *events; /* List of events from client */ - int num_events; /* The number of events (length of the list) */ - LayoutQueryTimeFunc func; /* Function to convert a list item to a start/end time pair */ - int num_rows; /* Size of the time partition */ - time_t *partition; /* The time partition containing start and end time values */ - int *array; /* Working array of free and allocated time slots */ - int *allocations; /* Returned array of slot allocations */ - int *slots; /* Returned array of slots used */ - int num_slots; /* Number of slots used */ -}; - - -/* This defines the maximum number of events to overlap per row. More than that number of events - * will not be displayed. This is not ideal, so sue me. - */ -#define MAX_EVENTS_PER_ROW 32 - - -/* Compares two time_t values, used for qsort() */ -static int -compare_time_t (const void *a, const void *b) -{ - time_t ta, tb; - - ta = *((time_t *) a); - tb = *((time_t *) b); - - if (ta < tb) - return -1; - else if (ta > tb) - return 1; - else - return 0; -} - -/* Builds a partition of the time range occupied by the events in the list. It returns an array - * with the times that define the partition and the number of items in the partition. - */ -static void -build_partition (struct layout_info *li) -{ - time_t *rows, *p, *q; - GList *list; - int i, unique_vals; - - /* This is the maximum number of rows we would need */ - - li->num_rows = li->num_events * 2; - - /* Fill the rows with the times */ - - rows = g_new (time_t, li->num_rows); - - for (list = li->events, p = rows; list; list = list->next) { - (* li->func) (list, &p[0], &p[1]); - p += 2; - } - - /* Do a sort | uniq on the array */ - - qsort (rows, li->num_rows, sizeof (time_t), compare_time_t); - - p = rows; - q = rows + 1; - unique_vals = 1; - - for (i = 1; i < li->num_rows; i++, q++) - if (*q != *p) { - unique_vals++; - p++; - *p = *q; - } - - /* Return the number of unique values in the partition and the partition array itself */ - - li->num_rows = unique_vals; - li->partition = rows; -} - -/* Returns the index of the element in the partition that corresponds to the specified time */ -int -find_index (struct layout_info *li, time_t t) -{ - int i; - - for (i = 0; ; i++) - if (li->partition[i] == t) - return i; - - g_assert_not_reached (); -} - -#define xy(li, x, y) li->array[(y * MAX_EVENTS_PER_ROW) + (x)] - -/* Checks that all the cells in the slot array at the specified slot column are free to use by an - * event that has the specified range. - */ -static int -range_is_empty (struct layout_info *li, int slot, time_t start, time_t end) -{ - int i; - - for (i = find_index (li, start); li->partition[i] < end; i++) - if (xy (li, slot, i) != -1) - return FALSE; - - return TRUE; -} - -/* Allocates a time in the slot array for the specified event's index */ -static void -range_allocate (struct layout_info *li, int slot, time_t start, time_t end, int ev_num) -{ - int i; - - for (i = find_index (li, start); li->partition[i] < end; i++) - xy (li, slot, i) = ev_num; -} - -/* Performs the initial allocation of slots for events. Each event gets one column; they will be - * expanded in a later stage. Returns the number of columns used. - */ -static void -initial_allocate (struct layout_info *li) -{ - GList *events; - int i; - int slot; - int num_slots; - time_t start, end; - - num_slots = 0; - - for (i = 0, events = li->events; events; events = events->next, i++) { - (* li->func) (events, &start, &end); - - /* Start with no allocation, no columns */ - - li->allocations[i] = -1; - li->slots[i] = 0; - - /* Find a free column for the event */ - - for (slot = 0; slot < MAX_EVENTS_PER_ROW; slot++) - if (range_is_empty (li, slot, start, end)) { - range_allocate (li, slot, start, end, i); - - li->allocations[i] = slot; - li->slots[i] = 1; - - if ((slot + 1) > num_slots) - num_slots = slot + 1; - - break; - } - } - - li->num_slots = num_slots; -} - -/* Returns the maximum number of columns that an event can expanded by in the slot array */ -static int -columns_to_expand (struct layout_info *li, int ev_num, time_t start, time_t end) -{ - int cols; - int slot; - int i_start; - int i; - - cols = 0; - - i_start = find_index (li, start); - - for (slot = li->allocations[ev_num] + 1; slot < li->num_slots; slot++) { - for (i = i_start; li->partition[i] < end; i++) - if (xy (li, slot, i) != -1) - return cols; - - cols++; - } - - return cols; -} - -/* Expands an event by the specified number of columns */ -static void -do_expansion (struct layout_info *li, int ev_num, time_t start, time_t end, int num_cols) -{ - int i, j; - int slot; - - for (i = find_index (li, start); li->partition[i] < end; i++) { - slot = li->allocations[ev_num] + 1; - - for (j = 0; j < num_cols; j++) - xy (li, slot + j, i) = ev_num; - } -} - -/* Expands the events in the slot array to occupy as many columns as possible. This is the second - * pass of the layout algorithm. - */ -static void -expand_events (struct layout_info *li) -{ - GList *events; - time_t start, end; - int i; - int cols; - - for (i = 0, events = li->events; events; events = events->next, i++) { - (* li->func) (events, &start, &end); - - cols = columns_to_expand (li, i, start, end); - - if (cols == 0) - continue; /* We can't expand this event */ - - do_expansion (li, i, start, end, cols); - - li->slots[i] += cols; - } -} - -void -layout_events (GList *events, LayoutQueryTimeFunc func, int *num_slots, int **allocations, int **slots) -{ - struct layout_info li; - int i; - - g_return_if_fail (num_slots != NULL); - g_return_if_fail (allocations != NULL); - g_return_if_fail (slots != NULL); - - if (!events) { - *num_slots = 0; - *allocations = NULL; - *slots = NULL; - - return; - } - - li.events = events; - li.num_events = g_list_length (events); - li.func = func; - - /* Build the partition of the time range, and then build the array of slots */ - - build_partition (&li); - - li.array = g_new (int, li.num_rows * MAX_EVENTS_PER_ROW); - for (i = 0; i < (li.num_rows * MAX_EVENTS_PER_ROW); i++) - li.array[i] = -1; /* This is our 'empty' value */ - - /* Build the arrays for allocations and columns used */ - - li.allocations = g_new (int, li.num_events); - li.slots = g_new (int, li.num_events); - - /* Perform initial allocation and then expand the events to as many slots as they can occupy */ - - initial_allocate (&li); - expand_events (&li); - - /* Clean up and return values */ - - g_free (li.array); - - *num_slots = li.num_slots; - *allocations = li.allocations; - *slots = li.slots; -} diff --git a/calendar/gui/layout.h b/calendar/gui/layout.h deleted file mode 100644 index 734b720b8b..0000000000 --- a/calendar/gui/layout.h +++ /dev/null @@ -1,37 +0,0 @@ -/* Event layout engine for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef LAYOUT_H -#define LAYOUT_H - -#include <glib.h> -#include <time.h> - - -/* Functions of this type must translate the list item into two time_t values for the start and end - * of an event. - */ -typedef void (* LayoutQueryTimeFunc) (GList *event, time_t *start, time_t *end); - - -/* This is the main layout function for overlapping events. You pass in a list of (presumably) - * events and a function that should take a list element and return the start and end times for the - * event corresponding to that list element. - * - * It returns the number of slots ("columns") that you need to take into account when actually - * painting the events, the array of the first slot index that each event occupies, and the array of - * number of slots that each event occupies. You have to free both arrays. - * - * You will get somewhat better-looking results if the list of events is sorted by using the start - * time as the primary sort key and the end time as the secondary sort key -- so that "longer" - * events go first in the list. - */ -void layout_events (GList *events, LayoutQueryTimeFunc func, int *num_slots, int **allocations, int **slots); - - -#endif diff --git a/calendar/gui/main.c b/calendar/gui/main.c deleted file mode 100644 index 19cebcd8c8..0000000000 --- a/calendar/gui/main.c +++ /dev/null @@ -1,828 +0,0 @@ -/* - * Main file for the GNOME Calendar program - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: - * Miguel de Icaza (miguel@kernel.org) - * Federico Mena (federico@nuclecu.unam.mx) - */ - -#include <config.h> -#include <gnome.h> -#include <pwd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <string.h> -#include <ctype.h> -#include "calendar.h" -#include "alarm.h" -#include "eventedit.h" -#include "gnome-cal.h" -#include "main.h" -#include "timeutil.h" - - -#define COOKIE_USER_HOME_DIR ((char *) -1) - - -/* The username, used to set the `owner' field of the event */ -char *user_name; - -/* The full user name from the Gecos field */ -char *full_name; - -/* The user's default calendar file */ -char *user_calendar_file; - -/* a gnome-config string prefix that can be used to access the calendar config info */ -char *calendar_settings; - -/* Day begin, day end parameters */ -int day_begin, day_end; - -/* Whether weeks starts on Sunday or Monday */ -int week_starts_on_monday; - -/* If true, do not show our top level window */ -int startup_hidden = 0; - -/* The array of color properties -- keep in sync with the enumeration defined in main.h. The color - * values specified here are the defaults for the program. - */ -struct color_prop color_props[] = { - { 0x3e72, 0x35ec, 0x8ba2, "Outline:", "/calendar/Colors/outline" }, - { 0xffff, 0xffff, 0xffff, "Headings:", "/calendar/Colors/headings" }, - { 0xf26c, 0xecec, 0xbbe7, "Empty days:", "/calendar/Colors/empty_bg" }, - { 0xfc1e, 0xf87f, 0x5f80, "Appointments:", "/calendar/Colors/mark_bg" }, - { 0xd364, 0xc6b7, 0x7969, "Highlighted day:", "/calendar/Colors/prelight_bg" }, - { 0x01f0, 0x01f0, 0x01f0, "Day numbers:", "/calendar/Colors/day_fg" }, - { 0x0000, 0x0000, 0xffff, "Current day's number:", "/calendar/Colors/current_fg" } -}; - -/* Number of active calendars */ -int active_calendars = 0; - -/* A list of all of the calendars started */ -GList *all_calendars = NULL; - -static void new_calendar (char *full_name, char *calendar_file, char *geometry, char *view, gboolean hidden); - -/* For dumping part of a calendar */ -static time_t from_t, to_t; - -/* File to load instead of the user default's file */ -static char *load_file; - -/* If set, show events for the specified date and quit */ -static int show_events; - -static void -init_username (void) -{ - char *p; - struct passwd *passwd; - - passwd = getpwuid (getuid ()); - if ((p = passwd->pw_name)) { - char *comma; - - user_name = g_strdup (p); - full_name = g_strdup (passwd->pw_gecos); - - /* Keep only the name from the gecos field */ - if ((comma = strchr (full_name, ',')) != NULL) - *comma = 0; - } else { - if ((p = getenv ("USER"))) { - user_name = g_strdup (p); - full_name = g_strdup (p); - return; - } else { - user_name = g_strdup ("unknown"); - full_name = g_strdup ("unknown"); - } - } - endpwent (); -} - -static int -range_check_hour (int hour) -{ - if (hour < 0) - hour = 0; - else if (hour >= 24) - hour = 23; - - return hour; -} - -/* - * Initializes the calendar internal variables, loads defaults - */ -static void -init_calendar (void) -{ - int i; - char *cspec, *color; - char *str; - - init_username (); - user_calendar_file = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/user-cal.vcf"); - - gnome_config_push_prefix (calendar_settings); - - /* Read calendar settings */ - - day_begin = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day start=8")); - day_end = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day end=17")); - am_pm_flag = gnome_config_get_bool ("/calendar/Calendar/AM PM flag=0"); - week_starts_on_monday = gnome_config_get_bool ("/calendar/Calendar/Week starts on Monday=0"); - - if (day_end < day_begin){ - day_begin = 8; - day_end = 17; - } - - /* Read color settings */ - - for (i = 0; i < COLOR_PROP_LAST; i++) { - cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b); - str = g_strconcat (color_props[i].key, "=", cspec, NULL); - - color = gnome_config_get_string (str); - parse_color_spec (color, &color_props[i].r, &color_props[i].g, &color_props[i].b); - - g_free (str); - g_free (color); - } - - /* Done */ - - gnome_config_pop_prefix (); -} - -static void save_calendar_cmd (GtkWidget *widget, void *data); - -static void -about_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkWidget *about; - const gchar *authors[] = { - "Miguel de Icaza (miguel@kernel.org)", - "Federico Mena (federico@gimp.org)", - "Arturo Espinosa (arturo@nuclecu.unam.mx)", - NULL - }; - - about = gnome_about_new (_("Gnome Calendar"), VERSION, - "(C) 1998 the Free Software Foundation", - authors, - _("The GNOME personal calendar and schedule manager."), - NULL); - gtk_window_set_modal (GTK_WINDOW (about), TRUE); - gnome_dialog_set_close (GNOME_DIALOG (about), TRUE); - gtk_widget_show (about); -} - -static void -display_objedit (GtkWidget *widget, GnomeCalendar *gcal) -{ - GtkWidget *ee; - iCalObject *ico; - - /* Default to the day the user is looking at */ - ico = ical_new ("", user_name, ""); - ico->new = 1; - ico->dtstart = time_add_minutes (gcal->current_display, day_begin * 60); - ico->dtend = time_add_minutes (ico->dtstart, day_begin * 60 + 30 ); - - ee = event_editor_new (gcal, ico); - gtk_widget_show (ee); -} - -static void -display_objedit_today (GtkWidget *widget, GnomeCalendar *gcal) -{ - GtkWidget *ee; - - ee = event_editor_new (gcal, NULL); - gtk_widget_show (ee); -} - -static void -close_cmd (GtkWidget *widget, GnomeCalendar *gcal) -{ - all_calendars = g_list_remove (all_calendars, gcal); - if (gcal->cal->modified){ - if (!gcal->cal->filename) - save_calendar_cmd (widget, gcal); - else - calendar_save (gcal->cal, gcal->cal->filename); - } - - gtk_widget_destroy (GTK_WIDGET (gcal)); - active_calendars--; - - if (active_calendars == 0) - gtk_main_quit (); -} - -void -time_format_changed (void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_time_format_changed (GNOME_CALENDAR (l->data)); -} - -void -colors_changed (void) -{ - GList *l; - - for (l = all_calendars; l; l = l->next) - gnome_calendar_colors_changed (GNOME_CALENDAR (l->data)); -} - -static void -quit_cmd (void) -{ - while (all_calendars){ - GnomeCalendar *cal = GNOME_CALENDAR (all_calendars->data); - - close_cmd (GTK_WIDGET (cal), cal); - } -} - -/* Sets a clock cursor for the specified calendar window */ -static void -set_clock_cursor (GnomeCalendar *gcal) -{ - GdkCursor *cursor; - - cursor = gdk_cursor_new (GDK_WATCH); - gdk_window_set_cursor (GTK_WIDGET (gcal)->window, cursor); - gdk_cursor_destroy (cursor); - gdk_flush (); -} - -/* Resets the normal cursor for the specified calendar window */ -static void -set_normal_cursor (GnomeCalendar *gcal) -{ - gdk_window_set_cursor (GTK_WIDGET (gcal)->window, NULL); - gdk_flush (); -} - -static void -previous_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_previous (gcal); - set_normal_cursor (gcal); -} - -static void -next_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_next (gcal); - set_normal_cursor (gcal); -} - -static void -today_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - set_clock_cursor (gcal); - gnome_calendar_goto_today (gcal); - set_normal_cursor (gcal); -} - -static void -goto_clicked (GtkWidget *widget, GnomeCalendar *gcal) -{ - goto_dialog (gcal); -} - -static void -new_calendar_cmd (GtkWidget *widget, void *data) -{ - new_calendar (full_name, NULL, NULL, NULL, FALSE); -} - -static void -open_ok (GtkWidget *widget, GtkFileSelection *fs) -{ - /* FIXME: find out who owns this calendar and use that name */ - new_calendar ("Somebody", gtk_file_selection_get_filename (fs), NULL, NULL, FALSE); - - gtk_widget_destroy (GTK_WIDGET (fs)); -} - -static void -open_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkFileSelection *fs; - - fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Open calendar"))); - - gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", - (GtkSignalFunc) open_ok, - fs); - gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", - (GtkSignalFunc) gtk_widget_destroy, - GTK_OBJECT (fs)); - - gtk_widget_show (GTK_WIDGET (fs)); - gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me */ -} - -static void -save_ok (GtkWidget *widget, GtkFileSelection *fs) -{ - GnomeCalendar *gcal; - - gcal = GNOME_CALENDAR (gtk_object_get_user_data (GTK_OBJECT (fs))); - gtk_window_set_wmclass (GTK_WINDOW (gcal), "gnomecal", "gnomecal"); - - if (gcal->cal->filename) - g_free (gcal->cal->filename); - - gcal->cal->filename = g_strdup (gtk_file_selection_get_filename (fs)); - calendar_save (gcal->cal, gcal->cal->filename); - gtk_main_quit (); -} - -static gint -close_save (GtkWidget *w) -{ - gtk_main_quit (); - return TRUE; -} - -static void -save_as_calendar_cmd (GtkWidget *widget, void *data) -{ - GtkFileSelection *fs; - - fs = GTK_FILE_SELECTION (gtk_file_selection_new (_("Save calendar"))); - gtk_object_set_user_data (GTK_OBJECT (fs), data); - - gtk_signal_connect (GTK_OBJECT (fs->ok_button), "clicked", - (GtkSignalFunc) save_ok, - fs); - gtk_signal_connect_object (GTK_OBJECT (fs->cancel_button), "clicked", - (GtkSignalFunc) close_save, - GTK_OBJECT (fs)); - gtk_signal_connect_object (GTK_OBJECT (fs), "delete_event", - GTK_SIGNAL_FUNC (close_save), - GTK_OBJECT (fs)); - gtk_widget_show (GTK_WIDGET (fs)); - gtk_grab_add (GTK_WIDGET (fs)); /* Yes, it is modal, so sue me even more */ - gtk_main (); - gtk_widget_destroy (GTK_WIDGET (fs)); -} - -static void -properties_cmd (GtkWidget *widget, GtkWidget *gcal) -{ - properties (gcal); -} - -static void -save_calendar_cmd (GtkWidget *widget, void *data) -{ - GnomeCalendar *gcal = data; - - if (gcal->cal->filename){ - struct stat s; - - stat (gcal->cal->filename, &s); - - if (s.st_mtime != gcal->cal->file_time){ - GtkWidget *box; - char *str; - int b; - - str = g_strdup_printf ( - _("File %s has changed since it was loaded\nContinue?"), - gcal->cal->filename); - box = gnome_message_box_new (str, GNOME_MESSAGE_BOX_INFO, - GNOME_STOCK_BUTTON_YES, - GNOME_STOCK_BUTTON_NO, - NULL); - g_free (str); - gnome_dialog_set_default (GNOME_DIALOG (box), 1); - b = gnome_dialog_run (GNOME_DIALOG (box)); - gtk_object_destroy (GTK_OBJECT (box)); - - if (b != 0) - return; - } - - calendar_save (gcal->cal, gcal->cal->filename); - } else - save_as_calendar_cmd (widget, data); -} - -static GnomeUIInfo gnome_cal_file_menu [] = { - GNOMEUIINFO_MENU_NEW_ITEM(N_("_New calendar"), - N_("Create a new calendar"), - new_calendar_cmd, NULL), - - GNOMEUIINFO_MENU_OPEN_ITEM(open_calendar_cmd, NULL), - - GNOMEUIINFO_MENU_SAVE_ITEM(save_calendar_cmd, NULL), - - GNOMEUIINFO_MENU_SAVE_AS_ITEM(save_as_calendar_cmd, NULL), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_MENU_CLOSE_ITEM(close_cmd, NULL), - - GNOMEUIINFO_MENU_EXIT_ITEM(quit_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_edit_menu [] = { - { GNOME_APP_UI_ITEM, N_("_New appointment..."), - N_("Create a new appointment"), display_objedit, NULL, NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, - { GNOME_APP_UI_ITEM, N_("New appointment for _today..."), - N_("Create a new appointment for today"), - display_objedit_today, NULL, NULL, - GNOME_APP_PIXMAP_STOCK, GNOME_STOCK_MENU_NEW, 0, 0, NULL }, - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_help_menu [] = { - GNOMEUIINFO_HELP ("cal"), - - GNOMEUIINFO_MENU_ABOUT_ITEM(about_calendar_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_settings_menu [] = { - GNOMEUIINFO_MENU_PREFERENCES_ITEM(properties_cmd, NULL), - - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_cal_menu [] = { - GNOMEUIINFO_MENU_FILE_TREE(gnome_cal_file_menu), - GNOMEUIINFO_MENU_EDIT_TREE(gnome_cal_edit_menu), - GNOMEUIINFO_MENU_SETTINGS_TREE(gnome_cal_settings_menu), - GNOMEUIINFO_MENU_HELP_TREE(gnome_cal_help_menu), - GNOMEUIINFO_END -}; - -static GnomeUIInfo gnome_toolbar [] = { - GNOMEUIINFO_ITEM_STOCK (N_("New"), N_("Create a new appointment"), display_objedit, GNOME_STOCK_PIXMAP_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Prev"), N_("Go back in time"), previous_clicked, GNOME_STOCK_PIXMAP_BACK), - GNOMEUIINFO_ITEM_STOCK (N_("Today"), N_("Go to present time"), today_clicked, GNOME_STOCK_PIXMAP_HOME), - GNOMEUIINFO_ITEM_STOCK (N_("Next"), N_("Go forward in time"), next_clicked, GNOME_STOCK_PIXMAP_FORWARD), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Go to"), N_("Go to a specific date"), goto_clicked, GNOME_STOCK_PIXMAP_JUMP_TO), - - GNOMEUIINFO_END -}; - -static void -setup_menu (GtkWidget *gcal) -{ - gnome_app_create_menus_with_data (GNOME_APP (gcal), gnome_cal_menu, gcal); - gnome_app_create_toolbar_with_data (GNOME_APP (gcal), gnome_toolbar, gcal); - gnome_app_install_menu_hints(GNOME_APP(gcal), gnome_cal_menu); -} - -static void -setup_appbar (GtkWidget *gcal) -{ - GnomeAppBar *appbar; - - appbar = gnome_appbar_new (FALSE, TRUE, GNOME_PREFERENCES_USER); - gnome_app_set_statusbar (GNOME_APP (gcal), GTK_WIDGET(appbar)); -} - -static gint -calendar_close_event (GtkWidget *widget, GdkEvent *event, GnomeCalendar *gcal) -{ - close_cmd (widget, gcal); - return TRUE; -} - -static void -new_calendar (char *full_name, char *calendar_file, char *geometry, char *page, gboolean hidden) -{ - GtkWidget *toplevel; - char title[128]; - int xpos, ypos, width, height; - - /* i18n: This "%s%s" indicates possession. Languages where the order is - the inverse should translate it to "%2$s%1$s". */ - g_snprintf(title, 128, _("%s%s"), full_name, _("'s calendar")); - - toplevel = gnome_calendar_new (title); - - if (gnome_parse_geometry (geometry, &xpos, &ypos, &width, &height)){ - if (xpos != -1) - gtk_widget_set_uposition (toplevel, xpos, ypos); - if (width != -1) - gtk_widget_set_usize (toplevel, width, height); - } - setup_appbar (toplevel); - setup_menu (toplevel); - - - if (page) - gnome_calendar_set_view (GNOME_CALENDAR (toplevel), page); - - if (calendar_file && g_file_exists (calendar_file)) - gnome_calendar_load (GNOME_CALENDAR (toplevel), calendar_file); - else - GNOME_CALENDAR (toplevel)->cal->filename = g_strdup (calendar_file); - - gtk_signal_connect (GTK_OBJECT (toplevel), "delete_event", - GTK_SIGNAL_FUNC(calendar_close_event), toplevel); - - active_calendars++; - all_calendars = g_list_prepend (all_calendars, toplevel); - - if (hidden){ - GnomeWinState state; - - state = gnome_win_hints_get_state (toplevel); - - state |= WIN_STATE_MINIMIZED; - gnome_win_hints_set_state (toplevel, state); - } - - gtk_widget_show (toplevel); -} - -static void -process_dates (void) -{ - if (!from_t) - from_t = time_day_begin (time (NULL)); - - if (!to_t || to_t < from_t) - to_t = time_add_day (from_t, 1); -} - -enum { - GEOMETRY_KEY = -1, - USERFILE_KEY = -2, - VIEW_KEY = -3, - HIDDEN_KEY = -4, -}; - -/* Lists used to startup various GnomeCalendars */ -static GList *start_calendars; -static GList *start_geometries; -static GList *start_views; - -static int -same_day (struct tm *a, struct tm *b) -{ - return (a->tm_mday == b->tm_mday && - a->tm_mon == b->tm_mon && - a->tm_year == b->tm_year); -} - -static void -dump_events (void) -{ - Calendar *cal; - GList *l; - char *s; - time_t now = time (NULL); - struct tm today = *localtime (&now); - - process_dates (); - init_calendar (); - - cal = calendar_new (full_name); - s = calendar_load (cal, load_file ? load_file : user_calendar_file); - if (s){ - printf ("error: %s\n", s); - exit (1); - } - l = calendar_get_events_in_range (cal, from_t, to_t); - for (; l; l = l->next){ - char start [80], end [80]; - CalendarObject *co = l->data; - struct tm ts, te; - char *format; - - ts = *localtime (&co->ev_start); - te = *localtime (&co->ev_end); - - if (same_day (&today, &ts)) - format = "%H:%M"; - else - format = "%A %d, %H:%M"; - strftime (start, sizeof (start), format, &ts); - - if (!same_day (&ts, &te)) - format = "%A %d, %H:%M"; - strftime (end, sizeof (start), format, &te); - - printf ("%s -- %s\n", start, end); - printf (" %s\n", co->ico->summary); - } - calendar_destroy_event_list (l); - calendar_destroy (cal); - exit (0); -} - -extern time_t get_date (); - -static void -parse_an_arg (poptContext ctx, - enum poptCallbackReason reason, - const struct poptOption *opt, - char *arg, void *data) -{ - switch (opt->val){ - case 'f': - from_t = get_date (arg, NULL); - break; - - case 't': - to_t = get_date (arg, NULL); - break; - - case GEOMETRY_KEY: - start_geometries = g_list_append (start_geometries, arg); - break; - - case USERFILE_KEY: - /* This is a special key that tells the program to load - * the user's calendar file. This allows session management - * to work even if the User's home directory changes location - * (ie, on a networked setup). - */ - arg = COOKIE_USER_HOME_DIR; - /* fall through */ - - case VIEW_KEY: - start_views = g_list_append (start_views, arg); - break; - - case 'F': - start_calendars = g_list_append (start_calendars, arg); - break; - - case 'e': - show_events = 1; - break; - - case HIDDEN_KEY: - startup_hidden = 1; - break; - - default: - } -} - -static const struct poptOption options [] = { - { NULL, '\0', POPT_ARG_CALLBACK, parse_an_arg, 0, NULL, NULL }, - { "events", 'e', POPT_ARG_NONE, NULL, 'e', N_("Show events and quit"), - NULL }, - { "from", 'f', POPT_ARG_STRING, NULL, 'f', N_("Specifies start date [for --events]"), N_("DATE") }, - { "file", 'F', POPT_ARG_STRING, NULL, 'F', N_("File to load calendar from"), N_("FILE") }, - { "userfile", '\0', POPT_ARG_NONE, NULL, USERFILE_KEY, N_("Load the user calendar"), NULL }, - { "geometry", '\0', POPT_ARG_STRING, NULL, GEOMETRY_KEY, N_("Geometry for starting up"), N_("GEOMETRY") }, - { "view", '\0', POPT_ARG_STRING, NULL, VIEW_KEY, N_("The startup view mode"), N_("VIEW") }, - { "to", 't', POPT_ARG_STRING, NULL, 't', N_("Specifies ending date [for --events]"), N_("DATE") }, - { "hidden", 0, POPT_ARG_NONE, NULL, HIDDEN_KEY, N_("If used, starts in iconic mode"), NULL }, - { NULL, '\0', 0, NULL, 0} -}; - -static void -session_die (void) -{ - quit_cmd (); -} - -/* - * Save the session callback - */ -static int -session_save_state (GnomeClient *client, gint phase, GnomeRestartStyle save_style, gint shutdown, - GnomeInteractStyle interact_style, gint fast, gpointer client_data) -{ - char *sess_id; - char **argv = (char **) g_malloc (sizeof (char *) * ((active_calendars * 6) + 3)); - GList *l, *free_list = 0; - int i; - - sess_id = gnome_client_get_id (client); - - argv [0] = client_data; - for (i = 1, l = all_calendars; l; l = l->next){ - GnomeCalendar *gcal = GNOME_CALENDAR (l->data); - char *geometry; - - geometry = gnome_geometry_string (GTK_WIDGET (gcal)->window); - - if (strcmp (gcal->cal->filename, user_calendar_file) == 0) - argv [i++] = "--userfile"; - else { - argv [i++] = "--file"; - argv [i++] = gcal->cal->filename; - } - argv [i++] = "--geometry"; - argv [i++] = geometry; - argv [i++] = "--view"; - argv [i++] = gnome_calendar_get_current_view_name (gcal); - free_list = g_list_append (free_list, geometry); - calendar_save (gcal->cal, gcal->cal->filename); - } - argv [i] = NULL; - gnome_client_set_clone_command (client, i, argv); - gnome_client_set_restart_command (client, i, argv); - - for (l = free_list; l; l = l->next) - g_free (l->data); - g_list_free (free_list); - - return 1; -} - -int -main(int argc, char *argv[]) -{ - GnomeClient *client; - - bindtextdomain (PACKAGE, GNOMELOCALEDIR); - textdomain (PACKAGE); - - gnome_init_with_popt_table ("calendar", VERSION, argc, argv, - options, 0, NULL); - - if (show_events) - dump_events (); - - client = gnome_master_client (); - if (client){ - gtk_signal_connect (GTK_OBJECT (client), "save_yourself", - GTK_SIGNAL_FUNC (session_save_state), argv [0]); - gtk_signal_connect (GTK_OBJECT (client), "die", - GTK_SIGNAL_FUNC (session_die), NULL); - } - - process_dates (); - alarm_init (); - init_calendar (); - - /* - * Load all of the calendars specifies in the command line with - * the geometry specificied -if any- - */ - if (start_calendars){ - GList *p, *g, *v; - char *title; - - p = start_calendars; - g = start_geometries; - v = start_views; - while (p){ - char *file = p->data; - char *geometry = g ? g->data : NULL; - char *page_name = v ? v->data : NULL; - - if (file == COOKIE_USER_HOME_DIR) - file = user_calendar_file; - - if (strcmp (file, user_calendar_file) == 0) - title = full_name; - else - title = file; - new_calendar (title, file, geometry, page_name, startup_hidden); - - p = p->next; - if (g) - g = g->next; - if (v) - v = v->next; - } - g_list_free (p); - } else { - char *geometry = start_geometries ? start_geometries->data : NULL; - char *page_name = start_views ? start_views->data : NULL; - - new_calendar (full_name, user_calendar_file, geometry, page_name, startup_hidden); - } - gtk_main (); - return 0; -} diff --git a/calendar/gui/main.h b/calendar/gui/main.h deleted file mode 100644 index 615b372acf..0000000000 --- a/calendar/gui/main.h +++ /dev/null @@ -1,60 +0,0 @@ -#ifndef MAIN_H -#define MAIN_H - -/* Calendar preferences */ - -extern int day_begin, day_end; -extern char *user_name; -extern int am_pm_flag; -extern int week_starts_on_monday; - -/* This enum and the following array define the color preferences */ - -typedef enum { - COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */ - COLOR_PROP_HEADING_COLOR, /* Color for headings */ - COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */ - COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */ - COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */ - COLOR_PROP_DAY_FG, /* Color for day numbers */ - COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */ - COLOR_PROP_LAST /* Number of color properties */ -} ColorProp; - -struct color_prop { - int r; /* Values are in [0, 65535] */ - int g; - int b; - char *label; /* Label for properties dialog */ - char *key; /* Key for gnome_config */ -}; - -extern struct color_prop color_props[]; - -/* Creates and runs the preferences dialog box */ -void properties (GtkWidget *toplevel); - -/* Asks for all the time-related displays to be updated when the user changes the time format - * preferences. - */ -void time_format_changed (void); - -/* Asks for all the month items' colors to be reset */ -void colors_changed (void); - -/* Creates and runs the Go-to date dialog */ -void goto_dialog (GnomeCalendar *gcal); - -/* Returns a pointer to a statically-allocated string with a representation of the specified color. - * Values must be in [0, 65535]. - */ -char *build_color_spec (int r, int g, int b); - -/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */ -void parse_color_spec (char *spec, int *r, int *g, int *b); - -/* Calls build_color_spec() for the color in the specified property number */ -char *color_spec_from_prop (ColorProp propnum); - - -#endif diff --git a/calendar/gui/mark.c b/calendar/gui/mark.c deleted file mode 100644 index 2de8e2b880..0000000000 --- a/calendar/gui/mark.c +++ /dev/null @@ -1,269 +0,0 @@ -/* Functions to mark calendars - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include "gnome-cal.h" -#include "main.h" -#include "mark.h" -#include "timeutil.h" - - -/* Frees the specified data when an object is destroyed */ -static void -free_data (GtkObject *object, gpointer data) -{ - g_free (data); -} - -/* If the array of "marked" attributes for the days in a a month item has not been created yet, this - * function creates the array and clears it. Otherwise, it just returns the existing array. - */ -static char * -get_attributes (GnomeMonthItem *mitem) -{ - char *attrs; - - attrs = gtk_object_get_data (GTK_OBJECT (mitem), "day_mark_attributes"); - - if (!attrs) { - attrs = g_new0 (char, 42); - gtk_object_set_data (GTK_OBJECT (mitem), "day_mark_attributes", attrs); - gtk_signal_connect (GTK_OBJECT (mitem), "destroy", - (GtkSignalFunc) free_data, - attrs); - } - - return attrs; -} - -void -colorify_month_item (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data) -{ - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (func != NULL); - - unmark_month_item (mitem); - - /* We have to do this in several calls to gnome_canvas_item_set(), as color_spec_from_prop() - * returns a pointer to a static string -- and we need several values. - */ - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "heading_color", (* func) (COLOR_PROP_HEADING_COLOR, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "outline_color", (* func) (COLOR_PROP_OUTLINE_COLOR, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "day_box_color", (* func) (COLOR_PROP_EMPTY_DAY_BG, func_data), - NULL); - - gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem), - "day_color", (* func) (COLOR_PROP_DAY_FG, func_data), - NULL); -} - -/* 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. The array of day attributes is modified - * accordingly. - */ -static void -mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end) -{ - struct tm tm; - 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 */ - - mark_month_item_index (mitem, day_index, default_color_func, NULL); - - /* Next day */ - - tm.tm_mday++; - } -} - -void -mark_month_item (GnomeMonthItem *mitem, Calendar *cal) -{ - time_t month_begin, month_end; - GList *list, *l; - CalendarObject *co; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (cal != NULL); - - 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); -} - -void -mark_month_item_index (GnomeMonthItem *mitem, int index, GetColorFunc func, gpointer func_data) -{ - char *attrs; - GnomeCanvasItem *item; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail ((index >= 0) && (index < 42)); - g_return_if_fail (func != NULL); - - attrs = get_attributes (mitem); - - attrs[index] = TRUE; - - item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + index); - gnome_canvas_item_set (item, - "fill_color", (* func) (COLOR_PROP_MARK_DAY_BG, func_data), - NULL); -} - -void -unmark_month_item (GnomeMonthItem *mitem) -{ - int i; - char *attrs; - GnomeCanvasItem *item; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - - attrs = get_attributes (mitem); - - /* Find marked days and unmark them by turning off their marked attribute flag and changing - * the color. - */ - - for (i = 0; i < 42; i++) - if (attrs[i]) { - attrs[i] = FALSE; - - item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + i); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_EMPTY_DAY_BG), - NULL); - } -} - -/* Handles EnterNotify and LeaveNotify events from the month item's day groups, and performs - * appropriate prelighting. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - GnomeMonthItem *mitem; - GnomeCanvasItem *box; - int child_num, day; - GetColorFunc func; - gpointer func_data; - char *color; - char *attrs; - - /* We only accept enters and leaves */ - - if (!((event->type == GDK_ENTER_NOTIFY) || (event->type == GDK_LEAVE_NOTIFY))) - return FALSE; - - /* Get index information */ - - mitem = GNOME_MONTH_ITEM (data); - child_num = gnome_month_item_child2num (mitem, item); - day = gnome_month_item_num2day (mitem, child_num); - - if (day == 0) - return FALSE; /* it was a day outside the month's range */ - - child_num -= GNOME_MONTH_ITEM_DAY_GROUP; - box = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + child_num); - - /* Get colors */ - - func = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_func"); - func_data = gtk_object_get_data (GTK_OBJECT (mitem), "prelight_color_data"); - - /* Now actually set the proper color in the item */ - - switch (event->type) { - case GDK_ENTER_NOTIFY: - color = (* func) (COLOR_PROP_PRELIGHT_DAY_BG, func_data); - gnome_canvas_item_set (box, - "fill_color", color, - NULL); - break; - - case GDK_LEAVE_NOTIFY: - attrs = get_attributes (mitem); - color = (* func) (attrs[child_num] ? COLOR_PROP_MARK_DAY_BG : COLOR_PROP_EMPTY_DAY_BG, - func_data); - gnome_canvas_item_set (box, - "fill_color", color, - NULL); - break; - - default: - g_assert_not_reached (); - } - - return TRUE; -} - -void -month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data) -{ - GnomeCanvasItem *day_group; - int i; - - g_return_if_fail (mitem != NULL); - g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem)); - g_return_if_fail (func != NULL); - - /* Store the function in the object data */ - - gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_func", func); - gtk_object_set_data (GTK_OBJECT (mitem), "prelight_color_data", func_data); - - /* Connect the appropriate signals to perform prelighting */ - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - mitem); - } -} - -char * -default_color_func (ColorProp propnum, gpointer data) -{ - return color_spec_from_prop (propnum); -} diff --git a/calendar/gui/mark.h b/calendar/gui/mark.h deleted file mode 100644 index 18ec39b76b..0000000000 --- a/calendar/gui/mark.h +++ /dev/null @@ -1,57 +0,0 @@ -/* 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" - - -/* These are the fonts used for the montly calendars */ - -#define HEADING_FONT "-*-helvetica-bold-r-normal--14-*-*-*-p-*-*-*" -#define TITLE_FONT "-*-helvetica-bold-r-normal--12-*-*-*-p-*-*-*" -#define DAY_HEADING_FONT "-*-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" -#define NORMAL_DAY_FONT "-*-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" -#define CURRENT_DAY_FONT "-*-helvetica-bold-r-normal--12-*-*-*-p-*-*-*" -#define BIG_DAY_HEADING_FONT "-*-helvetica-bold-r-normal--14-*-*-*-p-*-*-*" -#define BIG_NORMAL_DAY_FONT "-*-helvetica-medium-r-normal--14-*-*-*-p-*-*-*" -#define BIG_CURRENT_DAY_FONT "-*-helvetica-bold-r-normal--14-*-*-*-p-*-*-*" - - -/* Functions of this type are used by the marking functions to fetch color specifications. Such - * a function must return a color spec based on the property passed to it. - */ -typedef char * (* GetColorFunc) (ColorProp propnum, gpointer data); - - -/* Sets the user-configured colors and font for a month item. It also tags the days as unmarked. */ -void colorify_month_item (GnomeMonthItem *month, GetColorFunc func, gpointer func_data); - -/* 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); - -/* Marks a day specified by index, not by day number */ -void mark_month_item_index (GnomeMonthItem *mitem, int index, GetColorFunc func, gpointer func_data); - -/* Unmarks all the days in the specified month item */ -void unmark_month_item (GnomeMonthItem *mitem); - -/* Prepares a monthly calendar item to prelight when the mouse goes over the days. */ - -void month_item_prepare_prelight (GnomeMonthItem *mitem, GetColorFunc func, gpointer func_data); - -/* This is the default prelight function you can use for most puposes. You can use NULL as the - * func_data. - */ -char *default_color_func (ColorProp prop_num, gpointer data); - - -#endif diff --git a/calendar/gui/month-view.c b/calendar/gui/month-view.c deleted file mode 100644 index 07a92578dd..0000000000 --- a/calendar/gui/month-view.c +++ /dev/null @@ -1,799 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <libgnomeui/gnome-canvas-text.h> -#include "eventedit.h" -#include "layout.h" -#include "month-view.h" -#include "main.h" -#include "mark.h" -#include "quick-view.h" -#include "timeutil.h" - - -/* Spacing between title and calendar */ -#define SPACING 4 - -/* Padding between day borders and event text */ -#define EVENT_PADDING 3 - -/* Font for the month view events */ -#define EVENT_FONT "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" - - -static void month_view_class_init (MonthViewClass *class); -static void month_view_init (MonthView *mv); -static void month_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void month_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvasClass *parent_class; - - -GtkType -month_view_get_type (void) -{ - static GtkType month_view_type = 0; - - if (!month_view_type) { - GtkTypeInfo month_view_info = { - "MonthView", - sizeof (MonthView), - sizeof (MonthViewClass), - (GtkClassInitFunc) month_view_class_init, - (GtkObjectInitFunc) month_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - month_view_type = gtk_type_unique (gnome_canvas_get_type (), &month_view_info); - } - - return month_view_type; -} - -static void -month_view_class_init (MonthViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - widget_class->size_request = month_view_size_request; - widget_class->size_allocate = month_view_size_allocate; -} - -/* Creates the quick view when a day is clicked in the month view */ -static void -do_quick_view_popup (MonthView *mv, GdkEventButton *event, int day) -{ - time_t day_begin_time, day_end_time; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_begin_time = time_from_day (mv->year, mv->month, day); - day_end_time = time_day_end (day_begin_time); - - list = calendar_get_events_in_range (mv->calendar->cal, day_begin_time, day_end_time); - - strftime (date_str, sizeof (date_str), "%a %b %d %Y", localtime (&day_begin_time)); - qv = quick_view_new (mv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - calendar_destroy_event_list (list); -} - -/* Callback used to destroy the popup menu when the month view is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Creates a new appointment in the current day */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (mv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - MonthView *mv; - time_t *t; - - mv = MONTH_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (mv->calendar, view_name); - gnome_calendar_goto (mv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_year (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "yearview"); -} - -static GnomeUIInfo mv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _year"), NULL, jump_to_year, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Creates the popup menu for the month view if it does not yet exist, and attaches it to the month - * view object so that it can be destroyed when appropriate. - */ -static GtkWidget * -get_popup_menu (MonthView *mv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (mv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (mv_popup_menu); - gtk_object_set_data (GTK_OBJECT (mv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (mv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Pops up the menu for the month view. */ -static void -do_popup_menu (MonthView *mv, GdkEventButton *event, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (mv); - - /* Enable or disable items as appropriate */ - - gtk_widget_set_sensitive (mv_popup_menu[0].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[2].widget, day != 0); - gtk_widget_set_sensitive (mv_popup_menu[3].widget, day != 0); - - if (day == 0) - day = 1; - - /* Store the time for the menu item callbacks to use */ - - t = time_from_day (mv->year, mv->month, day); - - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (mv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, mv); -} - -/* Event handler for day groups. When mouse button 1 is pressed, it will pop up a quick view with - * the events in that day. When mouse button 3 is pressed, it will pop up a menu. - */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - int child_num; - int day; - - mv = MONTH_VIEW (data); - - child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (mv->mitem), item); - day = gnome_month_item_num2day (GNOME_MONTH_ITEM (mv->mitem), child_num); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if ((event->button.button == 1) && (day != 0)) { - do_quick_view_popup (mv, (GdkEventButton *) event, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (mv, (GdkEventButton *) event, day); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Returns the index of the specified arrow in the array of arrows */ -static int -get_arrow_index (MonthView *mv, GnomeCanvasItem *arrow) -{ - int i; - - for (i = 0; i < 42; i++) - if (mv->up[i] == arrow) - return i; - else if (mv->down[i] == arrow) - return i + 42; - - g_warning ("Eeeek, arrow %p not found in month view %p", arrow, mv); - return -1; -} - -/* Checks whether arrows need to be displayed at the specified day index or not */ -static void -check_arrow_visibility (MonthView *mv, int day_index) -{ - GtkArg args[3]; - double text_height; - double clip_height; - double y_offset; - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 3, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - - /* Check up arrow */ - - if (y_offset < 0.0) - gnome_canvas_item_show (mv->up[day_index]); - else - gnome_canvas_item_hide (mv->up[day_index]); - - if (y_offset > (clip_height - text_height)) - gnome_canvas_item_show (mv->down[day_index]); - else - gnome_canvas_item_hide (mv->down[day_index]); -} - -/* Finds which arrow was clicked and scrolls the corresponding text item in the month view */ -static void -do_arrow_click (MonthView *mv, GnomeCanvasItem *arrow) -{ - int arrow_index; - int day_index; - int up; - GtkArg args[4]; - double text_height, clip_height; - double y_offset; - GdkFont *font; - - arrow_index = get_arrow_index (mv, arrow); - up = (arrow_index < 42); - day_index = up ? arrow_index : (arrow_index - 42); - - /* See how much we can scroll */ - - args[0].name = "text_height"; - args[1].name = "clip_height"; - args[2].name = "y_offset"; - args[3].name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->text[day_index]), 4, args); - - text_height = GTK_VALUE_DOUBLE (args[0]); - clip_height = GTK_VALUE_DOUBLE (args[1]); - y_offset = GTK_VALUE_DOUBLE (args[2]); - font = GTK_VALUE_BOXED (args[3]); - - if (up) - y_offset += font->ascent + font->descent; - else - y_offset -= font->ascent + font->descent; - - if (y_offset > 0.0) - y_offset = 0.0; - else if (y_offset < (clip_height - text_height)) - y_offset = clip_height - text_height; - - /* Scroll */ - - gnome_canvas_item_set (mv->text[day_index], - "y_offset", y_offset, - NULL); - - check_arrow_visibility (mv, day_index); -} - -/* Event handler for the scroll arrows in the month view */ -static gint -arrow_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - MonthView *mv; - - mv = MONTH_VIEW (data); - - switch (event->type) { - case GDK_ENTER_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG), - NULL); - return TRUE; - - case GDK_LEAVE_NOTIFY: - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - NULL); - return TRUE; - - case GDK_BUTTON_PRESS: - if (event->button.button != 1) - break; - - do_arrow_click (mv, item); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Creates a new arrow out of the specified points and connects the proper signals to it */ -static GnomeCanvasItem * -new_arrow (MonthView *mv, GnomeCanvasGroup *group, GnomeCanvasPoints *points) -{ - GnomeCanvasItem *item; - char *color_spec; - - color_spec = color_spec_from_prop (COLOR_PROP_DAY_FG); - - item = gnome_canvas_item_new (GNOME_CANVAS_GROUP (group), - gnome_canvas_polygon_get_type (), - "points", points, - "fill_color", color_spec, - "outline_color", color_spec, - NULL); - - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) arrow_event, - mv); - - return item; -} - -static void -month_view_init (MonthView *mv) -{ - int i; - GnomeCanvasItem *day_group; - GnomeCanvasPoints *points; - - /* Title */ - - mv->title = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (mv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "font", HEADING_FONT, - "fill_color", "black", - NULL); - - /* Month item */ - - mv->mitem = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (mv))); - gnome_canvas_item_set (mv->mitem, - "x", 0.0, - "anchor", GTK_ANCHOR_NW, - "day_anchor", GTK_ANCHOR_NE, - "start_on_monday", week_starts_on_monday, - "heading_padding", 2.0, - "heading_font", BIG_DAY_HEADING_FONT, - "day_font", BIG_NORMAL_DAY_FONT, - NULL); - - /* Arrows and text items. The arrows start hidden by default; they will be shown as - * appropriate by the item adjustment code. Also, connect to the event signal of the - * day groups so that we can pop up the quick view when appropriate. - */ - - points = gnome_canvas_points_new (3); - - for (i = 0; i < 42; i++) { - day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - i + GNOME_MONTH_ITEM_DAY_GROUP); - gtk_signal_connect (GTK_OBJECT (day_group), "event", - (GtkSignalFunc) day_event, - mv); - - /* Up arrow */ - - points->coords[0] = 3; - points->coords[1] = 10; - points->coords[2] = 11; - points->coords[3] = 10; - points->coords[4] = 7; - points->coords[5] = 3; - - mv->up[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Down arrow */ - - points->coords[0] = 13; - points->coords[1] = 3; - points->coords[2] = 17; - points->coords[3] = 10; - points->coords[4] = 21; - points->coords[5] = 3; - - mv->down[i] = new_arrow (mv, GNOME_CANVAS_GROUP (day_group), points); - - /* Text item */ - - mv->text[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (day_group), - gnome_canvas_text_get_type (), - "font", EVENT_FONT, - "anchor", GTK_ANCHOR_NW, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "clip", TRUE, - NULL); - } - - mv->old_current_index = -1; -} - -GtkWidget * -month_view_new (GnomeCalendar *calendar, time_t month) -{ - MonthView *mv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - mv = gtk_type_new (month_view_get_type ()); - mv->calendar = calendar; - - month_view_colors_changed (mv); - month_view_set (mv, month); - return GTK_WIDGET (mv); -} - -static void -month_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - if (GTK_WIDGET_CLASS (parent_class)->size_request) - (* GTK_WIDGET_CLASS (parent_class)->size_request) (widget, requisition); - - requisition->width = 200; - requisition->height = 150; -} - -/* Adjusts the text items for events in the month view to the appropriate size. It also makes the - * corresponding arrows visible or invisible, as appropriate. - */ -static void -adjust_children (MonthView *mv) -{ - int i; - GnomeCanvasItem *item; - double x1, y1, x2, y2; - GtkArg arg; - - for (i = 0; i < 42; i++) { - /* Get dimensions of the day group */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_GROUP); - gnome_canvas_item_get_bounds (item, &x1, &y1, &x2, &y2); - - /* Normalize and add paddings */ - - x2 -= x1 + EVENT_PADDING; - x1 = EVENT_PADDING; - y2 -= y1 + EVENT_PADDING; - y1 = EVENT_PADDING; - - /* Add height of day label to y1 */ - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), i + GNOME_MONTH_ITEM_DAY_LABEL); - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 1, &arg); - y1 += GTK_VALUE_DOUBLE (arg); - - /* Set the position and clip size */ - - gnome_canvas_item_set (mv->text[i], - "x", x1, - "y", y1, - "clip_width", x2 - x1, - "clip_height", y2 - y1, - "x_offset", 0.0, - "y_offset", 0.0, - NULL); - - /* See what visibility state the arrows should be set to */ - - check_arrow_visibility (mv, i); - } -} - -static void -month_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - MonthView *mv; - GdkFont *font; - GtkArg arg; - int y; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_MONTH_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - mv = MONTH_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (mv), 0, 0, allocation->width, allocation->height); - - /* Adjust items to new size */ - - arg.name = "font_gdk"; - gtk_object_getv (GTK_OBJECT (mv->title), 1, &arg); - font = GTK_VALUE_BOXED (arg); - - gnome_canvas_item_set (mv->title, - "x", (double) allocation->width / 2.0, - "y", (double) SPACING, - NULL); - - y = font->ascent + font->descent + 2 * SPACING; - gnome_canvas_item_set (mv->mitem, - "y", (double) y, - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - y - 1), - NULL); - - /* Adjust children */ - - adjust_children (mv); -} - -/* This defines the environment for the calendar iterator function that is used to populate the - * month view with events. - */ -struct iter_info { - MonthView *mv; /* The month view we are creating children for */ - int first_day_index; /* Index of the first day of the month within the month item */ - time_t month_begin, month_end; /* Beginning and end of month */ - GString **strings; /* Array of strings to populate */ -}; - -/* This is the calendar iterator function used to populate the string array with event information. - * For each event, it iterates through all the days that the event touches and appends the proper - * information to the string array in the iter_info structure. - */ -static int -add_event (iCalObject *ico, time_t start, time_t end, void *data) -{ - struct iter_info *ii; - struct tm *tm; - time_t t; - time_t day_begin_time, day_end_time; - - ii = data; - - /* Get the first day of the event */ - - t = MAX (start, ii->month_begin); - day_begin_time = time_day_begin (t); - day_end_time = time_day_end (day_begin_time); - - /* Loop until the event ends or the month ends. For each day touched, append the proper - * information to the corresponding string. - */ - - do { - tm = localtime (&day_begin_time); - g_string_sprintfa (ii->strings[ii->first_day_index + tm->tm_mday - 1], "%s\n", ico->summary); - - /* Next day */ - - day_begin_time = time_add_day (day_begin_time, 1); - day_end_time = time_day_end (day_begin_time); - } while ((end > day_begin_time) && (day_begin_time < ii->month_end)); - - return TRUE; /* this means we are not finished yet with event generation */ -} - -void -month_view_update (MonthView *mv, iCalObject *object, int flags) -{ - struct iter_info ii; - GString *strings[42]; - int i; - time_t t; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - ii.mv = mv; - - /* Create an array of empty GStrings */ - - ii.strings = strings; - - for (i = 0; i < 42; i++) - strings[i] = g_string_new (NULL); - - ii.first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), 1); - g_assert (ii.first_day_index != -1); - - /* Populate the array of strings with events */ - - t = time_from_day (mv->year, mv->month, 1); - ii.month_begin = time_month_begin (t); - ii.month_end = time_month_end (t); - - calendar_iterate (mv->calendar->cal, ii.month_begin, ii.month_end, add_event, &ii); - - for (i = 0; i < 42; i++) { - /* Delete the last character if it is a newline */ - - if (strings[i]->str && strings[i]->len && (strings[i]->str[strings[i]->len - 1] == '\n')) - g_string_truncate (strings[i], strings[i]->len - 1); - - gnome_canvas_item_set (mv->text[i], - "text", strings[i]->str, - NULL); - g_string_free (strings[i], TRUE); - } - - /* Adjust children for scrolling */ - - adjust_children (mv); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (MonthView *mv) -{ - time_t t; - struct tm *tm; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (mv->old_current_index != -1) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "font", BIG_NORMAL_DAY_FONT, - NULL); - - mv->old_current_index = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = localtime (&t); - - if (((tm->tm_year + 1900) == mv->year) && (tm->tm_mon == mv->month)) { - mv->old_current_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (mv->mitem), tm->tm_mday); - g_assert (mv->old_current_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mv->mitem), - GNOME_MONTH_ITEM_DAY_LABEL + mv->old_current_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "font", BIG_CURRENT_DAY_FONT, - NULL); - } -} - -void -month_view_set (MonthView *mv, time_t month) -{ - struct tm *tm; - char buf[100]; - - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - /* Title */ - - tm = localtime (&month); - - mv->year = tm->tm_year + 1900; - mv->month = tm->tm_mon; - - strftime (buf, 100, "%B %Y", tm); - - gnome_canvas_item_set (mv->title, - "text", buf, - NULL); - - /* Month item */ - - gnome_canvas_item_set (mv->mitem, - "year", mv->year, - "month", mv->month, - NULL); - - /* Update events */ - - month_view_update (mv, NULL, 0); - mark_current_day (mv); -} - -void -month_view_time_format_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - gnome_canvas_item_set (mv->mitem, - "start_on_monday", week_starts_on_monday, - NULL); - - month_view_set (mv, time_month_begin (time_from_day (mv->year, mv->month, 1))); -} - -void -month_view_colors_changed (MonthView *mv) -{ - g_return_if_fail (mv != NULL); - g_return_if_fail (IS_MONTH_VIEW (mv)); - - colorify_month_item (GNOME_MONTH_ITEM (mv->mitem), default_color_func, NULL); - mark_current_day (mv); - - /* FIXME: set children to the marked color */ -} diff --git a/calendar/gui/month-view.h b/calendar/gui/month-view.h deleted file mode 100644 index 6e49c2f931..0000000000 --- a/calendar/gui/month-view.h +++ /dev/null @@ -1,72 +0,0 @@ -/* Month view display for gncal - * - * Copyright (C) 1998 Red Hat Software, Inc. - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef MONTH_VIEW_H -#define MONTH_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_MONTH_VIEW (month_view_get_type ()) -#define MONTH_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_MONTH_VIEW, MonthView)) -#define MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_MONTH_VIEW, MonthViewClass)) -#define IS_MONTH_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_MONTH_VIEW)) -#define IS_MONTH_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_MONTH_VIEW)) - - -typedef struct _MonthView MonthView; -typedef struct _MonthViewClass MonthViewClass; - -struct _MonthView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year of the month we are displaying */ - int month; /* The month we are displaying */ - int old_current_index; /* The index of the day marked as current, or -1 if none */ - - GnomeCanvasItem *up[42]; /* Arrows to go up in the days */ - GnomeCanvasItem *down[42]; /* Arrows to go down in the days */ - GnomeCanvasItem *text[42]; /* Text items for the events */ - - GnomeCanvasItem *title; /* The title heading with the month/year */ - GnomeCanvasItem *mitem; /* The canvas month item used by this month view */ -}; - -struct _MonthViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType month_view_get_type (void); - -/* Creates a new month view widget associated to the specified calendar */ -GtkWidget *month_view_new (GnomeCalendar *calendar, time_t month); - -/* Notifies the month view that a calendar object has changed */ -void month_view_update (MonthView *mv, iCalObject *ico, int flags); - -/* Notifies the month view about a change of date */ -void month_view_set (MonthView *mv, time_t month); - -/* Notifies the month view that the time format has changed */ -void month_view_time_format_changed (MonthView *mv); - -/* Notifies the month view that the colors have changed */ -void month_view_colors_changed (MonthView *mv); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/popup-menu.c b/calendar/gui/popup-menu.c deleted file mode 100644 index 3686183146..0000000000 --- a/calendar/gui/popup-menu.c +++ /dev/null @@ -1,37 +0,0 @@ -/* Popup menu utilities for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#include <config.h> -#include <gnome.h> -#include "popup-menu.h" - - -void -popup_menu (struct menu_item *items, int nitems, GdkEventButton *event) -{ - GtkWidget *menu; - GtkWidget *item; - int i; - - menu = gtk_menu_new (); /* FIXME: this baby is never freed */ - - for (i = 0; i < nitems; i++) { - if (items[i].text) { - item = gtk_menu_item_new_with_label (_(items[i].text)); - gtk_signal_connect (GTK_OBJECT (item), "activate", - items[i].callback, - items[i].data); - gtk_widget_set_sensitive (item, items[i].sensitive); - } else - item = gtk_menu_item_new (); - - gtk_widget_show (item); - gtk_menu_append (GTK_MENU (menu), item); - } - - gtk_menu_popup (GTK_MENU (menu), NULL, NULL, NULL, NULL, event->button, event->time); -} diff --git a/calendar/gui/popup-menu.h b/calendar/gui/popup-menu.h deleted file mode 100644 index a4590dbb98..0000000000 --- a/calendar/gui/popup-menu.h +++ /dev/null @@ -1,25 +0,0 @@ -/* Popup menu utilities for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef POPUP_MENU_H -#define POPUP_MENU_H - -#include <gdk/gdktypes.h> -#include <gtk/gtksignal.h> - - -struct menu_item { - char *text; - GtkSignalFunc callback; - gpointer data; - int sensitive; -}; - -void popup_menu (struct menu_item *items, int nitems, GdkEventButton *event); - - -#endif diff --git a/calendar/gui/prop.c b/calendar/gui/prop.c deleted file mode 100644 index 1e771812f9..0000000000 --- a/calendar/gui/prop.c +++ /dev/null @@ -1,559 +0,0 @@ -/* Calendar properties dialog box - * - * Copyright (C) 1998 the Free Software Foundation - * - * Authors: Miguel de Icaza <miguel@kernel.org> - * Federico Mena <federico@nuclecu.unam.mx> - */ -#include <config.h> -#include <langinfo.h> -#include <gnome.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" -#include "main.h" -#include "mark.h" - -/* These specify the page numbers in the preferences notebook */ -enum { - PROP_TIME_DISPLAY, - PROP_COLORS -}; - -static GtkWidget *prop_win; /* The preferences dialog */ - -/* Widgets for the time display page */ - -static GtkWidget *time_format_12; /* Radio button for 12-hour format */ -static GtkWidget *time_format_24; /* Radio button for 24-hour format */ -static GtkWidget *start_on_sunday; /* Check button for weeks starting on Sunday */ -static GtkWidget *start_on_monday; /* Check button for weeks starting on Monday */ -static GtkWidget *start_omenu; /* Option menu for start of day */ -static GtkWidget *end_omenu; /* Option menu for end of day */ -static GtkWidget *start_items[24]; /* Menu items for start of day menu */ -static GtkWidget *end_items[24]; /* Menu items for end of day menu */ - -/* Widgets for the colors page */ - -static GtkWidget *color_pickers[COLOR_PROP_LAST]; -static GnomeCanvasItem *month_item; - - -/* Callback used when the property box is closed -- just sets the prop_win variable to null. */ -static int -prop_cancel (void) -{ - prop_win = NULL; - return FALSE; -} - -/* Returns the index of the active item in a menu */ -static int -get_active_index (GtkWidget *menu) -{ - GtkWidget *active; - - active = gtk_menu_get_active (GTK_MENU (menu)); - return GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (active))); -} - -/* Applies the settings in the time display page */ -static void -prop_apply_time_display (void) -{ - /* Day begin/end */ - - day_begin = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (start_omenu))); - day_end = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (end_omenu))); - gnome_config_set_int ("/calendar/Calendar/Day start", day_begin); - gnome_config_set_int ("/calendar/Calendar/Day end", day_end); - - /* Time format */ - - am_pm_flag = GTK_TOGGLE_BUTTON (time_format_12)->active; - gnome_config_set_bool ("/calendar/Calendar/AM PM flag", am_pm_flag); - - /* Week start */ - - week_starts_on_monday = GTK_TOGGLE_BUTTON (start_on_monday)->active; - gnome_config_set_bool ("/calendar/Calendar/Week starts on Monday", week_starts_on_monday); - - gnome_config_sync (); - time_format_changed (); -} - -/* Applies the settings in the colors page */ -static void -prop_apply_colors (void) -{ - int i; - char *cspec; - gushort r, g, b; - - for (i = 0; i < COLOR_PROP_LAST; i++) { - gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[i]), &r, &g, &b, NULL); - color_props[i].r = r; - color_props[i].g = g; - color_props[i].b = b; - - cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b); - gnome_config_set_string (color_props[i].key, cspec); - } - - gnome_config_sync (); - colors_changed (); -} - -/* Callback used when the Apply button is clicked. */ -static void -prop_apply (GtkWidget *w, int page) -{ - switch (page) { - case PROP_TIME_DISPLAY: - prop_apply_time_display (); - break; - - case PROP_COLORS: - prop_apply_colors (); - break; - - case -1: - break; - - default: - g_warning ("We have a loose penguin!"); - g_assert_not_reached (); - } -} - -/* Notifies the property box that the data has changed */ -static void -prop_changed (void) -{ - gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win)); -} - -/* Builds and returns a two-element radio button group surrounded by a frame. The radio buttons are - * stored in the specified variables, and the first radio button's state is set according to the - * specified flag value. The buttons are connected to the prop_changed() function to update the property - * box's dirty state. - */ -static GtkWidget * -build_two_radio_group (char *title, - char *radio_1_title, GtkWidget **radio_1_widget, - char *radio_2_title, GtkWidget **radio_2_widget, - int radio_1_value) -{ - GtkWidget *frame; - GtkWidget *vbox; - - frame = gtk_frame_new (title); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - *radio_1_widget = gtk_radio_button_new_with_label (NULL, radio_1_title); - gtk_box_pack_start (GTK_BOX (vbox), *radio_1_widget, FALSE, FALSE, 0); - - *radio_2_widget = gtk_radio_button_new_with_label_from_widget (GTK_RADIO_BUTTON (*radio_1_widget), - radio_2_title); - gtk_box_pack_start (GTK_BOX (vbox), *radio_2_widget, FALSE, FALSE, 0); - - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (*radio_1_widget), radio_1_value); - gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (*radio_2_widget), !radio_1_value); - - gtk_signal_connect (GTK_OBJECT (*radio_1_widget), "toggled", - (GtkSignalFunc) prop_changed, - NULL); - - return frame; -} - -/* Callback invoked when a menu item from the start/end time option menus is selected. It adjusts - * the other menu to the proper time, if needed. - */ -static void -hour_activated (GtkWidget *widget, gpointer data) -{ - int start, end; - - if (data == start_omenu) { - /* Adjust the end menu */ - - start = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (widget))); - end = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (end_omenu))); - - if (end < start) - gtk_option_menu_set_history (GTK_OPTION_MENU (end_omenu), start); - } else if (data == end_omenu) { - /* Adjust the start menu */ - - end = GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (widget))); - start = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (start_omenu))); - - if (start > end) - gtk_option_menu_set_history (GTK_OPTION_MENU (start_omenu), end); - } else - g_assert_not_reached (); - - gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win)); -} - -/* Builds an option menu of 24 hours */ -static GtkWidget * -build_hours_menu (GtkWidget **items, int active) -{ - GtkWidget *omenu; - GtkWidget *menu; - int i; - char buf[100]; - struct tm tm; - - omenu = gtk_option_menu_new (); - menu = gtk_menu_new (); - - memset (&tm, 0, sizeof (tm)); - - for (i = 0; i < 24; i++) { - tm.tm_hour = i; - strftime (buf, 100, "%I:%M %p", &tm); - - items[i] = gtk_menu_item_new_with_label (buf); - gtk_object_set_user_data (GTK_OBJECT (items[i]), GINT_TO_POINTER (i)); - gtk_signal_connect (GTK_OBJECT (items[i]), "activate", - (GtkSignalFunc) hour_activated, - omenu); - - gtk_menu_append (GTK_MENU (menu), items[i]); - gtk_widget_show (items[i]); - } - - gtk_option_menu_set_menu (GTK_OPTION_MENU (omenu), menu); - gtk_option_menu_set_history (GTK_OPTION_MENU (omenu), active); - return omenu; -} - -/* Creates the time display page in the preferences dialog */ -static void -create_time_display_page (void) -{ - GtkWidget *table; - GtkWidget *vbox; - GtkWidget *frame; - GtkWidget *hbox2; - GtkWidget *hbox3; - GtkWidget *w; - - table = gtk_table_new (2, 2, FALSE); - gtk_container_set_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL); - gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), table, - gtk_label_new (_("Time display"))); - - /* Time format */ - - w = build_two_radio_group (_("Time format"), - _("12-hour (AM/PM)"), &time_format_12, - _("24-hour"), &time_format_24, - am_pm_flag); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, 0, 1, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - /* Weeks start on */ - - w = build_two_radio_group (_("Weeks start on"), - _("Sunday"), &start_on_sunday, - _("Monday"), &start_on_monday, - !week_starts_on_monday); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - /* Day range */ - - frame = gtk_frame_new (_("Day range")); - gtk_table_attach (GTK_TABLE (table), frame, - 1, 2, 0, 2, - GTK_EXPAND | GTK_FILL, - GTK_EXPAND | GTK_FILL, - 0, 0); - - vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL); - gtk_container_set_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), vbox); - - w = gtk_label_new (_("Please select the start and end hours you want\n" - "to be displayed in the day view and week view.\n" - "Times outside this range will not be displayed\n" - "by default.")); - gtk_label_set_justify (GTK_LABEL (w), GTK_JUSTIFY_LEFT); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.0); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - hbox2 = gtk_hbox_new (FALSE, GNOME_PAD); - gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0); - - /* Day start */ - - hbox3 = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox2), hbox3, FALSE, FALSE, 0); - - w = gtk_label_new (_("Day start:")); - gtk_box_pack_start (GTK_BOX (hbox3), w, FALSE, FALSE, 0); - - start_omenu = build_hours_menu (start_items, day_begin); - gtk_box_pack_start (GTK_BOX (hbox3), start_omenu, FALSE, FALSE, 0); - - /* Day end */ - - hbox3 = gtk_hbox_new (FALSE, GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox2), hbox3, FALSE, FALSE, 0); - - w = gtk_label_new (_("Day end:")); - gtk_box_pack_start (GTK_BOX (hbox3), w, FALSE, FALSE, 0); - - end_omenu = build_hours_menu (end_items, day_end); - gtk_box_pack_start (GTK_BOX (hbox3), end_omenu, FALSE, FALSE, 0); -} - -/* Called when the canvas for the month item is size allocated. We use this to change the canvas' - * scrolling region and the month item's size. - */ -static void -canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data) -{ - gnome_canvas_item_set (month_item, - "width", (double) (allocation->width - 1), - "height", (double) (allocation->height - 1), - NULL); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (widget), - 0, 0, - allocation->width, allocation->height); -} - -/* Returns a color spec based on the color pickers */ -static char * -color_spec_from_picker (int num) -{ - gushort r, g, b; - - gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[num]), &r, &g, &b, NULL); - - return build_color_spec (r, g, b); -} - -/* Callback used to query color information for the properties box */ -static char * -fetch_color_spec (ColorProp propnum, gpointer data) -{ - return color_spec_from_picker (propnum); -} - -/* Marks fake event days in the month item sample */ -static void -fake_mark_days (void) -{ - static int day_nums[] = { 1, 4, 8, 16, 17, 18, 20, 25, 28 }; /* some random days */ - int first_day_index; - int i; - - first_day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (month_item), 1); - - for (i = 0; i < (sizeof (day_nums) / sizeof (day_nums[0])); i++) - mark_month_item_index (GNOME_MONTH_ITEM (month_item), first_day_index + day_nums[i] - 1, - fetch_color_spec, NULL); -} - -/* Switches the month item to the current date and highlights the current day's number */ -static void -set_current_day (void) -{ - struct tm *tm; - time_t t; - GnomeCanvasItem *item; - int day_index; - - /* Set the date */ - - t = time (NULL); - tm = localtime (&t); - - gnome_canvas_item_set (month_item, - "year", tm->tm_year + 1900, - "month", tm->tm_mon, - NULL); - - /* Highlight current day */ - - day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (month_item), tm->tm_mday); - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item), GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_picker (COLOR_PROP_CURRENT_DAY_FG), - "font", CURRENT_DAY_FONT, - NULL); -} - -/* This is the version of a color spec query function that is appropriate for the preferences dialog */ -static char * -prop_color_func (ColorProp propnum, gpointer data) -{ - return color_spec_from_picker (propnum); -} - -/* Sets the colors of the month item to the current prerences */ -static void -reconfigure_month (void) -{ - colorify_month_item (GNOME_MONTH_ITEM (month_item), prop_color_func, NULL); - fake_mark_days (); - set_current_day (); - - /* Reset prelighting information */ - - month_item_prepare_prelight (GNOME_MONTH_ITEM (month_item), fetch_color_spec, NULL); -} - -/* Callback used when a color is changed */ -static void -color_set (void) -{ - reconfigure_month (); - prop_changed (); -} - -/* Creates the colors page in the preferences dialog */ -static void -create_colors_page (void) -{ - GtkWidget *frame; - GtkWidget *hbox; - GtkWidget *table; - GtkWidget *w; - int i; - - frame = gtk_frame_new (_("Colors for months")); - gtk_container_set_border_width (GTK_CONTAINER (frame), GNOME_PAD_SMALL); - gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), frame, - gtk_label_new (_("Colors"))); - - hbox = gtk_hbox_new (FALSE, GNOME_PAD); - gtk_container_set_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL); - gtk_container_add (GTK_CONTAINER (frame), hbox); - - table = gtk_table_new (COLOR_PROP_LAST, 2, FALSE); - gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0); - - /* Create the color pickers */ - - for (i = 0; i < COLOR_PROP_LAST; i++) { - /* Label */ - - w = gtk_label_new (_(color_props[i].label)); - gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5); - gtk_table_attach (GTK_TABLE (table), w, - 0, 1, i, i + 1, - GTK_FILL, 0, - 0, 0); - - /* Color picker */ - - color_pickers[i] = gnome_color_picker_new (); - gnome_color_picker_set_title (GNOME_COLOR_PICKER (color_pickers[i]), _(color_props[i].label)); - gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (color_pickers[i]), - color_props[i].r, color_props[i].g, color_props[i].b, 0); - gtk_table_attach (GTK_TABLE (table), color_pickers[i], - 1, 2, i, i + 1, - 0, 0, - 0, 0); - gtk_signal_connect (GTK_OBJECT (color_pickers[i]), "color_set", - (GtkSignalFunc) color_set, - NULL); - } - - /* Create the sample calendar */ - - w = gnome_canvas_new (); - gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0); - - month_item = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (w))); - gnome_canvas_item_set (month_item, - "start_on_monday", week_starts_on_monday, - NULL); - reconfigure_month (); - - gtk_signal_connect (GTK_OBJECT (w), "size_allocate", - canvas_size_allocate, - NULL); - -} - -/* Creates and displays the preferences dialog for the whole application */ -void -properties (GtkWidget *toplevel) -{ - static GnomeHelpMenuEntry help_entry = { NULL, "properties" }; - - help_entry.name = gnome_app_id; - - if (prop_win) - return; - - prop_win = gnome_property_box_new (); - gtk_window_set_title (GTK_WINDOW (prop_win), _("Preferences")); - gnome_dialog_set_parent (GNOME_DIALOG (prop_win), GTK_WINDOW (toplevel)); - - create_time_display_page (); - create_colors_page (); - - gtk_signal_connect (GTK_OBJECT (prop_win), "destroy", - (GtkSignalFunc) prop_cancel, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "delete_event", - (GtkSignalFunc) prop_cancel, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "apply", - (GtkSignalFunc) prop_apply, NULL); - - gtk_signal_connect (GTK_OBJECT (prop_win), "help", - GTK_SIGNAL_FUNC (gnome_help_pbox_display), - &help_entry); - - gtk_widget_show_all (prop_win); -} - -char * -build_color_spec (int r, int g, int b) -{ - static char spec[100]; - - sprintf (spec, "#%04x%04x%04x", r, g, b); - return spec; -} - -void -parse_color_spec (char *spec, int *r, int *g, int *b) -{ - g_return_if_fail (spec != NULL); - g_return_if_fail (r != NULL); - g_return_if_fail (r != NULL); - g_return_if_fail (r != NULL); - - if (sscanf (spec, "#%04x%04x%04x", r, g, b) != 3) { - g_warning ("Invalid color specification %s, returning black", spec); - - *r = *g = *b = 0; - } -} - -char * -color_spec_from_prop (ColorProp propnum) -{ - return build_color_spec (color_props[propnum].r, color_props[propnum].g, color_props[propnum].b); -} diff --git a/calendar/gui/quick-view.c b/calendar/gui/quick-view.c deleted file mode 100644 index 337cfdbf73..0000000000 --- a/calendar/gui/quick-view.c +++ /dev/null @@ -1,274 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#include <config.h> -#include "quick-view.h" -#include "main.h" - - -#define QUICK_VIEW_FONT "-adobe-helvetica-medium-r-normal--10-*-*-*-p-*-*-*" - - -static void quick_view_class_init (QuickViewClass *class); -static void quick_view_init (QuickView *qv); - -static gint quick_view_button_release (GtkWidget *widget, GdkEventButton *event); -static gint quick_view_map_event (GtkWidget *widget, GdkEventAny *event); - - -static GtkWindowClass *parent_class; - - -GtkType -quick_view_get_type (void) -{ - static GtkType quick_view_type = 0; - - if (!quick_view_type) { - GtkTypeInfo quick_view_info = { - "QuickView", - sizeof (QuickView), - sizeof (QuickViewClass), - (GtkClassInitFunc) quick_view_class_init, - (GtkObjectInitFunc) quick_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - quick_view_type = gtk_type_unique (gtk_window_get_type (), &quick_view_info); - } - - return quick_view_type; -} - -static void -quick_view_class_init (QuickViewClass *class) -{ - GtkWidgetClass *widget_class; - - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gtk_window_get_type ()); - - widget_class->button_release_event = quick_view_button_release; - widget_class->map_event = quick_view_map_event; -} - -static void -quick_view_init (QuickView *qv) -{ - GTK_WINDOW (qv)->type = GTK_WINDOW_POPUP; - gtk_window_set_position (GTK_WINDOW (qv), GTK_WIN_POS_MOUSE); -} - -static gint -quick_view_button_release (GtkWidget *widget, GdkEventButton *event) -{ - QuickView *qv; - - qv = QUICK_VIEW (widget); - - if (event->button != qv->button) - return FALSE; - - gdk_pointer_ungrab (event->time); - gtk_grab_remove (GTK_WIDGET (qv)); - gtk_widget_hide (GTK_WIDGET (qv)); - - gtk_main_quit (); /* End modality of the quick view */ - return TRUE; -} - -static gint -quick_view_map_event (GtkWidget *widget, GdkEventAny *event) -{ - GdkCursor *cursor; - - cursor = gdk_cursor_new (GDK_ARROW); - gdk_pointer_grab (widget->window, - TRUE, - GDK_BUTTON_RELEASE_MASK, - NULL, - cursor, - GDK_CURRENT_TIME); - gdk_cursor_destroy (cursor); - - return FALSE; -} - -/* Creates the items corresponding to a single calendar object. Takes in the y position of the - * items to create and returns the y position of the next item to create. Also takes in the current - * maximum width for items and returns the new maximum width. - */ -void -create_items_for_event (QuickView *qv, CalendarObject *co, double *y, double *max_width) -{ - GnomeCanvas *canvas; - GnomeCanvasItem *item; - char start[100], end[100]; - struct tm start_tm, end_tm; - char *str; - GtkArg args[2]; - - /* FIXME: make this nice */ - - canvas = GNOME_CANVAS (qv->canvas); - - start_tm = *localtime (&co->ev_start); - end_tm = *localtime (&co->ev_end); - - if (am_pm_flag) { - strftime (start, sizeof (start), "%I:%M%p", &start_tm); - strftime (end, sizeof (end), "%I:%M%p", &end_tm); - } else { - strftime (start, sizeof (start), "%H:%M", &start_tm); - strftime (end, sizeof (end), "%H:%M", &end_tm); - } - - str = g_strconcat (start, " - ", end, " ", co->ico->summary, NULL); - - item = gnome_canvas_item_new (gnome_canvas_root (canvas), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", *y, - "anchor", GTK_ANCHOR_NW, - "text", str, - "font", QUICK_VIEW_FONT, - NULL); - - g_free (str); - - /* Measure the text and return the proper size values */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - if (GTK_VALUE_DOUBLE (args[0]) > *max_width) - *max_width = GTK_VALUE_DOUBLE (args[0]); - - *y += GTK_VALUE_DOUBLE (args[1]); -} - -/* Creates the canvas items corresponding to the events in the list */ -static void -setup_event_list (QuickView *qv, GList *event_list) -{ - CalendarObject *co; - GnomeCanvasItem *item; - GtkArg args[2]; - double y, max_width; - - /* If there are no events, then just put a simple label */ - - if (!event_list) { - item = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (qv->canvas)), - gnome_canvas_text_get_type (), - "x", 0.0, - "y", 0.0, - "anchor", GTK_ANCHOR_NW, - "text", _("No appointments for this day"), - "font", QUICK_VIEW_FONT, - NULL); - - /* Measure the text and set the proper sizes */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (item), 2, args); - - y = GTK_VALUE_DOUBLE (args[1]); - max_width = GTK_VALUE_DOUBLE (args[0]); - } else { - /* Create the items for all the events in the list */ - - y = 0.0; - max_width = 0.0; - - for (; event_list; event_list = event_list->next) { - co = event_list->data; - create_items_for_event (qv, co, &y, &max_width); - } - } - - /* Set the scrolling region to fit all the items */ - - gnome_canvas_set_scroll_region (GNOME_CANVAS (qv->canvas), - 0.0, 0.0, - max_width, y); - - gtk_widget_set_usize (qv->canvas, max_width, y); -} - -GtkWidget * -quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list) -{ - QuickView *qv; - GtkWidget *vbox; - GtkWidget *w; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - qv = gtk_type_new (quick_view_get_type ()); - qv->calendar = calendar; - - /* Create base widgets for the popup window */ - - w = gtk_frame_new (NULL); - gtk_frame_set_shadow_type (GTK_FRAME (w), GTK_SHADOW_ETCHED_OUT); - gtk_container_add (GTK_CONTAINER (qv), w); - - vbox = gtk_vbox_new (FALSE, 0); - gtk_container_add (GTK_CONTAINER (w), vbox); - - w = gtk_label_new (title); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_hseparator_new (); - gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0); - - w = gtk_alignment_new (0.5, 0.5, 0.0, 0.0); - gtk_container_set_border_width (GTK_CONTAINER (w), GNOME_PAD_SMALL); - gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0); - - gtk_widget_push_visual (gdk_imlib_get_visual ()); - gtk_widget_push_colormap (gdk_imlib_get_colormap ()); - - qv->canvas = gnome_canvas_new (); - - gtk_widget_pop_colormap (); - gtk_widget_pop_visual (); - - gtk_container_add (GTK_CONTAINER (w), qv->canvas); - - /* Set up the event list */ - - setup_event_list (qv, event_list); - - return GTK_WIDGET (qv); -} - -void -quick_view_do_popup (QuickView *qv, GdkEventButton *event) -{ - g_return_if_fail (qv != NULL); - g_return_if_fail (IS_QUICK_VIEW (qv)); - g_return_if_fail (event != NULL); - - /* Pop up the window */ - - gtk_widget_show_all (GTK_WIDGET (qv)); - gtk_grab_add (GTK_WIDGET (qv)); - - qv->button = event->button; - - gtk_main (); /* Begin modality */ - - /* The button release event handler will call gtk_main_quit() */ -} diff --git a/calendar/gui/quick-view.h b/calendar/gui/quick-view.h deleted file mode 100644 index c6b2cf8814..0000000000 --- a/calendar/gui/quick-view.h +++ /dev/null @@ -1,59 +0,0 @@ -/* Quick view widget for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx - */ - -#ifndef QUICK_VIEW_H -#define QUICK_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_QUICK_VIEW (quick_view_get_type ()) -#define QUICK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_QUICK_VIEW, QuickView)) -#define QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_QUICK_VIEW, QuickViewClass)) -#define IS_QUICK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_QUICK_VIEW)) -#define IS_QUICK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_QUICK_VIEW)) - - -typedef struct _QuickView QuickView; -typedef struct _QuickViewClass QuickViewClass; - -struct _QuickView { - GtkWindow window; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - GtkWidget *canvas; /* The canvas that displays the contents of the quick view */ - - int button; /* The button that was pressed to pop up the quick view */ -}; - -struct _QuickViewClass { - GtkWindowClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType quick_view_get_type (void); - -/* Creates a new quick view with the specified title and the specified event list. It is associated - * to the specified calendar. The event list must be a list of CalendarObject structures. - */ -GtkWidget *quick_view_new (GnomeCalendar *calendar, char *title, GList *event_list); - -/* Pops up the quick view widget modally and loops until the uses closes it by releasing the mouse - * button. You can destroy the quick view when this function returns. - */ -void quick_view_do_popup (QuickView *qv, GdkEventButton *event); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/recur.xpm b/calendar/gui/recur.xpm deleted file mode 100644 index 49836b62e7..0000000000 --- a/calendar/gui/recur.xpm +++ /dev/null @@ -1,83 +0,0 @@ -/* XPM */ -static char * recur_xpm[] = { -"16 16 64 1", -" c None", -". c #350000", -"+ c #2A0000", -"@ c #1B0000", -"# c #280000", -"$ c #430000", -"% c #090000", -"& c #160000", -"* c #250000", -"= c #460000", -"- c #550000", -"; c #610000", -"> c #0D0000", -", c #1F0000", -"' c #4B0000", -") c #5E0000", -"! c #6B0000", -"~ c #750000", -"{ c #790000", -"] c #810000", -"^ c #FFFF83", -"/ c #FFFF89", -"( c #FFFF93", -"_ c #8B0000", -": c #900000", -"< c #930000", -"[ c #FFFF62", -"} c #A10000", -"| c #FFFF41", -"1 c #FFFF3B", -"2 c #FFFF31", -"3 c #B70000", -"4 c #B20000", -"5 c #AE0000", -"6 c #FFFF22", -"7 c #FFFF16", -"8 c #FFFF06", -"9 c #C90000", -"0 c #C10000", -"a c #BB0000", -"b c #FFF600", -"c c #FFE100", -"d c #FFC500", -"e c #E40000", -"f c #D70000", -"g c #CD0000", -"h c #FFDB00", -"i c #FFA900", -"j c #FF8500", -"k c #FF5900", -"l c #FF2800", -"m c #FC0000", -"n c #ED0000", -"o c #E10000", -"p c #FFAF00", -"q c #FF9400", -"r c #FF7400", -"s c #FF5000", -"t c #FF0100", -"u c #F30000", -"v c #E80000", -"w c #FF6900", -"x c #FF4900", -"y c #FF0800", -" ", -" . ", -" +. ", -" @#.$ ", -" %&*.=-; ", -" >,.')!~ ", -" &. !{] ", -" ^/( . _:< ", -" [[[ }}} ", -" |12 345 ", -" 678 90a ", -" bcd efg ", -" hdijklmnof ", -" pqrsltuv ", -" wxly ", -" "}; diff --git a/calendar/gui/test.vcf b/calendar/gui/test.vcf deleted file mode 100644 index bfe93b3c14..0000000000 --- a/calendar/gui/test.vcf +++ /dev/null @@ -1,133 +0,0 @@ -BEGIN:VCALENDAR -PRODID:-//GNOME//NONSGML GnomeCalendar//EN -TZ:MST -VERSION:0.13 -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980601T150000 -DTEND:19980601T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Cada dos dias de 06/01 al 07/01 -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D2 19980701T140000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T140000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:5 dias. -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980501T140000 -DTEND:19980501T150000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980429T004635 -SUMMARY:Diariamente de 05/01 al 06/01 -STATUS:NEEDS ACTION -CLASS:PRIVATE -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 19980601T000000 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VEVENT -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T010000 -DTEND:19980415T013000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Diario durante 5 dias -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:D1 #5 -END:VEVENT - -BEGIN:VTODO -UID:KOrganizer - 846930886 -SEQUENCE:1 -DTSTART:19980415T140000 -DUE:19691231T180000 -DCREATED:19980402T023558 -LAST-MODIFIED:19980402T023558 -SUMMARY:Normal -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T120000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semanal -- 4 semanas -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 WE #4 -END:VTODO - -BEGIN:VTODO -UID:KOrganizer - 1804289383 -SEQUENCE:1 -DTSTART:19980415T003000 -DUE:19691231T180000 -DCREATED:19980402T023552 -LAST-MODIFIED:19980330T225948 -SUMMARY:Semana: Mi, Ju, Vi, Dom (10 veces) -STATUS:NEEDS ACTION -CLASS:PUBLIC -PRIORITY:0 -TRANSP:0 -RELATED-TO:0 -RRULE:W1 SU WE TH FR #10 -END:VTODO - -END:VCALENDAR - diff --git a/calendar/gui/topic.dat b/calendar/gui/topic.dat deleted file mode 100644 index edc7813b26..0000000000 --- a/calendar/gui/topic.dat +++ /dev/null @@ -1,2 +0,0 @@ -gnome-cal.html Manual -gnome-cal.html#cmdline Command line options
\ No newline at end of file diff --git a/calendar/gui/view-utils.c b/calendar/gui/view-utils.c deleted file mode 100644 index 6287b1cbfe..0000000000 --- a/calendar/gui/view-utils.c +++ /dev/null @@ -1,201 +0,0 @@ -/* Miscellaneous utility functions for the calendar view widgets - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Federico Mena <quartic@gimp.org> - * Miguel de Icaza <miguel@kernel.org> - */ - -#include <string.h> -#include "view-utils.h" -#include <libgnomeui/gnome-icon-text.h> - -int am_pm_flag = 0; - -static char * -nicetime (struct tm *tm) -{ - static char buf [20]; - char *p = buf; - - if (am_pm_flag){ - if (tm->tm_min) - strftime (buf, sizeof (buf), "%l:%M%p", tm); - else - strftime (buf, sizeof (buf), "%l%p", tm); - } else { - if (tm->tm_min) - strftime (buf, sizeof (buf), "%k:%M", tm); - else - strftime (buf, sizeof (buf), "%k", tm); - } - while (*p == ' ') - p++; - return p; -} - -typedef struct { - GnomeIconTextInfo *layout; - int lines; - int assigned_lines; -} line_info_t; - -void -view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, - int flags, GList *events, time_t start, time_t end) -{ - GdkFont *font = widget->style->font; - int font_height; - int y, max_y, items, i, need_more, nlines, base, extra; - GList *list; - line_info_t *lines; - - if (events == NULL) - return; - - items = g_list_length (events); - lines = g_new0 (line_info_t, items); - - font_height = font->ascent + font->descent; - max_y = area->y + area->height - font_height * ((flags & VIEW_UTILS_DRAW_SPLIT) ? 2 : 1); - - /* - * Layout all the lines, measure the space needs - */ - for (i = 0, list = events; list; list = list->next, i++){ - CalendarObject *co = list->data; - struct tm tm_start, tm_end; - iCalObject *ico = co->ico; - char buf [60]; - char *full_text; - - tm_start = *localtime (&co->ev_start); - tm_end = *localtime (&co->ev_end); - - strcpy (buf, nicetime (&tm_start)); - - if (flags & VIEW_UTILS_DRAW_END){ - strcat (buf, "-"); - strcat (buf, nicetime (&tm_end)); - } - - full_text = g_strconcat (buf, ": ", ico->summary, NULL); - lines [i].layout = gnome_icon_layout_text ( - font, full_text, "\n -,.;:=#", area->width, TRUE); - lines [i].lines = g_list_length (lines [i].layout->rows); - - g_free (full_text); - } - - /* - * Compute how many lines we will give to each row - */ - nlines = 1 + max_y / font_height; - base = nlines / items; - extra = nlines % items; - need_more = 0; - - for (i = 0; i < items; i++){ - if (lines [i].lines <= base){ - extra += base - lines [i].lines; - lines [i].assigned_lines = lines [i].lines; - } else { - need_more++; - lines [i].assigned_lines = base; - } - } - - /* - * use any extra space - */ - while (need_more && extra > 0){ - need_more = 0; - - for (i = 0; i < items; i++){ - if (lines [i].lines > lines [i].assigned_lines){ - lines [i].assigned_lines++; - extra--; - } - - if (extra == 0) - break; - - if (lines [i].lines > lines [i].assigned_lines) - need_more = 1; - } - } - - /* - * Draw the information - */ - gdk_gc_set_clip_rectangle (gc, area); - y = area->y; - for (i = 0; i < items; i++){ - int line; - - list = lines [i].layout->rows; - - for (line = 0; line < lines [i].assigned_lines; line++){ - GnomeIconTextInfoRow *row = list->data; - - list = list->next; - - if (row) - gdk_draw_string ( - window, font, gc, - area->x, y + font->ascent, - row->text); - y += font_height; - } - } - - gdk_gc_set_clip_rectangle (gc, NULL); - - /* - * Free resources. - */ - - for (i = 0; i < items; i++) - gnome_icon_text_info_free (lines [i].layout); - g_free (lines); -} - -void -view_utils_draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow) -{ - int x, y; - int xthick, ythick; - GdkGC *light_gc, *dark_gc; - - gdk_draw_rectangle (window, - widget->style->bg_gc[GTK_STATE_NORMAL], - TRUE, - rect->x, rect->y, - rect->width, rect->height); - - light_gc = widget->style->light_gc[GTK_STATE_NORMAL]; - dark_gc = widget->style->dark_gc[GTK_STATE_NORMAL]; - - xthick = widget->style->klass->xthickness; - ythick = widget->style->klass->ythickness; - - gdk_gc_set_clip_rectangle (light_gc, rect); - gdk_gc_set_clip_rectangle (dark_gc, rect); - - for (y = rect->y + ythick; y < (rect->y + rect->height - ythick); y += 3) - for (x = rect->x + xthick; x < (rect->x + rect->width - xthick); x += 6) { - gdk_draw_point (window, light_gc, x, y); - gdk_draw_point (window, dark_gc, x + 1, y + 1); - - gdk_draw_point (window, light_gc, x + 3, y + 1); - gdk_draw_point (window, dark_gc, x + 4, y + 2); - } - - gdk_gc_set_clip_rectangle (light_gc, NULL); - gdk_gc_set_clip_rectangle (dark_gc, NULL); - - gtk_draw_shadow (widget->style, window, - GTK_STATE_NORMAL, shadow, - rect->x, rect->y, - rect->width, rect->height); -} diff --git a/calendar/gui/view-utils.h b/calendar/gui/view-utils.h deleted file mode 100644 index a1876b6032..0000000000 --- a/calendar/gui/view-utils.h +++ /dev/null @@ -1,28 +0,0 @@ -/* Miscellaneous utility functions for the calendar view widgets - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <quartic@gimp.org> - */ - -#ifndef VIEW_UTILS_H -#define VIEW_UTILS_H - - -#include <gtk/gtk.h> -#include "calendar.h" - - -enum { - VIEW_UTILS_DRAW_END = 1 << 0, - VIEW_UTILS_DRAW_SPLIT = 1 << 1 -}; - - -void view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRectangle *area, - int flags, GList *events, time_t start, time_t end); - -void view_utils_draw_textured_frame (GtkWidget *widget, GdkWindow *window, GdkRectangle *rect, GtkShadowType shadow); - - -#endif diff --git a/calendar/gui/week-view.c b/calendar/gui/week-view.c deleted file mode 100644 index 89e489a92d..0000000000 --- a/calendar/gui/week-view.c +++ /dev/null @@ -1,100 +0,0 @@ -/* Week view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include "year-view.h" - - -static void week_view_class_init (WeekViewClass *class); -static void week_view_init (WeekView *wv); - - -GtkType -week_view_get_type (void) -{ - static GtkType week_view_type = 0; - - if (!week_view_type) { - GtkTypeInfo week_view_info = { - "WeekView", - sizeof (WeekView), - sizeof (WeekViewClass), - (GtkClassInitFunc) week_view_class_init, - (GtkObjectInitFunc) week_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - week_view_type = gtk_type_unique (gnome_canvas_get_type (), &week_view_info); - } - - return week_view_type; -} - -static void -week_view_class_init (WeekViewClass *class) -{ - /* FIXME */ -} - -static void -week_view_init (WeekView *wv) -{ - GnomeCanvasGroup *root; - - root = gnome_canvas_root (GNOME_CANVAS (wv)); - - /* Title */ - - wv->title = gnome_canvas_item_new (root, - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "font", HEADING_FONT, - "fill_color", "black", - NULL); -} - -GtkWidget * -week_view_new (GnomeCalendar *calendar, time_t week) -{ - WeekView *wv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - wv = gtk_type_new (week_view_get_type ()); - wv->calendar = calendar; - - week_view_colors_changed (wv); - week_view_set (wv, week); - return GTK_WIDGET (wv); -} - -void -week_view_update (WeekView *wv, iCalObject *ico, int flags) -{ - /* FIXME */ -} - -void -week_view_set (WeekView *wv, time_t week) -{ - /* FIXME */ -} - -void -week_view_time_format_changed (WeekView *wv) -{ - /* FIXME */ -} - -void -week_view_colors_changed (WeekView *wv) -{ - /* FIXME */ -} diff --git a/calendar/gui/week-view.h b/calendar/gui/week-view.h deleted file mode 100644 index 1bf6a4ed02..0000000000 --- a/calendar/gui/week-view.h +++ /dev/null @@ -1,63 +0,0 @@ -/* Week view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Author: Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef WEEK_VIEW_H -#define WEEK_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" - -BEGIN_GNOME_DECLS - - -#define TYPE_WEEK_VIEW (week_view_get_type ()) -#define WEEK_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_WEEK_VIEW, WeekView)) -#define WEEK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_WEEK_VIEW, WeekViewClass)) -#define IS_WEEK_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_WEEK_VIEW)) -#define IS_WEEK_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_WEEK_VIEW)) - - -typedef struct _WeekView WeekView; -typedef struct _WeekViewClass WeekViewClass; - -struct _WeekView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - time_t week; /* Start of the week we are viewing */ - - GnomeCanvasItem *title; /* The title of the week view */ -}; - -struct _WeekViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType week_view_get_type (void); - -/* Creates a new week view associated to the specified calendar */ -GtkWidget *week_view_new (GnomeCalendar *calendar, time_t week); - -/* Notifies the week view that a calendar object has changed */ -void week_view_update (WeekView *wv, iCalObject *ico, int flags); - -/* Notifies the week view about a change of date */ -void week_view_set (WeekView *wv, time_t week); - -/* Notifies the week view that the time format has changed */ -void week_view_time_format_changed (WeekView *wv); - -/* Notifies the week view that the colors have changed */ -void week_view_colors_changed (WeekView *wv); - - -END_GNOME_DECLS - -#endif diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c deleted file mode 100644 index 786270bea3..0000000000 --- a/calendar/gui/year-view.c +++ /dev/null @@ -1,736 +0,0 @@ -/* Year view display for gncal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#include <config.h> -#include <gtk/gtkmain.h> -#include <gnome.h> -#include "eventedit.h" -#include "year-view.h" -#include "main.h" -#include "mark.h" -#include "quick-view.h" -#include "timeutil.h" - - -#define HEAD_SPACING 4 /* Spacing between year heading and months */ -#define TITLE_SPACING 1 /* Spacing between title and calendar */ -#define SPACING 4 /* Spacing between months */ - - -static void year_view_class_init (YearViewClass *class); -static void year_view_init (YearView *yv); -static void year_view_destroy (GtkObject *object); -static void year_view_size_request (GtkWidget *widget, - GtkRequisition *requisition); -static void year_view_size_allocate (GtkWidget *widget, - GtkAllocation *allocation); - - -static GnomeCanvas *parent_class; - - -GtkType -year_view_get_type (void) -{ - static GtkType year_view_type = 0; - - if (!year_view_type) { - GtkTypeInfo year_view_info = { - "YearView", - sizeof (YearView), - sizeof (YearViewClass), - (GtkClassInitFunc) year_view_class_init, - (GtkObjectInitFunc) year_view_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - year_view_type = gtk_type_unique (gnome_canvas_get_type (), &year_view_info); - } - - return year_view_type; -} - -static void -year_view_class_init (YearViewClass *class) -{ - GtkObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GtkObjectClass *) class; - widget_class = (GtkWidgetClass *) class; - - parent_class = gtk_type_class (gnome_canvas_get_type ()); - - object_class->destroy = year_view_destroy; - - widget_class->size_request = year_view_size_request; - widget_class->size_allocate = year_view_size_allocate; -} - -/* Resizes the year view's child items. This is done in the idle loop for performance (we avoid - * resizing on every size allocation). - */ -static gint -idle_handler (gpointer data) -{ - YearView *yv; - GtkArg arg; - double head_height; - double title_height; - double width, height; - double month_width; - double month_height; - double month_yofs; - double xofs, yofs; - double x, y; - int i; - - yv = data; - - /* Get the heights of the heading and the titles */ - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 1, &arg); - head_height = GTK_VALUE_DOUBLE (arg) + 2 * HEAD_SPACING; - - arg.name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &arg); - title_height = GTK_VALUE_DOUBLE (arg); - - /* Space for the titles and months */ - - width = GTK_WIDGET (yv)->allocation.width; - height = GTK_WIDGET (yv)->allocation.height - head_height; - - /* Offsets */ - - xofs = (width + SPACING) / 3.0; - yofs = (height + SPACING) / 4.0; - - /* Month item vertical offset */ - - month_yofs = title_height + TITLE_SPACING; - - /* Month item dimensions */ - - month_width = (width - 2 * SPACING) / 3.0; - month_height = (yofs - SPACING) - month_yofs; - - /* Adjust the year heading */ - - gnome_canvas_item_set (yv->heading, - "x", width / 2.0, - "y", (double) HEAD_SPACING, - NULL); - - /* Adjust titles and months */ - - for (i = 0; i < 12; i++) { - x = (i % 3) * xofs; - y = head_height + (i / 3) * yofs; - - gnome_canvas_item_set (yv->titles[i], - "x", x + month_width / 2.0, - "y", y, - NULL); - - gnome_canvas_item_set (yv->mitems[i], - "x", x, - "y", y + month_yofs, - "width", month_width, - "height", month_height, - NULL); - } - - /* Done */ - - yv->need_resize = FALSE; - return FALSE; -} - -/* Marks the year view as needing a resize, which will be performed during the idle loop */ -static void -need_resize (YearView *yv) -{ - if (yv->need_resize) - return; - - yv->need_resize = TRUE; - yv->idle_id = gtk_idle_add (idle_handler, yv); -} - -/* Callback used to destroy the year view's popup menu when the year view itself is destroyed */ -static void -destroy_menu (GtkWidget *widget, gpointer data) -{ - gtk_widget_destroy (GTK_WIDGET (data)); -} - -/* Create a new appointment in the highlighted day from the year view's popup menu */ -static void -new_appointment (GtkWidget *widget, gpointer data) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - event_editor_new_whole_day (yv->calendar, *t); -} - -/* Convenience functions to jump to a view and set the time */ -static void -do_jump (GtkWidget *widget, gpointer data, char *view_name) -{ - YearView *yv; - time_t *t; - - yv = YEAR_VIEW (data); - - /* Get the time data from the menu item */ - - t = gtk_object_get_data (GTK_OBJECT (widget), "time_data"); - - /* Set the view and time */ - - gnome_calendar_set_view (yv->calendar, view_name); - gnome_calendar_goto (yv->calendar, *t); -} - -/* The following three callbacks set the view in the calendar and change the time */ - -static void -jump_to_day (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "dayview"); -} - -static void -jump_to_week (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "weekview"); -} - -static void -jump_to_month (GtkWidget *widget, gpointer data) -{ - do_jump (widget, data, "monthview"); -} - -/* Information for the year view's popup menu */ -static GnomeUIInfo yv_popup_menu[] = { - GNOMEUIINFO_ITEM_STOCK (N_("_New appointment in this day..."), NULL, new_appointment, GNOME_STOCK_MENU_NEW), - - GNOMEUIINFO_SEPARATOR, - - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _day"), NULL, jump_to_day, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _week"), NULL, jump_to_week, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_ITEM_STOCK (N_("Jump to this _month"), NULL, jump_to_month, GNOME_STOCK_MENU_JUMP_TO), - GNOMEUIINFO_END -}; - -/* Returns the popup menu cooresponding to the specified year view. If the menu has not been - * created yet, it creates it and attaches it to the year view. - */ -static GtkWidget * -get_popup_menu (YearView *yv) -{ - GtkWidget *menu; - - menu = gtk_object_get_data (GTK_OBJECT (yv), "popup_menu"); - - if (!menu) { - menu = gnome_popup_menu_new (yv_popup_menu); - gtk_object_set_data (GTK_OBJECT (yv), "popup_menu", menu); - gtk_signal_connect (GTK_OBJECT (yv), "destroy", - (GtkSignalFunc) destroy_menu, - menu); - } - - return menu; -} - -/* Executes the year view's popup menu. It may disable/enable some menu items based on the - * specified flags. A pointer to a time_t value containing the specified time data is set in the - * "time_data" object data key of the menu items. - */ -static void -do_popup_menu (YearView *yv, GdkEventButton *event, int allow_new, int allow_day, int allow_week, int allow_month, - int year, int month, int day) -{ - GtkWidget *menu; - static time_t t; - - menu = get_popup_menu (yv); - - /* Enable/disable items as appropriate */ - - gtk_widget_set_sensitive (yv_popup_menu[0].widget, allow_new); - gtk_widget_set_sensitive (yv_popup_menu[2].widget, allow_day); - gtk_widget_set_sensitive (yv_popup_menu[3].widget, allow_week); - gtk_widget_set_sensitive (yv_popup_menu[4].widget, allow_month); - - /* Set the day item relevant to the context */ - - t = time_from_day (year, month, day); - - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[0].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[2].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[3].widget), "time_data", &t); - gtk_object_set_data (GTK_OBJECT (yv_popup_menu[4].widget), "time_data", &t); - - gnome_popup_menu_do_popup (menu, NULL, NULL, event, yv); -} - -/* Creates the quick view when the user clicks on a day */ -static void -do_quick_view_popup (YearView *yv, GdkEventButton *event, int year, int month, int day) -{ - time_t day_start, day_end; - GList *list; - GtkWidget *qv; - char date_str[256]; - - day_start = time_from_day (year, month, day); - day_end = time_day_end (day_start); - - list = calendar_get_events_in_range (yv->calendar->cal, day_start, day_end); - - strftime (date_str, sizeof (date_str), "%a %b %d %Y", localtime (&day_start)); - qv = quick_view_new (yv->calendar, date_str, list); - - quick_view_do_popup (QUICK_VIEW (qv), event); - - gtk_widget_destroy (qv); - calendar_destroy_event_list (list); -} - -/* Event handler for days in the year's month items */ -static gint -day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - int child_num, day; - - mitem = GNOME_MONTH_ITEM (data); - child_num = gnome_month_item_child2num (mitem, item); - day = gnome_month_item_num2day (mitem, child_num); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (day == 0) - break; - - if (event->button.button == 1) { - do_quick_view_popup (yv, (GdkEventButton *) event, mitem->year, mitem->month, day); - return TRUE; - } else if (event->button.button == 3) { - do_popup_menu (yv, (GdkEventButton *) event, TRUE, TRUE, TRUE, TRUE, - mitem->year, mitem->month, day); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - } - - break; - - default: - break; - } - - return FALSE; -} - -/* Event handler for whole month items */ -static gint -month_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data) -{ - YearView *yv; - GnomeMonthItem *mitem; - - mitem = GNOME_MONTH_ITEM (item); - - yv = YEAR_VIEW (item->canvas); - - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button != 3) - break; - - do_popup_menu (yv, (GdkEventButton *) event, FALSE, FALSE, FALSE, TRUE, - mitem->year, mitem->month, 1); - - /* We have to stop the signal emission because mark.c will grab it too and - * set the return value to FALSE. Blargh. - */ - gtk_signal_emit_stop_by_name (GTK_OBJECT (item), "event"); - return TRUE; - - default: - break; - } - - return FALSE; -} - -/* Sets up the month item with the specified index -- connects signals for handling events, etc. */ -static void -setup_month_item (YearView *yv, int n) -{ - GnomeCanvasItem *mitem; - GnomeCanvasItem *item; - int i; - - mitem = yv->mitems[n]; - - /* Connect the day signals */ - - for (i = 0; i < 42; i++) { - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_GROUP + i); - gtk_signal_connect (GTK_OBJECT (item), "event", - (GtkSignalFunc) day_event, - mitem); - } - - /* Connect the month signals */ - - gtk_signal_connect (GTK_OBJECT (mitem), "event", - (GtkSignalFunc) month_event, - NULL); - - /* Prepare for prelighting */ - - month_item_prepare_prelight (GNOME_MONTH_ITEM (mitem), default_color_func, NULL); -} - -/* Computes the minimum size for the year view and stores it in its internal fields */ -static void -compute_min_size (YearView *yv) -{ - GtkArg args[2]; - double m_width; - double m_height; - double max_width; - double w; - int i; - - /* Compute the minimum size of the year heading */ - - args[0].name = "text_width"; - args[1].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->heading), 2, args); - - m_width = GTK_VALUE_DOUBLE (args[0]); - m_height = 2 * HEAD_SPACING + GTK_VALUE_DOUBLE (args[1]); - - /* Add height of month titles and their spacings */ - - args[0].name = "text_height"; - gtk_object_getv (GTK_OBJECT (yv->titles[0]), 1, &args[0]); - - m_height += 4 * (GTK_VALUE_DOUBLE (args[0]) + TITLE_SPACING); - - /* Add width of month titles */ - - max_width = 0.0; - - for (i = 0; i < 12; i++) { - args[0].name = "text_width"; - gtk_object_getv (GTK_OBJECT (yv->titles[i]), 1, &args[0]); - - w = GTK_VALUE_DOUBLE (args[0]); - if (max_width < w) - max_width = w; - } - - max_width = 3 * max_width + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add width of month items */ - - args[0].name = "width"; - args[1].name = "height"; - gtk_object_getv (GTK_OBJECT (yv->mitems[0]), 2, args); - - max_width = 3 * GTK_VALUE_DOUBLE (args[0]) + 2 * SPACING; - - if (m_width < max_width) - m_width = max_width; - - /* Add height of month items */ - - m_height += 4 * GTK_VALUE_DOUBLE (args[1]) + 3 * SPACING; - - /* Finally, set the minimum width and height in the year view */ - - yv->min_width = (int) (m_width + 0.5); - yv->min_height = (int) (m_height + 0.5); -} - -static void -year_view_init (YearView *yv) -{ - int i; - char buf[100]; - struct tm tm; - - memset (&tm, 0, sizeof (tm)); - - /* Heading */ - - yv->heading = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "anchor", GTK_ANCHOR_N, - "font", HEADING_FONT, - "fill_color", "black", - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) { - /* Title */ - - strftime (buf, 100, "%B", &tm); - tm.tm_mon++; - - yv->titles[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)), - gnome_canvas_text_get_type (), - "text", buf, - "anchor", GTK_ANCHOR_N, - "font", TITLE_FONT, - "fill_color", "black", - NULL); - - /* Month item */ - - yv->mitems[i] = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (yv))); - gnome_canvas_item_set (yv->mitems[i], - "anchor", GTK_ANCHOR_NW, - "start_on_monday", week_starts_on_monday, - "heading_font", DAY_HEADING_FONT, - "day_font", NORMAL_DAY_FONT, - NULL); - setup_month_item (yv, i); - } - - /* We will need to resize the items when we paint for the first time */ - - yv->old_marked_day = -1; - yv->idle_id = -1; - need_resize (yv); -} - -static void -year_view_destroy (GtkObject *object) -{ - YearView *yv; - - g_return_if_fail (object != NULL); - g_return_if_fail (IS_YEAR_VIEW (object)); - - yv = YEAR_VIEW (object); - - if (yv->need_resize) { - yv->need_resize = FALSE; - gtk_idle_remove (yv->idle_id); - } - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -GtkWidget * -year_view_new (GnomeCalendar *calendar, time_t year) -{ - YearView *yv; - - g_return_val_if_fail (calendar != NULL, NULL); - g_return_val_if_fail (GNOME_IS_CALENDAR (calendar), NULL); - - yv = gtk_type_new (year_view_get_type ()); - yv->calendar = calendar; - - year_view_colors_changed (yv); - year_view_set (yv, year); - compute_min_size (yv); - return GTK_WIDGET (yv); -} - -static void -year_view_size_request (GtkWidget *widget, GtkRequisition *requisition) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (requisition != NULL); - - yv = YEAR_VIEW (widget); - - requisition->width = yv->min_width; - requisition->height = yv->min_height; -} - -static void -year_view_size_allocate (GtkWidget *widget, GtkAllocation *allocation) -{ - YearView *yv; - - g_return_if_fail (widget != NULL); - g_return_if_fail (IS_YEAR_VIEW (widget)); - g_return_if_fail (allocation != NULL); - - yv = YEAR_VIEW (widget); - - if (GTK_WIDGET_CLASS (parent_class)->size_allocate) - (* GTK_WIDGET_CLASS (parent_class)->size_allocate) (widget, allocation); - - gnome_canvas_set_scroll_region (GNOME_CANVAS (yv), 0, 0, allocation->width, allocation->height); - need_resize (yv); -} - -void -year_view_update (YearView *yv, iCalObject *object, int flags) -{ - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - /* If only the summary changed, we don't care */ - - if (object && ((flags & CHANGE_SUMMARY) == flags)) - return; - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -/* Unmarks the old day that was marked as current and marks the current day if appropriate */ -static void -mark_current_day (YearView *yv) -{ - time_t t; - struct tm *tm; - int month_index, day_index; - GnomeCanvasItem *item; - - /* Unmark the old day */ - - if (yv->old_marked_day != -1) { - month_index = yv->old_marked_day / 42; - day_index = yv->old_marked_day % 42; - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_DAY_FG), - "font", NORMAL_DAY_FONT, - NULL); - - yv->old_marked_day = -1; - } - - /* Mark the new day */ - - t = time (NULL); - tm = localtime (&t); - - if ((tm->tm_year + 1900) == yv->year) { - month_index = tm->tm_mon; - day_index = gnome_month_item_day2index (GNOME_MONTH_ITEM (yv->mitems[month_index]), tm->tm_mday); - g_assert (day_index != -1); - - item = gnome_month_item_num2child (GNOME_MONTH_ITEM (yv->mitems[month_index]), - GNOME_MONTH_ITEM_DAY_LABEL + day_index); - gnome_canvas_item_set (item, - "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG), - "font", CURRENT_DAY_FONT, - NULL); - - yv->old_marked_day = month_index * 42 + day_index; - } -} - -void -year_view_set (YearView *yv, time_t year) -{ - struct tm *tm; - char buf[100]; - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - tm = localtime (&year); - yv->year = tm->tm_year + 1900; - - /* Heading */ - - sprintf (buf, "%d", yv->year); - gnome_canvas_item_set (yv->heading, - "text", buf, - NULL); - - /* Months */ - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "year", yv->year, - "month", i, - NULL); - - /* 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); - } - - mark_current_day (yv); -} - -void -year_view_time_format_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) - gnome_canvas_item_set (yv->mitems[i], - "start_on_monday", week_starts_on_monday, - NULL); - - year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1))); -} - -void -year_view_colors_changed (YearView *yv) -{ - int i; - - g_return_if_fail (yv != NULL); - g_return_if_fail (IS_YEAR_VIEW (yv)); - - for (i = 0; i < 12; i++) { - colorify_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), default_color_func, NULL); - mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal); - } - - mark_current_day (yv); -} diff --git a/calendar/gui/year-view.h b/calendar/gui/year-view.h deleted file mode 100644 index 77e63366d5..0000000000 --- a/calendar/gui/year-view.h +++ /dev/null @@ -1,77 +0,0 @@ -/* Year view display for Gnomecal - * - * Copyright (C) 1998 The Free Software Foundation - * - * Authors: Arturo Espinosa <arturo@nuclecu.unam.mx> - * Federico Mena <federico@nuclecu.unam.mx> - */ - -#ifndef YEAR_VIEW_H -#define YEAR_VIEW_H - -#include <libgnome/gnome-defs.h> -#include "gnome-cal.h" -#include "gnome-month-item.h" - - -BEGIN_GNOME_DECLS - - -#define TYPE_YEAR_VIEW (year_view_get_type ()) -#define YEAR_VIEW(obj) (GTK_CHECK_CAST ((obj), TYPE_YEAR_VIEW, YearView)) -#define YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), TYPE_YEAR_VIEW, YearViewClass)) -#define IS_YEAR_VIEW(obj) (GTK_CHECK_TYPE ((obj), TYPE_YEAR_VIEW)) -#define IS_YEAR_VIEW_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), TYPE_YEAR_VIEW)) - - -typedef struct _YearView YearView; -typedef struct _YearViewClass YearViewClass; - -struct _YearView { - GnomeCanvas canvas; - - GnomeCalendar *calendar; /* The calendar we are associated to */ - - int year; /* The year we are displaying */ - - GnomeCanvasItem *heading; /* Big heading with year */ - GnomeCanvasItem *titles[12]; /* Titles for months */ - GnomeCanvasItem *mitems[12]; /* Month items */ - - int old_marked_day; /* The day that is marked as the current day */ - - int min_width; /* Minimum dimensions of year view, used for size_request*/ - int min_height; - - guint idle_id; /* ID of idle handler for resize */ - - int need_resize : 1; /* Specifies whether we need to resize the canvas items or not */ -}; - -struct _YearViewClass { - GnomeCanvasClass parent_class; -}; - - -/* Standard Gtk function */ -GtkType year_view_get_type (void); - -/* Creates a new year view widget associated to the specified calendar */ -GtkWidget *year_view_new (GnomeCalendar *calendar, time_t year); - -/* Notifies the year view that a calendar object has changed */ -void year_view_update (YearView *yv, iCalObject *ico, int flags); - -/* Notifies the year view about a change of date */ -void year_view_set (YearView *yv, time_t year); - -/* Notifies the year view that the time format has changed */ -void year_view_time_format_changed (YearView *yv); - -/* Notifies the year view that colors have changed */ -void year_view_colors_changed (YearView *yv); - - -END_GNOME_DECLS - -#endif |