From 905f7de48f5c591caa340f099fff821e07bf82e4 Mon Sep 17 00:00:00 2001 From: Christopher James Lahey Date: Thu, 27 Jan 2000 07:51:37 +0000 Subject: Use e_canvas_item_grab_focus so that it will work with old versions of 2000-01-28 Christopher James Lahey * widgets/e-minicard-label.c, widgets/e-minicard.c: Use e_canvas_item_grab_focus so that it will work with old versions of gnome-canvas. * widgets/e-canvas.c, widgets/e-canvas.h: Finished working around focus bugs. svn path=/trunk/; revision=1649 --- e-util/e-canvas.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ e-util/e-canvas.h | 5 ++++ 2 files changed, 73 insertions(+) (limited to 'e-util') diff --git a/e-util/e-canvas.c b/e-util/e-canvas.c index 74af105b36..850e438386 100644 --- a/e-util/e-canvas.c +++ b/e-util/e-canvas.c @@ -27,6 +27,11 @@ static void e_canvas_class_init (ECanvasClass *klass); static gint e_canvas_key (GtkWidget *widget, GdkEventKey *event); +static gint e_canvas_focus_in (GtkWidget *widget, + GdkEventFocus *event); +static gint e_canvas_focus_out (GtkWidget *widget, + GdkEventFocus *event); + static int emit_event (GnomeCanvas *canvas, GdkEvent *event); static GnomeCanvasClass *parent_class = NULL; @@ -71,6 +76,8 @@ e_canvas_class_init (ECanvasClass *klass) widget_class->key_press_event = e_canvas_key; widget_class->key_release_event = e_canvas_key; + widget_class->focus_in_event = e_canvas_focus_in; + widget_class->focus_out_event = e_canvas_focus_out; } static void @@ -231,3 +238,64 @@ e_canvas_key (GtkWidget *widget, GdkEventKey *event) return emit_event (canvas, (GdkEvent *) event); } + +/** + * e_canvas_item_grab_focus: + * @item: A canvas item. + * + * 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, it grabs + * it as well. + **/ +void +e_canvas_item_grab_focus (GnomeCanvasItem *item) +{ + GnomeCanvasItem *focused_item; + GdkEvent ev; + + g_return_if_fail (item != NULL); + g_return_if_fail (GNOME_IS_CANVAS_ITEM (item)); + g_return_if_fail (GTK_WIDGET_CAN_FOCUS (GTK_WIDGET (item->canvas))); + + focused_item = item->canvas->focused_item; + + if (focused_item) { + ev.focus_change.type = GDK_FOCUS_CHANGE; + ev.focus_change.window = GTK_LAYOUT (item->canvas)->bin_window; + ev.focus_change.send_event = FALSE; + ev.focus_change.in = FALSE; + + emit_event (item->canvas, &ev); + } + + item->canvas->focused_item = item; + gtk_widget_grab_focus (GTK_WIDGET (item->canvas)); +} + +/* Focus in handler for the canvas */ +static gint +e_canvas_focus_in (GtkWidget *widget, GdkEventFocus *event) +{ + GnomeCanvas *canvas; + + canvas = GNOME_CANVAS (widget); + + if (canvas->focused_item) + return emit_event (canvas, (GdkEvent *) event); + else + return FALSE; +} + +/* Focus out handler for the canvas */ +static gint +e_canvas_focus_out (GtkWidget *widget, GdkEventFocus *event) +{ + GnomeCanvas *canvas; + + canvas = GNOME_CANVAS (widget); + + if (canvas->focused_item) + return emit_event (canvas, (GdkEvent *) event); + else + return FALSE; +} diff --git a/e-util/e-canvas.h b/e-util/e-canvas.h index 06c3625f3a..0ece5ae3b4 100644 --- a/e-util/e-canvas.h +++ b/e-util/e-canvas.h @@ -58,6 +58,11 @@ struct _ECanvasClass GtkType 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); + #ifdef __cplusplus } #endif /* __cplusplus */ -- cgit v1.2.3