Class: Gtk::Menu

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#accel_groupGtk::AccelGroup

The accel group holding accelerators for the menu.

Returns:

#accel_group=(accel_group) ⇒ Gtk::AccelGroup

The accel group holding accelerators for the menu.

Parameters:

Returns:

#accel_pathString

An accel path used to conveniently construct accel paths of child items.

Returns:

  • (String)

    accel-path

#accel_path=(accel_path) ⇒ String

An accel path used to conveniently construct accel paths of child items.

Parameters:

  • accel_path (String)

Returns:

  • (String)

    accel-path

  • (String)

    accel-path

#activeInteger

The index of the currently selected menu item, or -1 if no menu item is selected.

Returns:

  • (Integer)

    active

#active=(active) ⇒ Integer

The index of the currently selected menu item, or -1 if no menu item is selected.

Parameters:

  • active (Integer)

Returns:

  • (Integer)

    active

  • (Integer)

    active

#anchor_hintsGdk::AnchorHints

Positioning hints for aligning the menu relative to a rectangle.

These hints determine how the menu should be positioned in the case that the menu would fall off-screen if placed in its ideal position.

![](popup-flip.png)

For example, %GDK_ANCHOR_FLIP_Y will replace %GDK_GRAVITY_NORTH_WEST with %GDK_GRAVITY_SOUTH_WEST and vice versa if the menu extends beyond the bottom edge of the monitor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:rect-anchor-dx, Gtk::Menu:rect-anchor-dy, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Returns:

#anchor_hints=(anchor_hints) ⇒ Gdk::AnchorHints

Positioning hints for aligning the menu relative to a rectangle.

These hints determine how the menu should be positioned in the case that the menu would fall off-screen if placed in its ideal position.

![](popup-flip.png)

For example, %GDK_ANCHOR_FLIP_Y will replace %GDK_GRAVITY_NORTH_WEST with %GDK_GRAVITY_SOUTH_WEST and vice versa if the menu extends beyond the bottom edge of the monitor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:rect-anchor-dx, Gtk::Menu:rect-anchor-dy, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Parameters:

Returns:

#attach(child, left_attach, right_attach, top_attach, bottom_attach) ⇒ nil

Adds a new Gtk::MenuItem 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).

Note that this function is not related to gtk_menu_detach().

Parameters:

  • child (Gtk::Widget)

    a Gtk::MenuItem

  • left_attach (Integer)

    The column number to attach the left side of the item to

  • right_attach (Integer)

    The column number to attach the right side of the item to

  • top_attach (Integer)

    The row number to attach the top of the item to

  • bottom_attach (Integer)

    The row number to attach the bottom of the item to

Returns:

  • (nil)

#attach_to_widget(attach_widget, detacher) ⇒ nil

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.

If the menu is attached to the widget then it will be destroyed when the widget is destroyed, as if it was a child widget. An attached menu will also move between screens correctly if the widgets moves between screens.

Parameters:

  • attach_widget (Gtk::Widget)

    the Gtk::Widget that the menu will be attached to

  • detacher (Gtk::MenuDetachFunc)

    the user supplied callback function that will be called when the menu calls gtk_menu_detach()

Returns:

  • (nil)

#attach_widgetGtk::Widget

The widget the menu is attached to. Setting this property attaches the menu without a Gtk::MenuDetachFunc. If you need to use a detacher, use gtk_menu_attach_to_widget() directly.

Returns:

#attach_widget=(attach_widget) ⇒ Gtk::Widget

The widget the menu is attached to. Setting this property attaches the menu without a Gtk::MenuDetachFunc. If you need to use a detacher, use gtk_menu_attach_to_widget() directly.

Parameters:

Returns:

#detachnil

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.

Returns:

  • (nil)

The Gdk::WindowTypeHint to use for the menu’s #GdkWindow.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dx, #GtkMenu:rect-anchor-dy, and #GtkMenu::popped-up.

Returns:

The Gdk::WindowTypeHint to use for the menu’s #GdkWindow.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dx, #GtkMenu:rect-anchor-dy, and #GtkMenu::popped-up.

Parameters:

Returns:

#monitorInteger

The monitor the menu will be popped up on.

Returns:

  • (Integer)

    monitor

#monitor=(monitor) ⇒ Integer

The monitor the menu will be popped up on.

Parameters:

  • monitor (Integer)

Returns:

  • (Integer)

    monitor

  • (Integer)

    monitor

#newGtk::Widget

Creates a new Gtk::Menu

Returns:

#new_from_model(model) ⇒ Gtk::Widget

Creates a Gtk::Menu and populates it with menu items and submenus according to model.

The created menu items are connected to actions found in the Gtk::ApplicationWindow to which the menu belongs - typically by means of being attached to a widget (see gtk_menu_attach_to_widget()) that is contained within the Gtk::ApplicationWindows widget hierarchy.

Actions can also be added using gtk_widget_insert_action_group() on the menu’s attach widget or on any of its parent widgets.

Parameters:

Returns:

#place_on_monitor(monitor) ⇒ nil

Places menu on the given monitor.

Parameters:

  • monitor (Gdk::Monitor)

    the monitor to place the menu on

Returns:

  • (nil)

#popdownnil

Removes the menu from the screen.

Returns:

  • (nil)

Displays a menu and makes it available for selection.

Applications can use this function to display context-sensitive menus, and will typically supply nil for the parent_menu_shell, parent_menu_item, func and data parameters. The default menu positioning function will position the menu at the current mouse cursor position.

The button parameter should be the mouse button pressed to initiate the menu popup. If the menu popup was initiated by something other than a mouse button press, such as a mouse button release or a keypress, button should be 0.

The activate_time parameter is used to conflict-resolve initiation of concurrent requests for mouse/keyboard grab requests. To function properly, this needs to be the timestamp of the user event (such as a mouse click or key press) that caused the initiation of the popup. Only if no such event is available, gtk_get_current_event_time() can be used instead.

Note that this function does not work very well on GDK backends that do not have global coordinates, such as Wayland or Mir. You should probably use one of the gtk_menu_popup_at_ variants, which do not have this problem.

Parameters:

  • parent_menu_shell (Gtk::Widget)

    the menu shell containing the triggering menu item, or nil

  • parent_menu_item (Gtk::Widget)

    the menu item whose activation triggered the popup, or nil

  • func (Gtk::MenuPositionFunc)

    a user supplied function used to position the menu, or nil

  • data (GObject)

    user supplied data to be passed to func.

  • button (Integer)

    the mouse button which was pressed to initiate the event.

  • activate_time (Integer)

    the time at which the activation event occurred.

Returns:

  • (nil)

Displays menu and makes it available for selection.

See gtk_menu_popup_at_widget () to pop up a menu at a widget. gtk_menu_popup_at_rect () also allows you to position a menu at an arbitrary rectangle.

menu will be positioned at the pointer associated with trigger_event.

Properties that influence the behaviour of this function are Gtk::Menu:anchor-hints, #GtkMenu:rect-anchor-dx, #GtkMenu:rect-anchor-dy, and Gtk::Menu:menu-type-hint. Connect to the #GtkMenu::popped-up signal to find out how it was actually positioned.

Parameters:

  • trigger_event (Gdk::Event)

    the Gdk::Event that initiated this request or nil if it’s the current event

Returns:

  • (nil)

Displays menu and makes it available for selection.

See gtk_menu_popup_at_widget () and gtk_menu_popup_at_pointer (), which handle more common cases for popping up menus.

menu will be positioned at rect, aligning their anchor points. rect is relative to the top-left corner of rect_window. rect_anchor and menu_anchor determine anchor points on rect and menu to pin together. menu can optionally be offset by Gtk::Menu:rect-anchor-dx and Gtk::Menu:rect-anchor-dy.

Anchors should be specified under the assumption that the text direction is left-to-right; they will be flipped horizontally automatically if the text direction is right-to-left.

Other properties that influence the behaviour of this function are Gtk::Menu:anchor-hints and #GtkMenu:menu-type-hint. Connect to the Gtk::Menu::popped-up signal to find out how it was actually positioned.

Parameters:

  • rect_window (Gdk::Window)

    the Gdk::Window rect is relative to

  • rect (Gdk::Rectangle)

    the Gdk::Rectangle to align menu with

  • rect_anchor (Gdk::Gravity)

    the point on rect to align with menu’s anchor point

  • menu_anchor (Gdk::Gravity)

    the point on menu to align with rect’s anchor point

  • trigger_event (Gdk::Event)

    the Gdk::Event that initiated this request or nil if it’s the current event

Returns:

  • (nil)

Displays menu and makes it available for selection.

See gtk_menu_popup_at_pointer () to pop up a menu at the master pointer. gtk_menu_popup_at_rect () also allows you to position a menu at an arbitrary rectangle.

![](popup-anchors.png)

menu will be positioned at widget, aligning their anchor points. widget_anchor and menu_anchor determine anchor points on widget and menu to pin together. menu can optionally be offset by Gtk::Menu:rect-anchor-dx and Gtk::Menu:rect-anchor-dy.

Anchors should be specified under the assumption that the text direction is left-to-right; they will be flipped horizontally automatically if the text direction is right-to-left.

Other properties that influence the behaviour of this function are Gtk::Menu:anchor-hints and #GtkMenu:menu-type-hint. Connect to the Gtk::Menu::popped-up signal to find out how it was actually positioned.

Parameters:

  • widget (Gtk::Widget)

    the Gtk::Widget to align menu with

  • widget_anchor (Gdk::Gravity)

    the point on widget to align with menu’s anchor point

  • menu_anchor (Gdk::Gravity)

    the point on menu to align with widget’s anchor point

  • trigger_event (Gdk::Event)

    the Gdk::Event that initiated this request or nil if it’s the current event

Returns:

  • (nil)

Displays a menu and makes it available for selection.

Applications can use this function to display context-sensitive menus, and will typically supply nil for the parent_menu_shell, parent_menu_item, func, data and destroy parameters. The default menu positioning function will position the menu at the current position of device (or its corresponding pointer).

The button parameter should be the mouse button pressed to initiate the menu popup. If the menu popup was initiated by something other than a mouse button press, such as a mouse button release or a keypress, button should be 0.

The activate_time parameter is used to conflict-resolve initiation of concurrent requests for mouse/keyboard grab requests. To function properly, this needs to be the time stamp of the user event (such as a mouse click or key press) that caused the initiation of the popup. Only if no such event is available, gtk_get_current_event_time() can be used instead.

Note that this function does not work very well on GDK backends that do not have global coordinates, such as Wayland or Mir. You should probably use one of the gtk_menu_popup_at_ variants, which do not have this problem.

Parameters:

  • device (Gdk::Device)

    a Gdk::Device

  • parent_menu_shell (Gtk::Widget)

    the menu shell containing the triggering menu item, or nil

  • parent_menu_item (Gtk::Widget)

    the menu item whose activation triggered the popup, or nil

  • func (Gtk::MenuPositionFunc)

    a user supplied function used to position the menu, or nil

  • data (GObject)

    user supplied data to be passed to func

  • destroy (GLib::DestroyNotify)

    destroy notify for data

  • button (Integer)

    the mouse button which was pressed to initiate the event

  • activate_time (Integer)

    the time at which the activation event occurred

Returns:

  • (nil)

#rect_anchor_dxInteger

Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dy, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Returns:

  • (Integer)

    rect-anchor-dx

#rect_anchor_dx=(rect_anchor_dx) ⇒ Integer

Horizontal offset to apply to the menu, i.e. the rectangle or widget anchor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dy, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Parameters:

  • rect_anchor_dx (Integer)

Returns:

  • (Integer)

    rect-anchor-dx

  • (Integer)

    rect-anchor-dx

#rect_anchor_dyInteger

Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dx, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Returns:

  • (Integer)

    rect-anchor-dy

#rect_anchor_dy=(rect_anchor_dy) ⇒ Integer

Vertical offset to apply to the menu, i.e. the rectangle or widget anchor.

See gtk_menu_popup_at_rect (), gtk_menu_popup_at_widget (), gtk_menu_popup_at_pointer (), Gtk::Menu:anchor-hints, Gtk::Menu:rect-anchor-dx, #GtkMenu:menu-type-hint, and #GtkMenu::popped-up.

Parameters:

  • rect_anchor_dy (Integer)

Returns:

  • (Integer)

    rect-anchor-dy

  • (Integer)

    rect-anchor-dy

#reorder_child(child, position) ⇒ nil

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

Parameters:

  • child (Gtk::Widget)

    the Gtk::MenuItem to move

  • position (Integer)

    the new position to place child. Positions are numbered from 0 to n - 1

Returns:

  • (nil)

#repositionnil

Repositions the menu according to its position function.

Returns:

  • (nil)

#reserve_toggle_sizeTrueClass

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

Returns:

  • (TrueClass)

    Whether the menu reserves toggle space

#reserve_toggle_size=(reserve_toggle_size) ⇒ TrueClass

A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.

This property should only be changed from its default value for special-purposes such as tabular menus. Regular menus that are connected to a menu bar or context menus should reserve toggle space for consistency.

Parameters:

  • reserve_toggle_size (TrueClass)

Returns:

  • (TrueClass)

    reserve-toggle-size

  • (TrueClass)

    reserve-toggle-size

#reserve_toggle_size?TrueClass

A boolean that indicates whether the menu reserves space for toggles and icons, regardless of their actual presence.

This property should only be changed from its default value for special-purposes such as tabular menus. Regular menus that are connected to a menu bar or context menus should reserve toggle space for consistency.

Returns:

  • (TrueClass)

    reserve-toggle-size

#screen=(screen) ⇒ nil

Sets the Gdk::Screen on which the menu will be displayed.

Parameters:

  • screen (Gdk::Screen)

    a Gdk::Screen, or nil if the screen should be determined by the widget the menu is attached to

Returns:

  • (nil)

#tearoff_stateTrueClass

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

Returns:

  • (TrueClass)

    true if the menu is currently torn off.

#tearoff_state=(tearoff_state) ⇒ TrueClass

A boolean that indicates whether the menu is torn-off.

Parameters:

  • tearoff_state (TrueClass)

Returns:

  • (TrueClass)

    tearoff-state

  • (TrueClass)

    tearoff-state

#tearoff_state?TrueClass

A boolean that indicates whether the menu is torn-off.

Returns:

  • (TrueClass)

    tearoff-state

#tearoff_titleString

A title that may be displayed by the window manager when this menu is torn-off.

Returns:

  • (String)

    tearoff-title

#tearoff_title=(tearoff_title) ⇒ String

A title that may be displayed by the window manager when this menu is torn-off.

Parameters:

  • tearoff_title (String)

Returns:

  • (String)

    tearoff-title

  • (String)

    tearoff-title

#titleString

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

Returns:

  • (String)

    the title of the menu, or nil if the menu has no title set on it. This string is owned by GTK+ and should not be modified or freed.

#title=(title) ⇒ nil

Sets the title string for the menu.

The title is displayed when the menu is shown as a tearoff menu. If title is nil, the menu will see if it is attached to a parent menu item, and if so it will try to use the same text as that menu item’s label.

Parameters:

  • title (String)

    a string containing the title for the menu, or nil to inherit the title of the parent menu item, if any

Returns:

  • (nil)