diff options
author | Matthew Barnes <mbarnes@redhat.com> | 2010-08-13 03:05:34 +0800 |
---|---|---|
committer | Matthew Barnes <mbarnes@redhat.com> | 2010-08-13 03:41:02 +0800 |
commit | 6caf022926a6dc7ae0a84e514510def0de87109a (patch) | |
tree | 02e11a04238d2d0aa77cea2ef01b69069ebc1f89 /widgets/misc | |
parent | 5f49fa2561433c08a1f0450365b764ebfff3f611 (diff) | |
download | gsoc2013-evolution-6caf022926a6dc7ae0a84e514510def0de87109a.tar.gz gsoc2013-evolution-6caf022926a6dc7ae0a84e514510def0de87109a.tar.zst gsoc2013-evolution-6caf022926a6dc7ae0a84e514510def0de87109a.zip |
ECanvas cleanups.
Diffstat (limited to 'widgets/misc')
-rw-r--r-- | widgets/misc/e-calendar.c | 2 | ||||
-rw-r--r-- | widgets/misc/e-canvas.c | 689 | ||||
-rw-r--r-- | widgets/misc/e-canvas.h | 125 |
3 files changed, 410 insertions, 406 deletions
diff --git a/widgets/misc/e-calendar.c b/widgets/misc/e-calendar.c index fd8f882b25..bf556ae657 100644 --- a/widgets/misc/e-calendar.c +++ b/widgets/misc/e-calendar.c @@ -97,7 +97,7 @@ static void e_calendar_start_auto_move (ECalendar *cal, static gboolean e_calendar_auto_move_handler (gpointer data); static void e_calendar_stop_auto_move (ECalendar *cal); -G_DEFINE_TYPE (ECalendar, e_calendar, E_CANVAS_TYPE) +G_DEFINE_TYPE (ECalendar, e_calendar, E_TYPE_CANVAS) static void e_calendar_class_init (ECalendarClass *class) diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c index 3b8d5ed57f..8d4336e4dd 100644 --- a/widgets/misc/e-canvas.c +++ b/widgets/misc/e-canvas.c @@ -28,24 +28,6 @@ #include "e-canvas.h" -static void e_canvas_dispose (GObject *object); -static void e_canvas_realize (GtkWidget *widget); -static void e_canvas_unrealize (GtkWidget *widget); -static gint e_canvas_key (GtkWidget *widget, - GdkEventKey *event); -static gint e_canvas_button (GtkWidget *widget, - GdkEventButton *event); - -static gint e_canvas_focus_in (GtkWidget *widget, - GdkEventFocus *event); -static gint e_canvas_focus_out (GtkWidget *widget, - GdkEventFocus *event); - -static void e_canvas_style_set (GtkWidget *widget, - GtkStyle *previous_style); - -static gint emit_event (GnomeCanvas *canvas, GdkEvent *event); - #define d(x) enum { @@ -53,95 +35,15 @@ enum { LAST_SIGNAL }; -static guint e_canvas_signals [LAST_SIGNAL] = { 0, }; +static guint signals[LAST_SIGNAL]; G_DEFINE_TYPE (ECanvas, e_canvas, GNOME_TYPE_CANVAS) -static void -e_canvas_class_init (ECanvasClass *klass) -{ - GObjectClass *object_class; - GtkWidgetClass *widget_class; - - object_class = (GObjectClass*) klass; - widget_class = (GtkWidgetClass *) klass; - - object_class->dispose = e_canvas_dispose; - - widget_class->key_press_event = e_canvas_key; - widget_class->key_release_event = e_canvas_key; - widget_class->button_press_event = e_canvas_button; - widget_class->button_release_event = e_canvas_button; - widget_class->focus_in_event = e_canvas_focus_in; - widget_class->focus_out_event = e_canvas_focus_out; - widget_class->style_set = e_canvas_style_set; - widget_class->realize = e_canvas_realize; - widget_class->unrealize = e_canvas_unrealize; - - klass->reflow = NULL; - - e_canvas_signals [REFLOW] = - g_signal_new ("reflow", - G_OBJECT_CLASS_TYPE (object_class), - G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (ECanvasClass, reflow), - NULL, NULL, - g_cclosure_marshal_VOID__VOID, - G_TYPE_NONE, 0); -} - -static void -e_canvas_init (ECanvas *canvas) -{ - canvas->selection = NULL; - canvas->cursor = NULL; - canvas->im_context = gtk_im_multicontext_new (); - canvas->tooltip_window = NULL; -} - -static void -e_canvas_dispose (GObject *object) -{ - ECanvas *canvas = E_CANVAS(object); - - if (canvas->idle_id) - g_source_remove(canvas->idle_id); - canvas->idle_id = 0; - - if (canvas->grab_cancelled_check_id) - g_source_remove (canvas->grab_cancelled_check_id); - canvas->grab_cancelled_check_id = 0; - - if (canvas->toplevel) { - if (canvas->visibility_notify_id) - g_signal_handler_disconnect (canvas->toplevel, - canvas->visibility_notify_id); - canvas->visibility_notify_id = 0; - - g_object_unref (canvas->toplevel); - canvas->toplevel = NULL; - } - - if (canvas->im_context) { - g_object_unref (canvas->im_context); - canvas->im_context = NULL; - } - - if ((G_OBJECT_CLASS (e_canvas_parent_class))->dispose) - (*(G_OBJECT_CLASS (e_canvas_parent_class))->dispose) (object); -} - -GtkWidget * -e_canvas_new (void) -{ - return GTK_WIDGET (g_object_new (E_CANVAS_TYPE, NULL)); -} - -/* Emits an event for an item in the canvas, be it the current item, grabbed - * item, or focused item, as appropriate. - */ +/* Emits an event for an item in the canvas, be it the current + * item, grabbed item, or focused item, as appropriate. */ static gint -emit_event (GnomeCanvas *canvas, GdkEvent *event) +canvas_emit_event (GnomeCanvas *canvas, + GdkEvent *event) { GdkEvent *ev; gint finished; @@ -166,77 +68,77 @@ emit_event (GnomeCanvas *canvas, GdkEvent *event) if (canvas->grabbed_item) { switch (event->type) { - case GDK_ENTER_NOTIFY: - mask = GDK_ENTER_NOTIFY_MASK; - break; + case GDK_ENTER_NOTIFY: + mask = GDK_ENTER_NOTIFY_MASK; + break; + + case GDK_LEAVE_NOTIFY: + mask = GDK_LEAVE_NOTIFY_MASK; + break; + + case GDK_MOTION_NOTIFY: + mask = GDK_POINTER_MOTION_MASK; + break; + + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + mask = GDK_BUTTON_PRESS_MASK; + break; + + case GDK_BUTTON_RELEASE: + mask = GDK_BUTTON_RELEASE_MASK; + break; + + case GDK_KEY_PRESS: + mask = GDK_KEY_PRESS_MASK; + break; + + case GDK_KEY_RELEASE: + mask = GDK_KEY_RELEASE_MASK; + break; + + default: + mask = 0; + break; + } + + if (!(mask & canvas->grabbed_event_mask)) + return FALSE; + } + + /* Convert to world coordinates -- we have two cases because of + * different offsets of the fields in the event structures. */ + + ev = gdk_event_copy (event); + switch (ev->type) { + case GDK_ENTER_NOTIFY: case GDK_LEAVE_NOTIFY: - mask = GDK_LEAVE_NOTIFY_MASK; + gnome_canvas_window_to_world ( + canvas, + ev->crossing.x, ev->crossing.y, + &ev->crossing.x, &ev->crossing.y); break; case GDK_MOTION_NOTIFY: - mask = GDK_POINTER_MOTION_MASK; - break; - case GDK_BUTTON_PRESS: case GDK_2BUTTON_PRESS: case GDK_3BUTTON_PRESS: - mask = GDK_BUTTON_PRESS_MASK; - break; - case GDK_BUTTON_RELEASE: - mask = GDK_BUTTON_RELEASE_MASK; - break; - - case GDK_KEY_PRESS: - mask = GDK_KEY_PRESS_MASK; - break; - - case GDK_KEY_RELEASE: - mask = GDK_KEY_RELEASE_MASK; + gnome_canvas_window_to_world ( + canvas, + ev->motion.x, ev->motion.y, + &ev->motion.x, &ev->motion.y); break; default: - mask = 0; break; - } - - if (!(mask & canvas->grabbed_event_mask)) - return FALSE; - } - - /* Convert to world coordinates -- we have two cases because of diferent - * offsets of the fields in the event structures. - */ - - ev = gdk_event_copy (event); - - switch (ev->type) { - case GDK_ENTER_NOTIFY: - case GDK_LEAVE_NOTIFY: - gnome_canvas_window_to_world (canvas, - ev->crossing.x, ev->crossing.y, - &ev->crossing.x, &ev->crossing.y); - break; - - case GDK_MOTION_NOTIFY: - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - case GDK_BUTTON_RELEASE: - gnome_canvas_window_to_world (canvas, - ev->motion.x, ev->motion.y, - &ev->motion.x, &ev->motion.y); - break; - - default: - break; } - /* The event is propagated up the hierarchy (for if someone connected to - * a group instead of a leaf event), and emission is stopped if a - * handler returns TRUE, just like for GtkWidget events. - */ + /* The event is propagated up the hierarchy (for if someone connected + * to a group instead of a leaf event), and emission is stopped if a + * handler returns TRUE, just like for GtkWidget events. */ finished = FALSE; @@ -256,28 +158,10 @@ emit_event (GnomeCanvas *canvas, GdkEvent *event) return finished; } -/* Key event handler for the canvas */ -static gint -e_canvas_key (GtkWidget *widget, GdkEventKey *event) -{ - GnomeCanvas *canvas; - GdkEvent full_event; - - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE); - g_return_val_if_fail (event != NULL, FALSE); - - canvas = GNOME_CANVAS (widget); - - full_event.key = *event; - - return emit_event (canvas, &full_event); -} - -/* This routine invokes the point method of the item. The argument x, y should - * be in the parent's item-relative coordinate system. This routine applies the - * inverse of the item's transform, maintaining the affine invariant. - */ +/* This routine invokes the point method of the item. The argument x, y + * should be in the parent's item-relative coordinate system. This routine + * applies the inverse of the item's transform, maintaining the affine + * invariant. */ #define HACKISH_AFFINE static double @@ -423,11 +307,12 @@ pick_current_item (GnomeCanvas *canvas, GdkEvent *event) new_event.crossing.detail = GDK_NOTIFY_ANCESTOR; new_event.crossing.subwindow = NULL; canvas->in_repick = TRUE; - retval = emit_event (canvas, &new_event); + retval = canvas_emit_event (canvas, &new_event); canvas->in_repick = FALSE; } - /* new_current_item may have been set to NULL during the call to emit_event() above */ + /* new_current_item may have been set to NULL during + * the call to canvas_emit_event() above. */ if ((canvas->new_current_item != canvas->current_item) && button_down) { canvas->left_grabbed_item = TRUE; @@ -446,22 +331,117 @@ pick_current_item (GnomeCanvas *canvas, GdkEvent *event) new_event.type = GDK_ENTER_NOTIFY; new_event.crossing.detail = GDK_NOTIFY_ANCESTOR; new_event.crossing.subwindow = NULL; - retval = emit_event (canvas, &new_event); + retval = canvas_emit_event (canvas, &new_event); } return retval; } -/* Button event handler for the canvas */ +static void +canvas_style_set_recursive (GnomeCanvasItem *item, + GtkStyle *previous_style) +{ + guint signal_id = g_signal_lookup ("style_set", G_OBJECT_TYPE (item)); + if (signal_id >= 1) { + GSignalQuery query; + g_signal_query (signal_id, &query); + if (query.return_type == G_TYPE_NONE && + query.n_params == 1 && + query.param_types[0] == GTK_TYPE_STYLE) { + g_signal_emit (item, signal_id, 0, previous_style); + } + } + + if (GNOME_IS_CANVAS_GROUP (item) ) { + GList *items = GNOME_CANVAS_GROUP (item)->item_list; + for (; items; items = items->next) + canvas_style_set_recursive ( + items->data, previous_style); + } +} + +static void +canvas_dispose (GObject *object) +{ + ECanvas *canvas = E_CANVAS(object); + + if (canvas->idle_id) + g_source_remove(canvas->idle_id); + canvas->idle_id = 0; + + if (canvas->grab_cancelled_check_id) + g_source_remove (canvas->grab_cancelled_check_id); + canvas->grab_cancelled_check_id = 0; + + if (canvas->toplevel) { + if (canvas->visibility_notify_id) + g_signal_handler_disconnect (canvas->toplevel, + canvas->visibility_notify_id); + canvas->visibility_notify_id = 0; + + g_object_unref (canvas->toplevel); + canvas->toplevel = NULL; + } + + if (canvas->im_context) { + g_object_unref (canvas->im_context); + canvas->im_context = NULL; + } + + /* Chain up to parent's dispose() method. */ + G_OBJECT_CLASS (e_canvas_parent_class)->dispose (object); +} + +static void +canvas_realize (GtkWidget *widget) +{ + ECanvas *ecanvas = E_CANVAS (widget); + GdkWindow *window; + + /* Chain up to parent's realize() method. */ + GTK_WIDGET_CLASS (e_canvas_parent_class)->realize (widget); + + window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); + gdk_window_set_back_pixmap (window, NULL, FALSE); + + window = gtk_widget_get_window (widget); + gtk_im_context_set_client_window (ecanvas->im_context, window); +} + +static void +canvas_unrealize (GtkWidget *widget) +{ + ECanvas * ecanvas = E_CANVAS (widget); + + if (ecanvas->idle_id) { + g_source_remove(ecanvas->idle_id); + ecanvas->idle_id = 0; + } + + gtk_im_context_set_client_window (ecanvas->im_context, NULL); + + /* Chain up to parent's unrealize() method. */ + GTK_WIDGET_CLASS (e_canvas_parent_class)->unrealize (widget); +} + +static void +canvas_style_set (GtkWidget *widget, + GtkStyle *previous_style) +{ + canvas_style_set_recursive ( + GNOME_CANVAS_ITEM (gnome_canvas_root ( + GNOME_CANVAS (widget))), previous_style); +} + static gint -e_canvas_button (GtkWidget *widget, GdkEventButton *event) +canvas_button_event (GtkWidget *widget, + GdkEventButton *event) { GnomeCanvas *canvas; GdkWindow *bin_window; gint mask; gint retval; - g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE); @@ -482,109 +462,75 @@ e_canvas_button (GtkWidget *widget, GdkEventButton *event) return retval; switch (event->button) { - case 1: - mask = GDK_BUTTON1_MASK; - break; - case 2: - mask = GDK_BUTTON2_MASK; - break; - case 3: - mask = GDK_BUTTON3_MASK; - break; - case 4: - mask = GDK_BUTTON4_MASK; - break; - case 5: - mask = GDK_BUTTON5_MASK; - break; - default: - mask = 0; + case 1: + mask = GDK_BUTTON1_MASK; + break; + case 2: + mask = GDK_BUTTON2_MASK; + break; + case 3: + mask = GDK_BUTTON3_MASK; + break; + case 4: + mask = GDK_BUTTON4_MASK; + break; + case 5: + mask = GDK_BUTTON5_MASK; + break; + default: + mask = 0; } switch (event->type) { - case GDK_BUTTON_PRESS: - case GDK_2BUTTON_PRESS: - case GDK_3BUTTON_PRESS: - /* Pick the current item as if the button were not pressed, and - * then process the event. - */ - canvas->state = event->state; - pick_current_item (canvas, (GdkEvent *) event); - canvas->state ^= mask; - retval = emit_event (canvas, (GdkEvent *) event); - break; - - case GDK_BUTTON_RELEASE: - /* Process the event as if the button were pressed, then repick - * after the button has been released - */ - canvas->state = event->state; - retval = emit_event (canvas, (GdkEvent *) event); - event->state ^= mask; - canvas->state = event->state; - pick_current_item (canvas, (GdkEvent *) event); - event->state ^= mask; - break; - - default: - g_return_val_if_reached(0); + case GDK_BUTTON_PRESS: + case GDK_2BUTTON_PRESS: + case GDK_3BUTTON_PRESS: + /* Pick the current item as if the button were not + * pressed, and then process the event. */ + canvas->state = event->state; + pick_current_item (canvas, (GdkEvent *) event); + canvas->state ^= mask; + retval = canvas_emit_event (canvas, (GdkEvent *) event); + break; + + case GDK_BUTTON_RELEASE: + /* Process the event as if the button were pressed, + * then repick after the button has been released. */ + canvas->state = event->state; + retval = canvas_emit_event (canvas, (GdkEvent *) event); + event->state ^= mask; + canvas->state = event->state; + pick_current_item (canvas, (GdkEvent *) event); + event->state ^= mask; + break; + + default: + g_return_val_if_reached (0); } return retval; } -/** - * e_canvas_item_grab_focus: - * @item: A canvas item. - * @widget_too: Whether or not to grab the widget-level focus too - * - * Makes the specified item take the keyboard focus, so all keyboard - * events will be sent to it. If the canvas widget itself did not have - * the focus and @widget_too is %TRUE, it grabs that focus as well. - **/ -void -e_canvas_item_grab_focus (GnomeCanvasItem *item, gboolean widget_too) +static gint +canvas_key_event (GtkWidget *widget, + GdkEventKey *event) { - GnomeCanvasItem *focused_item; - GdkWindow *bin_window; - GdkEvent ev; - - g_return_if_fail (item != NULL); - g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); - g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas))); - - bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)); - - focused_item = item->canvas->focused_item; - - if (focused_item) { - ev.focus_change.type = GDK_FOCUS_CHANGE; - ev.focus_change.window = bin_window; - ev.focus_change.send_event = FALSE; - ev.focus_change.in = FALSE; - - emit_event (item->canvas, &ev); - } + GnomeCanvas *canvas; + GdkEvent full_event; - item->canvas->focused_item = item; + g_return_val_if_fail (GNOME_IS_CANVAS (widget), FALSE); + g_return_val_if_fail (event != NULL, FALSE); - if (widget_too && !gtk_widget_has_focus (GTK_WIDGET(item->canvas))) { - gtk_widget_grab_focus (GTK_WIDGET (item->canvas)); - } + canvas = GNOME_CANVAS (widget); - if (item) { - ev.focus_change.type = GDK_FOCUS_CHANGE; - ev.focus_change.window = bin_window; - ev.focus_change.send_event = FALSE; - ev.focus_change.in = TRUE; + full_event.key = *event; - emit_event (item->canvas, &ev); - } + return canvas_emit_event (canvas, &full_event); } -/* Focus in handler for the canvas */ static gint -e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event) +canvas_focus_in_event (GtkWidget *widget, + GdkEventFocus *event) { GnomeCanvas *canvas; ECanvas *ecanvas; @@ -603,15 +549,15 @@ e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event) if (canvas->focused_item) { full_event.focus_change = *event; - return emit_event (canvas, &full_event); + return canvas_emit_event (canvas, &full_event); } else { return FALSE; } } -/* Focus out handler for the canvas */ static gint -e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) +canvas_focus_out_event (GtkWidget *widget, + GdkEventFocus *event) { GnomeCanvas *canvas; ECanvas *ecanvas; @@ -630,75 +576,106 @@ e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) if (canvas->focused_item) { full_event.focus_change = *event; - return emit_event (canvas, &full_event); + return canvas_emit_event (canvas, &full_event); } else { return FALSE; } } static void -ec_style_set_recursive (GnomeCanvasItem *item, GtkStyle *previous_style) +e_canvas_class_init (ECanvasClass *class) { - guint signal_id = g_signal_lookup ("style_set", G_OBJECT_TYPE (item)); - if (signal_id >= 1) { - GSignalQuery query; - g_signal_query (signal_id, &query); - if (query.return_type == G_TYPE_NONE && - query.n_params == 1 && - query.param_types[0] == GTK_TYPE_STYLE) { - g_signal_emit (item, signal_id, 0, previous_style); - } - } + GObjectClass *object_class; + GtkWidgetClass *widget_class; - if (GNOME_IS_CANVAS_GROUP (item) ) { - GList *items = GNOME_CANVAS_GROUP (item)->item_list; - for (; items; items = items->next) - ec_style_set_recursive (items->data, previous_style); - } + object_class = G_OBJECT_CLASS (class); + object_class->dispose = canvas_dispose; + + widget_class = GTK_WIDGET_CLASS (class); + widget_class->realize = canvas_realize; + widget_class->unrealize = canvas_unrealize; + widget_class->style_set = canvas_style_set; + widget_class->button_press_event = canvas_button_event; + widget_class->button_release_event = canvas_button_event; + widget_class->key_press_event = canvas_key_event; + widget_class->key_release_event = canvas_key_event; + widget_class->focus_in_event = canvas_focus_in_event; + widget_class->focus_out_event = canvas_focus_out_event; + + signals[REFLOW] = g_signal_new ( + "reflow", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (ECanvasClass, reflow), + NULL, NULL, + g_cclosure_marshal_VOID__VOID, + G_TYPE_NONE, 0); } static void -e_canvas_style_set (GtkWidget *widget, GtkStyle *previous_style) +e_canvas_init (ECanvas *canvas) { - ec_style_set_recursive ( - GNOME_CANVAS_ITEM (gnome_canvas_root (GNOME_CANVAS (widget))), - previous_style); + canvas->im_context = gtk_im_multicontext_new (); } -static void -e_canvas_realize (GtkWidget *widget) +GtkWidget * +e_canvas_new (void) { - ECanvas *ecanvas = E_CANVAS (widget); - GdkWindow *window; + return g_object_new (E_TYPE_CANVAS, NULL); +} - if (GTK_WIDGET_CLASS (e_canvas_parent_class)->realize) - (* GTK_WIDGET_CLASS (e_canvas_parent_class)->realize) (widget); +/** + * e_canvas_item_grab_focus: + * @item: A canvas item. + * @widget_too: Whether or not to grab the widget-level focus too + * + * Makes the specified item take the keyboard focus, so all keyboard + * events will be sent to it. If the canvas widget itself did not have + * the focus and @widget_too is %TRUE, it grabs that focus as well. + **/ +void +e_canvas_item_grab_focus (GnomeCanvasItem *item, + gboolean widget_too) +{ + GnomeCanvasItem *focused_item; + GdkWindow *bin_window; + GdkEvent ev; - window = gtk_layout_get_bin_window (GTK_LAYOUT (widget)); - gdk_window_set_back_pixmap (window, NULL, FALSE); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + g_return_if_fail (gtk_widget_get_can_focus (GTK_WIDGET (item->canvas))); - window = gtk_widget_get_window (widget); - gtk_im_context_set_client_window (ecanvas->im_context, window); -} + bin_window = gtk_layout_get_bin_window (GTK_LAYOUT (item->canvas)); -static void -e_canvas_unrealize (GtkWidget *widget) -{ - ECanvas * ecanvas = E_CANVAS (widget); + focused_item = item->canvas->focused_item; - if (ecanvas->idle_id) { - g_source_remove(ecanvas->idle_id); - ecanvas->idle_id = 0; + if (focused_item) { + ev.focus_change.type = GDK_FOCUS_CHANGE; + ev.focus_change.window = bin_window; + ev.focus_change.send_event = FALSE; + ev.focus_change.in = FALSE; + + canvas_emit_event (item->canvas, &ev); } - gtk_im_context_set_client_window (ecanvas->im_context, NULL); + item->canvas->focused_item = item; + + if (widget_too && !gtk_widget_has_focus (GTK_WIDGET(item->canvas))) { + gtk_widget_grab_focus (GTK_WIDGET (item->canvas)); + } - if (GTK_WIDGET_CLASS (e_canvas_parent_class)->unrealize) - (* GTK_WIDGET_CLASS (e_canvas_parent_class)->unrealize) (widget); + if (item) { + ev.focus_change.type = GDK_FOCUS_CHANGE; + ev.focus_change.window = bin_window; + ev.focus_change.send_event = FALSE; + ev.focus_change.in = TRUE; + + canvas_emit_event (item->canvas, &ev); + } } static void -e_canvas_item_invoke_reflow (GnomeCanvasItem *item, gint flags) +e_canvas_item_invoke_reflow (GnomeCanvasItem *item, + gint flags) { GnomeCanvasGroup *group; GList *list; @@ -747,8 +724,7 @@ idle_handler (gpointer data) /* Reset idle id */ canvas->idle_id = 0; - g_signal_emit (canvas, - e_canvas_signals [REFLOW], 0); + g_signal_emit (canvas, signals [REFLOW], 0); GDK_THREADS_LEAVE(); @@ -780,6 +756,8 @@ e_canvas_item_descendent_needs_reflow (GnomeCanvasItem *item) void e_canvas_item_request_reflow (GnomeCanvasItem *item) { + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + if (item->flags & GNOME_CANVAS_ITEM_REALIZED) { item->flags |= E_CANVAS_ITEM_NEEDS_REFLOW; e_canvas_item_descendent_needs_reflow(item); @@ -790,15 +768,21 @@ e_canvas_item_request_reflow (GnomeCanvasItem *item) void e_canvas_item_request_parent_reflow (GnomeCanvasItem *item) { - g_return_if_fail(item != NULL); - g_return_if_fail(GNOME_IS_CANVAS_ITEM(item)); - e_canvas_item_request_reflow(item->parent); + g_return_if_fail (GNOME_IS_CANVAS_ITEM(item)); + + e_canvas_item_request_reflow (item->parent); } void -e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, ECanvasItemReflowFunc func) +e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, + ECanvasItemReflowFunc func) { - g_object_set_data(G_OBJECT(item), "ECanvasItem::reflow_callback", (gpointer) func); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + g_return_if_fail (func != NULL); + + g_object_set_data ( + G_OBJECT(item), "ECanvasItem::reflow_callback", + (gpointer) func); } static gboolean @@ -833,38 +817,43 @@ grab_cancelled_check (gpointer data) gint e_canvas_item_grab (ECanvas *canvas, - GnomeCanvasItem *item, - guint event_mask, - GdkCursor *cursor, - guint32 etime, - ECanvasItemGrabCancelled cancelled_cb, - gpointer cancelled_data) + GnomeCanvasItem *item, + guint event_mask, + GdkCursor *cursor, + guint32 etime, + ECanvasItemGrabCancelled cancelled_cb, + gpointer cancelled_data) { - if (gtk_grab_get_current ()) { + gint ret_val; + + g_return_val_if_fail (E_IS_CANVAS (canvas), -1); + g_return_val_if_fail (GNOME_IS_CANVAS_ITEM (item), -1); + + if (gtk_grab_get_current ()) return GDK_GRAB_ALREADY_GRABBED; - } else { - gint ret_val = gnome_canvas_item_grab (item, event_mask, cursor, etime); - if (ret_val == GDK_GRAB_SUCCESS) { - canvas->grab_cancelled_cb = cancelled_cb; - canvas->grab_cancelled_check_id = - g_timeout_add_full (G_PRIORITY_LOW, - 100, - grab_cancelled_check, - canvas, - NULL); - canvas->grab_cancelled_time = etime; - canvas->grab_cancelled_data = cancelled_data; - } - return ret_val; + ret_val = gnome_canvas_item_grab ( + item, event_mask, cursor, etime); + if (ret_val == GDK_GRAB_SUCCESS) { + canvas->grab_cancelled_cb = cancelled_cb; + canvas->grab_cancelled_check_id = g_timeout_add_full ( + G_PRIORITY_LOW, 100, + grab_cancelled_check, canvas, NULL); + canvas->grab_cancelled_time = etime; + canvas->grab_cancelled_data = cancelled_data; } + + return ret_val; } void e_canvas_item_ungrab (ECanvas *canvas, - GnomeCanvasItem *item, - guint32 etime) + GnomeCanvasItem *item, + guint32 etime) { + g_return_if_fail (E_IS_CANVAS (canvas)); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + if (canvas->grab_cancelled_check_id) { g_source_remove (canvas->grab_cancelled_check_id); canvas->grab_cancelled_cb = NULL; diff --git a/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h index ea2364c749..fbcdd44981 100644 --- a/widgets/misc/e-canvas.h +++ b/widgets/misc/e-canvas.h @@ -20,38 +20,51 @@ * */ -#ifndef __E_CANVAS_H__ -#define __E_CANVAS_H__ +#ifndef E_CANVAS_H +#define E_CANVAS_H #include <gtk/gtk.h> #include <libgnomecanvas/gnome-canvas.h> -G_BEGIN_DECLS - /* ECanvas - A class derived from canvas for the purpose of adding - * evolution specific canvas hacks. - */ + * evolution specific canvas hacks. */ + +/* Standard GObject macros */ +#define E_TYPE_CANVAS \ + (e_canvas_get_type ()) +#define E_CANVAS(obj) \ + (G_TYPE_CHECK_INSTANCE_CAST \ + ((obj), E_TYPE_CANVAS, ECanvas)) +#define E_CANVAS_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_CAST \ + ((cls), E_TYPE_CANVAS, ECanvasClass)) +#define E_IS_CANVAS(obj) \ + (G_TYPE_CHECK_INSTANCE_TYPE \ + ((obj), E_TYPE_CANVAS)) +#define E_IS_CANVAS_CLASS(cls) \ + (G_TYPE_CHECK_CLASS_TYPE \ + ((cls), E_TYPE_CANVAS)) +#define E_CANVAS_GET_CLASS(obj) \ + (G_TYPE_INSTANCE_GET_CLASS \ + ((obj), E_TYPE_CANVAS, ECanvasClass)) -#define E_CANVAS_TYPE (e_canvas_get_type ()) -#define E_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), E_CANVAS_TYPE, ECanvas)) -#define E_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), E_CANVAS_TYPE, ECanvasClass)) -#define E_IS_CANVAS(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), E_CANVAS_TYPE)) -#define E_IS_CANVAS_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), E_CANVAS_TYPE)) +G_BEGIN_DECLS -typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item, - gint flags); +typedef void (*ECanvasItemReflowFunc) (GnomeCanvasItem *item, + gint flags); -typedef void (*ECanvasItemSelectionFunc) (GnomeCanvasItem *item, - gint flags, - gpointer user_data); +typedef void (*ECanvasItemSelectionFunc) (GnomeCanvasItem *item, + gint flags, + gpointer user_data); /* Returns the same as strcmp does. */ -typedef gint (*ECanvasItemSelectionCompareFunc) (GnomeCanvasItem *item, - gpointer data1, - gpointer data2, - gint flags); +typedef gint (*ECanvasItemSelectionCompareFunc) + (GnomeCanvasItem *item, + gpointer data1, + gpointer data2, + gint flags); -typedef struct _ECanvas ECanvas; -typedef struct _ECanvasClass ECanvasClass; +typedef struct _ECanvas ECanvas; +typedef struct _ECanvasClass ECanvasClass; /* Object flags for items */ enum { @@ -70,18 +83,20 @@ typedef struct { gpointer id; } ECanvasSelectionInfo; -typedef void (*ECanvasItemGrabCancelled) (ECanvas *canvas, GnomeCanvasItem *item, gpointer data); +typedef void (*ECanvasItemGrabCancelled) (ECanvas *canvas, + GnomeCanvasItem *item, + gpointer data); -struct _ECanvas -{ +struct _ECanvas { GnomeCanvas parent; - gint idle_id; - GList *selection; + + gint idle_id; + GList *selection; ECanvasSelectionInfo *cursor; - GtkWidget *tooltip_window; - gint visibility_notify_id; - GtkWidget *toplevel; + GtkWidget *tooltip_window; + gint visibility_notify_id; + GtkWidget *toplevel; /* Input context for dead key support */ GtkIMContext *im_context; @@ -92,36 +107,36 @@ struct _ECanvas gpointer grab_cancelled_data; }; -struct _ECanvasClass -{ +struct _ECanvasClass { GnomeCanvasClass parent_class; - void (* reflow) (ECanvas *canvas); + + void (*reflow) (ECanvas *canvas); }; -GType e_canvas_get_type (void); -GtkWidget *e_canvas_new (void); +GType e_canvas_get_type (void); +GtkWidget * e_canvas_new (void); /* Used to send all of the keystroke events to a specific item as well as - * GDK_FOCUS_CHANGE events. - */ -void e_canvas_item_grab_focus (GnomeCanvasItem *item, - gboolean widget_too); -void e_canvas_item_request_reflow (GnomeCanvasItem *item); -void e_canvas_item_request_parent_reflow (GnomeCanvasItem *item); -void e_canvas_item_set_reflow_callback (GnomeCanvasItem *item, - ECanvasItemReflowFunc func); - -gint e_canvas_item_grab (ECanvas *canvas, - GnomeCanvasItem *item, - guint event_mask, - GdkCursor *cursor, - guint32 etime, - ECanvasItemGrabCancelled cancelled, - gpointer cancelled_data); -void e_canvas_item_ungrab (ECanvas *canvas, - GnomeCanvasItem *item, - guint32 etime); + * GDK_FOCUS_CHANGE events. */ +void e_canvas_item_grab_focus (GnomeCanvasItem *item, + gboolean widget_too); +void e_canvas_item_request_reflow (GnomeCanvasItem *item); +void e_canvas_item_request_parent_reflow + (GnomeCanvasItem *item); +void e_canvas_item_set_reflow_callback + (GnomeCanvasItem *item, + ECanvasItemReflowFunc func); +gint e_canvas_item_grab (ECanvas *canvas, + GnomeCanvasItem *item, + guint event_mask, + GdkCursor *cursor, + guint32 etime, + ECanvasItemGrabCancelled cancelled, + gpointer cancelled_data); +void e_canvas_item_ungrab (ECanvas *canvas, + GnomeCanvasItem *item, + guint32 etime); G_END_DECLS -#endif /* __E_CANVAS_H__ */ +#endif /* E_CANVAS_H */ |