GtkUIManager

GtkUIManager

Synopsis

#include <gtk/gtk.h>

                    GtkUIManager;
GtkUIManager *      gtk_ui_manager_new                  (void);
void                gtk_ui_manager_set_add_tearoffs     (GtkUIManager *manager,
                                                         gboolean add_tearoffs);
gboolean            gtk_ui_manager_get_add_tearoffs     (GtkUIManager *manager);
void                gtk_ui_manager_insert_action_group  (GtkUIManager *manager,
                                                         GtkActionGroup *action_group,
                                                         gint pos);
void                gtk_ui_manager_remove_action_group  (GtkUIManager *manager,
                                                         GtkActionGroup *action_group);
GList *             gtk_ui_manager_get_action_groups    (GtkUIManager *manager);
GtkAccelGroup *     gtk_ui_manager_get_accel_group      (GtkUIManager *manager);
GtkWidget *         gtk_ui_manager_get_widget           (GtkUIManager *manager,
                                                         const gchar *path);
GSList *            gtk_ui_manager_get_toplevels        (GtkUIManager *manager,
                                                         GtkUIManagerItemType types);
GtkAction *         gtk_ui_manager_get_action           (GtkUIManager *manager,
                                                         const gchar *path);
guint               gtk_ui_manager_add_ui_from_string   (GtkUIManager *manager,
                                                         const gchar *buffer,
                                                         gssize length,
                                                         GError **error);
guint               gtk_ui_manager_add_ui_from_file     (GtkUIManager *manager,
                                                         const gchar *filename,
                                                         GError **error);
guint               gtk_ui_manager_new_merge_id         (GtkUIManager *manager);
enum                GtkUIManagerItemType;
void                gtk_ui_manager_add_ui               (GtkUIManager *manager,
                                                         guint merge_id,
                                                         const gchar *path,
                                                         const gchar *name,
                                                         const gchar *action,
                                                         GtkUIManagerItemType type,
                                                         gboolean top);
void                gtk_ui_manager_remove_ui            (GtkUIManager *manager,
                                                         guint merge_id);
gchar *             gtk_ui_manager_get_ui               (GtkUIManager *manager);
void                gtk_ui_manager_ensure_update        (GtkUIManager *manager);

Description

Details

GtkUIManager

typedef struct {
  GObject parent;
} GtkUIManager;


gtk_ui_manager_new ()

GtkUIManager *      gtk_ui_manager_new                  (void);

Creates a new ui manager object.

Returns :

a new ui manager object.

Since 2.4


gtk_ui_manager_set_add_tearoffs ()

void                gtk_ui_manager_set_add_tearoffs     (GtkUIManager *manager,
                                                         gboolean add_tearoffs);

Sets the "add_tearoffs" property, which controls whether menus generated by this GtkUIManager will have tearoff menu items.

Note that this only affects regular menus. Generated popup menus never have tearoff menu items.

manager :

a GtkUIManager

add_tearoffs :

whether tearoff menu items are added

Since 2.4


gtk_ui_manager_get_add_tearoffs ()

gboolean            gtk_ui_manager_get_add_tearoffs     (GtkUIManager *manager);

Returns whether menus generated by this GtkUIManager will have tearoff menu items.

manager :

a GtkUIManager

Returns :

whether tearoff menu items are added

Since 2.4


gtk_ui_manager_insert_action_group ()

void                gtk_ui_manager_insert_action_group  (GtkUIManager *manager,
                                                         GtkActionGroup *action_group,
                                                         gint pos);

Inserts an action group into the list of action groups associated with manager. Actions in earlier groups hide actions with the same name in later groups.

manager :

a GtkUIManager object

action_group :

the action group to be inserted

pos :

the position at which the group will be inserted.

Since 2.4


gtk_ui_manager_remove_action_group ()

void                gtk_ui_manager_remove_action_group  (GtkUIManager *manager,
                                                         GtkActionGroup *action_group);

Removes an action group from the list of action groups associated with manager.

manager :

a GtkUIManager object

action_group :

the action group to be removed

Since 2.4


gtk_ui_manager_get_action_groups ()

GList *             gtk_ui_manager_get_action_groups    (GtkUIManager *manager);

Returns the list of action groups associated with manager.

manager :

a GtkUIManager object

Returns :

a GList of action groups. The list is owned by GTK+ and should not be modified. [element-type GtkActionGroup][transfer none GtkActionGroup]

Since 2.4


gtk_ui_manager_get_accel_group ()

GtkAccelGroup *     gtk_ui_manager_get_accel_group      (GtkUIManager *manager);

Returns the GtkAccelGroup associated with manager.

manager :

a GtkUIManager object

Returns :

the GtkAccelGroup. [transfer none]

Since 2.4


gtk_ui_manager_get_widget ()

GtkWidget *         gtk_ui_manager_get_widget           (GtkUIManager *manager,
                                                         const gchar *path);

Looks up a widget by following a path. The path consists of the names specified in the XML description of the UI. separated by '/'. Elements which don't have a name or action attribute in the XML (e.g. <popup>) can be addressed by their XML element name (e.g. "popup"). The root element ("/ui") can be omitted in the path.

Note that the widget found by following a path that ends in a <menu> element is the menuitem to which the menu is attached, not the menu itmanager.

Also note that the widgets constructed by a ui manager are not tied to the lifecycle of the ui manager. If you add the widgets returned by this function to some container or explicitly ref them, they will survive the destruction of the ui manager.

manager :

a GtkUIManager

path :

a path

Returns :

the widget found by following the path, or NULL if no widget was found. [transfer none]

Since 2.4


gtk_ui_manager_get_toplevels ()

GSList *            gtk_ui_manager_get_toplevels        (GtkUIManager *manager,
                                                         GtkUIManagerItemType types);

Obtains a list of all toplevel widgets of the requested types.

manager :

a GtkUIManager

types :

specifies the types of toplevel widgets to include. Allowed types are GTK_UI_MANAGER_MENUBAR, GTK_UI_MANAGER_TOOLBAR and GTK_UI_MANAGER_POPUP.

Returns :

a newly-allocated GSList of all toplevel widgets of the requested types. Free the returned list with g_slist_free(). [element-type GtkWidget][transfer container GtkWidget]

Since 2.4


gtk_ui_manager_get_action ()

GtkAction *         gtk_ui_manager_get_action           (GtkUIManager *manager,
                                                         const gchar *path);

Looks up an action by following a path. See gtk_ui_manager_get_widget() for more information about paths.

manager :

a GtkUIManager

path :

a path

Returns :

the action whose proxy widget is found by following the path, or NULL if no widget was found. [transfer none]

Since 2.4


gtk_ui_manager_add_ui_from_string ()

guint               gtk_ui_manager_add_ui_from_string   (GtkUIManager *manager,
                                                         const gchar *buffer,
                                                         gssize length,
                                                         GError **error);

Parses a string containing a UI definition and merges it with the current contents of manager. An enclosing <ui> element is added if it is missing.

manager :

a GtkUIManager object

buffer :

the string to parse

length :

the length of buffer (may be -1 if buffer is nul-terminated)

error :

return location for an error

Returns :

The merge id for the merged UI. The merge id can be used to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred, the return value is 0.

Since 2.4


gtk_ui_manager_add_ui_from_file ()

guint               gtk_ui_manager_add_ui_from_file     (GtkUIManager *manager,
                                                         const gchar *filename,
                                                         GError **error);

Parses a file containing a UI definition and merges it with the current contents of manager.

manager :

a GtkUIManager object

filename :

the name of the file to parse. [type filename]

error :

return location for an error

Returns :

The merge id for the merged UI. The merge id can be used to unmerge the UI with gtk_ui_manager_remove_ui(). If an error occurred, the return value is 0.

Since 2.4


gtk_ui_manager_new_merge_id ()

guint               gtk_ui_manager_new_merge_id         (GtkUIManager *manager);

Returns an unused merge id, suitable for use with gtk_ui_manager_add_ui().

manager :

a GtkUIManager

Returns :

an unused merge id.

Since 2.4


enum GtkUIManagerItemType

typedef enum {
  GTK_UI_MANAGER_AUTO              = 0,
  GTK_UI_MANAGER_MENUBAR           = 1 << 0,
  GTK_UI_MANAGER_MENU              = 1 << 1,
  GTK_UI_MANAGER_TOOLBAR           = 1 << 2,
  GTK_UI_MANAGER_PLACEHOLDER       = 1 << 3,
  GTK_UI_MANAGER_POPUP             = 1 << 4,
  GTK_UI_MANAGER_MENUITEM          = 1 << 5,
  GTK_UI_MANAGER_TOOLITEM          = 1 << 6,
  GTK_UI_MANAGER_SEPARATOR         = 1 << 7,
  GTK_UI_MANAGER_ACCELERATOR       = 1 << 8,
  GTK_UI_MANAGER_POPUP_WITH_ACCELS = 1 << 9
} GtkUIManagerItemType;


gtk_ui_manager_add_ui ()

void                gtk_ui_manager_add_ui               (GtkUIManager *manager,
                                                         guint merge_id,
                                                         const gchar *path,
                                                         const gchar *name,
                                                         const gchar *action,
                                                         GtkUIManagerItemType type,
                                                         gboolean top);

Adds a UI element to the current contents of manager.

If type is GTK_UI_MANAGER_AUTO, GTK+ inserts a menuitem, toolitem or separator if such an element can be inserted at the place determined by path. Otherwise type must indicate an element that can be inserted at the place determined by path.

If path points to a menuitem or toolitem, the new element will be inserted before or after this item, depending on top.

manager :

a GtkUIManager

merge_id :

the merge id for the merged UI, see gtk_ui_manager_new_merge_id()

path :

a path

name :

the name for the added UI element

action :

the name of the action to be proxied, or NULL to add a separator. [allow-none]

type :

the type of UI element to add.

top :

if TRUE, the UI element is added before its siblings, otherwise it is added after its siblings.

Since 2.4


gtk_ui_manager_remove_ui ()

void                gtk_ui_manager_remove_ui            (GtkUIManager *manager,
                                                         guint merge_id);

Unmerges the part of managers content identified by merge_id.

manager :

a GtkUIManager object

merge_id :

a merge id as returned by gtk_ui_manager_add_ui_from_string()

Since 2.4


gtk_ui_manager_get_ui ()

gchar *             gtk_ui_manager_get_ui               (GtkUIManager *manager);

Creates a UI definition of the merged UI.

manager :

a GtkUIManager

Returns :

A newly allocated string containing an XML representation of the merged UI.

Since 2.4


gtk_ui_manager_ensure_update ()

void                gtk_ui_manager_ensure_update        (GtkUIManager *manager);

Makes sure that all pending updates to the UI have been completed.

This may occasionally be necessary, since GtkUIManager updates the UI in an idle function. A typical example where this function is useful is to enforce that the menubar and toolbar have been added to the main window before showing it:

1
2
3
4
5
6
7
gtk_container_add (GTK_CONTAINER (window), vbox); 
g_signal_connect (merge, "add-widget", 
                  G_CALLBACK (add_widget), vbox);
gtk_ui_manager_add_ui_from_file (merge, "my-menus");
gtk_ui_manager_add_ui_from_file (merge, "my-toolbars");
gtk_ui_manager_ensure_update (merge);  
gtk_widget_show (window);

manager :

a GtkUIManager

Since 2.4