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:tearoff-state ##### -->
102 <!-- ##### ARG GtkMenu:tearoff-title ##### -->
107 <!-- ##### ARG GtkMenu:bottom-attach ##### -->
112 <!-- ##### ARG GtkMenu:left-attach ##### -->
117 <!-- ##### ARG GtkMenu:right-attach ##### -->
122 <!-- ##### ARG GtkMenu:top-attach ##### -->
127 <!-- ##### ARG GtkMenu:double-arrows ##### -->
132 <!-- ##### ARG GtkMenu:horizontal-offset ##### -->
137 <!-- ##### ARG GtkMenu:horizontal-padding ##### -->
142 <!-- ##### ARG GtkMenu:vertical-offset ##### -->
147 <!-- ##### ARG GtkMenu:vertical-padding ##### -->
152 <!-- ##### FUNCTION gtk_menu_new ##### -->
154 Creates a new #GtkMenu.
157 @Returns: a new #GtkMenu.
160 <!-- ##### FUNCTION gtk_menu_set_screen ##### -->
169 <!-- ##### MACRO gtk_menu_append ##### -->
171 Adds a new #GtkMenuItem to the end of the menu's item list.
175 @child: The #GtkMenuItem to add.
176 @Deprecated: Use gtk_menu_shell_append() instead.
179 <!-- ##### MACRO gtk_menu_prepend ##### -->
181 Adds a new #GtkMenuItem to the beginning of the menu's item list.
185 @child: The #GtkMenuItem to add.
186 @Deprecated: Use gtk_menu_shell_prepend() instead.
189 <!-- ##### MACRO gtk_menu_insert ##### -->
191 Adds a new #GtkMenuItem to the menu's item list at the position
192 indicated by @position.
196 @child: The #GtkMenuItem to add.
197 @pos: The position in the item list where @child is added.
198 Positions are numbered from 0 to n-1.
199 @Deprecated: Use gtk_menu_shell_insert() instead.
202 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
204 Moves a #GtkMenuItem to a new position within the #GtkMenu.
208 @child: the #GtkMenuItem to move.
209 @position: the new position to place @child. Positions are numbered from
213 <!-- ##### FUNCTION gtk_menu_attach ##### -->
226 <!-- ##### FUNCTION gtk_menu_popup ##### -->
238 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
240 Set the #GtkAccelGroup which holds global accelerators for the menu.
241 This accelerator group needs to also be added to all windows that
242 this menu is being used in with gtk_window_add_accel_group(), in order
243 for those windows to support all the accelerators contained in this group.
247 @accel_group: the #GtkAccelGroup to be associated with the menu.
250 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
252 Gets the #GtkAccelGroup which holds global accelerators for the menu.
253 See gtk_menu_set_accel_group().
257 @Returns: the #GtkAccelGroup associated with the menu.
260 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
269 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
277 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
286 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
295 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
297 Removes the menu from the screen.
303 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
305 Repositions the menu according to its position function.
311 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
313 Returns the selected menu item from the menu. This is used by the
318 @Returns: the #GtkMenuItem that was last selected in the menu. If a
319 selection has not yet been made, the first menu item is selected.
322 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
324 Selects the specified menu item within the menu. This is used by the
325 #GtkOptionMenu and should not be used by anyone else.
329 @index_: the index of the menu item to select. Index values are from
333 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
335 Changes the tearoff state of the menu. A menu is normally displayed
336 as drop down menu which persists as long as the menu is active. It can
337 also be displayed as a tearoff menu which persists until it is closed
342 @torn_off: If %TRUE, menu is displayed as a tearoff menu.
345 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
347 Attaches the menu to the widget and provides a callback function that will
348 be invoked when the menu calls gtk_menu_detach() during its destruction.
352 @attach_widget: the #GtkWidget that the menu will be attached to.
353 @detacher: the user supplied callback function that will be called when
354 the menu calls gtk_menu_detach().
357 <!-- ##### FUNCTION gtk_menu_detach ##### -->
359 Detaches the menu from the widget to which it had been attached.
360 This function will call the callback function, @detacher, provided
361 when the gtk_menu_attach_to_widget() function was called.
367 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
369 Returns the #GtkWidget that the menu is attached to.
373 @Returns: the #GtkWidget that the menu is attached to.
376 <!-- ##### FUNCTION gtk_menu_get_for_attach_widget ##### -->
385 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
387 A user function supplied when calling gtk_menu_popup() which controls the
388 positioning of the menu when it is displayed. The function sets the @x
389 and @y parameters to the coordinates where the menu is to be drawn.
393 @x: address of the #gint representing the horizontal position where the
394 menu shall be drawn. This is an output parameter.
395 @y: address of the #gint representing the vertical position where the
396 menu shall be drawn. This is an output parameter.
397 @push_in: whether the first menu item should be offset (pushed in) to be
398 aligned with the menu popup position (only useful for GtkOptionMenu).
399 @user_data: the data supplied by the user in the gtk_menu_popup() @data
403 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
405 A user function supplied when calling gtk_menu_attach_to_widget() which
406 will be called when the menu is later detached from the widget.
409 @attach_widget: the #GtkWidget that the menu is being detached from.
410 @menu: the #GtkMenu being detached.
413 <!-- ##### FUNCTION gtk_menu_set_monitor ##### -->