1 <!-- ##### SECTION Title ##### -->
4 <!-- ##### SECTION Short_Description ##### -->
7 <!-- ##### SECTION Long_Description ##### -->
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.
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.
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
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.
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.
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.
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.
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.
69 <title>Simple <structname>GtkDialog</structname> usage.</title>
72 /* Function to open a dialog box displaying the message provided. */
74 void quick_message (gchar *message) {
76 GtkWidget *dialog, *label, *content_area;
78 /* Create the widgets */
80 dialog = gtk_dialog_new_with_buttons ("Message",
81 main_application_window,
82 GTK_DIALOG_DESTROY_WITH_PARENT,
86 content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
87 label = gtk_label_new (message);
89 /* Ensure that the dialog box is destroyed when the user responds. */
91 g_signal_connect_swapped (dialog,
93 G_CALLBACK (gtk_widget_destroy),
96 /* Add the label, and show everything we've added to the dialog. */
98 gtk_container_add (GTK_CONTAINER (content_area), label);
99 gtk_widget_show_all (dialog);
106 <refsect2 id="GtkDialog-BUILDER-UI"><title>GtkDialog as GtkBuildable</title>
108 The GtkDialog implementation of the GtkBuildable interface exposes the
109 @vbox and @action_area as internal children with the names "vbox" and
113 GtkDialog supports a custom <action-widgets> element, which
114 can contain multiple <action-widget> 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).
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">
127 <object class="GtkButton" id="button_cancel"/>
130 <object class="GtkButton" id="button_ok"/>
137 <action-widget response="3">button_ok</action-widget>
138 <action-widget response="-5">button_cancel</action-widget>
145 <!-- ##### SECTION See_Also ##### -->
150 <term>#GtkVBox</term>
151 <listitem><para>Pack widgets vertically.</para></listitem>
154 <term>#GtkWindow</term>
155 <listitem><para>Alter the properties of your dialog box.</para></listitem>
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>
165 <!-- ##### SECTION Stability_Level ##### -->
168 <!-- ##### STRUCT GtkDialog ##### -->
170 <structfield>vbox</structfield> is a #GtkVBox - the main part of the
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.
181 <!-- ##### SIGNAL GtkDialog::close ##### -->
186 @dialog: the object which received the signal.
188 <!-- ##### SIGNAL GtkDialog::response ##### -->
196 <!-- ##### ARG GtkDialog:has-separator ##### -->
201 <!-- ##### ARG GtkDialog:action-area-border ##### -->
206 <!-- ##### ARG GtkDialog:button-spacing ##### -->
211 <!-- ##### ARG GtkDialog:content-area-border ##### -->
216 <!-- ##### ENUM GtkDialogFlags ##### -->
218 Flags used to influence dialog construction.
221 @GTK_DIALOG_MODAL: Make the constructed dialog modal,
222 see gtk_window_set_modal().
223 @GTK_DIALOG_DESTROY_WITH_PARENT: Destroy the dialog when its
224 parent is destroyed, see gtk_window_set_destroy_with_parent().
225 @GTK_DIALOG_NO_SEPARATOR: Don't put a separator between the
226 action area and the dialog content.
228 <!-- ##### ENUM GtkResponseType ##### -->
230 Predefined values for use as response ids in gtk_dialog_add_button().
231 All predefined values are negative, GTK+ leaves positive values for
232 application-defined response ids.
235 @GTK_RESPONSE_NONE: Returned if an action widget has no response id, or if
236 the dialog gets programmatically hidden or destroyed.
237 @GTK_RESPONSE_REJECT: Generic response id, not used by GTK+ dialogs.
238 @GTK_RESPONSE_ACCEPT: Generic response id, not used by GTK+ dialogs.
239 @GTK_RESPONSE_DELETE_EVENT: Returned if the dialog is deleted.
240 @GTK_RESPONSE_OK: Returned by OK buttons in GTK+ dialogs.
241 @GTK_RESPONSE_CANCEL: Returned by Cancel buttons in GTK+ dialogs.
242 @GTK_RESPONSE_CLOSE: Returned by Close buttons in GTK+ dialogs.
243 @GTK_RESPONSE_YES: Returned by Yes buttons in GTK+ dialogs.
244 @GTK_RESPONSE_NO: Returned by No buttons in GTK+ dialogs.
245 @GTK_RESPONSE_APPLY: Returned by Apply buttons in GTK+ dialogs.
246 @GTK_RESPONSE_HELP: Returned by Help buttons in GTK+ dialogs.
248 <!-- ##### FUNCTION gtk_dialog_new ##### -->
250 Creates a new dialog box. Widgets should not be packed into this #GtkWindow
251 directly, but into the @vbox and @action_area, as described above.
254 @Returns: a new #GtkDialog.
257 <!-- ##### FUNCTION gtk_dialog_new_with_buttons ##### -->
270 <!-- ##### FUNCTION gtk_dialog_run ##### -->
279 <!-- ##### FUNCTION gtk_dialog_response ##### -->
288 <!-- ##### FUNCTION gtk_dialog_add_button ##### -->
299 <!-- ##### FUNCTION gtk_dialog_add_buttons ##### -->
309 <!-- ##### FUNCTION gtk_dialog_add_action_widget ##### -->
319 <!-- ##### FUNCTION gtk_dialog_get_has_separator ##### -->
328 <!-- ##### FUNCTION gtk_dialog_set_default_response ##### -->
337 <!-- ##### FUNCTION gtk_dialog_set_has_separator ##### -->
346 <!-- ##### FUNCTION gtk_dialog_set_response_sensitive ##### -->
356 <!-- ##### FUNCTION gtk_dialog_get_response_for_widget ##### -->
366 <!-- ##### FUNCTION gtk_dialog_get_action_area ##### -->
375 <!-- ##### FUNCTION gtk_dialog_get_content_area ##### -->
384 <!-- ##### FUNCTION gtk_alternative_dialog_button_order ##### -->
393 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order ##### -->
403 <!-- ##### FUNCTION gtk_dialog_set_alternative_button_order_from_array ##### -->