Synopsis#include <gtk/gtk.h> GtkDialog; enum GtkDialogFlags; enum GtkResponseType; GtkWidget* gtk_dialog_new (void); GtkWidget* gtk_dialog_new_with_buttons (const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, ...); gint gtk_dialog_run (GtkDialog *dialog); void gtk_dialog_response (GtkDialog *dialog, gint response_id); GtkWidget* gtk_dialog_add_button (GtkDialog *dialog, const gchar *button_text, gint response_id); void gtk_dialog_add_buttons (GtkDialog *dialog, const gchar *first_button_text, ...); void gtk_dialog_add_action_widget (GtkDialog *dialog, GtkWidget *child, gint response_id); gboolean gtk_dialog_get_has_separator (GtkDialog *dialog); void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id); void gtk_dialog_set_has_separator (GtkDialog *dialog, gboolean setting); void gtk_dialog_set_response_sensitive (GtkDialog *dialog, gint response_id, gboolean setting); gint gtk_dialog_get_response_for_widget (GtkDialog *dialog, GtkWidget *widget); GtkWidget* gtk_dialog_get_action_area (GtkDialog *dialog); GtkWidget* gtk_dialog_get_content_area (GtkDialog *dialog); gboolean gtk_alternative_dialog_button_order (GdkScreen *screen); void gtk_dialog_set_alternative_button_order (GtkDialog *dialog, gint first_response_id, ...); void gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog, gint n_params, gint *new_order); Object HierarchyGObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkContainer +----GtkBin +----GtkWindow +----GtkDialog +----GtkAboutDialog +----GtkColorSelectionDialog +----GtkFileChooserDialog +----GtkFileSelection +----GtkFontSelectionDialog +----GtkInputDialog +----GtkMessageDialog +----GtkPageSetupUnixDialog +----GtkPrintUnixDialog +----GtkRecentChooserDialog Style Properties"action-area-border" gint : Read "button-spacing" gint : Read "content-area-border" gint : Read DescriptionDialog boxes are a convenient way to prompt the user for a small amount of input, e.g. to display a message, ask a question, or anything else that does not require extensive effort on the user's part.
GTK+ treats a dialog as a window split vertically. The top section is a
GtkVBox, and is where widgets such as a GtkLabel or a GtkEntry should
be packed. The bottom area is known as the
GtkDialog boxes are created with a call to
If 'dialog' is a newly created dialog, the two primary areas of the window
can be accessed through
A 'modal' dialog (that is, one which freezes the rest of the application from
user input), can be created by calling
If you add buttons to GtkDialog using
If you want to block waiting for a dialog to return before returning control
flow to your code, you can call For the simple dialog in the following example, in reality you'd probably use GtkMessageDialog to save yourself some effort. But you'd need to create the dialog contents manually if you had more than a simple message in the dialog. Example 5. Simple GtkDialog usage. /* Function to open a dialog box displaying the message provided. */ void quick_message (gchar *message) { GtkWidget *dialog, *label, *content_area; /* Create the widgets */ dialog = gtk_dialog_new_with_buttons ("Message", main_application_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_NONE, NULL); content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog)); label = gtk_label_new (message); /* Ensure that the dialog box is destroyed when the user responds. */ g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); /* Add the label, and show everything we've added to the dialog. */ gtk_container_add (GTK_CONTAINER (content_area), label); gtk_widget_show_all (dialog); }
GtkDialog as GtkBuildable
The GtkDialog implementation of the GtkBuildable interface exposes the
GtkDialog supports a custom <action-widgets> element, which
can contain multiple <action-widget> elements. The "response"
attribute specifies a numeric response, and the content of the element
is the id of widget (which should be a child of the dialogs Example 6. A GtkDialog UI definition fragment. <object class="GtkDialog" id="dialog1"> <child internal-child="vbox">" <object class="GtkVBox"> <child internal-child="action_area"> <object class="GtkHButtonBox"> <child> <object class="GtkButton" id="button_cancel"/> </child> <child> <object class="GtkButton" id="button_ok"/> </child> </object> </child> </object> </child> <action-widgets> <action-widget response="3">button_ok</action-widget> <action-widget response="-5">button_cancel</action-widget> </action-widgets> </object> DetailsGtkDialogtypedef struct { GtkWidget *GSEAL (vbox); GtkWidget *GSEAL (action_area); } GtkDialog;
enum GtkDialogFlagstypedef enum { GTK_DIALOG_MODAL = 1 << 0, /* call gtk_window_set_modal (win, TRUE) */ GTK_DIALOG_DESTROY_WITH_PARENT = 1 << 1, /* call gtk_window_set_destroy_with_parent () */ GTK_DIALOG_NO_SEPARATOR = 1 << 2 /* no separator bar above buttons */ } GtkDialogFlags; Flags used to influence dialog construction.
enum GtkResponseTypetypedef enum { /* GTK returns this if a response widget has no response_id, * or if the dialog gets programmatically hidden or destroyed. */ GTK_RESPONSE_NONE = -1, /* GTK won't return these unless you pass them in * as the response for an action widget. They are * for your convenience. */ GTK_RESPONSE_REJECT = -2, GTK_RESPONSE_ACCEPT = -3, /* If the dialog is deleted. */ GTK_RESPONSE_DELETE_EVENT = -4, /* These are returned from GTK dialogs, and you can also use them * yourself if you like. */ GTK_RESPONSE_OK = -5, GTK_RESPONSE_CANCEL = -6, GTK_RESPONSE_CLOSE = -7, GTK_RESPONSE_YES = -8, GTK_RESPONSE_NO = -9, GTK_RESPONSE_APPLY = -10, GTK_RESPONSE_HELP = -11 } GtkResponseType;
Predefined values for use as response ids in
gtk_dialog_new ()GtkWidget* gtk_dialog_new (void);
Creates a new dialog box. Widgets should not be packed into this GtkWindow
directly, but into the
gtk_dialog_new_with_buttons ()GtkWidget* gtk_dialog_new_with_buttons (const gchar *title, GtkWindow *parent, GtkDialogFlags flags, const gchar *first_button_text, ...);
Creates a new GtkDialog with title Here's a simple example: GtkWidget *dialog = gtk_dialog_new_with_buttons ("My dialog", main_app_window, GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
gtk_dialog_run ()gint gtk_dialog_run (GtkDialog *dialog);
Blocks in a recursive main loop until the
Before entering the recursive main loop,
During
After Typical usage of this function might be: gint result = gtk_dialog_run (GTK_DIALOG (dialog)); switch (result) { case GTK_RESPONSE_ACCEPT: do_application_specific_something (); break; default: do_nothing_since_dialog_was_cancelled (); break; } gtk_widget_destroy (dialog);
Note that even though the recursive main loop gives the effect of a
modal dialog (it prevents the user from interacting with other
windows in the same window group while the dialog is run), callbacks
such as timeouts, IO channel watches, DND drops, etc, will
be triggered during a
gtk_dialog_response ()void gtk_dialog_response (GtkDialog *dialog, gint response_id);
Emits the "response" signal with the given response ID.
Used to indicate that the user has responded to the dialog in some way;
typically either you or
gtk_dialog_add_button ()GtkWidget* gtk_dialog_add_button (GtkDialog *dialog, const gchar *button_text, gint response_id);
Adds a button with the given text (or a stock button, if
gtk_dialog_add_buttons ()void gtk_dialog_add_buttons (GtkDialog *dialog, const gchar *first_button_text, ...);
Adds more buttons, same as calling
gtk_dialog_add_action_widget ()void gtk_dialog_add_action_widget (GtkDialog *dialog, GtkWidget *child, gint response_id);
Adds an activatable widget to the action area of a GtkDialog,
connecting a signal handler that will emit the "response"
signal on the dialog when the widget is activated. The widget is
appended to the end of the dialog's action area. If you want to add a
non-activatable widget, simply pack it into the
gtk_dialog_get_has_separator ()gboolean gtk_dialog_get_has_separator (GtkDialog *dialog); Accessor for whether the dialog has a separator.
gtk_dialog_set_default_response ()void gtk_dialog_set_default_response (GtkDialog *dialog, gint response_id);
Sets the last widget in the dialog's action area with the given
gtk_dialog_set_has_separator ()void gtk_dialog_set_has_separator (GtkDialog *dialog, gboolean setting);
Sets whether the dialog has a separator above the buttons.
gtk_dialog_set_response_sensitive ()void gtk_dialog_set_response_sensitive (GtkDialog *dialog, gint response_id, gboolean setting);
Calls
gtk_dialog_get_response_for_widget ()gint gtk_dialog_get_response_for_widget (GtkDialog *dialog, GtkWidget *widget); Gets the response id of a widget in the action area of a dialog.
Since 2.8 gtk_dialog_get_action_area ()GtkWidget* gtk_dialog_get_action_area (GtkDialog *dialog);
Returns the action area of
Since 2.14 gtk_dialog_get_content_area ()GtkWidget* gtk_dialog_get_content_area (GtkDialog *dialog);
Returns the content area of
Since 2.14 gtk_alternative_dialog_button_order ()gboolean gtk_alternative_dialog_button_order (GdkScreen *screen);
Returns
If you need to use this function, you should probably connect
to the ::notify:gtk-alternative-button-order signal on the
GtkSettings object associated to
Since 2.6 gtk_dialog_set_alternative_button_order ()void gtk_dialog_set_alternative_button_order (GtkDialog *dialog, gint first_response_id, ...);
Sets an alternative button order. If the
"gtk-alternative-button-order" setting is set to By default, GTK+ dialogs use the button order advocated by the Gnome Human Interface Guidelines with the affirmative button at the far right, and the cancel button left of it. But the builtin GTK+ dialogs and GtkMessageDialogs do provide an alternative button order, which is more suitable on some platforms, e.g. Windows. Use this function after adding all the buttons to your dialog, as the following example shows: cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL); ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_OK, GTK_RESPONSE_OK); gtk_widget_grab_default (ok_button); help_button = gtk_dialog_add_button (GTK_DIALOG (dialog), GTK_STOCK_HELP, GTK_RESPONSE_HELP); gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog), GTK_RESPONSE_OK, GTK_RESPONSE_CANCEL, GTK_RESPONSE_HELP, -1);
Since 2.6 gtk_dialog_set_alternative_button_order_from_array ()void gtk_dialog_set_alternative_button_order_from_array (GtkDialog *dialog, gint n_params, gint *new_order);
Sets an alternative button order. If the
"gtk-alternative-button-order" setting is set to
See This function is for use by language bindings.
Since 2.6 Style Property DetailsThe
|
|
user data set when the signal handler was connected. |
"response"
signalvoid user_function (GtkDialog *dialog, gint response_id, gpointer user_data) : Run Last
Emitted when an action widget is clicked, the dialog receives a
delete event, or the application programmer calls gtk_dialog_response()
.
On a delete event, the response ID is GTK_RESPONSE_DELETE_EVENT.
Otherwise, it depends on which action widget was clicked.
|
the object on which the signal is emitted |
|
the response ID |
|
user data set when the signal handler was connected. |