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.bottomThe 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.
Menu self()Returns `this`, for use in `with` statements.MenuGidBuilder builder()Get builder for [gtk.menu.Menu] Returns: New builder objectgtk.accel_group.AccelGroup accelGroup() @propertyGet `accelGroup` property. Returns: The accel group holding accelerators for the menu.void accelGroup(gtk.accel_group.AccelGroup propval) @propertySet `accelGroup` property. Params: propval = The accel group holding accelerators for the menu.string accelPath() @propertyGet `accelPath` property. Returns: An accel path used to conveniently construct accel paths of child items.void accelPath(string propval) @propertySet `accelPath` property. Params: propval = An accel path used to conveniently construct accel paths of child items.int active() @propertyGet `active` property. Returns: The index of the currently selected menu item, or -1 if no menu item is selected.void active(int propval) @propertySet `active` property. Params: propval = The index of the currently selected menu item, or -1 if no menu item is selected.gdk.types.AnchorHints anchorHints() @propertyGet `anchorHints` property. Returns: Positioning hints for aligning the menu relative to a rectangle.void anchorHints(gdk.types.AnchorHints propval) @propertySet `anchorHints` property. Params: propval = Positioning hints for aligning the menu relative to a rectangle.gtk.widget.Widget attachWidget() @propertyGet `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) @propertySet `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() @propertyGet `menuTypeHint` property. Returns: The #GdkWindowTypeHint to use for the menu's #GdkWindow.void menuTypeHint(gdk.types.WindowTypeHint propval) @propertySet `menuTypeHint` property. Params: propval = The #GdkWindowTypeHint to use for the menu's #GdkWindow.void monitor(int propval) @propertySet `monitor` property. Params: propval = The monitor the menu will be popped up on.int rectAnchorDx() @propertyGet `rectAnchorDx` property. Returns: Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.void rectAnchorDx(int propval) @propertySet `rectAnchorDx` property. Params: propval = Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.int rectAnchorDy() @propertyGet `rectAnchorDy` property. Returns: Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.void rectAnchorDy(int propval) @propertySet `rectAnchorDy` property. Params: propval = Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.bool reserveToggleSize() @propertyGet `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) @propertySet `reserveToggleSize` property. Params: propval = A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.bool tearoffState() @propertyGet `tearoffState` property. Returns: A boolean that indicates whether the menu is torn-off.void tearoffState(bool propval) @propertySet `tearoffState` property. Params: propval = A boolean that indicates whether the menu is torn-off.string tearoffTitle() @propertyGet `tearoffTitle` property. Returns: A title that may be displayed by the window manager when this menu is torn-off.void tearoffTitle(string propval) @propertySet `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)Creates a #GtkMenu and populates it with menu items and submenus according to model.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.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 leftattach, rightattach, topattach and bottomattach. These each represent the leftmost,...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.gtk.accel_group.AccelGroup getAccelGroup()Gets the #GtkAccelGroup which holds global accelerators for the menu. See [gtk.menu.Menu.setAccelGroup]. Returns: the #GtkAccelGroup associated with the menustring getAccelPath()Retrieves the accelerator path set on the menu. Returns: the accelerator path set on the menu.gtk.widget.Widget getActive()Returns 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()Returns the #GtkWidget that the menu is attached to. Returns: the #GtkWidget that the menu is attached toint getMonitor()Retrieves 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 setbool getReserveToggleSize()Returns whether the menu reserves space for toggles and icons, regardless of their actual presence. Returns: Whether the menu reserves toggle spacebool getTearoffState()Returns whether the menu is torn off. See [gtk.menu.Menu.setTearoffState]. Returns: true if the menu is currently torn off.string getTitle()Returns 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)Places menu on the given monitor.void popdown()Removes the menu from the screen.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.void popupAtPointer(gdk.event.Event triggerEvent = null)Displays 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)Displays 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)Displays 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)Displays a menu and makes it available for selection.void reorderChild(gtk.widget.Widget child, int position)Moves child to a new position in the list of menu children.void reposition()Repositions the menu according to its position function.void setAccelGroup(gtk.accel_group.AccelGroup accelGroup = null)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.addAccelGr...void setAccelPath(string accelPath = null)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 ...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.void setMonitor(int monitorNum)Informs GTK+ on which monitor a menu should be popped up. See [gdk.monitor.MonitorWrap.getGeometry].void setReserveToggleSize(bool reserveToggleSize)Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.void setScreen(gdk.screen.Screen screen = null)Sets the #GdkScreen on which the menu will be displayed.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...void setTitle(string title = null)Sets 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)Connect 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)Connect to `PoppedUp` signal.T accelGroup(gtk.accel_group.AccelGroup propval)Set `accelGroup` property. Params: propval = The accel group holding accelerators for the menu. Returns: Builder instance for fluent chainingT accelPath(string propval)Set `accelPath` property. Params: propval = An accel path used to conveniently construct accel paths of child items. Returns: Builder instance for fluent chainingT active(int propval)Set `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 chainingT anchorHints(gdk.types.AnchorHints propval)Set `anchorHints` property. Params: propval = Positioning hints for aligning the menu relative to a rectangle.T attachWidget(gtk.widget.Widget propval)Set `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)Set `menuTypeHint` property. Params: propval = The #GdkWindowTypeHint to use for the menu's #GdkWindow.T monitor(int propval)Set `monitor` property. Params: propval = The monitor the menu will be popped up on. Returns: Builder instance for fluent chainingT rectAnchorDx(int propval)Set `rectAnchorDx` property. Params: propval = Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.T rectAnchorDy(int propval)Set `rectAnchorDy` property. Params: propval = Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.T reserveToggleSize(bool propval)Set `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)Set `tearoffState` property. Params: propval = A boolean that indicates whether the menu is torn-off. Returns: Builder instance for fluent chainingT tearoffTitle(string propval)Set `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 chainingFluent builder for [gtk.menu.Menu]
Menu build()