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 --- widgets/e-canvas.c | 68 +++++++++++++++++++++++++++++++++++ widgets/e-canvas.h | 5 +++ widgets/e-minicard-label.c | 3 +- widgets/e-minicard.c | 5 +-- widgets/e-minicard/e-minicard-label.c | 3 +- widgets/e-minicard/e-minicard.c | 5 +-- widgets/misc/e-canvas.c | 68 +++++++++++++++++++++++++++++++++++ widgets/misc/e-canvas.h | 5 +++ 8 files changed, 156 insertions(+), 6 deletions(-) (limited to 'widgets') diff --git a/widgets/e-canvas.c b/widgets/e-canvas.c index 74af105b36..850e438386 100644 --- a/widgets/e-canvas.c +++ b/widgets/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/widgets/e-canvas.h b/widgets/e-canvas.h index 06c3625f3a..0ece5ae3b4 100644 --- a/widgets/e-canvas.h +++ b/widgets/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 */ diff --git a/widgets/e-minicard-label.c b/widgets/e-minicard-label.c index 2b0fb3faf8..43603f2d6d 100644 --- a/widgets/e-minicard-label.c +++ b/widgets/e-minicard-label.c @@ -23,6 +23,7 @@ #include #include "e-minicard-label.h" #include "e-text.h" +#include "e-canvas.h" static void e_minicard_label_init (EMinicardLabel *card); static void e_minicard_label_class_init (EMinicardLabelClass *klass); static void e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -152,7 +153,7 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) break; case ARG_HAS_FOCUS: if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) - gnome_canvas_item_grab_focus(e_minicard_label->field); + e_canvas_item_grab_focus(e_minicard_label->field); break; case ARG_FIELD: if ( e_minicard_label->field ) diff --git a/widgets/e-minicard.c b/widgets/e-minicard.c index b6de4b2d0c..b667f1ac21 100644 --- a/widgets/e-minicard.c +++ b/widgets/e-minicard.c @@ -24,6 +24,7 @@ #include "e-minicard.h" #include "e-minicard-label.h" #include "e-text.h" +#include "e-canvas.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -153,7 +154,7 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "has_focus", GTK_VALUE_BOOL(*arg), NULL); else - gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); @@ -353,7 +354,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) break; case GDK_BUTTON_PRESS: if (event->button.button == 1) { - gnome_canvas_item_grab_focus(item); + e_canvas_item_grab_focus(item); } break; case GDK_KEY_PRESS: diff --git a/widgets/e-minicard/e-minicard-label.c b/widgets/e-minicard/e-minicard-label.c index 2b0fb3faf8..43603f2d6d 100644 --- a/widgets/e-minicard/e-minicard-label.c +++ b/widgets/e-minicard/e-minicard-label.c @@ -23,6 +23,7 @@ #include #include "e-minicard-label.h" #include "e-text.h" +#include "e-canvas.h" static void e_minicard_label_init (EMinicardLabel *card); static void e_minicard_label_class_init (EMinicardLabelClass *klass); static void e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -152,7 +153,7 @@ e_minicard_label_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) break; case ARG_HAS_FOCUS: if (e_minicard_label->field && GTK_VALUE_BOOL(*arg)) - gnome_canvas_item_grab_focus(e_minicard_label->field); + e_canvas_item_grab_focus(e_minicard_label->field); break; case ARG_FIELD: if ( e_minicard_label->field ) diff --git a/widgets/e-minicard/e-minicard.c b/widgets/e-minicard/e-minicard.c index b6de4b2d0c..b667f1ac21 100644 --- a/widgets/e-minicard/e-minicard.c +++ b/widgets/e-minicard/e-minicard.c @@ -24,6 +24,7 @@ #include "e-minicard.h" #include "e-minicard-label.h" #include "e-text.h" +#include "e-canvas.h" static void e_minicard_init (EMinicard *card); static void e_minicard_class_init (EMinicardClass *klass); static void e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id); @@ -153,7 +154,7 @@ e_minicard_set_arg (GtkObject *o, GtkArg *arg, guint arg_id) "has_focus", GTK_VALUE_BOOL(*arg), NULL); else - gnome_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); + e_canvas_item_grab_focus(GNOME_CANVAS_ITEM(e_minicard)); break; case ARG_CARD: /* e_minicard->card = GTK_VALUE_POINTER (*arg); @@ -353,7 +354,7 @@ e_minicard_event (GnomeCanvasItem *item, GdkEvent *event) break; case GDK_BUTTON_PRESS: if (event->button.button == 1) { - gnome_canvas_item_grab_focus(item); + e_canvas_item_grab_focus(item); } break; case GDK_KEY_PRESS: diff --git a/widgets/misc/e-canvas.c b/widgets/misc/e-canvas.c index 74af105b36..850e438386 100644 --- a/widgets/misc/e-canvas.c +++ b/widgets/misc/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/widgets/misc/e-canvas.h b/widgets/misc/e-canvas.h index 06c3625f3a..0ece5ae3b4 100644 --- a/widgets/misc/e-canvas.h +++ b/widgets/misc/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