Commit b28228d9 authored by Michael Natterer's avatar Michael Natterer 😴

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.
parent 4c68fb70
......@@ -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);
......@@ -994,11 +990,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;
}
......@@ -1112,15 +1110,6 @@ gimp_display_shell_profile_changed (GimpColorManaged *managed)
gimp_display_shell_expose_full (shell);
}
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)
......
......@@ -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;
}
......
......@@ -378,15 +378,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,
......@@ -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
......
......@@ -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 */
......
......@@ -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__ */
......@@ -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,
......
......@@ -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,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment