1
2@c %start of fragment
3
4@node GtkDialog
5@chapter GtkDialog
6Create popup windows
7
8@section Overview
9Dialog boxes are a convenient way to prompt the user for a small amount of
10input, e.g. to display a message, ask a question, or anything else that does not
11require extensive effort on the user's part.
12
13GTK+ treats a dialog as a window split vertically. The top section is a
14@code{<gtk-vbox>}, and is where widgets such as a @code{<gtk-label>} or a
15@code{<gtk-entry>} should be packed. The bottom area is known as the . This is
16generally used for packing buttons into the dialog which may perform functions
17such as cancel, ok, or apply. The two areas are separated by a
18@code{<gtk-hseparator>}.
19
20@code{<gtk-dialog>} boxes are created with a call to @code{gtk-dialog-new} or
21@code{gtk-dialog-new-with-buttons}. @code{gtk-dialog-new-with-buttons} is
22recommended; it allows you to set the dialog title, some convenient flags, and
23add simple buttons.
24
25If 'dialog' is a newly created dialog, the two primary areas of the window can
26be accessed as @samp{GTK_DIALOG(dialog)->vbox} and
27@samp{GTK_DIALOG(dialog)->action_area}, as can be seen from the example, below.
28
29A 'modal' dialog (that is, one which freezes the rest of the application from
30user input), can be created by calling @code{gtk-window-set-modal} on the
31dialog. Use the @code{gtk-window} macro to cast the widget returned from
32@code{gtk-dialog-new} into a @code{<gtk-window>}. When using
33@code{gtk-dialog-new-with-buttons} you can also pass the
34@code{<gtk-dialog-modal>} flag to make a dialog modal.
35
36If you add buttons to @code{<gtk-dialog>} using
37@code{gtk-dialog-new-with-buttons}, @code{gtk-dialog-add-button},
38@code{gtk-dialog-add-buttons}, or @code{gtk-dialog-add-action-widget}, clicking
39the button will emit a signal called "response" with a response ID that you
40specified. GTK+ will never assign a meaning to positive response IDs; these are
41entirely user-defined. But for convenience, you can use the response IDs in the
42@code{<gtk-response-type>} enumeration (these all have values less than zero).
43If a dialog receives a delete event, the "response" signal will be emitted with
44a response ID of @code{<gtk-response-delete-event>}.
45
46If you want to block waiting for a dialog to return before returning control
47flow to your code, you can call @code{gtk-dialog-run}. This function enters a
48recursive main loop and waits for the user to respond to the dialog, returning
49the response ID corresponding to the button the user clicked.
50
51For the simple dialog in the following example, in reality you'd probably use
52@code{<gtk-message-dialog>} to save yourself some effort. But you'd need to
53create the dialog contents manually if you had more than a simple message in the
54dialog.
55
56@example
57
58
59/* Function to open a dialog box displaying the message provided. */
60
61void quick_message (gchar *message) @{
62
63   GtkWidget *dialog, *label;
64
65   /* Create the widgets */
66
67   dialog = gtk_dialog_new_with_buttons ("Message",
68                                         main_application_window,
69                                         GTK_DIALOG_DESTROY_WITH_PARENT,
70                                         GTK_STOCK_OK,
71                                         GTK_RESPONSE_NONE,
72                                         NULL);
73   label = gtk_label_new (message);
74
75   /* Ensure that the dialog box is destroyed when the user responds. */
76
77   g_signal_connect_swapped (dialog,
78                             "response",
79                             G_CALLBACK (gtk_widget_destroy),
80                             dialog);
81
82   /* Add the label, and show everything we've added to the dialog. */
83
84   gtk_container_add (GTK_CONTAINER (GTK_DIALOG(dialog)->vbox),
85                      label);
86   gtk_widget_show_all (dialog);
87@}
88
89@end example
90
91@section Usage
92@include defuns-gtkdialog.xml.texi
93
94@c %end of fragment
95