diff options
Diffstat (limited to 'calendar')
29 files changed, 402 insertions, 220 deletions
diff --git a/calendar/ChangeLog b/calendar/ChangeLog index ae78b7afd9..f9c54bdaf7 100644 --- a/calendar/ChangeLog +++ b/calendar/ChangeLog @@ -1,5 +1,20 @@ 1998-04-16 Federico Mena Quintero <federico@nuclecu.unam.mx> + * eventedit.c (ee_store_alarm): Use menu_shell->children, not + menu->children. Why does GtkMenu have a children field in the + object structure? + (check_dates): New function that insures that start_date < end_date. + (check_times): In addition to checking whether the event spans the + whole day, now it insures that start_time < end_time. + + * gncal-full-day.c (child_set_size): Now children get bigger + temporarily while they are focused. This allows the handles not + to "overlap" the rows used by the child and thus allow editing of + very thin events. + (recompute_motion): Fix for new child coordinates. + (gncal_full_day_expose): Make it use find_child_by_window() + instead of looking for it by hand. + * bell.xpm recur.xpm: XPM files for events with alarm and recurrence, respectively. diff --git a/calendar/cal-util/calobj.c b/calendar/cal-util/calobj.c index a744836c89..8272fd1560 100644 --- a/calendar/cal-util/calobj.c +++ b/calendar/cal-util/calobj.c @@ -4,7 +4,7 @@ * * Authors: * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@gimp.org) + * Federico Mena (quartic@gimp.org) */ #include <string.h> #include <glib.h> diff --git a/calendar/cal-util/calobj.h b/calendar/cal-util/calobj.h index 684605b271..9b69eefd5f 100644 --- a/calendar/cal-util/calobj.h +++ b/calendar/cal-util/calobj.h @@ -2,7 +2,8 @@ * Internal representation of a Calendar object. This is modeled after the * iCalendar/vCalendar specificiation * - * Authors: Miguel de Icaza (miguel@gnu.org), Federico Mena (federico@gimp.org). + * Authors: Miguel de Icaza (miguel@gnu.org) + * Federico Mena (quartic@gimp.org). */ #ifndef CALOBJ_H #define CALOBJ_H diff --git a/calendar/calendar.c b/calendar/calendar.c index 9f9ef4dc51..dd0a5cca3f 100644 --- a/calendar/calendar.c +++ b/calendar/calendar.c @@ -8,7 +8,7 @@ * * Authors: * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@gimp.org) + * Federico Mena (quartic@gimp.org) * */ diff --git a/calendar/calobj.c b/calendar/calobj.c index a744836c89..8272fd1560 100644 --- a/calendar/calobj.c +++ b/calendar/calobj.c @@ -4,7 +4,7 @@ * * Authors: * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@gimp.org) + * Federico Mena (quartic@gimp.org) */ #include <string.h> #include <glib.h> diff --git a/calendar/calobj.h b/calendar/calobj.h index 684605b271..9b69eefd5f 100644 --- a/calendar/calobj.h +++ b/calendar/calobj.h @@ -2,7 +2,8 @@ * Internal representation of a Calendar object. This is modeled after the * iCalendar/vCalendar specificiation * - * Authors: Miguel de Icaza (miguel@gnu.org), Federico Mena (federico@gimp.org). + * Authors: Miguel de Icaza (miguel@gnu.org) + * Federico Mena (quartic@gimp.org). */ #ifndef CALOBJ_H #define CALOBJ_H diff --git a/calendar/eventedit.c b/calendar/eventedit.c index 5452d5694f..be308284aa 100644 --- a/calendar/eventedit.c +++ b/calendar/eventedit.c @@ -2,7 +2,8 @@ * EventEditor widget * Copyright (C) 1998 the Free Software Foundation * - * Author: Miguel de Icaza (miguel@kernel.org) + * Authors: Miguel de Icaza (miguel@kernel.org) + * Federico Mena (quartic@gimp.org) */ #include <gnome.h> @@ -53,22 +54,6 @@ event_editor_class_init (EventEditorClass *class) object_class->destroy = event_editor_destroy; } -/* - * when the start time is changed, this adjusts the end time. - */ -static void -adjust_end_time (GtkWidget *widget, 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); - if (tm->tm_hour < 22) - tm->tm_hour++; - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (tm)); -} - GtkWidget * adjust (GtkWidget *w, gfloat x, gfloat y, gfloat xs, gfloat ys) { @@ -90,19 +75,95 @@ ee_check_all_day (EventEditor *ee) 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){ + 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{ + 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 if the selected hour range spans all of the day + * Callback: checks that start_time < end_time and whether the + * selected hour range spans all of the day */ static void -check_times (GtkWidget *widget, EventEditor *ee) +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); } @@ -147,8 +208,8 @@ event_editor_setup_time_frame (EventEditor *ee) /* 1. Start time */ ee->start_time = start_time = gnome_date_edit_new (ee->ical->dtstart); gnome_date_edit_set_popup_range ((GnomeDateEdit *) start_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (start_time), "time_changed", - GTK_SIGNAL_FUNC (adjust_end_time), ee); + 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, @@ -163,6 +224,8 @@ event_editor_setup_time_frame (EventEditor *ee) /* 2. End time */ ee->end_time = end_time = gnome_date_edit_new (ee->ical->dtend); 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, @@ -371,7 +434,7 @@ ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type) item = gtk_menu_get_active (menu); - for (idx = 0, child = menu->children; child->data != item; child = child->next) + for (idx = 0, child = GTK_MENU_SHELL (menu)->children; child->data != item; child = child->next) idx++; alarm->units = idx; diff --git a/calendar/gncal-day-view.c b/calendar/gncal-day-view.c index 5337f0058b..d338802240 100644 --- a/calendar/gncal-day-view.c +++ b/calendar/gncal-day-view.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <gtk/gtksignal.h> diff --git a/calendar/gncal-day-view.h b/calendar/gncal-day-view.h index 564788fc81..dae1897fb6 100644 --- a/calendar/gncal-day-view.h +++ b/calendar/gncal-day-view.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef GNCAL_DAY_VIEW_H diff --git a/calendar/gncal-full-day.c b/calendar/gncal-full-day.c index 67756d0482..d7aecccfee 100644 --- a/calendar/gncal-full-day.c +++ b/calendar/gncal-full-day.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> @@ -260,9 +260,9 @@ child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, int draw_ch /* Left handle */ rect.x = 0; - rect.y = 0; + rect.y = has_focus ? HANDLE_SIZE : 0; rect.width = HANDLE_SIZE; - rect.height = has_focus ? (child->height - HANDLE_SIZE) : child->height; + 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); @@ -270,9 +270,9 @@ child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, int draw_ch if (has_focus) { /* Top handle */ - rect.x = HANDLE_SIZE; + rect.x = 0; rect.y = 0; - rect.width = child->width - HANDLE_SIZE; + rect.width = child->width; rect.height = HANDLE_SIZE; if (gdk_rectangle_intersect (&rect, area, &dest)) @@ -413,6 +413,58 @@ child_realized_setup (GtkWidget *widget, gpointer data) strlen (child->ico->summary)); } +static void +child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) +{ + 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, 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)) { + 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) { @@ -420,9 +472,7 @@ child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) child = data; - /* Paint handles on child */ - - child_set_text_pos (child); + child_set_size (child); return FALSE; } @@ -442,9 +492,7 @@ child_focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data) child->ico->summary = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); - /* Erase handles from child */ - - child_set_text_pos (child); + child_set_size (child); /* Notify calendar of change */ @@ -556,21 +604,6 @@ child_destroy (GncalFullDay *fullday, Child *child) g_free (child); } -static void -child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) -{ - 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, height); -} - static struct layout_row * layout_get_rows (GncalFullDay *fullday, int *rowcount) { @@ -607,12 +640,13 @@ layout_get_rows (GncalFullDay *fullday, int *rowcount) } static void -layout_kill_rows (struct layout_row *rows, int f_rows) +layout_free_rows (struct layout_row *rows, int f_rows) { int i; - + for (i = 0; i < f_rows; i++) - g_free (rows [i].slots); + g_free (rows[i].slots); + g_free (rows); } @@ -677,44 +711,22 @@ calc_labels_width (GncalFullDay *fullday) return max_w; } -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 layout_child (GncalFullDay *fullday, Child *child, struct layout_row *rows, int left_x) { - int c_y, c_width, c_height; GtkWidget *widget; - int row_height; - - /* Calculate child position */ widget = GTK_WIDGET (fullday); - row_height = calc_row_height (fullday); - - c_y = widget->style->klass->ythickness; + child->x = left_x; /* FIXME: for now, the children overlap. Make it layout them nicely. */ - c_width = widget->allocation.width - (widget->style->klass->xthickness + left_x); - - c_y += child->lower_row * row_height; - c_height = child->rows_used * row_height; + child->width = widget->allocation.width - (widget->style->klass->xthickness + left_x); /* Position child */ - child_set_pos (fullday, child, left_x, c_y, c_width, c_height); + child_set_size (child); } static void @@ -734,7 +746,7 @@ layout_children (GncalFullDay *fullday) for (children = fullday->children; children; children = children->next) layout_child (fullday, children->data, rows, left_x); - layout_kill_rows (rows, rowcount); + layout_free_rows (rows, rowcount); } guint @@ -1332,7 +1344,7 @@ draw_xor_rect (GncalFullDay *fullday) 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 * i - 2); + 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); @@ -1381,6 +1393,7 @@ button_1 (GncalFullDay *fullday, GdkEventButton *event) 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; @@ -1440,20 +1453,25 @@ button_1 (GncalFullDay *fullday, GdkEventButton *event) gtk_widget_get_pointer (widget, NULL, &y); - if (event->x < HANDLE_SIZE) + 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; - else if (event->y < HANDLE_SIZE) - di->drag_mode = DRAG_SIZE_TOP; - else - di->drag_mode = DRAG_SIZE_BOTTOM; row_height = calc_row_height (fullday); di->child = child; di->child_click_y = event->y; - di->child_start_row = get_row_from_y (fullday, child->y, FALSE); - di->child_rows_used = child->height / row_height; + di->child_start_row = child->lower_row; + di->child_rows_used = child->rows_used; gdk_pointer_grab (child->window, FALSE, (GDK_BUTTON_MOTION_MASK @@ -1535,6 +1553,7 @@ recompute_motion (GncalFullDay *fullday, int y) struct drag_info *di; int f_rows; int row; + int has_focus; di = fullday->drag_info; @@ -1558,7 +1577,9 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_MOVE: - row = get_row_from_y (fullday, y - di->child_click_y, TRUE); + 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; @@ -1568,7 +1589,7 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_SIZE_TOP: - row = get_row_from_y (fullday, y, TRUE); + 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; @@ -1579,7 +1600,7 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_SIZE_BOTTOM: - row = get_row_from_y (fullday, y, TRUE); + row = get_row_from_y (fullday, y - HANDLE_SIZE, TRUE); if (row <= di->child_start_row) row = di->child_start_row + 1; @@ -1748,8 +1769,8 @@ static gint gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) { GncalFullDay *fullday; - GList *children; Child *child; + int on_text; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); @@ -1762,15 +1783,12 @@ gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) if (event->window == widget->window) paint_back (fullday, &event->area); - else - for (children = fullday->children; children; children = children->next) { - child = children->data; + else { + child = find_child_by_window (fullday, event->window, &on_text); - if (event->window == child->window) { - child_draw (fullday, child, &event->area, FALSE); - break; - } - } + if (child && !on_text) + child_draw (fullday, child, &event->area, FALSE); + } return FALSE; } diff --git a/calendar/gncal-full-day.h b/calendar/gncal-full-day.h index 1e8e779582..ed4d0bf847 100644 --- a/calendar/gncal-full-day.h +++ b/calendar/gncal-full-day.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef GNCAL_FULL_DAY_H diff --git a/calendar/gncal-week-view.c b/calendar/gncal-week-view.c index 1cf35fac5f..e391c80344 100644 --- a/calendar/gncal-week-view.c +++ b/calendar/gncal-week-view.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> diff --git a/calendar/gncal-week-view.h b/calendar/gncal-week-view.h index 81bc44c816..9df1e35b91 100644 --- a/calendar/gncal-week-view.h +++ b/calendar/gncal-week-view.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef WEEK_VIEW_H diff --git a/calendar/gui/calendar.c b/calendar/gui/calendar.c index 9f9ef4dc51..dd0a5cca3f 100644 --- a/calendar/gui/calendar.c +++ b/calendar/gui/calendar.c @@ -8,7 +8,7 @@ * * Authors: * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@gimp.org) + * Federico Mena (quartic@gimp.org) * */ diff --git a/calendar/gui/eventedit.c b/calendar/gui/eventedit.c index 5452d5694f..be308284aa 100644 --- a/calendar/gui/eventedit.c +++ b/calendar/gui/eventedit.c @@ -2,7 +2,8 @@ * EventEditor widget * Copyright (C) 1998 the Free Software Foundation * - * Author: Miguel de Icaza (miguel@kernel.org) + * Authors: Miguel de Icaza (miguel@kernel.org) + * Federico Mena (quartic@gimp.org) */ #include <gnome.h> @@ -53,22 +54,6 @@ event_editor_class_init (EventEditorClass *class) object_class->destroy = event_editor_destroy; } -/* - * when the start time is changed, this adjusts the end time. - */ -static void -adjust_end_time (GtkWidget *widget, 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); - if (tm->tm_hour < 22) - tm->tm_hour++; - gnome_date_edit_set_time (GNOME_DATE_EDIT (ee->end_time), mktime (tm)); -} - GtkWidget * adjust (GtkWidget *w, gfloat x, gfloat y, gfloat xs, gfloat ys) { @@ -90,19 +75,95 @@ ee_check_all_day (EventEditor *ee) 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){ + 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{ + 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 if the selected hour range spans all of the day + * Callback: checks that start_time < end_time and whether the + * selected hour range spans all of the day */ static void -check_times (GtkWidget *widget, EventEditor *ee) +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); } @@ -147,8 +208,8 @@ event_editor_setup_time_frame (EventEditor *ee) /* 1. Start time */ ee->start_time = start_time = gnome_date_edit_new (ee->ical->dtstart); gnome_date_edit_set_popup_range ((GnomeDateEdit *) start_time, day_begin, day_end); - gtk_signal_connect (GTK_OBJECT (start_time), "time_changed", - GTK_SIGNAL_FUNC (adjust_end_time), ee); + 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, @@ -163,6 +224,8 @@ event_editor_setup_time_frame (EventEditor *ee) /* 2. End time */ ee->end_time = end_time = gnome_date_edit_new (ee->ical->dtend); 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, @@ -371,7 +434,7 @@ ee_store_alarm (CalendarAlarm *alarm, enum AlarmType type) item = gtk_menu_get_active (menu); - for (idx = 0, child = menu->children; child->data != item; child = child->next) + for (idx = 0, child = GTK_MENU_SHELL (menu)->children; child->data != item; child = child->next) idx++; alarm->units = idx; diff --git a/calendar/gui/gncal-day-view.c b/calendar/gui/gncal-day-view.c index 5337f0058b..d338802240 100644 --- a/calendar/gui/gncal-day-view.c +++ b/calendar/gui/gncal-day-view.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <gtk/gtksignal.h> diff --git a/calendar/gui/gncal-day-view.h b/calendar/gui/gncal-day-view.h index 564788fc81..dae1897fb6 100644 --- a/calendar/gui/gncal-day-view.h +++ b/calendar/gui/gncal-day-view.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef GNCAL_DAY_VIEW_H diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c index 67756d0482..d7aecccfee 100644 --- a/calendar/gui/gncal-full-day.c +++ b/calendar/gui/gncal-full-day.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> @@ -260,9 +260,9 @@ child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, int draw_ch /* Left handle */ rect.x = 0; - rect.y = 0; + rect.y = has_focus ? HANDLE_SIZE : 0; rect.width = HANDLE_SIZE; - rect.height = has_focus ? (child->height - HANDLE_SIZE) : child->height; + 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); @@ -270,9 +270,9 @@ child_draw (GncalFullDay *fullday, Child *child, GdkRectangle *area, int draw_ch if (has_focus) { /* Top handle */ - rect.x = HANDLE_SIZE; + rect.x = 0; rect.y = 0; - rect.width = child->width - HANDLE_SIZE; + rect.width = child->width; rect.height = HANDLE_SIZE; if (gdk_rectangle_intersect (&rect, area, &dest)) @@ -413,6 +413,58 @@ child_realized_setup (GtkWidget *widget, gpointer data) strlen (child->ico->summary)); } +static void +child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) +{ + 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, 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)) { + 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) { @@ -420,9 +472,7 @@ child_focus_in (GtkWidget *widget, GdkEventFocus *event, gpointer data) child = data; - /* Paint handles on child */ - - child_set_text_pos (child); + child_set_size (child); return FALSE; } @@ -442,9 +492,7 @@ child_focus_out (GtkWidget *widget, GdkEventFocus *event, gpointer data) child->ico->summary = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); - /* Erase handles from child */ - - child_set_text_pos (child); + child_set_size (child); /* Notify calendar of change */ @@ -556,21 +604,6 @@ child_destroy (GncalFullDay *fullday, Child *child) g_free (child); } -static void -child_set_pos (GncalFullDay *fullday, Child *child, int x, int y, int width, int height) -{ - 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, height); -} - static struct layout_row * layout_get_rows (GncalFullDay *fullday, int *rowcount) { @@ -607,12 +640,13 @@ layout_get_rows (GncalFullDay *fullday, int *rowcount) } static void -layout_kill_rows (struct layout_row *rows, int f_rows) +layout_free_rows (struct layout_row *rows, int f_rows) { int i; - + for (i = 0; i < f_rows; i++) - g_free (rows [i].slots); + g_free (rows[i].slots); + g_free (rows); } @@ -677,44 +711,22 @@ calc_labels_width (GncalFullDay *fullday) return max_w; } -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 layout_child (GncalFullDay *fullday, Child *child, struct layout_row *rows, int left_x) { - int c_y, c_width, c_height; GtkWidget *widget; - int row_height; - - /* Calculate child position */ widget = GTK_WIDGET (fullday); - row_height = calc_row_height (fullday); - - c_y = widget->style->klass->ythickness; + child->x = left_x; /* FIXME: for now, the children overlap. Make it layout them nicely. */ - c_width = widget->allocation.width - (widget->style->klass->xthickness + left_x); - - c_y += child->lower_row * row_height; - c_height = child->rows_used * row_height; + child->width = widget->allocation.width - (widget->style->klass->xthickness + left_x); /* Position child */ - child_set_pos (fullday, child, left_x, c_y, c_width, c_height); + child_set_size (child); } static void @@ -734,7 +746,7 @@ layout_children (GncalFullDay *fullday) for (children = fullday->children; children; children = children->next) layout_child (fullday, children->data, rows, left_x); - layout_kill_rows (rows, rowcount); + layout_free_rows (rows, rowcount); } guint @@ -1332,7 +1344,7 @@ draw_xor_rect (GncalFullDay *fullday) 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 * i - 2); + 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); @@ -1381,6 +1393,7 @@ button_1 (GncalFullDay *fullday, GdkEventButton *event) 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; @@ -1440,20 +1453,25 @@ button_1 (GncalFullDay *fullday, GdkEventButton *event) gtk_widget_get_pointer (widget, NULL, &y); - if (event->x < HANDLE_SIZE) + 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; - else if (event->y < HANDLE_SIZE) - di->drag_mode = DRAG_SIZE_TOP; - else - di->drag_mode = DRAG_SIZE_BOTTOM; row_height = calc_row_height (fullday); di->child = child; di->child_click_y = event->y; - di->child_start_row = get_row_from_y (fullday, child->y, FALSE); - di->child_rows_used = child->height / row_height; + di->child_start_row = child->lower_row; + di->child_rows_used = child->rows_used; gdk_pointer_grab (child->window, FALSE, (GDK_BUTTON_MOTION_MASK @@ -1535,6 +1553,7 @@ recompute_motion (GncalFullDay *fullday, int y) struct drag_info *di; int f_rows; int row; + int has_focus; di = fullday->drag_info; @@ -1558,7 +1577,9 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_MOVE: - row = get_row_from_y (fullday, y - di->child_click_y, TRUE); + 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; @@ -1568,7 +1589,7 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_SIZE_TOP: - row = get_row_from_y (fullday, y, TRUE); + 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; @@ -1579,7 +1600,7 @@ recompute_motion (GncalFullDay *fullday, int y) break; case DRAG_SIZE_BOTTOM: - row = get_row_from_y (fullday, y, TRUE); + row = get_row_from_y (fullday, y - HANDLE_SIZE, TRUE); if (row <= di->child_start_row) row = di->child_start_row + 1; @@ -1748,8 +1769,8 @@ static gint gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) { GncalFullDay *fullday; - GList *children; Child *child; + int on_text; g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GNCAL_IS_FULL_DAY (widget), FALSE); @@ -1762,15 +1783,12 @@ gncal_full_day_expose (GtkWidget *widget, GdkEventExpose *event) if (event->window == widget->window) paint_back (fullday, &event->area); - else - for (children = fullday->children; children; children = children->next) { - child = children->data; + else { + child = find_child_by_window (fullday, event->window, &on_text); - if (event->window == child->window) { - child_draw (fullday, child, &event->area, FALSE); - break; - } - } + if (child && !on_text) + child_draw (fullday, child, &event->area, FALSE); + } return FALSE; } diff --git a/calendar/gui/gncal-full-day.h b/calendar/gui/gncal-full-day.h index 1e8e779582..ed4d0bf847 100644 --- a/calendar/gui/gncal-full-day.h +++ b/calendar/gui/gncal-full-day.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef GNCAL_FULL_DAY_H diff --git a/calendar/gui/gncal-week-view.c b/calendar/gui/gncal-week-view.c index 1cf35fac5f..e391c80344 100644 --- a/calendar/gui/gncal-week-view.c +++ b/calendar/gui/gncal-week-view.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> diff --git a/calendar/gui/gncal-week-view.h b/calendar/gui/gncal-week-view.h index 81bc44c816..9df1e35b91 100644 --- a/calendar/gui/gncal-week-view.h +++ b/calendar/gui/gncal-week-view.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef WEEK_VIEW_H diff --git a/calendar/gui/view-utils.c b/calendar/gui/view-utils.c index f5a3b41928..1a5322228d 100644 --- a/calendar/gui/view-utils.c +++ b/calendar/gui/view-utils.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> diff --git a/calendar/gui/view-utils.h b/calendar/gui/view-utils.h index 6e934c0407..a1876b6032 100644 --- a/calendar/gui/view-utils.h +++ b/calendar/gui/view-utils.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef VIEW_UTILS_H diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c index 2960e39d35..8f5a786239 100644 --- a/calendar/gui/year-view.c +++ b/calendar/gui/year-view.c @@ -9,6 +9,7 @@ */ #include "gncal-year-view.h" +#include "timeutil.h" static void gncal_year_view_init (GncalYearView *yview); diff --git a/calendar/pcs/calobj.c b/calendar/pcs/calobj.c index a744836c89..8272fd1560 100644 --- a/calendar/pcs/calobj.c +++ b/calendar/pcs/calobj.c @@ -4,7 +4,7 @@ * * Authors: * Miguel de Icaza (miguel@gnu.org) - * Federico Mena (federico@gimp.org) + * Federico Mena (quartic@gimp.org) */ #include <string.h> #include <glib.h> diff --git a/calendar/pcs/calobj.h b/calendar/pcs/calobj.h index 684605b271..9b69eefd5f 100644 --- a/calendar/pcs/calobj.h +++ b/calendar/pcs/calobj.h @@ -2,7 +2,8 @@ * Internal representation of a Calendar object. This is modeled after the * iCalendar/vCalendar specificiation * - * Authors: Miguel de Icaza (miguel@gnu.org), Federico Mena (federico@gimp.org). + * Authors: Miguel de Icaza (miguel@gnu.org) + * Federico Mena (quartic@gimp.org). */ #ifndef CALOBJ_H #define CALOBJ_H diff --git a/calendar/view-utils.c b/calendar/view-utils.c index f5a3b41928..1a5322228d 100644 --- a/calendar/view-utils.c +++ b/calendar/view-utils.c @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #include <string.h> diff --git a/calendar/view-utils.h b/calendar/view-utils.h index 6e934c0407..a1876b6032 100644 --- a/calendar/view-utils.h +++ b/calendar/view-utils.h @@ -2,7 +2,7 @@ * * Copyright (C) 1998 The Free Software Foundation * - * Author: Federico Mena <federico@nuclecu.unam.mx> + * Author: Federico Mena <quartic@gimp.org> */ #ifndef VIEW_UTILS_H diff --git a/calendar/year-view.c b/calendar/year-view.c index 2960e39d35..8f5a786239 100644 --- a/calendar/year-view.c +++ b/calendar/year-view.c @@ -9,6 +9,7 @@ */ #include "gncal-year-view.h" +#include "timeutil.h" static void gncal_year_view_init (GncalYearView *yview); |