[balsa/popover: 28/63] mime-widget-text: Connect to the "pressed" signal



commit 8af03a73afcab439cbeb0200bbd84717dd0e092b
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Thu Jun 4 17:53:18 2020 -0400

    mime-widget-text: Connect to the "pressed" signal
    
    of a GtkGestureMultiPress, instead of the "button-press" widget event.
    And set the gesture's button to 0.
    
    The gesture and the popover should be attached to the web-view, not our
    LibBalsaHtml container. If the info-bar is not showing there is no
    difference, but when it is showing it should not pop up the context
    menu; also, the event coordinates are relative to the web-view, not the
    container.

 src/balsa-mime-widget-text.c | 39 +++++++++++++++++++++++++++++----------
 1 file changed, 29 insertions(+), 10 deletions(-)
---
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index a22999a80..a7cc22fee 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1282,6 +1282,7 @@ bmwt_html_popup_context_menu(GtkWidget * html, BalsaMessage * bm)
     GtkWidget *popover;
     const GdkEvent *event;
     GdkEvent *current_event = NULL;
+    gdouble x, y;
 
     popover = g_object_get_data(G_OBJECT(html), "popover");
     if (popover == NULL) {
@@ -1289,7 +1290,7 @@ bmwt_html_popup_context_menu(GtkWidget * html, BalsaMessage * bm)
 
         menu = g_menu_new();
         bmwt_populate_popup_menu(bm, html, menu);
-        popover = gtk_popover_new_from_model(html, G_MENU_MODEL(menu));
+        popover = gtk_popover_new_from_model(libbalsa_html_get_view_widget(html), G_MENU_MODEL(menu));
         g_object_set_data(G_OBJECT(html), "popover", popover);
     }
 
@@ -1300,13 +1301,15 @@ bmwt_html_popup_context_menu(GtkWidget * html, BalsaMessage * bm)
     if (event == NULL)
         event = current_event = gtk_get_current_event();
 
-    if (event != NULL && gdk_event_triggers_context_menu(event)) {
+    if (event != NULL &&
+        gdk_event_triggers_context_menu(event) &&
+        gdk_event_get_coords(event, &x, &y)) {
         GdkRectangle rectangle;
 
         /* Pop up above the pointer */
-        rectangle.x = event->button.x;
+        rectangle.x = (gint) x;
         rectangle.width = 0;
-        rectangle.y = event->button.y;
+        rectangle.y = (gint) y;
         rectangle.height = 0;
         gtk_popover_set_pointing_to(GTK_POPOVER(popover), &rectangle);
     }
@@ -1318,12 +1321,24 @@ bmwt_html_popup_context_menu(GtkWidget * html, BalsaMessage * bm)
     return TRUE;
 }
 
-static gboolean
-balsa_gtk_html_button_press_cb(GtkWidget * html, GdkEventButton * event,
-                               BalsaMessage * bm)
+static void
+balsa_gtk_html_button_press_cb(GtkGestureMultiPress *multi_press,
+                               gint                  n_press,
+                               gdouble               x,
+                               gdouble               y,
+                               gpointer              user_data)
 {
-    return(gdk_event_triggers_context_menu((GdkEvent *) event)
-           ? balsa_gtk_html_popup(html, bm) : GDK_EVENT_PROPAGATE);
+    BalsaMessage *bm = user_data;
+    GtkGesture *gesture;
+    const GdkEvent *event;
+
+    gesture = GTK_GESTURE(multi_press);
+    event = gtk_gesture_get_last_event(gesture, gtk_gesture_get_last_updated_sequence(gesture));
+
+    if (gdk_event_triggers_context_menu(event)) {
+        GtkWidget *html = gtk_event_controller_get_widget(GTK_EVENT_CONTROLLER(gesture));
+        balsa_gtk_html_popup(html, bm) ;
+    }
 }
 
 static BalsaMimeWidget *
@@ -1332,6 +1347,7 @@ bm_widget_new_html(BalsaMessage * bm, LibBalsaMessageBody * mime_body)
     BalsaMimeWidgetText *mwt = g_object_new(BALSA_TYPE_MIME_WIDGET_TEXT, NULL);
     GtkWidget *widget;
     GtkEventController *key_controller;
+    GtkGesture *gesture;
 
     mwt->text_widget = widget =
         libbalsa_html_new(mime_body,
@@ -1345,8 +1361,11 @@ bm_widget_new_html(BalsaMessage * bm, LibBalsaMessageBody * mime_body)
     g_signal_connect(key_controller, "key-pressed",
                     G_CALLBACK(balsa_mime_widget_key_pressed), bm);
 
-    g_signal_connect(widget, "button-press-event",
+    gesture = gtk_gesture_multi_press_new(libbalsa_html_get_view_widget(widget));
+    gtk_gesture_single_set_button(GTK_GESTURE_SINGLE(gesture), 0);
+    g_signal_connect(gesture, "pressed",
                      G_CALLBACK(balsa_gtk_html_button_press_cb), bm);
+
     g_signal_connect(widget, "popup-menu",
                      G_CALLBACK(balsa_gtk_html_popup), bm);
 


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