1 2@c %start of fragment 3 4@node GtkMenu 5@chapter GtkMenu 6A menu widget 7 8@section Overview 9A @code{<gtk-menu>} is a @code{<gtk-menu-shell>} that implements a drop down 10menu consisting of a list of @code{<gtk-menu-item>} objects which can be 11navigated and activated by the user to perform application functions. 12 13A @code{<gtk-menu>} is most commonly dropped down by activating a 14@code{<gtk-menu-item>} in a @code{<gtk-menu-bar>} or popped up by activating a 15@code{<gtk-menu-item>} in another @code{<gtk-menu>}. 16 17A @code{<gtk-menu>} can also be popped up by activating a 18@code{<gtk-option-menu>}. Other composite widgets such as the 19@code{<gtk-notebook>} can pop up a @code{<gtk-menu>} as well. 20 21Applications can display a @code{<gtk-menu>} as a popup menu by calling the 22@code{gtk-menu-popup} function. The example below shows how an application can 23pop up a menu when the 3rd mouse button is pressed. 24 25@example 26 27 /* connect our handler which will popup the menu */ 28 g_signal_connect_swapped (window, "button_press_event", 29 G_CALLBACK (my_popup_handler), menu); 30@end example 31 32@example 33 34static gint 35my_popup_handler (GtkWidget *widget, GdkEvent *event) 36@{ 37 GtkMenu *menu; 38 GdkEventButton *event_button; 39 40 g_return_val_if_fail (widget != NULL, FALSE); 41 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE); 42 g_return_val_if_fail (event != NULL, FALSE); 43 44 /* The "widget" is the menu that was supplied when 45 * g_signal_connect_swapped() was called. 46 */ 47 menu = GTK_MENU (widget); 48 49 if (event->type == GDK_BUTTON_PRESS) 50 @{ 51 event_button = (GdkEventButton *) event; 52 if (event_button->button == 3) 53 @{ 54 gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 55 event_button->button, event_button->time); 56 return TRUE; 57 @} 58 @} 59 60 return FALSE; 61@} 62@end example 63 64@section Usage 65@include defuns-gtkmenu.xml.texi 66 67@c %end of fragment 68