Menu

A #GtkMenu is a #GtkMenuShell that implements a drop down menu consisting of a list of #GtkMenuItem objects which can be navigated and activated by the user to perform application functions.

A #GtkMenu is most commonly dropped down by activating a #GtkMenuItem in a #GtkMenuBar or popped up by activating a #GtkMenuItem in another #GtkMenu.

A #GtkMenu can also be popped up by activating a #GtkComboBox. Other composite widgets such as the #GtkNotebook can pop up a #GtkMenu as well.

Applications can display a #GtkMenu as a popup menu by calling the gtk_menu_popup() function. The example below shows how an application can pop up a menu when the 3rd mouse button is pressed.

Connecting the popup signal handler.

|[<!-- language="C" --> // connect our handler which will popup the menu g_signal_connect_swapped (window, "button_press_event", G_CALLBACK (my_popup_handler), menu); ]|

Signal handler which displays a popup menu.

|[<!-- language="C" --> static gint my_popup_handler (GtkWidget *widget, GdkEvent *event) { GtkMenu *menu; GdkEventButton *event_button;

g_return_val_if_fail (widget != NULL, FALSE); g_return_val_if_fail (GTK_IS_MENU (widget), FALSE); g_return_val_if_fail (event != NULL, FALSE);

// The "widget" is the menu that was supplied when // g_signal_connect_swapped() was called. menu = GTK_MENU (widget);

if (event->type == GDK_BUTTON_PRESS) { event_button = (GdkEventButton *) event; if (event_button->button == GDK_BUTTON_SECONDARY) { gtk_menu_popup (menu, NULL, NULL, NULL, NULL, event_button->button, event_button->time); return TRUE; } }

return FALSE; } ]|

CSS nodes

|[<!-- language="plain" --> menu ├── arrow.top ├── <child> ┊ ├── <child> ╰── arrow.bottom ]|

The main CSS node of GtkMenu has name menu, and there are two subnodes with name arrow, for scrolling menu arrows. These subnodes get the .top and .bottom style classes.

class Menu : MenuShell {}

Constructors

this
this(GtkMenu* gtkMenu, bool ownedRef)

Sets our main struct and passes it to the parent class.

this
this()

Creates a new #GtkMenu

this
this(MenuModel model)

Creates a #GtkMenu and populates it with menu items and submenus according to @model.

Members

Functions

addOnMoveScroll
void addOnMoveScroll(void delegate(GtkScrollType, Menu) dlg, ConnectFlags connectFlags)
appendSubmenu
Menu appendSubmenu(string label)

Creates and append a submenu to this menu. This menu item that actualy has the sub menu is also created.

appendSubmenu
void appendSubmenu(string label, Menu submenu)
attach
void attach(Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach)

Adds a new #GtkMenuItem to a (table) menu. The number of “cells” that an item will occupy is specified by @left_attach, @right_attach, @top_attach and @bottom_attach. These each represent the leftmost, rightmost, uppermost and lower column and row numbers of the table. (Columns and rows are indexed from zero).

attachToWidget
void attachToWidget(Widget attachWidget, GtkMenuDetachFunc detacher)

Attaches the menu to the widget and provides a callback function that will be invoked when the menu calls gtk_menu_detach() during its destruction.

detach
void detach()

Detaches the menu from the widget to which it had been attached. This function will call the callback function, @detacher, provided when the gtk_menu_attach_to_widget() function was called.

getAccelGroup
AccelGroup getAccelGroup()

Gets the #GtkAccelGroup which holds global accelerators for the menu. See gtk_menu_set_accel_group().

getAccelPath
string getAccelPath()

Retrieves the accelerator path set on the menu.

getActive
Widget getActive()

Returns the selected menu item from the menu. This is used by the #GtkComboBox.

getAttachWidget
Widget getAttachWidget()

Returns the #GtkWidget that the menu is attached to.

getMenuStruct
GtkMenu* getMenuStruct()

Get the main Gtk struct

getMonitor
int getMonitor()

Retrieves the number of the monitor on which to show the menu.

getReserveToggleSize
bool getReserveToggleSize()

Returns whether the menu reserves space for toggles and icons, regardless of their actual presence.

getStruct
void* getStruct()

the main Gtk struct as a void*

getTearoffState
bool getTearoffState()

Returns whether the menu is torn off. See gtk_menu_set_tearoff_state().

getTitle
string getTitle()

Returns the title of the menu. See gtk_menu_set_title().

popdown
void popdown()

Removes the menu from the screen.

popup
void popup(uint button, uint activateTime)

Popups up this menu

popup
void popup(Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, uint button, uint activateTime)

Displays a menu and makes it available for selection.

popupForDevice
void popupForDevice(Device device, Widget parentMenuShell, Widget parentMenuItem, GtkMenuPositionFunc func, void* data, GDestroyNotify destroy, uint button, uint activateTime)

Displays a menu and makes it available for selection.

prependSubmenu
Menu prependSubmenu(string label)
reorderChild
void reorderChild(Widget child, int position)

Moves @child to a new @position in the list of @menu children.

reposition
void reposition()

Repositions the menu according to its position function.

setAccelGroup
void setAccelGroup(AccelGroup accelGroup)

Set the #GtkAccelGroup which holds global accelerators for the menu. This accelerator group needs to also be added to all windows that this menu is being used in with gtk_window_add_accel_group(), in order for those windows to support all the accelerators contained in this group.

setAccelPath
void setAccelPath(string accelPath)

Sets an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed. The main purpose of this function is to spare the programmer the inconvenience of having to call gtk_menu_item_set_accel_path() on each menu item that should support runtime user changable accelerators. Instead, by just calling gtk_menu_set_accel_path() on their parent, each menu item of this menu, that contains a label describing its purpose, automatically gets an accel path assigned.

setActive
void setActive(uint index)

Selects the specified menu item within the menu. This is used by the #GtkComboBox and should not be used by anyone else.

setMonitor
void setMonitor(int monitorNum)

Informs GTK+ on which monitor a menu should be popped up. See gdk_screen_get_monitor_geometry().

setReserveToggleSize
void setReserveToggleSize(bool reserveToggleSize)

Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.

setScreen
void setScreen(Screen screen)

Sets the #GdkScreen on which the menu will be displayed.

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
setTearoffState
void setTearoffState(bool tornOff)

Changes the tearoff state of the menu. A menu is normally displayed as drop down menu which persists as long as the menu is active. It can also be displayed as a tearoff menu which persists until it is closed or reattached.

setTitle
void setTitle(string title)

Sets the title string for the menu.

Static functions

callBackMoveScroll
void callBackMoveScroll(GtkMenu* menuStruct, GtkScrollType scrollType, Menu _menu)
Undocumented in source. Be warned that the author may not have intended to support it.
getForAttachWidget
ListG getForAttachWidget(Widget widget)

Returns a list of the menus which are attached to this widget. This list is owned by GTK+ and must not be modified.

getType
GType getType()

Variables

connectedSignals
int[string] connectedSignals;
Undocumented in source.
gtkMenu
GtkMenu* gtkMenu;

the main Gtk struct

onMoveScrollListeners
void delegate(GtkScrollType, Menu)[] onMoveScrollListeners;
Undocumented in source.

Inherited Members

From MenuShell

gtkMenuShell
GtkMenuShell* gtkMenuShell;

the main Gtk struct

getMenuShellStruct
GtkMenuShell* getMenuShellStruct()

Get the main Gtk struct

getStruct
void* getStruct()

the main Gtk struct as a void*

setStruct
void setStruct(GObject* obj)
Undocumented in source. Be warned that the author may not have intended to support it.
getType
GType getType()
activateItem
void activateItem(Widget menuItem, bool forceDeactivate)

Activates the menu item within the menu shell.

append
void append(MenuItem child)

Adds a new #GtkMenuItem to the end of the menu shell's item list.

bindModel
void bindModel(MenuModel model, string actionNamespace, bool withSeparators)

Establishes a binding between a #GtkMenuShell and a #GMenuModel.

cancel
void cancel()

Cancels the selection within the menu shell.

deactivate
void deactivate()

Deactivates the menu shell.

deselect
void deselect()

Deselects the currently selected item from the menu shell, if any.

getParentShell
Widget getParentShell()

Gets the parent menu shell.

getSelectedItem
Widget getSelectedItem()

Gets the currently selected item.

getTakeFocus
bool getTakeFocus()

Returns %TRUE if the menu shell will take the keyboard focus on popup.

insert
void insert(Widget child, int position)

Adds a new #GtkMenuItem to the menu shell’s item list at the position indicated by @position.

prepend
void prepend(Widget child)

Adds a new #GtkMenuItem to the beginning of the menu shell's item list.

selectFirst
void selectFirst(bool searchSensitive)

Select the first visible or selectable child of the menu shell; don’t select tearoff items unless the only item is a tearoff item.

selectItem
void selectItem(Widget menuItem)

Selects the menu item from the menu shell.

setTakeFocus
void setTakeFocus(bool takeFocus)

If @take_focus is %TRUE (the default) the menu shell will take the keyboard focus so that it will receive all keyboard events which is needed to enable keyboard navigation in menus.

connectedSignals
int[string] connectedSignals;
Undocumented in source.
onActivateCurrentListeners
void delegate(bool, MenuShell)[] onActivateCurrentListeners;
Undocumented in source.
addOnActivateCurrent
void addOnActivateCurrent(void delegate(bool, MenuShell) dlg, ConnectFlags connectFlags)

An action signal that activates the current menu item within the menu shell.

callBackActivateCurrent
void callBackActivateCurrent(GtkMenuShell* menushellStruct, bool forceHide, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onCancelListeners
void delegate(MenuShell)[] onCancelListeners;
Undocumented in source.
addOnCancel
void addOnCancel(void delegate(MenuShell) dlg, ConnectFlags connectFlags)

An action signal which cancels the selection within the menu shell. Causes the #GtkMenuShell::selection-done signal to be emitted.

callBackCancel
void callBackCancel(GtkMenuShell* menushellStruct, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onCycleFocusListeners
void delegate(GtkDirectionType, MenuShell)[] onCycleFocusListeners;
Undocumented in source.
addOnCycleFocus
void addOnCycleFocus(void delegate(GtkDirectionType, MenuShell) dlg, ConnectFlags connectFlags)

A keybinding signal which moves the focus in the given @direction.

callBackCycleFocus
void callBackCycleFocus(GtkMenuShell* menushellStruct, GtkDirectionType direction, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onDeactivateListeners
void delegate(MenuShell)[] onDeactivateListeners;
Undocumented in source.
addOnDeactivate
void addOnDeactivate(void delegate(MenuShell) dlg, ConnectFlags connectFlags)

This signal is emitted when a menu shell is deactivated.

callBackDeactivate
void callBackDeactivate(GtkMenuShell* menushellStruct, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onInsertListeners
void delegate(Widget, int, MenuShell)[] onInsertListeners;
Undocumented in source.
addOnInsert
void addOnInsert(void delegate(Widget, int, MenuShell) dlg, ConnectFlags connectFlags)

The ::insert signal is emitted when a new #GtkMenuItem is added to a #GtkMenuShell. A separate signal is used instead of GtkContainer::add because of the need for an additional position parameter.

callBackInsert
void callBackInsert(GtkMenuShell* menushellStruct, GtkWidget* child, int position, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onMoveCurrentListeners
void delegate(GtkMenuDirectionType, MenuShell)[] onMoveCurrentListeners;
Undocumented in source.
addOnMoveCurrent
void addOnMoveCurrent(void delegate(GtkMenuDirectionType, MenuShell) dlg, ConnectFlags connectFlags)

An keybinding signal which moves the current menu item in the direction specified by @direction.

callBackMoveCurrent
void callBackMoveCurrent(GtkMenuShell* menushellStruct, GtkMenuDirectionType direction, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onMoveSelectedListeners
bool delegate(int, MenuShell)[] onMoveSelectedListeners;
Undocumented in source.
addOnMoveSelected
void addOnMoveSelected(bool delegate(int, MenuShell) dlg, ConnectFlags connectFlags)

The ::move-selected signal is emitted to move the selection to another item.

callBackMoveSelected
int callBackMoveSelected(GtkMenuShell* menushellStruct, int distance, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.
onSelectionDoneListeners
void delegate(MenuShell)[] onSelectionDoneListeners;
Undocumented in source.
addOnSelectionDone
void addOnSelectionDone(void delegate(MenuShell) dlg, ConnectFlags connectFlags)

This signal is emitted when a selection has been completed within a menu shell.

callBackSelectionDone
void callBackSelectionDone(GtkMenuShell* menushellStruct, MenuShell _menushell)
Undocumented in source. Be warned that the author may not have intended to support it.

Meta