aboutsummaryrefslogtreecommitdiffstats
path: root/calendar/gui
diff options
context:
space:
mode:
Diffstat (limited to 'calendar/gui')
-rw-r--r--calendar/gui/gnome-cal.c12
-rw-r--r--calendar/gui/gnome-cal.h3
-rw-r--r--calendar/gui/gnome-month-item.c144
-rw-r--r--calendar/gui/gnome-month-item.h6
-rw-r--r--calendar/gui/goto.c151
-rw-r--r--calendar/gui/main.c46
-rw-r--r--calendar/gui/main.h40
-rw-r--r--calendar/gui/mark.c44
-rw-r--r--calendar/gui/month-view.c14
-rw-r--r--calendar/gui/month-view.h3
-rw-r--r--calendar/gui/prop.c292
-rw-r--r--calendar/gui/year-view.c21
-rw-r--r--calendar/gui/year-view.h3
13 files changed, 604 insertions, 175 deletions
diff --git a/calendar/gui/gnome-cal.c b/calendar/gui/gnome-cal.c
index cf9dbefcc7..9f34a6277a 100644
--- a/calendar/gui/gnome-cal.c
+++ b/calendar/gui/gnome-cal.c
@@ -440,3 +440,15 @@ gnome_calendar_time_format_changed (GnomeCalendar *gcal)
month_view_time_format_changed (MONTH_VIEW (gcal->month_view));
year_view_time_format_changed (YEAR_VIEW (gcal->year_view));
}
+
+void
+gnome_calendar_colors_changed (GnomeCalendar *gcal)
+{
+ g_return_if_fail (gcal != NULL);
+ g_return_if_fail (GNOME_IS_CALENDAR (gcal));
+
+ /* FIXME: add day and week view when they are done */
+
+ month_view_colors_changed (MONTH_VIEW (gcal->month_view));
+ year_view_colors_changed (YEAR_VIEW (gcal->year_view));
+}
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index 186e90bc83..afe546be2d 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -67,6 +67,9 @@ void gnome_calendar_object_changed (GnomeCalendar *gcal,
/* Notifies the calendar that the time format has changed and it must update all its views */
void gnome_calendar_time_format_changed (GnomeCalendar *gcal);
+/* Notifies the calendar that the colors have changed and it must update all its views */
+void gnome_calendar_colors_changed (GnomeCalendar *gcal);
+
END_GNOME_DECLS
diff --git a/calendar/gui/gnome-month-item.c b/calendar/gui/gnome-month-item.c
index 289664e535..b1ef4925bf 100644
--- a/calendar/gui/gnome-month-item.c
+++ b/calendar/gui/gnome-month-item.c
@@ -62,6 +62,10 @@ enum {
ARG_DAY_FONT_GDK,
ARG_HEAD_COLOR,
ARG_HEAD_COLOR_GDK,
+ ARG_OUTLINE_COLOR,
+ ARG_OUTLINE_COLOR_GDK,
+ ARG_DAY_BOX_COLOR,
+ ARG_DAY_BOX_COLOR_GDK,
ARG_DAY_COLOR,
ARG_DAY_COLOR_GDK
};
@@ -136,6 +140,10 @@ gnome_month_item_class_init (GnomeMonthItemClass *class)
gtk_object_add_arg_type ("GnomeMonthItem::day_font_gdk", GTK_TYPE_GDK_FONT, GTK_ARG_READWRITE, ARG_DAY_FONT_GDK);
gtk_object_add_arg_type ("GnomeMonthItem::heading_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_HEAD_COLOR);
gtk_object_add_arg_type ("GnomeMonthItem::heading_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_HEAD_COLOR_GDK);
+ gtk_object_add_arg_type ("GnomeMonthItem::outline_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_OUTLINE_COLOR);
+ gtk_object_add_arg_type ("GnomeMonthItem::outline_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_OUTLINE_COLOR_GDK);
+ gtk_object_add_arg_type ("GnomeMonthItem::day_box_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_BOX_COLOR);
+ gtk_object_add_arg_type ("GnomeMonthItem::day_box_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_BOX_COLOR_GDK);
gtk_object_add_arg_type ("GnomeMonthItem::day_color", GTK_TYPE_STRING, GTK_ARG_WRITABLE, ARG_DAY_COLOR);
gtk_object_add_arg_type ("GnomeMonthItem::day_color_gdk", GTK_TYPE_GDK_COLOR, GTK_ARG_READWRITE, ARG_DAY_COLOR_GDK);
@@ -302,19 +310,26 @@ set_head_font (GnomeMonthItem *mitem)
NULL);
}
-/* Sets the color for all the day headings */
+/* Sets the color for all the headings */
static void
set_head_color (GnomeMonthItem *mitem)
{
int i;
- GdkColor color;
+ GdkColor outline;
+ GdkColor head;
- color.pixel = mitem->head_pixel;
+ outline.pixel = mitem->outline_pixel;
+ head.pixel = mitem->head_pixel;
+
+ for (i = 0; i < 7; i++) {
+ gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i],
+ "fill_color_gdk", &outline,
+ NULL);
- for (i = 0; i < 7; i++)
gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_HEAD_LABEL + i],
- "fill_color_gdk", &color,
+ "fill_color_gdk", &head,
NULL);
+ }
}
/* Creates the items for the day name headings */
@@ -336,7 +351,6 @@ create_headings (GnomeMonthItem *mitem)
mitem->items[GNOME_MONTH_ITEM_HEAD_BOX + i] =
gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_HEAD_GROUP + i]),
gnome_canvas_rect_get_type (),
- "fill_color", "black",
NULL);
/* Label */
@@ -491,19 +505,29 @@ set_day_font (GnomeMonthItem *mitem)
NULL);
}
-/* Sets the color for all the day numbers */
+/* Sets the color for all the day items */
static void
set_day_color (GnomeMonthItem *mitem)
{
int i;
- GdkColor color;
+ GdkColor outline;
+ GdkColor day_box;
+ GdkColor day;
- color.pixel = mitem->day_pixel;
+ outline.pixel = mitem->outline_pixel;
+ day_box.pixel = mitem->day_box_pixel;
+ day.pixel = mitem->day_pixel;
+
+ for (i = 0; i < 42; i++) {
+ gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i],
+ "outline_color_gdk", &outline,
+ "fill_color_gdk", &day_box,
+ NULL);
- for (i = 0; i < 42; i++)
gnome_canvas_item_set (mitem->items[GNOME_MONTH_ITEM_DAY_LABEL + i],
- "fill_color_gdk", &color,
+ "fill_color_gdk", &day,
NULL);
+ }
}
/* Creates the items for the days */
@@ -525,8 +549,6 @@ create_days (GnomeMonthItem *mitem)
mitem->items[GNOME_MONTH_ITEM_DAY_BOX + i] =
gnome_canvas_item_new (GNOME_CANVAS_GROUP (mitem->items[GNOME_MONTH_ITEM_DAY_GROUP + i]),
gnome_canvas_rect_get_type (),
- "outline_color", "black",
- "fill_color", "#d6d6d6d6d6d6",
NULL);
/* Label */
@@ -643,8 +665,10 @@ gnome_month_item_construct (GnomeMonthItem *mitem)
gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "#d6d6d6d6d6d6", &color);
mitem->head_pixel = color.pixel;
+ mitem->day_box_pixel = color.pixel;
gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, "black", &color);
+ mitem->outline_pixel = color.pixel;
mitem->day_pixel = color.pixel;
create_items (mitem);
@@ -733,13 +757,36 @@ reanchor (GnomeMonthItem *mitem)
NULL);
}
+/* Sets the color of the specified pixel value to that of the specified argument, which must be in
+ * GdkColor format if format is TRUE, otherwise it must be in string format.
+ */
+static void
+set_color_arg (GnomeMonthItem *mitem, gulong *pixel, GtkArg *arg, int gdk_format, int set_head, int set_day)
+{
+ GdkColor color;
+
+ if (gdk_format)
+ *pixel = ((GdkColor *) GTK_VALUE_BOXED (*arg))->pixel;
+ else {
+ if (gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, GTK_VALUE_STRING (*arg), &color))
+ *pixel = color.pixel;
+ else
+ *pixel = 0;
+ }
+
+ if (set_head)
+ set_head_color (mitem);
+
+ if (set_day)
+ set_day_color (mitem);
+}
+
static void
gnome_month_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
GnomeMonthItem *mitem;
char **day_names;
int i;
- GdkColor color;
mitem = GNOME_MONTH_ITEM (object);
@@ -873,31 +920,35 @@ gnome_month_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
break;
case ARG_HEAD_COLOR:
- if (gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, GTK_VALUE_STRING (*arg), &color))
- mitem->head_pixel = color.pixel;
- else
- mitem->head_pixel = 0;
-
- set_head_color (mitem);
+ set_color_arg (mitem, &mitem->head_pixel, arg, FALSE, TRUE, FALSE);
break;
case ARG_HEAD_COLOR_GDK:
- mitem->head_pixel = ((GdkColor *) GTK_VALUE_BOXED (*arg))->pixel;
- set_head_color (mitem);
+ set_color_arg (mitem, &mitem->head_pixel, arg, TRUE, TRUE, FALSE);
break;
- case ARG_DAY_COLOR:
- if (gnome_canvas_get_color (GNOME_CANVAS_ITEM (mitem)->canvas, GTK_VALUE_STRING (*arg), &color))
- mitem->day_pixel = color.pixel;
- else
- mitem->day_pixel = 0;
+ case ARG_OUTLINE_COLOR:
+ set_color_arg (mitem, &mitem->outline_pixel, arg, FALSE, TRUE, TRUE);
+ break;
- set_day_color (mitem);
+ case ARG_OUTLINE_COLOR_GDK:
+ set_color_arg (mitem, &mitem->outline_pixel, arg, TRUE, TRUE, TRUE);
+ break;
+
+ case ARG_DAY_BOX_COLOR:
+ set_color_arg (mitem, &mitem->day_box_pixel, arg, FALSE, FALSE, TRUE);
+ break;
+
+ case ARG_DAY_BOX_COLOR_GDK:
+ set_color_arg (mitem, &mitem->day_box_pixel, arg, TRUE, FALSE, TRUE);
+ break;
+
+ case ARG_DAY_COLOR:
+ set_color_arg (mitem, &mitem->day_pixel, arg, FALSE, FALSE, TRUE);
break;
case ARG_DAY_COLOR_GDK:
- mitem->day_pixel = ((GdkColor *) GTK_VALUE_BOXED (*arg))->pixel;
- set_day_color (mitem);
+ set_color_arg (mitem, &mitem->day_pixel, arg, TRUE, FALSE, TRUE);
break;
default:
@@ -905,11 +956,24 @@ gnome_month_item_set_arg (GtkObject *object, GtkArg *arg, guint arg_id)
}
}
+/* Allocates a GdkColor structure filled with the specified pixel, and puts it into the specified
+ * arg for returning it in the get_arg method.
+ */
+static void
+get_color_arg (GnomeMonthItem *mitem, gulong pixel, GtkArg *arg)
+{
+ GdkColor *color;
+
+ color = g_new (GdkColor, 1);
+ color->pixel = pixel;
+ gdk_color_context_query_color (GNOME_CANVAS_ITEM (mitem)->canvas->cc, color);
+ GTK_VALUE_BOXED (*arg) = color;
+}
+
static void
gnome_month_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
{
GnomeMonthItem *mitem;
- GdkColor *color;
mitem = GNOME_MONTH_ITEM (object);
@@ -975,17 +1039,19 @@ gnome_month_item_get_arg (GtkObject *object, GtkArg *arg, guint arg_id)
break;
case ARG_HEAD_COLOR_GDK:
- color = g_new (GdkColor, 1);
- color->pixel = mitem->head_pixel;
- gdk_color_context_query_color (GNOME_CANVAS_ITEM (mitem)->canvas->cc, color);
- GTK_VALUE_BOXED (*arg) = color;
+ get_color_arg (mitem, mitem->head_pixel, arg);
+ break;
+
+ case ARG_OUTLINE_COLOR_GDK:
+ get_color_arg (mitem, mitem->outline_pixel, arg);
+ break;
+
+ case ARG_DAY_BOX_COLOR_GDK:
+ get_color_arg (mitem, mitem->day_box_pixel, arg);
break;
case ARG_DAY_COLOR_GDK:
- color = g_new (GdkColor, 1);
- color->pixel = mitem->day_pixel;
- gdk_color_context_query_color (GNOME_CANVAS_ITEM (mitem)->canvas->cc, color);
- GTK_VALUE_BOXED (*arg) = color;
+ get_color_arg (mitem, mitem->day_pixel, arg);
break;
default:
diff --git a/calendar/gui/gnome-month-item.h b/calendar/gui/gnome-month-item.h
index d117aa85b5..f529d1724c 100644
--- a/calendar/gui/gnome-month-item.h
+++ b/calendar/gui/gnome-month-item.h
@@ -72,6 +72,10 @@ typedef enum {
* day_font_gdk GdkFont * RW Pointer to GdkFont for the day numbers
* heading_color string W X color specification for heading labels
* heading_color_gdk GdkColor * RW Pointer to an allocated GdkColor for heading labels
+ * outline_color string W X color specification for outline (lines and fill of heading boxes)
+ * outline_color_gdk GdkColor * RW Pointer to an allocated GdkColor for outline
+ * day_box_color string W X color specification for day boxes
+ * day_box_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day boxes
* day_color string W X color specification for day number labels
* day_color_gdk GdkColor * RW Pointer to an allocated GdkColor for day number labels
*/
@@ -112,6 +116,8 @@ struct _GnomeMonthItem {
GdkFont *day_font; /* Font for the day numbers */
gulong head_pixel; /* Color for heading labels */
+ gulong outline_pixel; /* Color for the outline (lines and heading boxes) */
+ gulong day_box_pixel; /* Color for the day boxes */
gulong day_pixel; /* Color for day number labels */
int start_on_monday : 1; /* Start the week on Monday? If false, then start from Sunday */
diff --git a/calendar/gui/goto.c b/calendar/gui/goto.c
index c312189ce7..16fada2f5b 100644
--- a/calendar/gui/goto.c
+++ b/calendar/gui/goto.c
@@ -14,35 +14,55 @@
#include "timeutil.h"
+static GtkWidget *goto_win; /* The goto dialog window */
+static GnomeCanvasItem *month_item; /* The month item in the dialog */
+static GnomeCalendar *gnome_calendar; /* The gnome calendar the dialog refers to */
+static gulong day_pixels[42]; /* Colors of the day backgrounds */
+
+
/* Updates the specified month item by marking it appropriately from the calendar the dialog refers
* to. */
static void
-update (GnomeMonthItem *mitem, GtkWidget *dialog)
+update (void)
{
- GnomeCalendar *gcal;
+ int i;
+ GnomeCanvasItem *item;
+ GtkArg arg;
+ GdkColor *c;
+
+ /* First, mark the days */
+
+ unmark_month_item (GNOME_MONTH_ITEM (month_item));
+ mark_month_item (GNOME_MONTH_ITEM (month_item), gnome_calendar->cal);
+
+ /* Now save the colors of the day backgrounds */
+
+ for (i = 0; i < 42; i++) {
+ arg.name = "fill_color_gdk";
- gcal = GNOME_CALENDAR (gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar"));
+ item = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item),
+ GNOME_MONTH_ITEM_DAY_BOX + i);
+ gtk_object_getv (GTK_OBJECT (item), 1, &arg);
- unmark_month_item (mitem);
- mark_month_item (mitem, gcal->cal);
+ c = GTK_VALUE_BOXED (arg);
+ day_pixels[i] = c->pixel;
+ g_free (c);
+ }
}
/* Callback used when the year adjustment is changed */
static void
-year_changed (GtkAdjustment *adj, GtkWidget *dialog)
+year_changed (GtkAdjustment *adj, gpointer data)
{
- GnomeCanvasItem *mitem;
-
- mitem = gtk_object_get_data (GTK_OBJECT (dialog), "month_item");
- gnome_canvas_item_set (mitem,
+ gnome_canvas_item_set (month_item,
"year", (int) adj->value,
NULL);
- update (GNOME_MONTH_ITEM (mitem), dialog);
+ update ();
}
/* Creates the year control with its adjustment */
static GtkWidget *
-create_year (GtkWidget *dialog, GnomeCalendar *gcal, int year)
+create_year (int year)
{
GtkWidget *hbox;
GtkAdjustment *adj;
@@ -57,7 +77,7 @@ create_year (GtkWidget *dialog, GnomeCalendar *gcal, int year)
adj = GTK_ADJUSTMENT (gtk_adjustment_new (year, 1900, 9999, 1, 10, 10));
gtk_signal_connect (GTK_OBJECT (adj), "value_changed",
(GtkSignalFunc) year_changed,
- dialog);
+ NULL);
w = gtk_spin_button_new (adj, 1.0, 0);
gtk_widget_set_usize (w, 60, 0);
@@ -71,23 +91,18 @@ create_year (GtkWidget *dialog, GnomeCalendar *gcal, int year)
static void
month_toggled (GtkToggleButton *toggle, gpointer data)
{
- GtkWidget *dialog;
- GnomeCanvasItem *mitem;
-
if (!toggle->active)
return;
- dialog = gtk_object_get_user_data (GTK_OBJECT (toggle));
- mitem = gtk_object_get_data (GTK_OBJECT (dialog), "month_item");
- gnome_canvas_item_set (mitem,
+ gnome_canvas_item_set (month_item,
"month", GPOINTER_TO_INT (data),
NULL);
- update (GNOME_MONTH_ITEM (mitem), dialog);
+ update ();
}
/* Creates the months control */
static GtkWidget *
-create_months (GtkWidget *dialog, GnomeCalendar *gcal, int month)
+create_months (int month)
{
GtkWidget *table;
GtkWidget *w;
@@ -96,7 +111,7 @@ create_months (GtkWidget *dialog, GnomeCalendar *gcal, int month)
struct tm tm;
char buf[100];
- tm = *localtime (&gcal->current_display);
+ tm = *localtime (&gnome_calendar->current_display);
table = gtk_table_new (2, 6, TRUE);
@@ -111,7 +126,6 @@ create_months (GtkWidget *dialog, GnomeCalendar *gcal, int month)
w = gtk_radio_button_new (group);
group = gtk_radio_button_group (GTK_RADIO_BUTTON (w));
- gtk_object_set_user_data (GTK_OBJECT (w), dialog);
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (w), FALSE);
gtk_container_add (GTK_CONTAINER (w), gtk_label_new (buf));
@@ -136,9 +150,9 @@ create_months (GtkWidget *dialog, GnomeCalendar *gcal, int month)
/* Sets the scrolling region of the canvas to the allocation size */
static void
-set_scroll_region (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+set_scroll_region (GtkWidget *widget, GtkAllocation *allocation)
{
- gnome_canvas_item_set (data,
+ gnome_canvas_item_set (month_item,
"width", (double) (allocation->width - 1),
"height", (double) (allocation->height - 1),
NULL);
@@ -155,18 +169,14 @@ set_scroll_region (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
static gint
day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
- GtkWidget *dialog;
- GnomeCalendar *gcal;
- GnomeMonthItem *mitem;
GnomeCanvasItem *box;
int child_num, day;
+ GdkColor color;
- dialog = GTK_WIDGET (data);
- gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
- mitem = gtk_object_get_data (GTK_OBJECT (dialog), "month_item");
+ child_num = gnome_month_item_child2num (GNOME_MONTH_ITEM (month_item), item);
+ day = gnome_month_item_num2day (GNOME_MONTH_ITEM (month_item), child_num);
- child_num = gnome_month_item_child2num (mitem, item);
- day = gnome_month_item_num2day (mitem, child_num);
+ child_num -= GNOME_MONTH_ITEM_DAY_GROUP;
if (day == 0)
return FALSE;
@@ -174,22 +184,27 @@ day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
switch (event->type) {
case GDK_BUTTON_PRESS:
if ((event->button.button == 1) && (day != 0)) {
- gnome_calendar_goto (gcal, time_from_day (mitem->year, mitem->month, day));
- gtk_widget_destroy (dialog);
+ gnome_calendar_goto (gnome_calendar,
+ time_from_day (GNOME_MONTH_ITEM (month_item)->year,
+ GNOME_MONTH_ITEM (month_item)->month, day));
+ gtk_widget_destroy (goto_win);
}
break;
case GDK_ENTER_NOTIFY:
- box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ box = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item),
+ child_num + GNOME_MONTH_ITEM_DAY_BOX);
gnome_canvas_item_set (box,
- "fill_color", "#ea60ea60ea60",
+ "fill_color", color_spec_from_prop (COLOR_PROP_PRELIGHT_DAY_BG),
NULL);
break;
case GDK_LEAVE_NOTIFY:
- box = gnome_month_item_num2child (mitem, child_num - GNOME_MONTH_ITEM_DAY_GROUP + GNOME_MONTH_ITEM_DAY_BOX);
+ box = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item),
+ child_num + GNOME_MONTH_ITEM_DAY_BOX);
+ color.pixel = day_pixels[child_num];
gnome_canvas_item_set (box,
- "fill_color", "#d6d6d6d6d6d6",
+ "fill_color_gdk", &color,
NULL);
break;
@@ -202,26 +217,22 @@ day_event (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
/* Creates the canvas with the month item for selecting days */
static GtkWidget *
-create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int year)
+create_days (int day, int month, int year)
{
GtkWidget *canvas;
- GnomeCanvasItem *mitem;
int i;
GnomeCanvasItem *day_group;
canvas = gnome_canvas_new ();
gnome_canvas_set_size (GNOME_CANVAS (canvas), 150, 120);
- mitem = gnome_month_item_new (GNOME_CANVAS_GROUP (GNOME_CANVAS (canvas)->root));
- gnome_canvas_item_set (mitem,
+ month_item = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (canvas)));
+ gnome_canvas_item_set (month_item,
"month", month,
"year", year,
"start_on_monday", week_starts_on_monday,
- "heading_color", "white",
NULL);
- update (GNOME_MONTH_ITEM (mitem), dialog);
-
- gtk_object_set_data (GTK_OBJECT (dialog), "month_item", mitem);
+ update ();
/* Connect to size_allocate so that we can change the size of the month item and the
* scrolling region appropriately.
@@ -229,15 +240,15 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
gtk_signal_connect (GTK_OBJECT (canvas), "size_allocate",
(GtkSignalFunc) set_scroll_region,
- mitem);
+ NULL);
/* Bind the day groups to our event handler */
for (i = 0; i < 42; i++) {
- day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), i + GNOME_MONTH_ITEM_DAY_GROUP);
+ day_group = gnome_month_item_num2child (GNOME_MONTH_ITEM (month_item), i + GNOME_MONTH_ITEM_DAY_GROUP);
gtk_signal_connect (GTK_OBJECT (day_group), "event",
(GtkSignalFunc) day_event,
- dialog);
+ NULL);
}
return canvas;
@@ -246,34 +257,28 @@ create_days (GtkWidget *dialog, GnomeCalendar *gcal, int day, int month, int yea
static void
goto_today (GtkWidget *widget, gpointer data)
{
- GtkWidget *dialog;
- GnomeCalendar *gcal;
-
- dialog = GTK_WIDGET (data);
- gcal = gtk_object_get_data (GTK_OBJECT (dialog), "gnome_calendar");
-
- gnome_calendar_goto_today (gcal);
- gtk_widget_destroy (dialog);
+ gnome_calendar_goto_today (gnome_calendar);
+ gtk_widget_destroy (goto_win);
}
/* Creates a "goto date" dialog and runs it */
void
goto_dialog (GnomeCalendar *gcal)
{
- GtkWidget *dialog;
GtkWidget *vbox;
GtkWidget *hbox;
GtkWidget *w;
struct tm *tm;
- tm = localtime (&gcal->current_display);
+ gnome_calendar = gcal;
+
+ tm = localtime (&gnome_calendar->current_display);
- dialog = gnome_dialog_new (_("Go to date"),
- GNOME_STOCK_BUTTON_CANCEL,
- NULL);
- gtk_object_set_data (GTK_OBJECT (dialog), "gnome_calendar", gcal);
+ goto_win = gnome_dialog_new (_("Go to date"),
+ GNOME_STOCK_BUTTON_CANCEL,
+ NULL);
- vbox = GNOME_DIALOG (dialog)->vbox;
+ vbox = GNOME_DIALOG (goto_win)->vbox;
/* Instructions */
@@ -287,19 +292,19 @@ goto_dialog (GnomeCalendar *gcal)
/* Year */
- w = create_year (dialog, gcal, tm->tm_year + 1900);
+ w = create_year (tm->tm_year + 1900);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
/* Month */
- w = create_months (dialog, gcal, tm->tm_mon);
+ w = create_months (tm->tm_mon);
gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
/* Days (canvas with month item) */
- w = create_days (dialog, gcal, tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
+ w = create_days (tm->tm_mday, tm->tm_mon, tm->tm_year + 1900);
gtk_box_pack_start (GTK_BOX (vbox), w, TRUE, TRUE, 0);
gtk_widget_show (w);
@@ -312,14 +317,14 @@ goto_dialog (GnomeCalendar *gcal)
w = gtk_button_new_with_label (_("Go to today"));
gtk_signal_connect (GTK_OBJECT (w), "clicked",
(GtkSignalFunc) goto_today,
- dialog);
+ NULL);
gtk_box_pack_start (GTK_BOX (hbox), w, FALSE, FALSE, 0);
gtk_widget_show (w);
/* Run! */
- gnome_dialog_set_modal (GNOME_DIALOG (dialog));
- gnome_dialog_set_close (GNOME_DIALOG (dialog), TRUE);
- gnome_dialog_set_parent (GNOME_DIALOG (dialog), GTK_WINDOW (gcal));
- gtk_widget_show (dialog);
+ gnome_dialog_set_modal (GNOME_DIALOG (goto_win));
+ gnome_dialog_set_close (GNOME_DIALOG (goto_win), TRUE);
+ gnome_dialog_set_parent (GNOME_DIALOG (goto_win), GTK_WINDOW (gnome_calendar));
+ gtk_widget_show (goto_win);
}
diff --git a/calendar/gui/main.c b/calendar/gui/main.c
index 066aac783c..5ccdeee3ff 100644
--- a/calendar/gui/main.c
+++ b/calendar/gui/main.c
@@ -42,7 +42,20 @@ int day_begin, day_end;
/* Whether weeks starts on Sunday or Monday */
int week_starts_on_monday;
-/* Number of calendars active */
+/* The array of color properties -- keep in sync with the enumeration defined in main.h. The color
+ * values specified here are the defaults for the program.
+ */
+struct color_prop color_props[] = {
+ { 0x0000, 0x0000, 0x0000, "Outline:", "/calendar/Colors/outline" },
+ { 0xffff, 0xffff, 0xffff, "Headings:", "/calendar/Colors/headings" },
+ { 0xd6d6, 0xd6d6, 0xd6d6, "Empty days:", "/calendar/Colors/empty_bg" },
+ { 0xd2d2, 0xb4b4, 0x8c8c, "Appointment days:", "/calendar/Colors/mark_bg" },
+ { 0xea60, 0xea60, 0xea60, "Highlighted day:", "/calendar/Colors/prelight_bg" },
+ { 0x0000, 0x0000, 0x0000, "Day numbers:", "/calendar/Colors/day_fg" },
+ { 0x0000, 0x0000, 0xffff, "Current day's number:", "/calendar/Colors/current_fg" }
+};
+
+/* Number of active calendars */
int active_calendars = 0;
/* A list of all of the calendars started */
@@ -105,10 +118,17 @@ range_check_hour (int hour)
static void
init_calendar (void)
{
+ int i;
+ char *cspec, *color;
+ char *str;
+
init_username ();
user_calendar_file = g_concat_dir_and_file (gnome_util_user_home (), ".gnome/user-cal.vcf");
gnome_config_push_prefix (calendar_settings);
+
+ /* Read calendar settings */
+
day_begin = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day start=8"));
day_end = range_check_hour (gnome_config_get_int ("/calendar/Calendar/Day end=17"));
am_pm_flag = gnome_config_get_bool ("/calendar/Calendar/AM PM flag=0");
@@ -119,6 +139,21 @@ init_calendar (void)
day_end = 17;
}
+ /* Read color settings */
+
+ for (i = 0; i < COLOR_PROP_LAST; i++) {
+ cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b);
+ str = g_copy_strings (color_props[i].key, "=", cspec, NULL);
+
+ color = gnome_config_get_string (str);
+ parse_color_spec (color, &color_props[i].r, &color_props[i].g, &color_props[i].b);
+
+ g_free (str);
+ g_free (color);
+ }
+
+ /* Done */
+
gnome_config_pop_prefix ();
}
@@ -197,6 +232,15 @@ time_format_changed (void)
gnome_calendar_time_format_changed (GNOME_CALENDAR (l->data));
}
+void
+colors_changed (void)
+{
+ GList *l;
+
+ for (l = all_calendars; l; l = l->next)
+ gnome_calendar_colors_changed (GNOME_CALENDAR (l->data));
+}
+
static void
quit_cmd (void)
{
diff --git a/calendar/gui/main.h b/calendar/gui/main.h
index 6f22f946f9..5cd0d1c5c4 100644
--- a/calendar/gui/main.h
+++ b/calendar/gui/main.h
@@ -1,13 +1,36 @@
#ifndef MAIN_H
#define MAIN_H
-/* Global preferences */
+/* Calendar preferences */
extern int day_begin, day_end;
extern char *user_name;
extern int am_pm_flag;
extern int week_starts_on_monday;
+/* This enum and the following array define the color preferences */
+
+enum {
+ COLOR_PROP_OUTLINE_COLOR, /* Color of calendar outline */
+ COLOR_PROP_HEADING_COLOR, /* Color for headings */
+ COLOR_PROP_EMPTY_DAY_BG, /* Background color for empty days */
+ COLOR_PROP_MARK_DAY_BG, /* Background color for days with appointments */
+ COLOR_PROP_PRELIGHT_DAY_BG, /* Background color for prelighted day */
+ COLOR_PROP_DAY_FG, /* Color for day numbers */
+ COLOR_PROP_CURRENT_DAY_FG, /* Color for current day's number */
+ COLOR_PROP_LAST /* Number of color properties */
+};
+
+struct color_prop {
+ int r; /* Values are in [0, 65535] */
+ int g;
+ int b;
+ char *label; /* Label for properties dialog */
+ char *key; /* Key for gnome_config */
+};
+
+extern struct color_prop color_props[];
+
/* Creates and runs the preferences dialog box */
void properties (void);
@@ -16,7 +39,22 @@ void properties (void);
*/
void time_format_changed (void);
+/* Asks for all the month items' colors to be reset */
+void colors_changed (void);
+
/* Creates and runs the Go-to date dialog */
void goto_dialog (GnomeCalendar *gcal);
+/* Returns a pointer to a statically-allocated string with a representation of the specified color.
+ * Values must be in [0, 65535].
+ */
+char *build_color_spec (int r, int g, int b);
+
+/* Parses a color specification of the form "#%04x%04x%04x" and returns the color components. */
+void parse_color_spec (char *spec, int *r, int *g, int *b);
+
+/* Calls build_color_spec() for the color in the specified property number */
+char *color_spec_from_prop (int propnum);
+
+
#endif
diff --git a/calendar/gui/mark.c b/calendar/gui/mark.c
index b1c6df8fa3..6aab8b1b74 100644
--- a/calendar/gui/mark.c
+++ b/calendar/gui/mark.c
@@ -6,6 +6,8 @@
*/
#include <config.h>
+#include "gnome-cal.h"
+#include "main.h"
#include "mark.h"
#include "timeutil.h"
@@ -34,14 +36,7 @@ mark_event_in_month (GnomeMonthItem *mitem, time_t start, time_t end)
item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_BOX + day_index);
gnome_canvas_item_set (item,
- "fill_color", "tan",
- NULL);
-
- /* Mark the day label */
-
- item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
- gnome_canvas_item_set (item,
- "fill_color", "black",
+ "fill_color", color_spec_from_prop (COLOR_PROP_MARK_DAY_BG),
NULL);
/* Next day */
@@ -65,7 +60,7 @@ mark_current_day (GnomeMonthItem *mitem)
day_index = gnome_month_item_day2index (mitem, tm->tm_mday);
item = gnome_month_item_num2child (mitem, GNOME_MONTH_ITEM_DAY_LABEL + day_index);
gnome_canvas_item_set (item,
- "fill_color", "blue",
+ "fill_color", color_spec_from_prop (COLOR_PROP_CURRENT_DAY_FG),
NULL);
}
}
@@ -98,25 +93,26 @@ mark_month_item (GnomeMonthItem *mitem, Calendar *cal)
void
unmark_month_item (GnomeMonthItem *mitem)
{
- int i;
- GnomeCanvasItem *item;
-
g_return_if_fail (mitem != NULL);
g_return_if_fail (GNOME_IS_MONTH_ITEM (mitem));
- for (i = 0; i < 42; i++) {
- /* Box */
+ /* We have to do this in several calls to gnome_canvas_item_set(), as color_spec_from_prop()
+ * returns a pointer to a static string -- and we need several values.
+ */
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_BOX + i);
- gnome_canvas_item_set (item,
- "fill_color", "#d6d6d6d6d6d6",
- NULL);
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "heading_color", color_spec_from_prop (COLOR_PROP_HEADING_COLOR),
+ NULL);
- /* Label */
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "outline_color", color_spec_from_prop (COLOR_PROP_OUTLINE_COLOR),
+ NULL);
- item = gnome_month_item_num2child (GNOME_MONTH_ITEM (mitem), GNOME_MONTH_ITEM_DAY_LABEL + i);
- gnome_canvas_item_set (item,
- "fill_color", "black",
- NULL);
- }
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "day_box_color", color_spec_from_prop (COLOR_PROP_EMPTY_DAY_BG),
+ NULL);
+
+ gnome_canvas_item_set (GNOME_CANVAS_ITEM (mitem),
+ "day_color", color_spec_from_prop (COLOR_PROP_DAY_FG),
+ NULL);
}
diff --git a/calendar/gui/month-view.c b/calendar/gui/month-view.c
index 16e6c72e8a..4d1a9bf967 100644
--- a/calendar/gui/month-view.c
+++ b/calendar/gui/month-view.c
@@ -66,7 +66,7 @@ month_view_init (MonthView *mv)
{
/* Title */
- mv->title = gnome_canvas_item_new (GNOME_CANVAS_GROUP (mv->canvas.root),
+ mv->title = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (mv)),
gnome_canvas_text_get_type (),
"anchor", GTK_ANCHOR_N,
"font", "-*-helvetica-bold-r-normal--18-*-*-*-p-*-iso8859-1",
@@ -75,7 +75,7 @@ month_view_init (MonthView *mv)
/* Month item */
- mv->mitem = gnome_month_item_new (GNOME_CANVAS_GROUP (mv->canvas.root));
+ mv->mitem = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (mv)));
gnome_canvas_item_set (mv->mitem,
"x", 0.0,
"anchor", GTK_ANCHOR_NW,
@@ -205,3 +205,13 @@ month_view_time_format_changed (MonthView *mv)
/* FIXME: update events */
}
+
+void
+month_view_colors_changed (MonthView *mv)
+{
+ g_return_if_fail (mv != NULL);
+ g_return_if_fail (IS_MONTH_VIEW (mv));
+
+ unmark_month_item (mv->mitem);
+ /* FIXME */
+}
diff --git a/calendar/gui/month-view.h b/calendar/gui/month-view.h
index a164332f98..70476c82f2 100644
--- a/calendar/gui/month-view.h
+++ b/calendar/gui/month-view.h
@@ -55,6 +55,9 @@ void month_view_set (MonthView *mv, time_t month);
/* Notifies the month view that the time format has changed */
void month_view_time_format_changed (MonthView *mv);
+/* Notifies the month view that the colors have changed */
+void month_view_colors_changed (MonthView *mv);
+
END_GNOME_DECLS
diff --git a/calendar/gui/prop.c b/calendar/gui/prop.c
index 709d321229..bdc8c9e937 100644
--- a/calendar/gui/prop.c
+++ b/calendar/gui/prop.c
@@ -10,8 +10,18 @@
#include <gnome.h>
#include "gnome-cal.h"
#include "main.h"
+#include "gnome-month-item.h"
+
+/* These specify the page numbers in the preferences notebook */
+enum {
+ PROP_TIME_DISPLAY,
+ PROP_COLORS
+};
static GtkWidget *prop_win; /* The preferences dialog */
+
+/* Widgets for the time display page */
+
static GtkWidget *time_format_12; /* Radio button for 12-hour format */
static GtkWidget *time_format_24; /* Radio button for 24-hour format */
static GtkWidget *start_on_sunday; /* Check button for weeks starting on Sunday */
@@ -21,6 +31,12 @@ static GtkWidget *end_omenu; /* Option menu for end of day */
static GtkWidget *start_items[24]; /* Menu items for start of day menu */
static GtkWidget *end_items[24]; /* Menu items for end of day menu */
+/* Widgets for the colors page */
+
+static GtkWidget *color_pickers[COLOR_PROP_LAST];
+static GnomeCanvasItem *month_item;
+
+
/* Callback used when the property box is closed -- just sets the prop_win variable to null. */
static int
prop_cancel (void)
@@ -39,13 +55,10 @@ get_active_index (GtkWidget *menu)
return GPOINTER_TO_INT (gtk_object_get_user_data (GTK_OBJECT (active)));
}
-/* Callback used when the Apply button is clicked. */
+/* Applies the settings in the time display page */
static void
-prop_apply (GtkWidget *w, int page)
+prop_apply_time_display (void)
{
- if (page != -1)
- return;
-
/* Day begin/end */
day_begin = get_active_index (gtk_option_menu_get_menu (GTK_OPTION_MENU (start_omenu)));
@@ -67,16 +80,57 @@ prop_apply (GtkWidget *w, int page)
time_format_changed ();
}
+/* Applies the settings in the colors page */
+static void
+prop_apply_colors (void)
+{
+ int i;
+ char *cspec;
+
+ for (i = 0; i < COLOR_PROP_LAST; i++) {
+ gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[i]),
+ &color_props[i].r, &color_props[i].g, &color_props[i].b, NULL);
+
+ cspec = build_color_spec (color_props[i].r, color_props[i].g, color_props[i].b);
+ gnome_config_set_string (color_props[i].key, cspec);
+ }
+
+ gnome_config_sync ();
+ colors_changed ();
+}
+
+/* Callback used when the Apply button is clicked. */
+static void
+prop_apply (GtkWidget *w, int page)
+{
+ switch (page) {
+ case PROP_TIME_DISPLAY:
+ prop_apply_time_display ();
+ break;
+
+ case PROP_COLORS:
+ prop_apply_colors ();
+ break;
+
+ case -1:
+ break;
+
+ default:
+ g_warning ("We have a loose penguin!");
+ g_assert_not_reached ();
+ }
+}
+
/* Notifies the property box that the data has changed */
static void
-toggled (GtkWidget *widget, gpointer data)
+prop_changed (void)
{
gnome_property_box_changed (GNOME_PROPERTY_BOX (prop_win));
}
/* Builds and returns a two-element radio button group surrounded by a frame. The radio buttons are
* stored in the specified variables, and the first radio button's state is set according to the
- * specified flag value. The buttons are connected to the toggled() function to update the property
+ * specified flag value. The buttons are connected to the prop_changed() function to update the property
* box's dirty state.
*/
static GtkWidget *
@@ -90,7 +144,7 @@ build_two_radio_group (char *title,
frame = gtk_frame_new (title);
- vbox = gtk_vbox_new (TRUE, 0);
+ vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (frame), vbox);
*radio_1_widget = gtk_radio_button_new_with_label (NULL, radio_1_title);
@@ -104,7 +158,7 @@ build_two_radio_group (char *title,
gtk_toggle_button_set_state (GTK_TOGGLE_BUTTON (*radio_2_widget), !radio_1_value);
gtk_signal_connect (GTK_OBJECT (*radio_1_widget), "toggled",
- (GtkSignalFunc) toggled,
+ (GtkSignalFunc) prop_changed,
NULL);
return frame;
@@ -174,40 +228,35 @@ build_hours_menu (GtkWidget **items, int active)
return omenu;
}
-/* Creates and displays the preferences dialog for the whole application */
-void
-properties (void)
+/* Creates the time display page in the preferences dialog */
+static void
+create_time_display_page (void)
{
- GtkWidget *hbox;
+ GtkWidget *table;
GtkWidget *vbox;
GtkWidget *frame;
GtkWidget *hbox2;
GtkWidget *hbox3;
GtkWidget *w;
- if (prop_win)
- return;
-
- /* Main window and hbox for property page */
-
- prop_win = gnome_property_box_new ();
- gtk_window_set_title (GTK_WINDOW (prop_win), _("Preferences"));
-
- hbox = gtk_hbox_new (FALSE, GNOME_PAD_SMALL);
- gtk_container_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL);
- gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), hbox,
+ table = gtk_table_new (2, 2, FALSE);
+ gtk_container_border_width (GTK_CONTAINER (table), GNOME_PAD_SMALL);
+ gtk_table_set_row_spacings (GTK_TABLE (table), GNOME_PAD_SMALL);
+ gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL);
+ gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), table,
gtk_label_new (_("Time display")));
/* Time format */
- vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
- gtk_box_pack_start (GTK_BOX (hbox), vbox, FALSE, FALSE, 0);
-
w = build_two_radio_group (_("Time format"),
_("12-hour (AM/PM)"), &time_format_12,
_("24-hour"), &time_format_24,
am_pm_flag);
- gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
+ gtk_table_attach (GTK_TABLE (table), w,
+ 0, 1, 0, 1,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 0, 0);
/* Weeks start on */
@@ -215,12 +264,20 @@ properties (void)
_("Sunday"), &start_on_sunday,
_("Monday"), &start_on_monday,
!week_starts_on_monday);
- gtk_box_pack_start (GTK_BOX (vbox), w, FALSE, FALSE, 0);
+ gtk_table_attach (GTK_TABLE (table), w,
+ 0, 1, 1, 2,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 0, 0);
/* Day range */
frame = gtk_frame_new (_("Day range"));
- gtk_box_pack_start (GTK_BOX (hbox), frame, TRUE, TRUE, 0);
+ gtk_table_attach (GTK_TABLE (table), frame,
+ 1, 2, 0, 2,
+ GTK_EXPAND | GTK_FILL,
+ GTK_EXPAND | GTK_FILL,
+ 0, 0);
vbox = gtk_vbox_new (FALSE, GNOME_PAD_SMALL);
gtk_container_border_width (GTK_CONTAINER (vbox), GNOME_PAD_SMALL);
@@ -258,9 +315,152 @@ properties (void)
end_omenu = build_hours_menu (end_items, day_end);
gtk_box_pack_start (GTK_BOX (hbox3), end_omenu, FALSE, FALSE, 0);
+}
+
+/* Called when the canvas for the month item is size allocated. We use this to change the canvas'
+ * scrolling region and the month item's size.
+ */
+static void
+canvas_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
+{
+ gnome_canvas_item_set (month_item,
+ "width", (double) (allocation->width - 1),
+ "height", (double) (allocation->height - 1),
+ NULL);
+
+ gnome_canvas_set_scroll_region (GNOME_CANVAS (widget),
+ 0, 0,
+ allocation->width, allocation->height);
+}
+
+/* Returns a color spec based on the color pickers */
+static char *
+color_spec_from_picker (int num)
+{
+ int r, g, b;
+
+ gnome_color_picker_get_i16 (GNOME_COLOR_PICKER (color_pickers[num]), &r, &g, &b, NULL);
- /* Done! */
+ return build_color_spec (r, g, b);
+}
+
+/* Sets the colors of the month item to the current prerences */
+static void
+reconfigure_month (void)
+{
+ /* We have to do this in two calls to gnome_canvas_item_set(), as color_spec_from_picker()
+ * returns a pointer to a static string -- and we need two values.
+ */
+
+ gnome_canvas_item_set (month_item,
+ "heading_color", color_spec_from_picker (COLOR_PROP_HEADING_COLOR),
+ NULL);
+
+ gnome_canvas_item_set (month_item,
+ "outline_color", color_spec_from_picker (COLOR_PROP_OUTLINE_COLOR),
+ NULL);
+
+ /* FIXME: set the rest of the colors -- simulate marking of the month item, set the
+ * current day, etc. The following is incorrect.
+ */
+
+ gnome_canvas_item_set (month_item,
+ "day_box_color", color_spec_from_picker (COLOR_PROP_EMPTY_DAY_BG),
+ NULL);
+
+ gnome_canvas_item_set (month_item,
+ "day_color", color_spec_from_picker (COLOR_PROP_DAY_FG),
+ NULL);
+}
+
+/* Callback used when a color is changed */
+static void
+color_set (void)
+{
+ reconfigure_month ();
+ prop_changed ();
+}
+
+/* Creates the colors page in the preferences dialog */
+static void
+create_colors_page (void)
+{
+ GtkWidget *frame;
+ GtkWidget *hbox;
+ GtkWidget *table;
+ GtkWidget *w;
+ int i;
+
+ frame = gtk_frame_new (_("Colors for months"));
+ gtk_container_border_width (GTK_CONTAINER (frame), GNOME_PAD_SMALL);
+ gnome_property_box_append_page (GNOME_PROPERTY_BOX (prop_win), frame,
+ gtk_label_new (_("Colors")));
+
+ hbox = gtk_hbox_new (FALSE, GNOME_PAD);
+ gtk_container_border_width (GTK_CONTAINER (hbox), GNOME_PAD_SMALL);
+ gtk_container_add (GTK_CONTAINER (frame), hbox);
+
+ table = gtk_table_new (COLOR_PROP_LAST, 2, FALSE);
+ gtk_table_set_col_spacings (GTK_TABLE (table), GNOME_PAD_SMALL);
+ gtk_box_pack_start (GTK_BOX (hbox), table, FALSE, FALSE, 0);
+
+ /* Create the color pickers */
+
+ for (i = 0; i < COLOR_PROP_LAST; i++) {
+ /* Label */
+
+ w = gtk_label_new (_(color_props[i].label));
+ gtk_misc_set_alignment (GTK_MISC (w), 0.0, 0.5);
+ gtk_table_attach (GTK_TABLE (table), w,
+ 0, 1, i, i + 1,
+ GTK_FILL, 0,
+ 0, 0);
+
+ /* Color picker */
+
+ color_pickers[i] = gnome_color_picker_new ();
+ gnome_color_picker_set_title (GNOME_COLOR_PICKER (color_pickers[i]), _(color_props[i].label));
+ gnome_color_picker_set_i16 (GNOME_COLOR_PICKER (color_pickers[i]),
+ color_props[i].r, color_props[i].g, color_props[i].b, 0);
+ gtk_table_attach (GTK_TABLE (table), color_pickers[i],
+ 1, 2, i, i + 1,
+ 0, 0,
+ 0, 0);
+ gtk_signal_connect (GTK_OBJECT (color_pickers[i]), "color_set",
+ (GtkSignalFunc) color_set,
+ NULL);
+ }
+
+ /* Create the sample calendar */
+
+ w = gnome_canvas_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), w, TRUE, TRUE, 0);
+
+ month_item = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (w)));
+ gnome_canvas_item_set (month_item,
+ "start_on_monday", week_starts_on_monday,
+ NULL);
+ reconfigure_month ();
+ gtk_signal_connect (GTK_OBJECT (w), "size_allocate",
+ canvas_size_allocate,
+ NULL);
+
+}
+
+/* Creates and displays the preferences dialog for the whole application */
+void
+properties (void)
+{
+ if (prop_win)
+ return;
+
+ prop_win = gnome_property_box_new ();
+ gtk_window_set_title (GTK_WINDOW (prop_win), _("Preferences"));
+
+ create_time_display_page ();
+ create_colors_page ();
+
gtk_signal_connect (GTK_OBJECT (prop_win), "destroy",
(GtkSignalFunc) prop_cancel, NULL);
@@ -272,3 +472,33 @@ properties (void)
gtk_widget_show_all (prop_win);
}
+
+char *
+build_color_spec (int r, int g, int b)
+{
+ static char spec[100];
+
+ sprintf (spec, "#%04x%04x%04x", r, g, b);
+ return spec;
+}
+
+void
+parse_color_spec (char *spec, int *r, int *g, int *b)
+{
+ g_return_if_fail (spec != NULL);
+ g_return_if_fail (r != NULL);
+ g_return_if_fail (r != NULL);
+ g_return_if_fail (r != NULL);
+
+ if (sscanf (spec, "#%04x%04x%04x", r, g, b) != 3) {
+ g_warning ("Invalid color specification %s, returning black", spec);
+
+ *r = *g = *b = 0;
+ }
+}
+
+char *
+color_spec_from_prop (int propnum)
+{
+ return build_color_spec (color_props[propnum].r, color_props[propnum].g, color_props[propnum].b);
+}
diff --git a/calendar/gui/year-view.c b/calendar/gui/year-view.c
index a09862f5f0..7458b61500 100644
--- a/calendar/gui/year-view.c
+++ b/calendar/gui/year-view.c
@@ -165,7 +165,7 @@ year_view_init (YearView *yv)
/* Heading */
- yv->heading = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ yv->heading = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)),
gnome_canvas_text_get_type (),
"anchor", GTK_ANCHOR_N,
"font", "-*-helvetica-bold-r-normal--14-*-*-*-*-*-iso8859-1",
@@ -180,7 +180,7 @@ year_view_init (YearView *yv)
strftime (buf, 100, "%B", &tm);
tm.tm_mon++;
- yv->titles[i] = gnome_canvas_item_new (GNOME_CANVAS_GROUP (yv->canvas.root),
+ yv->titles[i] = gnome_canvas_item_new (gnome_canvas_root (GNOME_CANVAS (yv)),
gnome_canvas_text_get_type (),
"text", buf,
"anchor", GTK_ANCHOR_N,
@@ -190,11 +190,10 @@ year_view_init (YearView *yv)
/* Month item */
- yv->mitems[i] = gnome_month_item_new (GNOME_CANVAS_GROUP (yv->canvas.root));
+ yv->mitems[i] = gnome_month_item_new (gnome_canvas_root (GNOME_CANVAS (yv)));
gnome_canvas_item_set (yv->mitems[i],
"anchor", GTK_ANCHOR_NW,
"start_on_monday", week_starts_on_monday,
- "heading_color", "white",
NULL);
}
@@ -339,3 +338,17 @@ year_view_time_format_changed (YearView *yv)
year_view_set (yv, time_year_begin (time_from_day (yv->year, 0, 1)));
}
+
+void
+year_view_colors_changed (YearView *yv)
+{
+ int i;
+
+ g_return_if_fail (yv != NULL);
+ g_return_if_fail (IS_YEAR_VIEW (yv));
+
+ for (i = 0; i < 12; i++) {
+ unmark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]));
+ mark_month_item (GNOME_MONTH_ITEM (yv->mitems[i]), yv->calendar->cal);
+ }
+}
diff --git a/calendar/gui/year-view.h b/calendar/gui/year-view.h
index fa0b4ed65c..071380ba2b 100644
--- a/calendar/gui/year-view.h
+++ b/calendar/gui/year-view.h
@@ -63,6 +63,9 @@ void year_view_set (YearView *yv, time_t year);
/* Notifies the year view that the time format has changed */
void year_view_time_format_changed (YearView *yv);
+/* Notifies the year view that colors have changed */
+void year_view_colors_changed (YearView *yv);
+
END_GNOME_DECLS