]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkdialog.sgml
Additions
[~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><title>GtkDialog as a GtkBuildable</title>
108 <para>
109 GtkDialog exposes the @vbox and @action_area as internal children 
110 with the names "vbox" and "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 @vbox: 
181 @action_area: 
182
183 <!-- ##### SIGNAL GtkDialog::close ##### -->
184 <para>
185
186 </para>
187
188 @dialog: the object which received the signal.
189
190 <!-- ##### SIGNAL GtkDialog::response ##### -->
191 <para>
192 Emitted when an action widget is clicked, the dialog receives a delete event, or
193 the application programmer calls gtk_dialog_response(). On a delete event, the
194 response ID is #GTK_RESPONSE_NONE. Otherwise, it depends on which action widget
195 was clicked.
196 </para>
197
198 @dialog: the object which received the signal.
199 @arg1: the response ID
200
201 <!-- ##### ARG GtkDialog:has-separator ##### -->
202 <para>
203
204 </para>
205
206 <!-- ##### ARG GtkDialog:action-area-border ##### -->
207 <para>
208
209 </para>
210
211 <!-- ##### ARG GtkDialog:button-spacing ##### -->
212 <para>
213
214 </para>
215
216 <!-- ##### ARG GtkDialog:content-area-border ##### -->
217 <para>
218
219 </para>
220
221 <!-- ##### ENUM GtkDialogFlags ##### -->
222 <para>
223 Flags used to influence dialog construction.
224 </para>
225
226 @GTK_DIALOG_MODAL: Make the constructed dialog modal, 
227   see gtk_window_set_modal().
228 @GTK_DIALOG_DESTROY_WITH_PARENT: Destroy the dialog when its
229   parent is destroyed, see gtk_window_set_destroy_with_parent().
230 @GTK_DIALOG_NO_SEPARATOR: Don't put a separator between the
231   action area and the dialog content.
232
233 <!-- ##### ENUM GtkResponseType ##### -->
234 <para>
235 Predefined values for use as response ids in gtk_dialog_add_button().
236 All predefined values are negative, GTK+ leaves positive values for
237 application-defined response ids. 
238 </para>
239
240 @GTK_RESPONSE_NONE: Returned if an action widget has no response id, or if 
241    the dialog gets programmatically hidden or destroyed.
242 @GTK_RESPONSE_REJECT: Generic response id, not used by GTK+ dialogs.
243 @GTK_RESPONSE_ACCEPT: Generic response id, not used by GTK+ dialogs.
244 @GTK_RESPONSE_DELETE_EVENT: Returned if the dialog is deleted.
245 @GTK_RESPONSE_OK: Returned by OK buttons in GTK+ dialogs.
246 @GTK_RESPONSE_CANCEL: Returned by Cancel buttons in GTK+ dialogs.
247 @GTK_RESPONSE_CLOSE: Returned by Close buttons in GTK+ dialogs.
248 @GTK_RESPONSE_YES: Returned by Yes buttons in GTK+ dialogs.
249 @GTK_RESPONSE_NO: Returned by No buttons in GTK+ dialogs.
250 @GTK_RESPONSE_APPLY: Returned by Apply buttons in GTK+ dialogs.
251 @GTK_RESPONSE_HELP: Returned by Help buttons in GTK+ dialogs.
252
253 <!-- ##### FUNCTION gtk_dialog_new ##### -->
254 <para>
255 Creates a new dialog box. Widgets should not be packed into this #GtkWindow
256 directly, but into the @vbox and @action_area, as described above. 
257 </para>
258
259 @Returns: a new #GtkDialog.
260
261
262 <!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
263 <para>
264
265 </para>
266
267 @title: 
268 @parent: 
269 @flags: 
270 @first_button_text: 
271 @Varargs: 
272 @Returns: 
273
274
275 <!-- ##### FUNCTION gtk_dialog_run ##### -->
276 <para>
277
278 </para>
279
280 @dialog: 
281 @Returns: 
282
283
284 <!-- ##### FUNCTION gtk_dialog_response ##### -->
285 <para>
286
287 </para>
288
289 @dialog: 
290 @response_id: 
291
292
293 <!-- ##### FUNCTION gtk_dialog_add_button ##### -->
294 <para>
295
296 </para>
297
298 @dialog: 
299 @button_text: 
300 @response_id: 
301 @Returns: 
302
303
304 <!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
305 <para>
306
307 </para>
308
309 @dialog: 
310 @first_button_text: 
311 @Varargs: 
312
313
314 <!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
315 <para>
316
317 </para>
318
319 @dialog: 
320 @child: 
321 @response_id: 
322
323
324 <!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
325 <para>
326
327 </para>
328
329 @dialog: 
330 @Returns: 
331
332
333 <!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
334 <para>
335
336 </para>
337
338 @dialog: 
339 @response_id: 
340
341
342 <!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
343 <para>
344
345 </para>
346
347 @dialog: 
348 @setting: 
349
350
351 <!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
352 <para>
353
354 </para>
355
356 @dialog: 
357 @response_id: 
358 @setting: 
359
360
361 <!-- ##### FUNCTION gtk_dialog_get_response_for_widget ##### -->
362 <para>
363
364 </para>
365
366 @dialog: 
367 @widget: 
368 @Returns: 
369
370
371 <!-- ##### FUNCTION gtk_alternative_dialog_button_order ##### -->
372 <para>
373
374 </para>
375
376 @screen: 
377 @Returns: 
378
379
380 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order ##### -->
381 <para>
382
383 </para>
384
385 @dialog: 
386 @first_response_id: 
387 @Varargs: 
388
389
390 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order_from_array ##### -->
391 <para>
392
393 </para>
394
395 @dialog: 
396 @n_params: 
397 @new_order: 
398
399