]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkmenu.sgml
use g_file_test() instead of long deprecated g_scanner_stat_mode().
[~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     gtk_signal_connect_object(GTK_OBJECT(window), "button_press_event",
36         GTK_SIGNAL_FUNC (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    * gtk_signal_connect_object 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 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 <!-- # Unused Parameters # -->
100 @m: 
101 @c: 
102 @menu: a #GtkMenu.
103 @child: The #GtkMenuItem to add.
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 <!-- # Unused Parameters # -->
112 @m: 
113 @c: 
114 @menu: a #GtkMenu.
115 @child: The #GtkMenuItem to add.
116
117
118 <!-- ##### MACRO gtk_menu_insert ##### -->
119 <para>
120 Adds a new #GtkMenuItem to the menu's item list at the position
121 indicated by @position. 
122 </para>
123
124 <!-- # Unused Parameters # -->
125 @menu: a #GtkMenu.
126 @child: The #GtkMenuItem to add.
127 @position: The position in the item list where @child is added.
128 Positions are numbered from 0 to n-1.
129
130
131 <!-- ##### FUNCTION gtk_menu_reorder_child ##### -->
132 <para>
133 Moves a #GtkMenuItem to a new position within the #GtkMenu.
134 </para>
135
136 @menu: a #GtkMenu.
137 @child: the #GtkMenuItem to move.
138 @position: the new position to place @child.  Positions are numbered from 
139 0 to n-1.
140
141
142 <!-- ##### FUNCTION gtk_menu_popup ##### -->
143 <para>
144 Displays a menu and makes it available for selection.  Applications can use
145 this function to display context-sensitive menus, and will typically supply
146 NULL for the @parent_menu_shell, @parent_menu_item, @func and @data 
147 parameters.  The default menu positioning function will position the menu
148 at the current pointer position.
149 </para>
150
151 @menu: a #GtkMenu.
152 @parent_menu_shell: the menu shell containing the triggering menu item.
153 @parent_menu_item: the menu item whose activation triggered the popup.
154 @func: a user supplied function used to position the menu.
155 @data: user supplied data to be passed to @func.
156 @button: the button which was pressed to initiate the event.
157 @activate_time: the time at which the activation event occurred.
158
159
160 <!-- ##### FUNCTION gtk_menu_set_accel_group ##### -->
161 <para>
162 Set the #GtkAccelGroup which holds global accelerators for the menu.
163 </para>
164
165 @menu: a #GtkMenu.
166 @accel_group: the #GtkAccelGroup to be associated with the menu.
167
168
169 <!-- ##### FUNCTION gtk_menu_get_accel_group ##### -->
170 <para>
171
172 </para>
173
174 @menu: 
175 @Returns: 
176
177
178 <!-- ##### FUNCTION gtk_menu_set_title ##### -->
179 <para>
180 Sets the title string for the menu.  The title is displayed when the menu
181 is shown as a tearoff menu.
182 </para>
183
184 @menu: a #GtkMenu.
185 @title: a string containing the title for the menu.
186
187
188 <!-- ##### FUNCTION gtk_menu_popdown ##### -->
189 <para>
190 Removes the menu from the screen.
191 </para>
192
193 @menu: a #GtkMenu.
194
195
196 <!-- ##### FUNCTION gtk_menu_reposition ##### -->
197 <para>
198 Repositions the menu according to its position function.
199 </para>
200
201 @menu: a #GtkMenu.
202
203
204 <!-- ##### FUNCTION gtk_menu_get_active ##### -->
205 <para>
206 Returns the selected menu item from the menu.  This is used by the 
207 #GtkOptionMenu.
208 </para>
209
210 @menu: a #GtkMenu.
211 @Returns: the #GtkMenuItem that was last selected in the menu.  If a 
212 selection has not yet been made, the first menu item is selected.
213
214
215 <!-- ##### FUNCTION gtk_menu_set_active ##### -->
216 <para>
217 Selects the specified menu item within the menu.  This is used by the
218 #GtkOptionMenu.
219 </para>
220
221 @menu: a #GtkMenu.
222 @index: the index of the menu item to select.  Index values are from
223 0 to n-1.
224
225
226 <!-- ##### FUNCTION gtk_menu_set_tearoff_state ##### -->
227 <para>
228 Changes the tearoff state of the menu.  A menu is normally displayed 
229 as drop down menu which persists as long as the menu is active.  It can 
230 also be displayed as a tearoff menu which persists until it is closed 
231 or reattached.
232 </para>
233
234 @menu: a #GtkMenu.
235 @torn_off: If TRUE, menu is displayed as a tearoff menu.
236
237
238 <!-- ##### FUNCTION gtk_menu_attach_to_widget ##### -->
239 <para>
240 Attaches the menu to the widget and provides a callback function that will
241 be invoked when the menu calls gtk_menu_detach() during its destruction.
242 </para>
243
244 @menu: a #GtkMenu.
245 @attach_widget: the #GtkWidget that the menu will be attached to.
246 @detacher: the user supplied callback function that will be called when 
247 the menu calls gtk_menu_detach().
248
249
250 <!-- ##### FUNCTION gtk_menu_detach ##### -->
251 <para>
252 Detaches the menu from the widget to which it had been attached.  
253 This function will call the callback function, @detacher, provided
254 when the gtk_menu_attach_to_widget() function was called.
255 </para>
256
257 @menu: a #GtkMenu.
258
259
260 <!-- ##### FUNCTION gtk_menu_get_attach_widget ##### -->
261 <para>
262 Returns the #GtkWidget that the menu is attached to.
263 </para>
264
265 @menu: a #GtkMenu.
266 @Returns: the #GtkWidget that the menu is attached to.
267
268
269 <!-- ##### USER_FUNCTION GtkMenuPositionFunc ##### -->
270 <para>
271 A user function supplied when calling gtk_menu_popup() which controls the
272 positioning of the menu when it is displayed.  The function sets the @x
273 and @y parameters to the coordinates where the menu is to be drawn.
274 </para>
275
276 @menu: a #GtkMenu.
277 @x: address of the #gint representing the horizontal position where the
278 menu shall be drawn.  This is an output parameter.
279 @y: address of the #gint representing the vertical position where the
280 menu shall be drawn.  This is an output parameter.
281 @push_in: 
282 @user_data: the data supplied by the user in the gtk_menu_popup() @data
283 parameter.
284
285
286 <!-- ##### USER_FUNCTION GtkMenuDetachFunc ##### -->
287 <para>
288 A user function supplied when calling gtk_menu_attach_to_widget() which 
289 will be called when the menu is later detached from the widget.
290 </para>
291
292 @attach_widget: the #GtkWidget that the menu is being detached from.
293 @menu: the #GtkMenu being detached.
294
295