Gtk.Application_Window.Gtk_Application_Window is a Gtk.Window.Gtk_Window subclass that offers some extra functionality for better integration with Gtk.Application.Gtk_Application features. Notably, it can handle both the application menu as well as the menubar. See Gtk.Application.Set_App_Menu and Gtk.Application.Set_Menubar.
This class implements the Glib.Action_Group.Gaction_Group and Glib.Action_Map.Gaction_Map interfaces, to let you add window-specific actions that will be exported by the associated Gtk.Application.Gtk_Application, 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 Glib.Menu_Model.Gmenu_Model.
Note that widgets that are placed inside a Gtk.Application_Window.Gtk_Application_Window can also activate these actions, if they implement the Gtk.Actionable.Gtk_Actionable interface.
As with Gtk.Application.Gtk_Application, 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).
The settings Gtk.Settings.Gtk_Settings:gtk-shell-shows-app-menu and Gtk.Settings.Gtk_Settings: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 Gtk.Application_Window.Gtk_Application_Window will automatically show a Gtk.Menu_Bar.Gtk_Menu_Bar for it. This behaviour can be overridden with the Gtk.Application_Window.Gtk_Application_Window:show-menubar property. If the desktop environment does not display the application menu, then it will automatically be included in the menubar or in the windows client-side decorations.
## A GtkApplicationWindow with a menubar
GtkApplication *app = gtk_application_new ("org.gtk.test", 0);
GtkBuilder *builder = gtk_builder_new_from_string (
"<interface>"
" <menu id='menubar'>"
" <submenu label='_Edit'>"
" <item label='_Copy' action='win.copy'/>"
" <item label='_Paste' action='win.paste'/>"
" </submenu>"
" </menu>"
"</interface>",
-1);
GMenuModel *menubar = G_MENU_MODEL (gtk_builder_get_object (builder,
"menubar"));
gtk_application_set_menubar (GTK_APPLICATION (app), menubar);
g_object_unref (builder);
// ...
GtkWidget *window = gtk_application_window_new (app);
## Handling fallback yourself
A simple example
The XML format understood by Gtk.Builder.Gtk_Builder for Glib.Menu_Model.Gmenu_Model consists of a toplevel <menu> element, which contains one or more <item> elements. Each <item> element contains <attribute> and <link> elements with a mandatory name attribute. <link> elements have the same content model as <menu>. Instead of <link name="submenu> or <link name="section">, you can use <submenu> or <section> elements.
Attribute values can be translated using gettext, like other Gtk.Builder.Gtk_Builder content. <attribute> elements can be marked for translation with a translatable="yes" attribute. It is also possible to specify message context and translator comments, using the context and comments attributes. To make use of this, the Gtk.Builder.Gtk_Builder must have been given the gettext domain to use.
The following attributes are used when constructing menu items: - "label": a user-visible string to display - "action": the prefixed name of the action to trigger - "target": the parameter to use when activating the action - "icon" and "verb-icon": names of icons that may be displayed - "submenu-action": name of an action that may be used to determine if a submenu can be opened - "hidden-when": a string used to determine when the item will be hidden. Possible values include "action-disabled", "action-missing", "macos-menubar".
The following attributes are used when constructing sections: - "label": a user-visible string to use as section heading - "display-hint": a string used to determine special formatting for the section. Possible values include "horizontal-buttons". - "text-direction": a string used to determine the Gtk.Enums.Gtk_Text_Direction to use when "display-hint" is set to "horizontal-buttons". Possible values include "rtl", "ltr", and "none".
The following attributes are used when constructing submenus: - "label": a user-visible string to display - "icon": icon name to display
function "+"
(Widget : access Gtk_Application_Window_Record'Class)
return Glib.Action_Group.Gaction_Group
function "+"
(Widget : access Gtk_Application_Window_Record'Class)
return Glib.Action_Map.Gaction_Map
function "+"
(Widget : access Gtk_Application_Window_Record'Class)
return Gtk.Buildable.Gtk_Buildable
function "-"
(Interf : Glib.Action_Group.Gaction_Group)
return Gtk_Application_Window
function "-"
(Interf : Glib.Action_Map.Gaction_Map)
return Gtk_Application_Window
function "-"
(Interf : Gtk.Buildable.Gtk_Buildable)
return Gtk_Application_Window
procedure Action_Added
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String)
procedure Action_Enabled_Changed
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String;
Enabled : Boolean)
procedure Action_Removed
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String)
procedure Action_State_Changed
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String;
State : Glib.Variant.Gvariant)
procedure Activate_Action
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String;
Parameter : Glib.Variant.Gvariant)
procedure Add_Action
(Self : not null access Gtk_Application_Window_Record;
Action : Glib.Action.Gaction)
procedure Add_Action_Entries
(Self : not null access Gtk_Application_Window_Record;
Entries : GAction_Entry_Array;
User_Data : System.Address := System.Null_Address)
procedure Change_Action_State
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String;
Value : Glib.Variant.Gvariant)
function Get_Action_Enabled
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Boolean
function Get_Action_Parameter_Type
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type
function Get_Action_State
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Glib.Variant.Gvariant
function Get_Action_State_Hint
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Glib.Variant.Gvariant
function Get_Action_State_Type
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Glib.Variant.Gvariant_Type
function Get_Help_Overlay
(Self : not null access Gtk_Application_Window_Record)
return Gtk.Shortcuts_Window.Gtk_Shortcuts_Window
Gets the Gtk.Shortcuts_Window.Gtk_Shortcuts_Window that has been set up with a prior call to Gtk.Application_Window.Set_Help_Overlay. Since: gtk+ 3.20
the help overlay associated with Window, or null
function Get_Id
(Self : not null access Gtk_Application_Window_Record) return Guint
Returns the unique ID of the window. If the window has not yet been added to a Gtk.Application.Gtk_Application, returns 0. Since: gtk+ 3.6
the unique ID for Window, or 0 if the window has not yet been added to a Gtk.Application.Gtk_Application
function Get_Show_Menubar
(Self : not null access Gtk_Application_Window_Record) return Boolean
Returns whether the window will display a menubar for the app menu and menubar as needed. Since: gtk+ 3.4
True if Window will display a menubar when needed
function Get_Type return Glib.GType
type Gtk_Application_Window is access all Gtk_Application_Window_Record'Class;
function Gtk_Application_Window_New
(Application : not null access Gtk.Application.Gtk_Application_Record'Class)
return Gtk_Application_Window
Creates a new Gtk.Application_Window.Gtk_Application_Window. Since: gtk+ 3.4
a Gtk.Application.Gtk_Application
type Gtk_Application_Window_Record is new Gtk_Window_Record with null record;
procedure Gtk_New
(Self : out Gtk_Application_Window;
Application : not null access Gtk.Application.Gtk_Application_Record'Class)
Creates a new Gtk.Application_Window.Gtk_Application_Window. Since: gtk+ 3.4 Initialize does nothing if the object was already created with another call to Initialize* or G_New.
a Gtk.Application.Gtk_Application
function Has_Action
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Boolean
package Implements_Gaction_Group is new Glib.Types.Implements
(Glib.Action_Group.Gaction_Group, Gtk_Application_Window_Record, Gtk_Application_Window);
package Implements_Gaction_Map is new Glib.Types.Implements
(Glib.Action_Map.Gaction_Map, Gtk_Application_Window_Record, Gtk_Application_Window);
package Implements_Gtk_Buildable is new Glib.Types.Implements
(Gtk.Buildable.Gtk_Buildable, Gtk_Application_Window_Record, Gtk_Application_Window);
procedure Initialize
(Self : not null access Gtk_Application_Window_Record'Class;
Application : not null access Gtk.Application.Gtk_Application_Record'Class)
Creates a new Gtk.Application_Window.Gtk_Application_Window. Since: gtk+ 3.4 Initialize does nothing if the object was already created with another call to Initialize* or G_New.
a Gtk.Application.Gtk_Application
function List_Actions
(Self : not null access Gtk_Application_Window_Record)
return GNAT.Strings.String_List
function Lookup_Action
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String) return Glib.Action.Gaction
function Query_Action
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String;
Enabled : access Boolean;
Parameter_Type : access Glib.Variant.Gvariant_Type;
State_Type : access Glib.Variant.Gvariant_Type;
State_Hint : access Glib.Variant.Gvariant;
State : access Glib.Variant.Gvariant) return Boolean
procedure Remove_Action
(Self : not null access Gtk_Application_Window_Record;
Action_Name : UTF8_String)
procedure Set_Help_Overlay
(Self : not null access Gtk_Application_Window_Record;
Help_Overlay : access Gtk.Shortcuts_Window.Gtk_Shortcuts_Window_Record'Class)
Associates a shortcuts window with the application window, and sets up an action with the name win.show-help-overlay to present it. Window takes resposibility for destroying Help_Overlay. Since: gtk+ 3.20
a Gtk.Shortcuts_Window.Gtk_Shortcuts_Window
procedure Set_Show_Menubar
(Self : not null access Gtk_Application_Window_Record;
Show_Menubar : Boolean)
Sets whether the window will display a menubar for the app menu and menubar as needed. Since: gtk+ 3.4
whether to show a menubar when needed
Show_Menubar_Property : constant Glib.Properties.Property_Boolean;
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.