2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkUIManager.html
28 * strct = GtkUIManager
55 * - GtkAccelGroup* -> AccelGroup
56 * - GtkAction* -> Action
57 * - GtkActionGroup* -> ActionGroup
58 * - GtkWidget* -> Widget
64 private import gtk
.gtktypes
;
66 private import lib
.gtk
;
68 private import glib
.Str
;
69 private import gtk
.ActionGroup
;
70 private import glib
.ListG
;
71 private import gtk
.AccelGroup
;
72 private import gtk
.Widget
;
73 private import glib
.ListSG
;
74 private import gtk
.Action
;
78 * A GtkUIManager constructs a user interface (menus and toolbars) from
79 * one or more UI definitions, which reference actions from one or more
82 * The UI definitions are specified in an XML format which can be
83 * roughly described by the following DTD.
84 * <!ELEMENT ui (menubar|toolbar|popup|accelerator)* >
85 * <!ELEMENT menubar (menuitem|separator|placeholder|menu)* >
86 * <!ELEMENT menu (menuitem|separator|placeholder|menu)* >
87 * <!ELEMENT popup (menuitem|separator|placeholder|menu)* >
88 * <!ELEMENT toolbar (toolitem|separator|placeholder)* >
89 * <!ELEMENT placeholder (menuitem|toolitem|separator|placeholder|menu)* >
90 * <!ELEMENT menuitem EMPTY >
91 * <!ELEMENT toolitem (menu?) >
92 * <!ELEMENT separator EMPTY >
93 * <!ELEMENT accelerator EMPTY >
94 * <!ATTLIST menubar name #IMPLIED
96 * <!ATTLIST toolbar name #IMPLIED
98 * <!ATTLIST popup name #IMPLIED
100 * <!ATTLIST placeholder name #IMPLIED
102 * <!ATTLIST separator name #IMPLIED
104 * expand (true|false) #IMPLIED >
105 * <!ATTLIST menu name #IMPLIED
107 * position (top|bot) #IMPLIED >
108 * <!ATTLIST menuitem name #IMPLIED
110 * position (top|bot) #IMPLIED >
111 * <!ATTLIST toolitem name #IMPLIED
113 * position (top|bot) #IMPLIED >
114 * <!ATTLIST accelerator name #IMPLIED
116 * There are some additional restrictions beyond those specified in the
117 * DTD, e.g. every toolitem must have a toolbar in its anchestry and
118 * every menuitem must have a menubar or popup in its anchestry. Since
119 * a GMarkup parser is used to parse the UI description, it must not only
120 * be valid XML, but valid GMarkup.
121 * If a name is not specified, it defaults to the action. If an action is
122 * not specified either, the element name is used. The name and action
123 * attributes must not contain '/' characters after parsing (since that
124 * would mess up path lookup) and must be usable as XML attributes when
125 * enclosed in doublequotes, thus they must not '"' characters or references
126 * to the quot; entity.
127 * Example1.A UI definition
130 * <menu name="FileMenu" action="FileMenuAction">
131 * <menuitem name="New" action="New2Action" />
132 * <placeholder name="FileMenuAdditions" />
134 * <menu name="JustifyMenu" action="JustifyMenuAction">
135 * <menuitem name="Left" action="justify-left"/>
136 * <menuitem name="Centre" action="justify-center"/>
137 * <menuitem name="Right" action="justify-right"/>
138 * <menuitem name="Fill" action="justify-fill"/>
141 * <toolbar action="toolbar1">
142 * <placeholder name="JustifyToolItems">
144 * <toolitem name="Left" action="justify-left"/>
145 * <toolitem name="Centre" action="justify-center"/>
146 * <toolitem name="Right" action="justify-right"/>
147 * <toolitem name="Fill" action="justify-fill"/>
152 * The constructed widget hierarchy is very similar to the element tree
153 * of the XML, with the exception that placeholders are merged into their
154 * parents. The correspondence of XML elements to widgets should be
163 * a GtkMenu attached to a menuitem
165 * a GtkMenuItem subclass, the exact type depends on the
168 * a GtkToolItem subclass, the exact type depends on the
169 * action. Note that toolitem elements may contain a menu element, but only
170 * if their associated action specifies a GtkMenuToolButton as proxy.
172 * a GtkSeparatorMenuItem or
173 * GtkSeparatorToolItem
175 * a keyboard accelerator
176 * The "position" attribute determines where a constructed widget is positioned
177 * wrt. to its siblings in the partially constructed tree. If it is
178 * "top", the widget is prepended, otherwise it is appended.
181 * The most remarkable feature of GtkUIManager is that it can overlay a set
182 * of menuitems and toolitems over another one, and demerge them later.
183 * Merging is done based on the names of the XML elements. Each element is
184 * identified by a path which consists of the names of its anchestors, separated
185 * by slashes. For example, the menuitem named "Left" in the example above
186 * has the path /ui/menubar/JustifyMenu/Left and the
187 * toolitem with the same name has path
188 * /ui/toolbar1/JustifyToolItems/Left.
191 * Every action has an accelerator path. Accelerators are installed together with
192 * menuitem proxies, but they can also be explicitly added with <accelerator>
193 * elements in the UI definition. This makes it possible to have accelerators for
194 * actions even if they have no visible proxies.
197 * The separators created by GtkUIManager are "smart", i.e. they do not show up
198 * in the UI unless they end up between two visible menu or tool items. Separators
199 * which are located at the very beginning or end of the menu or toolbar
200 * containing them, or multiple separators next to each other, are hidden. This
201 * is a useful feature, since the merging of UI elements from multiple sources
202 * can make it hard or impossible to determine in advance whether a separator
203 * will end up in such an unfortunate position.
204 * For separators in toolbars, you can set expand="true" to
205 * turn them from a small, visible separator to an expanding, invisible one.
206 * Toolitems following an expanding separator are effectively right-aligned.
209 * Submenus pose similar problems to separators inconnection with merging. It is
210 * impossible to know in advance whether they will end up empty after merging.
211 * GtkUIManager offers two ways to treat empty submenus:
212 * make them disappear by hiding the menu item they're attached to
213 * add an insensitive "Empty" item
214 * The behaviour is chosen based on the "hide_if_empty" property of the action
215 * to which the submenu is associated.
217 private import gobject
.ObjectG
;
218 public class UIManager
: ObjectG
221 /** the main Gtk struct */
222 protected GtkUIManager
* gtkUIManager
;
225 public GtkUIManager
* getUIManagerStruct()
231 /** the main Gtk struct as a void* */
232 protected void* getStruct()
234 return cast(void*)gtkUIManager
;
238 * Sets our main struct and passes it to the parent class
240 public this (GtkUIManager
* gtkUIManager
)
242 super(cast(GObject
*)gtkUIManager
);
243 this.gtkUIManager
= gtkUIManager
;
249 // imports for the signal processing
250 private import gobject
.Signals
;
251 private import gdk
.gdktypes
;
252 int[char[]] connectedSignals
;
254 void delegate(UIManager
)[] onActionsChangedListeners
;
255 void addOnActionsChanged(void delegate(UIManager
) dlg
)
257 if ( !("actions-changed" in connectedSignals
) )
262 cast(GCallback
)&callBackActionsChanged
,
265 cast(ConnectFlags
)0);
266 connectedSignals
["actions-changed"] = 1;
268 onActionsChangedListeners
~= dlg
;
270 extern(C
) static void callBackActionsChanged(GtkUIManager
* mergeStruct
, UIManager uIManager
)
272 bit consumed
= false;
274 foreach ( void delegate(UIManager
) dlg
; uIManager
.onActionsChangedListeners
)
282 void delegate(Widget
, UIManager
)[] onAddWidgetListeners
;
283 void addOnAddWidget(void delegate(Widget
, UIManager
) dlg
)
285 if ( !("add-widget" in connectedSignals
) )
290 cast(GCallback
)&callBackAddWidget
,
293 cast(ConnectFlags
)0);
294 connectedSignals
["add-widget"] = 1;
296 onAddWidgetListeners
~= dlg
;
298 extern(C
) static void callBackAddWidget(GtkUIManager
* mergeStruct
, GtkWidget
* widget
, UIManager uIManager
)
300 bit consumed
= false;
302 foreach ( void delegate(Widget
, UIManager
) dlg
; uIManager
.onAddWidgetListeners
)
304 dlg(new Widget(widget
), uIManager
);
310 void delegate(Action
, Widget
, UIManager
)[] onConnectProxyListeners
;
311 void addOnConnectProxy(void delegate(Action
, Widget
, UIManager
) dlg
)
313 if ( !("connect-proxy" in connectedSignals
) )
318 cast(GCallback
)&callBackConnectProxy
,
321 cast(ConnectFlags
)0);
322 connectedSignals
["connect-proxy"] = 1;
324 onConnectProxyListeners
~= dlg
;
326 extern(C
) static void callBackConnectProxy(GtkUIManager
* uimanagerStruct
, GtkAction
* action
, GtkWidget
* proxy
, UIManager uIManager
)
328 bit consumed
= false;
330 foreach ( void delegate(Action
, Widget
, UIManager
) dlg
; uIManager
.onConnectProxyListeners
)
332 dlg(new Action(action
), new Widget(proxy
), uIManager
);
338 void delegate(Action
, Widget
, UIManager
)[] onDisconnectProxyListeners
;
339 void addOnDisconnectProxy(void delegate(Action
, Widget
, UIManager
) dlg
)
341 if ( !("disconnect-proxy" in connectedSignals
) )
346 cast(GCallback
)&callBackDisconnectProxy
,
349 cast(ConnectFlags
)0);
350 connectedSignals
["disconnect-proxy"] = 1;
352 onDisconnectProxyListeners
~= dlg
;
354 extern(C
) static void callBackDisconnectProxy(GtkUIManager
* uimanagerStruct
, GtkAction
* action
, GtkWidget
* proxy
, UIManager uIManager
)
356 bit consumed
= false;
358 foreach ( void delegate(Action
, Widget
, UIManager
) dlg
; uIManager
.onDisconnectProxyListeners
)
360 dlg(new Action(action
), new Widget(proxy
), uIManager
);
366 void delegate(Action
, UIManager
)[] onPostActivateListeners
;
367 void addOnPostActivate(void delegate(Action
, UIManager
) dlg
)
369 if ( !("post-activate" in connectedSignals
) )
374 cast(GCallback
)&callBackPostActivate
,
377 cast(ConnectFlags
)0);
378 connectedSignals
["post-activate"] = 1;
380 onPostActivateListeners
~= dlg
;
382 extern(C
) static void callBackPostActivate(GtkUIManager
* uimanagerStruct
, GtkAction
* action
, UIManager uIManager
)
384 bit consumed
= false;
386 foreach ( void delegate(Action
, UIManager
) dlg
; uIManager
.onPostActivateListeners
)
388 dlg(new Action(action
), uIManager
);
394 void delegate(Action
, UIManager
)[] onPreActivateListeners
;
395 void addOnPreActivate(void delegate(Action
, UIManager
) dlg
)
397 if ( !("pre-activate" in connectedSignals
) )
402 cast(GCallback
)&callBackPreActivate
,
405 cast(ConnectFlags
)0);
406 connectedSignals
["pre-activate"] = 1;
408 onPreActivateListeners
~= dlg
;
410 extern(C
) static void callBackPreActivate(GtkUIManager
* uimanagerStruct
, GtkAction
* action
, UIManager uIManager
)
412 bit consumed
= false;
414 foreach ( void delegate(Action
, UIManager
) dlg
; uIManager
.onPreActivateListeners
)
416 dlg(new Action(action
), uIManager
);
425 * Creates a new ui manager object.
427 * a new ui manager object.
432 // GtkUIManager* gtk_ui_manager_new (void);
433 this(cast(GtkUIManager
*)gtk_ui_manager_new() );
437 * Sets the "add_tearoffs" property, which controls whether menus
438 * generated by this GtkUIManager will have tearoff menu items.
439 * Note that this only affects regular menus. Generated popup
440 * menus never have tearoff menu items.
444 * whether tearoff menu items are added
447 public void setAddTearoffs(int addTearoffs
)
449 // void gtk_ui_manager_set_add_tearoffs (GtkUIManager *self, gboolean add_tearoffs);
450 gtk_ui_manager_set_add_tearoffs(gtkUIManager
, addTearoffs
);
454 * Returns whether menus generated by this GtkUIManager
455 * will have tearoff menu items.
459 * whether tearoff menu items are added
462 public int getAddTearoffs()
464 // gboolean gtk_ui_manager_get_add_tearoffs (GtkUIManager *self);
465 return gtk_ui_manager_get_add_tearoffs(gtkUIManager
);
469 * Inserts an action group into the list of action groups associated
470 * with self. Actions in earlier groups hide actions with the same
471 * name in later groups.
473 * a GtkUIManager object
475 * the action group to be inserted
477 * the position at which the group will be inserted.
480 public void insertActionGroup(ActionGroup actionGroup
, int pos
)
482 // void gtk_ui_manager_insert_action_group (GtkUIManager *self, GtkActionGroup *action_group, gint pos);
483 gtk_ui_manager_insert_action_group(gtkUIManager
, (actionGroup
is null) ?
null : actionGroup
.getActionGroupStruct(), pos
);
487 * Removes an action group from the list of action groups associated
490 * a GtkUIManager object
492 * the action group to be removed
495 public void removeActionGroup(ActionGroup actionGroup
)
497 // void gtk_ui_manager_remove_action_group (GtkUIManager *self, GtkActionGroup *action_group);
498 gtk_ui_manager_remove_action_group(gtkUIManager
, (actionGroup
is null) ?
null : actionGroup
.getActionGroupStruct());
502 * Returns the list of action groups associated with self.
504 * a GtkUIManager object
506 * a GList of action groups. The list is owned by GTK+
507 * and should not be modified.
510 public ListG
getActionGroups()
512 // GList* gtk_ui_manager_get_action_groups (GtkUIManager *self);
513 return new ListG( gtk_ui_manager_get_action_groups(gtkUIManager
) );
517 * Returns the GtkAccelGroup associated with self.
519 * a GtkUIManager object
524 public AccelGroup
getAccelGroup()
526 // GtkAccelGroup* gtk_ui_manager_get_accel_group (GtkUIManager *self);
527 return new AccelGroup( gtk_ui_manager_get_accel_group(gtkUIManager
) );
531 * Looks up a widget by following a path.
532 * The path consists of the names specified in the XML description of the UI.
533 * separated by '/'. Elements which don't have a name or action attribute in
534 * the XML (e.g. <popup>) can be addressed by their XML element name
535 * (e.g. "popup"). The root element ("/ui") can be omitted in the path.
536 * Note that the widget found by following a path that ends in a <menu>
537 * element is the menuitem to which the menu is attached, not the menu itself.
538 * Also note that the widgets constructed by a ui manager are not tied to
539 * the lifecycle of the ui manager. If you add the widgets returned by this
540 * function to some container or explicitly ref them, they will survive the
541 * destruction of the ui manager.
547 * the widget found by following the path, or NULL if no widget
551 public Widget
getWidget(char[] path
)
553 // GtkWidget* gtk_ui_manager_get_widget (GtkUIManager *self, const gchar *path);
554 return new Widget( gtk_ui_manager_get_widget(gtkUIManager
, Str
.toStringz(path
)) );
558 * Obtains a list of all toplevel widgets of the requested types.
562 * specifies the types of toplevel widgets to include. Allowed
563 * types are GTK_UI_MANAGER_MENUBAR, GTK_UI_MANAGER_TOOLBAR and
564 * GTK_UI_MANAGER_POPUP.
566 * a newly-allocated of all toplevel widgets of the requested
570 public ListSG
getToplevels(GtkUIManagerItemType types
)
572 // GSList* gtk_ui_manager_get_toplevels (GtkUIManager *self, GtkUIManagerItemType types);
573 return new ListSG( gtk_ui_manager_get_toplevels(gtkUIManager
, types
) );
577 * Looks up an action by following a path. See gtk_ui_manager_get_widget()
578 * for more information about paths.
584 * the action whose proxy widget is found by following the path,
585 * or NULL if no widget was found.
588 public Action
getAction(char[] path
)
590 // GtkAction* gtk_ui_manager_get_action (GtkUIManager *self, const gchar *path);
591 return new Action( gtk_ui_manager_get_action(gtkUIManager
, Str
.toStringz(path
)) );
595 * Parses a string containing a UI definition and
596 * merges it with the current contents of self. An enclosing <ui>
597 * element is added if it is missing.
599 * a GtkUIManager object
601 * the string to parse
603 * the length of buffer (may be -1 if buffer is nul-terminated)
605 * return location for an error
607 * The merge id for the merged UI. The merge id can be used
608 * to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
609 * the return value is 0.
612 public uint addUiFromString(char[] buffer
, int length
, GError
** error
)
614 // guint gtk_ui_manager_add_ui_from_string (GtkUIManager *self, const gchar *buffer, gssize length, GError **error);
615 return gtk_ui_manager_add_ui_from_string(gtkUIManager
, Str
.toStringz(buffer
), length
, error
);
619 * Parses a file containing a UI definition and
620 * merges it with the current contents of self.
622 * a GtkUIManager object
624 * the name of the file to parse
626 * return location for an error
628 * The merge id for the merged UI. The merge id can be used
629 * to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred,
630 * the return value is 0.
633 public uint addUiFromFile(char[] filename
, GError
** error
)
635 // guint gtk_ui_manager_add_ui_from_file (GtkUIManager *self, const gchar *filename, GError **error);
636 return gtk_ui_manager_add_ui_from_file(gtkUIManager
, Str
.toStringz(filename
), error
);
640 * Returns an unused merge id, suitable for use with
641 * gtk_ui_manager_add_ui().
645 * an unused merge id.
648 public uint newMergeId()
650 // guint gtk_ui_manager_new_merge_id (GtkUIManager *self);
651 return gtk_ui_manager_new_merge_id(gtkUIManager
);
656 * Adds a UI element to the current contents of self.
657 * If type is GTK_UI_MANAGER_AUTO, GTK+ inserts a menuitem, toolitem or
658 * separator if such an element can be inserted at the place determined by
659 * path. Otherwise type must indicate an element that can be inserted at
660 * the place determined by path.
661 * If path points to a menuitem or toolitem, the new element will be inserted
662 * before or after this item, depending on top.
666 * the merge id for the merged UI, see gtk_ui_manager_new_merge_id()
670 * the name for the added UI element
672 * the name of the action to be proxied, or NULL to add a separator
674 * the type of UI element to add.
676 * if TRUE, the UI element is added before its siblings, otherwise it
677 * is added after its siblings.
680 public void addUi(uint mergeId
, char[] path
, char[] name
, char[] action
, GtkUIManagerItemType type
, int top
)
682 // void gtk_ui_manager_add_ui (GtkUIManager *self, guint merge_id, const gchar *path, const gchar *name, const gchar *action, GtkUIManagerItemType type, gboolean top);
683 gtk_ui_manager_add_ui(gtkUIManager
, mergeId
, Str
.toStringz(path
), Str
.toStringz(name
), Str
.toStringz(action
), type
, top
);
687 * Unmerges the part of selfs content identified by merge_id.
689 * a GtkUIManager object
691 * a merge id as returned by gtk_ui_manager_add_ui_from_string()
694 public void removeUi(uint mergeId
)
696 // void gtk_ui_manager_remove_ui (GtkUIManager *self, guint merge_id);
697 gtk_ui_manager_remove_ui(gtkUIManager
, mergeId
);
701 * Creates a UI definition of the merged UI.
705 * A newly allocated string containing an XML representation of
709 public char[] getUi()
711 // gchar* gtk_ui_manager_get_ui (GtkUIManager *self);
712 return Str
.toString(gtk_ui_manager_get_ui(gtkUIManager
) );
716 * Makes sure that all pending updates to the UI have been completed.
717 * This may occasionally be necessary, since GtkUIManager updates the
718 * UI in an idle function. A typical example where this function is
719 * useful is to enforce that the menubar and toolbar have been added to
720 * the main window before showing it:
721 * gtk_container_add (GTK_CONTAINER (window), vbox);
722 * g_signal_connect (merge, "add_widget",
723 * G_CALLBACK (add_widget), vbox);
724 * gtk_ui_manager_add_ui_from_file (merge, "my-menus");
725 * gtk_ui_manager_add_ui_from_file (merge, "my-toolbars");
726 * gtk_ui_manager_ensure_update (merge);
727 * gtk_widget_show (window);
732 * The "add-tearoffs" property
733 * "add-tearoffs" gboolean : Read / Write
734 * The "add-tearoffs" property controls whether generated menus
735 * have tearoff menu items.
736 * Note that this only affects regular menus. Generated popup
737 * menus never have tearoff menu items.
738 * Default value: FALSE
741 public void ensureUpdate()
743 // void gtk_ui_manager_ensure_update (GtkUIManager *self);
744 gtk_ui_manager_ensure_update(gtkUIManager
);