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.
19
Do not confuse the GtkUIManager UI Definitions described here with
20
the similarly named <link linkend="BUILDER-UI">GtkBuilder UI
24
<programlisting><![CDATA[
25
<!ELEMENT ui (menubar|toolbar|popup|accelerator)* >
26
<!ELEMENT menubar (menuitem|separator|placeholder|menu)* >
27
<!ELEMENT menu (menuitem|separator|placeholder|menu)* >
28
<!ELEMENT popup (menuitem|separator|placeholder|menu)* >
29
<!ELEMENT toolbar (toolitem|separator|placeholder)* >
30
<!ELEMENT placeholder (menuitem|toolitem|separator|placeholder|menu)* >
31
<!ELEMENT menuitem EMPTY >
32
<!ELEMENT toolitem (menu?) >
33
<!ELEMENT separator EMPTY >
34
<!ELEMENT accelerator EMPTY >
35
<!ATTLIST menubar name #IMPLIED
37
<!ATTLIST toolbar name #IMPLIED
39
<!ATTLIST popup name #IMPLIED
41
accelerators (true|false) #IMPLIED >
42
<!ATTLIST placeholder name #IMPLIED
44
<!ATTLIST separator name #IMPLIED
46
expand (true|false) #IMPLIED >
47
<!ATTLIST menu name #IMPLIED
49
position (top|bot) #IMPLIED >
50
<!ATTLIST menuitem name #IMPLIED
52
position (top|bot) #IMPLIED
53
always-show-image (true|false) #IMPLIED >
54
<!ATTLIST toolitem name #IMPLIED
56
position (top|bot) #IMPLIED >
57
<!ATTLIST accelerator name #IMPLIED
58
action #REQUIRED >
60
There are some additional restrictions beyond those specified in the
61
DTD, e.g. every toolitem must have a toolbar in its anchestry and
62
every menuitem must have a menubar or popup in its anchestry. Since
63
a #GMarkup parser is used to parse the UI description, it must not only
64
be valid XML, but valid #GMarkup.
67
If a name is not specified, it defaults to the action. If an action is
68
not specified either, the element name is used. The name and action
69
attributes must not contain '/' characters after parsing (since that
70
would mess up path lookup) and must be usable as XML attributes when
71
enclosed in doublequotes, thus they must not '"' characters or references
72
to the &quot; entity.
75
<title>A UI definition</title>
79
<menu name="FileMenu" action="FileMenuAction">
80
<menuitem name="New" action="New2Action" />
81
<placeholder name="FileMenuAdditions" />
83
<menu name="JustifyMenu" action="JustifyMenuAction">
84
<menuitem name="Left" action="justify-left"/>
85
<menuitem name="Centre" action="justify-center"/>
86
<menuitem name="Right" action="justify-right"/>
87
<menuitem name="Fill" action="justify-fill"/>
90
<toolbar action="toolbar1">
91
<placeholder name="JustifyToolItems">
93
<toolitem name="Left" action="justify-left"/>
94
<toolitem name="Centre" action="justify-center"/>
95
<toolitem name="Right" action="justify-right"/>
96
<toolitem name="Fill" action="justify-fill"/>
104
The constructed widget hierarchy is very similar to the element tree
105
of the XML, with the exception that placeholders are merged into their
106
parents. The correspondence of XML elements to widgets should be
109
<varlistentry><term>menubar</term>
110
<listitem><para>a #GtkMenuBar</para></listitem>
112
<varlistentry><term>toolbar</term>
113
<listitem><para>a #GtkToolbar</para></listitem>
115
<varlistentry><term>popup</term>
116
<listitem><para>a toplevel #GtkMenu</para></listitem>
118
<varlistentry><term>menu</term>
119
<listitem><para>a #GtkMenu attached to a menuitem</para></listitem>
121
<varlistentry><term>menuitem</term>
122
<listitem><para>a #GtkMenuItem subclass, the exact type depends on the
123
action</para></listitem>
125
<varlistentry><term>toolitem</term>
126
<listitem><para>a #GtkToolItem subclass, the exact type depends on the
127
action. Note that toolitem elements may contain a menu element, but only
128
if their associated action specifies a #GtkMenuToolButton as proxy.</para></listitem>
130
<varlistentry><term>separator</term>
131
<listitem><para>a #GtkSeparatorMenuItem or
132
#GtkSeparatorToolItem</para></listitem>
134
<varlistentry><term>accelerator</term>
135
<listitem><para>a keyboard accelerator</para></listitem>
140
The "position" attribute determines where a constructed widget is positioned
141
wrt. to its siblings in the partially constructed tree. If it is
142
"top", the widget is prepended, otherwise it is appended.
145
<refsect2 id="UI-Merging">
146
<title>UI Merging</title>
148
The most remarkable feature of #GtkUIManager is that it can overlay a set
149
of menuitems and toolitems over another one, and demerge them later.
152
Merging is done based on the names of the XML elements. Each element is
153
identified by a path which consists of the names of its anchestors, separated
154
by slashes. For example, the menuitem named "Left" in the example above
155
has the path <literal>/ui/menubar/JustifyMenu/Left</literal> and the
156
toolitem with the same name has path
157
<literal>/ui/toolbar1/JustifyToolItems/Left</literal>.
161
<title>Accelerators</title>
163
Every action has an accelerator path. Accelerators are installed together with
164
menuitem proxies, but they can also be explicitly added with <accelerator>
165
elements in the UI definition. This makes it possible to have accelerators for
166
actions even if they have no visible proxies.
169
<refsect2 id="Smart-Separators">
170
<title>Smart Separators</title>
172
The separators created by #GtkUIManager are "smart", i.e. they do not show up
173
in the UI unless they end up between two visible menu or tool items. Separators
174
which are located at the very beginning or end of the menu or toolbar
175
containing them, or multiple separators next to each other, are hidden. This
176
is a useful feature, since the merging of UI elements from multiple sources
177
can make it hard or impossible to determine in advance whether a separator
178
will end up in such an unfortunate position.
182
For separators in toolbars, you can set <literal>expand="true"</literal> to
183
turn them from a small, visible separator to an expanding, invisible one.
184
Toolitems following an expanding separator are effectively right-aligned.
188
<title>Empty Menus</title>
190
Submenus pose similar problems to separators inconnection with merging. It is
191
impossible to know in advance whether they will end up empty after merging.
192
#GtkUIManager offers two ways to treat empty submenus:
194
<listitem><para>make them disappear by hiding the menu item they're attached to
196
<listitem><para>add an insensitive "Empty" item
199
The behaviour is chosen based on the "hide_if_empty" property of the action
200
to which the submenu is associated.
204
<refsect2 id="GtkUIManager-BUILDER-UI">
205
<title>GtkUIManager as GtkBuildable</title>
207
The GtkUIManager implementation of the GtkBuildable interface accepts
208
GtkActionGroup objects as <child> elements in UI definitions.
211
A GtkUIManager UI definition as described above can be embedded in
212
an GtkUIManager <object> element in a GtkBuilder UI definition.
215
The widgets that are constructed by a GtkUIManager can be embedded in
216
other parts of the constructed user interface with the help of the
217
"constructor" attribute. See the example below.
220
<title>An embedded GtkUIManager UI definition</title>
221
<programlisting><![CDATA[
222
<object class="GtkUIManager" id="uiman">
224
<object class="GtkActionGroup" id="actiongroup">
226
<object class="GtkAction" id="file">
227
<property name="label">_File</property>
233
<menubar name="menubar1">
239
<object class="GtkWindow" id="main-window">
241
<object class="GtkMenuBar" id="menubar1" constructor="uiman"/>
248
<!-- ##### SECTION See_Also ##### -->
253
<!-- ##### SECTION Stability_Level ##### -->
256
<!-- ##### SECTION Image ##### -->
259
<!-- ##### STRUCT GtkUIManager ##### -->
261
The <structname>GtkUIManager</structname> struct contains only private
262
members and should not be accessed directly.
266
<!-- ##### SIGNAL GtkUIManager::actions-changed ##### -->
271
@uimanager: the object which received the signal.
273
<!-- ##### SIGNAL GtkUIManager::add-widget ##### -->
278
@uimanager: the object which received the signal.
281
<!-- ##### SIGNAL GtkUIManager::connect-proxy ##### -->
286
@uimanager: the object which received the signal.
290
<!-- ##### SIGNAL GtkUIManager::disconnect-proxy ##### -->
295
@uimanager: the object which received the signal.
299
<!-- ##### SIGNAL GtkUIManager::post-activate ##### -->
304
@uimanager: the object which received the signal.
307
<!-- ##### SIGNAL GtkUIManager::pre-activate ##### -->
312
@uimanager: the object which received the signal.
315
<!-- ##### ARG GtkUIManager:add-tearoffs ##### -->
320
<!-- ##### ARG GtkUIManager:ui ##### -->
325
<!-- ##### FUNCTION gtk_ui_manager_new ##### -->
334
<!-- ##### FUNCTION gtk_ui_manager_set_add_tearoffs ##### -->
343
<!-- ##### FUNCTION gtk_ui_manager_get_add_tearoffs ##### -->
352
<!-- ##### FUNCTION gtk_ui_manager_insert_action_group ##### -->
362
<!-- ##### FUNCTION gtk_ui_manager_remove_action_group ##### -->
371
<!-- ##### FUNCTION gtk_ui_manager_get_action_groups ##### -->
380
<!-- ##### FUNCTION gtk_ui_manager_get_accel_group ##### -->
389
<!-- ##### FUNCTION gtk_ui_manager_get_widget ##### -->
399
<!-- ##### FUNCTION gtk_ui_manager_get_toplevels ##### -->
409
<!-- ##### FUNCTION gtk_ui_manager_get_action ##### -->
419
<!-- ##### FUNCTION gtk_ui_manager_add_ui_from_string ##### -->
431
<!-- ##### MACRO gtk_ui_manager_add_ui_from_file ##### -->
439
<!-- ##### FUNCTION gtk_ui_manager_new_merge_id ##### -->
448
<!-- ##### ENUM GtkUIManagerItemType ##### -->
450
These enumeration values are used by gtk_ui_manager_add_ui() to determine
451
what UI element to create.
454
@GTK_UI_MANAGER_AUTO: Pick the type of the UI element according to context.
455
@GTK_UI_MANAGER_MENUBAR: Create a menubar.
456
@GTK_UI_MANAGER_MENU: Create a menu.
457
@GTK_UI_MANAGER_TOOLBAR: Create a toolbar.
458
@GTK_UI_MANAGER_PLACEHOLDER: Insert a placeholder.
459
@GTK_UI_MANAGER_POPUP: Create a popup menu.
460
@GTK_UI_MANAGER_MENUITEM: Create a menuitem.
461
@GTK_UI_MANAGER_TOOLITEM: Create a toolitem.
462
@GTK_UI_MANAGER_SEPARATOR: Create a separator.
463
@GTK_UI_MANAGER_ACCELERATOR: Install an accelerator.
464
@GTK_UI_MANAGER_POPUP_WITH_ACCELS: Same as %GTK_UI_MANAGER_POPUP, but the actions' accelerators are shown.
466
<!-- ##### FUNCTION gtk_ui_manager_add_ui ##### -->
480
<!-- ##### FUNCTION gtk_ui_manager_remove_ui ##### -->
489
<!-- ##### FUNCTION gtk_ui_manager_get_ui ##### -->
498
<!-- ##### FUNCTION gtk_ui_manager_ensure_update ##### -->