diff options
author | Federico Mena Quintero <federico@helixcode.com> | 2000-12-15 19:39:48 +0800 |
---|---|---|
committer | Federico Mena Quintero <federico@src.gnome.org> | 2000-12-15 19:39:48 +0800 |
commit | 937d719a6a5b880df4b75cfe8318d37fd4a4e814 (patch) | |
tree | 6185ecc76c9e1f333d47d2d35dbb8c91021d3fea /calendar/gui/weekday-picker.c | |
parent | 5674d76445b199855d4d431b6db4c0302f4a932b (diff) | |
download | gsoc2013-evolution-937d719a6a5b880df4b75cfe8318d37fd4a4e814.tar.gz gsoc2013-evolution-937d719a6a5b880df4b75cfe8318d37fd4a4e814.tar.zst gsoc2013-evolution-937d719a6a5b880df4b75cfe8318d37fd4a4e814.zip |
Fixes bug #955.
2000-12-14 Federico Mena Quintero <federico@helixcode.com>
Fixes bug #955.
* gui/weekday-picker.c (WeekdayPickerPrivate): Added a field for
the week_start_day, to be used in the same way as
calendar-config.h defines it. Removed the week_starts_on_monday
flag.
(day_event_cb): Use the week_start_day.
(colorize_items): Likewise.
(configure_items): Likewise.
(weekday_picker_set_week_start_day): New function.
(weekday_picker_get_week_start_day): New function.
(weekday_picker_set_week_starts_on_monday): Removed function.
(weekday_picker_get_week_starts_on_monday): Removed function.
* gui/widget-util.[ch]: New files with utilities for creating or
configuring widgets.
* gui/widget-util.c (date_edit_new): New function to create an
EDateEdit configured with the calendar's preferences; moved over
from event-editor.c.
* gui/event-editor.c (make_recur_weekly_special): Use
weekday_picker_set_week_start_day() and the corresponding function
from calendar-config.h.
(init_widgets): Likewise.
(make_date_edit_with_time): Removed function.
(make_recur_ending_until_special): Use date_edit_new().
(make_date_edit): Likewise.
* gui/dialogs/task-editor.c (task_editor_create_date_edit): Likewise.
* gui/event-editor-dialog.glade: Removed references to
make_date_edit_with_time(); replace them with make_date_edit().
* gui/Makefile.am (evolution_calendar_SOURCES): Added
widget-util.[ch] to the list of sources.
svn path=/trunk/; revision=7037
Diffstat (limited to 'calendar/gui/weekday-picker.c')
-rw-r--r-- | calendar/gui/weekday-picker.c | 111 |
1 files changed, 38 insertions, 73 deletions
diff --git a/calendar/gui/weekday-picker.c b/calendar/gui/weekday-picker.c index 4c0ede2579..7059b14133 100644 --- a/calendar/gui/weekday-picker.c +++ b/calendar/gui/weekday-picker.c @@ -41,6 +41,9 @@ struct _WeekdayPickerPrivate { /* Blocked days; these cannot be modified */ guint8 blocked_day_mask; + /* Day that defines the start of the week; 0 = Sunday, ..., 6 = Saturday */ + int week_start_day; + /* Metrics */ int font_ascent, font_descent; int max_letter_width; @@ -48,9 +51,6 @@ struct _WeekdayPickerPrivate { /* Components */ GnomeCanvasItem *boxes[7]; GnomeCanvasItem *labels[7]; - - /* Whether the week starts on Monday or Sunday */ - guint week_starts_on_monday : 1; }; @@ -164,12 +164,9 @@ day_event_cb (GnomeCanvasItem *item, GdkEvent *event, gpointer data) /* Turn on that day */ - if (priv->week_starts_on_monday) { - if (i == 6) - i = 0; - else - i++; - } + i += priv->week_start_day; + if (i >= 7) + i -= 7; if (priv->blocked_day_mask & (0x1 << i)) return TRUE; @@ -268,65 +265,30 @@ colorize_items (WeekdayPicker *wp) sel_fill = >K_WIDGET (wp)->style->bg[GTK_STATE_SELECTED]; sel_text_fill = >K_WIDGET (wp)->style->fg[GTK_STATE_SELECTED]; - if (priv->week_starts_on_monday) { + for (i = 0; i < 7; i++) { + int day; GdkColor *f, *t; - for (i = 1; i < 7; i++) { - if (priv->day_mask & (0x1 << i)) { - f = sel_fill; - t = sel_text_fill; - } else { - f = fill; - t = text_fill; - } - - gnome_canvas_item_set (priv->boxes[i - 1], - "fill_color_gdk", f, - "outline_color_gdk", outline, - NULL); - - gnome_canvas_item_set (priv->labels[i - 1], - "fill_color_gdk", t, - NULL); - } + day = i + priv->week_start_day; + if (day >= 7) + day -= 7; - if (priv->day_mask & (0x1 << 0)) { + if (priv->day_mask & (0x1 << day)) { f = sel_fill; t = sel_text_fill; } else { f = fill; t = text_fill; } - - gnome_canvas_item_set (priv->boxes[6], + + gnome_canvas_item_set (priv->boxes[i], "fill_color_gdk", f, "outline_color_gdk", outline, NULL); - gnome_canvas_item_set (priv->labels[6], + gnome_canvas_item_set (priv->labels[i], "fill_color_gdk", t, NULL); - } else { - GdkColor *f, *t; - - for (i = 0; i < 7; i++) { - if (priv->day_mask & (0x1 << i)) { - f = sel_fill; - t = sel_text_fill; - } else { - f = fill; - t = text_fill; - } - - gnome_canvas_item_set (priv->boxes[i], - "fill_color_gdk", f, - "outline_color_gdk", outline, - NULL); - - gnome_canvas_item_set (priv->labels[i], - "fill_color_gdk", t, - NULL); - } } } @@ -346,14 +308,15 @@ configure_items (WeekdayPicker *wp) height = GTK_WIDGET (wp)->allocation.height; box_width = (width - 1) / 7; - - if (priv->week_starts_on_monday) - str = _("MTWTFSS"); - else - str = _("SMTWTFS"); + str = _("SMTWTFS"); for (i = 0; i < 7; i++) { char *c; + int day; + + day = i + priv->week_start_day; + if (day >= 7) + day -= 7; gnome_canvas_item_set (priv->boxes[i], "x1", (double) (i * box_width), @@ -363,7 +326,7 @@ configure_items (WeekdayPicker *wp) "width_pixels", 0, NULL); - c = g_strndup (str + i, 1); + c = g_strndup (str + day, 1); gnome_canvas_item_set (priv->labels[i], "text", c, "font_gdk", GTK_WIDGET (wp)->style->font, @@ -564,43 +527,45 @@ weekday_picker_get_blocked_days (WeekdayPicker *wp) } /** - * weekday_picker_set_week_starts_on_monday: + * weekday_picker_set_week_start_day: * @wp: A weekday picker. - * @on_monday: Whether weeks start on Monday. + * @week_start_day: Index of the day that defines the start of the week; 0 is + * Sunday, 1 is Monday, etc. * - * Sets whether a weekday picker should display weeks as starting on monday. - * The default setting is to make Sunday the first day of the week. + * Sets the day that defines the start of the week for a weekday picker. **/ void -weekday_picker_set_week_starts_on_monday (WeekdayPicker *wp, gboolean on_monday) +weekday_picker_set_week_start_day (WeekdayPicker *wp, int week_start_day) { WeekdayPickerPrivate *priv; g_return_if_fail (wp != NULL); g_return_if_fail (IS_WEEKDAY_PICKER (wp)); + g_return_if_fail (week_start_day >= 0 && week_start_day < 7); priv = wp->priv; - priv->week_starts_on_monday = on_monday ? TRUE : FALSE; + priv->week_start_day = week_start_day; configure_items (wp); } /** - * weekday_picker_get_week_starts_on_monday: + * weekday_picker_get_week_start_day: * @wp: A weekday picker. * - * Queries whether a weekday picker is set to show weeks as starting on Monday. + * Queries the day that defines the start of the week in a weekday picker. * - * Return value: TRUE if weeks start on monday, FALSE if on Sunday. + * Return value: Index of the day that defines the start of the week. See + * weekday_picker_set_week_start_day() to see how this is represented. **/ -gboolean -weekday_picker_get_week_starts_on_monday (WeekdayPicker *wp) +int +weekday_picker_get_week_start_day (WeekdayPicker *wp) { WeekdayPickerPrivate *priv; - g_return_val_if_fail (wp != NULL, FALSE); - g_return_val_if_fail (IS_WEEKDAY_PICKER (wp), FALSE); + g_return_val_if_fail (wp != NULL, -1); + g_return_val_if_fail (IS_WEEKDAY_PICKER (wp), -1); priv = wp->priv; - return priv->week_starts_on_monday; + return priv->week_start_day; } |