]> Pileus Git - ~andy/gtk/commitdiff
GtkWidget: Add gtk_widget_insert_action_group()
authorLars Uebernickel <lars.uebernickel@canonical.com>
Fri, 17 Aug 2012 22:09:35 +0000 (18:09 -0400)
committerRyan Lortie <desrt@desrt.ca>
Mon, 20 Aug 2012 17:09:04 +0000 (13:09 -0400)
This allows adding a GActionGroup with a given name at an arbitrary
point in the widget tree.

This patch also adds an internal _get_action_muxer() API.  Calling this
will create a GActionMuxer associated with the widget.  The parent of
the muxer will be the muxer of the widget's conceptual parent.  For
non-menus, that is the normal parent.  For menus, it is the attach
widget.

In this way, we end up with a hierarchy of GActionMuxer that largely
reflects the hierarchy of GtkWidget, but only in places that the action
context has been requested.  These muxers are the ones on which the
inserted actions groups are installed.

A following patch will add a user of this API.

docs/reference/gtk/gtk3-sections.txt
gtk/gtk.symbols
gtk/gtkmenu.c
gtk/gtkwidget.c
gtk/gtkwidget.h
gtk/gtkwidgetprivate.h

index 0d16ef420aff26220882828873a1b079e650076a..8bdcb890db3433288acc57e1214e3b50afd01019 100644 (file)
@@ -5291,6 +5291,7 @@ gtk_widget_get_mapped
 gtk_widget_get_requisition
 gtk_widget_device_is_shadowed
 gtk_widget_get_modifier_mask
+gtk_widget_insert_action_group
 
 <SUBSECTION>
 gtk_widget_get_path
index f0bffa4c6955234a2832ba9ce13e4640d2313b0d..1441671857ad7d7fc85107e20c258a7fdb59fdb4 100644 (file)
@@ -3828,6 +3828,7 @@ gtk_widget_unmap
 gtk_widget_unparent
 gtk_widget_unrealize
 gtk_widget_unset_state_flags
+gtk_widget_insert_action_group
 #ifdef GDK_WINDOWING_WIN32
 gtk_win32_embed_widget_get_type
 #endif
index 9f0bfee8182a6b469f7d1a04ae550b63458d56b1..6667ed5f6d3e30bb7f228596174586f071e40e24 100644 (file)
@@ -1220,6 +1220,8 @@ gtk_menu_attach_to_widget (GtkMenu           *menu,
   /* Attach the widget to the toplevel window. */
   gtk_window_set_attached_to (GTK_WINDOW (menu->priv->toplevel), attach_widget);
 
+  _gtk_widget_update_parent_muxer (GTK_WIDGET (menu));
+
   /* Fallback title for menu comes from attach widget */
   gtk_menu_update_title (menu);
 
@@ -1294,6 +1296,8 @@ gtk_menu_detach (GtkMenu *menu)
 
   g_slice_free (GtkMenuAttachData, data);
 
+  _gtk_widget_update_parent_muxer (GTK_WIDGET (menu));
+
   /* Fallback title for menu comes from attach widget */
   gtk_menu_update_title (menu);
 
index 628ff17c745980883bf4af74ced36acf153fdfb1..ebcea8375552bdd93c80d11d4a1f1bc3b11e1985 100644 (file)
@@ -390,6 +390,9 @@ struct _GtkWidgetPrivate
   /* The widget's requested sizes */
   SizeRequestCache requests;
 
+  /* actions attached to this or any parent widget */
+  GActionMuxer *muxer;
+
   /* The widget's window or its parent window if it does
    * not have a window. (Which will be indicated by the
    * GTK_NO_WINDOW flag being set).
@@ -3899,6 +3902,8 @@ gtk_widget_unparent (GtkWidget *widget)
   if (priv->context)
     gtk_style_context_set_parent (priv->context, NULL);
 
+  _gtk_widget_update_parent_muxer (widget);
+
   g_signal_emit (widget, widget_signals[PARENT_SET], 0, old_parent);
   if (toplevel)
     {
@@ -7968,6 +7973,8 @@ gtk_widget_set_parent (GtkWidget *widget,
     gtk_style_context_set_parent (priv->context,
                                   gtk_widget_get_style_context (parent));
 
+  _gtk_widget_update_parent_muxer (widget);
+
   g_signal_emit (widget, widget_signals[PARENT_SET], 0, NULL);
   if (priv->parent->priv->anchored)
     _gtk_widget_propagate_hierarchy_changed (widget, NULL);
@@ -10268,6 +10275,8 @@ gtk_widget_dispose (GObject *object)
       priv->in_destruction = FALSE;
     }
 
+  g_clear_object (&priv->muxer);
+
   G_OBJECT_CLASS (gtk_widget_parent_class)->dispose (object);
 }
 
@@ -14072,3 +14081,61 @@ _gtk_widget_set_style (GtkWidget *widget,
 {
   widget->priv->style = style;
 }
+
+void
+_gtk_widget_update_parent_muxer (GtkWidget *widget)
+{
+  GtkWidget *parent;
+  GActionMuxer *parent_muxer;
+
+  if (widget->priv->muxer == NULL)
+    return;
+
+  if (GTK_IS_MENU (widget))
+    parent = gtk_menu_get_attach_widget (GTK_MENU (widget));
+  else
+    parent = gtk_widget_get_parent (widget);
+
+  parent_muxer = parent ? _gtk_widget_get_action_muxer (parent) : NULL;
+
+  g_action_muxer_set_parent (widget->priv->muxer, parent_muxer);
+}
+
+GActionMuxer *
+_gtk_widget_get_action_muxer (GtkWidget *widget)
+{
+  if (widget->priv->muxer == NULL)
+    {
+      widget->priv->muxer = g_action_muxer_new ();
+      _gtk_widget_update_parent_muxer (widget);
+    }
+
+  return widget->priv->muxer;
+}
+
+/**
+ * gtk_widget_insert_action_group:
+ * @widget: a #GtkWidget
+ * @name: the prefix for actions in @group
+ * @group: a #GActionGroup
+ *
+ * Inserts @group into @widget. Children of @widget that implement
+ * #GtkActionable can then be associated with actions in @group by
+ * setting their 'action-name' to @prefix.<action-name>.
+ *
+ * Since: 3.6
+ */
+void
+gtk_widget_insert_action_group (GtkWidget    *widget,
+                                const gchar  *name,
+                                GActionGroup *group)
+{
+  GActionMuxer *muxer;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));
+  g_return_if_fail (name != NULL);
+
+  muxer = _gtk_widget_get_action_muxer (widget);
+
+  g_action_muxer_insert (muxer, name, group);
+}
index 576d7e91b9c2bbbf2d3e29b4be6185ac7ee311bf..c17847811770a953c2b36676f031c3cec7e2bf44 100644 (file)
@@ -886,6 +886,10 @@ GDK_AVAILABLE_IN_3_4
 GdkModifierType   gtk_widget_get_modifier_mask (GtkWidget         *widget,
                                                 GdkModifierIntent  intent);
 
+GDK_AVAILABLE_IN_3_6
+void                    gtk_widget_insert_action_group                  (GtkWidget    *widget,
+                                                                         const gchar  *name,
+                                                                         GActionGroup *group);
 
 G_END_DECLS
 
index c59ed3902fa8bc9f40ea3f52c4af99923336b4a2..c7c0cfee64fc95931d90ff83060da1b745039544 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "gtkcsstypesprivate.h"
 #include "gtkwidget.h"
+#include "gactionmuxer.h"
 
 G_BEGIN_DECLS
 
@@ -178,6 +179,9 @@ void              _gtk_widget_invalidate_style_context     (GtkWidget    *widget
                                                             GtkCssChange  change);
 void              _gtk_widget_style_context_invalidated    (GtkWidget    *widget);
 
+void              _gtk_widget_update_parent_muxer          (GtkWidget    *widget);
+GActionMuxer *    _gtk_widget_get_action_muxer             (GtkWidget    *widget);
+
 G_END_DECLS
 
 #endif /* __GTK_WIDGET_PRIVATE_H__ */