]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkdialog.sgml
f8503043a259f066a6368c9e81c2e07a93c457ba
[~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 <!-- ##### SECTION See_Also ##### -->
108
109 <para>
110 <variablelist>
111 <varlistentry>
112 <term>#GtkVBox</term>
113 <listitem><para>Pack widgets vertically.</para></listitem>
114 </varlistentry>
115 <varlistentry>
116 <term>#GtkWindow</term>
117 <listitem><para>Alter the properties of your dialog box.</para></listitem>
118 </varlistentry>
119 <varlistentry>
120 <term>#GtkButton</term>
121 <listitem><para>Add them to the <structfield>action_area</structfield> to get a
122 response from the user.</para></listitem>
123 </varlistentry>
124 </variablelist>
125 </para>
126
127 <!-- ##### SECTION Stability_Level ##### -->
128
129
130 <!-- ##### STRUCT GtkDialog ##### -->
131 <para>
132 <structfield>vbox</structfield> is a #GtkVBox - the main part of the
133 dialog box.
134 </para>
135
136 <para>
137 <structfield>action_area</structfield> is a #GtkHButtonBox packed below the
138 dividing #GtkHSeparator in the dialog. It is treated exactly the same
139 as any other #GtkHButtonBox.
140 </para>
141
142 @vbox: 
143 @action_area: 
144
145 <!-- ##### SIGNAL GtkDialog::close ##### -->
146 <para>
147
148 </para>
149
150 @dialog: the object which received the signal.
151
152 <!-- ##### SIGNAL GtkDialog::response ##### -->
153 <para>
154 Emitted when an action widget is clicked, the dialog receives a delete event, or
155 the application programmer calls gtk_dialog_response(). On a delete event, the
156 response ID is #GTK_RESPONSE_NONE. Otherwise, it depends on which action widget
157 was clicked.
158 </para>
159
160 @dialog: the object which received the signal.
161 @arg1: the response ID
162
163 <!-- ##### ARG GtkDialog:has-separator ##### -->
164 <para>
165
166 </para>
167
168 <!-- ##### ARG GtkDialog:action-area-border ##### -->
169 <para>
170
171 </para>
172
173 <!-- ##### ARG GtkDialog:button-spacing ##### -->
174 <para>
175
176 </para>
177
178 <!-- ##### ARG GtkDialog:content-area-border ##### -->
179 <para>
180
181 </para>
182
183 <!-- ##### ENUM GtkDialogFlags ##### -->
184 <para>
185 Flags used to influence dialog construction.
186 </para>
187
188 @GTK_DIALOG_MODAL: Make the constructed dialog modal, 
189   see gtk_widget_set_modal().
190 @GTK_DIALOG_DESTROY_WITH_PARENT: Destroy the dialog when its
191   parent is destroyed, see gtk_window_set_destroy_with_parent().
192 @GTK_DIALOG_NO_SEPARATOR: Don't put a separator between the
193   action area and the dialog content.
194
195 <!-- ##### ENUM GtkResponseType ##### -->
196 <para>
197 Predefined values for use as response ids in gtk_dialog_add_button().
198 All predefined values are negative, GTK+ leaves positive values for
199 application-defined response ids. 
200 </para>
201
202 @GTK_RESPONSE_NONE: Returned if an action widget has no response id, or if 
203    the dialog gets programmatically hidden or destroyed.
204 @GTK_RESPONSE_REJECT: Generic response id, not used by GTK+ dialogs.
205 @GTK_RESPONSE_ACCEPT: Generic response id, not used by GTK+ dialogs.
206 @GTK_RESPONSE_DELETE_EVENT: Returned if the dialog is deleted.
207 @GTK_RESPONSE_OK: Returned by OK buttons in GTK+ dialogs.
208 @GTK_RESPONSE_CANCEL: Returned by Cancel buttons in GTK+ dialogs.
209 @GTK_RESPONSE_CLOSE: Returned by Close buttons in GTK+ dialogs.
210 @GTK_RESPONSE_YES: Returned by Yes buttons in GTK+ dialogs.
211 @GTK_RESPONSE_NO: Returned by No buttons in GTK+ dialogs.
212 @GTK_RESPONSE_APPLY: Returned by Apply buttons in GTK+ dialogs.
213 @GTK_RESPONSE_HELP: Returned by Help buttons in GTK+ dialogs.
214
215 <!-- ##### FUNCTION gtk_dialog_new ##### -->
216 <para>
217 Creates a new dialog box. Widgets should not be packed into this #GtkWindow
218 directly, but into the @vbox and @action_area, as described above. 
219 </para>
220
221 @Returns: a new #GtkDialog.
222
223
224 <!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
225 <para>
226
227 </para>
228
229 @title: 
230 @parent: 
231 @flags: 
232 @first_button_text: 
233 @Varargs: 
234 @Returns: 
235
236
237 <!-- ##### FUNCTION gtk_dialog_run ##### -->
238 <para>
239
240 </para>
241
242 @dialog: 
243 @Returns: 
244
245
246 <!-- ##### FUNCTION gtk_dialog_response ##### -->
247 <para>
248
249 </para>
250
251 @dialog: 
252 @response_id: 
253
254
255 <!-- ##### FUNCTION gtk_dialog_add_button ##### -->
256 <para>
257
258 </para>
259
260 @dialog: 
261 @button_text: 
262 @response_id: 
263 @Returns: 
264
265
266 <!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
267 <para>
268
269 </para>
270
271 @dialog: 
272 @first_button_text: 
273 @Varargs: 
274
275
276 <!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
277 <para>
278
279 </para>
280
281 @dialog: 
282 @child: 
283 @response_id: 
284
285
286 <!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
287 <para>
288
289 </para>
290
291 @dialog: 
292 @Returns: 
293
294
295 <!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
296 <para>
297
298 </para>
299
300 @dialog: 
301 @response_id: 
302
303
304 <!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
305 <para>
306
307 </para>
308
309 @dialog: 
310 @setting: 
311
312
313 <!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
314 <para>
315
316 </para>
317
318 @dialog: 
319 @response_id: 
320 @setting: 
321
322
323 <!-- ##### FUNCTION gtk_dialog_get_response_for_widget ##### -->
324 <para>
325
326 </para>
327
328 @dialog: 
329 @widget: 
330 @Returns: 
331
332
333 <!-- ##### FUNCTION gtk_alternative_dialog_button_order ##### -->
334 <para>
335
336 </para>
337
338 @screen: 
339 @Returns: 
340
341
342 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order ##### -->
343 <para>
344
345 </para>
346
347 @dialog: 
348 @first_response_id: 
349 @Varargs: 
350
351
352 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order_from_array ##### -->
353 <para>
354
355 </para>
356
357 @dialog: 
358 @n_params: 
359 @new_order: 
360
361