[gimp/soc-2010-cage] app: fix keyboard focus navigation in overlay children



commit 18e2dd7072f5637e006238ff8c1e42acedc3fa1e
Author: Michael Natterer <mitch gimp org>
Date:   Sat Jun 12 18:39:21 2010 +0200

    app: fix keyboard focus navigation in overlay children
    
    Implement GtkWidget::focus() and override GtkContainer's focus()
    implementation which would always give focus to the canvas because it
    is focussable. Instead, try navigating in the focussed overlay child
    first, and use GtkContainer's default implementation only if that
    fails (which happens when focus navigation leaves the overlay child).

 app/display/gimpcanvas.c |   23 +++++++++++++++++++++++
 1 files changed, 23 insertions(+), 0 deletions(-)
---
diff --git a/app/display/gimpcanvas.c b/app/display/gimpcanvas.c
index 4942d6f..08d94c6 100644
--- a/app/display/gimpcanvas.c
+++ b/app/display/gimpcanvas.c
@@ -64,6 +64,8 @@ static gboolean   gimp_canvas_focus_in_event  (GtkWidget       *widget,
                                                GdkEventFocus   *event);
 static gboolean   gimp_canvas_focus_out_event (GtkWidget       *widget,
                                                GdkEventFocus   *event);
+static gboolean   gimp_canvas_focus           (GtkWidget       *widget,
+                                               GtkDirectionType direction);
 
 static GdkGC    * gimp_canvas_gc_new          (GimpCanvas      *canvas,
                                                GimpCanvasStyle  style);
@@ -173,6 +175,7 @@ gimp_canvas_class_init (GimpCanvasClass *klass)
   widget_class->style_set       = gimp_canvas_style_set;
   widget_class->focus_in_event  = gimp_canvas_focus_in_event;
   widget_class->focus_out_event = gimp_canvas_focus_out_event;
+  widget_class->focus           = gimp_canvas_focus;
 
   g_object_class_install_property (object_class, PROP_CONFIG,
                                    g_param_spec_object ("config", NULL, NULL,
@@ -316,6 +319,26 @@ gimp_canvas_focus_out_event (GtkWidget     *widget,
   return FALSE;
 }
 
+static gboolean
+gimp_canvas_focus (GtkWidget        *widget,
+                   GtkDirectionType  direction)
+{
+  GtkWidget *focus = gtk_container_get_focus_child (GTK_CONTAINER (widget));
+
+  /* override GtkContainer's focus() implementation which would always
+   * give focus to the canvas because it is focussable. Instead, try
+   * navigating in the focussed overlay child first, and use
+   * GtkContainer's default implementation only if that fails (which
+   * happens when cursor navigation leaves the overlay child's
+   * widget).
+   */
+
+  if (focus && gtk_widget_child_focus (focus, direction))
+    return TRUE;
+
+  return GTK_WIDGET_CLASS (parent_class)->focus (widget, direction);
+}
+
 /* Returns: %TRUE if the XOR color is not white */
 static gboolean
 gimp_canvas_get_xor_color (GimpCanvas *canvas,



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]