A menu widget
Class GtkMenu
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 GtkOptionMenu. 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_popup() function. The example below shows how an application can pop up a menu when the 3rd mouse button is pressed.
[...]
Methods | |
attach | Adds a new GtkMenuItem to a (table) menu. |
attach_to_widget | 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. |
detach | Detaches the menu from the widget to which it had been attached. |
get_accel_path | Retrieves the accelerator path set on the menu. |
get_active | Returns the selected menu item from the menu. |
get_attach_widget | Returns the GtkWidget that the menu is attached to. |
get_for_attach_widget | Returns a list of the menus which are attached to this widget. |
get_monitor | Retrieves the number of the monitor on which to show the menu. |
get_reserve_toggle_size | Returns whether the menu reserves space for toggles and icons, regardless of their actual presence. |
get_tearoff_state | Returns whether the menu is torn off. |
get_title | Returns the title of the menu. |
popdown | Removes the menu from the screen. |
popup | Displays a menu and makes it available for selection. |
reorder_child | Moves a GtkMenuItem to a new position within the GtkMenu. |
reposition | Repositions the menu according to its position function. |
set_accel_group | Set the GtkAccelGroup which holds global accelerators for the menu. |
set_accel_path | Sets an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed. |
set_active | Selects the specified menu item within the menu. |
set_monitor | Informs GTK+ on which monitor a menu should be popped up. |
set_reserve_toggle_size | Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence. |
set_screen | Sets the GdkScreen on which the menu will be displayed. |
set_tearoff_state | Changes the tearoff state of the menu. |
set_title | Sets the title string for the menu. |
signal_move_scroll | . |
Adds a new GtkMenuItem to a (table) menu.
GtkMenu.attach( child, left_attach, right_attach, top_attach, bottom_attach )
child | a GtkMenuItem. |
left_attach | The column number to attach the left side of the item to. |
right_attach | The column number to attach the right side of the item to. |
top_attach | The row number to attach the top of the item to. |
bottom_attach | The row number to attach the bottom of the item to. |
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().
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.
GtkMenu.attach_to_widget( attach_widget )
attach_widget | the GtkWidget that the menu will be attached to. |
Detaches the menu from the widget to which it had been attached.
GtkMenu.detach()
This function will call the callback function, detacher, provided when the gtk_menu_attach_to_widget() function was called.
Retrieves the accelerator path set on the menu.
GtkMenu.get_accel_path()
Return | the accelerator path set on the menu. |
Returns the selected menu item from the menu.
GtkMenu.get_active()
Return | the GtkMenuItem that was last selected in the menu. If a selection has not yet been made, the first menu item is selected. |
Returns the GtkWidget that the menu is attached to.
GtkMenu.get_attach_widget()
Return | the GtkWidget that the menu is attached to. |
Returns a list of the menus which are attached to this widget.
GtkMenu.get_for_attach_widget( widget )
widget | a GtkWidget |
Return | the list of menus attached to his widget |
Retrieves the number of the monitor on which to show the menu.
GtkMenu.get_monitor()
Return | the number of the monitor on which the menu should be popped up or -1, if no monitor has been set |
Returns whether the menu reserves space for toggles and icons, regardless of their actual presence.
GtkMenu.get_reserve_toggle_size()
Return | Whether the menu reserves toggle space |
Returns whether the menu is torn off.
GtkMenu.get_tearoff_state()
Return | true if the menu is currently torn off. |
Returns the title of the menu.
GtkMenu.get_title()
Return | the title of the menu, or nil if the menu has no title set on it. |
Removes the menu from the screen.
GtkMenu.popdown()
Displays a menu and makes it available for selection.
GtkMenu.popup( parent_menu_shell, parent_menu_item, button, activate_time )
parent_menu_shell | the menu shell containing the triggering menu item, or NULL. |
parent_menu_item | the menu item whose activation triggered the popup, or NULL. |
button | the mouse button which was pressed to initiate the event. |
activate_time | the time at which the activation event occurred. |
Applications can use this function to display context-sensitive menus, and will typically supply NULL 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.
[...]
Moves a GtkMenuItem to a new position within the GtkMenu.
GtkMenu.reorder_child( child, position )
child | the GtkMenuItem to move. |
position | the new position to place child. Positions are numbered from 0 to n-1. |
Repositions the menu according to its position function.
GtkMenu.reposition()
Set the GtkAccelGroup which holds global accelerators for the menu.
GtkMenu.set_accel_group( accel_group )
accel_group | a GtkAccelGroup, or nil. |
This accelerator group needs to also be added to all windows that this menu is being used in with gtk_window_add_accel_group(), in order for those windows to support all the accelerators contained in this group.
Sets an accelerator path for this menu from which accelerator paths for its immediate children, its menu items, can be constructed.
GtkMenu.set_accel_path( accel_path )
accel_path | a valid accelerator path, or nil. [...] |
Selects the specified menu item within the menu.
GtkMenu.set_active( index_ )
index_ | the index of the menu item to select. Index values are from 0 to n-1. |
Informs GTK+ on which monitor a menu should be popped up.
GtkMenu.set_monitor( monitor_num )
monitor_num | the number of the monitor on which the menu should be popped up |
[...]
Sets whether the menu should reserve space for drawing toggles or icons, regardless of their actual presence.
GtkMenu.set_reserve_toggle_size( reserve_toggle_size )
reserve_toggle_size | whether to reserve size for toggles |
Sets the GdkScreen on which the menu will be displayed.
GtkMenu.set_screen( a )
a | GdkScreen, or NULL if the screen should be determined by the widget the menu is attached to |
Changes the tearoff state of the menu.
GtkMenu.set_tearoff_state( torn_off )
torn_off | If true, menu is displayed as a tearoff 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 it is closed or reattached.
Sets the title string for the menu.
GtkMenu.set_title( title )
title | a string containing the title for the menu , or nil. |
The title is displayed when the menu is shown as a tearoff menu. If title is NULL, 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.
.
GtkMenu.signal_move_scroll()