gtk.menu

Module for [Menu] class

Types 3

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.

Methods
GType _getGType() static nothrow
GType _gType() @property nothrow
Menu self() nothrowReturns `this`, for use in `with` statements.
MenuGidBuilder builder() static nothrowGet builder for [gtk.menu.Menu] Returns: New builder object
gtk.accel_group.AccelGroup accelGroup() @property nothrowGet `accelGroup` property. Returns: The accel group holding accelerators for the menu.
void accelGroup(gtk.accel_group.AccelGroup propval) @property nothrowSet `accelGroup` property. Params: propval = The accel group holding accelerators for the menu.
string accelPath() @property nothrowGet `accelPath` property. Returns: An accel path used to conveniently construct accel paths of child items.
void accelPath(string propval) @property nothrowSet `accelPath` property. Params: propval = An accel path used to conveniently construct accel paths of child items.
int active() @property nothrowGet `active` property. Returns: The index of the currently selected menu item, or -1 if no menu item is selected.
void active(int propval) @property nothrowSet `active` property. Params: propval = The index of the currently selected menu item, or -1 if no menu item is selected.
gdk.types.AnchorHints anchorHints() @property nothrowGet `anchorHints` property. Returns: Positioning hints for aligning the menu relative to a rectangle.
void anchorHints(gdk.types.AnchorHints propval) @property nothrowSet `anchorHints` property. Params: propval = Positioning hints for aligning the menu relative to a rectangle.
gtk.widget.Widget attachWidget() @property nothrowGet `attachWidget` property. Returns: The widget the menu is attached to. Setting this property attaches the menu without a #GtkMenuDetachFunc. If you need to use a detacher, use [gtk.menu.Menu.att...
void attachWidget(gtk.widget.Widget propval) @property nothrowSet `attachWidget` property. Params: propval = The widget the menu is attached to. Setting this property attaches the menu without a #GtkMenuDetachFunc. If you need to use a detacher, use [gtk.menu...
gdk.types.WindowTypeHint menuTypeHint() @property nothrowGet `menuTypeHint` property. Returns: The #GdkWindowTypeHint to use for the menu's #GdkWindow.
void menuTypeHint(gdk.types.WindowTypeHint propval) @property nothrowSet `menuTypeHint` property. Params: propval = The #GdkWindowTypeHint to use for the menu's #GdkWindow.
int monitor() @property nothrowGet `monitor` property. Returns: The monitor the menu will be popped up on.
void monitor(int propval) @property nothrowSet `monitor` property. Params: propval = The monitor the menu will be popped up on.
int rectAnchorDx() @property nothrowGet `rectAnchorDx` property. Returns: Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.
void rectAnchorDx(int propval) @property nothrowSet `rectAnchorDx` property. Params: propval = Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.
int rectAnchorDy() @property nothrowGet `rectAnchorDy` property. Returns: Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.
void rectAnchorDy(int propval) @property nothrowSet `rectAnchorDy` property. Params: propval = Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.
bool reserveToggleSize() @property nothrowGet `reserveToggleSize` property. Returns: A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.
void reserveToggleSize(bool propval) @property nothrowSet `reserveToggleSize` property. Params: propval = A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.
bool tearoffState() @property nothrowGet `tearoffState` property. Returns: A boolean that indicates whether the menu is torn-off.
void tearoffState(bool propval) @property nothrowSet `tearoffState` property. Params: propval = A boolean that indicates whether the menu is torn-off.
string tearoffTitle() @property nothrowGet `tearoffTitle` property. Returns: A title that may be displayed by the window manager when this menu is torn-off.
void tearoffTitle(string propval) @property nothrowSet `tearoffTitle` property. Params: propval = A title that may be displayed by the window manager when this menu is torn-off.
gtk.menu.Menu newFromModel(gio.menu_model.MenuModel model) static nothrowCreates a #GtkMenu and populates it with menu items and submenus according to model.
gtk.widget.Widget[] getForAttachWidget(gtk.widget.Widget widget) static nothrowReturns a list of the menus which are attached to this widget. This list is owned by GTK+ and must not be modified.
void attach(gtk.widget.Widget child, uint leftAttach, uint rightAttach, uint topAttach, uint bottomAttach) nothrowAdds 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 leftm...
void detach() nothrowDetaches 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.
gtk.accel_group.AccelGroup getAccelGroup() nothrowGets the #GtkAccelGroup which holds global accelerators for the menu. See [gtk.menu.Menu.setAccelGroup]. Returns: the #GtkAccelGroup associated with the menu
string getAccelPath() nothrowRetrieves the accelerator path set on the menu. Returns: the accelerator path set on the menu.
gtk.widget.Widget getActive() nothrowReturns the selected menu item from the menu. This is used by the #GtkComboBox. Returns: the #GtkMenuItem that was last selected in the menu. If a selection has not yet been made, the first menu ...
gtk.widget.Widget getAttachWidget() nothrowReturns the #GtkWidget that the menu is attached to. Returns: the #GtkWidget that the menu is attached to
int getMonitor() nothrowRetrieves the number of the monitor on which to show the menu. Returns: the number of the monitor on which the menu should be popped up or -1, if no monitor has been set
bool getReserveToggleSize() nothrowReturns whether the menu reserves space for toggles and icons, regardless of their actual presence. Returns: Whether the menu reserves toggle space
bool getTearoffState() nothrowReturns whether the menu is torn off. See [gtk.menu.Menu.setTearoffState]. Returns: true if the menu is currently torn off.
string getTitle() nothrowReturns the title of the menu. See [gtk.menu.Menu.setTitle]. Returns: the title of the menu, or null if the menu has no title set on it. This string is owned by GTK+ and should not be modified or f...
void placeOnMonitor(gdk.monitor.MonitorWrap monitor) nothrowPlaces menu on the given monitor.
void popdown() nothrowRemoves the menu from the screen.
void popup(gtk.widget.Widget parentMenuShell, gtk.widget.Widget parentMenuItem, gtk.types.MenuPositionFunc func, uint button, uint activateTime) nothrowDisplays a menu and makes it available for selection.
void popupAtPointer(gdk.event.Event triggerEvent = null) nothrowDisplays menu and makes it available for selection.
void popupAtRect(gdk.window.Window rectWindow, gdk.rectangle.Rectangle rect, gdk.types.Gravity rectAnchor, gdk.types.Gravity menuAnchor, gdk.event.Event triggerEvent = null) nothrowDisplays menu and makes it available for selection.
void popupAtWidget(gtk.widget.Widget widget, gdk.types.Gravity widgetAnchor, gdk.types.Gravity menuAnchor, gdk.event.Event triggerEvent = null) nothrowDisplays menu and makes it available for selection.
void popupForDevice(gdk.device.Device device, gtk.widget.Widget parentMenuShell, gtk.widget.Widget parentMenuItem, gtk.types.MenuPositionFunc func, uint button, uint activateTime) nothrowDisplays a menu and makes it available for selection.
void reorderChild(gtk.widget.Widget child, int position) nothrowMoves child to a new position in the list of menu children.
void reposition() nothrowRepositions the menu according to its position function.
void setAccelGroup(gtk.accel_group.AccelGroup accelGroup = null) nothrowSet 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.addAccelGr...
void setAccelPath(string accelPath = null) nothrowSets 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 ...
void setActive(uint index) nothrowSelects the specified menu item within the menu. This is used by the #GtkComboBox and should not be used by anyone else.
void setMonitor(int monitorNum) nothrowInforms GTK+ on which monitor a menu should be popped up. See [gdk.monitor.MonitorWrap.getGeometry].
void setReserveToggleSize(bool reserveToggleSize) nothrowSets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.
void setScreen(gdk.screen.Screen screen = null) nothrowSets the #GdkScreen on which the menu will be displayed.
void setTearoffState(bool tornOff) nothrowChanges 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...
void setTitle(string title = null) nothrowSets the title string for the menu.
gulong connectMoveScroll(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == gtk.types.ScrollType))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] : gtk.menu.Menu))) && Parameters!T.length < 3) nothrowConnect to `MoveScroll` signal.
gulong connectPoppedUp(T)(T callback, Flag!"After" after = No.After) if (isCallable!T && is(ReturnType!T == void) && (Parameters!T.length < 1 || (ParameterStorageClassTuple!T[0] == ParameterStorageClass.none && is(Parameters!T[0] == void *))) && (Parameters!T.length < 2 || (ParameterStorageClassTuple!T[1] == ParameterStorageClass.none && is(Parameters!T[1] == void *))) && (Parameters!T.length < 3 || (ParameterStorageClassTuple!T[2] == ParameterStorageClass.none && is(Parameters!T[2] == bool))) && (Parameters!T.length < 4 || (ParameterStorageClassTuple!T[3] == ParameterStorageClass.none && is(Parameters!T[3] == bool))) && (Parameters!T.length < 5 || (ParameterStorageClassTuple!T[4] == ParameterStorageClass.none && is(Parameters!T[4] : gtk.menu.Menu))) && Parameters!T.length < 6) nothrowConnect to `PoppedUp` signal.
Constructors
this(void * ptr, Flag!"Take" take)
this()Creates a new #GtkMenu Returns: a new #GtkMenu

Fluent builder implementation template for gtk.menu.Menu

Methods
T accelGroup(gtk.accel_group.AccelGroup propval) nothrowSet `accelGroup` property. Params: propval = The accel group holding accelerators for the menu. Returns: Builder instance for fluent chaining
T accelPath(string propval) nothrowSet `accelPath` property. Params: propval = An accel path used to conveniently construct accel paths of child items. Returns: Builder instance for fluent chaining
T active(int propval) nothrowSet `active` property. Params: propval = The index of the currently selected menu item, or -1 if no menu item is selected. Returns: Builder instance for fluent chaining
T anchorHints(gdk.types.AnchorHints propval) nothrowSet `anchorHints` property. Params: propval = Positioning hints for aligning the menu relative to a rectangle.
T attachWidget(gtk.widget.Widget propval) nothrowSet `attachWidget` property. Params: propval = The widget the menu is attached to. Setting this property attaches the menu without a #GtkMenuDetachFunc. If you need to use a detacher, use [gtk.menu...
T menuTypeHint(gdk.types.WindowTypeHint propval) nothrowSet `menuTypeHint` property. Params: propval = The #GdkWindowTypeHint to use for the menu's #GdkWindow.
T monitor(int propval) nothrowSet `monitor` property. Params: propval = The monitor the menu will be popped up on. Returns: Builder instance for fluent chaining
T rectAnchorDx(int propval) nothrowSet `rectAnchorDx` property. Params: propval = Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.
T rectAnchorDy(int propval) nothrowSet `rectAnchorDy` property. Params: propval = Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.
T reserveToggleSize(bool propval) nothrowSet `reserveToggleSize` property. Params: propval = A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.
T tearoffState(bool propval) nothrowSet `tearoffState` property. Params: propval = A boolean that indicates whether the menu is torn-off. Returns: Builder instance for fluent chaining
T tearoffTitle(string propval) nothrowSet `tearoffTitle` property. Params: propval = A title that may be displayed by the window manager when this menu is torn-off. Returns: Builder instance for fluent chaining

Fluent builder for gtk.menu.Menu

Methods
Menu build() nothrowCreate object from builder. Returns: New object