]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkmenu.sgml
s/columns/rows/ in docs. (#70199)
[~andy/gtk] / docs / reference / gtk / tmpl / gtkmenu.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkMenu
3
4 <!-- ##### SECTION Short_Description ##### -->
5 a drop down 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 (GTK_OBJECT (window), "button_press_event",
36         G_CALLBACK (my_popup_handler), GTK_OBJECT (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 <!-- ##### STRUCT GtkMenu ##### -->
80 <para>
81 The #GtkMenu struct contains private data only, and
82 should be accessed using the functions below.
83 </para>
84
85
86 <!-- ##### FUNCTION gtk_menu_new ##### -->
87 <para>
88 Creates a new #GtkMenu.
89 </para>
90
91 @Returns: a new #GtkMenu.
92
93
94 <!-- ##### MACRO gtk_menu_append ##### -->
95 <para>
96 Adds a new #GtkMenuItem to the end of the menu's item list.
97 </para>
98
99 @menu: a #GtkMenu.
100 @child: The #GtkMenuItem to add.
101 <!-- # Unused Parameters # -->
102 @m: 
103 @c: 
104
105
106 <!-- ##### MACRO gtk_menu_prepend ##### -->
107 <para>
108 Adds a new #GtkMenuItem to the beginning of the menu's item list.
109 </para>
110
111 @menu: a #GtkMenu.
112 @child: The #GtkMenuItem to add.
113 <!-- # Unused Parameters # -->
114 @menu_child: 
115 @m: 
116 @c: 
117
118
119 <!-- ##### MACRO gtk_menu_insert ##### -->
120 <para>
121 Adds a new #GtkMenuItem to the menu's item list at the position
122 indicated by @position. 
123 </para>
124
125 @menu: a #GtkMenu.
126 @child: The #GtkMenuItem to add.
127 @pos: 
128 <!-- # Unused Parameters # -->
129 @position: The position in the item list where @child is added.
130 Positions are numbered from 0 to n-1.
131
132
133 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
134 <para>
135 Moves a #GtkMenuItem to a new position within the #GtkMenu.
136 </para>
137
138 @menu: a #GtkMenu.
139 @child: the #GtkMenuItem to move.
140 @position: the new position to place @child.  Positions are numbered from 
141 0 to n-1.
142
143
144 <!-- ##### FUNCTION gtk_menu_popup ##### -->
145 <para>
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.
151 </para>
152
153 @menu: a #GtkMenu.
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.
160
161
162 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
163 <para>
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.
168 </para>
169
170 @menu: a #GtkMenu.
171 @accel_group: the #GtkAccelGroup to be associated with the menu.
172
173
174 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
175 <para>
176 Gets the #GtkAccelGroup which holds global accelerators for the menu.
177 See gtk_menu_set_accel_group().
178 </para>
179
180 @menu: a #GtkMenu.
181 @Returns: the #GtkAccelGroup associated with the menu.
182
183
184 <!-- ##### FUNCTION gtk_menu_set_accel_path ##### -->
185 <para>
186
187 </para>
188
189 @menu: 
190 @accel_path: 
191
192
193 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
194 <para>
195 </para>
196
197 @menu: 
198 @title: 
199
200
201 <!-- ##### FUNCTION gtk_menu_get_tearoff_state ##### -->
202 <para>
203
204 </para>
205
206 @menu: 
207 @Returns: 
208
209
210 <!-- ##### FUNCTION gtk_menu_get_title ##### -->
211 <para>
212
213 </para>
214
215 @menu: 
216 @Returns: 
217
218
219 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
220 <para>
221 Removes the menu from the screen.
222 </para>
223
224 @menu: a #GtkMenu.
225
226
227 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
228 <para>
229 Repositions the menu according to its position function.
230 </para>
231
232 @menu: a #GtkMenu.
233
234
235 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
236 <para>
237 Returns the selected menu item from the menu.  This is used by the 
238 #GtkOptionMenu.
239 </para>
240
241 @menu: a #GtkMenu.
242 @Returns: the #GtkMenuItem that was last selected in the menu.  If a 
243 selection has not yet been made, the first menu item is selected.
244
245
246 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
247 <para>
248 Selects the specified menu item within the menu.  This is used by the
249 #GtkOptionMenu and should not be used by anyone else.
250 </para>
251
252 @menu: a #GtkMenu.
253 @index: the index of the menu item to select.  Index values are from
254 0 to n-1.
255
256
257 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
258 <para>
259 Changes the tearoff state of the menu.  A menu is normally displayed 
260 as drop down menu which persists as long as the menu is active.  It can 
261 also be displayed as a tearoff menu which persists until it is closed 
262 or reattached.
263 </para>
264
265 @menu: a #GtkMenu.
266 @torn_off: If %TRUE, menu is displayed as a tearoff menu.
267
268
269 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
270 <para>
271 Attaches the menu to the widget and provides a callback function that will
272 be invoked when the menu calls gtk_menu_detach() during its destruction.
273 </para>
274
275 @menu: a #GtkMenu.
276 @attach_widget: the #GtkWidget that the menu will be attached to.
277 @detacher: the user supplied callback function that will be called when 
278 the menu calls gtk_menu_detach().
279
280
281 <!-- ##### FUNCTION gtk_menu_detach ##### -->
282 <para>
283 Detaches the menu from the widget to which it had been attached.  
284 This function will call the callback function, @detacher, provided
285 when the gtk_menu_attach_to_widget() function was called.
286 </para>
287
288 @menu: a #GtkMenu.
289
290
291 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
292 <para>
293 Returns the #GtkWidget that the menu is attached to.
294 </para>
295
296 @menu: a #GtkMenu.
297 @Returns: the #GtkWidget that the menu is attached to.
298
299
300 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
301 <para>
302 A user function supplied when calling gtk_menu_popup() which controls the
303 positioning of the menu when it is displayed.  The function sets the @x
304 and @y parameters to the coordinates where the menu is to be drawn.
305 </para>
306
307 @menu: a #GtkMenu.
308 @x: address of the #gint representing the horizontal position where the
309 menu shall be drawn.  This is an output parameter.
310 @y: address of the #gint representing the vertical position where the
311 menu shall be drawn.  This is an output parameter.
312 @push_in: 
313 @user_data: the data supplied by the user in the gtk_menu_popup() @data
314 parameter.
315
316
317 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
318 <para>
319 A user function supplied when calling gtk_menu_attach_to_widget() which 
320 will be called when the menu is later detached from the widget.
321 </para>
322
323 @attach_widget: the #GtkWidget that the menu is being detached from.
324 @menu: the #GtkMenu being detached.
325
326
327 <!-- ##### ARG GtkMenu:tearoff-title ##### -->
328 <para>
329
330 </para>
331