diff options
author | William Jon McCann <william.jon.mccann@gmail.com> | 2013-12-22 12:43:35 -0500 |
---|---|---|
committer | William Jon McCann <william.jon.mccann@gmail.com> | 2014-01-06 12:44:59 -0500 |
commit | 4b1838bde6b9dd547f1afc4e925c9d9055684525 (patch) | |
tree | 22cb816d4f663a71f0ab860b6812635271d95d11 /gtk/gtkmenubutton.c | |
parent | f7c5dfdeef65948371c0211ab253eea5edeae695 (diff) | |
download | gtk+-4b1838bde6b9dd547f1afc4e925c9d9055684525.tar.gz |
Fix positioning of up menu button popup
Use the menu allocation instead of the request size.
https://bugzilla.gnome.org/show_bug.cgi?id=720939
Diffstat (limited to 'gtk/gtkmenubutton.c')
-rw-r--r-- | gtk/gtkmenubutton.c | 45 |
1 files changed, 20 insertions, 25 deletions
diff --git a/gtk/gtkmenubutton.c b/gtk/gtkmenubutton.c index f551d9059d..ca24c329bc 100644 --- a/gtk/gtkmenubutton.c +++ b/gtk/gtkmenubutton.c @@ -255,13 +255,12 @@ menu_position_up_down_func (GtkMenu *menu, GtkMenuButtonPrivate *priv = menu_button->priv; GtkWidget *widget = GTK_WIDGET (menu_button); GtkWidget *toplevel; - GtkRequisition menu_req; GtkTextDirection direction; GdkRectangle monitor; gint monitor_num; GdkScreen *screen; GdkWindow *window; - GtkAllocation allocation, arrow_allocation; + GtkAllocation menu_allocation, allocation, arrow_allocation; GtkAlign align; /* In the common case the menu button is showing a dropdown menu, set the @@ -274,9 +273,6 @@ menu_position_up_down_func (GtkMenu *menu, gtk_window_set_type_hint (GTK_WINDOW (toplevel), GDK_WINDOW_TYPE_HINT_DROPDOWN_MENU); } - gtk_widget_get_preferred_size (GTK_WIDGET (priv->popup), - &menu_req, NULL); - align = gtk_widget_get_halign (GTK_WIDGET (priv->popup)); direction = gtk_widget_get_direction (widget); window = gtk_widget_get_window (priv->align_widget ? priv->align_widget : widget); @@ -289,6 +285,7 @@ menu_position_up_down_func (GtkMenu *menu, gtk_widget_get_allocation (priv->align_widget ? priv->align_widget : widget, &allocation); gtk_widget_get_allocation (widget, &arrow_allocation); + gtk_widget_get_allocation (GTK_WIDGET (priv->popup), &menu_allocation); gdk_window_get_origin (window, x, y); *x += allocation.x; @@ -299,27 +296,27 @@ menu_position_up_down_func (GtkMenu *menu, align = GTK_ALIGN_START; if (align == GTK_ALIGN_CENTER) - *x -= (menu_req.width - allocation.width) / 2; + *x -= (menu_allocation.width - allocation.width) / 2; else if ((align == GTK_ALIGN_START && direction == GTK_TEXT_DIR_LTR) || (align == GTK_ALIGN_END && direction == GTK_TEXT_DIR_RTL)) - *x += MAX (allocation.width - menu_req.width, 0); - else if (menu_req.width > allocation.width) - *x -= menu_req.width - allocation.width; + *x += MAX (allocation.width - menu_allocation.width, 0); + else if (menu_allocation.width > allocation.width) + *x -= menu_allocation.width - allocation.width; - if (priv->arrow_type == GTK_ARROW_UP && *y - menu_req.height >= monitor.y) + if (priv->arrow_type == GTK_ARROW_UP && *y - menu_allocation.height >= monitor.y) { - *y -= menu_req.height; + *y -= menu_allocation.height; } else { - if ((*y + arrow_allocation.height + menu_req.height) <= monitor.y + monitor.height) + if ((*y + arrow_allocation.height + menu_allocation.height) <= monitor.y + monitor.height) *y += arrow_allocation.height; - else if ((*y - menu_req.height) >= monitor.y) - *y -= menu_req.height; + else if ((*y - menu_allocation.height) >= monitor.y) + *y -= menu_allocation.height; else if (monitor.y + monitor.height - (*y + arrow_allocation.height) > *y) *y += arrow_allocation.height; else - *y -= menu_req.height; + *y -= menu_allocation.height; } *push_in = FALSE; @@ -334,8 +331,8 @@ menu_position_side_func (GtkMenu *menu, { GtkMenuButtonPrivate *priv = menu_button->priv; GtkAllocation allocation; + GtkAllocation menu_allocation; GtkWidget *widget = GTK_WIDGET (menu_button); - GtkRequisition menu_req; GdkRectangle monitor; gint monitor_num; GdkScreen *screen; @@ -343,9 +340,6 @@ menu_position_side_func (GtkMenu *menu, GtkAlign align; GtkTextDirection direction; - gtk_widget_get_preferred_size (GTK_WIDGET (priv->popup), - &menu_req, NULL); - window = gtk_widget_get_window (widget); direction = gtk_widget_get_direction (widget); @@ -359,20 +353,21 @@ menu_position_side_func (GtkMenu *menu, gdk_window_get_origin (gtk_button_get_event_window (GTK_BUTTON (menu_button)), x, y); gtk_widget_get_allocation (widget, &allocation); + gtk_widget_get_allocation (GTK_WIDGET (priv->popup), &menu_allocation); if ((priv->arrow_type == GTK_ARROW_RIGHT && direction == GTK_TEXT_DIR_LTR) || (priv->arrow_type == GTK_ARROW_LEFT && direction == GTK_TEXT_DIR_RTL)) { - if (*x + allocation.width + menu_req.width <= monitor.x + monitor.width) + if (*x + allocation.width + menu_allocation.width <= monitor.x + monitor.width) *x += allocation.width; else - *x -= menu_req.width; + *x -= menu_allocation.width; } else { - if (*x - menu_req.width >= monitor.x) - *x -= menu_req.width; + if (*x - menu_allocation.width >= monitor.x) + *x -= menu_allocation.width; else *x += allocation.width; } @@ -382,9 +377,9 @@ menu_position_side_func (GtkMenu *menu, align = GTK_ALIGN_START; if (align == GTK_ALIGN_CENTER) - *y -= (menu_req.height - allocation.height) / 2; + *y -= (menu_allocation.height - allocation.height) / 2; else if (align == GTK_ALIGN_END) - *y -= menu_req.height - allocation.height; + *y -= menu_allocation.height - allocation.height; *push_in = FALSE; } |