]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkdialog.sgml
2.13.5
[~andy/gtk] / docs / reference / gtk / tmpl / gtkdialog.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkDialog
3
4 <!-- ##### SECTION Short_Description ##### -->
5 Create popup windows
6
7 <!-- ##### SECTION Long_Description ##### -->
8
9 <para>
10 Dialog boxes are a convenient way to prompt the user for a small amount of
11 input, e.g. to display a message, ask a question, or anything else that does 
12 not require extensive effort on the user's part.
13 </para>
14
15 <para>
16 GTK+ treats a dialog as a window split vertically. The top section is a
17 #GtkVBox, and is where widgets such as a #GtkLabel or a #GtkEntry should
18 be packed. The bottom area is known as the
19 <structfield>action_area</structfield>. This is generally used for
20 packing buttons into the dialog which may perform functions such as
21 cancel, ok, or apply. The two areas are separated by a #GtkHSeparator.
22 </para>
23
24 <para>
25 #GtkDialog boxes are created with a call to gtk_dialog_new() or
26 gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it
27 allows you to set the dialog title, some convenient flags, and add simple
28 buttons.
29 </para>
30
31 <para>
32 If 'dialog' is a newly created dialog, the two primary areas of the window 
33 can be accessed through gtk_dialog_get_content_area() and
34 gtk_dialog_get_action_area(), as can be seen from the example, below.
35 </para>
36
37 <para>
38 A 'modal' dialog (that is, one which freezes the rest of the application from
39 user input), can be created by calling gtk_window_set_modal() on the dialog. Use
40 the GTK_WINDOW() macro to cast the widget returned from gtk_dialog_new() into a
41 #GtkWindow. When using gtk_dialog_new_with_buttons() you can also pass the
42 #GTK_DIALOG_MODAL flag to make a dialog modal.
43 </para>
44
45 <para>
46 If you add buttons to #GtkDialog using gtk_dialog_new_with_buttons(),
47 gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
48 gtk_dialog_add_action_widget(), clicking the button will emit a signal called
49 "response" with a response ID that you specified. GTK+ will never assign a
50 meaning to positive response IDs; these are entirely user-defined. But for
51 convenience, you can use the response IDs in the #GtkResponseType enumeration
52 (these all have values less than zero). If a dialog receives a delete event, 
53 the "response" signal will be emitted with a response ID of #GTK_RESPONSE_DELETE_EVENT.
54 </para>
55
56
57 <para>
58 If you want to block waiting for a dialog to return before returning control
59 flow to your code, you can call gtk_dialog_run(). This function enters a
60 recursive main loop and waits for the user to respond to the dialog, returning the 
61 response ID corresponding to the button the user clicked.
62 </para>
63
64 <para>
65 For the simple dialog in the following example, in reality you'd probably use
66 #GtkMessageDialog to save yourself some effort.  But you'd need to create the
67 dialog contents manually if you had more than a simple message in the dialog.
68 <example>
69 <title>Simple <structname>GtkDialog</structname> usage.</title>
70 <programlisting>
71
72 /* Function to open a dialog box displaying the message provided. */
73
74 void quick_message (gchar *message) {
75
76    GtkWidget *dialog, *label, *content_area;
77    
78    /* Create the widgets */
79    
80    dialog = gtk_dialog_new_with_buttons ("Message",
81                                          main_application_window,
82                                          GTK_DIALOG_DESTROY_WITH_PARENT,
83                                          GTK_STOCK_OK,
84                                          GTK_RESPONSE_NONE,
85                                          NULL);
86    content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
87    label = gtk_label_new (message);
88    
89    /* Ensure that the dialog box is destroyed when the user responds. */
90    
91    g_signal_connect_swapped (dialog,
92                              "response", 
93                              G_CALLBACK (gtk_widget_destroy),
94                              dialog);
95
96    /* Add the label, and show everything we've added to the dialog. */
97
98    gtk_container_add (GTK_CONTAINER (content_area), label);
99    gtk_widget_show_all (dialog);
100 }
101
102 </programlisting>
103 </example>
104 </para>
105
106 <refsect2 id="GtkDialog-BUILDER-UI"><title>GtkDialog as GtkBuildable</title>
107 <para>
108 The GtkDialog implementation of the GtkBuildable interface exposes the 
109 @vbox and @action_area as internal children with the names "vbox" and 
110 "action_area".
111 </para>
112 <para>
113 GtkDialog supports a custom &lt;action-widgets&gt; element, which 
114 can contain multiple &lt;action-widget&gt; elements. The "response"
115 attribute specifies a numeric response, and the content of the element
116 is the id of widget (which should be a child of the dialogs @action_area).
117 </para>
118 <example>
119 <title>A <structname>GtkDialog</structname> UI definition fragment.</title>
120 <programlisting><![CDATA[
121 <object class="GtkDialog" id="dialog1">
122   <child internal-child="vbox">"
123     <object class="GtkVBox">
124       <child internal-child="action_area">
125         <object class="GtkHButtonBox">
126           <child>
127             <object class="GtkButton" id="button_cancel"/>
128           </child>
129           <child>
130             <object class="GtkButton" id="button_ok"/>
131           </child>
132         </object>
133       </child>
134     </object>
135   </child>
136   <action-widgets>
137     <action-widget response="3">button_ok</action-widget>
138     <action-widget response="-5">button_cancel</action-widget>
139   </action-widgets>
140 </object>
141 ]]></programlisting>
142 </example>
143 </refsect2>
144
145 <!-- ##### SECTION See_Also ##### -->
146
147 <para>
148 <variablelist>
149 <varlistentry>
150 <term>#GtkVBox</term>
151 <listitem><para>Pack widgets vertically.</para></listitem>
152 </varlistentry>
153 <varlistentry>
154 <term>#GtkWindow</term>
155 <listitem><para>Alter the properties of your dialog box.</para></listitem>
156 </varlistentry>
157 <varlistentry>
158 <term>#GtkButton</term>
159 <listitem><para>Add them to the <structfield>action_area</structfield> to get a
160 response from the user.</para></listitem>
161 </varlistentry>
162 </variablelist>
163 </para>
164
165 <!-- ##### SECTION Stability_Level ##### -->
166
167
168 <!-- ##### STRUCT GtkDialog ##### -->
169 <para>
170 <structfield>vbox</structfield> is a #GtkVBox - the main part of the
171 dialog box.
172 </para>
173
174 <para>
175 <structfield>action_area</structfield> is a #GtkHButtonBox packed below the
176 dividing #GtkHSeparator in the dialog. It is treated exactly the same
177 as any other #GtkHButtonBox.
178 </para>
179
180
181 <!-- ##### SIGNAL GtkDialog::close ##### -->
182 <para>
183
184 </para>
185
186 @dialog: the object which received the signal.
187
188 <!-- ##### SIGNAL GtkDialog::response ##### -->
189 <para>
190
191 </para>
192
193 @dialog: 
194 @arg1: 
195
196 <!-- ##### ARG GtkDialog:has-separator ##### -->
197 <para>
198
199 </para>
200
201 <!-- ##### ARG GtkDialog:action-area-border ##### -->
202 <para>
203
204 </para>
205
206 <!-- ##### ARG GtkDialog:button-spacing ##### -->
207 <para>
208
209 </para>
210
211 <!-- ##### ARG GtkDialog:content-area-border ##### -->
212 <para>
213
214 </para>
215
216 <!-- ##### ENUM GtkDialogFlags ##### -->
217 <para>
218 Flags used to influence dialog construction.
219 </para>
220
221 @GTK_DIALOG_MODAL: Make the constructed dialog modal, 
222   see gtk_window_set_modal().
223 @GTK_DIALOG_DESTROY_WITH_PARENT: Destroy the dialog when its
224   parent is destroyed, see gtk_window_set_destroy_with_parent().
225 @GTK_DIALOG_NO_SEPARATOR: Don't put a separator between the
226   action area and the dialog content.
227
228 <!-- ##### ENUM GtkResponseType ##### -->
229 <para>
230 Predefined values for use as response ids in gtk_dialog_add_button().
231 All predefined values are negative, GTK+ leaves positive values for
232 application-defined response ids. 
233 </para>
234
235 @GTK_RESPONSE_NONE: Returned if an action widget has no response id, or if 
236    the dialog gets programmatically hidden or destroyed.
237 @GTK_RESPONSE_REJECT: Generic response id, not used by GTK+ dialogs.
238 @GTK_RESPONSE_ACCEPT: Generic response id, not used by GTK+ dialogs.
239 @GTK_RESPONSE_DELETE_EVENT: Returned if the dialog is deleted.
240 @GTK_RESPONSE_OK: Returned by OK buttons in GTK+ dialogs.
241 @GTK_RESPONSE_CANCEL: Returned by Cancel buttons in GTK+ dialogs.
242 @GTK_RESPONSE_CLOSE: Returned by Close buttons in GTK+ dialogs.
243 @GTK_RESPONSE_YES: Returned by Yes buttons in GTK+ dialogs.
244 @GTK_RESPONSE_NO: Returned by No buttons in GTK+ dialogs.
245 @GTK_RESPONSE_APPLY: Returned by Apply buttons in GTK+ dialogs.
246 @GTK_RESPONSE_HELP: Returned by Help buttons in GTK+ dialogs.
247
248 <!-- ##### FUNCTION gtk_dialog_new ##### -->
249 <para>
250 Creates a new dialog box. Widgets should not be packed into this #GtkWindow
251 directly, but into the @vbox and @action_area, as described above. 
252 </para>
253
254 @Returns: a new #GtkDialog.
255
256
257 <!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
258 <para>
259
260 </para>
261
262 @title: 
263 @parent: 
264 @flags: 
265 @first_button_text: 
266 @Varargs: 
267 @Returns: 
268
269
270 <!-- ##### FUNCTION gtk_dialog_run ##### -->
271 <para>
272
273 </para>
274
275 @dialog: 
276 @Returns: 
277
278
279 <!-- ##### FUNCTION gtk_dialog_response ##### -->
280 <para>
281
282 </para>
283
284 @dialog: 
285 @response_id: 
286
287
288 <!-- ##### FUNCTION gtk_dialog_add_button ##### -->
289 <para>
290
291 </para>
292
293 @dialog: 
294 @button_text: 
295 @response_id: 
296 @Returns: 
297
298
299 <!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
300 <para>
301
302 </para>
303
304 @dialog: 
305 @first_button_text: 
306 @Varargs: 
307
308
309 <!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
310 <para>
311
312 </para>
313
314 @dialog: 
315 @child: 
316 @response_id: 
317
318
319 <!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
320 <para>
321
322 </para>
323
324 @dialog: 
325 @Returns: 
326
327
328 <!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
329 <para>
330
331 </para>
332
333 @dialog: 
334 @response_id: 
335
336
337 <!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
338 <para>
339
340 </para>
341
342 @dialog: 
343 @setting: 
344
345
346 <!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
347 <para>
348
349 </para>
350
351 @dialog: 
352 @response_id: 
353 @setting: 
354
355
356 <!-- ##### FUNCTION gtk_dialog_get_response_for_widget ##### -->
357 <para>
358
359 </para>
360
361 @dialog: 
362 @widget: 
363 @Returns: 
364
365
366 <!-- ##### FUNCTION gtk_dialog_get_action_area ##### -->
367 <para>
368
369 </para>
370
371 @dialog: 
372 @Returns: 
373
374
375 <!-- ##### FUNCTION gtk_dialog_get_content_area ##### -->
376 <para>
377
378 </para>
379
380 @dialog: 
381 @Returns: 
382
383
384 <!-- ##### FUNCTION gtk_alternative_dialog_button_order ##### -->
385 <para>
386
387 </para>
388
389 @screen: 
390 @Returns: 
391
392
393 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order ##### -->
394 <para>
395
396 </para>
397
398 @dialog: 
399 @first_response_id: 
400 @Varargs: 
401
402
403 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order_from_array ##### -->
404 <para>
405
406 </para>
407
408 @dialog: 
409 @n_params: 
410 @new_order: 
411
412