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