2011-11-30 14:34:29 +00:00
|
|
|
/*
|
|
|
|
* Copyright © 2011 Canonical Limited
|
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2 of the licence, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2012-02-27 13:01:10 +00:00
|
|
|
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
2011-11-30 14:34:29 +00:00
|
|
|
*
|
|
|
|
* Author: Ryan Lortie <desrt@desrt.ca>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include "gtkapplicationwindow.h"
|
|
|
|
|
2011-12-17 17:28:30 +00:00
|
|
|
#include "gtkapplicationprivate.h"
|
2012-08-18 03:23:51 +00:00
|
|
|
#include "gtkwidgetprivate.h"
|
2012-01-20 06:01:08 +00:00
|
|
|
#include "gtkwindowprivate.h"
|
2013-11-16 06:52:04 +00:00
|
|
|
#include "gtkheaderbar.h"
|
2012-09-11 15:38:06 +00:00
|
|
|
#include "gtkmenubar.h"
|
2011-12-01 04:49:23 +00:00
|
|
|
#include "gtkintl.h"
|
2012-03-03 18:22:22 +00:00
|
|
|
#include "gtksettings.h"
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2012-04-11 14:24:04 +00:00
|
|
|
#ifdef HAVE_GIO_UNIX
|
|
|
|
#include <gio/gdesktopappinfo.h>
|
|
|
|
#endif
|
|
|
|
|
2011-12-01 00:14:48 +00:00
|
|
|
/**
|
|
|
|
* SECTION:gtkapplicationwindow
|
|
|
|
* @title: GtkApplicationWindow
|
|
|
|
* @short_description: GtkWindow subclass with GtkApplication support
|
|
|
|
*
|
2011-12-01 22:47:34 +00:00
|
|
|
* GtkApplicationWindow is a #GtkWindow subclass that offers some
|
|
|
|
* extra functionality for better integration with #GtkApplication
|
|
|
|
* features. Notably, it can handle both the application menu as well
|
2012-01-09 22:30:09 +00:00
|
|
|
* as the menubar. See gtk_application_set_app_menu() and
|
|
|
|
* gtk_application_set_menubar().
|
2011-12-01 22:47:34 +00:00
|
|
|
*
|
|
|
|
* This class implements the #GActionGroup and #GActionMap interfaces,
|
|
|
|
* to let you add window-specific actions that will be exported by the
|
|
|
|
* associated #GtkApplication, together with its application-wide
|
|
|
|
* actions. Window-specific actions are prefixed with the "win."
|
|
|
|
* prefix and application-wide actions are prefixed with the "app."
|
|
|
|
* prefix. Actions must be addressed with the prefixed name when
|
|
|
|
* referring to them from a #GMenuModel.
|
2011-12-01 00:14:48 +00:00
|
|
|
*
|
2012-01-25 03:51:05 +00:00
|
|
|
* Note that widgets that are placed inside a GtkApplicationWindow
|
|
|
|
* can also activate these actions, if they implement the
|
|
|
|
* GtkActionable interface.
|
|
|
|
*
|
2011-12-17 18:17:31 +00:00
|
|
|
* As with #GtkApplication, the GDK lock will be acquired when
|
|
|
|
* processing actions arriving from other processes and should therefore
|
|
|
|
* be held when activating actions locally (if GDK threads are enabled).
|
|
|
|
*
|
2011-12-08 04:55:33 +00:00
|
|
|
* The settings #GtkSettings:gtk-shell-shows-app-menu and
|
|
|
|
* #GtkSettings:gtk-shell-shows-menubar tell GTK+ whether the
|
|
|
|
* desktop environment is showing the application menu and menubar
|
|
|
|
* models outside the application as part of the desktop shell.
|
|
|
|
* For instance, on OS X, both menus will be displayed remotely;
|
|
|
|
* on Windows neither will be. gnome-shell (starting with version 3.4)
|
|
|
|
* will display the application menu, but not the menubar.
|
|
|
|
*
|
|
|
|
* If the desktop environment does not display the menubar, then
|
2012-07-02 06:19:06 +00:00
|
|
|
* #GtkApplicationWindow will automatically show a #GtkMenuBar for it.
|
2011-12-20 19:10:39 +00:00
|
|
|
* (see the #GtkApplication docs for some screenshots of how this
|
|
|
|
* looks on different platforms).
|
2011-12-08 04:55:33 +00:00
|
|
|
* This behaviour can be overridden with the #GtkApplicationWindow:show-menubar
|
|
|
|
* property. If the desktop environment does not display the application
|
2013-11-16 20:00:16 +00:00
|
|
|
* menu, then it will automatically be included in the menubar. It can
|
|
|
|
* also be shown as part of client-side window decorations, e.g. by
|
2013-12-13 05:59:00 +00:00
|
|
|
* using gtk_header_bar_set_show_close_button().
|
2011-12-05 00:16:08 +00:00
|
|
|
*
|
|
|
|
* <example><title>A GtkApplicationWindow with a menubar</title>
|
|
|
|
* <programlisting><![CDATA[
|
|
|
|
* app = gtk_application_new ();
|
|
|
|
*
|
|
|
|
* builder = gtk_builder_new ();
|
|
|
|
* gtk_builder_add_from_string (builder,
|
|
|
|
* "<interface>"
|
|
|
|
* " <menu id='menubar'>"
|
|
|
|
* " <submenu label='_Edit'>"
|
|
|
|
* " <item label='_Copy' action='win.copy'/>"
|
|
|
|
* " <item label='_Paste' action='win.paste'/>"
|
|
|
|
* " </submenu>"
|
|
|
|
* " </menu>"
|
|
|
|
* "</interface>");
|
2012-01-09 22:30:09 +00:00
|
|
|
* gtk_application_set_menubar (G_APPLICATION (app),
|
|
|
|
* G_MENU_MODEL (gtk_builder_get_object (builder, "menubar")));
|
2011-12-05 00:16:08 +00:00
|
|
|
* g_object_unref (builder);
|
|
|
|
*
|
|
|
|
* ...
|
|
|
|
*
|
|
|
|
* window = gtk_application_window_new (app);
|
|
|
|
* ]]>
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
2012-01-26 01:58:55 +00:00
|
|
|
*
|
2012-07-23 01:01:15 +00:00
|
|
|
* <example><title>Handling fallback yourself</title>
|
|
|
|
* <programlisting>
|
|
|
|
* <xi:include xmlns:xi="http://www.w3.org/2001/XInclude" parse="text" href="../../../../examples/sunny.c">
|
|
|
|
* <xi:fallback>FIXME: MISSING XINCLUDE CONTENT</xi:fallback>
|
|
|
|
* </xi:include>
|
|
|
|
* </programlisting>
|
|
|
|
* </example>
|
|
|
|
*
|
2012-01-26 01:58:55 +00:00
|
|
|
* The XML format understood by #GtkBuilder for #GMenuModel consists
|
|
|
|
* of a toplevel <tag class="starttag">menu</tag> element, which contains
|
|
|
|
* one or more <tag class="starttag">item</tag> elements. Each
|
|
|
|
* <tag class="starttag">item</tag> element contains
|
|
|
|
* <tag class="starttag">attribute</tag> and <tag class="starttag">link</tag>
|
|
|
|
* elements with a mandatory name attribute.
|
|
|
|
* <tag class="starttag">link</tag> elements have the same content
|
|
|
|
* model as <tag class="starttag">menu</tag>.
|
|
|
|
*
|
|
|
|
* Attribute values can be translated using gettext, like other #GtkBuilder
|
|
|
|
* content. <tag class="starttag">attribute</tag> elements can be marked for
|
|
|
|
* translation with a <literal>translatable="yes"</literal> attribute.
|
|
|
|
* It is also possible to specify message context and translator comments,
|
|
|
|
* using the context and comments attributes. To make use of this, the
|
|
|
|
* #GtkBuilder must have been given the gettext domain to use.
|
2011-12-01 00:14:48 +00:00
|
|
|
*/
|
2011-12-17 17:50:02 +00:00
|
|
|
|
|
|
|
typedef GSimpleActionGroupClass GtkApplicationWindowActionsClass;
|
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
GSimpleActionGroup parent_instance;
|
|
|
|
GtkWindow *window;
|
|
|
|
} GtkApplicationWindowActions;
|
|
|
|
|
|
|
|
static GType gtk_application_window_actions_get_type (void);
|
|
|
|
static void gtk_application_window_actions_iface_init (GRemoteActionGroupInterface *iface);
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindowActions, gtk_application_window_actions, G_TYPE_SIMPLE_ACTION_GROUP,
|
|
|
|
G_IMPLEMENT_INTERFACE (G_TYPE_REMOTE_ACTION_GROUP, gtk_application_window_actions_iface_init))
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_activate_action_full (GRemoteActionGroup *remote,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *parameter,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions = (GtkApplicationWindowActions *) remote;
|
|
|
|
GApplication *application;
|
|
|
|
GApplicationClass *class;
|
|
|
|
|
|
|
|
application = G_APPLICATION (gtk_window_get_application (actions->window));
|
|
|
|
class = G_APPLICATION_GET_CLASS (application);
|
|
|
|
|
|
|
|
class->before_emit (application, platform_data);
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (actions), action_name, parameter);
|
|
|
|
class->after_emit (application, platform_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_change_action_state_full (GRemoteActionGroup *remote,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *value,
|
|
|
|
GVariant *platform_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions = (GtkApplicationWindowActions *) remote;
|
|
|
|
GApplication *application;
|
|
|
|
GApplicationClass *class;
|
|
|
|
|
|
|
|
application = G_APPLICATION (gtk_window_get_application (actions->window));
|
|
|
|
class = G_APPLICATION_GET_CLASS (application);
|
|
|
|
|
|
|
|
class->before_emit (application, platform_data);
|
|
|
|
g_action_group_change_action_state (G_ACTION_GROUP (actions), action_name, value);
|
|
|
|
class->after_emit (application, platform_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_init (GtkApplicationWindowActions *actions)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_iface_init (GRemoteActionGroupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->activate_action_full = gtk_application_window_actions_activate_action_full;
|
|
|
|
iface->change_action_state_full = gtk_application_window_actions_change_action_state_full;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_actions_class_init (GtkApplicationWindowActionsClass *class)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
static GSimpleActionGroup *
|
|
|
|
gtk_application_window_actions_new (GtkApplicationWindow *window)
|
|
|
|
{
|
|
|
|
GtkApplicationWindowActions *actions;
|
|
|
|
|
|
|
|
actions = g_object_new (gtk_application_window_actions_get_type (), NULL);
|
|
|
|
actions->window = GTK_WINDOW (window);
|
|
|
|
|
|
|
|
return G_SIMPLE_ACTION_GROUP (actions);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Now onto GtkApplicationWindow... */
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
struct _GtkApplicationWindowPrivate
|
|
|
|
{
|
2011-11-30 16:51:41 +00:00
|
|
|
GSimpleActionGroup *actions;
|
2011-12-02 03:01:07 +00:00
|
|
|
GtkWidget *menubar;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-09-22 03:37:48 +00:00
|
|
|
gboolean show_menubar;
|
2011-12-02 03:01:07 +00:00
|
|
|
GMenu *app_menu_section;
|
|
|
|
GMenu *menubar_section;
|
2011-12-17 17:28:30 +00:00
|
|
|
|
2012-04-20 17:29:11 +00:00
|
|
|
guint id;
|
2011-11-30 14:34:29 +00:00
|
|
|
};
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_update_menubar (GtkApplicationWindow *window)
|
|
|
|
{
|
|
|
|
gboolean should_have_menubar;
|
|
|
|
gboolean have_menubar;
|
|
|
|
|
|
|
|
have_menubar = window->priv->menubar != NULL;
|
|
|
|
|
|
|
|
should_have_menubar = window->priv->show_menubar &&
|
|
|
|
(g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) ||
|
|
|
|
g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)));
|
|
|
|
|
|
|
|
if (have_menubar && !should_have_menubar)
|
|
|
|
{
|
|
|
|
gtk_widget_unparent (window->priv->menubar);
|
|
|
|
window->priv->menubar = NULL;
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (window));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!have_menubar && should_have_menubar)
|
|
|
|
{
|
|
|
|
GMenu *combined;
|
|
|
|
|
|
|
|
combined = g_menu_new ();
|
|
|
|
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->app_menu_section));
|
|
|
|
g_menu_append_section (combined, NULL, G_MENU_MODEL (window->priv->menubar_section));
|
|
|
|
|
2012-09-11 15:38:06 +00:00
|
|
|
window->priv->menubar = gtk_menu_bar_new_from_model (G_MENU_MODEL (combined));
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_set_parent (window->priv->menubar, GTK_WIDGET (window));
|
|
|
|
gtk_widget_show_all (window->priv->menubar);
|
|
|
|
g_object_unref (combined);
|
|
|
|
|
|
|
|
gtk_widget_queue_resize (GTK_WIDGET (window));
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 20:41:43 +00:00
|
|
|
|
2012-04-14 18:30:26 +00:00
|
|
|
static gchar *
|
2012-04-20 03:41:53 +00:00
|
|
|
gtk_application_window_get_app_desktop_name (void)
|
2012-04-14 18:30:26 +00:00
|
|
|
{
|
|
|
|
gchar *retval = NULL;
|
|
|
|
|
|
|
|
#ifdef HAVE_GIO_UNIX
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:41:43 +00:00
|
|
|
static void
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_app_menu (GtkApplicationWindow *window,
|
|
|
|
GtkSettings *settings)
|
2011-11-30 20:41:43 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
gboolean shown_by_shell;
|
2013-11-16 06:52:04 +00:00
|
|
|
gboolean shown_by_titlebar;
|
2011-11-30 20:41:43 +00:00
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
g_object_get (settings, "gtk-shell-shows-app-menu", &shown_by_shell, NULL);
|
2011-12-02 03:01:07 +00:00
|
|
|
|
2013-11-16 19:46:10 +00:00
|
|
|
shown_by_titlebar = _gtk_window_titlebar_shows_app_menu (GTK_WINDOW (window));
|
2013-11-16 06:52:04 +00:00
|
|
|
|
|
|
|
if (shown_by_shell || shown_by_titlebar)
|
2011-12-02 03:01:07 +00:00
|
|
|
{
|
|
|
|
/* the shell shows it, so don't show it locally */
|
|
|
|
if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->app_menu_section)) != 0)
|
|
|
|
g_menu_remove (window->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 (window->priv->app_menu_section)) == 0)
|
|
|
|
{
|
|
|
|
GMenuModel *app_menu;
|
|
|
|
|
2011-12-19 17:33:21 +00:00
|
|
|
app_menu = gtk_application_get_app_menu (gtk_window_get_application (GTK_WINDOW (window)));
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (app_menu != NULL)
|
2012-01-21 01:06:25 +00:00
|
|
|
{
|
2012-04-14 18:30:26 +00:00
|
|
|
const gchar *app_name;
|
|
|
|
gchar *name;
|
2012-01-21 01:06:25 +00:00
|
|
|
|
2012-04-14 18:30:26 +00:00
|
|
|
app_name = g_get_application_name ();
|
|
|
|
if (app_name != g_get_prgname ())
|
2012-04-11 14:24:04 +00:00
|
|
|
{
|
2012-04-14 18:30:26 +00:00
|
|
|
/* the app has set its application name, use it */
|
|
|
|
name = g_strdup (app_name);
|
2012-04-11 14:24:04 +00:00
|
|
|
}
|
2012-04-14 18:30:26 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* get the name from .desktop file */
|
|
|
|
name = gtk_application_window_get_app_desktop_name ();
|
|
|
|
if (name == NULL)
|
|
|
|
name = g_strdup (_("Application"));
|
|
|
|
}
|
|
|
|
|
2012-01-21 01:06:25 +00:00
|
|
|
g_menu_append_submenu (window->priv->app_menu_section, name, app_menu);
|
2012-04-14 18:30:26 +00:00
|
|
|
g_free (name);
|
2012-01-21 01:06:25 +00:00
|
|
|
}
|
2011-12-02 03:01:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_menubar (GtkApplicationWindow *window,
|
|
|
|
GtkSettings *settings)
|
2011-12-02 03:01:07 +00:00
|
|
|
{
|
|
|
|
gboolean shown_by_shell;
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
g_object_get (settings, "gtk-shell-shows-menubar", &shown_by_shell, NULL);
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (shown_by_shell)
|
|
|
|
{
|
|
|
|
/* the shell shows it, so don't show it locally */
|
|
|
|
if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) != 0)
|
|
|
|
g_menu_remove (window->priv->menubar_section, 0);
|
|
|
|
}
|
|
|
|
else
|
2011-12-01 22:47:34 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
/* the shell does not show it, so make sure we show it */
|
|
|
|
if (g_menu_model_get_n_items (G_MENU_MODEL (window->priv->menubar_section)) == 0)
|
|
|
|
{
|
|
|
|
GMenuModel *menubar;
|
|
|
|
|
2011-12-19 17:33:21 +00:00
|
|
|
menubar = gtk_application_get_menubar (gtk_window_get_application (GTK_WINDOW (window)));
|
2011-12-02 03:01:07 +00:00
|
|
|
|
|
|
|
if (menubar != NULL)
|
|
|
|
g_menu_append_section (window->priv->menubar_section, NULL, menubar);
|
|
|
|
}
|
2011-12-01 22:47:34 +00:00
|
|
|
}
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_shell_shows_app_menu_changed (GObject *object,
|
|
|
|
GParamSpec *pspec,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = user_data;
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_app_menu (window, GTK_SETTINGS (object));
|
2011-12-02 03:01:07 +00:00
|
|
|
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;
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_menubar (window, GTK_SETTINGS (object));
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_application_window_update_menubar (window);
|
|
|
|
}
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
static gchar **
|
|
|
|
gtk_application_window_list_actions (GActionGroup *group)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
/* may be NULL after dispose has run */
|
|
|
|
if (!window->priv->actions)
|
|
|
|
return g_new0 (char *, 0 + 1);
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
return g_action_group_list_actions (G_ACTION_GROUP (window->priv->actions));
|
|
|
|
}
|
|
|
|
|
|
|
|
static gboolean
|
|
|
|
gtk_application_window_query_action (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
gboolean *enabled,
|
|
|
|
const GVariantType **parameter_type,
|
|
|
|
const GVariantType **state_type,
|
|
|
|
GVariant **state_hint,
|
|
|
|
GVariant **state)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return FALSE;
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
return g_action_group_query_action (G_ACTION_GROUP (window->priv->actions),
|
|
|
|
action_name, enabled, parameter_type, state_type, state_hint, state);
|
|
|
|
}
|
|
|
|
|
2011-11-30 17:06:40 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_activate_action (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *parameter)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_action_group_activate_action (G_ACTION_GROUP (window->priv->actions), action_name, parameter);
|
2011-11-30 17:06:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_change_action_state (GActionGroup *group,
|
|
|
|
const gchar *action_name,
|
|
|
|
GVariant *state)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (group);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return;
|
|
|
|
|
|
|
|
g_action_group_change_action_state (G_ACTION_GROUP (window->priv->actions), action_name, state);
|
2011-11-30 17:06:40 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
static GAction *
|
2011-12-01 05:21:11 +00:00
|
|
|
gtk_application_window_lookup_action (GActionMap *action_map,
|
2011-11-30 16:51:41 +00:00
|
|
|
const gchar *action_name)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return NULL;
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
return g_action_map_lookup_action (G_ACTION_MAP (window->priv->actions), action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_add_action (GActionMap *action_map,
|
|
|
|
GAction *action)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return;
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
g_action_map_add_action (G_ACTION_MAP (window->priv->actions), action);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_remove_action (GActionMap *action_map,
|
|
|
|
const gchar *action_name)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (action_map);
|
|
|
|
|
2013-12-16 17:25:54 +00:00
|
|
|
if (!window->priv->actions)
|
|
|
|
return;
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
g_action_map_remove_action (G_ACTION_MAP (window->priv->actions), action_name);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_group_iface_init (GActionGroupInterface *iface)
|
|
|
|
{
|
|
|
|
iface->list_actions = gtk_application_window_list_actions;
|
|
|
|
iface->query_action = gtk_application_window_query_action;
|
2011-11-30 17:06:40 +00:00
|
|
|
iface->activate_action = gtk_application_window_activate_action;
|
|
|
|
iface->change_action_state = gtk_application_window_change_action_state;
|
2011-11-30 16:51:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_map_iface_init (GActionMapInterface *iface)
|
|
|
|
{
|
|
|
|
iface->lookup_action = gtk_application_window_lookup_action;
|
|
|
|
iface->add_action = gtk_application_window_add_action;
|
|
|
|
iface->remove_action = gtk_application_window_remove_action;
|
|
|
|
}
|
|
|
|
|
|
|
|
G_DEFINE_TYPE_WITH_CODE (GtkApplicationWindow, gtk_application_window, GTK_TYPE_WINDOW,
|
2013-06-27 19:02:52 +00:00
|
|
|
G_ADD_PRIVATE (GtkApplicationWindow)
|
2011-11-30 16:51:41 +00:00
|
|
|
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))
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
enum {
|
|
|
|
PROP_0,
|
2011-12-01 22:47:34 +00:00
|
|
|
PROP_SHOW_MENUBAR,
|
2011-11-30 14:34:29 +00:00
|
|
|
N_PROPS
|
|
|
|
};
|
|
|
|
static GParamSpec *gtk_application_window_properties[N_PROPS];
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_get_preferred_height (GtkWidget *widget,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)
|
|
|
|
->get_preferred_height (widget, minimum_height, natural_height);
|
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
{
|
|
|
|
gint menubar_min_height, menubar_nat_height;
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_get_preferred_height (window->priv->menubar, &menubar_min_height, &menubar_nat_height);
|
2011-11-30 14:34:29 +00:00
|
|
|
*minimum_height += menubar_min_height;
|
|
|
|
*natural_height += menubar_nat_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_get_preferred_height_for_width (GtkWidget *widget,
|
|
|
|
gint width,
|
|
|
|
gint *minimum_height,
|
|
|
|
gint *natural_height)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)
|
|
|
|
->get_preferred_height_for_width (widget, width, minimum_height, natural_height);
|
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
{
|
|
|
|
gint menubar_min_height, menubar_nat_height;
|
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_get_preferred_height_for_width (window->priv->menubar, width, &menubar_min_height, &menubar_nat_height);
|
2011-11-30 14:34:29 +00:00
|
|
|
*minimum_height += menubar_min_height;
|
|
|
|
*natural_height += menubar_nat_height;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_get_preferred_width (GtkWidget *widget,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)
|
|
|
|
->get_preferred_width (widget, minimum_width, natural_width);
|
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
{
|
|
|
|
gint menubar_min_width, menubar_nat_width;
|
2013-11-16 19:49:21 +00:00
|
|
|
gint border_width;
|
|
|
|
GtkBorder border = { 0 };
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_get_preferred_width (window->priv->menubar, &menubar_min_width, &menubar_nat_width);
|
2013-11-16 19:49:21 +00:00
|
|
|
|
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
|
|
|
_gtk_window_get_decoration_size (GTK_WINDOW (widget), &border);
|
|
|
|
|
|
|
|
menubar_min_width += 2 * border_width + border.left + border.right;
|
|
|
|
menubar_nat_width += 2 * border_width + border.left + border.right;
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
*minimum_width = MAX (*minimum_width, menubar_min_width);
|
|
|
|
*natural_width = MAX (*natural_width, menubar_nat_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_get_preferred_width_for_height (GtkWidget *widget,
|
|
|
|
gint height,
|
|
|
|
gint *minimum_width,
|
|
|
|
gint *natural_width)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2012-01-14 18:26:09 +00:00
|
|
|
gint menubar_height;
|
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
gtk_widget_get_preferred_height (window->priv->menubar, &menubar_height, NULL);
|
|
|
|
else
|
|
|
|
menubar_height = 0;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)
|
2012-01-14 18:26:09 +00:00
|
|
|
->get_preferred_width_for_height (widget, height - menubar_height, minimum_width, natural_width);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
{
|
|
|
|
gint menubar_min_width, menubar_nat_width;
|
2013-11-16 19:49:21 +00:00
|
|
|
gint border_width;
|
|
|
|
GtkBorder border = { 0 };
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2012-01-14 18:26:09 +00:00
|
|
|
gtk_widget_get_preferred_width_for_height (window->priv->menubar, menubar_height, &menubar_min_width, &menubar_nat_width);
|
2013-11-16 19:49:21 +00:00
|
|
|
|
|
|
|
border_width = gtk_container_get_border_width (GTK_CONTAINER (widget));
|
|
|
|
_gtk_window_get_decoration_size (GTK_WINDOW (widget), &border);
|
|
|
|
|
|
|
|
menubar_min_width += 2 * border_width + border.left + border.right;
|
|
|
|
menubar_nat_width += 2 * border_width + border.left + border.right;
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
*minimum_width = MAX (*minimum_width, menubar_min_width);
|
|
|
|
*natural_width = MAX (*natural_width, menubar_nat_width);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_size_allocate (GtkWidget *widget,
|
|
|
|
GtkAllocation *allocation)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
|
|
|
|
|
|
|
if (window->priv->menubar != NULL)
|
|
|
|
{
|
2013-02-26 19:33:04 +00:00
|
|
|
GtkAllocation menubar_allocation;
|
|
|
|
GtkAllocation child_allocation;
|
2012-01-14 18:23:02 +00:00
|
|
|
gint menubar_height;
|
2011-11-30 14:34:29 +00:00
|
|
|
GtkWidget *child;
|
|
|
|
|
2013-02-26 19:33:04 +00:00
|
|
|
_gtk_window_set_allocation (GTK_WINDOW (widget), allocation, &child_allocation);
|
|
|
|
menubar_allocation = child_allocation;
|
2012-01-15 00:48:40 +00:00
|
|
|
|
2013-02-26 19:33:04 +00:00
|
|
|
gtk_widget_get_preferred_height_for_width (window->priv->menubar,
|
|
|
|
menubar_allocation.width,
|
|
|
|
&menubar_height, NULL);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2012-01-14 18:23:02 +00:00
|
|
|
menubar_allocation.height = menubar_height;
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_size_allocate (window->priv->menubar, &menubar_allocation);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-11-13 02:01:29 +00:00
|
|
|
child_allocation.y += menubar_height;
|
|
|
|
child_allocation.height -= menubar_height;
|
2011-11-30 14:34:29 +00:00
|
|
|
child = gtk_bin_get_child (GTK_BIN (window));
|
|
|
|
if (child != NULL && gtk_widget_get_visible (child))
|
2013-11-13 02:01:29 +00:00
|
|
|
gtk_widget_size_allocate (child, &child_allocation);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)
|
|
|
|
->size_allocate (widget, allocation);
|
|
|
|
}
|
|
|
|
|
2011-11-30 20:41:43 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_realize (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
2011-12-03 19:55:03 +00:00
|
|
|
GtkSettings *settings;
|
2011-11-30 20:41:43 +00:00
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
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);
|
|
|
|
|
2013-11-16 19:46:10 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->realize (widget);
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
gtk_application_window_update_shell_shows_app_menu (window, settings);
|
|
|
|
gtk_application_window_update_shell_shows_menubar (window, settings);
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_application_window_update_menubar (window);
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-03 19:55:03 +00:00
|
|
|
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);
|
|
|
|
|
2013-11-16 19:46:10 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->unrealize (widget);
|
2011-12-03 19:55:03 +00:00
|
|
|
}
|
|
|
|
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
GActionGroup *
|
|
|
|
gtk_application_window_get_action_group (GtkApplicationWindow *window)
|
2011-12-17 17:28:30 +00:00
|
|
|
{
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
return G_ACTION_GROUP (window->priv->actions);
|
2011-12-17 17:28:30 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 14:34:29 +00:00
|
|
|
static void
|
|
|
|
gtk_application_window_real_map (GtkWidget *widget)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (widget);
|
|
|
|
|
2011-12-01 04:53:39 +00:00
|
|
|
/* XXX could eliminate this by tweaking gtk_window_map */
|
2011-11-30 14:34:29 +00:00
|
|
|
if (window->priv->menubar)
|
2011-12-02 03:01:07 +00:00
|
|
|
gtk_widget_map (window->priv->menubar);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2013-11-19 21:24:57 +00:00
|
|
|
GTK_WIDGET_CLASS (gtk_application_window_parent_class)->map (widget);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_real_forall_internal (GtkContainer *container,
|
|
|
|
gboolean include_internal,
|
|
|
|
GtkCallback callback,
|
|
|
|
gpointer user_data)
|
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (container);
|
|
|
|
|
|
|
|
if (window->priv->menubar)
|
2011-12-02 03:01:07 +00:00
|
|
|
callback (window->priv->menubar, user_data);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
GTK_CONTAINER_CLASS (gtk_application_window_parent_class)
|
|
|
|
->forall (container, include_internal, callback, user_data);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 04:59:32 +00:00
|
|
|
gtk_application_window_get_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-12-01 22:47:34 +00:00
|
|
|
case PROP_SHOW_MENUBAR:
|
2011-12-02 03:01:07 +00:00
|
|
|
g_value_set_boolean (value, window->priv->show_menubar);
|
2011-11-30 14:34:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-12-01 04:59:32 +00:00
|
|
|
gtk_application_window_set_property (GObject *object,
|
|
|
|
guint prop_id,
|
|
|
|
const GValue *value,
|
|
|
|
GParamSpec *pspec)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
|
|
|
|
|
|
|
switch (prop_id)
|
|
|
|
{
|
2011-12-01 22:47:34 +00:00
|
|
|
case PROP_SHOW_MENUBAR:
|
|
|
|
gtk_application_window_set_show_menubar (window, g_value_get_boolean (value));
|
2011-11-30 14:34:29 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
g_assert_not_reached ();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2011-11-30 20:55:31 +00:00
|
|
|
gtk_application_window_dispose (GObject *object)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
|
|
|
GtkApplicationWindow *window = GTK_APPLICATION_WINDOW (object);
|
|
|
|
|
2011-12-02 03:13:56 +00:00
|
|
|
if (window->priv->menubar)
|
|
|
|
{
|
|
|
|
gtk_widget_unparent (window->priv->menubar);
|
|
|
|
window->priv->menubar = NULL;
|
|
|
|
}
|
2011-12-02 03:14:57 +00:00
|
|
|
|
|
|
|
g_clear_object (&window->priv->app_menu_section);
|
|
|
|
g_clear_object (&window->priv->menubar_section);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
|
|
|
G_OBJECT_CLASS (gtk_application_window_parent_class)
|
2011-11-30 20:55:31 +00:00
|
|
|
->dispose (object);
|
2013-12-16 17:25:54 +00:00
|
|
|
|
|
|
|
/* We do this below the chain-up above to give us a chance to be
|
|
|
|
* removed from the GtkApplication (which is done in the dispose
|
|
|
|
* handler of GtkWindow).
|
|
|
|
*
|
|
|
|
* That reduces our chances of being watched as a GActionGroup from a
|
|
|
|
* muxer constructed by GtkApplication. Even still, it's
|
|
|
|
* theoretically possible that someone else could be watching us.
|
|
|
|
* Therefore, we have to take care to ensure that we don't violate our
|
|
|
|
* obligations under the interface of GActionGroup.
|
|
|
|
*
|
|
|
|
* The easiest thing is just for us to act as if all of the actions
|
|
|
|
* suddenly disappeared.
|
|
|
|
*/
|
|
|
|
if (window->priv->actions)
|
|
|
|
{
|
|
|
|
gchar **action_names;
|
|
|
|
guint signal;
|
|
|
|
gint i;
|
|
|
|
|
|
|
|
/* Only send the remove signals if someone is listening */
|
|
|
|
signal = g_signal_lookup ("action-removed", G_TYPE_ACTION_GROUP);
|
|
|
|
if (signal && g_signal_has_handler_pending (window, signal, 0, TRUE))
|
|
|
|
/* need to send a removed signal for each action */
|
|
|
|
action_names = g_action_group_list_actions (G_ACTION_GROUP (window->priv->actions));
|
|
|
|
else
|
|
|
|
/* don't need to send signals: nobody is watching */
|
|
|
|
action_names = NULL;
|
|
|
|
|
|
|
|
/* Free the group before sending the signals for two reasons:
|
|
|
|
*
|
|
|
|
* 1) we want any incoming calls to see an empty group
|
|
|
|
*
|
|
|
|
* 2) we don't want signal handlers that trigger in response to
|
|
|
|
* the action-removed signals that we're firing to attempt to
|
|
|
|
* modify the action group in a way that may cause it to fire
|
|
|
|
* additional signals (which we would then propagate)
|
|
|
|
*/
|
|
|
|
g_object_unref (window->priv->actions);
|
|
|
|
window->priv->actions = NULL;
|
|
|
|
|
|
|
|
/* It's safe to send the signals now, if we need to. */
|
|
|
|
if (action_names)
|
|
|
|
{
|
|
|
|
for (i = 0; action_names[i]; i++)
|
|
|
|
g_action_group_action_removed (G_ACTION_GROUP (window), action_names[i]);
|
|
|
|
|
|
|
|
g_strfreev (action_names);
|
|
|
|
}
|
|
|
|
}
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_init (GtkApplicationWindow *window)
|
|
|
|
{
|
2013-06-27 19:02:52 +00:00
|
|
|
window->priv = gtk_application_window_get_instance_private (window);
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2011-12-17 17:50:02 +00:00
|
|
|
window->priv->actions = gtk_application_window_actions_new (window);
|
2011-12-02 03:01:07 +00:00
|
|
|
window->priv->app_menu_section = g_menu_new ();
|
|
|
|
window->priv->menubar_section = g_menu_new ();
|
2011-11-30 16:51:41 +00:00
|
|
|
|
2012-08-17 22:21:59 +00:00
|
|
|
gtk_widget_insert_action_group (GTK_WIDGET (window), "win", G_ACTION_GROUP (window->priv->actions));
|
|
|
|
|
2011-11-30 16:51:41 +00:00
|
|
|
/* window->priv->actions is the one and only ref on the group, so when
|
2011-11-30 20:55:31 +00:00
|
|
|
* we dispose, the action group will die, disconnecting all signals.
|
2011-11-30 16:51:41 +00:00
|
|
|
*/
|
|
|
|
g_signal_connect_swapped (window->priv->actions, "action-added",
|
|
|
|
G_CALLBACK (g_action_group_action_added), window);
|
|
|
|
g_signal_connect_swapped (window->priv->actions, "action-enabled-changed",
|
|
|
|
G_CALLBACK (g_action_group_action_enabled_changed), window);
|
|
|
|
g_signal_connect_swapped (window->priv->actions, "action-state-changed",
|
|
|
|
G_CALLBACK (g_action_group_action_state_changed), window);
|
|
|
|
g_signal_connect_swapped (window->priv->actions, "action-removed",
|
|
|
|
G_CALLBACK (g_action_group_action_removed), window);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
gtk_application_window_class_init (GtkApplicationWindowClass *class)
|
|
|
|
{
|
|
|
|
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (class);
|
|
|
|
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
|
|
|
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
|
|
|
|
|
|
|
container_class->forall = gtk_application_window_real_forall_internal;
|
|
|
|
widget_class->get_preferred_height = gtk_application_window_real_get_preferred_height;
|
|
|
|
widget_class->get_preferred_height_for_width = gtk_application_window_real_get_preferred_height_for_width;
|
|
|
|
widget_class->get_preferred_width = gtk_application_window_real_get_preferred_width;
|
|
|
|
widget_class->get_preferred_width_for_height = gtk_application_window_real_get_preferred_width_for_height;
|
|
|
|
widget_class->size_allocate = gtk_application_window_real_size_allocate;
|
2011-11-30 20:41:43 +00:00
|
|
|
widget_class->realize = gtk_application_window_real_realize;
|
2011-12-03 19:55:03 +00:00
|
|
|
widget_class->unrealize = gtk_application_window_real_unrealize;
|
2011-11-30 14:34:29 +00:00
|
|
|
widget_class->map = gtk_application_window_real_map;
|
|
|
|
object_class->get_property = gtk_application_window_get_property;
|
|
|
|
object_class->set_property = gtk_application_window_set_property;
|
2011-11-30 20:55:31 +00:00
|
|
|
object_class->dispose = gtk_application_window_dispose;
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
|
|
|
* GtkApplicationWindow:show-menubar:
|
|
|
|
*
|
|
|
|
* If this property is %TRUE, the window will display a menubar
|
|
|
|
* that includes the app menu and menubar, unless these are
|
2012-01-09 22:30:09 +00:00
|
|
|
* shown by the desktop shell. See gtk_application_set_app_menu()
|
|
|
|
* and gtk_application_set_menubar().
|
2011-12-04 23:40:19 +00:00
|
|
|
*
|
|
|
|
* If %FALSE, the window will not display a menubar, regardless
|
|
|
|
* of whether the desktop shell is showing the menus or not.
|
|
|
|
*/
|
2011-12-01 22:47:34 +00:00
|
|
|
gtk_application_window_properties[PROP_SHOW_MENUBAR] =
|
|
|
|
g_param_spec_boolean ("show-menubar",
|
|
|
|
P_("Show a menubar"),
|
2011-12-04 23:40:19 +00:00
|
|
|
P_("TRUE if the window should show a "
|
|
|
|
"menubar at the top of the window"),
|
2011-12-02 03:01:07 +00:00
|
|
|
TRUE, G_PARAM_CONSTRUCT | G_PARAM_STATIC_STRINGS | G_PARAM_READWRITE);
|
2011-11-30 14:34:29 +00:00
|
|
|
g_object_class_install_properties (object_class, N_PROPS, gtk_application_window_properties);
|
|
|
|
}
|
|
|
|
|
2011-12-01 04:59:32 +00:00
|
|
|
/**
|
|
|
|
* gtk_application_window_new:
|
|
|
|
* @application: a #GtkApplication
|
|
|
|
*
|
|
|
|
* Creates a new #GtkApplicationWindow.
|
|
|
|
*
|
|
|
|
* Returns: a newly created #GtkApplicationWindow
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
2011-11-30 14:34:29 +00:00
|
|
|
GtkWidget *
|
|
|
|
gtk_application_window_new (GtkApplication *application)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION (application), NULL);
|
|
|
|
|
|
|
|
return g_object_new (GTK_TYPE_APPLICATION_WINDOW,
|
|
|
|
"application", application,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
2011-11-30 14:34:29 +00:00
|
|
|
gboolean
|
2011-12-01 22:47:34 +00:00
|
|
|
gtk_application_window_get_show_menubar (GtkApplicationWindow *window)
|
2011-11-30 14:34:29 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
return window->priv->show_menubar;
|
2011-11-30 20:41:43 +00:00
|
|
|
}
|
|
|
|
|
2011-12-04 23:40:19 +00:00
|
|
|
/**
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
* Since: 3.4
|
|
|
|
*/
|
2011-12-02 03:01:07 +00:00
|
|
|
void
|
|
|
|
gtk_application_window_set_show_menubar (GtkApplicationWindow *window,
|
|
|
|
gboolean show_menubar)
|
2011-11-30 20:41:43 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
|
2011-12-01 22:47:34 +00:00
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
show_menubar = !!show_menubar;
|
2011-12-01 22:47:34 +00:00
|
|
|
|
2011-12-02 03:01:07 +00:00
|
|
|
if (window->priv->show_menubar != show_menubar)
|
2011-11-30 20:41:43 +00:00
|
|
|
{
|
2011-12-02 03:01:07 +00:00
|
|
|
window->priv->show_menubar = show_menubar;
|
|
|
|
|
|
|
|
gtk_application_window_update_menubar (window);
|
2011-11-30 14:34:29 +00:00
|
|
|
|
2011-12-01 22:47:34 +00:00
|
|
|
g_object_notify_by_pspec (G_OBJECT (window), gtk_application_window_properties[PROP_SHOW_MENUBAR]);
|
2011-11-30 14:34:29 +00:00
|
|
|
}
|
|
|
|
}
|
2012-01-06 03:22:06 +00:00
|
|
|
|
2012-04-20 17:29:11 +00:00
|
|
|
/**
|
|
|
|
* gtk_application_window_get_id:
|
|
|
|
* @window: a #GtkApplicationWindow
|
|
|
|
*
|
|
|
|
* Returns the unique ID of the window. If the window has not yet been added to
|
|
|
|
* a #GtkApplication, returns <literal>0</literal>.
|
|
|
|
*
|
|
|
|
* Returns: the unique ID for @window, or <literal>0</literal> if the window
|
|
|
|
* has not yet been added to a #GtkApplication
|
|
|
|
*
|
|
|
|
* Since: 3.6
|
|
|
|
*/
|
|
|
|
guint
|
|
|
|
gtk_application_window_get_id (GtkApplicationWindow *window)
|
|
|
|
{
|
|
|
|
g_return_val_if_fail (GTK_IS_APPLICATION_WINDOW (window), 0);
|
|
|
|
|
|
|
|
return window->priv->id;
|
|
|
|
}
|
Refactor GtkApplication
gtkapplication.c has turned into a bit of an #ifdef mess over time, and
many of the current checks are incorrect. As an example, if you build
Gtk for wayland, and exclude the X11 backend, much of the functionality
required by wayland (such as exporting menu models) will be disabled.
Solve that by introducing a backend mechanism to GtkApplication (named
GtkApplicationImpl) similar to the one in GApplication. Add backends
for Wayland, X11 and Quartz, with X11 and Wayland sharing a common
'DBus' superclass.
GtkApplicationImpl
|
/--------------+-------------------\
| |
GtkApplicationImplDBus GtkApplicationImplQuartz
|
/-----------+-----------------\
| |
GtkApplicationImplX11 GtkApplicationImplWayland
GtkApplicationImpl itself is essentially a bunch of vfuncs that serve as
hooks for various things that the platform-specific backends may be
interested in doing (startup, shutdown, managing windows, inhibit, etc.)
With this change, all platform specific code has been removed from
gtkapplication.c and gtkapplicationwindow.c (both of which are now free
of #ifdefs, except for a UNIX-specific use of GDesktopAppInfo in
gtkapplicationwindow.c).
Additionally, because of the movement of the property-setting code out
of GtkApplicationWindow, the _GTK_APPLICATION_ID properties (and
friends) will be set on non-GtkApplicationWindows, such as dialogs.
https://bugzilla.gnome.org/show_bug.cgi?id=720550
2013-12-16 14:32:13 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
gtk_application_window_set_id (GtkApplicationWindow *window,
|
|
|
|
guint id)
|
|
|
|
{
|
|
|
|
g_return_if_fail (GTK_IS_APPLICATION_WINDOW (window));
|
|
|
|
window->priv->id = id;
|
|
|
|
}
|