]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkmenu.sgml
2.13.4
[~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:double-arrows ##### -->
153 <para>
154
155 </para>
156
157 <!-- ##### ARG GtkMenu:horizontal-offset ##### -->
158 <para>
159
160 </para>
161
162 <!-- ##### ARG GtkMenu:horizontal-padding ##### -->
163 <para>
164
165 </para>
166
167 <!-- ##### ARG GtkMenu:vertical-offset ##### -->
168 <para>
169
170 </para>
171
172 <!-- ##### ARG GtkMenu:vertical-padding ##### -->
173 <para>
174
175 </para>
176
177 <!-- ##### FUNCTION gtk_menu_new ##### -->
178 <para>
179 Creates a new #GtkMenu.
180 </para>
181
182 @Returns: a new #GtkMenu.
183
184
185 <!-- ##### FUNCTION gtk_menu_set_screen ##### -->
186 <para>
187
188 </para>
189
190 @menu: 
191 @screen: 
192
193
194 <!-- ##### MACRO gtk_menu_append ##### -->
195 <para>
196 Adds a new #GtkMenuItem to the end of the menu's item list.
197 </para>
198
199 @menu: a #GtkMenu.
200 @child: The #GtkMenuItem to add.
201 @Deprecated: Use gtk_menu_shell_append() instead.
202
203
204 <!-- ##### MACRO gtk_menu_prepend ##### -->
205 <para>
206 Adds a new #GtkMenuItem to the beginning 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_prepend() instead.
212
213
214 <!-- ##### MACRO gtk_menu_insert ##### -->
215 <para>
216 Adds a new #GtkMenuItem to the menu's item list at the position
217 indicated by @position. 
218 </para>
219
220 @menu: a #GtkMenu.
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.
225
226
227 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
228 <para>
229 Moves a #GtkMenuItem to a new position within the #GtkMenu.
230 </para>
231
232 @menu: a #GtkMenu.
233 @child: the #GtkMenuItem to move.
234 @position: the new position to place @child.  Positions are numbered from 
235 0 to n-1.
236
237
238 <!-- ##### FUNCTION gtk_menu_attach ##### -->
239 <para>
240
241 </para>
242
243 @menu: 
244 @child: 
245 @left_attach: 
246 @right_attach: 
247 @top_attach: 
248 @bottom_attach: 
249
250
251 <!-- ##### FUNCTION gtk_menu_popup ##### -->
252
253
254 @menu: 
255 @parent_menu_shell: 
256 @parent_menu_item: 
257 @func: 
258 @data: 
259 @button: 
260 @activate_time: 
261
262
263 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
264 <para>
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.
269 </para>
270
271 @menu: a #GtkMenu.
272 @accel_group: the #GtkAccelGroup to be associated with the menu.
273
274
275 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
276 <para>
277 Gets the #GtkAccelGroup which holds global accelerators for the menu.
278 See gtk_menu_set_accel_group().
279 </para>
280
281 @menu: a #GtkMenu.
282 @Returns: the #GtkAccelGroup associated with the menu.
283
284
285 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
286 <para>
287
288 </para>
289
290 @menu: 
291 @accel_path: 
292
293
294 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
295 <para>
296 </para>
297
298 @menu: 
299 @title: 
300
301
302 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
303 <para>
304
305 </para>
306
307 @menu: 
308 @Returns: 
309
310
311 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
312 <para>
313
314 </para>
315
316 @menu: 
317 @Returns: 
318
319
320 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
321 <para>
322 Removes the menu from the screen.
323 </para>
324
325 @menu: a #GtkMenu.
326
327
328 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
329 <para>
330 Repositions the menu according to its position function.
331 </para>
332
333 @menu: a #GtkMenu.
334
335
336 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
337 <para>
338 Returns the selected menu item from the menu.  This is used by the 
339 #GtkOptionMenu.
340 </para>
341
342 @menu: a #GtkMenu.
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.
345
346
347 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
348 <para>
349 Selects the specified menu item within the menu.  This is used by the
350 #GtkOptionMenu and should not be used by anyone else.
351 </para>
352
353 @menu: a #GtkMenu.
354 @index_: the index of the menu item to select.  Index values are from
355 0 to n-1.
356
357
358 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
359 <para>
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 
363 or reattached.
364 </para>
365
366 @menu: a #GtkMenu.
367 @torn_off: If %TRUE, menu is displayed as a tearoff menu.
368
369
370 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
371 <para>
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.
374 </para>
375
376 @menu: a #GtkMenu.
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().
380
381
382 <!-- ##### FUNCTION gtk_menu_detach ##### -->
383 <para>
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.
387 </para>
388
389 @menu: a #GtkMenu.
390
391
392 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
393 <para>
394 Returns the #GtkWidget that the menu is attached to.
395 </para>
396
397 @menu: a #GtkMenu.
398 @Returns: the #GtkWidget that the menu is attached to.
399
400
401 <!-- ##### FUNCTION gtk_menu_get_for_attach_widget ##### -->
402 <para>
403
404 </para>
405
406 @widget: 
407 @Returns: 
408
409
410 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
411 <para>
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.
415 </para>
416
417 @menu: a #GtkMenu.
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
425         popup position.
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
436 parameter.
437
438
439 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
440 <para>
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.
443 </para>
444
445 @attach_widget: the #GtkWidget that the menu is being detached from.
446 @menu: the #GtkMenu being detached.
447
448
449 <!-- ##### FUNCTION gtk_menu_set_monitor ##### -->
450 <para>
451
452 </para>
453
454 @menu: 
455 @monitor_num: 
456
457