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