~ubuntu-branches/ubuntu/raring/gtk+2.0/raring-proposed

« back to all changes in this revision

Viewing changes to docs/reference/gtk/tmpl/gtkdialog.sgml

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2012-02-06 22:03:26 UTC
  • mfrom: (1.14.12)
  • Revision ID: package-import@ubuntu.com-20120206220326-10d7cnkpdpbi9iox
Tags: 2.24.10-0ubuntu1
* New upstream version, dropped patches included in the new version
* debian/patches/090_logging_file_saves.patch:
  - improve the logging of saved filed, thanks Siegfried Gevatter 
    (lp: #920961)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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" id="vbox">
 
124
      <child internal-child="action_area">
 
125
        <object class="GtkHButtonBox" id="button_box">
 
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
<!-- ##### SECTION Image ##### -->
 
169
 
 
170
 
 
171
<!-- ##### STRUCT GtkDialog ##### -->
 
172
<para>
 
173
<structfield>vbox</structfield> is a #GtkVBox - the main part of the
 
174
dialog box.
 
175
</para>
 
176
 
 
177
<para>
 
178
<structfield>action_area</structfield> is a #GtkHButtonBox packed below the
 
179
dividing #GtkHSeparator in the dialog. It is treated exactly the same
 
180
as any other #GtkHButtonBox.
 
181
</para>
 
182
 
 
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
<!-- ##### ARG GtkDialog:content-area-spacing ##### -->
 
220
<para>
 
221
 
 
222
</para>
 
223
 
 
224
<!-- ##### ENUM GtkDialogFlags ##### -->
 
225
<para>
 
226
Flags used to influence dialog construction.
 
227
</para>
 
228
 
 
229
@GTK_DIALOG_MODAL: Make the constructed dialog modal, 
 
230
  see gtk_window_set_modal().
 
231
@GTK_DIALOG_DESTROY_WITH_PARENT: Destroy the dialog when its
 
232
  parent is destroyed, see gtk_window_set_destroy_with_parent().
 
233
@GTK_DIALOG_NO_SEPARATOR: Don't put a separator between the
 
234
  action area and the dialog content. This option has been deprecated in GTK+ 2.22. It will be removed in GTK+ 3
 
235
 
 
236
<!-- ##### ENUM GtkResponseType ##### -->
 
237
<para>
 
238
Predefined values for use as response ids in gtk_dialog_add_button().
 
239
All predefined values are negative, GTK+ leaves positive values for
 
240
application-defined response ids. 
 
241
</para>
 
242
 
 
243
@GTK_RESPONSE_NONE: Returned if an action widget has no response id, or if 
 
244
   the dialog gets programmatically hidden or destroyed.
 
245
@GTK_RESPONSE_REJECT: Generic response id, not used by GTK+ dialogs.
 
246
@GTK_RESPONSE_ACCEPT: Generic response id, not used by GTK+ dialogs.
 
247
@GTK_RESPONSE_DELETE_EVENT: Returned if the dialog is deleted.
 
248
@GTK_RESPONSE_OK: Returned by OK buttons in GTK+ dialogs.
 
249
@GTK_RESPONSE_CANCEL: Returned by Cancel buttons in GTK+ dialogs.
 
250
@GTK_RESPONSE_CLOSE: Returned by Close buttons in GTK+ dialogs.
 
251
@GTK_RESPONSE_YES: Returned by Yes buttons in GTK+ dialogs.
 
252
@GTK_RESPONSE_NO: Returned by No buttons in GTK+ dialogs.
 
253
@GTK_RESPONSE_APPLY: Returned by Apply buttons in GTK+ dialogs.
 
254
@GTK_RESPONSE_HELP: Returned by Help buttons in GTK+ dialogs.
 
255
 
 
256
<!-- ##### FUNCTION gtk_dialog_new ##### -->
 
257
<para>
 
258
Creates a new dialog box. Widgets should not be packed into this #GtkWindow
 
259
directly, but into the @vbox and @action_area, as described above. 
 
260
</para>
 
261
 
 
262
@void: 
 
263
@Returns: a new #GtkDialog.
 
264
 
 
265
 
 
266
<!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
 
267
<para>
 
268
 
 
269
</para>
 
270
 
 
271
@title: 
 
272
@parent: 
 
273
@flags: 
 
274
@first_button_text: 
 
275
@...: 
 
276
@Returns: 
 
277
 
 
278
 
 
279
<!-- ##### FUNCTION gtk_dialog_run ##### -->
 
280
<para>
 
281
 
 
282
</para>
 
283
 
 
284
@dialog: 
 
285
@Returns: 
 
286
 
 
287
 
 
288
<!-- ##### FUNCTION gtk_dialog_response ##### -->
 
289
<para>
 
290
 
 
291
</para>
 
292
 
 
293
@dialog: 
 
294
@response_id: 
 
295
 
 
296
 
 
297
<!-- ##### FUNCTION gtk_dialog_add_button ##### -->
 
298
<para>
 
299
 
 
300
</para>
 
301
 
 
302
@dialog: 
 
303
@button_text: 
 
304
@response_id: 
 
305
@Returns: 
 
306
 
 
307
 
 
308
<!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
 
309
<para>
 
310
 
 
311
</para>
 
312
 
 
313
@dialog: 
 
314
@first_button_text: 
 
315
@...: 
 
316
 
 
317
 
 
318
<!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
 
319
<para>
 
320
 
 
321
</para>
 
322
 
 
323
@dialog: 
 
324
@child: 
 
325
@response_id: 
 
326
 
 
327
 
 
328
<!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
 
329
<para>
 
330
 
 
331
</para>
 
332
 
 
333
@dialog: 
 
334
@Returns: 
 
335
 
 
336
 
 
337
<!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
 
338
<para>
 
339
 
 
340
</para>
 
341
 
 
342
@dialog: 
 
343
@response_id: 
 
344
 
 
345
 
 
346
<!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
 
347
<para>
 
348
 
 
349
</para>
 
350
 
 
351
@dialog: 
 
352
@setting: 
 
353
 
 
354
 
 
355
<!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
 
356
<para>
 
357
 
 
358
</para>
 
359
 
 
360
@dialog: 
 
361
@response_id: 
 
362
@setting: 
 
363
 
 
364
 
 
365
<!-- ##### FUNCTION gtk_dialog_get_response_for_widget ##### -->
 
366
<para>
 
367
 
 
368
</para>
 
369
 
 
370
@dialog: 
 
371
@widget: 
 
372
@Returns: 
 
373
 
 
374
 
 
375
<!-- ##### FUNCTION gtk_dialog_get_widget_for_response ##### -->
 
376
<para>
 
377
 
 
378
</para>
 
379
 
 
380
@dialog: 
 
381
@response_id: 
 
382
@Returns: 
 
383
 
 
384
 
 
385
<!-- ##### FUNCTION gtk_dialog_get_action_area ##### -->
 
386
<para>
 
387
 
 
388
</para>
 
389
 
 
390
@dialog: 
 
391
@Returns: 
 
392
 
 
393
 
 
394
<!-- ##### FUNCTION gtk_dialog_get_content_area ##### -->
 
395
<para>
 
396
 
 
397
</para>
 
398
 
 
399
@dialog: 
 
400
@Returns: 
 
401
 
 
402
 
 
403
<!-- ##### FUNCTION gtk_alternative_dialog_button_order ##### -->
 
404
<para>
 
405
 
 
406
</para>
 
407
 
 
408
@screen: 
 
409
@Returns: 
 
410
 
 
411
 
 
412
<!-- ##### FUNCTION gtk_dialog_set_alternative_button_order ##### -->
 
413
<para>
 
414
 
 
415
</para>
 
416
 
 
417
@dialog: 
 
418
@first_response_id: 
 
419
@...: 
 
420
 
 
421
 
 
422
<!-- ##### FUNCTION gtk_dialog_set_alternative_button_order_from_array ##### -->
 
423
<para>
 
424
 
 
425
</para>
 
426
 
 
427
@dialog: 
 
428
@n_params: 
 
429
@new_order: 
 
430
 
 
431