aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog9
-rw-r--r--lib/ephy-gui.c63
-rw-r--r--lib/ephy-gui.h6
-rw-r--r--src/bookmarks/ephy-bookmarks-editor.c6
-rw-r--r--src/ephy-history-window.c3
5 files changed, 77 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 1ee43b016..1e7be162d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+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
+
2004-09-13 Adam Hooper <adamh@cvs.gnome.org>
* data/Makefile.am:
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
diff --git a/lib/ephy-gui.h b/lib/ephy-gui.h
index 8c3846d10..0c9c5a04c 100644
--- a/lib/ephy-gui.h
+++ b/lib/ephy-gui.h
@@ -30,6 +30,12 @@
G_BEGIN_DECLS
+void ephy_gui_menu_position_tree_selection (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gboolean *push_in,
+ gpointer user_data);
+
void ephy_gui_menu_position_under_widget (GtkMenu *menu,
gint *x,
gint *y,
diff --git a/src/bookmarks/ephy-bookmarks-editor.c b/src/bookmarks/ephy-bookmarks-editor.c
index 360dc8f37..3a6cd2db0 100644
--- a/src/bookmarks/ephy-bookmarks-editor.c
+++ b/src/bookmarks/ephy-bookmarks-editor.c
@@ -1137,7 +1137,8 @@ ephy_bookmarks_editor_show_popup_cb (GtkWidget *view,
widget = gtk_ui_manager_get_widget (editor->priv->ui_merge,
"/EphyBookmarkEditorPopup");
- gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, 2,
+ gtk_menu_popup (GTK_MENU (widget), NULL, NULL,
+ ephy_gui_menu_position_tree_selection, view, 2,
gtk_get_current_event_time ());
return TRUE;
@@ -1228,7 +1229,8 @@ keyword_node_show_popup_cb (GtkWidget *view, EphyBookmarksEditor *editor)
widget = gtk_ui_manager_get_widget (editor->priv->ui_merge,
"/EphyBookmarkKeywordPopup");
- gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, 2,
+ gtk_menu_popup (GTK_MENU (widget), NULL, NULL,
+ ephy_gui_menu_position_tree_selection, view, 2,
gtk_get_current_event_time ());
return TRUE;
diff --git a/src/ephy-history-window.c b/src/ephy-history-window.c
index b045d48ab..b28a792cd 100644
--- a/src/ephy-history-window.c
+++ b/src/ephy-history-window.c
@@ -842,7 +842,8 @@ ephy_history_window_show_popup_cb (GtkWidget *view,
widget = gtk_ui_manager_get_widget (editor->priv->ui_merge,
"/EphyHistoryWindowPopup");
- gtk_menu_popup (GTK_MENU (widget), NULL, NULL, NULL, NULL, 2,
+ gtk_menu_popup (GTK_MENU (widget), NULL, NULL,
+ ephy_gui_menu_position_tree_selection, view, 2,
gtk_get_current_event_time ());
return TRUE;