Top |
Functions
GtkWidget * | gtk_dialog_new () |
GtkWidget * | gtk_dialog_new_with_buttons () |
void | gtk_dialog_response () |
GtkWidget * | gtk_dialog_add_button () |
void | gtk_dialog_add_buttons () |
void | gtk_dialog_add_action_widget () |
void | gtk_dialog_set_default_response () |
void | gtk_dialog_set_response_sensitive () |
int | gtk_dialog_get_response_for_widget () |
GtkWidget * | gtk_dialog_get_widget_for_response () |
GtkWidget * | gtk_dialog_get_content_area () |
GtkWidget * | gtk_dialog_get_header_bar () |
Object Hierarchy
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkWindow ╰── GtkDialog ├── GtkAppChooserDialog ├── GtkColorChooserDialog ├── GtkFileChooserDialog ├── GtkFontChooserDialog ├── GtkMessageDialog ├── GtkPageSetupUnixDialog ╰── GtkPrintUnixDialog
Implemented Interfaces
GtkDialog implements GtkAccessible, GtkBuildable, GtkConstraintTarget, GtkNative, GtkShortcutManager and GtkRoot.
Description
Dialogs 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.
The main area of a GtkDialog is called the "content area", and is yours
to populate with widgets such a GtkLabel or GtkEntry, to present
your information, questions, or tasks to the user. In addition, dialogs
allow you to add "action widgets". Most commonly, action widgets are
buttons. Depending on the platform, action widgets may be presented
in the header bar at the top of the window, or at the bottom of the window.
To add action widgets, use GtkDialog using gtk_dialog_new_with_buttons()
,
gtk_dialog_add_button()
, gtk_dialog_add_buttons()
, or
gtk_dialog_add_action_widget()
.
Clicking a button that was added as an action widget will emit the “response” signal with a response ID that you specified. GTK will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in the GtkResponseType enumeration (these all have values less than zero). If a dialog receives a delete event, the “response” signal will be emitted with the GTK_RESPONSE_DELETE_EVENT response ID.
Dialogs are created with a call to gtk_dialog_new()
or
gtk_dialog_new_with_buttons()
. gtk_dialog_new_with_buttons()
is
recommended; it allows you to set the dialog title, some convenient
flags, and add simple buttons.
A “modal” dialog (that is, one which freezes the rest of the application
from user input), can be created by calling gtk_window_set_modal()
on the
dialog. Use the GTK_WINDOW()
macro to cast the widget returned from
gtk_dialog_new()
into a GtkWindow. When using gtk_dialog_new_with_buttons()
you can also pass the GTK_DIALOG_MODAL flag to make a dialog modal.
For the simple dialog in the following example, a GtkMessageDialog would save some effort. But you’d need to create the dialog contents manually if you had more than a simple message in the dialog.
An example for simple GtkDialog usage:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
// Function to open a dialog box with a message void quick_message (GtkWindow *parent, char *message) { GtkWidget *dialog, *label, *content_area; GtkDialogFlags flags; // Create the widgets flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons ("Message", parent, flags, _("_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_window_destroy), dialog); // Add the label, and show everything we’ve added gtk_box_append (GTK_BOX (content_area), label); gtk_widget_show (dialog); } |
GtkDialog as GtkBuildable
The GtkDialog implementation of the GtkBuildable interface exposes the
content_area
as an internal child with the name “content_area”.
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 action_area
). To mark a response
as default, set the “default“ attribute of the <action-widget> element
to true.
GtkDialog supports adding action widgets by specifying “action“ as the “type“ attribute of a <child> element. The widget will be added either to the action area or the headerbar of the dialog, depending on the “use-header-bar“ property. The response id has to be associated with the action widget using the <action-widgets> element.
An example of a GtkDialog UI definition fragment:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
<object class="GtkDialog" id="dialog1"> <child type="action"> <object class="GtkButton" id="button_cancel"/> </child> <child type="action"> <object class="GtkButton" id="button_ok"> </object> </child> <action-widgets> <action-widget response="cancel">button_cancel</action-widget> <action-widget response="ok" default="true">button_ok</action-widget> </action-widgets> </object> |
Functions
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 content_area
and action_area
, as described above.
gtk_dialog_new_with_buttons ()
GtkWidget * gtk_dialog_new_with_buttons (const char *title
,GtkWindow *parent
,GtkDialogFlags flags
,const char *first_button_text
,...
);
Creates a new GtkDialog with title title
(or NULL
for the default
title; see gtk_window_set_title()
) and transient parent parent
(or
NULL
for none; see gtk_window_set_transient_for()
). The flags
argument can be used to make the dialog modal (GTK_DIALOG_MODAL)
and/or to have it destroyed along with its transient parent
(GTK_DIALOG_DESTROY_WITH_PARENT). After flags
, button
text/response ID pairs should be listed, with a NULL
pointer ending
the list. Button text can be arbitrary text. A response ID can be
any positive number, or one of the values in the GtkResponseType
enumeration. If the user clicks one of these dialog buttons,
GtkDialog will emit the “response” signal with the corresponding
response ID. If a GtkDialog receives a delete event,
it will emit ::response with a response ID of GTK_RESPONSE_DELETE_EVENT.
However, destroying a dialog does not emit the ::response signal;
so be careful relying on ::response when using the
GTK_DIALOG_DESTROY_WITH_PARENT flag. Buttons are from left to right,
so the first button in the list will be the leftmost button in the dialog.
Here’s a simple example:
1 2 3 4 5 6 7 8 9 10 11 |
GtkWindow *main_app_window; // Window the dialog should show up on GtkWidget *dialog; GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_dialog_new_with_buttons ("My dialog", main_app_window, flags, _("_OK"), GTK_RESPONSE_ACCEPT, _("_Cancel"), GTK_RESPONSE_REJECT, NULL); |
Parameters
title |
Title of the dialog, or |
[allow-none] |
parent |
Transient parent of the dialog, or |
[allow-none] |
flags |
from GtkDialogFlags |
|
first_button_text |
text to go in first button, or |
[allow-none] |
... |
response ID for first button, then additional buttons, ending with |
gtk_dialog_response ()
void gtk_dialog_response (GtkDialog *dialog
,int 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.
gtk_dialog_add_button ()
GtkWidget * gtk_dialog_add_button (GtkDialog *dialog
,const char *button_text
,int response_id
);
Adds a button with the given text and sets things up so that
clicking the button will emit the “response” signal with
the given response_id
. The button is appended to the end of the
dialog’s action area. The button widget is returned, but usually
you don’t need it.
gtk_dialog_add_buttons ()
void gtk_dialog_add_buttons (GtkDialog *dialog
,const char *first_button_text
,...
);
Adds more buttons, same as calling gtk_dialog_add_button()
repeatedly. The variable argument list should be NULL
-terminated
as with gtk_dialog_new_with_buttons()
. Each button must have both
text and response ID.
gtk_dialog_add_action_widget ()
void gtk_dialog_add_action_widget (GtkDialog *dialog
,GtkWidget *child
,int 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 action_area
field
of the GtkDialog struct.
gtk_dialog_set_default_response ()
void gtk_dialog_set_default_response (GtkDialog *dialog
,int response_id
);
Sets the last widget in the dialog’s action area with the given response_id
as the default widget for the dialog. Pressing “Enter” normally activates
the default widget.
gtk_dialog_set_response_sensitive ()
void gtk_dialog_set_response_sensitive (GtkDialog *dialog
,int response_id
,gboolean setting
);
Calls gtk_widget_set_sensitive (widget, @setting)
for each widget in the dialog’s action area with the given response_id
.
A convenient way to sensitize/desensitize dialog buttons.
gtk_dialog_get_response_for_widget ()
int gtk_dialog_get_response_for_widget (GtkDialog *dialog
,GtkWidget *widget
);
Gets the response id of a widget in the action area of a dialog.
gtk_dialog_get_widget_for_response ()
GtkWidget * gtk_dialog_get_widget_for_response (GtkDialog *dialog
,int response_id
);
Gets the widget button that uses the given response ID in the action area of a dialog.
gtk_dialog_get_content_area ()
GtkWidget *
gtk_dialog_get_content_area (GtkDialog *dialog
);
Returns the content area of dialog
.
gtk_dialog_get_header_bar ()
GtkWidget *
gtk_dialog_get_header_bar (GtkDialog *dialog
);
Returns the header bar of dialog
. Note that the
headerbar is only used by the dialog if the
“use-header-bar” property is TRUE
.
Types and Values
struct GtkDialog
struct GtkDialog;
The GtkDialog contains only private fields and should not be directly accessed.
struct GtkDialogClass
struct GtkDialogClass { GtkWindowClass parent_class; void (* response) (GtkDialog *dialog, int response_id); /* Keybinding signals */ void (* close) (GtkDialog *dialog); };
enum GtkDialogFlags
Flags used to influence dialog construction.
Members
Make the constructed dialog modal,
see |
||
Destroy the dialog when its
parent is destroyed, see |
||
Create dialog with actions in header bar instead of action area |
enum GtkResponseType
Predefined values for use as response ids in gtk_dialog_add_button()
.
All predefined values are negative; GTK leaves values of 0 or greater for
application-defined response ids.
Members
Returned if an action widget has no response id, or if the dialog gets programmatically hidden or destroyed |
||
Generic response id, not used by GTK dialogs |
||
Generic response id, not used by GTK dialogs |
||
Returned if the dialog is deleted |
||
Returned by OK buttons in GTK dialogs |
||
Returned by Cancel buttons in GTK dialogs |
||
Returned by Close buttons in GTK dialogs |
||
Returned by Yes buttons in GTK dialogs |
||
Returned by No buttons in GTK dialogs |
||
Returned by Apply buttons in GTK dialogs |
||
Returned by Help buttons in GTK dialogs |
Property Details
The “use-header-bar”
property
“use-header-bar” int
TRUE
if the dialog uses a GtkHeaderBar for action buttons
instead of the action-area.
For technical reasons, this property is declared as an integer
property, but you should only set it to TRUE
or FALSE
.
Owner: GtkDialog
Flags: Read / Write / Construct Only
Allowed values: [-1,1]
Default value: -1
Signal Details
The “close”
signal
void user_function (GtkDialog *dialog, gpointer user_data)
The ::close signal is a keybinding signal which gets emitted when the user uses a keybinding to close the dialog.
The default binding for this signal is the Escape key.
Flags: Action
The “response”
signal
void user_function (GtkDialog *dialog, int response_id, gpointer user_data)
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.
Parameters
dialog |
the object on which the signal is emitted |
|
response_id |
the response ID |
|
user_data |
user data set when the signal handler was connected. |
Flags: Run Last