From e1635ef07ac4dbbb2511a01ed32ef096399d11fb Mon Sep 17 00:00:00 2001 From: Damon Chaplin Date: Wed, 29 Nov 2000 00:19:44 +0000 Subject: finished 12-hour support and tried to tidy up & comment the drawing code 2000-11-28 Damon Chaplin * gui/e-day-view*.[hc]: * gui/e-week-view*.[hc]: finished 12-hour support and tried to tidy up & comment the drawing code in places. Also fixed a couple of bugs I spotted. All the options on the 'Calendar' page should now work. svn path=/trunk/; revision=6706 --- calendar/gui/e-day-view-top-item.c | 119 ++++++++++++++++++++++++------------- 1 file changed, 79 insertions(+), 40 deletions(-) (limited to 'calendar/gui/e-day-view-top-item.c') diff --git a/calendar/gui/e-day-view-top-item.c b/calendar/gui/e-day-view-top-item.c index 8a85983592..a9ece2cc50 100644 --- a/calendar/gui/e-day-view-top-item.c +++ b/calendar/gui/e-day-view-top-item.c @@ -340,7 +340,9 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, gint text_x, icon_x, icon_y, icon_x_inc; CalComponent *comp; gchar buffer[16]; - gint hour, minute, offset, time_width, time_x, min_end_time_x; + gint hour, display_hour, minute, offset, time_width, time_x; + gint min_end_time_x, suffix_width, max_icon_x; + gchar *suffix; gboolean draw_start_triangle, draw_end_triangle; GdkRectangle clip_rect; @@ -435,45 +437,28 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, to take the scroll offset into account. It will always be 0. */ text_x = event->canvas_item->x1; - /* Draw the icons. */ - icon_x_inc = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD; - icon_x = text_x - icon_x_inc - x; - icon_y = item_y + 1 + E_DAY_VIEW_ICON_Y_PAD - y; - - if (cal_component_has_recurrences (comp)) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->recurrence_mask); - gdk_draw_pixmap (drawable, gc, - day_view->recurrence_icon, - 0, 0, icon_x, icon_y, - E_DAY_VIEW_ICON_WIDTH, - E_DAY_VIEW_ICON_HEIGHT); - icon_x -= icon_x_inc; - } - - if (cal_component_has_alarms (comp)) { - gdk_gc_set_clip_origin (gc, icon_x, icon_y); - gdk_gc_set_clip_mask (gc, day_view->reminder_mask); - gdk_draw_pixmap (drawable, gc, - day_view->reminder_icon, - 0, 0, icon_x, icon_y, - E_DAY_VIEW_ICON_WIDTH, - E_DAY_VIEW_ICON_HEIGHT); - icon_x -= icon_x_inc; - } - gdk_gc_set_clip_mask (gc, NULL); - - /* Draw the start & end times, if necessary. - Note that GtkLabel adds 1 to the ascent so we must do that to be - level with it. */ + /* Draw the start & end times, if necessary. */ min_end_time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; + time_width = e_day_view_get_time_string_width (day_view); + if (event->start > day_view->day_starts[start_day]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->start_minute; hour = offset / 60; minute = offset % 60; - sprintf (buffer, "%02i:%02i", hour, minute); + /* Calculate the actual hour number to display. For 12-hour + format we convert 0-23 to 12-11am/12-11pm. */ + e_day_view_convert_time_to_display (day_view, hour, + &display_hour, + &suffix, &suffix_width); + if (day_view->use_24_hour_format) { + g_snprintf (buffer, sizeof (buffer), "%2i:%02i", + display_hour, minute); + } else { + g_snprintf (buffer, sizeof (buffer), "%2i:%02i%s", + display_hour, minute, suffix); + } clip_rect.x = item_x - x; clip_rect.y = item_y - y; @@ -481,36 +466,90 @@ e_day_view_top_item_draw_long_event (EDayViewTopItem *dvtitem, clip_rect.height = item_h; gdk_gc_set_clip_rectangle (fg_gc, &clip_rect); + time_x = item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x; + if (hour < 10) + time_x += day_view->digit_width; + gdk_draw_string (drawable, font, fg_gc, - item_x + E_DAY_VIEW_LONG_EVENT_X_PAD - x, - item_y + E_DAY_VIEW_LONG_EVENT_Y_PAD + font->ascent + 1 - y, + time_x, + item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + + E_DAY_VIEW_LONG_EVENT_Y_PAD + + font->ascent - y, buffer); gdk_gc_set_clip_rectangle (fg_gc, NULL); - min_end_time_x += day_view->small_hour_widths[hour] + 2 - + day_view->max_minute_width + day_view->colon_width; + min_end_time_x += time_width + + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } + max_icon_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD + - E_DAY_VIEW_ICON_WIDTH; + if (event->end < day_view->day_starts[end_day + 1]) { offset = day_view->first_hour_shown * 60 + day_view->first_minute_shown + event->end_minute; hour = offset / 60; minute = offset % 60; - time_width = day_view->small_hour_widths[hour] - + day_view->max_minute_width + day_view->colon_width; time_x = item_x + item_w - E_DAY_VIEW_LONG_EVENT_X_PAD - time_width - E_DAY_VIEW_LONG_EVENT_TIME_X_PAD - x; if (time_x >= min_end_time_x) { - sprintf (buffer, "%02i:%02i", hour, minute); + /* Calculate the actual hour number to display. */ + e_day_view_convert_time_to_display (day_view, hour, + &display_hour, + &suffix, + &suffix_width); + if (day_view->use_24_hour_format) { + g_snprintf (buffer, sizeof (buffer), + "%2i:%02i", display_hour, minute); + } else { + g_snprintf (buffer, sizeof (buffer), + "%2i:%02i%s", display_hour, minute, + suffix); + } + + if (hour < 10) + time_x += day_view->digit_width; + gdk_draw_string (drawable, font, fg_gc, time_x, item_y + E_DAY_VIEW_LONG_EVENT_Y_PAD + font->ascent + 1 - y, buffer); + + max_icon_x -= time_width + E_DAY_VIEW_LONG_EVENT_TIME_X_PAD; } } + + /* Draw the icons. */ + icon_x_inc = E_DAY_VIEW_ICON_WIDTH + E_DAY_VIEW_ICON_X_PAD; + icon_x = text_x - icon_x_inc - x; + icon_y = item_y + E_DAY_VIEW_LONG_EVENT_BORDER_HEIGHT + + E_DAY_VIEW_ICON_Y_PAD - y; + + if (icon_x <= max_icon_x && cal_component_has_recurrences (comp)) { + gdk_gc_set_clip_origin (gc, icon_x, icon_y); + gdk_gc_set_clip_mask (gc, day_view->recurrence_mask); + gdk_draw_pixmap (drawable, gc, + day_view->recurrence_icon, + 0, 0, icon_x, icon_y, + E_DAY_VIEW_ICON_WIDTH, + E_DAY_VIEW_ICON_HEIGHT); + icon_x -= icon_x_inc; + } + + if (icon_x <= max_icon_x && cal_component_has_alarms (comp)) { + gdk_gc_set_clip_origin (gc, icon_x, icon_y); + gdk_gc_set_clip_mask (gc, day_view->reminder_mask); + gdk_draw_pixmap (drawable, gc, + day_view->reminder_icon, + 0, 0, icon_x, icon_y, + E_DAY_VIEW_ICON_WIDTH, + E_DAY_VIEW_ICON_HEIGHT); + icon_x -= icon_x_inc; + } + gdk_gc_set_clip_mask (gc, NULL); } -- cgit v1.2.3