]> Pileus Git - ~andy/gtk/blob - docs/reference/gtk/tmpl/gtkdialog.sgml
=== Released 2.5.0 ===
[~andy/gtk] / docs / reference / gtk / tmpl / gtkdialog.sgml
1 <!-- ##### SECTION Title ##### -->
2 GtkDialog
3
4 <!-- ##### SECTION Short_Description ##### -->
5
6 create popup windows.
7
8 <!-- ##### SECTION Long_Description ##### -->
9
10 <para>
11 Dialog boxes are a convenient way to prompt the user for a small amount of
12 input, eg. to display a message, ask a question, or anything else that does not
13 require extensive effort on the user's part.
14 </para>
15
16 <para>
17 GTK+ treats a dialog as a window split vertically. The top section is a
18 #GtkVBox, and is where widgets such as a #GtkLabel or a #GtkEntry should
19 be packed. The bottom area is known as the
20 <structfield>action_area</structfield>. This is generally used for
21 packing buttons into the dialog which may perform functions such as
22 cancel, ok, or apply. The two areas are separated by a #GtkHSeparator.
23 </para>
24
25 <para>
26 #GtkDialog boxes are created with a call to gtk_dialog_new() or
27 gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it
28 allows you to set the dialog title, some convenient flags, and add simple
29 buttons.
30 </para>
31
32 <para>
33 If 'dialog' is a newly created dialog, the two primary areas of the window 
34 can be accessed as <literal>GTK_DIALOG(dialog)->vbox</literal> and 
35 <literal>GTK_DIALOG(dialog)->action_area</literal>,
36 as can be seen from the example, below.
37 </para>
38
39 <para>
40 A 'modal' dialog (that is, one which freezes the rest of the application from
41 user input), can be created by calling gtk_window_set_modal() on the dialog. Use
42 the GTK_WINDOW() macro to cast the widget returned from gtk_dialog_new() into a
43 #GtkWindow. When using gtk_dialog_new_with_buttons() you can also pass the
44 #GTK_DIALOG_MODAL flag to make a dialog modal.
45 </para>
46
47 <para>
48 If you add buttons to #GtkDialog using gtk_dialog_new_with_buttons(),
49 gtk_dialog_add_button(), gtk_dialog_add_buttons(), or
50 gtk_dialog_add_action_widget(), clicking the button will emit a signal called
51 "response" with a response ID that you specified. GTK+ will never assign a
52 meaning to positive response IDs; these are entirely user-defined. But for
53 convenience, you can use the response IDs in the #GtkResponseType enumeration
54 (these all have values less than zero). If a dialog receives a delete event, the
55 "response" signal will be emitted with a response ID of #GTK_RESPONSE_NONE.
56 </para>
57
58
59 <para>
60 If you want to block waiting for a dialog to return before returning control
61 flow to your code, you can call gtk_dialog_run(). This function enters a
62 recursive main loop and waits for the user to respond to the dialog, returning the 
63 response ID corresponding to the button the user clicked.
64 </para>
65
66 <para>
67 For the simple dialog in the following example, in reality you'd probably use
68 #GtkMessageDialog to save yourself some effort.  But you'd need to create the
69 dialog contents manually if you had more than a simple message in the dialog.
70 <example>
71 <title>Simple <structname>GtkDialog</structname> usage.</title>
72 <programlisting>
73
74 /* Function to open a dialog box displaying the message provided. */
75
76 void quick_message (gchar *message) {
77
78    GtkWidget *dialog, *label;
79    
80    /* Create the widgets */
81    
82    dialog = gtk_dialog_new_with_buttons ("Message",
83                                          main_application_window,
84                                          GTK_DIALOG_DESTROY_WITH_PARENT,
85                                          GTK_STOCK_OK,
86                                          GTK_RESPONSE_NONE,
87                                          NULL);
88    label = gtk_label_new (message);
89    
90    /* Ensure that the dialog box is destroyed when the user responds. */
91    
92    g_signal_connect_swapped (dialog,
93                              "response", 
94                              G_CALLBACK (gtk_widget_destroy),
95                              dialog);
96
97    /* Add the label, and show everything we've added to the dialog. */
98
99    gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
100                       label);
101    gtk_widget_show_all (dialog);
102 }
103
104 </programlisting>
105 </example>
106 </para>
107
108 <!-- ##### SECTION See_Also ##### -->
109
110 <para>
111 <variablelist>
112 <varlistentry>
113 <term>#GtkVBox</term>
114 <listitem><para>Pack widgets vertically.</para></listitem>
115 </varlistentry>
116 <varlistentry>
117 <term>#GtkWindow</term>
118 <listitem><para>Alter the properties of your dialog box.</para></listitem>
119 </varlistentry>
120 <varlistentry>
121 <term>#GtkButton</term>
122 <listitem><para>Add them to the <structfield>action_area</structfield> to get a
123 response from the user.</para></listitem>
124 </varlistentry>
125 </variablelist>
126 </para>
127
128 <!-- ##### STRUCT GtkDialog ##### -->
129 <para>
130 <structfield>vbox</structfield> is a #GtkVBox - the main part of the
131 dialog box.
132 </para>
133
134 <para>
135 <structfield>action_area</structfield> is a #GtkHButtonBox packed below the
136 dividing #GtkHSeparator in the dialog. It is treated exactly the same
137 as any other #GtkHButtonBox.
138 </para>
139
140 @vbox: 
141 @action_area: 
142
143 <!-- ##### SIGNAL GtkDialog::close ##### -->
144 <para>
145
146 </para>
147
148 @dialog: the object which received the signal.
149
150 <!-- ##### SIGNAL GtkDialog::response ##### -->
151 <para>
152 Emitted when an action widget is clicked, the dialog receives a delete event, or
153 the application programmer calls gtk_dialog_response(). On a delete event, the
154 response ID is #GTK_RESPONSE_NONE. Otherwise, it depends on which action widget
155 was clicked.
156 </para>
157
158 @dialog: the object which received the signal.
159 @arg1: the response ID
160
161 <!-- ##### ARG GtkDialog:has-separator ##### -->
162 <para>
163
164 </para>
165
166 <!-- ##### ARG GtkDialog:action-area-border ##### -->
167 <para>
168
169 </para>
170
171 <!-- ##### ARG GtkDialog:button-spacing ##### -->
172 <para>
173
174 </para>
175
176 <!-- ##### ARG GtkDialog:content-area-border ##### -->
177 <para>
178
179 </para>
180
181 <!-- ##### ENUM GtkDialogFlags ##### -->
182 <para>
183
184 </para>
185
186 @GTK_DIALOG_MODAL: 
187 @GTK_DIALOG_DESTROY_WITH_PARENT: 
188 @GTK_DIALOG_NO_SEPARATOR: 
189
190 <!-- ##### ENUM GtkResponseType ##### -->
191 <para>
192
193 </para>
194
195 @GTK_RESPONSE_NONE: 
196 @GTK_RESPONSE_REJECT: 
197 @GTK_RESPONSE_ACCEPT: 
198 @GTK_RESPONSE_DELETE_EVENT: 
199 @GTK_RESPONSE_OK: 
200 @GTK_RESPONSE_CANCEL: 
201 @GTK_RESPONSE_CLOSE: 
202 @GTK_RESPONSE_YES: 
203 @GTK_RESPONSE_NO: 
204 @GTK_RESPONSE_APPLY: 
205 @GTK_RESPONSE_HELP: 
206
207 <!-- ##### FUNCTION gtk_dialog_new ##### -->
208 <para>
209 Creates a new dialog box. Widgets should not be packed into this #GtkWindow
210 directly, but into the @vbox and @action_area, as described above. 
211 </para>
212
213 @Returns: a new #GtkDialog.
214
215
216 <!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
217 <para>
218
219 </para>
220
221 @title: 
222 @parent: 
223 @flags: 
224 @first_button_text: 
225 @Varargs: 
226 @Returns: 
227
228
229 <!-- ##### FUNCTION gtk_dialog_run ##### -->
230 <para>
231
232 </para>
233
234 @dialog: 
235 @Returns: 
236
237
238 <!-- ##### FUNCTION gtk_dialog_response ##### -->
239 <para>
240
241 </para>
242
243 @dialog: 
244 @response_id: 
245
246
247 <!-- ##### FUNCTION gtk_dialog_add_button ##### -->
248 <para>
249
250 </para>
251
252 @dialog: 
253 @button_text: 
254 @response_id: 
255 @Returns: 
256
257
258 <!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
259 <para>
260
261 </para>
262
263 @dialog: 
264 @first_button_text: 
265 @Varargs: 
266
267
268 <!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
269 <para>
270
271 </para>
272
273 @dialog: 
274 @child: 
275 @response_id: 
276 <!-- # Unused Parameters # -->
277 @widget: 
278
279
280 <!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
281 <para>
282
283 </para>
284
285 @dialog: 
286 @Returns: 
287
288
289 <!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
290 <para>
291
292 </para>
293
294 @dialog: 
295 @response_id: 
296
297
298 <!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
299 <para>
300
301 </para>
302
303 @dialog: 
304 @setting: 
305
306
307 <!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
308 <para>
309
310 </para>
311
312 @dialog: 
313 @response_id: 
314 @setting: 
315
316