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