[gtk+/wip/attachment-parameters: 3/3] gtkmenu: add gtk_menu_popup_with_parameters ()
- From: William Hua <williamhua src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/attachment-parameters: 3/3] gtkmenu: add gtk_menu_popup_with_parameters ()
- Date: Fri, 18 Sep 2015 21:46:03 +0000 (UTC)
commit a2c98080d249aee2a3ebef5a89f3211e708a5447
Author: William Hua <william hua canonical com>
Date: Fri Sep 18 16:46:44 2015 -0400
gtkmenu: add gtk_menu_popup_with_parameters ()
gtk/gtkmenu.c | 157 +++++++++++++++++++++++++++++++++++---------------
gtk/gtkmenu.h | 8 +++
gtk/gtkmenuprivate.h | 2 +
3 files changed, 120 insertions(+), 47 deletions(-)
---
diff --git a/gtk/gtkmenu.c b/gtk/gtkmenu.c
index 61f8541..305b822 100644
--- a/gtk/gtkmenu.c
+++ b/gtk/gtkmenu.c
@@ -1496,53 +1496,17 @@ associate_menu_grab_transfer_window (GtkMenu *menu)
g_object_set_data (G_OBJECT (toplevel_window), I_("gdk-attached-grab-window"), transfer_window);
}
-/**
- * gtk_menu_popup_for_device:
- * @menu: a #GtkMenu
- * @device: (allow-none): a #GdkDevice
- * @parent_menu_shell: (allow-none): the menu shell containing the triggering
- * menu item, or %NULL
- * @parent_menu_item: (allow-none): the menu item whose activation triggered
- * the popup, or %NULL
- * @func: (allow-none): a user supplied function used to position the menu,
- * or %NULL
- * @data: (allow-none): user supplied data to be passed to @func
- * @destroy: (allow-none): destroy notify for @data
- * @button: the mouse button which was pressed to initiate the event
- * @activate_time: the time at which the activation event occurred
- *
- * Displays a menu and makes it available for selection.
- *
- * Applications can use this function to display context-sensitive menus,
- * and will typically supply %NULL for the @parent_menu_shell,
- * @parent_menu_item, @func, @data and @destroy parameters. The default
- * menu positioning function will position the menu at the current position
- * of @device (or its corresponding pointer).
- *
- * The @button parameter should be the mouse button pressed to initiate
- * the menu popup. If the menu popup was initiated by something other than
- * a mouse button press, such as a mouse button release or a keypress,
- * @button should be 0.
- *
- * The @activate_time parameter is used to conflict-resolve initiation of
- * concurrent requests for mouse/keyboard grab requests. To function
- * properly, this needs to be the time stamp of the user event (such as
- * a mouse click or key press) that caused the initiation of the popup.
- * Only if no such event is available, gtk_get_current_event_time() can
- * be used instead.
- *
- * Since: 3.0
- */
-void
-gtk_menu_popup_for_device (GtkMenu *menu,
- GdkDevice *device,
- GtkWidget *parent_menu_shell,
- GtkWidget *parent_menu_item,
- GtkMenuPositionFunc func,
- gpointer data,
- GDestroyNotify destroy,
- guint button,
- guint32 activate_time)
+static void
+gtk_menu_popup_internal (GtkMenu *menu,
+ GdkDevice *device,
+ GtkWidget *parent_menu_shell,
+ GtkWidget *parent_menu_item,
+ GtkMenuPositionFunc func,
+ gpointer data,
+ GDestroyNotify destroy,
+ guint button,
+ guint32 activate_time,
+ GdkAttachmentParameters *parameters)
{
GtkMenuPrivate *priv = menu->priv;
GtkWidget *widget;
@@ -1555,6 +1519,9 @@ gtk_menu_popup_for_device (GtkMenu *menu,
GdkDevice *keyboard, *pointer, *source_device = NULL;
GdkDisplay *display;
+ if (!GTK_IS_MENU (menu) || (device && !GDK_IS_DEVICE (device)))
+ gdk_attachment_parameters_free (parameters);
+
g_return_if_fail (GTK_IS_MENU (menu));
g_return_if_fail (device == NULL || GDK_IS_DEVICE (device));
@@ -1674,6 +1641,7 @@ gtk_menu_popup_for_device (GtkMenu *menu,
*/
menu_shell->priv->parent_menu_shell = NULL;
menu_grab_transfer_window_destroy (menu);
+ gdk_attachment_parameters_free (parameters);
return;
}
@@ -1727,6 +1695,14 @@ gtk_menu_popup_for_device (GtkMenu *menu,
priv->position_func_data_destroy = destroy;
menu_shell->priv->activate_time = activate_time;
+ if (parameters != priv->attachment_parameters)
+ {
+ gdk_attachment_parameters_free (priv->attachment_parameters);
+ priv->attachment_parameters = parameters;
+ }
+ else if (parameters)
+ g_warning ("gtk_menu_popup_internal (): menu already owns parameters");
+
/* We need to show the menu here rather in the init function
* because code expects to be able to tell if the menu is onscreen
* by looking at gtk_widget_get_visible (menu)
@@ -1767,6 +1743,93 @@ gtk_menu_popup_for_device (GtkMenu *menu,
_gtk_menu_shell_update_mnemonics (menu_shell);
}
+void
+gtk_menu_popup_with_parameters (GtkMenu *menu,
+ GdkDevice *device,
+ GtkWidget *parent_menu_shell,
+ guint button,
+ guint32 activate_time,
+ GdkAttachmentParameters *parameters)
+{
+ if (!GTK_IS_MENU (menu))
+ gdk_attachment_parameters_free (parameters);
+
+ g_return_if_fail (GTK_IS_MENU (menu));
+
+ gtk_menu_popup_internal (menu,
+ device,
+ parent_menu_shell,
+ NULL,
+ NULL,
+ NULL,
+ NULL,
+ button,
+ activate_time,
+ parameters);
+}
+
+/**
+ * gtk_menu_popup_for_device:
+ * @menu: a #GtkMenu
+ * @device: (allow-none): a #GdkDevice
+ * @parent_menu_shell: (allow-none): the menu shell containing the triggering
+ * menu item, or %NULL
+ * @parent_menu_item: (allow-none): the menu item whose activation triggered
+ * the popup, or %NULL
+ * @func: (allow-none): a user supplied function used to position the menu,
+ * or %NULL
+ * @data: (allow-none): user supplied data to be passed to @func
+ * @destroy: (allow-none): destroy notify for @data
+ * @button: the mouse button which was pressed to initiate the event
+ * @activate_time: the time at which the activation event occurred
+ *
+ * Displays a menu and makes it available for selection.
+ *
+ * Applications can use this function to display context-sensitive menus,
+ * and will typically supply %NULL for the @parent_menu_shell,
+ * @parent_menu_item, @func, @data and @destroy parameters. The default
+ * menu positioning function will position the menu at the current position
+ * of @device (or its corresponding pointer).
+ *
+ * The @button parameter should be the mouse button pressed to initiate
+ * the menu popup. If the menu popup was initiated by something other than
+ * a mouse button press, such as a mouse button release or a keypress,
+ * @button should be 0.
+ *
+ * The @activate_time parameter is used to conflict-resolve initiation of
+ * concurrent requests for mouse/keyboard grab requests. To function
+ * properly, this needs to be the time stamp of the user event (such as
+ * a mouse click or key press) that caused the initiation of the popup.
+ * Only if no such event is available, gtk_get_current_event_time() can
+ * be used instead.
+ *
+ * Since: 3.0
+ */
+void
+gtk_menu_popup_for_device (GtkMenu *menu,
+ GdkDevice *device,
+ GtkWidget *parent_menu_shell,
+ GtkWidget *parent_menu_item,
+ GtkMenuPositionFunc func,
+ gpointer data,
+ GDestroyNotify destroy,
+ guint button,
+ guint32 activate_time)
+{
+ g_return_if_fail (GTK_IS_MENU (menu));
+
+ gtk_menu_popup_internal (menu,
+ device,
+ parent_menu_shell,
+ parent_menu_item,
+ func,
+ data,
+ destroy,
+ button,
+ activate_time,
+ NULL);
+}
+
/**
* gtk_menu_popup:
* @menu: a #GtkMenu
diff --git a/gtk/gtkmenu.h b/gtk/gtkmenu.h
index bf81a89..87146d5 100644
--- a/gtk/gtkmenu.h
+++ b/gtk/gtkmenu.h
@@ -155,6 +155,14 @@ void gtk_menu_popup_for_device (GtkMenu *menu,
guint button,
guint32 activate_time);
+GDK_AVAILABLE_IN_3_18
+void gtk_menu_popup_with_parameters (GtkMenu *menu,
+ GdkDevice *device,
+ GtkWidget *parent_menu_shell,
+ guint button,
+ guint32 activate_time,
+ GdkAttachmentParameters *parameters);
+
/* Position the menu according to its position function. Called
* from gtkmenuitem.c when a menu-item changes its allocation
*/
diff --git a/gtk/gtkmenuprivate.h b/gtk/gtkmenuprivate.h
index f1a40d8..5e0295d 100644
--- a/gtk/gtkmenuprivate.h
+++ b/gtk/gtkmenuprivate.h
@@ -51,6 +51,8 @@ struct _GtkMenuPrivate
gint position_x;
gint position_y;
+ GdkAttachmentParameters *attachment_parameters;
+
guint toggle_size;
guint accel_size;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]