aboutsummaryrefslogtreecommitdiffstats
path: root/calendar
diff options
context:
space:
mode:
authorMatthew Barnes <mbarnes@redhat.com>2010-01-04 11:47:27 +0800
committerMatthew Barnes <mbarnes@redhat.com>2010-01-05 09:22:21 +0800
commit5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a (patch)
tree92b05ad7116690bf2da53a0fa6ba813fcbea50c7 /calendar
parent69945127d8a7933512bb14eb20ff85354704b5cc (diff)
downloadgsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar.gz
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar.bz2
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar.lz
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar.xz
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.tar.zst
gsoc2013-evolution-5c80f1534b435ff5c1c9cc88eb9f5c5c1124f82a.zip
Coding style and whitespace cleanup.
Diffstat (limited to 'calendar')
-rw-r--r--calendar/gui/dialogs/comp-editor.h27
-rw-r--r--calendar/gui/e-task-table.c50
-rw-r--r--calendar/gui/ea-cal-view-event.c4
-rw-r--r--calendar/gui/gnome-cal.h20
-rw-r--r--calendar/gui/weekday-picker.c475
5 files changed, 301 insertions, 275 deletions
diff --git a/calendar/gui/dialogs/comp-editor.h b/calendar/gui/dialogs/comp-editor.h
index 54672ec3b8..4871beae8f 100644
--- a/calendar/gui/dialogs/comp-editor.h
+++ b/calendar/gui/dialogs/comp-editor.h
@@ -67,16 +67,25 @@ struct _CompEditorClass {
const gchar *help_section;
/* Virtual functions */
- void (*edit_comp) (CompEditor *page, ECalComponent *comp);
- void (*object_created) (CompEditor *page);
- gboolean (*send_comp) (CompEditor *page, ECalComponentItipMethod method, gboolean strip_alarms);
+ void (*edit_comp) (CompEditor *page,
+ ECalComponent *comp);
+ void (*object_created) (CompEditor *page);
+ gboolean (*send_comp) (CompEditor *page,
+ ECalComponentItipMethod method,
+ gboolean strip_alarms);
- void (*show_categories) (CompEditor *editor, gboolean visible);
- void (*show_role) (CompEditor *editor, gboolean visible);
- void (*show_rsvp) (CompEditor *editor, gboolean visible);
- void (*show_status) (CompEditor *editor, gboolean visible);
- void (*show_time_zone) (CompEditor *editor, gboolean visible);
- void (*show_type) (CompEditor *editor, gboolean visible);
+ void (*show_categories) (CompEditor *editor,
+ gboolean visible);
+ void (*show_role) (CompEditor *editor,
+ gboolean visible);
+ void (*show_rsvp) (CompEditor *editor,
+ gboolean visible);
+ void (*show_status) (CompEditor *editor,
+ gboolean visible);
+ void (*show_time_zone) (CompEditor *editor,
+ gboolean visible);
+ void (*show_type) (CompEditor *editor,
+ gboolean visible);
};
typedef enum {
diff --git a/calendar/gui/e-task-table.c b/calendar/gui/e-task-table.c
index 009d47daec..c4d364a930 100644
--- a/calendar/gui/e-task-table.c
+++ b/calendar/gui/e-task-table.c
@@ -739,7 +739,9 @@ task_table_query_tooltip (GtkWidget *widget,
use_24_hour_format = e_cal_model_get_use_24_hour_format (model);
if (dtstart.tzid) {
- zone = icalcomponent_get_timezone (e_cal_component_get_icalcomponent (new_comp), dtstart.tzid);
+ zone = icalcomponent_get_timezone (
+ e_cal_component_get_icalcomponent (new_comp),
+ dtstart.tzid);
if (!zone)
e_cal_get_timezone (
comp_data->client, dtstart.tzid, &zone, NULL);
@@ -1390,20 +1392,23 @@ check_for_retract (ECalComponent *comp, ECal *client)
ECalComponentOrganizer org;
gchar *email = NULL;
const gchar *strip = NULL;
- gboolean ret_val = FALSE;
+ gboolean ret_val;
- if (!(e_cal_component_has_attendees (comp) &&
- e_cal_get_save_schedules (client)))
- return ret_val;
+ if (!e_cal_component_has_attendees (comp))
+ return FALSE;
+
+ if (!e_cal_get_save_schedules (client))
+ return FALSE;
e_cal_component_get_organizer (comp, &org);
strip = itip_strip_mailto (org.value);
- if (e_cal_get_cal_address (client, &email, NULL) && !g_ascii_strcasecmp (email, strip)) {
- ret_val = TRUE;
- }
+ ret_val =
+ e_cal_get_cal_address (client, &email, NULL) &&
+ g_ascii_strcasecmp (email, strip) == 0;
g_free (email);
+
return ret_val;
}
@@ -1438,14 +1443,17 @@ e_task_table_delete_selected (ETaskTable *task_table)
if (comp_data) {
comp = e_cal_component_new ();
- e_cal_component_set_icalcomponent (comp, icalcomponent_new_clone (comp_data->icalcomp));
+ e_cal_component_set_icalcomponent (
+ comp, icalcomponent_new_clone (comp_data->icalcomp));
}
if ((n_selected == 1) && comp && check_for_retract (comp, comp_data->client)) {
gchar *retract_comment = NULL;
gboolean retract = FALSE;
- delete = prompt_retract_dialog (comp, &retract_comment, GTK_WIDGET (task_table), &retract);
+ delete = prompt_retract_dialog (
+ comp, &retract_comment,
+ GTK_WIDGET (task_table), &retract);
if (retract) {
GList *users = NULL;
icalcomponent *icalcomp = NULL, *mod_comp = NULL;
@@ -1471,7 +1479,9 @@ e_task_table_delete_selected (ETaskTable *task_table)
}
} else {
- delete = delete_component_dialog (comp, FALSE, n_selected, E_CAL_COMPONENT_TODO, GTK_WIDGET (task_table));
+ delete = delete_component_dialog (
+ comp, FALSE, n_selected,
+ E_CAL_COMPONENT_TODO, GTK_WIDGET (task_table));
}
if (delete)
@@ -1506,7 +1516,10 @@ e_task_table_get_selected (ETaskTable *task_table)
}
static void
-hide_completed_rows (ECalModel *model, GList *clients_list, gchar *hide_sexp, GPtrArray *comp_objects)
+hide_completed_rows (ECalModel *model,
+ GList *clients_list,
+ gchar *hide_sexp,
+ GPtrArray *comp_objects)
{
GList *l, *m, *objects;
ECal *client;
@@ -1548,13 +1561,17 @@ hide_completed_rows (ECalModel *model, GList *clients_list, gchar *hide_sexp, GP
}
if (changed) {
- /* to notify about changes, because in call of row_deleted there are still all events */
+ /* To notify about changes, because in call of
+ * row_deleted there are still all events. */
e_table_model_changed (E_TABLE_MODEL (model));
}
}
static void
-show_completed_rows (ECalModel *model, GList *clients_list, gchar *show_sexp, GPtrArray *comp_objects)
+show_completed_rows (ECalModel *model,
+ GList *clients_list,
+ gchar *show_sexp,
+ GPtrArray *comp_objects)
{
GList *l, *m, *objects;
ECal *client;
@@ -1583,7 +1600,10 @@ show_completed_rows (ECalModel *model, GList *clients_list, gchar *show_sexp, GP
comp_data->icalcomp = icalcomponent_new_clone (m->data);
e_cal_model_set_instance_times (comp_data,
e_cal_model_get_timezone (model));
- comp_data->dtstart = comp_data->dtend = comp_data->due = comp_data->completed = NULL;
+ comp_data->dtstart = NULL;
+ comp_data->dtend = NULL;
+ comp_data->due = NULL;
+ comp_data->completed = NULL;
comp_data->color = NULL;
g_ptr_array_add (comp_objects, comp_data);
diff --git a/calendar/gui/ea-cal-view-event.c b/calendar/gui/ea-cal-view-event.c
index 5f0af90261..4fbc93e3e2 100644
--- a/calendar/gui/ea-cal-view-event.c
+++ b/calendar/gui/ea-cal-view-event.c
@@ -276,7 +276,9 @@ ea_cal_view_event_get_name (AtkObject *accessible)
else
summary_string = g_strdup (_("Calendar Event: It has no summary."));
- name_string = g_strdup_printf ("%s %s %s %s", summary_string, alarm_string, recur_string, meeting_string);
+ name_string = g_strdup_printf (
+ "%s %s %s %s", summary_string,
+ alarm_string, recur_string, meeting_string);
g_free (summary_string);
ATK_OBJECT_CLASS (parent_class)->set_name (accessible, name_string);
diff --git a/calendar/gui/gnome-cal.h b/calendar/gui/gnome-cal.h
index 197396dbd6..5703b99811 100644
--- a/calendar/gui/gnome-cal.h
+++ b/calendar/gui/gnome-cal.h
@@ -93,19 +93,23 @@ struct _GnomeCalendarClass {
GtkVBoxClass parent_class;
/* Notification signals */
- void (* dates_shown_changed) (GnomeCalendar *gcal);
+ void (*dates_shown_changed) (GnomeCalendar *gcal);
- void (* calendar_selection_changed) (GnomeCalendar *gcal);
+ void (*calendar_selection_changed) (GnomeCalendar *gcal);
- void (* calendar_focus_change) (GnomeCalendar *gcal, gboolean in);
- void (* change_view) (GnomeCalendar *gcal,
- GnomeCalendarViewType view_type);
+ void (*calendar_focus_change) (GnomeCalendar *gcal,
+ gboolean in);
+ void (*change_view) (GnomeCalendar *gcal,
+ GnomeCalendarViewType view_type);
- void (* source_added) (GnomeCalendar *gcal, ESource *source);
- void (* source_removed) (GnomeCalendar *gcal, ESource *source);
+ void (*source_added) (GnomeCalendar *gcal,
+ ESource *source);
+ void (*source_removed) (GnomeCalendar *gcal,
+ ESource *source);
/* Action signals */
- void (* goto_date) (GnomeCalendar *gcal, GnomeCalendarGotoDateType date);
+ void (*goto_date) (GnomeCalendar *gcal,
+ GnomeCalendarGotoDateType date);
};
GType gnome_calendar_get_type (void);
diff --git a/calendar/gui/weekday-picker.c b/calendar/gui/weekday-picker.c
index 12c09b43c5..6e9f4bb34f 100644
--- a/calendar/gui/weekday-picker.c
+++ b/calendar/gui/weekday-picker.c
@@ -70,196 +70,19 @@ enum {
LAST_SIGNAL
};
-static void weekday_picker_destroy (GtkObject *object);
-
-static void weekday_picker_realize (GtkWidget *widget);
-static void weekday_picker_size_request (GtkWidget *widget, GtkRequisition *requisition);
-static void weekday_picker_size_allocate (GtkWidget *widget, GtkAllocation *allocation);
-static void weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style);
-static gboolean weekday_picker_focus (GtkWidget *widget, GtkDirectionType direction);
-static void colorize_items (WeekdayPicker *wp);
-
static guint wp_signals[LAST_SIGNAL];
G_DEFINE_TYPE (WeekdayPicker, weekday_picker, GNOME_TYPE_CANVAS)
-/* Class initialization function for the weekday picker */
-static void
-weekday_picker_class_init (WeekdayPickerClass *class)
-{
- GtkObjectClass *object_class;
- GtkWidgetClass *widget_class;
-
- object_class = (GtkObjectClass *) class;
- widget_class = (GtkWidgetClass *) class;
-
- wp_signals[CHANGED] =
- g_signal_new ("changed",
- G_TYPE_FROM_CLASS (object_class),
- G_SIGNAL_RUN_FIRST,
- G_STRUCT_OFFSET (WeekdayPickerClass, changed),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE, 0);
-
- object_class->destroy = weekday_picker_destroy;
-
- widget_class->realize = weekday_picker_realize;
- widget_class->size_request = weekday_picker_size_request;
- widget_class->size_allocate = weekday_picker_size_allocate;
- widget_class->style_set = weekday_picker_style_set;
- widget_class->focus = weekday_picker_focus;
-
- class->changed = NULL;
-}
-
-static void
-day_clicked (WeekdayPicker *wp, gint index)
-{
- WeekdayPickerPrivate *priv = wp->priv;
- guint8 day_mask;
-
- if (priv->blocked_day_mask & (0x1 << index))
- return;
-
- if (priv->day_mask & (0x1 << index))
- day_mask = priv->day_mask & ~(0x1 << index);
- else
- day_mask = priv->day_mask | (0x1 << index);
-
- weekday_picker_set_days (wp, day_mask);
-}
-
-static gint
-handle_key_press_event (WeekdayPicker *wp, GdkEvent *event)
-{
- WeekdayPickerPrivate *priv = wp->priv;
- guint keyval = event->key.keyval;
-
- if (priv->focus_day == -1)
- priv->focus_day = priv->week_start_day;
-
- switch (keyval) {
- case GDK_Up:
- case GDK_Right:
- priv->focus_day += 1;
- break;
- case GDK_Down:
- case GDK_Left:
- priv->focus_day -= 1;
- break;
- case GDK_space:
- case GDK_Return:
- day_clicked (wp, priv->focus_day);
- return TRUE;
- default:
- return FALSE;
- }
-
- if (priv->focus_day > 6)
- priv->focus_day = 0;
- if (priv->focus_day < 0)
- priv->focus_day = 6;
-
- colorize_items (wp);
- gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
- return TRUE;
-}
-
-/* Event handler for the day items */
-static gint
-day_event_cb (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
-{
- WeekdayPicker *wp;
- WeekdayPickerPrivate *priv;
- gint i;
-
- wp = WEEKDAY_PICKER (data);
- priv = wp->priv;
-
- if (event->type == GDK_KEY_PRESS)
- return handle_key_press_event(wp, event);
-
- if (!(event->type == GDK_BUTTON_PRESS && event->button.button == 1))
- return FALSE;
-
- /* Find which box was clicked */
-
- for (i = 0; i < 7; i++)
- if (priv->boxes[i] == item || priv->labels[i] == item)
- break;
-
- g_return_val_if_fail (i != 7, TRUE);
-
- i += priv->week_start_day;
- if (i >= 7)
- i -= 7;
-
- priv->focus_day = i;
- gnome_canvas_item_grab_focus (priv->boxes[i]);
- day_clicked (wp, i);
- return TRUE;
-}
-
-/* Creates the canvas items for the weekday picker. The items are empty until
- * they are configured elsewhere.
- */
-static void
-create_items (WeekdayPicker *wp)
-{
- WeekdayPickerPrivate *priv;
- GnomeCanvasGroup *parent;
- gint i;
-
- priv = wp->priv;
-
- parent = gnome_canvas_root (GNOME_CANVAS (wp));
-
- for (i = 0; i < 7; i++) {
- priv->boxes[i] = gnome_canvas_item_new (parent,
- GNOME_TYPE_CANVAS_RECT,
- NULL);
- g_signal_connect (priv->boxes[i], "event", G_CALLBACK (day_event_cb), wp);
-
- priv->labels[i] = gnome_canvas_item_new (parent,
- GNOME_TYPE_CANVAS_TEXT,
- NULL);
- g_signal_connect (priv->labels[i], "event", G_CALLBACK (day_event_cb), wp);
- }
-}
-
-/* Object initialization function for the weekday picker */
-static void
-weekday_picker_init (WeekdayPicker *wp)
-{
- WeekdayPickerPrivate *priv;
-
- priv = g_new0 (WeekdayPickerPrivate, 1);
-
- wp->priv = priv;
-
- create_items (wp);
- priv->focus_day = -1;
-}
-
-/* Finalize handler for the weekday picker */
-static void
-weekday_picker_destroy (GtkObject *object)
+static gchar *
+get_day_text (gint day_index)
{
- WeekdayPicker *wp;
- WeekdayPickerPrivate *priv;
-
- g_return_if_fail (object != NULL);
- g_return_if_fail (IS_WEEKDAY_PICKER (object));
-
- wp = WEEKDAY_PICKER (object);
- priv = wp->priv;
+ GDateWeekday weekday;
- g_free (priv);
- wp->priv = NULL;
+ /* Convert from tm_wday to GDateWeekday. */
+ weekday = (day_index == 0) ? G_DATE_SUNDAY : day_index;
- if (GTK_OBJECT_CLASS (weekday_picker_parent_class)->destroy)
- (* GTK_OBJECT_CLASS (weekday_picker_parent_class)->destroy) (object);
+ return g_strdup (e_get_weekday_name (weekday, TRUE));
}
static void
@@ -314,18 +137,6 @@ colorize_items (WeekdayPicker *wp)
}
}
-/* Configures the items in the weekday picker by setting their attributes. */
-static gchar *
-get_day_text (gint day_index)
-{
- GDateWeekday weekday;
-
- /* Convert from tm_wday to GDateWeekday. */
- weekday = (day_index == 0) ? G_DATE_SUNDAY : day_index;
-
- return g_strdup (e_get_weekday_name (weekday, TRUE));
-}
-
static void
configure_items (WeekdayPicker *wp)
{
@@ -370,7 +181,25 @@ configure_items (WeekdayPicker *wp)
colorize_items (wp);
}
-/* Realize handler for the weekday picker */
+static void
+weekday_picker_destroy (GtkObject *object)
+{
+ WeekdayPicker *wp;
+ WeekdayPickerPrivate *priv;
+
+ g_return_if_fail (object != NULL);
+ g_return_if_fail (IS_WEEKDAY_PICKER (object));
+
+ wp = WEEKDAY_PICKER (object);
+ priv = wp->priv;
+
+ g_free (priv);
+ wp->priv = NULL;
+
+ /* Chain up to parent's destroy() method. */
+ GTK_OBJECT_CLASS (weekday_picker_parent_class)->destroy (object);
+}
+
static void
weekday_picker_realize (GtkWidget *widget)
{
@@ -378,15 +207,15 @@ weekday_picker_realize (GtkWidget *widget)
wp = WEEKDAY_PICKER (widget);
- if (GTK_WIDGET_CLASS (weekday_picker_parent_class)->realize)
- (* GTK_WIDGET_CLASS (weekday_picker_parent_class)->realize) (widget);
+ /* Chain up to parent's realize() method. */
+ GTK_WIDGET_CLASS (weekday_picker_parent_class)->realize (widget);
configure_items (wp);
}
-/* Size_request handler for the weekday picker */
static void
-weekday_picker_size_request (GtkWidget *widget, GtkRequisition *requisition)
+weekday_picker_size_request (GtkWidget *widget,
+ GtkRequisition *requisition)
{
WeekdayPicker *wp;
WeekdayPickerPrivate *priv;
@@ -398,27 +227,31 @@ weekday_picker_size_request (GtkWidget *widget, GtkRequisition *requisition)
requisition->height = (priv->font_ascent + priv->font_descent + 2 * PADDING + 2);
}
-/* Size_allocate handler for the weekday picker */
static void
-weekday_picker_size_allocate (GtkWidget *widget, GtkAllocation *allocation)
+weekday_picker_size_allocate (GtkWidget *widget,
+ GtkAllocation *allocation)
{
+ GtkWidgetClass *widget_class;
WeekdayPicker *wp;
wp = WEEKDAY_PICKER (widget);
- if (GTK_WIDGET_CLASS (weekday_picker_parent_class)->size_allocate)
- (* GTK_WIDGET_CLASS (weekday_picker_parent_class)->size_allocate) (widget, allocation);
+ /* Chain up to parent's size_allocate() method. */
+ widget_class = GTK_WIDGET_CLASS (weekday_picker_parent_class);
+ widget_class->size_allocate (widget, allocation);
- gnome_canvas_set_scroll_region (GNOME_CANVAS (wp),
- 0, 0, allocation->width, allocation->height);
+ gnome_canvas_set_scroll_region (
+ GNOME_CANVAS (wp), 0, 0,
+ allocation->width, allocation->height);
configure_items (wp);
}
-/* Style_set handler for the weekday picker */
static void
-weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style)
+weekday_picker_style_set (GtkWidget *widget,
+ GtkStyle *previous_style)
{
+ GtkWidgetClass *widget_class;
WeekdayPicker *wp;
WeekdayPickerPrivate *priv;
gint max_width;
@@ -434,12 +267,15 @@ weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style)
/* Set up Pango prerequisites */
font_desc = gtk_widget_get_style (widget)->font_desc;
pango_context = gtk_widget_get_pango_context (widget);
- font_metrics = pango_context_get_metrics (pango_context, font_desc,
- pango_context_get_language (pango_context));
+ font_metrics = pango_context_get_metrics (
+ pango_context, font_desc,
+ pango_context_get_language (pango_context));
layout = pango_layout_new (pango_context);
- priv->font_ascent = PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics));
- priv->font_descent = PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics));
+ priv->font_ascent =
+ PANGO_PIXELS (pango_font_metrics_get_ascent (font_metrics));
+ priv->font_descent =
+ PANGO_PIXELS (pango_font_metrics_get_descent (font_metrics));
max_width = 0;
@@ -462,11 +298,193 @@ weekday_picker_style_set (GtkWidget *widget, GtkStyle *previous_style)
g_object_unref (layout);
pango_font_metrics_unref (font_metrics);
- if (GTK_WIDGET_CLASS (weekday_picker_parent_class)->style_set)
- (* GTK_WIDGET_CLASS (weekday_picker_parent_class)->style_set) (widget, previous_style);
+ /* Chain up to parent's style_set() method. */
+ widget_class = GTK_WIDGET_CLASS (weekday_picker_parent_class);
+ widget_class->style_set (widget, previous_style);
}
-
+static gboolean
+weekday_picker_focus (GtkWidget *widget,
+ GtkDirectionType direction)
+{
+ WeekdayPicker *wp;
+ WeekdayPickerPrivate *priv;
+
+ g_return_val_if_fail (widget != NULL, FALSE);
+ g_return_val_if_fail (IS_WEEKDAY_PICKER (widget), FALSE);
+ wp = WEEKDAY_PICKER (widget);
+ priv = wp->priv;
+
+ if (!GTK_WIDGET_CAN_FOCUS (widget))
+ return FALSE;
+
+ if (GTK_WIDGET_HAS_FOCUS (widget)) {
+ priv->focus_day = -1;
+ colorize_items (wp);
+ return FALSE;
+ }
+
+ priv->focus_day = priv->week_start_day;
+ gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+ colorize_items (wp);
+
+ return TRUE;
+}
+static void
+weekday_picker_class_init (WeekdayPickerClass *class)
+{
+ GtkObjectClass *object_class;
+ GtkWidgetClass *widget_class;
+
+ object_class = GTK_OBJECT_CLASS (class);
+ object_class->destroy = weekday_picker_destroy;
+
+ widget_class = GTK_WIDGET_CLASS (class);
+ widget_class->realize = weekday_picker_realize;
+ widget_class->size_request = weekday_picker_size_request;
+ widget_class->size_allocate = weekday_picker_size_allocate;
+ widget_class->style_set = weekday_picker_style_set;
+ widget_class->focus = weekday_picker_focus;
+
+ class->changed = NULL;
+
+ wp_signals[CHANGED] = g_signal_new (
+ "changed",
+ G_TYPE_FROM_CLASS (object_class),
+ G_SIGNAL_RUN_FIRST,
+ G_STRUCT_OFFSET (WeekdayPickerClass, changed),
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE, 0);
+}
+
+static void
+day_clicked (WeekdayPicker *wp, gint index)
+{
+ WeekdayPickerPrivate *priv = wp->priv;
+ guint8 day_mask;
+
+ if (priv->blocked_day_mask & (0x1 << index))
+ return;
+
+ if (priv->day_mask & (0x1 << index))
+ day_mask = priv->day_mask & ~(0x1 << index);
+ else
+ day_mask = priv->day_mask | (0x1 << index);
+
+ weekday_picker_set_days (wp, day_mask);
+}
+
+static gint
+handle_key_press_event (WeekdayPicker *wp, GdkEvent *event)
+{
+ WeekdayPickerPrivate *priv = wp->priv;
+ guint keyval = event->key.keyval;
+
+ if (priv->focus_day == -1)
+ priv->focus_day = priv->week_start_day;
+
+ switch (keyval) {
+ case GDK_Up:
+ case GDK_Right:
+ priv->focus_day += 1;
+ break;
+ case GDK_Down:
+ case GDK_Left:
+ priv->focus_day -= 1;
+ break;
+ case GDK_space:
+ case GDK_Return:
+ day_clicked (wp, priv->focus_day);
+ return TRUE;
+ default:
+ return FALSE;
+ }
+
+ if (priv->focus_day > 6)
+ priv->focus_day = 0;
+ if (priv->focus_day < 0)
+ priv->focus_day = 6;
+
+ colorize_items (wp);
+ gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
+ return TRUE;
+}
+
+/* Event handler for the day items */
+static gint
+day_event_cb (GnomeCanvasItem *item, GdkEvent *event, gpointer data)
+{
+ WeekdayPicker *wp;
+ WeekdayPickerPrivate *priv;
+ gint i;
+
+ wp = WEEKDAY_PICKER (data);
+ priv = wp->priv;
+
+ if (event->type == GDK_KEY_PRESS)
+ return handle_key_press_event(wp, event);
+
+ if (!(event->type == GDK_BUTTON_PRESS && event->button.button == 1))
+ return FALSE;
+
+ /* Find which box was clicked */
+
+ for (i = 0; i < 7; i++)
+ if (priv->boxes[i] == item || priv->labels[i] == item)
+ break;
+
+ g_return_val_if_fail (i != 7, TRUE);
+
+ i += priv->week_start_day;
+ if (i >= 7)
+ i -= 7;
+
+ priv->focus_day = i;
+ gnome_canvas_item_grab_focus (priv->boxes[i]);
+ day_clicked (wp, i);
+ return TRUE;
+}
+
+/* Creates the canvas items for the weekday picker. The items are empty until
+ * they are configured elsewhere.
+ */
+static void
+create_items (WeekdayPicker *wp)
+{
+ WeekdayPickerPrivate *priv;
+ GnomeCanvasGroup *parent;
+ gint i;
+
+ priv = wp->priv;
+
+ parent = gnome_canvas_root (GNOME_CANVAS (wp));
+
+ for (i = 0; i < 7; i++) {
+ priv->boxes[i] = gnome_canvas_item_new (parent,
+ GNOME_TYPE_CANVAS_RECT,
+ NULL);
+ g_signal_connect (priv->boxes[i], "event", G_CALLBACK (day_event_cb), wp);
+
+ priv->labels[i] = gnome_canvas_item_new (parent,
+ GNOME_TYPE_CANVAS_TEXT,
+ NULL);
+ g_signal_connect (priv->labels[i], "event", G_CALLBACK (day_event_cb), wp);
+ }
+}
+
+static void
+weekday_picker_init (WeekdayPicker *wp)
+{
+ WeekdayPickerPrivate *priv;
+
+ priv = g_new0 (WeekdayPickerPrivate, 1);
+
+ wp->priv = priv;
+
+ create_items (wp);
+ priv->focus_day = -1;
+}
/**
* weekday_picker_new:
@@ -614,30 +632,3 @@ weekday_picker_get_week_start_day (WeekdayPicker *wp)
return priv->week_start_day;
}
-/* focus handler for weekday picker */
-static gboolean
-weekday_picker_focus (GtkWidget *widget, GtkDirectionType direction)
-{
- WeekdayPicker *wp;
- WeekdayPickerPrivate *priv;
-
- g_return_val_if_fail (widget != NULL, FALSE);
- g_return_val_if_fail (IS_WEEKDAY_PICKER (widget), FALSE);
- wp = WEEKDAY_PICKER (widget);
- priv = wp->priv;
-
- if (!GTK_WIDGET_CAN_FOCUS (widget))
- return FALSE;
-
- if (GTK_WIDGET_HAS_FOCUS (widget)) {
- priv->focus_day = -1;
- colorize_items (wp);
- return FALSE;
- }
-
- priv->focus_day = priv->week_start_day;
- gnome_canvas_item_grab_focus (priv->boxes[priv->focus_day]);
- colorize_items (wp);
-
- return TRUE;
-}