[gimp/gtk3-port: 282/451] app: gimp_ui_manager_ui_popup_at_pointer() and use it where appropriate



commit dc3c112f44c29e925e4f990741de8ee459868ee8
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 2 12:19:32 2018 +0200

    app: gimp_ui_manager_ui_popup_at_pointer() and use it where appropriate
    
    Only one call to gimp_ui_manager_ui_popup() left...

 app/display/gimpdisplayshell-tool-events.c |   26 +++++--------
 app/widgets/gimpuimanager.c                |   56 ++++++++++++++++++++++-----
 app/widgets/gimpuimanager.h                |    6 +++
 3 files changed, 61 insertions(+), 27 deletions(-)
---
diff --git a/app/display/gimpdisplayshell-tool-events.c b/app/display/gimpdisplayshell-tool-events.c
index 8a50529..3dada27 100644
--- a/app/display/gimpdisplayshell-tool-events.c
+++ b/app/display/gimpdisplayshell-tool-events.c
@@ -269,10 +269,10 @@ gimp_display_shell_canvas_no_image_events (GtkWidget        *canvas,
     case GDK_BUTTON_PRESS:
       if (gdk_event_triggers_context_menu (event))
         {
-          gimp_ui_manager_ui_popup (shell->popup_manager,
-                                    "/dummy-menubar/image-popup",
-                                    GTK_WIDGET (shell),
-                                    NULL, NULL, NULL, NULL);
+          gimp_ui_manager_ui_popup_at_pointer (shell->popup_manager,
+                                               "/dummy-menubar/image-popup",
+                                               (GdkEvent *) event,
+                                               NULL, NULL);
           return TRUE;
         }
       break;
@@ -695,20 +695,14 @@ gimp_display_shell_canvas_tool_events_internal (GtkWidget         *canvas,
                                                         display,
                                                         &ui_path);
 
-            if (ui_manager)
+            if (! ui_manager)
               {
-                gimp_ui_manager_ui_popup (ui_manager,
-                                          ui_path,
-                                          GTK_WIDGET (shell),
-                                          NULL, NULL, NULL, NULL);
-              }
-            else
-              {
-                gimp_ui_manager_ui_popup (shell->popup_manager,
-                                          "/dummy-menubar/image-popup",
-                                          GTK_WIDGET (shell),
-                                          NULL, NULL, NULL, NULL);
+                ui_manager = shell->popup_manager;
+                ui_path    = "/dummy-menubar/image-popup";
               }
+
+            gimp_ui_manager_ui_popup_at_pointer (ui_manager, ui_path, event,
+                                                 NULL, NULL);
           }
         else if (bevent->button == 1)
           {
diff --git a/app/widgets/gimpuimanager.c b/app/widgets/gimpuimanager.c
index 9ff60ff..fea596a 100644
--- a/app/widgets/gimpuimanager.c
+++ b/app/widgets/gimpuimanager.c
@@ -587,7 +587,7 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
                           GDestroyNotify        popdown_func,
                           gpointer              popdown_data)
 {
-  GtkWidget *widget;
+  GtkWidget *menu;
   GdkEvent  *current_event;
   gint       x, y;
   guint      button;
@@ -598,15 +598,15 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
   g_return_if_fail (ui_path != NULL);
   g_return_if_fail (parent == NULL || GTK_IS_WIDGET (parent));
 
-  widget = gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), ui_path);
+  menu = gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), ui_path);
 
-  if (GTK_IS_MENU_ITEM (widget))
-    widget = gtk_menu_item_get_submenu (GTK_MENU_ITEM (widget));
+  if (GTK_IS_MENU_ITEM (menu))
+    menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
 
-  if (! widget)
+  if (! menu)
     return;
 
-  g_return_if_fail (GTK_IS_MENU (widget));
+  g_return_if_fail (GTK_IS_MENU (menu));
 
   if (! position_func)
     {
@@ -614,7 +614,7 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
       position_data = parent;
     }
 
-  (* position_func) (GTK_MENU (widget), &x, &y, position_data);
+  (* position_func) (GTK_MENU (menu), &x, &y, position_data);
 
   current_event = gtk_get_current_event ();
 
@@ -634,12 +634,12 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
   if (current_event)
     gdk_event_free (current_event);
 
-  menu_pos = g_object_get_data (G_OBJECT (widget), "menu-pos");
+  menu_pos = g_object_get_data (G_OBJECT (menu), "menu-pos");
 
   if (! menu_pos)
     {
       menu_pos = g_slice_new0 (MenuPos);
-      g_object_set_data_full (G_OBJECT (widget), "menu-pos", menu_pos,
+      g_object_set_data_full (G_OBJECT (menu), "menu-pos", menu_pos,
                               (GDestroyNotify) menu_pos_free);
     }
 
@@ -650,12 +650,12 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
     {
       g_object_set_data_full (G_OBJECT (manager), "popdown-data",
                               popdown_data, popdown_func);
-      g_signal_connect (widget, "selection-done",
+      g_signal_connect (menu, "selection-done",
                         G_CALLBACK (gimp_ui_manager_delete_popdown_data),
                         manager);
     }
 
-  gtk_menu_popup (GTK_MENU (widget),
+  gtk_menu_popup (GTK_MENU (menu),
                   NULL, NULL,
                   gimp_ui_manager_menu_pos, menu_pos,
                   button, activate_time);
@@ -702,6 +702,40 @@ gimp_ui_manager_ui_popup_at_widget (GimpUIManager  *manager,
                             trigger_event);
 }
 
+void
+gimp_ui_manager_ui_popup_at_pointer (GimpUIManager  *manager,
+                                     const gchar    *ui_path,
+                                     const GdkEvent *trigger_event,
+                                     GDestroyNotify  popdown_func,
+                                     gpointer        popdown_data)
+{
+  GtkWidget *menu;
+
+  g_return_if_fail (GIMP_IS_UI_MANAGER (manager));
+  g_return_if_fail (ui_path != NULL);
+
+  menu = gtk_ui_manager_get_widget (GTK_UI_MANAGER (manager), ui_path);
+
+  if (GTK_IS_MENU_ITEM (menu))
+    menu = gtk_menu_item_get_submenu (GTK_MENU_ITEM (menu));
+
+  if (! menu)
+    return;
+
+  g_return_if_fail (GTK_IS_MENU (menu));
+
+  if (popdown_func && popdown_data)
+    {
+      g_object_set_data_full (G_OBJECT (manager), "popdown-data",
+                              popdown_data, popdown_func);
+      g_signal_connect (menu, "selection-done",
+                        G_CALLBACK (gimp_ui_manager_delete_popdown_data),
+                        manager);
+    }
+
+  gtk_menu_popup_at_pointer (GTK_MENU (menu), trigger_event);
+}
+
 
 /*  private functions  */
 
diff --git a/app/widgets/gimpuimanager.h b/app/widgets/gimpuimanager.h
index 4d168f4..6354674 100644
--- a/app/widgets/gimpuimanager.h
+++ b/app/widgets/gimpuimanager.h
@@ -115,6 +115,12 @@ void            gimp_ui_manager_ui_popup_at_widget
                                              const GdkEvent         *trigger_event,
                                              GDestroyNotify          popdown_func,
                                              gpointer                popdown_data);
+void            gimp_ui_manager_ui_popup_at_pointer
+                                            (GimpUIManager          *manager,
+                                             const gchar            *ui_path,
+                                             const GdkEvent         *trigger_event,
+                                             GDestroyNotify          popdown_func,
+                                             gpointer                popdown_data);
 
 
 #endif  /* __GIMP_UI_MANAGER_H__ */


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