[balsa/gtk4: 61/311] Various: New API for libbalsa_popup_widget_popup()




commit 092c11ad43b85942a7f0288554d1ffd9fa295507
Author: Peter Bloomfield <PeterBloomfield bellsouth net>
Date:   Mon Jun 22 11:08:18 2020 -0400

    Various: New API for libbalsa_popup_widget_popup()
    
    It can get the target widget from the popup-widget, using either
    gtk_popover_get_relative_to() or gtk_menu_get_attach_widget().
    
    * libbalsa/libbalsa.c (libbalsa_popup_widget_popup):
    * libbalsa/libbalsa.h:
    * src/balsa-index.c (bndx_popup_menu_create), (bndx_do_popup):
    * src/balsa-mblist.c (bmbl_do_popup):
    * src/balsa-message.c (balsa_headers_attachments_popup),
      (tree_mult_selection_popup), (tree_button_press_cb), (display_content):
    * src/balsa-mime-widget-image.c (balsa_image_button_press_cb):
    * src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
    * src/sendmsg-window.c (attachment_button_press_cb), (attachment_popup_cb):
    * src/toolbar-factory.c (tm_popup_context_menu_cb):

 ChangeLog                     | 20 ++++++++++++++++++++
 libbalsa/libbalsa.c           | 27 +++++++++++----------------
 libbalsa/libbalsa.h           |  3 +--
 src/balsa-index.c             |  4 +---
 src/balsa-mblist.c            |  2 +-
 src/balsa-message.c           | 26 +++++---------------------
 src/balsa-mime-widget-image.c |  2 +-
 src/balsa-mime-widget-text.c  |  2 +-
 src/sendmsg-window.c          | 14 +++-----------
 src/toolbar-factory.c         |  2 +-
 10 files changed, 45 insertions(+), 57 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 1565c5858..88be2d22d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -329,6 +329,26 @@
 
        * src/balsa-mime-widget-text.c (text_view_url_popup):
 
+2020-06-22  Peter Bloomfield  <pbloomfield bellsouth net>
+
+       Various: New API for libbalsa_popup_widget_popup()
+
+       It can get the target widget from the popup-widget, using either
+       gtk_popover_get_relative_to() or gtk_menu_get_attach_widget().
+
+       * libbalsa/libbalsa.c (libbalsa_popup_widget_popup):
+       * libbalsa/libbalsa.h:
+       * src/balsa-index.c (bndx_popup_menu_create), (bndx_do_popup):
+       * src/balsa-mblist.c (bmbl_do_popup):
+       * src/balsa-message.c (balsa_headers_attachments_popup),
+       (tree_mult_selection_popup), (tree_button_press_cb),
+       (display_content):
+       * src/balsa-mime-widget-image.c (balsa_image_button_press_cb):
+       * src/balsa-mime-widget-text.c (bmwt_html_popup_context_menu):
+       * src/sendmsg-window.c (attachment_button_press_cb),
+       (attachment_popup_cb):
+       * src/toolbar-factory.c (tm_popup_context_menu_cb):
+
 2020-06-17  Peter Bloomfield  <pbloomfield bellsouth net>
 
        Various: Implement libbalsa_popup_widget_popup() as a wrapper for
diff --git a/libbalsa/libbalsa.c b/libbalsa/libbalsa.c
index 548a83486..b28e398df 100644
--- a/libbalsa/libbalsa.c
+++ b/libbalsa/libbalsa.c
@@ -800,31 +800,31 @@ libbalsa_popup_widget_new(GtkWidget   *relative_to,
  */
 void
 libbalsa_popup_widget_popup(GtkWidget      *popup_widget,
-                            const GdkEvent *event,
-                            GtkWidget      *widget)
+                            const GdkEvent *event)
 {
     g_return_if_fail(GTK_IS_POPOVER(popup_widget) || GTK_IS_MENU(popup_widget));
-    g_return_if_fail(widget == NULL || GTK_IS_WIDGET(widget));
 
     if (event != NULL && !gdk_event_triggers_context_menu(event))
         return;
 
     if (libbalsa_use_popover()) {
         GtkPopover *popover = GTK_POPOVER(popup_widget);
+        GtkWidget *relative_to = gtk_popover_get_relative_to(popover);
         gdouble x, y;
-        GdkRectangle rectangle;
 
         if (event != NULL &&
             gdk_event_get_coords(event, &x, &y)) {
-            if (GTK_IS_TREE_VIEW(widget)) {
-                gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(widget),
+            GdkRectangle rectangle;
+
+            if (GTK_IS_TREE_VIEW(relative_to)) {
+                gtk_tree_view_convert_bin_window_to_widget_coords(GTK_TREE_VIEW(relative_to),
                                                                   (gint) x,
                                                                   (gint) y,
                                                                   &rectangle.x,
                                                                   &rectangle.y);
                 rectangle.width = 0;
                 rectangle.height = 0;
-            } else if (GTK_IS_TOOLBAR(widget)) {
+            } else if (GTK_IS_TOOLBAR(relative_to)) {
                 gdouble x_root;
 
                 gdk_event_get_root_coords(event, &x_root, NULL);
@@ -838,16 +838,9 @@ libbalsa_popup_widget_popup(GtkWidget      *popup_widget,
                 rectangle.width = 0;
                 rectangle.height = 0;
             }
-        } else {
-            /* Pop up centered on widget */
-            gtk_widget_get_allocation(widget, (GtkAllocation *) &rectangle);
-            rectangle.x += rectangle.width / 2;
-            rectangle.y += rectangle.height / 2;
-            rectangle.width = 0;
-            rectangle.height = 0;
+            gtk_popover_set_pointing_to(popover, &rectangle);
         }
 
-        gtk_popover_set_pointing_to(popover, &rectangle);
         gtk_popover_popup(popover);
     } else {
         GtkMenu *menu = GTK_MENU(popup_widget);
@@ -855,7 +848,9 @@ libbalsa_popup_widget_popup(GtkWidget      *popup_widget,
         if (event != NULL) {
             gtk_menu_popup_at_pointer(menu, event);
         } else {
-            gtk_menu_popup_at_widget(menu, widget,
+            GtkWidget *attach_widget = gtk_menu_get_attach_widget(menu);
+
+            gtk_menu_popup_at_widget(menu, attach_widget,
                                      GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
                                      NULL);
         }
diff --git a/libbalsa/libbalsa.h b/libbalsa/libbalsa.h
index 24e6c2774..daecdad4a 100644
--- a/libbalsa/libbalsa.h
+++ b/libbalsa/libbalsa.h
@@ -191,8 +191,7 @@ GtkWidget *libbalsa_popup_widget_new  (GtkWidget      *relative_to,
                                        GMenuModel     *model,
                                        const gchar    *action_namespace);
 void       libbalsa_popup_widget_popup(GtkWidget      *popup_widget,
-                                       const GdkEvent *event,
-                                       GtkWidget      *widget);
+                                       const GdkEvent *event);
 
 #if HAVE_GTKSOURCEVIEW
 GtkWidget *libbalsa_source_view_new(gboolean highlight_phrases);
diff --git a/src/balsa-index.c b/src/balsa-index.c
index 455940f33..a03141e5a 100644
--- a/src/balsa-index.c
+++ b/src/balsa-index.c
@@ -2137,8 +2137,6 @@ bndx_popup_menu_create(BalsaIndex * bindex)
     bindex->popup_menu = menu;
     bindex->popup_widget =
         libbalsa_popup_widget_new(GTK_WIDGET(bindex), G_MENU_MODEL(menu), "popup");
-    if (libbalsa_use_popover())
-        gtk_popover_set_position(GTK_POPOVER(bindex->popup_widget), GTK_POS_BOTTOM);
 }
 
 /* bndx_do_popup: common code for the popup menu;
@@ -2222,7 +2220,7 @@ bndx_do_popup(BalsaIndex * index, const GdkEvent *event)
     g_menu_insert_item(index->popup_menu, index->move_position, item);
     g_object_unref(item);
 
-    libbalsa_popup_widget_popup(index->popup_widget, event, GTK_WIDGET(index));
+    libbalsa_popup_widget_popup(index->popup_widget, event);
 }
 
 /* End of popup stuff */
diff --git a/src/balsa-mblist.c b/src/balsa-mblist.c
index 1a01ee3e0..6dc22c568 100644
--- a/src/balsa-mblist.c
+++ b/src/balsa-mblist.c
@@ -739,7 +739,7 @@ bmbl_do_popup(GtkTreeView    *tree_view,
 
     menu = balsa_mailbox_node_get_context_menu(mbnode, GTK_WIDGET(tree_view));
 
-    libbalsa_popup_widget_popup(menu, event, GTK_WIDGET(tree_view));
+    libbalsa_popup_widget_popup(menu, event);
 
     if (mbnode != NULL)
        g_object_unref(mbnode);
diff --git a/src/balsa-message.c b/src/balsa-message.c
index b35b89d4d..4ce899eb7 100644
--- a/src/balsa-message.c
+++ b/src/balsa-message.c
@@ -240,16 +240,8 @@ balsa_message_class_init(BalsaMessageClass * klass)
 static void
 balsa_headers_attachments_popup(GtkButton * button, BalsaMessage * balsa_message)
 {
-    if (balsa_message->parts_popup != NULL) {
-        if (libbalsa_use_popover()) {
-            gtk_popover_popup(GTK_POPOVER(balsa_message->parts_popup));
-        } else {
-            gtk_menu_popup_at_widget(GTK_MENU(balsa_message->parts_popup),
-                                     GTK_WIDGET(balsa_message->attach_button),
-                                     GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
-                                     NULL);
-        }
-    }
+    if (balsa_message->parts_popup != NULL)
+        libbalsa_popup_widget_popup(balsa_message->parts_popup, NULL);
 }
 
 
@@ -1159,10 +1151,8 @@ tree_mult_selection_popup(BalsaMessage     *balsa_message,
         popup_widget = balsa_message->save_all_popup;
     }
 
-    if (popup_widget == NULL)
-        return;
-
-    libbalsa_popup_widget_popup(popup_widget, event, GTK_WIDGET(balsa_message));
+    if (popup_widget != NULL)
+        libbalsa_popup_widget_popup(popup_widget, event);
 }
 
 static gboolean
@@ -1226,7 +1216,7 @@ tree_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
                 gtk_tree_model_get(model, &iter, PART_INFO_COLUMN, &info, -1);
                 if (info != NULL) {
                     if (info->popup_widget != NULL)
-                        libbalsa_popup_widget_popup(info->popup_widget, event, NULL);
+                        libbalsa_popup_widget_popup(info->popup_widget, event);
                     g_object_unref(info);
                 }
             }
@@ -1744,12 +1734,6 @@ display_content(BalsaMessage * balsa_message)
 
     balsa_message->parts_menu = g_menu_new();
 
-    if (libbalsa_use_popover()) {
-        /* Detach any existing popup: */
-        if (balsa_message->parts_popup != NULL)
-            gtk_popover_set_relative_to(GTK_POPOVER(balsa_message->parts_popup), NULL);
-    }
-
     balsa_message->parts_popup = libbalsa_popup_widget_new(balsa_message->attach_button,
                                                            G_MENU_MODEL(balsa_message->parts_menu),
                                                            "message-menu");
diff --git a/src/balsa-mime-widget-image.c b/src/balsa-mime-widget-image.c
index 7e8ad0823..0fefd5c74 100644
--- a/src/balsa-mime-widget-image.c
+++ b/src/balsa-mime-widget-image.c
@@ -155,7 +155,7 @@ balsa_image_button_press_cb(GtkGestureMultiPress *multi_press_gesture,
     sequence = gtk_gesture_single_get_current_sequence(GTK_GESTURE_SINGLE(multi_press_gesture));
     event    = gtk_gesture_get_last_event(gesture, sequence);
 
-    libbalsa_popup_widget_popup(menu, event, NULL);
+    libbalsa_popup_widget_popup(menu, event);
 }
 
 static void
diff --git a/src/balsa-mime-widget-text.c b/src/balsa-mime-widget-text.c
index 795645dcb..567685576 100644
--- a/src/balsa-mime-widget-text.c
+++ b/src/balsa-mime-widget-text.c
@@ -1358,7 +1358,7 @@ bmwt_html_popup_context_menu(GtkWidget    *html,
     if (event == NULL)
         event = current_event = gtk_get_current_event();
 
-    libbalsa_popup_widget_popup(popup_widget, event, GTK_WIDGET(bm));
+    libbalsa_popup_widget_popup(popup_widget, event);
 
     if (current_event != NULL)
         gdk_event_free(current_event);
diff --git a/src/sendmsg-window.c b/src/sendmsg-window.c
index 7624b6073..9b869052b 100644
--- a/src/sendmsg-window.c
+++ b/src/sendmsg-window.c
@@ -2406,7 +2406,7 @@ attachment_button_press_cb(GtkGestureMultiPress *multi_press,
            gtk_tree_model_get(model, &iter, ATTACH_INFO_COLUMN, &attach_info, -1);
            if (attach_info != NULL) {
                if (attach_info->popup_menu != NULL)
-                    libbalsa_popup_widget_popup(attach_info->popup_menu, event, NULL);
+                    libbalsa_popup_widget_popup(attach_info->popup_menu, event);
                g_object_unref(attach_info);
            }
         }
@@ -2428,16 +2428,8 @@ attachment_popup_cb(GtkWidget *widget, gpointer user_data)
 
     gtk_tree_model_get(model, &iter, ATTACH_INFO_COLUMN, &attach_info, -1);
     if (attach_info != NULL) {
-       if (attach_info->popup_menu != NULL) {
-            if (libbalsa_use_popover()) {
-                gtk_popover_popup(GTK_POPOVER(attach_info->popup_menu));
-            } else {
-                gtk_menu_popup_at_widget(GTK_MENU(attach_info->popup_menu),
-                                         GTK_WIDGET(widget),
-                                         GDK_GRAVITY_CENTER, GDK_GRAVITY_CENTER,
-                                         NULL);
-            }
-        }
+       if (attach_info->popup_menu != NULL)
+            libbalsa_popup_widget_popup(attach_info->popup_menu, NULL);
        g_object_unref(attach_info);
     }
 
diff --git a/src/toolbar-factory.c b/src/toolbar-factory.c
index 2f197cd46..aed4f19ad 100644
--- a/src/toolbar-factory.c
+++ b/src/toolbar-factory.c
@@ -763,7 +763,7 @@ tm_popup_context_menu_cb(GtkWidget    * toolbar,
 
     event = gtk_get_current_event();
 
-    libbalsa_popup_widget_popup(popup_menu, event, toolbar);
+    libbalsa_popup_widget_popup(popup_menu, event);
     gtk_widget_set_sensitive(popup_menu, TRUE);
 
     if (event != NULL)


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