[recipes] Redo the event handling for the image page



commit 67b9cdd9155d69d139734a43e9123bffd454d894
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Mar 12 21:58:57 2017 -0400

    Redo the event handling for the image page
    
    Instead of forwarding events from GrWindow, grab focus to the
    event box and handle events on it. This makes keynav in the
    fullscreen image view work again.
    
    This uncovered a problem with the focus grabbing we now do in
    gr_edit_page_clear - it may end up grabbing the focus to an
    unrealized entry, which leads to critical warnings. So, redo
    this as well, by doing the focus grabbing separately, and
    only do it when we are actually showing the edit page.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=779958

 src/gr-edit-page.c   |   17 +++++++++++------
 src/gr-image-page.c  |   24 +++++++++++++++++++-----
 src/gr-image-page.ui |    3 +++
 src/gr-window.c      |    9 +++++++--
 4 files changed, 40 insertions(+), 13 deletions(-)
---
diff --git a/src/gr-edit-page.c b/src/gr-edit-page.c
index 9ec3f46..b6678eb 100644
--- a/src/gr-edit-page.c
+++ b/src/gr-edit-page.c
@@ -1459,13 +1459,21 @@ gr_edit_page_get_property (GObject    *object,
         }
 }
 
-static
-void set_unsaved (GrEditPage *page)
+static void
+set_unsaved (GrEditPage *page)
 {
         g_object_set (G_OBJECT (page),"unsaved", TRUE, NULL);
 }
 
 static void
+gr_edit_page_grab_focus (GtkWidget *widget)
+{
+        GrEditPage *self = GR_EDIT_PAGE (widget);
+
+        gtk_widget_grab_focus (self->name_entry);
+}
+
+static void
 gr_edit_page_class_init (GrEditPageClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -1475,6 +1483,7 @@ gr_edit_page_class_init (GrEditPageClass *klass)
         object_class->set_property = gr_edit_page_set_property;
         object_class->get_property = gr_edit_page_get_property;
 
+        widget_class->grab_focus = gr_edit_page_grab_focus;
 
         props [PROP_UNSAVED] = g_param_spec_boolean ("unsaved",
                                                       NULL, NULL,
@@ -1900,8 +1909,6 @@ gr_edit_page_clear (GrEditPage *page)
 
         store = gr_recipe_store_get ();
 
-        gtk_widget_grab_focus (page->name_entry);
-
         gtk_label_set_label (GTK_LABEL (page->name_label), _("Name Your Recipe"));
         gtk_entry_set_text (GTK_ENTRY (page->name_entry), "");
         set_combo_value (GTK_COMBO_BOX (page->cuisine_combo), "");
@@ -2104,8 +2111,6 @@ gr_edit_page_edit (GrEditPage *page,
 
         update_author_label (page, chef);
 
-        gtk_widget_grab_focus (page->name_entry);
-
         if (page->index_handler_id) {
                 g_signal_handler_disconnect (page->recipe, page->index_handler_id);
                 page->index_handler_id = 0;
diff --git a/src/gr-image-page.c b/src/gr-image-page.c
index ffb0406..c70716b 100644
--- a/src/gr-image-page.c
+++ b/src/gr-image-page.c
@@ -216,11 +216,6 @@ gr_image_page_init (GrImagePage *self)
 {
         gtk_widget_init_template (GTK_WIDGET (self));
 
-        gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_POINTER_MOTION_MASK);
-        gtk_widget_add_events (GTK_WIDGET (self->event_box), GDK_BUTTON_PRESS_MASK);
-g_signal_connect (self->event_box, "motion-notify-event", G_CALLBACK (motion_notify), self);
-        g_signal_connect (self->event_box, "key-press-event", G_CALLBACK (key_press_event), self);
-
         self->images = gr_image_array_new ();
 }
 
@@ -263,6 +258,14 @@ gr_image_page_set_property (GObject      *object,
 }
 
 static void
+gr_image_page_grab_focus (GtkWidget *widget)
+{
+        GrImagePage *self = GR_IMAGE_PAGE (widget);
+
+        gtk_widget_grab_focus (self->event_box);
+}
+
+static void
 gr_image_page_class_init (GrImagePageClass *klass)
 {
         GObjectClass *object_class = G_OBJECT_CLASS (klass);
@@ -273,6 +276,8 @@ gr_image_page_class_init (GrImagePageClass *klass)
         object_class->get_property = gr_image_page_get_property;
         object_class->set_property = gr_image_page_set_property;
 
+        widget_class->grab_focus = gr_image_page_grab_focus;
+
         pspec = g_param_spec_boxed ("images", NULL, NULL,
                                     G_TYPE_ARRAY,
                                     G_PARAM_READWRITE);
@@ -288,6 +293,8 @@ gr_image_page_class_init (GrImagePageClass *klass)
         gtk_widget_class_bind_template_callback (widget_class, stop_viewing);
         gtk_widget_class_bind_template_callback (widget_class, prev_image);
         gtk_widget_class_bind_template_callback (widget_class, next_image);
+        gtk_widget_class_bind_template_callback (widget_class, key_press_event);
+        gtk_widget_class_bind_template_callback (widget_class, motion_notify);
 }
 
 static void
@@ -337,3 +344,10 @@ gr_image_page_show_image (GrImagePage *page,
                 set_current_image (page);
         }
 }
+
+gboolean
+gr_image_page_handle_event (GrImagePage *page,
+                            GdkEvent    *event)
+{
+        return FALSE;
+}
diff --git a/src/gr-image-page.ui b/src/gr-image-page.ui
index 330a332..172e3eb 100644
--- a/src/gr-image-page.ui
+++ b/src/gr-image-page.ui
@@ -96,6 +96,9 @@
                 <property name="visible">1</property>
                 <property name="above-child">1</property>
                 <property name="can-focus">1</property>
+                <property 
name="events">GDK_KEY_PRESS_MASK|GDK_POINTER_MOTION_MASK|GDK_BUTTON_PRESS_MASK</property>
+                <signal name="motion-notify-event" handler="motion_notify"/>
+                <signal name="key-press-event" handler="key_press_event"/>
                 <child>
                   <object class="GtkImage" id="image">
                     <property name="visible">1</property>
diff --git a/src/gr-window.c b/src/gr-window.c
index ca08a73..ca1e14c 100644
--- a/src/gr-window.c
+++ b/src/gr-window.c
@@ -218,6 +218,7 @@ new_recipe (GrWindow *window)
         save_back_entry (window);
 
         gr_edit_page_clear (GR_EDIT_PAGE (window->edit_page));
+        gtk_widget_grab_focus (window->edit_page);
 
         gtk_header_bar_set_title (GTK_HEADER_BAR (window->header), _("Add a New Recipe"));
 
@@ -226,7 +227,7 @@ new_recipe (GrWindow *window)
         gtk_stack_set_visible_child_name (GTK_STACK (window->header_end_stack), "edit");
 
         gtk_stack_set_visible_child_name (GTK_STACK (window->main_stack), "edit");
-        gtk_widget_set_sensitive(window->save_button,FALSE);
+        gtk_widget_set_sensitive (window->save_button,FALSE);
 }
 
 static void
@@ -414,17 +415,19 @@ window_keypress_handler (GtkWidget *widget,
                          gpointer   data)
 {
         GrWindow *window = GR_WINDOW (widget);
-        GdkEventKey *e = (GdkEventKey *) event;
+//        GdkEventKey *e = (GdkEventKey *) event;
         const char *visible;
 
         visible = gtk_stack_get_visible_child_name (GTK_STACK (window->main_stack));
 
+#if 0
         if (strcmp (visible, "image") == 0) {
                 if (e->keyval == GDK_KEY_Escape) {
                         gr_window_show_image (window, NULL, -1);
                         return GDK_EVENT_STOP;
                 }
         }
+#endif
 
         if (strcmp (visible, "cooking") == 0)
                 return gr_cooking_page_handle_event (GR_COOKING_PAGE (window->cooking_page), event);
@@ -968,6 +971,7 @@ gr_window_edit_recipe (GrWindow *window,
         save_back_entry (window);
 
         gr_edit_page_edit (GR_EDIT_PAGE (window->edit_page), recipe);
+        gtk_widget_grab_focus (window->edit_page);
 
         gtk_header_bar_set_title (GTK_HEADER_BAR (window->header), gr_recipe_get_translated_name (recipe));
 
@@ -1342,6 +1346,7 @@ gr_window_show_image (GrWindow *window,
                 gr_image_page_set_images (GR_IMAGE_PAGE (window->image_page), images);
                 gr_image_page_show_image (GR_IMAGE_PAGE (window->image_page), index);
                 gtk_stack_set_visible_child_name (GTK_STACK (window->main_stack), "image");
+                gtk_widget_grab_focus (window->image_page);
                 gr_window_set_fullscreen (window, TRUE);
         }
         else {


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