A Menu is a MenuShell that implements a drop down menu
consisting of a list of MenuItem objects which can be navigated and activated by the user
to perform application functions.
A Menu is most commonly dropped down by activating a MenuItem in
a MenuBar or popped up by activating a MenuItem
in another Menu.
A Menu can also be popped up by activating a ComboBox. Other
composite widgets such as the Notebook can pop up a Menu as well.
Applications can display a Menu as a popup menu by calling the
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
Menu has name menu, and there are two subnodes with name arrow, for scrolling menu arrows. These subnodes get the .top and .bottom style
classes.
- public AccelGroup accel_group { get; set; }
The accel group holding accelerators for the menu.
- public string accel_path { get; set; }
An accel path used to conveniently construct accel paths of child
items.
- public int active { get; set; }
The index of the currently selected menu item, or -1 if no menu item
is selected.
- public AnchorHints anchor_hints { get; set construct; }
Positioning hints for aligning the menu relative to a rectangle.
- public Widget attach_widget { owned get; set; }
The widget the menu is attached to.
- public WindowTypeHint menu_type_hint { get; set construct; }
The WindowTypeHint to use for the menu's
Window.
- public int monitor { get; set; }
The monitor the menu will be popped up on.
- public int rect_anchor_dx { get; set construct; }
Horizontal offset to apply to the menu, i.
- public int rect_anchor_dy { get; set construct; }
Vertical offset to apply to the menu, i.
- public bool reserve_toggle_size { get; set; }
A boolean that indicates whether the menu reserves space for toggles
and icons, regardless of their actual presence.
- public bool tearoff_state { get; set; }
A boolean that indicates whether the menu is torn-off.
- public string tearoff_title { owned get; set; }
A title that may be displayed by the window manager when this menu is
torn-off.
- public void attach (Widget child, uint left_attach, uint right_attach, uint top_attach, uint bottom_attach)
- public void attach_to_widget (Widget attach_widget, MenuDetachFunc? detacher)
Attaches the menu to the widget and provides a callback function that
will be invoked when the menu calls detach during its destruction.
- public void detach ()
Detaches the menu from the widget to which it had been attached.
- public unowned AccelGroup get_accel_group ()
Gets the AccelGroup
which holds global accelerators for the menu.
- public unowned string get_accel_path ()
Retrieves the accelerator path set on the menu.
- public unowned Widget get_active ()
Returns the selected menu item from the menu.
- public unowned Widget get_attach_widget ()
Returns the Widget that
the menu is attached to.
- public int get_monitor ()
Retrieves the number of the monitor on which to show the menu.
- public bool get_reserve_toggle_size ()
Returns whether the menu reserves space for toggles and icons,
regardless of their actual presence.
- public bool get_tearoff_state ()
Returns whether the menu is torn off.
- public unowned string get_title ()
Returns the title of the menu.
- public void place_on_monitor (Monitor monitor)
Places this on the given monitor.
- public void popdown ()
Removes the menu from the screen.
- public void popup (Widget? parent_menu_shell, Widget? parent_menu_item, MenuPositionFunc? func, uint button, uint32 activate_time)
Displays a menu and makes it available for selection.
- public void popup_at_pointer (Event? trigger_event = null)
Displays this and makes it available
for selection.
- public void popup_at_rect (Window rect_window, Rectangle rect, Gravity rect_anchor, Gravity menu_anchor, Event? trigger_event = null)
Displays this and makes it available
for selection.
- public void popup_at_widget (Widget widget, Gravity widget_anchor, Gravity menu_anchor, Event? trigger_event = null)
Displays this and makes it available
for selection.
- public void popup_for_device (Device? device, Widget? parent_menu_shell, Widget? parent_menu_item, owned MenuPositionFunc? func, uint button, uint32 activate_time)
Displays a menu and makes it available for selection.
- public void reorder_child (Widget child, int position)
Moves child
to a new position
in the list of
this children.
- public void reposition ()
Repositions the menu according to its position function.
- public void set_accel_group (AccelGroup? accel_group)
Set the AccelGroup
which holds global accelerators for the menu.
- public void set_accel_path (string? accel_path)
Sets an accelerator path for this menu from which accelerator paths
for its immediate children, its menu items, can be constructed.
- public void set_active (uint index)
Selects the specified menu item within the menu.
- public void set_monitor (int monitor_num)
Informs GTK+ on which monitor a menu should be popped up.
- public void set_reserve_toggle_size (bool reserve_toggle_size)
Sets whether the menu should reserve space for drawing toggles or
icons, regardless of their actual presence.
- public void set_screen (Screen? screen)
Sets the Screen on which the menu will be
displayed.
- public void set_tearoff_state (bool torn_off)
Changes the tearoff state of the menu.
- public void set_title (string? title)
Sets the title string for the menu.