[gtk+/wip/gmenu] GtkApplication: add menu API



commit c378e0700fbc0e59d4ad6323f5c70c618db72a6a
Author: Ryan Lortie <desrt desrt ca>
Date:   Mon Dec 19 12:33:21 2011 -0500

    GtkApplication: add menu API
    
    We add the app-menu and menubar public APIs to GtkApplication while
    leaving the implementation in GApplication.
    
    The actual implementation will be moved soon.

 docs/reference/gtk/gtk3-sections.txt |    6 ++
 examples/bloatpad.c                  |    4 +-
 examples/plugman.c                   |    4 +-
 gtk/gtkapplication.c                 |   99 +++++++++++++++++++++++++++++++++-
 gtk/gtkapplication.h                 |    9 +++-
 gtk/gtkapplicationwindow.c           |    4 +-
 6 files changed, 117 insertions(+), 9 deletions(-)
---
diff --git a/docs/reference/gtk/gtk3-sections.txt b/docs/reference/gtk/gtk3-sections.txt
index 42e754f..935f56a 100644
--- a/docs/reference/gtk/gtk3-sections.txt
+++ b/docs/reference/gtk/gtk3-sections.txt
@@ -6994,6 +6994,12 @@ gtk_application_add_window
 gtk_application_remove_window
 gtk_application_get_windows
 
+<SUBSECTION>
+gtk_application_get_app_menu
+gtk_application_set_app_menu
+gtk_application_get_menubar
+gtk_application_set_menubar
+
 <SUBSECTION Standard>
 GtkApplicationClass
 GTK_TYPE_APPLICATION
diff --git a/examples/bloatpad.c b/examples/bloatpad.c
index ddd87ca..1f2a913 100644
--- a/examples/bloatpad.c
+++ b/examples/bloatpad.c
@@ -223,8 +223,8 @@ bloat_pad_startup (GApplication *application)
                                "    </submenu>"
                                "  </menu>"
                                "</interface>", -1, NULL);
-  g_application_set_app_menu (application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  g_application_set_menubar (application, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+  gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   g_object_unref (builder);
 }
 
diff --git a/examples/plugman.c b/examples/plugman.c
index ee49a17..23c034f 100644
--- a/examples/plugman.c
+++ b/examples/plugman.c
@@ -415,8 +415,8 @@ plug_man_startup (GApplication *application)
                                "    </submenu>"
                                "  </menu>"
                                "</interface>", -1, NULL);
-  g_application_set_app_menu (application, G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
-  g_application_set_menubar (application, G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
+  gtk_application_set_app_menu (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "app-menu")));
+  gtk_application_set_menubar (GTK_APPLICATION (application), G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
   g_object_set_data_full (G_OBJECT (application), "plugin-menu", gtk_builder_get_object (builder, "plugins"), g_object_unref);
   g_object_unref (builder);
 }
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index b6fe1b8..17ba543 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -216,8 +216,8 @@ gtk_application_menu_changed_quartz (GObject    *object,
   GMenu *combined;
 
   combined = g_menu_new ();
-  g_menu_append_submenu (combined, "Application", g_application_get_app_menu (G_APPLICATION (object)));
-  g_menu_append_section (combined, NULL, g_application_get_menubar (G_APPLICATION (object)));
+  g_menu_append_submenu (combined, "Application", g_application_get_app_menu (application));
+  g_menu_append_section (combined, NULL, gtk_application_get_menubar (application));
 
   gtk_quartz_set_main_menu (G_MENU_MODEL (combined), G_ACTION_OBSERVABLE (application->priv->muxer));
 }
@@ -748,3 +748,98 @@ gtk_application_remove_accelerator (GtkApplication *application,
   gtk_accel_map_change_entry (accel_path, 0, 0, FALSE);
   g_free (accel_path);
 }
+
+/**
+ * gtk_application_set_app_menu:
+ * @application: a #GtkApplication
+ * @app_menu: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the application menu for @application.
+ *
+ * The application menu is a single menu containing items that typically
+ * impact the application as a whole, rather than acting on a specific
+ * window or document.  For example, you would expect to see
+ * "Preferences" or "Quit" in an application menu, but not "Save" or
+ * "Print".
+ *
+ * If supported, the application menu will be rendered by the desktop
+ * environment.
+ *
+ * Since: 3.4
+ */
+void
+gtk_application_set_app_menu (GtkApplication *application,
+                              GMenuModel     *app_menu)
+{
+  g_object_set (application, "app-menu", app_menu, NULL);
+}
+
+/**
+ * gtk_application_get_app_menu:
+ * @application: a #GtkApplication
+ *
+ * Returns the menu model that has been set with
+ * g_application_set_app_menu().
+ *
+ * Returns: the application menu of @application
+ *
+ * Since: 3.4
+ */
+GMenuModel *
+gtk_application_get_app_menu (GtkApplication *application)
+{
+  GMenuModel *app_menu;
+
+  g_object_get (application, "app-menu", &app_menu, NULL);
+  g_object_unref (app_menu);
+
+  return app_menu;
+}
+
+/**
+ * gtk_application_set_menubar:
+ * @application: a #GtkApplication
+ * @menubar: (allow-none): a #GMenuModel, or %NULL
+ *
+ * Sets or unsets the menubar for windows of @application.
+ *
+ * This is a menubar in the traditional sense.
+ *
+ * Depending on the desktop environment, this may appear at the top of
+ * each window, or at the top of the screen.  In some environments, if
+ * both the application menu and the menubar are set, the application
+ * menu will be presented as if it were the first item of the menubar.
+ * Other environments treat the two as completely separate -- for
+ * example, the application menu may be rendered by the desktop shell
+ * while the menubar (if set) remains in each individual window.
+ *
+ * Since: 3.4
+ */
+void
+gtk_application_set_menubar (GtkApplication *application,
+                             GMenuModel     *menubar)
+{
+  g_object_set (application, "menubar", menubar, NULL);
+}
+
+/**
+ * gtk_application_get_menubar:
+ * @application: a #GtkApplication
+ *
+ * Returns the menu model that has been set with
+ * g_application_set_menubar().
+ *
+ * Returns: the menubar for windows of @application
+ *
+ * Since: 3.4
+ */
+GMenuModel *
+gtk_application_get_menubar (GtkApplication *application)
+{
+  GMenuModel *menubar;
+
+  g_object_get (application, "menubar", &menubar, NULL);
+  g_object_unref (menubar);
+
+  return menubar;
+}
diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h
index a75d66c..2f87bb9 100644
--- a/gtk/gtkapplication.h
+++ b/gtk/gtkapplication.h
@@ -73,9 +73,16 @@ void             gtk_application_add_window    (GtkApplication    *application,
 
 void             gtk_application_remove_window (GtkApplication    *application,
                                                 GtkWindow         *window);
-
 GList *          gtk_application_get_windows   (GtkApplication    *application);
 
+GMenuModel *     gtk_application_get_app_menu  (GtkApplication    *application);
+void             gtk_application_set_app_menu  (GtkApplication    *application,
+                                                GMenuModel        *model);
+
+GMenuModel *     gtk_application_get_menubar   (GtkApplication    *application);
+void             gtk_application_set_menubar   (GtkApplication    *application,
+                                                GMenuModel        *model);
+
 void             gtk_application_add_accelerator    (GtkApplication  *application,
                                                      const gchar     *accelerator,
                                                      const gchar     *action_name,
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 829d959..e11fc6c 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -251,7 +251,7 @@ gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window
         {
           GMenuModel *app_menu;
 
-          app_menu = g_application_get_app_menu (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
+          app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
 
           if (app_menu != NULL)
             g_menu_append_submenu (window->priv->app_menu_section, _("Application"), app_menu);
@@ -280,7 +280,7 @@ gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
         {
           GMenuModel *menubar;
 
-          menubar = g_application_get_menubar (G_APPLICATION (gtk_window_get_application (GTK_WINDOW (window))));
+          menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window)));
 
           if (menubar != NULL)
             g_menu_append_section (window->priv->menubar_section, NULL, menubar);



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