]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkmenu.sgml
Merge branch 'master' into client-side-windows
[~andy/gtk] / docs / reference / gtk / tmpl / gtkmenu.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkMenu
3
4 <!-- ##### SECTION Short_Description ##### -->
5 A menu widget
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
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.
12 </para>
13
14 <para>
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.  
17 </para>
18
19 <para>
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 
22 as well.
23 </para>
24
25 <para>
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.  
29 </para>
30
31 <example>
32 <title>Connecting the popup signal handler.</title>
33 <programlisting>
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);
37 </programlisting>
38 </example>
39
40 <example>
41 <title>Signal handler which displays a popup menu.</title>
42 <programlisting>
43 static gint
44 my_popup_handler (GtkWidget *widget, GdkEvent *event)
45 {
46   GtkMenu *menu;
47   GdkEventButton *event_button;
48
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);
52
53   /* The "widget" is the menu that was supplied when 
54    * g_signal_connect_swapped() was called.
55    */
56   menu = GTK_MENU (widget);
57
58   if (event->type == GDK_BUTTON_PRESS)
59     {
60       event_button = (GdkEventButton *) event;
61       if (event_button->button == 3)
62         {
63           gtk_menu_popup (menu, NULL, NULL, NULL, NULL, 
64                           event_button->button, event_button->time);
65           return TRUE;
66         }
67     }
68
69   return FALSE;
70 }
71 </programlisting>
72 </example>
73
74 <!-- ##### SECTION See_Also ##### -->
75 <para>
76
77 </para>
78
79 <!-- ##### SECTION Stability_Level ##### -->
80
81
82 <!-- ##### STRUCT GtkMenu ##### -->
83 <para>
84 The #GtkMenu struct contains private data only, and
85 should be accessed using the functions below.
86 </para>
87
88
89 <!-- ##### SIGNAL GtkMenu::move-scroll ##### -->
90 <para>
91
92 </para>
93
94 @menu: the object which received the signal.
95 @arg1: 
96
97 <!-- ##### ARG GtkMenu:accel-group ##### -->
98 <para>
99
100 </para>
101
102 <!-- ##### ARG GtkMenu:accel-path ##### -->
103 <para>
104
105 </para>
106
107 <!-- ##### ARG GtkMenu:active ##### -->
108 <para>
109
110 </para>
111
112 <!-- ##### ARG GtkMenu:attach-widget ##### -->
113 <para>
114
115 </para>
116
117 <!-- ##### ARG GtkMenu:monitor ##### -->
118 <para>
119
120 </para>
121
122 <!-- ##### ARG GtkMenu:tearoff-state ##### -->
123 <para>
124
125 </para>
126
127 <!-- ##### ARG GtkMenu:tearoff-title ##### -->
128 <para>
129
130 </para>
131
132 <!-- ##### ARG GtkMenu:bottom-attach ##### -->
133 <para>
134
135 </para>
136
137 <!-- ##### ARG GtkMenu:left-attach ##### -->
138 <para>
139
140 </para>
141
142 <!-- ##### ARG GtkMenu:right-attach ##### -->
143 <para>
144
145 </para>
146
147 <!-- ##### ARG GtkMenu:top-attach ##### -->
148 <para>
149
150 </para>
151
152 <!-- ##### ARG GtkMenu:arrow-placement ##### -->
153 <para>
154
155 </para>
156
157 <!-- ##### ARG GtkMenu:arrow-scaling ##### -->
158 <para>
159
160 </para>
161
162 <!-- ##### ARG GtkMenu:double-arrows ##### -->
163 <para>
164
165 </para>
166
167 <!-- ##### ARG GtkMenu:horizontal-offset ##### -->
168 <para>
169
170 </para>
171
172 <!-- ##### ARG GtkMenu:horizontal-padding ##### -->
173 <para>
174
175 </para>
176
177 <!-- ##### ARG GtkMenu:vertical-offset ##### -->
178 <para>
179
180 </para>
181
182 <!-- ##### ARG GtkMenu:vertical-padding ##### -->
183 <para>
184
185 </para>
186
187 <!-- ##### FUNCTION gtk_menu_new ##### -->
188 <para>
189 Creates a new #GtkMenu.
190 </para>
191
192 @Returns: a new #GtkMenu.
193
194
195 <!-- ##### FUNCTION gtk_menu_set_screen ##### -->
196 <para>
197
198 </para>
199
200 @menu: 
201 @screen: 
202
203
204 <!-- ##### MACRO gtk_menu_append ##### -->
205 <para>
206 Adds a new #GtkMenuItem to the end of the menu's item list.
207 </para>
208
209 @menu: a #GtkMenu.
210 @child: The #GtkMenuItem to add.
211 @Deprecated: Use gtk_menu_shell_append() instead.
212
213
214 <!-- ##### MACRO gtk_menu_prepend ##### -->
215 <para>
216 Adds a new #GtkMenuItem to the beginning of the menu's item list.
217 </para>
218
219 @menu: a #GtkMenu.
220 @child: The #GtkMenuItem to add.
221 @Deprecated: Use gtk_menu_shell_prepend() instead.
222
223
224 <!-- ##### MACRO gtk_menu_insert ##### -->
225 <para>
226 Adds a new #GtkMenuItem to the menu's item list at the position
227 indicated by @position. 
228 </para>
229
230 @menu: a #GtkMenu.
231 @child: The #GtkMenuItem to add.
232 @pos: The position in the item list where @child is added.
233       Positions are numbered from 0 to n-1.
234 @Deprecated: Use gtk_menu_shell_insert() instead.
235
236
237 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
238 <para>
239 Moves a #GtkMenuItem to a new position within the #GtkMenu.
240 </para>
241
242 @menu: a #GtkMenu.
243 @child: the #GtkMenuItem to move.
244 @position: the new position to place @child.  Positions are numbered from 
245 0 to n-1.
246
247
248 <!-- ##### FUNCTION gtk_menu_attach ##### -->
249 <para>
250
251 </para>
252
253 @menu: 
254 @child: 
255 @left_attach: 
256 @right_attach: 
257 @top_attach: 
258 @bottom_attach: 
259
260
261 <!-- ##### FUNCTION gtk_menu_popup ##### -->
262
263
264 @menu: 
265 @parent_menu_shell: 
266 @parent_menu_item: 
267 @func: 
268 @data: 
269 @button: 
270 @activate_time: 
271
272
273 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
274 <para>
275 Set the #GtkAccelGroup which holds global accelerators for the menu.
276 This accelerator group needs to also be added to all windows that
277 this menu is being used in with gtk_window_add_accel_group(), in order
278 for those windows to support all the accelerators contained in this group.
279 </para>
280
281 @menu: a #GtkMenu.
282 @accel_group: the #GtkAccelGroup to be associated with the menu.
283
284
285 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
286 <para>
287 Gets the #GtkAccelGroup which holds global accelerators for the menu.
288 See gtk_menu_set_accel_group().
289 </para>
290
291 @menu: a #GtkMenu.
292 @Returns: the #GtkAccelGroup associated with the menu.
293
294
295 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
296 <para>
297
298 </para>
299
300 @menu: 
301 @accel_path: 
302
303
304 <!-- ##### FUNCTION gtk_menu_get_accel_path ##### -->
305 <para>
306
307 </para>
308
309 @menu: 
310 @Returns: 
311
312
313 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
314 <para>
315 </para>
316
317 @menu: 
318 @title: 
319
320
321 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
322 <para>
323
324 </para>
325
326 @menu: 
327 @Returns: 
328
329
330 <!-- ##### FUNCTION gtk_menu_set_monitor ##### -->
331 <para>
332
333 </para>
334
335 @menu: 
336 @monitor_num: 
337
338
339 <!-- ##### FUNCTION gtk_menu_get_monitor ##### -->
340 <para>
341
342 </para>
343
344 @menu: 
345 @Returns: 
346
347
348 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
349 <para>
350
351 </para>
352
353 @menu: 
354 @Returns: 
355
356
357 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
358 <para>
359 Removes the menu from the screen.
360 </para>
361
362 @menu: a #GtkMenu.
363
364
365 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
366 <para>
367 Repositions the menu according to its position function.
368 </para>
369
370 @menu: a #GtkMenu.
371
372
373 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
374 <para>
375 Returns the selected menu item from the menu.  This is used by the 
376 #GtkOptionMenu.
377 </para>
378
379 @menu: a #GtkMenu.
380 @Returns: the #GtkMenuItem that was last selected in the menu.  If a 
381 selection has not yet been made, the first menu item is selected.
382
383
384 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
385 <para>
386 Selects the specified menu item within the menu.  This is used by the
387 #GtkOptionMenu and should not be used by anyone else.
388 </para>
389
390 @menu: a #GtkMenu.
391 @index_: the index of the menu item to select.  Index values are from
392 0 to n-1.
393
394
395 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
396 <para>
397 Changes the tearoff state of the menu.  A menu is normally displayed 
398 as drop down menu which persists as long as the menu is active.  It can 
399 also be displayed as a tearoff menu which persists until it is closed 
400 or reattached.
401 </para>
402
403 @menu: a #GtkMenu.
404 @torn_off: If %TRUE, menu is displayed as a tearoff menu.
405
406
407 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
408 <para>
409 Attaches the menu to the widget and provides a callback function that will
410 be invoked when the menu calls gtk_menu_detach() during its destruction.
411 </para>
412
413 @menu: a #GtkMenu.
414 @attach_widget: the #GtkWidget that the menu will be attached to.
415 @detacher: the user supplied callback function that will be called when 
416 the menu calls gtk_menu_detach().
417
418
419 <!-- ##### FUNCTION gtk_menu_detach ##### -->
420 <para>
421 Detaches the menu from the widget to which it had been attached.  
422 This function will call the callback function, @detacher, provided
423 when the gtk_menu_attach_to_widget() function was called.
424 </para>
425
426 @menu: a #GtkMenu.
427
428
429 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
430 <para>
431 Returns the #GtkWidget that the menu is attached to.
432 </para>
433
434 @menu: a #GtkMenu.
435 @Returns: the #GtkWidget that the menu is attached to.
436
437
438 <!-- ##### FUNCTION gtk_menu_get_for_attach_widget ##### -->
439 <para>
440
441 </para>
442
443 @widget: 
444 @Returns: 
445
446
447 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
448 <para>
449 A user function supplied when calling gtk_menu_popup() which controls the
450 positioning of the menu when it is displayed.  The function sets the @x
451 and @y parameters to the coordinates where the menu is to be drawn.
452 To make the menu appear on a different monitor than the mouse pointer,
453 gtk_menu_set_monitor() must be called.
454 </para>
455
456 @menu: a #GtkMenu.
457 @x: address of the #gint representing the horizontal position where the
458 menu shall be drawn.  This is an output parameter.
459 @y: address of the #gint representing the vertical position where the
460 menu shall be drawn.  This is an output parameter.
461 @push_in: This parameter controls how menus placed outside the monitor are handled.
462         If this is set to %TRUE and part of the menu is outside the monitor then
463         GTK+ pushes the window into the visible area, effectively modifying the
464         popup position.
465         Note that moving and possibly resizing the menu around will alter the
466         scroll position to keep the menu items "in place", i.e. at the same monitor
467         position they would have been without resizing.
468         In practice, this behavior is only useful for combobox popups or option
469         menus and cannot be used to simply confine a menu to monitor boundaries.
470         In that case, changing the scroll offset is not desirable.
471 @user_data: the data supplied by the user in the gtk_menu_popup() @data
472 parameter.
473
474
475 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
476 <para>
477 A user function supplied when calling gtk_menu_attach_to_widget() which 
478 will be called when the menu is later detached from the widget.
479 </para>
480
481 @attach_widget: the #GtkWidget that the menu is being detached from.
482 @menu: the #GtkMenu being detached.
483
484