diff options
author | Marco Pesenti Gritti <marco@gnome.org> | 2004-09-15 04:28:42 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <marco@src.gnome.org> | 2004-09-15 04:28:42 +0800 |
commit | ad595146b5a48a6b527d0f643e5b06edae32917d (patch) | |
tree | a1a623b63becd7b3ccdfeb4134d66732b3bfac9c /lib/ephy-gui.c | |
parent | e40e2cff4000f665f4b7c99f376b94f6c4e4b3bb (diff) | |
download | gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar.gz gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar.bz2 gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar.lz gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar.xz gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.tar.zst gsoc2013-epiphany-ad595146b5a48a6b527d0f643e5b06edae32917d.zip |
Better positioning of context menus for treeviews. Fix #152431
2004-09-13 Marco Pesenti Gritti <marco@gnome.org>
* lib/ephy-guy.c:
* src/bookmarks/ephy-bookmarks-editor.c:
* src/ephy-history-window.c:
Better positioning of context menus for treeviews.
Fix #152431
Diffstat (limited to 'lib/ephy-gui.c')
-rw-r--r-- | lib/ephy-gui.c | 63 |
1 files changed, 56 insertions, 7 deletions
diff --git a/lib/ephy-gui.c b/lib/ephy-gui.c index 88460dc78..fe340bcc5 100644 --- a/lib/ephy-gui.c +++ b/lib/ephy-gui.c @@ -36,11 +36,66 @@ #include <gtk/gtklabel.h> #include <gtk/gtkstock.h> #include <gtk/gtkmain.h> +#include <gtk/gtktreeselection.h> /* Styles for tab labels */ GtkStyle *loading_text_style = NULL; GtkStyle *new_text_style = NULL; +static void +sanitize_popup_position (GtkWidget *widget, GtkMenu *menu, gint *x, gint *y) +{ + GdkScreen *screen = gtk_widget_get_screen (widget); + gint monitor_num; + GdkRectangle monitor; + GtkRequisition req; + + gtk_widget_size_request (GTK_WIDGET (menu), &req); + + monitor_num = gdk_screen_get_monitor_at_point (screen, *x, *y); + gtk_menu_set_monitor (menu, monitor_num); + gdk_screen_get_monitor_geometry (screen, monitor_num, &monitor); + + *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)); +} + +void +ephy_gui_menu_position_tree_selection (GtkMenu *menu, + gint *x, + gint *y, + gboolean *push_in, + gpointer user_data) +{ + GtkTreeSelection *selection; + GList *selected_rows; + GtkTreeModel *model; + GtkTreeView *tree_view = GTK_TREE_VIEW (user_data); + GtkWidget *widget = GTK_WIDGET (user_data); + GtkRequisition req; + + gtk_widget_size_request (GTK_WIDGET (menu), &req); + gdk_window_get_origin (widget->window, x, y); + + *x += (widget->allocation.width - req.width) / 2; + + selection = gtk_tree_view_get_selection (tree_view); + selected_rows = gtk_tree_selection_get_selected_rows (selection, &model); + if (selected_rows) + { + GdkRectangle cell_rect; + + gtk_tree_view_get_cell_area (tree_view, selected_rows->data, + NULL, &cell_rect); + *y += CLAMP (cell_rect.y, 0, widget->allocation.height); + + g_list_foreach (selected_rows, (GFunc)gtk_tree_path_free, NULL); + g_list_free (selected_rows); + } + + sanitize_popup_position (widget, menu, x, y); +} + /** * gul_gui_menu_position_under_widget: */ @@ -52,7 +107,6 @@ ephy_gui_menu_position_under_widget (GtkMenu *menu, gpointer user_data) { GtkWidget *w = GTK_WIDGET (user_data); - gint screen_width, screen_height; GtkRequisition requisition; gboolean rtl; @@ -61,10 +115,6 @@ ephy_gui_menu_position_under_widget (GtkMenu *menu, gdk_window_get_origin (w->window, x, y); gtk_widget_size_request (GTK_WIDGET (menu), &requisition); - /* FIXME multihead */ - screen_width = gdk_screen_width (); - screen_height = gdk_screen_height (); - if (rtl) { *x += w->allocation.x + w->allocation.width - requisition.width; @@ -76,8 +126,7 @@ ephy_gui_menu_position_under_widget (GtkMenu *menu, *y += w->allocation.y + w->allocation.height; - *x = CLAMP (*x, 0, MAX (0, screen_width - requisition.width)); - *y = CLAMP (*y, 0, MAX (0, screen_height - requisition.height)); + sanitize_popup_position (w, menu, x, y); } gboolean |