[gtk/no-app-menu: 5/5] gtkapplication: Drop app menu support
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/no-app-menu: 5/5] gtkapplication: Drop app menu support
- Date: Thu, 21 May 2020 04:42:07 +0000 (UTC)
commit 19bbb22f278bca6f185020a2902aa48649d76886
Author: Matthias Clasen <mclasen redhat com>
Date: Thu May 21 00:39:15 2020 -0400
gtkapplication: Drop app menu support
Drop apis related to app menus and menubars in
both GtkApplication and GtkApplicationWindow.
Applications that want a menubar can just create
one themselves. OS X integration needs to be
revisited when we have a working OS X backend.
Fixes: #2731
gtk/gtkapplication.c | 299 -----------------------------
gtk/gtkapplication.h | 19 --
gtk/gtkapplicationwindow.c | 468 +--------------------------------------------
gtk/gtkapplicationwindow.h | 6 -
4 files changed, 1 insertion(+), 791 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index f4ca2b1744..e741106ffa 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -143,8 +143,6 @@ enum {
PROP_ZERO,
PROP_REGISTER_SESSION,
PROP_SCREENSAVER_ACTIVE,
- PROP_APP_MENU,
- PROP_MENUBAR,
PROP_ACTIVE_WINDOW,
NUM_PROPERTIES
};
@@ -158,14 +156,11 @@ typedef struct
GList *windows;
- GMenuModel *app_menu;
- GMenuModel *menubar;
guint last_window_id;
gboolean register_session;
gboolean screensaver_active;
GtkActionMuxer *muxer;
- GtkBuilder *menus_builder;
gchar *help_overlay_path;
guint profiler_id;
} GtkApplicationPrivate;
@@ -219,58 +214,6 @@ gtk_application_load_resources (GtkApplication *application)
g_free (iconspath);
}
- /* Load the menus */
- {
- gchar *menuspath;
-
- /* If the user has given a specific file for the variant of menu
- * that we are looking for, use it with preference.
- */
- if (gtk_application_prefers_app_menu (application))
- menuspath = g_strconcat (base_path, "/gtk/menus-appmenu.ui", NULL);
- else
- menuspath = g_strconcat (base_path, "/gtk/menus-traditional.ui", NULL);
-
- if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
- priv->menus_builder = gtk_builder_new_from_resource (menuspath);
- g_free (menuspath);
-
- /* If we didn't get the specific file, fall back. */
- if (priv->menus_builder == NULL)
- {
- menuspath = g_strconcat (base_path, "/gtk/menus.ui", NULL);
- if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
- priv->menus_builder = gtk_builder_new_from_resource (menuspath);
- g_free (menuspath);
- }
-
- /* Always load from -common as well, if we have it */
- menuspath = g_strconcat (base_path, "/gtk/menus-common.ui", NULL);
- if (g_resources_get_info (menuspath, G_RESOURCE_LOOKUP_FLAGS_NONE, NULL, NULL, NULL))
- {
- GError *error = NULL;
-
- if (priv->menus_builder == NULL)
- priv->menus_builder = gtk_builder_new ();
-
- if (!gtk_builder_add_from_resource (priv->menus_builder, menuspath, &error))
- g_error ("failed to load menus-common.ui: %s", error->message);
- }
- g_free (menuspath);
-
- if (priv->menus_builder)
- {
- GObject *menu;
-
- menu = gtk_builder_get_object (priv->menus_builder, "app-menu");
- if (menu != NULL && G_IS_MENU_MODEL (menu))
- gtk_application_set_app_menu (application, G_MENU_MODEL (menu));
- menu = gtk_builder_get_object (priv->menus_builder, "menubar");
- if (menu != NULL && G_IS_MENU_MODEL (menu))
- gtk_application_set_menubar (application, G_MENU_MODEL (menu));
- }
- }
-
/* Help overlay */
{
gchar *path;
@@ -490,14 +433,6 @@ gtk_application_get_property (GObject *object,
g_value_set_boolean (value, priv->screensaver_active);
break;
- case PROP_APP_MENU:
- g_value_set_object (value, gtk_application_get_app_menu (application));
- break;
-
- case PROP_MENUBAR:
- g_value_set_object (value, gtk_application_get_menubar (application));
- break;
-
case PROP_ACTIVE_WINDOW:
g_value_set_object (value, gtk_application_get_active_window (application));
break;
@@ -523,14 +458,6 @@ gtk_application_set_property (GObject *object,
priv->register_session = g_value_get_boolean (value);
break;
- case PROP_APP_MENU:
- gtk_application_set_app_menu (application, g_value_get_object (value));
- break;
-
- case PROP_MENUBAR:
- gtk_application_set_menubar (application, g_value_get_object (value));
- break;
-
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -543,9 +470,6 @@ gtk_application_finalize (GObject *object)
GtkApplication *application = GTK_APPLICATION (object);
GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
- g_clear_object (&priv->menus_builder);
- g_clear_object (&priv->app_menu);
- g_clear_object (&priv->menubar);
g_clear_object (&priv->muxer);
g_clear_object (&priv->accels);
@@ -800,20 +724,6 @@ gtk_application_class_init (GtkApplicationClass *class)
FALSE,
G_PARAM_READABLE|G_PARAM_STATIC_STRINGS);
- gtk_application_props[PROP_APP_MENU] =
- g_param_spec_object ("app-menu",
- P_("Application menu"),
- P_("The GMenuModel for the application menu"),
- G_TYPE_MENU_MODEL,
- G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
-
- gtk_application_props[PROP_MENUBAR] =
- g_param_spec_object ("menubar",
- P_("Menubar"),
- P_("The GMenuModel for the menubar"),
- G_TYPE_MENU_MODEL,
- G_PARAM_READWRITE|G_PARAM_STATIC_STRINGS);
-
gtk_application_props[PROP_ACTIVE_WINDOW] =
g_param_spec_object ("active-window",
P_("Active window"),
@@ -1029,182 +939,6 @@ gtk_application_update_accels (GtkApplication *application)
_gtk_window_notify_keys_changed (l->data);
}
-/**
- * gtk_application_prefers_app_menu:
- * @application: a #GtkApplication
- *
- * Determines if the desktop environment in which the application is
- * running would prefer an application menu be shown.
- *
- * If this function returns %TRUE then the application should call
- * gtk_application_set_app_menu() with the contents of an application
- * menu, which will be shown by the desktop environment. If it returns
- * %FALSE then you should consider using an alternate approach, such as
- * a menubar.
- *
- * The value returned by this function is purely advisory and you are
- * free to ignore it. If you call gtk_application_set_app_menu() even
- * if the desktop environment doesn't support app menus, then a fallback
- * will be provided.
- *
- * Applications are similarly free not to set an app menu even if the
- * desktop environment wants to show one. In that case, a fallback will
- * also be created by the desktop environment (GNOME, for example, uses
- * a menu with only a "Quit" item in it).
- *
- * The value returned by this function never changes. Once it returns a
- * particular value, it is guaranteed to always return the same value.
- *
- * You may only call this function after the application has been
- * registered and after the base startup handler has run. You're most
- * likely to want to use this from your own startup handler. It may
- * also make sense to consult this function while constructing UI (in
- * activate, open or an action activation handler) in order to determine
- * if you should show a gear menu or not.
- *
- * This function will return %FALSE on Mac OS and a default app menu
- * will be created automatically with the "usual" contents of that menu
- * typical to most Mac OS applications. If you call
- * gtk_application_set_app_menu() anyway, then this menu will be
- * replaced with your own.
- *
- * Returns: %TRUE if you should set an app menu
- **/
-gboolean
-gtk_application_prefers_app_menu (GtkApplication *application)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
- g_return_val_if_fail (GTK_IS_APPLICATION (application), FALSE);
- g_return_val_if_fail (priv->impl != NULL, FALSE);
-
- return gtk_application_impl_prefers_app_menu (priv->impl);
-}
-
-/**
- * gtk_application_set_app_menu:
- * @application: a #GtkApplication
- * @app_menu: (allow-none): a #GMenuModel, or %NULL
- *
- * Sets or unsets the application menu for @application.
- *
- * This can only be done in the primary instance of the application,
- * after it has been registered. #GApplication::startup is a good place
- * to call this.
- *
- * 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.
- *
- * Use the base #GActionMap interface to add actions, to respond to the user
- * selecting these menu items.
- */
-void
-gtk_application_set_app_menu (GtkApplication *application,
- GMenuModel *app_menu)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
- g_return_if_fail (GTK_IS_APPLICATION (application));
- g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)));
- g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
- g_return_if_fail (app_menu == NULL || G_IS_MENU_MODEL (app_menu));
-
- if (g_set_object (&priv->app_menu, app_menu))
- {
- gtk_application_impl_set_app_menu (priv->impl, app_menu);
-
- g_object_notify_by_pspec (G_OBJECT (application), gtk_application_props[PROP_APP_MENU]);
- }
-}
-
-/**
- * gtk_application_get_app_menu:
- * @application: a #GtkApplication
- *
- * Returns the menu model that has been set with
- * gtk_application_set_app_menu().
- *
- * Returns: (transfer none) (nullable): the application menu of @application
- * or %NULL if no application menu has been set.
- */
-GMenuModel *
-gtk_application_get_app_menu (GtkApplication *application)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
- g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
-
- return priv->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.
- *
- * This can only be done in the primary instance of the application,
- * after it has been registered. #GApplication::startup is a good place
- * to call this.
- *
- * 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.
- *
- * Use the base #GActionMap interface to add actions, to respond to the
- * user selecting these menu items.
- */
-void
-gtk_application_set_menubar (GtkApplication *application,
- GMenuModel *menubar)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
- g_return_if_fail (GTK_IS_APPLICATION (application));
- g_return_if_fail (g_application_get_is_registered (G_APPLICATION (application)));
- g_return_if_fail (!g_application_get_is_remote (G_APPLICATION (application)));
- g_return_if_fail (menubar == NULL || G_IS_MENU_MODEL (menubar));
-
- if (g_set_object (&priv->menubar, menubar))
- {
- gtk_application_impl_set_menubar (priv->impl, menubar);
-
- g_object_notify_by_pspec (G_OBJECT (application), gtk_application_props[PROP_MENUBAR]);
- }
-}
-
-/**
- * gtk_application_get_menubar:
- * @application: a #GtkApplication
- *
- * Returns the menu model that has been set with
- * gtk_application_set_menubar().
- *
- * Returns: (transfer none): the menubar for windows of @application
- */
-GMenuModel *
-gtk_application_get_menubar (GtkApplication *application)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
-
- g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
-
- return priv->menubar;
-}
-
/**
* GtkApplicationInhibitFlags:
* @GTK_APPLICATION_INHIBIT_LOGOUT: Inhibit ending the user session
@@ -1470,39 +1204,6 @@ gtk_application_handle_window_map (GtkApplication *application,
gtk_application_impl_handle_window_map (priv->impl, window);
}
-/**
- * gtk_application_get_menu_by_id:
- * @application: a #GtkApplication
- * @id: the id of the menu to look up
- *
- * Gets a menu from automatically loaded resources.
- * See [Automatic resources][automatic-resources]
- * for more information.
- *
- * Returns: (transfer none): Gets the menu with the
- * given id from the automatically loaded resources
- */
-GMenu *
-gtk_application_get_menu_by_id (GtkApplication *application,
- const gchar *id)
-{
- GtkApplicationPrivate *priv = gtk_application_get_instance_private (application);
- GObject *object;
-
- g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
- g_return_val_if_fail (id != NULL, NULL);
-
- if (!priv->menus_builder)
- return NULL;
-
- object = gtk_builder_get_object (priv->menus_builder, id);
-
- if (!object || !G_IS_MENU (object))
- return NULL;
-
- return G_MENU (object);
-}
-
void
gtk_application_set_screensaver_active (GtkApplication *application,
gboolean active)
diff --git a/gtk/gtkapplication.h b/gtk/gtkapplication.h
index 9678b6bf38..eb9dda79c4 100644
--- a/gtk/gtkapplication.h
+++ b/gtk/gtkapplication.h
@@ -85,18 +85,6 @@ void gtk_application_remove_window (GtkApplication *application,
GDK_AVAILABLE_IN_ALL
GList * gtk_application_get_windows (GtkApplication *application);
-GDK_AVAILABLE_IN_ALL
-GMenuModel * gtk_application_get_app_menu (GtkApplication *application);
-GDK_AVAILABLE_IN_ALL
-void gtk_application_set_app_menu (GtkApplication *application,
- GMenuModel *app_menu);
-
-GDK_AVAILABLE_IN_ALL
-GMenuModel * gtk_application_get_menubar (GtkApplication *application);
-GDK_AVAILABLE_IN_ALL
-void gtk_application_set_menubar (GtkApplication *application,
- GMenuModel *menubar);
-
typedef enum
{
GTK_APPLICATION_INHIBIT_LOGOUT = (1 << 0),
@@ -137,13 +125,6 @@ void gtk_application_set_accels_for_action (GtkApplication
const gchar *detailed_action_name,
const gchar * const *accels);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_application_prefers_app_menu (GtkApplication *application);
-
-GDK_AVAILABLE_IN_ALL
-GMenu * gtk_application_get_menu_by_id (GtkApplication *application,
- const gchar *id);
-
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkApplication, g_object_unref)
G_END_DECLS
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 9f13ef1799..606949dc88 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -25,7 +25,6 @@
#include "gtkwidgetprivate.h"
#include "gtkwindowprivate.h"
#include "gtkheaderbar.h"
-#include "gtkpopovermenubar.h"
#include "gtkintl.h"
#include "gtksettings.h"
#include "gtkshortcutswindowprivate.h"
@@ -188,11 +187,6 @@ typedef struct _GtkApplicationWindowPrivate GtkApplicationWindowPrivate;
struct _GtkApplicationWindowPrivate
{
GSimpleActionGroup *actions;
- GtkWidget *menubar;
-
- gboolean show_menubar;
- GMenu *app_menu_section;
- GMenu *menubar_section;
guint id;
@@ -207,169 +201,6 @@ G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_GROUP, gtk_application_window_group_iface_init)
G_IMPLEMENT_INTERFACE (G_TYPE_ACTION_MAP, gtk_application_window_map_iface_init))
-static void
-gtk_application_window_update_menubar (GtkApplicationWindow *window)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- gboolean should_have_menubar;
- gboolean have_menubar;
-
- have_menubar = priv->menubar != NULL;
-
- should_have_menubar = priv->show_menubar &&
- (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) ||
- g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)));
-
- if (have_menubar && !should_have_menubar)
- {
- gtk_widget_unparent (priv->menubar);
- priv->menubar = NULL;
- }
-
- if (!have_menubar && should_have_menubar)
- {
- GMenu *combined;
-
- combined = g_menu_new ();
- g_menu_append_section (combined, NULL, G_MENU_MODEL (priv->app_menu_section));
- g_menu_append_section (combined, NULL, G_MENU_MODEL (priv->menubar_section));
-
- priv->menubar = gtk_popover_menu_bar_new_from_model (G_MENU_MODEL (combined));
- gtk_widget_set_parent (priv->menubar, GTK_WIDGET (window));
- g_object_unref (combined);
- }
-}
-
-static gchar *
-gtk_application_window_get_app_desktop_name (void)
-{
- gchar *retval = NULL;
-
-#if defined(HAVE_GIO_UNIX) && !defined(__APPLE__)
- GDesktopAppInfo *app_info;
- const gchar *app_name = NULL;
- gchar *desktop_file;
-
- desktop_file = g_strconcat (g_get_prgname (), ".desktop", NULL);
- app_info = g_desktop_app_info_new (desktop_file);
- g_free (desktop_file);
-
- if (app_info != NULL)
- app_name = g_app_info_get_name (G_APP_INFO (app_info));
-
- if (app_name != NULL)
- retval = g_strdup (app_name);
-
- g_clear_object (&app_info);
-#endif /* HAVE_GIO_UNIX */
-
- return retval;
-}
-
-static void
-gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
- GtkSettings *settings)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- gboolean shown_by_shell;
-
- g_object_get (settings, "gtk-shell-shows-app-menu", &shown_by_shell, NULL);
-
- if (shown_by_shell)
- {
- /* the shell shows it, so don't show it locally */
- if (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) != 0)
- g_menu_remove (priv->app_menu_section, 0);
- }
- else
- {
- /* the shell does not show it, so make sure we show it */
- if (g_menu_model_get_n_items (G_MENU_MODEL (priv->app_menu_section)) == 0)
- {
- GMenuModel *app_menu = NULL;
-
- if (gtk_window_get_application (GTK_WINDOW (window)) != NULL)
- app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
-
- if (app_menu != NULL)
- {
- const gchar *app_name;
- gchar *name;
-
- app_name = g_get_application_name ();
- if (app_name != g_get_prgname ())
- {
- /* the app has set its application name, use it */
- name = g_strdup (app_name);
- }
- else
- {
- /* get the name from .desktop file */
- name = gtk_application_window_get_app_desktop_name ();
- if (name == NULL)
- name = g_strdup (_("Application"));
- }
-
- g_menu_append_submenu (priv->app_menu_section, name, app_menu);
- g_free (name);
- }
- }
- }
-}
-
-static void
-gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
- GtkSettings *settings)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- gboolean shown_by_shell;
-
- g_object_get (settings, "gtk-shell-shows-menubar", &shown_by_shell, NULL);
-
- if (shown_by_shell)
- {
- /* the shell shows it, so don't show it locally */
- if (g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)) != 0)
- g_menu_remove (priv->menubar_section, 0);
- }
- else
- {
- /* the shell does not show it, so make sure we show it */
- if (g_menu_model_get_n_items (G_MENU_MODEL (priv->menubar_section)) == 0)
- {
- GMenuModel *menubar = NULL;
-
- if (gtk_window_get_application (GTK_WINDOW (window)) != NULL)
- menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window)));
-
- if (menubar != NULL)
- g_menu_append_section (priv->menubar_section, NULL, menubar);
- }
- }
-}
-
-static void
-gtk_application_window_shell_shows_app_menu_changed (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- GtkApplicationWindow *window = user_data;
-
- gtk_application_window_update_shell_shows_app_menu (window, GTK_SETTINGS (object));
- gtk_application_window_update_menubar (window);
-}
-
-static void
-gtk_application_window_shell_shows_menubar_changed (GObject *object,
- GParamSpec *pspec,
- gpointer user_data)
-{
- GtkApplicationWindow *window = user_data;
-
- gtk_application_window_update_shell_shows_menubar (window, GTK_SETTINGS (object));
- gtk_application_window_update_menubar (window);
-}
-
static gchar **
gtk_application_window_list_actions (GActionGroup *group)
{
@@ -486,225 +317,11 @@ gtk_application_window_map_iface_init (GActionMapInterface *iface)
iface->remove_action = gtk_application_window_remove_action;
}
-enum {
- PROP_0,
- PROP_SHOW_MENUBAR,
- N_PROPS
-};
-static GParamSpec *gtk_application_window_properties[N_PROPS];
-
-static void
-gtk_application_window_measure (GtkWidget *widget,
- GtkOrientation orientation,
- int for_size,
- int *minimum,
- int *natural,
- int *minimum_baseline,
- int *natural_baseline)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
-
- if (priv->menubar != NULL)
- {
- int menubar_min, menubar_nat;
-
- if (orientation == GTK_ORIENTATION_HORIZONTAL)
- {
- GtkBorder border = {0};
- int menubar_height = 0;
-
- gtk_widget_measure (priv->menubar, GTK_ORIENTATION_VERTICAL,
- for_size, &menubar_height, NULL, NULL, NULL);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
- orientation,
- for_size - menubar_height,
- minimum, natural,
- minimum_baseline,
natural_baseline);
-
-
- gtk_widget_measure (priv->menubar, orientation, menubar_height, &menubar_min, &menubar_nat, NULL,
NULL);
-
- _gtk_window_get_shadow_width (GTK_WINDOW (widget), &border);
- menubar_min += border.left + border.right;
- menubar_nat += border.left + border.right;
-
- *minimum = MAX (*minimum, menubar_min);
- *natural = MAX (*natural, menubar_nat);
-
- }
- else /* VERTICAL */
- {
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline,
natural_baseline);
-
- gtk_widget_measure (priv->menubar, orientation, for_size, &menubar_min, &menubar_nat, NULL, NULL);
- *minimum += menubar_min;
- *natural += menubar_nat;
- }
- }
- else
- {
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->measure (widget,
- orientation,
- for_size,
- minimum, natural,
- minimum_baseline, natural_baseline);
- }
-}
-
-static void
-gtk_application_window_real_size_allocate (GtkWidget *widget,
- int width,
- int height,
- int baseline)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-
- if (priv->menubar != NULL)
- {
- GtkAllocation menubar_allocation;
- GtkAllocation child_allocation;
- gint menubar_height;
- GtkWidget *child;
-
- _gtk_window_set_allocation (GTK_WINDOW (widget), width, height, &child_allocation);
- menubar_allocation = child_allocation;
-
- gtk_widget_measure (priv->menubar, GTK_ORIENTATION_VERTICAL,
- menubar_allocation.width,
- &menubar_height, NULL, NULL, NULL);
-
- menubar_allocation.height = menubar_height;
- gtk_widget_size_allocate (priv->menubar, &menubar_allocation, baseline);
-
- child_allocation.y += menubar_height;
- child_allocation.height -= menubar_height;
- child = gtk_window_get_child (GTK_WINDOW (window));
- if (child != NULL && gtk_widget_get_visible (child))
- gtk_widget_size_allocate (child, &child_allocation, baseline);
- }
- else
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->size_allocate (widget,
- width,
- height,
- baseline);
-}
-
-static void
-gtk_application_window_real_realize (GtkWidget *widget)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
- GtkSettings *settings;
-
- settings = gtk_widget_get_settings (widget);
-
- g_signal_connect (settings, "notify::gtk-shell-shows-app-menu",
- G_CALLBACK (gtk_application_window_shell_shows_app_menu_changed), window);
- g_signal_connect (settings, "notify::gtk-shell-shows-menubar",
- G_CALLBACK (gtk_application_window_shell_shows_menubar_changed), window);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->realize (widget);
-
- gtk_application_window_update_shell_shows_app_menu (window, settings);
- gtk_application_window_update_shell_shows_menubar (window, settings);
- gtk_application_window_update_menubar (window);
-}
-
-static void
-gtk_application_window_real_unrealize (GtkWidget *widget)
-{
- GtkSettings *settings;
-
- settings = gtk_widget_get_settings (widget);
-
- g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_app_menu_changed,
widget);
- g_signal_handlers_disconnect_by_func (settings, gtk_application_window_shell_shows_menubar_changed,
widget);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unrealize (widget);
-}
-
GActionGroup *
gtk_application_window_get_action_group (GtkApplicationWindow *window)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- return G_ACTION_GROUP (priv->actions);
-}
-
-static void
-gtk_application_window_real_map (GtkWidget *widget)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-
- /* XXX could eliminate this by tweaking gtk_window_map */
- if (priv->menubar)
- gtk_widget_map (priv->menubar);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->map (widget);
-}
-
-static void
-gtk_application_window_real_unmap (GtkWidget *widget)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-
- /* XXX could eliminate this by tweaking gtk_window_unmap */
- if (priv->menubar)
- gtk_widget_unmap (priv->menubar);
-
- GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unmap (widget);
-}
-
-static void
-gtk_application_window_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
-
- switch (prop_id)
- {
- case PROP_SHOW_MENUBAR:
- g_value_set_boolean (value, priv->show_menubar);
- break;
-
- default:
- g_assert_not_reached ();
- }
-}
-
-static void
-gtk_application_window_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
-
- switch (prop_id)
- {
- case PROP_SHOW_MENUBAR:
- gtk_application_window_set_show_menubar (window, g_value_get_boolean (value));
- break;
-
- default:
- g_assert_not_reached ();
- }
+ return G_ACTION_GROUP (priv->actions);
}
static void
@@ -713,15 +330,6 @@ gtk_application_window_dispose (GObject *object)
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- if (priv->menubar)
- {
- gtk_widget_unparent (priv->menubar);
- priv->menubar = NULL;
- }
-
- g_clear_object (&priv->app_menu_section);
- g_clear_object (&priv->menubar_section);
-
if (priv->help_overlay)
{
gtk_window_destroy (GTK_WINDOW (priv->help_overlay));
@@ -746,8 +354,6 @@ gtk_application_window_init (GtkApplicationWindow *window)
GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
priv->actions = gtk_application_window_actions_new (window);
- priv->app_menu_section = g_menu_new ();
- priv->menubar_section = g_menu_new ();
gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (priv->actions));
@@ -767,38 +373,9 @@ gtk_application_window_init (GtkApplicationWindow *window)
static void
gtk_application_window_class_init (GtkApplicationWindowClass *class)
{
- GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
GObjectClass *object_class = G_OBJECT_CLASS (class);
- widget_class->measure = gtk_application_window_measure;
- widget_class->size_allocate = gtk_application_window_real_size_allocate;
- widget_class->realize = gtk_application_window_real_realize;
- widget_class->unrealize = gtk_application_window_real_unrealize;
- widget_class->map = gtk_application_window_real_map;
- widget_class->unmap = gtk_application_window_real_unmap;
-
- object_class->get_property = gtk_application_window_get_property;
- object_class->set_property = gtk_application_window_set_property;
object_class->dispose = gtk_application_window_dispose;
-
- /**
- * GtkApplicationWindow:show-menubar:
- *
- * If this property is %TRUE, the window will display a menubar
- * that includes the app menu and menubar, unless these are
- * shown by the desktop shell. See gtk_application_set_app_menu()
- * and gtk_application_set_menubar().
- *
- * If %FALSE, the window will not display a menubar, regardless
- * of whether the desktop shell is showing the menus or not.
- */
- gtk_application_window_properties[PROP_SHOW_MENUBAR] =
- g_param_spec_boolean ("show-menubar",
- P_("Show a menubar"),
- P_("TRUE if the window should show a "
- "menubar at the top of the window"),
- FALSE, G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE |
G_PARAM_EXPLICIT_NOTIFY);
- g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
}
/**
@@ -819,49 +396,6 @@ gtk_application_window_new (GtkApplication *application)
NULL);
}
-/**
- * gtk_application_window_get_show_menubar:
- * @window: a #GtkApplicationWindow
- *
- * Returns whether the window will display a menubar for the app menu
- * and menubar as needed.
- *
- * Returns: %TRUE if @window will display a menubar when needed
- */
-gboolean
-gtk_application_window_get_show_menubar (GtkApplicationWindow *window)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- return priv->show_menubar;
-}
-
-/**
- * gtk_application_window_set_show_menubar:
- * @window: a #GtkApplicationWindow
- * @show_menubar: whether to show a menubar when needed
- *
- * Sets whether the window will display a menubar for the app menu
- * and menubar as needed.
- */
-void
-gtk_application_window_set_show_menubar (GtkApplicationWindow *window,
- gboolean show_menubar)
-{
- GtkApplicationWindowPrivate *priv = gtk_application_window_get_instance_private (window);
- g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
-
- show_menubar = !!show_menubar;
-
- if (priv->show_menubar != show_menubar)
- {
- priv->show_menubar = show_menubar;
-
- gtk_application_window_update_menubar (window);
-
- g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_MENUBAR]);
- }
-}
-
/**
* gtk_application_window_get_id:
* @window: a #GtkApplicationWindow
diff --git a/gtk/gtkapplicationwindow.h b/gtk/gtkapplicationwindow.h
index 294e2f9d5b..23b6de5e83 100644
--- a/gtk/gtkapplicationwindow.h
+++ b/gtk/gtkapplicationwindow.h
@@ -66,12 +66,6 @@ GType gtk_application_window_get_type (void) G_GNUC_CONST;
GDK_AVAILABLE_IN_ALL
GtkWidget * gtk_application_window_new (GtkApplication *application);
-GDK_AVAILABLE_IN_ALL
-void gtk_application_window_set_show_menubar (GtkApplicationWindow *window,
- gboolean show_menubar);
-GDK_AVAILABLE_IN_ALL
-gboolean gtk_application_window_get_show_menubar (GtkApplicationWindow *window);
-
GDK_AVAILABLE_IN_ALL
guint gtk_application_window_get_id (GtkApplicationWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]