GtkMenu
A menu widget
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.
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 == 3)
{
gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
event_button->button, event_button->time);
return TRUE;
}
}
return FALSE;
}
The #GtkMenu struct contains private data only, and
should be accessed using the functions below.
@menu: the object which received the signal.
@arg1:
Creates a new #GtkMenu.
@Returns: a new #GtkMenu.
@menu:
@screen:
Adds a new #GtkMenuItem to the end of the menu's item list.
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
@m:
@c:
Adds a new #GtkMenuItem to the beginning of the menu's item list.
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
@menu_child:
@m:
@c:
Adds a new #GtkMenuItem to the menu's item list at the position
indicated by @position.
@menu: a #GtkMenu.
@child: The #GtkMenuItem to add.
@pos:
@position: The position in the item list where @child is added.
Positions are numbered from 0 to n-1.
Moves a #GtkMenuItem to a new position within the #GtkMenu.
@menu: a #GtkMenu.
@child: the #GtkMenuItem to move.
@position: the new position to place @child. Positions are numbered from
0 to n-1.
@menu:
@child:
@left_attach:
@right_attach:
@top_attach:
@bottom_attach:
@menu:
@parent_menu_shell:
@parent_menu_item:
@func:
@data:
@button:
@activate_time:
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_add_accel_group(), in order
for those windows to support all the accelerators contained in this group.
@menu: a #GtkMenu.
@accel_group: the #GtkAccelGroup to be associated with the menu.
Gets the #GtkAccelGroup which holds global accelerators for the menu.
See gtk_menu_set_accel_group().
@menu: a #GtkMenu.
@Returns: the #GtkAccelGroup associated with the menu.
@menu:
@accel_path:
@menu:
@title:
@menu:
@Returns:
@menu:
@Returns:
Removes the menu from the screen.
@menu: a #GtkMenu.
Repositions the menu according to its position function.
@menu: a #GtkMenu.
Returns the selected menu item from the menu. This is used by the
#GtkOptionMenu.
@menu: a #GtkMenu.
@Returns: the #GtkMenuItem that was last selected in the menu. If a
selection has not yet been made, the first menu item is selected.
Selects the specified menu item within the menu. This is used by the
#GtkOptionMenu and should not be used by anyone else.
@menu: a #GtkMenu.
@index_: the index of the menu item to select. Index values are from
0 to n-1.
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 it is closed
or reattached.
@menu: a #GtkMenu.
@torn_off: If %TRUE, menu is displayed as a tearoff menu.
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.
@menu: a #GtkMenu.
@attach_widget: the #GtkWidget that the menu will be attached to.
@detacher: the user supplied callback function that will be called when
the menu calls gtk_menu_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_attach_to_widget() function was called.
@menu: a #GtkMenu.
Returns the #GtkWidget that the menu is attached to.
@menu: a #GtkMenu.
@Returns: the #GtkWidget that the menu is attached to.
@widget:
@Returns:
A user function supplied when calling gtk_menu_popup() which controls the
positioning of the menu when it is displayed. The function sets the @x
and @y parameters to the coordinates where the menu is to be drawn.
@menu: a #GtkMenu.
@x: address of the #gint representing the horizontal position where the
menu shall be drawn. This is an output parameter.
@y: address of the #gint representing the vertical position where the
menu shall be drawn. This is an output parameter.
@push_in: whether the menu should be pushed in to be completely inside the
screen instead of just clamped to the size to the screen.
@user_data: the data supplied by the user in the gtk_menu_popup() @data
parameter.
A user function supplied when calling gtk_menu_attach_to_widget() which
will be called when the menu is later detached from the widget.
@attach_widget: the #GtkWidget that the menu is being detached from.
@menu: the #GtkMenu being detached.
@menu:
@monitor_num: