[gimp/gtk3-port] app: add gimp_ui_manager_ui_popup_at_widget()



commit afd2d7c41ff561ffe6319629d6e8deca42394393
Author: Michael Natterer <mitch gimp org>
Date:   Wed May 2 00:44:38 2018 +0200

    app: add gimp_ui_manager_ui_popup_at_widget()
    
    and use it where we used to pass gimp_button_menu_position() to
    gimp_ui_manager_up_popup(), remove gimp_button_menu_position() because
    it's now unused.

 app/display/gimpdisplayshell.c      |   25 +++-------
 app/widgets/gimpdockbook.c          |   25 ++++------
 app/widgets/gimptooloptionseditor.c |   20 +++-----
 app/widgets/gimpuimanager.c         |   41 ++++++++++++++++
 app/widgets/gimpuimanager.h         |    9 ++++
 app/widgets/gimpwidgets-utils.c     |   90 -----------------------------------
 app/widgets/gimpwidgets-utils.h     |    5 --
 7 files changed, 73 insertions(+), 142 deletions(-)
---
diff --git a/app/display/gimpdisplayshell.c b/app/display/gimpdisplayshell.c
index c51ca8a..fde001b 100644
--- a/app/display/gimpdisplayshell.c
+++ b/app/display/gimpdisplayshell.c
@@ -154,10 +154,6 @@ static GimpColorProfile *
                gimp_display_shell_get_color_profile(GimpColorManaged *managed);
 static void      gimp_display_shell_profile_changed(GimpColorManaged *managed);
 
-static void      gimp_display_shell_menu_position  (GtkMenu          *menu,
-                                                    gint             *x,
-                                                    gint             *y,
-                                                    gpointer          data);
 static void      gimp_display_shell_zoom_button_callback
                                                    (GimpDisplayShell *shell,
                                                     GtkWidget        *zoom_button);
@@ -1000,11 +996,13 @@ gimp_display_shell_popup_menu (GtkWidget *widget)
   gimp_context_set_display (gimp_get_user_context (shell->display->gimp),
                             shell->display);
 
-  gimp_ui_manager_ui_popup (shell->popup_manager, "/dummy-menubar/image-popup",
-                            GTK_WIDGET (shell),
-                            gimp_display_shell_menu_position,
-                            shell->origin,
-                            NULL, NULL);
+  gimp_ui_manager_ui_popup_at_widget (shell->popup_manager,
+                                      "/dummy-menubar/image-popup",
+                                      shell->origin,
+                                      GDK_GRAVITY_EAST,
+                                      GDK_GRAVITY_NORTH_WEST,
+                                      NULL,
+                                      NULL, NULL);
 
   return TRUE;
 }
@@ -1119,15 +1117,6 @@ gimp_display_shell_profile_changed (GimpColorManaged *managed)
 }
 
 static void
-gimp_display_shell_menu_position (GtkMenu  *menu,
-                                  gint     *x,
-                                  gint     *y,
-                                  gpointer  data)
-{
-  gimp_button_menu_position (GTK_WIDGET (data), menu, GTK_POS_RIGHT, x, y);
-}
-
-static void
 gimp_display_shell_zoom_button_callback (GimpDisplayShell *shell,
                                          GtkWidget        *zoom_button)
 {
diff --git a/app/widgets/gimpdockbook.c b/app/widgets/gimpdockbook.c
index 7a45ab3..7447462 100644
--- a/app/widgets/gimpdockbook.c
+++ b/app/widgets/gimpdockbook.c
@@ -50,7 +50,6 @@
 #include "gimpstringaction.h"
 #include "gimpuimanager.h"
 #include "gimpview.h"
-#include "gimpwidgets-utils.h"
 
 #include "gimp-log.h"
 #include "gimp-intl.h"
@@ -451,17 +450,6 @@ gimp_dockbook_menu_button_press (GimpDockbook   *dockbook,
   return handled;
 }
 
-static void
-gimp_dockbook_menu_position (GtkMenu  *menu,
-                             gint     *x,
-                             gint     *y,
-                             gpointer  data)
-{
-  GimpDockbook *dockbook = GIMP_DOCKBOOK (data);
-
-  gimp_button_menu_position (dockbook->p->menu_button, menu, GTK_POS_LEFT, x, y);
-}
-
 static gboolean
 gimp_dockbook_show_menu (GimpDockbook *dockbook)
 {
@@ -577,10 +565,15 @@ gimp_dockbook_show_menu (GimpDockbook *dockbook)
                           g_object_unref);
 
   gimp_ui_manager_update (dockbook_ui_manager, dockable);
-  gimp_ui_manager_ui_popup (dockbook_ui_manager, "/dockable-popup",
-                            GTK_WIDGET (dockable),
-                            gimp_dockbook_menu_position, dockbook,
-                            (GDestroyNotify) gimp_dockbook_menu_end, dockable);
+
+  gimp_ui_manager_ui_popup_at_widget (dockbook_ui_manager,
+                                      "/dockable-popup",
+                                      dockbook->p->menu_button,
+                                      GDK_GRAVITY_WEST,
+                                      GDK_GRAVITY_NORTH_EAST,
+                                      NULL,
+                                      (GDestroyNotify) gimp_dockbook_menu_end,
+                                      dockable);
 
   return TRUE;
 }
diff --git a/app/widgets/gimptooloptionseditor.c b/app/widgets/gimptooloptionseditor.c
index 4b243ed..53c192d 100644
--- a/app/widgets/gimptooloptionseditor.c
+++ b/app/widgets/gimptooloptionseditor.c
@@ -379,15 +379,6 @@ gimp_tool_options_editor_get_tool_options (GimpToolOptionsEditor *editor)
 /*  private functions  */
 
 static void
-gimp_tool_options_editor_menu_pos (GtkMenu  *menu,
-                                   gint     *x,
-                                   gint     *y,
-                                   gpointer  data)
-{
-  gimp_button_menu_position (GTK_WIDGET (data), menu, GTK_POS_RIGHT, x, y);
-}
-
-static void
 gimp_tool_options_editor_menu_popup (GimpToolOptionsEditor *editor,
                                      GtkWidget             *button,
                                      const gchar           *path)
@@ -399,10 +390,13 @@ gimp_tool_options_editor_menu_popup (GimpToolOptionsEditor *editor,
   gimp_ui_manager_update (gimp_editor_get_ui_manager (gimp_editor),
                           gimp_editor_get_popup_data (gimp_editor));
 
-  gimp_ui_manager_ui_popup (gimp_editor_get_ui_manager (gimp_editor), path,
-                            button,
-                            gimp_tool_options_editor_menu_pos, button,
-                            NULL, NULL);
+  gimp_ui_manager_ui_popup_at_widget (gimp_editor_get_ui_manager (gimp_editor),
+                                      path,
+                                      button,
+                                      GDK_GRAVITY_WEST,
+                                      GDK_GRAVITY_NORTH_EAST,
+                                      NULL,
+                                      NULL, NULL);
 }
 
 static void
diff --git a/app/widgets/gimpuimanager.c b/app/widgets/gimpuimanager.c
index ddc1063..9ff60ff 100644
--- a/app/widgets/gimpuimanager.c
+++ b/app/widgets/gimpuimanager.c
@@ -661,6 +661,47 @@ gimp_ui_manager_ui_popup (GimpUIManager        *manager,
                   button, activate_time);
 }
 
+void
+gimp_ui_manager_ui_popup_at_widget (GimpUIManager  *manager,
+                                    const gchar    *ui_path,
+                                    GtkWidget      *widget,
+                                    GdkGravity      widget_anchor,
+                                    GdkGravity      menu_anchor,
+                                    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);
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+
+  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_widget (GTK_MENU (menu), widget,
+                            widget_anchor,
+                            menu_anchor,
+                            trigger_event);
+}
+
 
 /*  private functions  */
 
diff --git a/app/widgets/gimpuimanager.h b/app/widgets/gimpuimanager.h
index 252de05..4d168f4 100644
--- a/app/widgets/gimpuimanager.h
+++ b/app/widgets/gimpuimanager.h
@@ -106,6 +106,15 @@ void            gimp_ui_manager_ui_popup    (GimpUIManager          *manager,
                                              gpointer                position_data,
                                              GDestroyNotify          popdown_func,
                                              gpointer                popdown_data);
+void            gimp_ui_manager_ui_popup_at_widget
+                                            (GimpUIManager          *manager,
+                                             const gchar            *ui_path,
+                                             GtkWidget              *widget,
+                                             GdkGravity              widget_anchor,
+                                             GdkGravity              menu_anchor,
+                                             const GdkEvent         *trigger_event,
+                                             GDestroyNotify          popdown_func,
+                                             gpointer                popdown_data);
 
 
 #endif  /* __GIMP_UI_MANAGER_H__ */
diff --git a/app/widgets/gimpwidgets-utils.c b/app/widgets/gimpwidgets-utils.c
index f7d216d..7ad4483 100644
--- a/app/widgets/gimpwidgets-utils.c
+++ b/app/widgets/gimpwidgets-utils.c
@@ -121,96 +121,6 @@ gimp_menu_position (GtkMenu *menu,
     *y = rect.y;
 }
 
-/**
- * gimp_button_menu_position:
- * @button: a button widget to popup the menu from
- * @menu: the menu to position
- * @position: the preferred popup direction for the menu (left or right)
- * @x: return location for x coordinate
- * @y: return location for y coordinate
- *
- * Utility function to position a menu that pops up from a button.
- **/
-void
-gimp_button_menu_position (GtkWidget       *button,
-                           GtkMenu         *menu,
-                           GtkPositionType  position,
-                           gint            *x,
-                           gint            *y)
-{
-  GdkScreen      *screen;
-  GtkAllocation   button_allocation;
-  GtkRequisition  menu_requisition;
-  GdkRectangle    rect;
-  gint            monitor;
-
-  g_return_if_fail (GTK_IS_WIDGET (button));
-  g_return_if_fail (gtk_widget_get_realized (button));
-  g_return_if_fail (GTK_IS_MENU (menu));
-  g_return_if_fail (x != NULL);
-  g_return_if_fail (y != NULL);
-
-  gtk_widget_get_allocation (button, &button_allocation);
-
-  if (gtk_widget_get_direction (button) == GTK_TEXT_DIR_RTL)
-    {
-      switch (position)
-        {
-        case GTK_POS_LEFT:   position = GTK_POS_RIGHT;  break;
-        case GTK_POS_RIGHT:  position = GTK_POS_LEFT;   break;
-        default:
-          break;
-        }
-    }
-
-  *x = 0;
-  *y = 0;
-
-  if (! gtk_widget_get_has_window (button))
-    {
-      *x += button_allocation.x;
-      *y += button_allocation.y;
-    }
-
-  gdk_window_get_root_coords (gtk_widget_get_window (button), *x, *y, x, y);
-
-  gtk_widget_get_preferred_size (GTK_WIDGET (menu), &menu_requisition, NULL);
-
-  screen = gtk_widget_get_screen (button);
-
-  monitor = gdk_screen_get_monitor_at_point (screen, *x, *y);
-  gdk_screen_get_monitor_workarea (screen, monitor, &rect);
-
-  gtk_menu_set_screen (menu, screen);
-
-  switch (position)
-    {
-    case GTK_POS_LEFT:
-      *x -= menu_requisition.width;
-      if (*x < rect.x)
-        *x += menu_requisition.width + button_allocation.width;
-      break;
-
-    case GTK_POS_RIGHT:
-      *x += button_allocation.width;
-      if (*x + menu_requisition.width > rect.x + rect.width)
-        *x -= button_allocation.width + menu_requisition.width;
-      break;
-
-    default:
-      g_warning ("%s: unhandled position (%d)", G_STRFUNC, position);
-      break;
-    }
-
-  *y += button_allocation.height / 2;
-
-  if (*y + menu_requisition.height > rect.y + rect.height)
-    *y -= menu_requisition.height;
-
-  if (*y < rect.y)
-    *y = rect.y;
-}
-
 void
 gimp_grid_attach_icon (GtkGrid     *grid,
                        gint         row,
diff --git a/app/widgets/gimpwidgets-utils.h b/app/widgets/gimpwidgets-utils.h
index 985aa4c..7bda22c 100644
--- a/app/widgets/gimpwidgets-utils.h
+++ b/app/widgets/gimpwidgets-utils.h
@@ -25,11 +25,6 @@
 void              gimp_menu_position               (GtkMenu              *menu,
                                                     gint                 *x,
                                                     gint                 *y);
-void              gimp_button_menu_position        (GtkWidget            *button,
-                                                    GtkMenu              *menu,
-                                                    GtkPositionType       position,
-                                                    gint                 *x,
-                                                    gint                 *y);
 void              gimp_grid_attach_icon            (GtkGrid              *grid,
                                                     gint                  row,
                                                     const gchar          *icon_name,


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