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.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.

  // 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.

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

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(void* ptr, Flag!"Take" take)
this
this()

Creates a new #GtkMenu

Members

Functions

attach
void attach(gtk.widget.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).

connectMoveScroll
gulong connectMoveScroll(T callback, Flag!"After" after)

Connect to MoveScroll signal.

connectPoppedUp
gulong connectPoppedUp(T callback, Flag!"After" after)

Connect to PoppedUp signal.

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.Menu.attachToWidget function was called.

getAccelGroup
gtk.accel_group.AccelGroup getAccelGroup()

Gets the #GtkAccelGroup which holds global accelerators for the menu. See gtk.menu.Menu.setAccelGroup.

getAccelPath
string getAccelPath()

Retrieves the accelerator path set on the menu.

getActive
gtk.widget.Widget getActive()

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

getAttachWidget
gtk.widget.Widget getAttachWidget()

Returns the #GtkWidget that the menu is attached to.

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.

getTearoffState
bool getTearoffState()

Returns whether the menu is torn off. See gtk.menu.Menu.setTearoffState.

getTitle
string getTitle()

Returns the title of the menu. See gtk.menu.Menu.setTitle.

placeOnMonitor
void placeOnMonitor(gdk.monitor.MonitorWrap monitor)

Places menu on the given monitor.

popdown
void popdown()

Removes the menu from the screen.

popup
void popup(gtk.widget.Widget parentMenuShell, gtk.widget.Widget parentMenuItem, gtk.types.MenuPositionFunc func, uint button, uint activateTime)

Displays a menu and makes it available for selection.

popupAtPointer
void popupAtPointer(gdk.event.Event triggerEvent)

Displays menu and makes it available for selection.

popupAtRect
void popupAtRect(gdk.window.Window rectWindow, gdk.rectangle.Rectangle rect, gdk.types.Gravity rectAnchor, gdk.types.Gravity menuAnchor, gdk.event.Event triggerEvent)

Displays menu and makes it available for selection.

popupAtWidget
void popupAtWidget(gtk.widget.Widget widget, gdk.types.Gravity widgetAnchor, gdk.types.Gravity menuAnchor, gdk.event.Event triggerEvent)

Displays menu and makes it available for selection.

popupForDevice
void popupForDevice(gdk.device.Device device, gtk.widget.Widget parentMenuShell, gtk.widget.Widget parentMenuItem, gtk.types.MenuPositionFunc func, uint button, uint activateTime)

Displays a menu and makes it available for selection.

reorderChild
void reorderChild(gtk.widget.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.

self
Menu self()

Returns this, for use in with statements.

setAccelGroup
void setAccelGroup(gtk.accel_group.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.Window.addAccelGroup, 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.MenuItem.setAccelPath on each menu item that should support runtime user changable accelerators. Instead, by just calling gtk.menu.Menu.setAccelPath 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.monitor.MonitorWrap.getGeometry.

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(gdk.screen.Screen screen)

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

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.

Properties

_gType
GType _gType [@property getter]
accelGroup
gtk.accel_group.AccelGroup accelGroup [@property getter]

Get accelGroup property.

accelGroup
gtk.accel_group.AccelGroup accelGroup [@property setter]

Set accelGroup property.

accelPath
string accelPath [@property getter]

Get accelPath property.

accelPath
string accelPath [@property setter]

Set accelPath property.

active
int active [@property getter]

Get active property.

active
int active [@property setter]

Set active property.

anchorHints
gdk.types.AnchorHints anchorHints [@property getter]

Get anchorHints property.

anchorHints
gdk.types.AnchorHints anchorHints [@property setter]

Set anchorHints property.

attachWidget
gtk.widget.Widget attachWidget [@property getter]

Get attachWidget property.

attachWidget
gtk.widget.Widget attachWidget [@property setter]

Set attachWidget property.

menuTypeHint
gdk.types.WindowTypeHint menuTypeHint [@property getter]

Get menuTypeHint property.

menuTypeHint
gdk.types.WindowTypeHint menuTypeHint [@property setter]

Set menuTypeHint property.

monitor
int monitor [@property getter]

Get monitor property.

monitor
int monitor [@property setter]

Set monitor property.

rectAnchorDx
int rectAnchorDx [@property getter]

Get rectAnchorDx property.

rectAnchorDx
int rectAnchorDx [@property setter]

Set rectAnchorDx property.

rectAnchorDy
int rectAnchorDy [@property getter]

Get rectAnchorDy property.

rectAnchorDy
int rectAnchorDy [@property setter]

Set rectAnchorDy property.

reserveToggleSize
bool reserveToggleSize [@property getter]

Get reserveToggleSize property.

reserveToggleSize
bool reserveToggleSize [@property setter]

Set reserveToggleSize property.

tearoffState
bool tearoffState [@property getter]

Get tearoffState property.

tearoffState
bool tearoffState [@property setter]

Set tearoffState property.

tearoffTitle
string tearoffTitle [@property getter]

Get tearoffTitle property.

tearoffTitle
string tearoffTitle [@property setter]

Set tearoffTitle property.

Static functions

_getGType
GType _getGType()
builder
MenuGidBuilder builder()

Get builder for gtk.menu.Menu

getForAttachWidget
gtk.widget.Widget[] getForAttachWidget(gtk.widget.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.

newFromModel
gtk.menu.Menu newFromModel(gio.menu_model.MenuModel model)

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

Inherited Members

From MenuShell

_getGType
GType _getGType()
_gType
GType _gType [@property getter]
self
MenuShell self()

Returns this, for use in with statements.

builder
MenuShellGidBuilder builder()

Get builder for gtk.menu_shell.MenuShell

takeFocus
bool takeFocus [@property getter]

Get takeFocus property.

takeFocus
bool takeFocus [@property setter]

Set takeFocus property.

activateItem
void activateItem(gtk.widget.Widget menuItem, bool forceDeactivate)

Activates the menu item within the menu shell.

append
void append(gtk.menu_item.MenuItem child)

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

bindModel
void bindModel(gio.menu_model.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
gtk.widget.Widget getParentShell()

Gets the parent menu shell.

getSelectedItem
gtk.widget.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(gtk.widget.Widget child, int position)

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

prepend
void prepend(gtk.widget.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(gtk.widget.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.

connectActivateCurrent
gulong connectActivateCurrent(T callback, Flag!"After" after)

Connect to ActivateCurrent signal.

connectCancel
gulong connectCancel(T callback, Flag!"After" after)

Connect to Cancel signal.

connectCycleFocus
gulong connectCycleFocus(T callback, Flag!"After" after)

Connect to CycleFocus signal.

connectDeactivate
gulong connectDeactivate(T callback, Flag!"After" after)

Connect to Deactivate signal.

connectInsert
gulong connectInsert(T callback, Flag!"After" after)

Connect to Insert signal.

connectMoveCurrent
gulong connectMoveCurrent(T callback, Flag!"After" after)

Connect to MoveCurrent signal.

connectMoveSelected
gulong connectMoveSelected(T callback, Flag!"After" after)

Connect to MoveSelected signal.

connectSelectionDone
gulong connectSelectionDone(T callback, Flag!"After" after)

Connect to SelectionDone signal.