1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
7 <!-- ##### SECTION Long_Description ##### -->
9 A #GtkMenu is a #GtkMenuShell that implements a drop down menu consisting of
10 a list of #GtkMenuItem objects which can be navigated and activated by the
11 user to perform application functions.
15 A #GtkMenu is most commonly dropped down by activating a #GtkMenuItem in a
16 #GtkMenuBar or popped up by activating a #GtkMenuItem in another #GtkMenu.
20 A #GtkMenu can also be popped up by activating a #GtkOptionMenu.
21 Other composite widgets such as the #GtkNotebook can pop up a #GtkMenu
26 Applications can display a #GtkMenu as a popup menu by calling the
27 gtk_menu_popup() function. The example below shows how an application
28 can pop up a menu when the 3rd mouse button is pressed.
32 <title>Connecting the popup signal handler.</title>
34 /* connect our handler which will popup the menu */
35 g_signal_connect_swapped (window, "button_press_event",
36 G_CALLBACK (my_popup_handler), menu);
41 <title>Signal handler which displays a popup menu.</title>
44 my_popup_handler (GtkWidget *widget, GdkEvent *event)
47 GdkEventButton *event_button;
49 g_return_val_if_fail (widget != NULL, FALSE);
50 g_return_val_if_fail (GTK_IS_MENU (widget), FALSE);
51 g_return_val_if_fail (event != NULL, FALSE);
53 /* The "widget" is the menu that was supplied when
54 * g_signal_connect_swapped() was called.
56 menu = GTK_MENU (widget);
58 if (event->type == GDK_BUTTON_PRESS)
60 event_button = (GdkEventButton *) event;
61 if (event_button->button == 3)
63 gtk_menu_popup (menu, NULL, NULL, NULL, NULL,
64 event_button->button, event_button->time);
74 <!-- ##### SECTION See_Also ##### -->
79 <!-- ##### SECTION Stability_Level ##### -->
82 <!-- ##### STRUCT GtkMenu ##### -->
84 The #GtkMenu struct contains private data only, and
85 should be accessed using the functions below.
89 <!-- ##### SIGNAL GtkMenu::move-scroll ##### -->
94 @menu: the object which received the signal.
97 <!-- ##### ARG GtkMenu:accel-group ##### -->
102 <!-- ##### ARG GtkMenu:accel-path ##### -->
107 <!-- ##### ARG GtkMenu:active ##### -->
112 <!-- ##### ARG GtkMenu:attach-widget ##### -->
117 <!-- ##### ARG GtkMenu:monitor ##### -->
122 <!-- ##### ARG GtkMenu:tearoff-state ##### -->
127 <!-- ##### ARG GtkMenu:tearoff-title ##### -->
132 <!-- ##### ARG GtkMenu:bottom-attach ##### -->
137 <!-- ##### ARG GtkMenu:left-attach ##### -->
142 <!-- ##### ARG GtkMenu:right-attach ##### -->
147 <!-- ##### ARG GtkMenu:top-attach ##### -->
152 <!-- ##### ARG GtkMenu:double-arrows ##### -->
157 <!-- ##### ARG GtkMenu:horizontal-offset ##### -->
162 <!-- ##### ARG GtkMenu:horizontal-padding ##### -->
167 <!-- ##### ARG GtkMenu:vertical-offset ##### -->
172 <!-- ##### ARG GtkMenu:vertical-padding ##### -->
177 <!-- ##### FUNCTION gtk_menu_new ##### -->
179 Creates a new #GtkMenu.
182 @Returns: a new #GtkMenu.
185 <!-- ##### FUNCTION gtk_menu_set_screen ##### -->
194 <!-- ##### MACRO gtk_menu_append ##### -->
196 Adds a new #GtkMenuItem to the end of the menu's item list.
200 @child: The #GtkMenuItem to add.
201 @Deprecated: Use gtk_menu_shell_append() instead.
204 <!-- ##### MACRO gtk_menu_prepend ##### -->
206 Adds a new #GtkMenuItem to the beginning of the menu's item list.
210 @child: The #GtkMenuItem to add.
211 @Deprecated: Use gtk_menu_shell_prepend() instead.
214 <!-- ##### MACRO gtk_menu_insert ##### -->
216 Adds a new #GtkMenuItem to the menu's item list at the position
217 indicated by @position.
221 @child: The #GtkMenuItem to add.
222 @pos: The position in the item list where @child is added.
223 Positions are numbered from 0 to n-1.
224 @Deprecated: Use gtk_menu_shell_insert() instead.
227 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
229 Moves a #GtkMenuItem to a new position within the #GtkMenu.
233 @child: the #GtkMenuItem to move.
234 @position: the new position to place @child. Positions are numbered from
238 <!-- ##### FUNCTION gtk_menu_attach ##### -->
251 <!-- ##### FUNCTION gtk_menu_popup ##### -->
263 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
265 Set the #GtkAccelGroup which holds global accelerators for the menu.
266 This accelerator group needs to also be added to all windows that
267 this menu is being used in with gtk_window_add_accel_group(), in order
268 for those windows to support all the accelerators contained in this group.
272 @accel_group: the #GtkAccelGroup to be associated with the menu.
275 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
277 Gets the #GtkAccelGroup which holds global accelerators for the menu.
278 See gtk_menu_set_accel_group().
282 @Returns: the #GtkAccelGroup associated with the menu.
285 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
294 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
302 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
311 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
320 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
322 Removes the menu from the screen.
328 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
330 Repositions the menu according to its position function.
336 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
338 Returns the selected menu item from the menu. This is used by the
343 @Returns: the #GtkMenuItem that was last selected in the menu. If a
344 selection has not yet been made, the first menu item is selected.
347 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
349 Selects the specified menu item within the menu. This is used by the
350 #GtkOptionMenu and should not be used by anyone else.
354 @index_: the index of the menu item to select. Index values are from
358 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
360 Changes the tearoff state of the menu. A menu is normally displayed
361 as drop down menu which persists as long as the menu is active. It can
362 also be displayed as a tearoff menu which persists until it is closed
367 @torn_off: If %TRUE, menu is displayed as a tearoff menu.
370 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
372 Attaches the menu to the widget and provides a callback function that will
373 be invoked when the menu calls gtk_menu_detach() during its destruction.
377 @attach_widget: the #GtkWidget that the menu will be attached to.
378 @detacher: the user supplied callback function that will be called when
379 the menu calls gtk_menu_detach().
382 <!-- ##### FUNCTION gtk_menu_detach ##### -->
384 Detaches the menu from the widget to which it had been attached.
385 This function will call the callback function, @detacher, provided
386 when the gtk_menu_attach_to_widget() function was called.
392 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
394 Returns the #GtkWidget that the menu is attached to.
398 @Returns: the #GtkWidget that the menu is attached to.
401 <!-- ##### FUNCTION gtk_menu_get_for_attach_widget ##### -->
410 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
412 A user function supplied when calling gtk_menu_popup() which controls the
413 positioning of the menu when it is displayed. The function sets the @x
414 and @y parameters to the coordinates where the menu is to be drawn.
418 @x: address of the #gint representing the horizontal position where the
419 menu shall be drawn. This is an output parameter.
420 @y: address of the #gint representing the vertical position where the
421 menu shall be drawn. This is an output parameter.
422 @push_in: This parameter controls how menus placed outside the monitor are handled.
423 If this is set to TRUE and part of the menu is outside the monitor then
424 GTK+ pushes the window into the visible area, effectively modifying the
426 Note that moving and possibly resizing the menu around will alter the
427 scroll position to keep the menu items "in place", i.e. at the same monitor
428 position they would have been without resizing.
429 In practice, this behavior is only useful for combobox popups or option
430 menus and cannot be used to simply confine a menu to monitor boundaries.
431 In that case, changing the scroll offset is not desirable.
432 To simply constrain the menu within the monitor, get its size with
433 gtk_widget_size_request() before showing it, and alter the coordinates
434 passed to gtk_menu_popup() accordingly.
435 @user_data: the data supplied by the user in the gtk_menu_popup() @data
439 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
441 A user function supplied when calling gtk_menu_attach_to_widget() which
442 will be called when the menu is later detached from the widget.
445 @attach_widget: the #GtkWidget that the menu is being detached from.
446 @menu: the #GtkMenu being detached.
449 <!-- ##### FUNCTION gtk_menu_set_monitor ##### -->