summaryrefslogtreecommitdiff
path: root/gtk/gtkentry.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2006-04-27 18:50:39 +0000
committerMatthias Clasen <matthiasc@src.gnome.org>2006-04-27 18:50:39 +0000
commit660f0898807dae6236128f1db2a8ae8cc90ae247 (patch)
treee1bd376200909f19895ffa0044955926c9de1063 /gtk/gtkentry.c
parent60c8c2b55c75ff7c21f7864bce816ecfc22195b8 (diff)
downloadgtk+-660f0898807dae6236128f1db2a8ae8cc90ae247.tar.gz
Improve positioning of the menu when popped up by keynav. (#334987,
2006-04-27 Matthias Clasen <mclasen@redhat.com> * gtk/gtkentry.c (popup_position_func): Improve positioning of the menu when popped up by keynav. (#334987, Christian Persch)
Diffstat (limited to 'gtk/gtkentry.c')
-rw-r--r--gtk/gtkentry.c41
1 files changed, 27 insertions, 14 deletions
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 2426c2a1a2..2cf8f01609 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -4828,31 +4828,44 @@ popup_position_func (GtkMenu *menu,
{
GtkEntry *entry = GTK_ENTRY (user_data);
GtkWidget *widget = GTK_WIDGET (entry);
- GdkScreen *screen = gtk_widget_get_screen (widget);
- GtkRequisition req;
- gint monitor_num;
+ GdkScreen *screen;
+ GtkRequisition menu_req;
GdkRectangle monitor;
-
+ GtkBorder inner_border;
+ gint monitor_num, strong_x, height;
+
g_return_if_fail (GTK_WIDGET_REALIZED (entry));
- gdk_window_get_origin (widget->window, x, y);
-
- gtk_widget_size_request (entry->popup_menu, &req);
-
- *x += widget->allocation.width / 2;
- *y += widget->allocation.height;
+ gdk_window_get_origin (entry->text_area, x, y);
- monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y);
+ screen = gtk_widget_get_screen (widget);
+ monitor_num = gdk_screen_get_monitor_at_window (screen, entry->text_area);
+ if (monitor_num < 0)
+ monitor_num = 0;
gtk_menu_set_monitor (menu, monitor_num);
+
gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor);
+ gtk_widget_size_request (entry->popup_menu, &menu_req);
+ gdk_drawable_get_size (entry->text_area, NULL, &height);
+ gtk_entry_get_cursor_locations (entry, CURSOR_STANDARD, &strong_x, NULL);
+ get_inner_border (entry, &inner_border);
+
+ *x += inner_border.left + strong_x - entry->scroll_offset;
+ if (gtk_widget_get_direction (widget) == GTK_TEXT_DIR_RTL)
+ *x -= menu_req.width;
- *x = CLAMP (*x, monitor.x, monitor.x + MAX (0, monitor.width - req.width));
- *y = CLAMP (*y, monitor.y, monitor.y + MAX (0, monitor.height - req.height));
+ if ((*y + height + menu_req.height) <= monitor.y + monitor.height)
+ *y += height;
+ else if ((*y - menu_req.height) >= monitor.y)
+ *y -= menu_req.height;
+ else if (monitor.y + monitor.height - (*y + height) > *y)
+ *y += height;
+ else
+ *y -= menu_req.height;
*push_in = FALSE;
}
-
static void
unichar_chosen_func (const char *text,
gpointer data)