[evolution] Bug #236996 - Calendar display for weekends in month view



commit 044adbe76a1bf09d83ece2ad7944d1d549fa4f34
Author: Milan Crha <mcrha redhat com>
Date:   Fri Jul 3 14:15:16 2009 +0200

    Bug #236996 - Calendar display for weekends in month view

 calendar/gui/e-week-view-main-item.c |   28 ++++++++++++++++++++++++++--
 calendar/gui/e-week-view.c           |   22 ++++++++++++++++++++++
 calendar/gui/e-week-view.h           |    1 +
 3 files changed, 49 insertions(+), 2 deletions(-)
---
diff --git a/calendar/gui/e-week-view-main-item.c b/calendar/gui/e-week-view-main-item.c
index 34bbe0f..35f56f4 100644
--- a/calendar/gui/e-week-view-main-item.c
+++ b/calendar/gui/e-week-view-main-item.c
@@ -30,6 +30,7 @@
 #include <glib/gi18n.h>
 #include "e-week-view-main-item.h"
 #include "ea-calendar.h"
+#include "calendar-config.h"
 
 static void e_week_view_main_item_set_property	(GObject	 *object,
 						 guint		  property_id,
@@ -189,6 +190,23 @@ e_week_view_main_item_draw (GnomeCanvasItem  *canvas_item,
 	}
 }
 
+static gint
+gdate_to_cal_weekdays (GDateWeekday wd)
+{
+	switch (wd) {
+	case G_DATE_MONDAY: return CAL_MONDAY;
+	case G_DATE_TUESDAY: return CAL_TUESDAY;
+	case G_DATE_WEDNESDAY: return CAL_WEDNESDAY;
+	case G_DATE_THURSDAY: return CAL_THURSDAY;
+	case G_DATE_FRIDAY: return CAL_FRIDAY;
+	case G_DATE_SATURDAY: return CAL_SATURDAY;
+	case G_DATE_SUNDAY: return CAL_SUNDAY;
+	default: break;
+	}
+
+	return 0;
+}
+
 static void
 e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 				gint		   day,
@@ -205,7 +223,7 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 	gint right_edge, bottom_edge, date_width, date_x, line_y;
 	gboolean show_day_name, show_month_name, selected;
 	gchar buffer[128], *format_string;
-	gint month, day_of_month, max_width;
+	gint day_of_week, month, day_of_month, max_width;
 	GdkColor *bg_color;
 	PangoFontDescription *font_desc;
 	PangoContext *pango_context;
@@ -213,6 +231,7 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 	PangoLayout *layout;
 	gboolean today = FALSE;
 	cairo_t *cr;
+	CalWeekdays working_days;
 
 #if 0
 	g_print ("Drawing Day:%i at %i,%i\n", day, x, y);
@@ -230,6 +249,7 @@ e_week_view_main_item_draw_day (EWeekViewMainItem *wvmitem,
 
 	g_return_if_fail (gc != NULL);
 
+	day_of_week = gdate_to_cal_weekdays (g_date_get_weekday (date));
 	month = g_date_get_month (date);
 	day_of_month = g_date_get_day (date);
 	line_y = y + E_WEEK_VIEW_DATE_T_PAD +
@@ -237,12 +257,16 @@ 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;
 
+	working_days = calendar_config_get_working_days ();
+
 	/* Draw the background of the day. In the month view odd months are
 	   one color and even months another, so you can easily see when each
 	   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 (week_view->multi_week_view && (month % 2 == 0))
+	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];
 	else
 		bg_color = &week_view->colors[E_WEEK_VIEW_COLOR_ODD_MONTHS];
diff --git a/calendar/gui/e-week-view.c b/calendar/gui/e-week-view.c
index 7853add..3db7e85 100644
--- a/calendar/gui/e-week-view.c
+++ b/calendar/gui/e-week-view.c
@@ -740,6 +740,27 @@ e_week_view_realize (GtkWidget *widget)
 	week_view->meeting_icon = e_icon_factory_get_icon ("stock_people", GTK_ICON_SIZE_MENU);
 }
 
+static GdkColor
+color_inc (GdkColor c, gint amount)
+{
+	#define dec(x)				\
+		if (x + amount >= 0		\
+		    && x + amount <= 0xFFFF)	\
+			x += amount;		\
+		else if (amount <= 0)		\
+			x = 0;			\
+		else				\
+			x = 0xFFFF;
+
+	dec (c.red);
+	dec (c.green);
+	dec (c.blue);
+
+	#undef dec
+
+	return c;
+}
+
 static void
 e_week_view_set_colors(EWeekView *week_view, GtkWidget *widget)
 {
@@ -754,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_MONTH_NONWORKING_DAY] = color_inc (week_view->colors[E_WEEK_VIEW_COLOR_EVEN_MONTHS], -0x0A0A);
 }
 
 static void
diff --git a/calendar/gui/e-week-view.h b/calendar/gui/e-week-view.h
index 513dae2..9ef7149 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_MONTH_NONWORKING_DAY,
 
 	E_WEEK_VIEW_COLOR_LAST
 } EWeekViewColors;



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