1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 constructing menus and toolbars from an XML description
7 <!-- ##### SECTION Long_Description ##### -->
9 A #GtkUIManager constructs a user interface (menus and toolbars) from
10 one or more UI definitions, which reference actions from one or more
13 <refsect2 id="XML-UI"><title>UI Definitions</title>
15 The UI definitions are specified in an XML format which can be
16 roughly described by the following DTD.
18 <!ELEMENT ui (menubar|toolbar|popup|accelerator)* >
19 <!ELEMENT menubar (menuitem|separator|placeholder|menu)* >
20 <!ELEMENT menu (menuitem|separator|placeholder|menu)* >
21 <!ELEMENT popup (menuitem|separator|placeholder|menu)* >
22 <!ELEMENT toolbar (toolitem|separator|placeholder)* >
23 <!ELEMENT placeholder (menuitem|toolitem|separator|placeholder|menu)* >
24 <!ELEMENT menuitem EMPTY >
25 <!ELEMENT toolitem EMPTY >
26 <!ELEMENT separator EMPTY >
27 <!ELEMENT accelerator EMPTY >
28 <!ATTLIST menubar name #IMPLIED >
29 <!ATTLIST toolbar name #IMPLIED >
30 <!ATTLIST popup name #IMPLIED >
31 <!ATTLIST placeholder name #IMPLIED >
32 <!ATTLIST menu name #IMPLIED
34 position (top|bot) #IMPLIED >
35 <!ATTLIST menuitem name #IMPLIED
37 position (top|bot) #IMPLIED >
38 <!ATTLIST toolitem name #IMPLIED
40 position (top|bot) #IMPLIED >
41 <!ATTLIST accelerator name #IMPLIED
42 action #REQUIRED >
44 There are some additional restrictions beyond those specified in the
45 DTD, e.g. every toolitem must have a toolbar in its anchestry and
46 every menuitem must have a menubar or popup in its anchestry. Since
47 a #GMarkup parser is used to parse the UI description, it must not only
48 be valid XML, but valid #GMarkup. If a name is not specified, it defaults
49 to the action. If an action is not specified either, the element name is
53 <title>A UI definition</title>
57 <menu name="FileMenu" action="FileMenuAction">
58 <menuitem name="New" action="New2Action" />
59 <placeholder name="FileMenuAdditions" />
61 <menu name="JustifyMenu" action="JustifyMenuAction">
62 <menuitem name="Left" action="justify-left"/>
63 <menuitem name="Centre" action="justify-center"/>
64 <menuitem name="Right" action="justify-right"/>
65 <menuitem name="Fill" action="justify-fill"/>
68 <toolbar action="toolbar1">
69 <placeholder name="JustifyToolItems">
71 <toolitem name="Left" action="justify-left"/>
72 <toolitem name="Centre" action="justify-center"/>
73 <toolitem name="Right" action="justify-right"/>
74 <toolitem name="Fill" action="justify-fill"/>
82 The constructed widget hierarchy is very similar to the element tree
83 of the XML, with the exception that placeholders are merged into their
84 parents. The correspondence of XML elements to widgets should be
87 <varlistentry><term>menubar</term>
88 <listitem><para>a #GtkMenuBar</para></listitem>
90 <varlistentry><term>toolbar</term>
91 <listitem><para>a #GtkToolbar</para></listitem>
93 <varlistentry><term>popup</term>
94 <listitem><para>a toplevel #GtkMenu</para></listitem>
96 <varlistentry><term>menu</term>
97 <listitem><para>a #GtkMenu attached to a menuitem</para></listitem>
99 <varlistentry><term>menuitem</term>
100 <listitem><para>a #GtkMenuItem subclass, the exact type depends on the
101 action</para></listitem>
103 <varlistentry><term>toolitem</term>
104 <listitem><para>a #GtkToolItem subclass, the exact type depends on the
105 action</para></listitem>
107 <varlistentry><term>separator</term>
108 <listitem><para>a #GtkSeparatorMenuItem or
109 #GtkSeparatorToolItem</para></listitem>
111 <varlistentry><term>accelerator</term>
112 <listitem><para>a keyboard accelerator</para></listitem>
117 The "position" attribute determines where a constructed widget is positioned
118 wrt. to its siblings in the partially constructed tree. If it is
119 "top", the widget is prepended, otherwise it is appended.
122 <refsect2 id="UI-Merging">
123 <title>UI Merging</title>
125 The most remarkable feature of #GtkUIManager is that it can overlay a set
126 of menuitems and toolitems over another one, and demerge them later.
129 Merging is done based on the name of the XML elements. Each element is
130 identified by a path which consists of the names of its anchestors, separated
131 by slashes. For example, the menuitem named "Left" in the example above
132 has the path <literal>/ui/menubar/JustifyMenu/Left</literal> and the
133 toolitem with the same name has path
134 <literal>/ui/toolbar1/JustifyToolItems/Left</literal>.
138 <title>Accelerators</title>
140 Every action has an accelerator path. Accelerators are installed together with
141 menuitem proxies, but they can also be explicitly added with <accelerator>
142 elements in the UI definition. This makes it possible to have accelerators for
143 actions even if they have no visible proxies.
146 <refsect2 id="Smart-Separators">
147 <title>Smart Separators</title>
149 The separators created by #GtkUIManager are "smart", i.e. they do not show up in the
150 UI unless they end up between two visible menu or tool items. Separators which are located
151 at the very beginning or end of the menu or toolbar containing them, or multiple separators
152 next to each other, are hidden. This is a useful feature, since the merging of UI elements
153 from multiple sources can make it hard or impossible to determine in advance whether a
154 separator will end up in such an unfortunate position.
158 <!-- ##### SECTION See_Also ##### -->
163 <!-- ##### STRUCT GtkUIManager ##### -->
165 The <structname>GtkUIManager</structname> struct contains only private
166 members and should not be accessed directly.
170 <!-- ##### FUNCTION gtk_ui_manager_new ##### -->
178 <!-- ##### FUNCTION gtk_ui_manager_set_add_tearoffs ##### -->
187 <!-- ##### FUNCTION gtk_ui_manager_get_add_tearoffs ##### -->
196 <!-- ##### FUNCTION gtk_ui_manager_insert_action_group ##### -->
206 <!-- ##### FUNCTION gtk_ui_manager_remove_action_group ##### -->
215 <!-- ##### FUNCTION gtk_ui_manager_get_action_groups ##### -->
224 <!-- ##### FUNCTION gtk_ui_manager_get_accel_group ##### -->
233 <!-- ##### FUNCTION gtk_ui_manager_get_widget ##### -->
243 <!-- ##### FUNCTION gtk_ui_manager_get_action ##### -->
253 <!-- ##### FUNCTION gtk_ui_manager_add_ui_from_string ##### -->
265 <!-- ##### FUNCTION gtk_ui_manager_add_ui_from_file ##### -->
276 <!-- ##### FUNCTION gtk_ui_manager_new_merge_id ##### -->
285 <!-- ##### ENUM GtkUIManagerItemType ##### -->
287 These enumeration values are used by gtk_ui_manager_add_ui() to determine
288 what UI element to create.
291 @GTK_UI_MANAGER_AUTO: Pick the type of the UI element according to context.
292 @GTK_UI_MANAGER_MENUBAR: Create a menubar.
293 @GTK_UI_MANAGER_MENU: Create a menu.
294 @GTK_UI_MANAGER_TOOLBAR: Create a toolbar.
295 @GTK_UI_MANAGER_PLACEHOLDER: Insert a placeholder.
296 @GTK_UI_MANAGER_POPUP: Create a popup menu.
297 @GTK_UI_MANAGER_MENUITEM: Create a menuitem.
298 @GTK_UI_MANAGER_TOOLITEM: Create a toolitem.
299 @GTK_UI_MANAGER_SEPARATOR: Create a separator.
300 @GTK_UI_MANAGER_ACCELERATOR: Install an accelerator.
302 <!-- ##### FUNCTION gtk_ui_manager_add_ui ##### -->
316 <!-- ##### FUNCTION gtk_ui_manager_remove_ui ##### -->
325 <!-- ##### FUNCTION gtk_ui_manager_get_ui ##### -->
334 <!-- ##### FUNCTION gtk_ui_manager_ensure_update ##### -->
342 <!-- ##### SIGNAL GtkUIManager::actions-changed ##### -->
347 @uimanager: the object which received the signal.
349 <!-- ##### SIGNAL GtkUIManager::add-widget ##### -->
354 @uimanager: the object which received the signal.
357 <!-- ##### ARG GtkUIManager:add-tearoffs ##### -->
362 <!-- ##### ARG GtkUIManager:ui ##### -->