[evolution] Bug #251694 - Highlight current day in a calendar



commit 266d51479ab6bc1fb2afddf73ef275047e6ced37
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jul 3 16:17:28 2009 +0200

    Bug #251694 - Highlight current day in a calendar

 calendar/gui/e-calendar-view.c       |   23 +++++++++++++++++++++++
 calendar/gui/e-calendar-view.h       |    2 ++
 calendar/gui/e-day-view-main-item.c  |   17 +++++++++++++++--
 calendar/gui/e-day-view.c            |    1 +
 calendar/gui/e-day-view.h            |    1 +
 calendar/gui/e-week-view-main-item.c |   31 +++++++++++++++++--------------
 calendar/gui/e-week-view.c           |    1 +
 calendar/gui/e-week-view.h           |    1 +
 8 files changed, 61 insertions(+), 16 deletions(-)
---
diff --git a/calendar/gui/e-calendar-view.c b/calendar/gui/e-calendar-view.c
index 07e067e..8cab14b 100644
--- a/calendar/gui/e-calendar-view.c
+++ b/calendar/gui/e-calendar-view.c
@@ -2686,3 +2686,26 @@ e_calendar_utils_show_info_silent (GtkWidget *widget)
 
 	e_activity_handler_make_error (handler, "calendar", E_LOG_WARNINGS, widget);
 }
+
+/* returns either light or dark yellow, based on the base_background,
+   which is the default background color */
+GdkColor
+get_today_background (const GdkColor base_background)
+{
+	GdkColor res = base_background;
+
+	if (res.red > 0x7FFF) {
+		/* light yellow for a light theme */
+		res.red   = 0xFFFF;
+		res.green = 0xFFFF;
+		res.blue  = 0xC0C0;
+	} else {
+		/* dark yellow for a dark theme */
+		res.red   = 0x3F3F;
+		res.green = 0x3F3F;
+		res.blue  = 0x0000;
+	}
+
+	return res;
+}
+
diff --git a/calendar/gui/e-calendar-view.h b/calendar/gui/e-calendar-view.h
index 57cc811..4d33fcb 100644
--- a/calendar/gui/e-calendar-view.h
+++ b/calendar/gui/e-calendar-view.h
@@ -188,6 +188,8 @@ void           draw_curved_rectangle (cairo_t *cr,
                                       double rect_height,
                                       double radius);
 
+GdkColor get_today_background (GdkColor event_background);
+
 G_END_DECLS
 
 #endif
diff --git a/calendar/gui/e-day-view-main-item.c b/calendar/gui/e-day-view-main-item.c
index 48830be..faed90a 100644
--- a/calendar/gui/e-day-view-main-item.c
+++ b/calendar/gui/e-day-view-main-item.c
@@ -175,9 +175,10 @@ e_day_view_main_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable,
 	gint work_day_start_y, work_day_end_y;
 	gint day_x, day_w, work_day;
 	gint start_row, end_row, rect_x, rect_y, rect_width, rect_height;
-	struct icaltimetype day_start_tt;
+	struct icaltimetype day_start_tt, today_tt;
 	gint weekday;
 	cairo_t *cr;
+	gboolean today = FALSE;
 
 	cr = gdk_cairo_create (drawable);
 
@@ -197,6 +198,9 @@ e_day_view_main_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable,
 	gc = day_view->main_gc;
 	work_day_end_y = e_day_view_convert_time_to_position (day_view, day_view->work_day_end_hour, day_view->work_day_end_minute) - y;
 
+	today_tt = icaltime_from_timet_with_zone (time (NULL), FALSE,
+						  e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
+
 	for (day = 0; day < day_view->days_shown; day++) {
 		day_start_tt = icaltime_from_timet_with_zone (day_view->day_starts[day], FALSE,
 							      e_calendar_view_get_timezone (E_CALENDAR_VIEW (day_view)));
@@ -216,8 +220,17 @@ e_day_view_main_item_draw (GnomeCanvasItem *canvas_item, GdkDrawable *drawable,
 			cairo_fill (cr);
 			cairo_restore (cr);
 
+			if (day_view->days_shown > 1) {
+				/* Check if we are drawing today */
+				today =  day_start_tt.year == today_tt.year
+					&& day_start_tt.month == today_tt.month
+					&& day_start_tt.day == today_tt.day;
+			} else {
+				today = FALSE;
+			}
+
 			cairo_save (cr);
-			gdk_cairo_set_source_color (cr, &day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING]);
+			gdk_cairo_set_source_color (cr, &day_view->colors[today ? E_DAY_VIEW_COLOR_BG_MULTIDAY_TODAY : E_DAY_VIEW_COLOR_BG_WORKING]);
 
 			cairo_rectangle (cr, day_x, work_day_start_y, day_w,
 					work_day_end_y - work_day_start_y);
diff --git a/calendar/gui/e-day-view.c b/calendar/gui/e-day-view.c
index ef9e9b1..6099a7d 100644
--- a/calendar/gui/e-day-view.c
+++ b/calendar/gui/e-day-view.c
@@ -1193,6 +1193,7 @@ e_day_view_set_colors(EDayView *day_view, GtkWidget *widget)
 	day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED] = widget->style->base[GTK_STATE_SELECTED];
 	day_view->colors[E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED] = widget->style->bg[GTK_STATE_SELECTED];
 	day_view->colors[E_DAY_VIEW_COLOR_BG_GRID] = widget->style->dark[GTK_STATE_NORMAL];
+	day_view->colors[E_DAY_VIEW_COLOR_BG_MULTIDAY_TODAY] = get_today_background (day_view->colors[E_DAY_VIEW_COLOR_BG_WORKING]);
 	day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS] = widget->style->dark[GTK_STATE_NORMAL];
 	day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED] = widget->style->bg[GTK_STATE_SELECTED];
 	day_view->colors[E_DAY_VIEW_COLOR_BG_TOP_CANVAS_GRID] = widget->style->light[GTK_STATE_NORMAL];
diff --git a/calendar/gui/e-day-view.h b/calendar/gui/e-day-view.h
index 2b3f11e..31b8949 100644
--- a/calendar/gui/e-day-view.h
+++ b/calendar/gui/e-day-view.h
@@ -143,6 +143,7 @@ typedef enum
 	E_DAY_VIEW_COLOR_BG_SELECTED,
 	E_DAY_VIEW_COLOR_BG_SELECTED_UNFOCUSSED,
 	E_DAY_VIEW_COLOR_BG_GRID,
+	E_DAY_VIEW_COLOR_BG_MULTIDAY_TODAY,
 
 	E_DAY_VIEW_COLOR_BG_TOP_CANVAS,
 	E_DAY_VIEW_COLOR_BG_TOP_CANVAS_SELECTED,
diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c
index 35f56f4..47804cb 100644
--- a/calendar/gui/e-week-view-main-item.c
+++ b/calendar/gui/e-week-view-main-item.c
@@ -257,6 +257,17 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 		PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics)) +
 		E_WEEK_VIEW_DATE_LINE_T_PAD;
 
+	if (!today) {
+		struct icaltimetype tt;
+
+		/* Check if we are drawing today */
+		tt = icaltime_from_timet_with_zone (time (NULL), FALSE,
+						    e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
+		today = g_date_get_year (date) == tt.year
+			&& g_date_get_month (date) == tt.month
+			&& g_date_get_day (date) == tt.day;
+	}
+
 	working_days = calendar_config_get_working_days ();
 
 	/* Draw the background of the day. In the month view odd months are
@@ -264,7 +275,9 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 	   month starts (defaults are white for odd - January, March, ... and
 	   light gray for even). In the week view the background is always the
 	   same color, the color used for the odd months in the month view. */
-	if ((working_days & day_of_week) == 0)
+	if (today)
+		bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_TODAY_BACKGROUND];
+	else if ((working_days & day_of_week) == 0)
 		bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_MONTH_NONWORKING_DAY];
 	else if (week_view->multi_week_view && (month % 2 == 0))
 		bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS];
@@ -377,21 +390,11 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 	if (selected) {
 		gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED]);
 	} else if (week_view->multi_week_view) {
-		struct icaltimetype tt;
-
-		/* Check if we are drawing today */
-		tt = icaltime_from_timet_with_zone (time (NULL), FALSE,
-						    e_calendar_view_get_timezone (E_CALENDAR_VIEW (week_view)));
-		if (g_date_get_year (date) == tt.year
-		    && g_date_get_month (date) == tt.month
-		    && g_date_get_day (date) == tt.day) {
+		if (today) {
 			gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_TODAY]);
-			today = TRUE;
-		}
-		else {
+		} else {
 			gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]);
-
-			}
+		}
 	} else {
 		gdk_cairo_set_source_color (cr, &week_view->colors[E_WEEK_VIEW_COLOR_DATES]);
 	}
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 3db7e85..bcede69 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -775,6 +775,7 @@ e_week_view_set_colors(EWeekView *week_view, GtkWidget *widget)
 	week_view->colors[E_WEEK_VIEW_COLOR_DATES] = widget->style->text[GTK_STATE_NORMAL];
 	week_view->colors[E_WEEK_VIEW_COLOR_DATES_SELECTED] = widget->style->text[GTK_STATE_SELECTED];
 	week_view->colors[E_WEEK_VIEW_COLOR_TODAY] = widget->style->base[GTK_STATE_SELECTED];
+	week_view->colors[E_WEEK_VIEW_COLOR_TODAY_BACKGROUND] = get_today_background (week_view->colors[E_WEEK_VIEW_COLOR_EVENT_BACKGROUND]);
 	week_view->colors[E_WEEK_VIEW_COLOR_MONTH_NONWORKING_DAY] = color_inc (week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS], -0x0A0A);
 }
 
diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h
index 9ef7149..eff5466 100644
--- a/calendar/gui/e-week-view.h
+++ b/calendar/gui/e-week-view.h
@@ -105,6 +105,7 @@ typedef enum
 	E_WEEK_VIEW_COLOR_DATES,
 	E_WEEK_VIEW_COLOR_DATES_SELECTED,
 	E_WEEK_VIEW_COLOR_TODAY,
+	E_WEEK_VIEW_COLOR_TODAY_BACKGROUND,
 	E_WEEK_VIEW_COLOR_MONTH_NONWORKING_DAY,
 
 	E_WEEK_VIEW_COLOR_LAST



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]