[gtk+] GtkPopoverMenu: Add API to open a submenu



commit 0b4c37624a970ab9b1c806014336dfee311fe11f
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 26 19:14:01 2014 -0400

    GtkPopoverMenu: Add API to open a submenu
    
    This allows alternative menu switching to be implemented, besides
    the builtin GtkModelButton support.

 docs/reference/gtk/gtk3-sections.txt |    1 +
 gtk/gtkpopovermenu.c                 |   42 +++++++++++++++++++++++++---------
 gtk/gtkpopovermenu.h                 |    5 ++++
 3 files changed, 37 insertions(+), 11 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 0e0bd6c..9b3f52c 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -7960,6 +7960,7 @@ gtk_popover_get_modal
 <TITLE>GtkPopoverMenu</TITLE>
 GtkPopoverMenu
 gtk_popover_menu_new
+gtk_popover_menu_open_submenu
 </SECTION>
 
 <SECTION>
diff --git a/gtk/gtkpopovermenu.c b/gtk/gtkpopovermenu.c
index 0e7e111..7947eb2 100644
--- a/gtk/gtkpopovermenu.c
+++ b/gtk/gtkpopovermenu.c
@@ -122,25 +122,16 @@ gtk_popover_menu_init (GtkPopoverMenu *popover)
 }
 
 static void
-back_to_main (GtkWidget *popover)
-{
-  GtkWidget *stack;
-
-  stack = gtk_bin_get_child (GTK_BIN (popover));
-  gtk_stack_set_visible_child_name (GTK_STACK (stack), "main");
-}
-
-static void
 gtk_popover_menu_map (GtkWidget *widget)
 {
   GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->map (widget);
-  back_to_main (widget);
+  gtk_popover_menu_open_submenu (GTK_POPOVER_MENU (widget), "main");
 }
 
 static void
 gtk_popover_menu_unmap (GtkWidget *widget)
 {
-  back_to_main (widget);
+  gtk_popover_menu_open_submenu (GTK_POPOVER_MENU (widget), "main");
   GTK_WIDGET_CLASS (gtk_popover_menu_parent_class)->unmap (widget);
 }
 
@@ -291,3 +282,32 @@ gtk_popover_menu_new (void)
 {
   return g_object_new (GTK_TYPE_POPOVER_MENU, NULL);
 }
+
+/**
+ * gtk_popover_menu_open_submenu:
+ * @popover: a #GtkPopoverMenu
+ * @name: the name of the menu to switch to
+ *
+ * Opens a submenu of the @popover. The @name
+ * must be one of the names given to the submenus
+ * of @popover with #GtkPopoverMenu:submenu, or
+ * "main" to switch back to the main menu.
+ *
+ * #GtkModelButton will open submenus automatically
+ * when the #GtkModelButton:menu-name property is set,
+ * so this function is only needed when you are using
+ * other kinds of widgets to initiate menu changes.
+ *
+ * Since: 3.16
+ */
+void
+gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
+                               const gchar    *name)
+{
+  GtkWidget *stack;
+
+  g_return_if_fail (GTK_IS_POPOVER_MENU (popover));
+
+  stack = gtk_bin_get_child (GTK_BIN (popover));
+  gtk_stack_set_visible_child_name (GTK_STACK (stack), name);
+}
diff --git a/gtk/gtkpopovermenu.h b/gtk/gtkpopovermenu.h
index 1cfaf70..b8f6373 100644
--- a/gtk/gtkpopovermenu.h
+++ b/gtk/gtkpopovermenu.h
@@ -52,6 +52,11 @@ GType       gtk_popover_menu_get_type (void) G_GNUC_CONST;
 GDK_AVAILABLE_IN_3_16
 GtkWidget * gtk_popover_menu_new      (void);
 
+GDK_AVAILABLE_IN_3_16
+void        gtk_popover_menu_open_submenu (GtkPopoverMenu *popover,
+                                           const gchar    *name);
+
+
 G_END_DECLS
 
 #endif /* __GTK_POPOVER_MENU_H__ */


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]