From e2fbfd581d4bfc223f50af93fb48667e78f4398d Mon Sep 17 00:00:00 2001 From: Federico Mena Quintero Date: Fri, 3 Apr 1998 08:05:35 +0000 Subject: The "better" format string for strftime() wasn't better, after all :-( 1998-04-03 Federico Mena Quintero * view-utils.c (view_utils_draw_events): The "better" format string for strftime() wasn't better, after all :-( ... plus more work on progress svn path=/trunk/; revision=101 --- calendar/gui/gncal-full-day.c | 68 +++++++++++++++++++++++++++++++++++++++++-- calendar/gui/gnome-cal.c | 16 +++++++++- calendar/gui/view-utils.c | 6 ++-- 3 files changed, 83 insertions(+), 7 deletions(-) (limited to 'calendar/gui') diff --git a/calendar/gui/gncal-full-day.c b/calendar/gui/gncal-full-day.c index 4b4820417a..ba646d5a2e 100644 --- a/calendar/gui/gncal-full-day.c +++ b/calendar/gui/gncal-full-day.c @@ -158,6 +158,9 @@ get_tm_bounds (GncalFullDay *fullday, struct tm *lower, struct 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; + return (umin - lmin) / fullday->interval; /* number of rows in view */ } @@ -177,7 +180,7 @@ calc_labels_width (GncalFullDay *fullday) time_upper = mktime (&upper); while (tim < time_upper) { - strftime (buf, 256, "%R%p", &cur); + strftime (buf, 256, "%X", &cur); width = gdk_string_width (GTK_WIDGET (fullday)->style->font, buf); @@ -240,9 +243,13 @@ static void paint_back (GncalFullDay *fullday, GdkRectangle *area) { GtkWidget *widget; - GdkRectangle rect; + GdkRectangle rect, dest; int x1, y1, width, height; int labels_width, division_x; + int rows, row_height; + int i, y; + struct tm tm; + char buf[256]; widget = GTK_WIDGET (fullday); @@ -261,10 +268,24 @@ paint_back (GncalFullDay *fullday, GdkRectangle *area) widget->allocation.width, widget->allocation.height); - /* Vertical division */ + /* Clear space for labels */ labels_width = calc_labels_width (fullday); + rect.x = x1; + rect.y = y1; + rect.width = 2 * TEXT_BORDER + labels_width; + rect.height = height; + + if (gdk_rectangle_intersect (&rect, area, &dest)) + gdk_draw_rectangle (widget->window, + widget->style->bg_gc[GTK_STATE_NORMAL], + TRUE, + dest.x, dest.y, + dest.width, dest.height); + + /* Vertical division */ + division_x = x1 + 2 * TEXT_BORDER + labels_width; gtk_draw_vline (widget->style, widget->window, @@ -272,6 +293,47 @@ paint_back (GncalFullDay *fullday, GdkRectangle *area) y1, y1 + height - 1, division_x); + + /* Horizontal divisions */ + + rows = get_tm_bounds (fullday, &tm, NULL); + + row_height = height / rows; /* includes division line */ + + y = row_height; + + for (i = 1; i < rows; i++) { + gdk_draw_line (widget->window, + widget->style->black_gc, + x1, y, + x1 + width - 1, y); + + y += row_height; + } + + /* Labels */ + + y = y1 + ((row_height - 1) - (widget->style->font->ascent + widget->style->font->descent)) / 2; + + for (i = 0; i < rows; i++) { + mktime (&tm); + + if (gdk_rectangle_intersect (&rect, area, &dest)) { + strftime (buf, 256, "%X", &tm); + + gdk_draw_string (widget->window, + widget->style->font, + widget->style->fg_gc[GTK_STATE_NORMAL], + x1 + TEXT_BORDER, + y + widget->style->font->ascent, + buf); + } + + rect.y += row_height; + y += row_height; + + tm.tm_min += fullday->interval; + } } static gint diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c index ede2e0825d..7fa7a5e40d 100644 --- a/calendar/gui/gnome-cal.c +++ b/calendar/gui/gnome-cal.c @@ -52,7 +52,21 @@ setup_widgets (GnomeCalendar *gcal) task_view = tasks_create (gcal); { - day_view = gncal_full_day_new (gcal, time (NULL), time (NULL) + 86400); + struct tm tm; + time_t a, b; + + tm = *localtime (&now); + tm.tm_hour = 0; + tm.tm_min = 0; + tm.tm_sec = 0; + + a = mktime (&tm); + + tm.tm_mday++; + + b = mktime (&tm); + + day_view = gncal_full_day_new (gcal, a, b); } gtk_notebook_append_page (GTK_NOTEBOOK (notebook), day_view, gtk_label_new (_("Day View"))); diff --git a/calendar/gui/view-utils.c b/calendar/gui/view-utils.c index 0c661d9dd6..f5a3b41928 100644 --- a/calendar/gui/view-utils.c +++ b/calendar/gui/view-utils.c @@ -79,11 +79,11 @@ view_utils_draw_events (GtkWidget *widget, GdkWindow *window, GdkGC *gc, GdkRect str = ico->summary; if (flags & VIEW_UTILS_DRAW_END) { - strftime (buf, 512, "%R%p-", &tm_start); + strftime (buf, 512, "%X-", &tm_start); len = strlen (buf); - strftime (buf + len, 512 - len, "%R%p ", &tm_end); + strftime (buf + len, 512 - len, "%X ", &tm_end); } else - strftime (buf, 512, "%R%p ", &tm_start); + strftime (buf, 512, "%X ", &tm_start); gdk_draw_string (window, widget->style->font, -- cgit