1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
5 a drop down menu widget.
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 gtk_signal_connect_object(GTK_OBJECT(window), "button_press_event",
36 GTK_SIGNAL_FUNC (my_popup_handler), GTK_OBJECT(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 * gtk_signal_connect_object 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 <!-- ##### STRUCT GtkMenu ##### -->
81 The #GtkMenu-struct struct contains private data only, and
82 should be accessed using the functions below.
86 <!-- ##### FUNCTION gtk_menu_new ##### -->
88 Creates a new #GtkMenu.
91 @Returns: a new #GtkMenu.
94 <!-- ##### MACRO gtk_menu_append ##### -->
96 Adds a new #GtkMenuItem to the end of the menu's item list.
99 <!-- # Unused Parameters # -->
101 @child: The #GtkMenuItem to add.
106 <!-- ##### MACRO gtk_menu_prepend ##### -->
108 Adds a new #GtkMenuItem to the beginning of the menu's item list.
111 <!-- # Unused Parameters # -->
113 @child: The #GtkMenuItem to add.
119 <!-- ##### MACRO gtk_menu_insert ##### -->
121 Adds a new #GtkMenuItem to the menu's item list at the position
122 indicated by @position.
125 <!-- # Unused Parameters # -->
127 @child: The #GtkMenuItem to add.
129 @position: The position in the item list where @child is added.
130 Positions are numbered from 0 to n-1.
133 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
135 Moves a #GtkMenuItem to a new position within the #GtkMenu.
139 @child: the #GtkMenuItem to move.
140 @position: the new position to place @child. Positions are numbered from
144 <!-- ##### FUNCTION gtk_menu_popup ##### -->
146 Displays a menu and makes it available for selection. Applications can use
147 this function to display context-sensitive menus, and will typically supply
148 NULL for the @parent_menu_shell, @parent_menu_item, @func and @data
149 parameters. The default menu positioning function will position the menu
150 at the current pointer position.
154 @parent_menu_shell: the menu shell containing the triggering menu item.
155 @parent_menu_item: the menu item whose activation triggered the popup.
156 @func: a user supplied function used to position the menu.
157 @data: user supplied data to be passed to @func.
158 @button: the button which was pressed to initiate the event.
159 @activate_time: the time at which the activation event occurred.
162 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
164 Set the #GtkAccelGroup which holds global accelerators for the menu.
165 This accelerator group needs to also be added to all windows that
166 this menu is being used in with gtk_window_add_accel_group(), in order
167 for those windows to support all the accelerators contained in this group.
171 @accel_group: the #GtkAccelGroup to be associated with the menu.
174 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
176 Gets the #GtkAccelGroup which holds global accelerators for the menu.
177 See gtk_menu_set_accel_group().
181 @Returns: the #GtkAccelGroup associated with the menu.
184 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
193 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
195 Sets the title string for the menu. The title is displayed when the menu
196 is shown as a tearoff menu.
200 @title: a string containing the title for the menu.
203 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
212 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
221 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
223 Removes the menu from the screen.
229 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
231 Repositions the menu according to its position function.
237 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
239 Returns the selected menu item from the menu. This is used by the
244 @Returns: the #GtkMenuItem that was last selected in the menu. If a
245 selection has not yet been made, the first menu item is selected.
248 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
250 Selects the specified menu item within the menu. This is used by the
255 @index: the index of the menu item to select. Index values are from
259 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
261 Changes the tearoff state of the menu. A menu is normally displayed
262 as drop down menu which persists as long as the menu is active. It can
263 also be displayed as a tearoff menu which persists until it is closed
268 @torn_off: If TRUE, menu is displayed as a tearoff menu.
271 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
273 Attaches the menu to the widget and provides a callback function that will
274 be invoked when the menu calls gtk_menu_detach() during its destruction.
278 @attach_widget: the #GtkWidget that the menu will be attached to.
279 @detacher: the user supplied callback function that will be called when
280 the menu calls gtk_menu_detach().
283 <!-- ##### FUNCTION gtk_menu_detach ##### -->
285 Detaches the menu from the widget to which it had been attached.
286 This function will call the callback function, @detacher, provided
287 when the gtk_menu_attach_to_widget() function was called.
293 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
295 Returns the #GtkWidget that the menu is attached to.
299 @Returns: the #GtkWidget that the menu is attached to.
302 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
304 A user function supplied when calling gtk_menu_popup() which controls the
305 positioning of the menu when it is displayed. The function sets the @x
306 and @y parameters to the coordinates where the menu is to be drawn.
310 @x: address of the #gint representing the horizontal position where the
311 menu shall be drawn. This is an output parameter.
312 @y: address of the #gint representing the vertical position where the
313 menu shall be drawn. This is an output parameter.
315 @user_data: the data supplied by the user in the gtk_menu_popup() @data
319 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
321 A user function supplied when calling gtk_menu_attach_to_widget() which
322 will be called when the menu is later detached from the widget.
325 @attach_widget: the #GtkWidget that the menu is being detached from.
326 @menu: the #GtkMenu being detached.
329 <!-- ##### ARG GtkMenu:tearoff-title ##### -->