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
<!-- ##### SECTION Image ##### -->
85
<!-- ##### STRUCT GtkMenu ##### -->
87
The #GtkMenu struct contains private data only, and
88
should be accessed using the functions below.
92
<!-- ##### SIGNAL GtkMenu::move-scroll ##### -->
97
@menu: the object which received the signal.
100
<!-- ##### ARG GtkMenu:accel-group ##### -->
105
<!-- ##### ARG GtkMenu:accel-path ##### -->
110
<!-- ##### ARG GtkMenu:active ##### -->
115
<!-- ##### ARG GtkMenu:attach-widget ##### -->
120
<!-- ##### ARG GtkMenu:monitor ##### -->
125
<!-- ##### ARG GtkMenu:reserve-toggle-size ##### -->
130
<!-- ##### ARG GtkMenu:tearoff-state ##### -->
135
<!-- ##### ARG GtkMenu:tearoff-title ##### -->
140
<!-- ##### ARG GtkMenu:bottom-attach ##### -->
145
<!-- ##### ARG GtkMenu:left-attach ##### -->
150
<!-- ##### ARG GtkMenu:right-attach ##### -->
155
<!-- ##### ARG GtkMenu:top-attach ##### -->
160
<!-- ##### ARG GtkMenu:arrow-placement ##### -->
165
<!-- ##### ARG GtkMenu:arrow-scaling ##### -->
170
<!-- ##### ARG GtkMenu:double-arrows ##### -->
175
<!-- ##### ARG GtkMenu:horizontal-offset ##### -->
180
<!-- ##### ARG GtkMenu:horizontal-padding ##### -->
185
<!-- ##### ARG GtkMenu:vertical-offset ##### -->
190
<!-- ##### ARG GtkMenu:vertical-padding ##### -->
195
<!-- ##### FUNCTION gtk_menu_new ##### -->
197
Creates a new #GtkMenu.
201
@Returns: a new #GtkMenu.
204
<!-- ##### FUNCTION gtk_menu_set_screen ##### -->
213
<!-- ##### MACRO gtk_menu_append ##### -->
215
Adds a new #GtkMenuItem to the end of the menu's item list.
219
@child: The #GtkMenuItem to add.
220
@Deprecated: Use gtk_menu_shell_append() instead.
223
<!-- ##### MACRO gtk_menu_prepend ##### -->
225
Adds a new #GtkMenuItem to the beginning of the menu's item list.
229
@child: The #GtkMenuItem to add.
230
@Deprecated: Use gtk_menu_shell_prepend() instead.
233
<!-- ##### MACRO gtk_menu_insert ##### -->
235
Adds a new #GtkMenuItem to the menu's item list at the position
236
indicated by @position.
240
@child: The #GtkMenuItem to add.
241
@pos: The position in the item list where @child is added.
242
Positions are numbered from 0 to n-1.
243
@Deprecated: Use gtk_menu_shell_insert() instead.
246
<!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
248
Moves a #GtkMenuItem to a new position within the #GtkMenu.
252
@child: the #GtkMenuItem to move.
253
@position: the new position to place @child. Positions are numbered from
257
<!-- ##### FUNCTION gtk_menu_attach ##### -->
270
<!-- ##### FUNCTION gtk_menu_popup ##### -->
282
<!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
284
Set the #GtkAccelGroup which holds global accelerators for the menu.
285
This accelerator group needs to also be added to all windows that
286
this menu is being used in with gtk_window_add_accel_group(), in order
287
for those windows to support all the accelerators contained in this group.
291
@accel_group: the #GtkAccelGroup to be associated with the menu.
294
<!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
296
Gets the #GtkAccelGroup which holds global accelerators for the menu.
297
See gtk_menu_set_accel_group().
301
@Returns: the #GtkAccelGroup associated with the menu.
304
<!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
313
<!-- ##### FUNCTION gtk_menu_get_accel_path ##### -->
322
<!-- ##### FUNCTION gtk_menu_set_title ##### -->
330
<!-- ##### FUNCTION gtk_menu_get_title ##### -->
339
<!-- ##### FUNCTION gtk_menu_set_monitor ##### -->
348
<!-- ##### FUNCTION gtk_menu_get_monitor ##### -->
357
<!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
366
<!-- ##### FUNCTION gtk_menu_set_reserve_toggle_size ##### -->
372
@reserve_toggle_size:
375
<!-- ##### FUNCTION gtk_menu_get_reserve_toggle_size ##### -->
384
<!-- ##### FUNCTION gtk_menu_popdown ##### -->
386
Removes the menu from the screen.
392
<!-- ##### FUNCTION gtk_menu_reposition ##### -->
394
Repositions the menu according to its position function.
400
<!-- ##### FUNCTION gtk_menu_get_active ##### -->
402
Returns the selected menu item from the menu. This is used by the
407
@Returns: the #GtkMenuItem that was last selected in the menu. If a
408
selection has not yet been made, the first menu item is selected.
411
<!-- ##### FUNCTION gtk_menu_set_active ##### -->
413
Selects the specified menu item within the menu. This is used by the
414
#GtkOptionMenu and should not be used by anyone else.
418
@index_: the index of the menu item to select. Index values are from
422
<!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
424
Changes the tearoff state of the menu. A menu is normally displayed
425
as drop down menu which persists as long as the menu is active. It can
426
also be displayed as a tearoff menu which persists until it is closed
431
@torn_off: If %TRUE, menu is displayed as a tearoff menu.
434
<!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
436
Attaches the menu to the widget and provides a callback function that will
437
be invoked when the menu calls gtk_menu_detach() during its destruction.
441
@attach_widget: the #GtkWidget that the menu will be attached to.
442
@detacher: the user supplied callback function that will be called when
443
the menu calls gtk_menu_detach().
446
<!-- ##### FUNCTION gtk_menu_detach ##### -->
448
Detaches the menu from the widget to which it had been attached.
449
This function will call the callback function, @detacher, provided
450
when the gtk_menu_attach_to_widget() function was called.
456
<!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
458
Returns the #GtkWidget that the menu is attached to.
462
@Returns: the #GtkWidget that the menu is attached to.
465
<!-- ##### FUNCTION gtk_menu_get_for_attach_widget ##### -->
474
<!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
476
A user function supplied when calling gtk_menu_popup() which controls the
477
positioning of the menu when it is displayed. The function sets the @x
478
and @y parameters to the coordinates where the menu is to be drawn.
479
To make the menu appear on a different monitor than the mouse pointer,
480
gtk_menu_set_monitor() must be called.
484
@x: address of the #gint representing the horizontal position where the
485
menu shall be drawn. This is an output parameter.
486
@y: address of the #gint representing the vertical position where the
487
menu shall be drawn. This is an output parameter.
488
@push_in: This parameter controls how menus placed outside the monitor are handled.
489
If this is set to %TRUE and part of the menu is outside the monitor then
490
GTK+ pushes the window into the visible area, effectively modifying the
492
Note that moving and possibly resizing the menu around will alter the
493
scroll position to keep the menu items "in place", i.e. at the same monitor
494
position they would have been without resizing.
495
In practice, this behavior is only useful for combobox popups or option
496
menus and cannot be used to simply confine a menu to monitor boundaries.
497
In that case, changing the scroll offset is not desirable.
498
@user_data: the data supplied by the user in the gtk_menu_popup() @data
502
<!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
504
A user function supplied when calling gtk_menu_attach_to_widget() which
505
will be called when the menu is later detached from the widget.
508
@attach_widget: the #GtkWidget that the menu is being detached from.
509
@menu: the #GtkMenu being detached.