diff options
author | Matthias Clasen <mclasen@redhat.com> | 2005-08-15 16:36:31 +0000 |
---|---|---|
committer | Matthias Clasen <matthiasc@src.gnome.org> | 2005-08-15 16:36:31 +0000 |
commit | 24a55633ce7180ab51772bb11e05e5f0e9345f6e (patch) | |
tree | 8230ac3edc1fa52fa38ea9a388b879f72f152e47 /gtk/gtkmenutoolbutton.c | |
parent | c92959a4485fa1d09404fcc21a17672c565a69e1 (diff) | |
download | gtk+-24a55633ce7180ab51772bb11e05e5f0e9345f6e.tar.gz |
Add some more tests for menu placement.
2005-08-15 Matthias Clasen <mclasen@redhat.com>
* tests/testtoolbar.c: Add some more tests for menu placement.
* gtk/gtkmenutoolbutton.c (menu_position_func):
* gtk/gtktoolbar.c (menu_position_func): Improve positioning
of toolbutton menus and of the overflow menu. (#312937,
#153870, Christian Persch, Paolo Borelli)
Diffstat (limited to 'gtk/gtkmenutoolbutton.c')
-rw-r--r-- | gtk/gtkmenutoolbutton.c | 41 |
1 files changed, 33 insertions, 8 deletions
diff --git a/gtk/gtkmenutoolbutton.c b/gtk/gtkmenutoolbutton.c index 976ce3f39f..0496260b36 100644 --- a/gtk/gtkmenutoolbutton.c +++ b/gtk/gtkmenutoolbutton.c @@ -278,36 +278,61 @@ menu_position_func (GtkMenu *menu, GtkMenuToolButton *button) { GtkMenuToolButtonPrivate *priv = button->priv; + GtkWidget *widget = GTK_WIDGET (button); GtkRequisition req; GtkRequisition menu_req; GtkOrientation orientation; GtkTextDirection direction; + GdkRectangle monitor; + gint monitor_num; + GdkScreen *screen; - gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y); - gtk_widget_size_request (priv->arrow_button, &req); gtk_widget_size_request (GTK_WIDGET (priv->menu), &menu_req); orientation = gtk_tool_item_get_orientation (GTK_TOOL_ITEM (button)); - direction = gtk_widget_get_direction (GTK_WIDGET (priv->arrow_button)); + direction = gtk_widget_get_direction (widget); + + screen = gtk_widget_get_screen (GTK_WIDGET (menu)); + monitor_num = gdk_screen_get_monitor_at_window (screen, widget->window); + if (monitor_num < 0) + monitor_num = 0; + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); if (orientation == GTK_ORIENTATION_HORIZONTAL) { + gdk_window_get_origin (widget->window, x, y); + *x += widget->allocation.x; + if (direction == GTK_TEXT_DIR_LTR) - *x += priv->arrow_button->allocation.width - req.width; + *x += MAX (widget->allocation.width - menu_req.width, 0); + else if (menu_req.width > widget->allocation.width) + *x -= menu_req.width - widget->allocation.width; + + if ((*y + priv->arrow_button->allocation.height + menu_req.height) <= monitor.y + monitor.height) + *y += priv->arrow_button->allocation.height; + else if ((*y - menu_req.height) >= monitor.y) + *y -= menu_req.height; + else if (monitor.y + monitor.height - (*y + priv->arrow_button->allocation.height) > *y) + *y += priv->arrow_button->allocation.height; else - *x += req.width - menu_req.width; - *y += priv->arrow_button->allocation.height; + *y -= menu_req.height; } else { + gdk_window_get_origin (GTK_BUTTON (priv->arrow_button)->event_window, x, y); + gtk_widget_size_request (priv->arrow_button, &req); + if (direction == GTK_TEXT_DIR_LTR) *x += priv->arrow_button->allocation.width; else *x -= menu_req.width; - *y += priv->arrow_button->allocation.height - req.height; + + if (*y + menu_req.height > monitor.y + monitor.height && + *y + priv->arrow_button->allocation.height - monitor.y > monitor.y + monitor.height - *y) + *y += priv->arrow_button->allocation.height - menu_req.height; } - *push_in = TRUE; + *push_in = FALSE; } static void |