[gtk+/wip/matthiasc/kill-event-signals: 121/126] testgtk: Stop using ::button-press-event



commit f40f6cf9b15a70a70c71f8524626d5857d6b22c1
Author: Matthias Clasen <mclasen redhat com>
Date:   Wed Jan 10 18:30:13 2018 -0500

    testgtk: Stop using ::button-press-event
    
    This one example can just as well use a gesture.

 tests/testgtk.c |   45 +++++++++++++++++++++------------------------
 1 files changed, 21 insertions(+), 24 deletions(-)
---
diff --git a/tests/testgtk.c b/tests/testgtk.c
index a23bafd..166ea93 100644
--- a/tests/testgtk.c
+++ b/tests/testgtk.c
@@ -3756,16 +3756,20 @@ cursor_model (void)
   return (GtkTreeModel *)store;
 }
 
-static gint
-cursor_event (GtkWidget *widget,
-              GdkEvent  *event,
-              GtkWidget *entry)
+static void
+cursor_pressed_cb (GtkGesture *gesture,
+                   int         n_pressed,
+                   double      x,
+                   double      y,
+                   GtkWidget  *entry)
 {
+  GtkWidget *widget;
   const gchar *name;
   gint i;
   const gint n = G_N_ELEMENTS (cursor_names);
-  GdkEventType type;
-  guint button;
+  int button;
+
+  widget = gtk_event_controller_get_widget (GTK_EVENT_CONTROLLER (gesture));
 
   name = (const gchar *)g_object_get_data (G_OBJECT (widget), "name");
   if (name != NULL)
@@ -3777,23 +3781,13 @@ cursor_event (GtkWidget *widget,
   else
     i = 0;
 
-  type = gdk_event_get_event_type (event);
-  gdk_event_get_button (event, &button);
-  if (type == GDK_BUTTON_PRESS &&
-      (button == GDK_BUTTON_PRIMARY ||
-       button == GDK_BUTTON_SECONDARY))
-    {
-      if (button == GDK_BUTTON_PRIMARY)
-        i = (i + 1) % n;
-      else
-        i = (i + n - 1) % n;
-
-      gtk_entry_set_text (GTK_ENTRY (entry), cursor_names[i]);
-
-      return TRUE;
-    }
+  button = gtk_gesture_single_get_current_button (GTK_GESTURE_SINGLE (gesture));
+  if (button == GDK_BUTTON_PRIMARY)
+    i = (i + 1) % n;
+  else
+    i = (i + n - 1) % n;
 
-  return FALSE;
+  gtk_entry_set_text (GTK_ENTRY (entry), cursor_names[i]);
 }
 
 static void
@@ -3862,6 +3856,7 @@ create_cursors (GtkWidget *widget)
   GtkEntryCompletion *completion;
   GtkTreeModel *model;
   gboolean cursor_demo = FALSE;
+  GtkGesture *gesture;
 
   if (!window)
     {
@@ -3950,8 +3945,10 @@ create_cursors (GtkWidget *widget)
       gtk_drawing_area_set_content_height (GTK_DRAWING_AREA (darea), 80);
       gtk_drawing_area_set_draw_func (GTK_DRAWING_AREA (darea), cursor_draw, NULL, NULL);
       gtk_container_add (GTK_CONTAINER (frame), darea);
-      g_signal_connect (darea, "button_press_event",
-                       G_CALLBACK (cursor_event), entry);
+      gesture = gtk_gesture_multi_press_new (darea);
+      gtk_gesture_single_set_button (GTK_GESTURE_SINGLE (gesture), 0);
+      g_signal_connect (gesture, "pressed", G_CALLBACK (cursor_pressed_cb), entry);
+      g_object_set_data_full (G_OBJECT (darea), "gesture", gesture, g_object_unref);
       gtk_widget_show (darea);
 
       g_signal_connect (entry, "changed",


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