[gtk/wip/matthiasc/context-menu: 190/202] Add gtk_widget_set_context_menu
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/matthiasc/context-menu: 190/202] Add gtk_widget_set_context_menu
- Date: Thu, 18 Apr 2019 05:07:16 +0000 (UTC)
commit 4f3f7256733211dadf9787b976bc303f8326d6e1
Author: Matthias Clasen <mclasen redhat com>
Date: Sat Jan 26 18:50:14 2019 -0500
Add gtk_widget_set_context_menu
This lets apps associate a menu model with a widget.
It is up to individual widgets to use it.
gtk/gtkwidget.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
gtk/gtkwidget.h | 7 ++++++
gtk/gtkwidgetprivate.h | 2 ++
3 files changed, 68 insertions(+)
---
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index ed93a7ba20..c8942f03e9 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -573,6 +573,7 @@ enum {
PROP_SCALE_FACTOR,
PROP_CSS_NAME,
PROP_LAYOUT_MANAGER,
+ PROP_CONTEXT_MENU,
NUM_PROPERTIES
};
@@ -1378,6 +1379,18 @@ gtk_widget_class_init (GtkWidgetClass *klass)
GTK_TYPE_LAYOUT_MANAGER,
GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+ /**
+ * GtkWidget:context-menu:
+ *
+ * The #GMenuModel that is used for this widgets context menu.
+ */
+ widget_props[PROP_CONTEXT_MENU] =
+ g_param_spec_object ("context-menu",
+ P_("Context Menu"),
+ P_("The menu model used for this widgets' context menu"),
+ G_TYPE_MENU_MODEL,
+ GTK_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
+
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, widget_props);
/**
@@ -2310,6 +2323,9 @@ gtk_widget_set_property (GObject *object,
case PROP_LAYOUT_MANAGER:
gtk_widget_set_layout_manager (widget, g_value_get_object (value));
break;
+ case PROP_CONTEXT_MENU:
+ gtk_widget_set_context_menu (widget, g_value_get_object (value));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -2462,6 +2478,9 @@ gtk_widget_get_property (GObject *object,
case PROP_LAYOUT_MANAGER:
g_value_set_object (value, gtk_widget_get_layout_manager (widget));
break;
+ case PROP_CONTEXT_MENU:
+ g_value_set_object (value, gtk_widget_get_context_menu (widget));
+ break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -13588,3 +13607,43 @@ gtk_widget_get_layout_manager (GtkWidget *widget)
return priv->layout_manager;
}
+
+/**
+ * gtk_widget_set_context_menu:
+ * @widget: a #GtkWidget
+ * @menu: (nullable): a #GMenuModel
+ *
+ * Sets the menu model to use for the widgets
+ * context menu.
+ */
+void
+gtk_widget_set_context_menu (GtkWidget *widget,
+ GMenuModel *menu)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
+ g_return_if_fail (GTK_IS_WIDGET (widget));
+ g_return_if_fail (menu == NULL || G_IS_MENU_MODEL (menu));
+
+ if (g_set_object (&priv->context_menu, menu))
+ g_object_notify_by_pspec (G_OBJECT (widget), widget_props[PROP_CONTEXT_MENU]);
+}
+
+/**
+ * gtk_widget_get_context_menu:
+ * @widget: a #GtkWidget
+ *
+ * Returns the menu model that is used for
+ * this widgets context menu.
+ *
+ * Returns: (transfer none) (nullable): a #GMenuModel
+ */
+GMenuModel *
+gtk_widget_get_context_menu (GtkWidget *widget)
+{
+ GtkWidgetPrivate *priv = gtk_widget_get_instance_private (widget);
+
+ g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
+
+ return priv->context_menu;
+}
diff --git a/gtk/gtkwidget.h b/gtk/gtkwidget.h
index 30741b9499..1a19dd055d 100644
--- a/gtk/gtkwidget.h
+++ b/gtk/gtkwidget.h
@@ -1054,6 +1054,13 @@ void gtk_widget_snapshot_child (GtkWidget *widget,
GtkWidget *child,
GtkSnapshot *snapshot);
+GDK_AVAILABLE_IN_ALL
+void gtk_widget_set_context_menu (GtkWidget *widget,
+ GMenuModel *menu);
+GDK_AVAILABLE_IN_ALL
+GMenuModel * gtk_widget_get_context_menu (GtkWidget *widget);
+
+
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkWidget, g_object_unref)
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkRequisition, gtk_requisition_free)
diff --git a/gtk/gtkwidgetprivate.h b/gtk/gtkwidgetprivate.h
index 7409ee047b..e47d8f7f6a 100644
--- a/gtk/gtkwidgetprivate.h
+++ b/gtk/gtkwidgetprivate.h
@@ -190,6 +190,8 @@ struct _GtkWidgetPrivate
/* Pointer cursor */
GdkCursor *cursor;
+
+ GMenuModel *context_menu;
};
GtkCssNode * gtk_widget_get_css_node (GtkWidget *widget);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]