Top |
Functions
Properties
GtkButtonsType | buttons | Write / Construct Only |
GtkWidget * | image | Read / Write |
GtkWidget * | message-area | Read |
GtkMessageType | message-type | Read / Write / Construct |
gchar * | secondary-text | Read / Write |
gboolean | secondary-use-markup | Read / Write |
gchar * | text | Read / Write |
gboolean | use-markup | Read / Write |
Object Hierarchy
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkContainer ╰── GtkBin ╰── GtkWindow ╰── GtkDialog ╰── GtkMessageDialog
Description
GtkMessageDialog presents a dialog with some message text. It’s simply a convenience widget; you could construct the equivalent of GtkMessageDialog from GtkDialog without too much effort, but GtkMessageDialog saves typing.
One difference from GtkDialog is that GtkMessageDialog sets the
“skip-taskbar-hint” property to TRUE
, so that the dialog is hidden
from the taskbar by default.
The easiest way to do a modal message dialog is to use gtk_dialog_run()
, though
you can also pass in the GTK_DIALOG_MODAL
flag, gtk_dialog_run()
automatically
makes the dialog modal and waits for the user to respond to it. gtk_dialog_run()
returns when any dialog button is clicked.
An example for using a modal dialog:
1 2 3 4 5 6 7 8 9 10 |
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_message_dialog_new (parent_window, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error reading “%s”: %s", filename, g_strerror (errno)); gtk_dialog_run (GTK_DIALOG (dialog)); gtk_widget_destroy (dialog); |
You might do a non-modal GtkMessageDialog as follows:
An example for a non-modal dialog:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_message_dialog_new (parent_window, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error reading “%s”: %s", filename, g_strerror (errno)); // Destroy the dialog when the user responds to it // (e.g. clicks a button) g_signal_connect_swapped (dialog, "response", G_CALLBACK (gtk_widget_destroy), dialog); |
Functions
gtk_message_dialog_new ()
GtkWidget * gtk_message_dialog_new (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const gchar *message_format
,...
);
Creates a new message dialog, which is a simple dialog with an icon indicating the dialog type (error, warning, etc.) and some text the user may want to see. When the user clicks a button a “response” signal is emitted with response IDs from GtkResponseType. See GtkDialog for more details.
gtk_message_dialog_new_with_markup ()
GtkWidget * gtk_message_dialog_new_with_markup (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const gchar *message_format
,...
);
Creates a new message dialog, which is a simple dialog with an icon indicating the dialog type (error, warning, etc.) and some text which is marked up with the Pango text markup language. When the user clicks a button a “response” signal is emitted with response IDs from GtkResponseType. See GtkDialog for more details.
Special XML characters in the printf()
arguments passed to this
function will automatically be escaped as necessary.
(See g_markup_printf_escaped()
for how this is implemented.)
Usually this is what you want, but if you have an existing
Pango markup string that you want to use literally as the
label, then you need to use gtk_message_dialog_set_markup()
instead, since you can’t pass the markup string either
as the format (it might contain “%” characters) or as a string
argument.
1 2 3 4 5 6 7 8 9 |
GtkWidget *dialog; GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT; dialog = gtk_message_dialog_new (parent_window, flags, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup); |
Since 2.4
gtk_message_dialog_set_markup ()
void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog
,const gchar *str
);
Sets the text of the message dialog to be str
, which is marked
up with the Pango text markup language.
Since 2.4
gtk_message_dialog_set_image ()
void gtk_message_dialog_set_image (GtkMessageDialog *dialog
,GtkWidget *image
);
gtk_message_dialog_set_image
has been deprecated since version 3.12 and should not be used in newly-written code.
Use GtkDialog to create dialogs with images
Sets the dialog’s image to image
.
Since 2.10
gtk_message_dialog_get_image ()
GtkWidget *
gtk_message_dialog_get_image (GtkMessageDialog *dialog
);
gtk_message_dialog_get_image
has been deprecated since version 3.12 and should not be used in newly-written code.
Use GtkDialog for dialogs with images
Gets the dialog’s image.
Since 2.14
gtk_message_dialog_format_secondary_text ()
void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog
,const gchar *message_format
,...
);
Sets the secondary text of the message dialog to be message_format
(with printf()
-style).
Parameters
message_dialog |
||
message_format |
|
[allow-none] |
... |
arguments for |
Since 2.6
gtk_message_dialog_format_secondary_markup ()
void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog
,const gchar *message_format
,...
);
Sets the secondary text of the message dialog to be message_format
(with
printf()
-style), which is marked up with the
Pango text markup language.
Due to an oversight, this function does not escape special XML characters
like gtk_message_dialog_new_with_markup()
does. Thus, if the arguments
may contain special XML characters, you should use g_markup_printf_escaped()
to escape it.
1 2 3 4 5 6 |
gchar *msg; msg = g_markup_printf_escaped (message_format, ...); gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg); g_free (msg); |
Parameters
message_dialog |
||
message_format |
printf()-style markup string (see
Pango markup format), or |
|
... |
arguments for |
Since 2.6
gtk_message_dialog_get_message_area ()
GtkWidget *
gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog
);
Returns the message area of the dialog. This is the box where the
dialog’s primary and secondary labels are packed. You can add your
own extra content to that box and it will appear below those labels.
See gtk_dialog_get_content_area()
for the corresponding
function in the parent GtkDialog.
Since 2.22
Types and Values
enum GtkButtonsType
Prebuilt sets of buttons for the dialog. If
none of these choices are appropriate, simply use GTK_BUTTONS_NONE
then call gtk_dialog_add_buttons()
.
Please note that
GTK_BUTTONS_OK
,GTK_BUTTONS_YES_NO
andGTK_BUTTONS_OK_CANCEL
are discouraged by the GNOME Human Interface Guidelines.
Property Details
The “buttons”
property
“buttons” GtkButtonsType
The buttons shown in the message dialog.
Flags: Write / Construct Only
Default value: GTK_BUTTONS_NONE
The “image”
property
“image” GtkWidget *
The image for this dialog.
GtkMessageDialog:image
has been deprecated since version 3.12 and should not be used in newly-written code.
Use GtkDialog to create dialogs with images
Flags: Read / Write
Since 2.10
The “message-area”
property
“message-area” GtkWidget *
The GtkBox that corresponds to the message area of this dialog. See
gtk_message_dialog_get_message_area()
for a detailed description of this
area.
Flags: Read
Since 2.22
The “message-type”
property
“message-type” GtkMessageType
The type of the message.
Flags: Read / Write / Construct
Default value: GTK_MESSAGE_INFO
The “secondary-text”
property
“secondary-text” gchar *
The secondary text of the message dialog.
Flags: Read / Write
Default value: NULL
Since 2.10
The “secondary-use-markup”
property
“secondary-use-markup” gboolean
TRUE
if the secondary text of the dialog includes Pango markup.
See pango_parse_markup()
.
Flags: Read / Write
Default value: FALSE
Since 2.10
The “text”
property
“text” gchar *
The primary text of the message dialog. If the dialog has a secondary text, this will appear as the title.
Flags: Read / Write
Default value: ""
Since 2.10
The “use-markup”
property
“use-markup” gboolean
TRUE
if the primary text of the dialog includes Pango markup.
See pango_parse_markup()
.
Flags: Read / Write
Default value: FALSE
Since 2.10
Style Property Details
The “message-border”
style property
“message-border” gint
Width of border around the label in the message dialog.
Flags: Read
Allowed values: >= 0
Default value: 12