summaryrefslogtreecommitdiff
path: root/libnautilus
diff options
context:
space:
mode:
authorRamiro Estrugo <ramiro@src.gnome.org>2000-02-15 20:46:14 +0000
committerRamiro Estrugo <ramiro@src.gnome.org>2000-02-15 20:46:14 +0000
commit943a049757f3550e544da79f5fe80f48662cdced (patch)
tree4378036b29e6fb9ef0e3b76add2fe157471e13d5 /libnautilus
parentc92672fc5a64b6cff2d3cbadb3e0c44e6185ce45 (diff)
downloadnautilus-943a049757f3550e544da79f5fe80f48662cdced.tar.gz
Added displacement offset for popup menus, so that the first item does'nt
get triggered right away.
Diffstat (limited to 'libnautilus')
-rw-r--r--libnautilus/nautilus-gtk-extensions.c56
-rw-r--r--libnautilus/nautilus-gtk-extensions.h6
2 files changed, 58 insertions, 4 deletions
diff --git a/libnautilus/nautilus-gtk-extensions.c b/libnautilus/nautilus-gtk-extensions.c
index 60577e5c9..84ab55eff 100644
--- a/libnautilus/nautilus-gtk-extensions.c
+++ b/libnautilus/nautilus-gtk-extensions.c
@@ -135,6 +135,42 @@ nautilus_gtk_selection_data_free_deep (GtkSelectionData *data)
}
/**
+ * nautilus_gtk_signal_connect_free_data:
+ *
+ * Function to displace the popup menu some, otherwise the first item
+ * gets selected right away.
+ * This function gets called by gtk_menu_popup ().
+ *
+ * @menu: the popup menu.
+ * @x: x coord where gtk want to place the menu
+ * @y: y coord where gtk want to place the menu
+ * @user_data: something
+ **/
+static void
+nautilus_popup_menu_position_func (GtkMenu *menu,
+ gint *x,
+ gint *y,
+ gpointer user_data)
+{
+ GdkPoint *offset;
+
+ g_assert (x != NULL);
+ g_assert (y != NULL);
+
+ offset = (GdkPoint*) user_data;
+
+ g_assert (offset != NULL);
+
+ /*
+ * XXX: Check for screen boundaries. Also, the cast from
+ * gint16 might cause problems. Unfortunately, GdkPoint
+ * uses gint16.
+ */
+ *x += (gint) offset->x;
+ *y += (gint) offset->y;
+}
+
+/**
* nautilus_pop_up_context_menu:
*
* Pop up a context menu under the mouse. This assumes that
@@ -147,18 +183,32 @@ nautilus_gtk_selection_data_free_deep (GtkSelectionData *data)
* so perhaps it belongs in a different file.
*
* @menu: The menu to pop up under the mouse.
+ * @offset_x: Number of pixels to displace the popup menu vertically
+ * @offset_y: Number of pixels to displace the popup menu horizontally
**/
void
-nautilus_pop_up_context_menu (GtkMenu *menu)
+nautilus_pop_up_context_menu (GtkMenu *menu,
+ gint16 offset_x,
+ gint16 offset_y)
{
+ GdkPoint offset;
+
g_return_if_fail (GTK_IS_MENU (menu));
+ offset.x = offset_x;
+ offset.y = offset_y;
+
/* We pass current time here instead of extracting it from
* the event, for API simplicity. This does not seem to make
* any practical difference. See man XGrabPointer for details.
*/
- gtk_menu_popup (menu, NULL, NULL, NULL,
- NULL, 3, GDK_CURRENT_TIME);
+ gtk_menu_popup (menu, /* menu */
+ NULL, /* parent_menu_shell */
+ NULL, /* parent_menu_item */
+ nautilus_popup_menu_position_func, /* func */
+ (gpointer) &offset, /* data */
+ 3, /* button */
+ GDK_CURRENT_TIME); /* activate_time */
gtk_object_sink (GTK_OBJECT(menu));
}
diff --git a/libnautilus/nautilus-gtk-extensions.h b/libnautilus/nautilus-gtk-extensions.h
index 57ed89081..71ab3da7c 100644
--- a/libnautilus/nautilus-gtk-extensions.h
+++ b/libnautilus/nautilus-gtk-extensions.h
@@ -40,6 +40,10 @@ void nautilus_gtk_window_present (GtkWindow
GtkSelectionData *nautilus_gtk_selection_data_copy_deep (const GtkSelectionData *selection_data);
void nautilus_gtk_selection_data_free_deep (GtkSelectionData *selection_data);
-void nautilus_pop_up_context_menu (GtkMenu *menu);
+#define NAUTILUS_DEFAULT_POPUP_MENU_DISPLACEMENT 2
+
+void nautilus_pop_up_context_menu (GtkMenu *menu,
+ gint16 offset_x,
+ gint16 offset_y);
#endif /* NAUTILUS_GTK_EXTENSIONS_H */