GTK+ 2 Reference Manual | ||||
---|---|---|---|---|
Top | Description | Object Hierarchy | Implemented Interfaces | Properties | Style Properties |
#include <gtk/gtk.h> struct GtkMessageDialog; enum GtkMessageType; enum GtkButtonsType; GtkWidget * gtk_message_dialog_new (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const gchar *message_format
,...
); GtkWidget * gtk_message_dialog_new_with_markup (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const gchar *message_format
,...
); void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog
,const gchar *str
); void gtk_message_dialog_set_image (GtkMessageDialog *dialog
,GtkWidget *image
); GtkWidget * gtk_message_dialog_get_image (GtkMessageDialog *dialog
); GtkWidget * gtk_message_dialog_get_message_area (GtkMessageDialog *message_dialog
); void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog
,const gchar *message_format
,...
); void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog
,const gchar *message_format
,...
);
GObject +----GInitiallyUnowned +----GtkObject +----GtkWidget +----GtkContainer +----GtkBin +----GtkWindow +----GtkDialog +----GtkMessageDialog
"buttons" GtkButtonsType : Write / Construct Only "image" GtkWidget* : Read / Write "message-area" GtkWidget* : Read "message-type" GtkMessageType : Read / Write / Construct "secondary-text" gchar* : Read / Write "secondary-use-markup" gboolean : Read / Write "text" gchar* : Read / Write "use-markup" gboolean : Read / Write
GtkMessageDialog presents a dialog with an image representing the type of message (Error, Question, etc.) alongside 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.
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.
Example 8. A modal dialog.
1 2 3 4 5 6 7 8 |
dialog = gtk_message_dialog_new (main_application_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error loading file '%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:
Example 9. A non-modal dialog.
1 2 3 4 5 6 7 8 9 10 11 |
dialog = gtk_message_dialog_new (main_application_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, "Error loading file '%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); |
The GtkMessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name "message_area".
typedef enum { GTK_MESSAGE_INFO, GTK_MESSAGE_WARNING, GTK_MESSAGE_QUESTION, GTK_MESSAGE_ERROR, GTK_MESSAGE_OTHER } GtkMessageType;
The type of message being displayed in the dialog.
typedef enum { GTK_BUTTONS_NONE, GTK_BUTTONS_OK, GTK_BUTTONS_CLOSE, GTK_BUTTONS_CANCEL, GTK_BUTTONS_YES_NO, GTK_BUTTONS_OK_CANCEL } 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()
.
GTK_BUTTONS_OK
, GTK_BUTTONS_YES_NO
and GTK_BUTTONS_OK_CANCEL
are discouraged by the
GNOME HIG.
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.
|
transient parent, or NULL for none. [allow-none]
|
|
flags |
|
type of message |
|
set of buttons to use |
|
printf() -style format string, or NULL . [allow-none]
|
Returns : |
a new GtkMessageDialog. [transfer none] |
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 |
GtkWidget *dialog; dialog = gtk_message_dialog_new (main_application_window, GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_ERROR, GTK_BUTTONS_CLOSE, NULL); gtk_message_dialog_set_markup (GTK_MESSAGE_DIALOG (dialog), markup); |
|
transient parent, or NULL for none. [allow-none]
|
|
flags |
|
type of message |
|
set of buttons to use |
|
printf() -style format string, or NULL . [allow-none]
|
Returns : |
a new GtkMessageDialog |
Since 2.4
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
|
a GtkMessageDialog |
|
markup string (see Pango markup format) |
Since 2.4
void gtk_message_dialog_set_image (GtkMessageDialog *dialog
,GtkWidget *image
);
Sets the dialog's image to image
.
|
a GtkMessageDialog |
|
the image |
Since 2.10
GtkWidget * gtk_message_dialog_get_image (GtkMessageDialog *dialog
);
Gets the dialog's image.
|
a GtkMessageDialog |
Returns : |
the dialog's image. [transfer none] |
Since 2.14
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,
on the right side of the dialog's image (or on the left for right-to-left
languages). See gtk_dialog_get_content_area()
for the corresponding
function in the parent GtkDialog.
|
a GtkMessageDialog |
Returns : |
A GtkVBox corresponding to the
"message area" in the message_dialog . [transfer none]
|
Since 2.22
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).
Note that setting a secondary text makes the primary text become bold, unless you have provided explicit markup.
|
a GtkMessageDialog |
|
printf() -style format string, or NULL . [allow-none]
|
Since 2.6
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.
Note that setting a secondary text makes the primary text become bold, unless you have provided explicit markup.
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 |
gchar *msg; msg = g_markup_printf_escaped (message_format, ...); gtk_message_dialog_format_secondary_markup (message_dialog, "%s", msg); g_free (msg); |
|
a GtkMessageDialog |
|
printf()-style markup string (see
Pango markup format), or NULL
|
Since 2.6
"buttons"
property"buttons" GtkButtonsType : Write / Construct Only
The buttons shown in the message dialog.
Default value: GTK_BUTTONS_NONE
"message-area"
property"message-area" GtkWidget* : Read
The GtkVBox that corresponds to the message area of this dialog. See
gtk_message_dialog_get_message_area()
for a detailed description of this
area.
Since 2.22
"message-type"
property"message-type" GtkMessageType : Read / Write / Construct
The type of the message. The type is used to determine the image that is shown in the dialog, unless the image is explicitly set by the ::image property.
Default value: GTK_MESSAGE_INFO
"secondary-text"
property"secondary-text" gchar* : Read / Write
The secondary text of the message dialog.
Default value: NULL
Since 2.10
"secondary-use-markup"
property"secondary-use-markup" gboolean : Read / Write
TRUE
if the secondary text of the dialog includes Pango markup.
See pango_parse_markup()
.
Default value: FALSE
Since 2.10
"text"
property"text" gchar* : Read / Write
The primary text of the message dialog. If the dialog has a secondary text, this will appear as the title.
Default value: ""
Since 2.10
"message-border"
style property"message-border" gint : Read
Width of border around the label and image in the message dialog.
Allowed values: >= 0
Default value: 12
"use-separator"
style property"use-separator" gboolean : Read
GtkMessageDialog:use-separator
has been deprecated since version 2.22 and should not be used in newly-written code. This style property will be removed in GTK+ 3
Whether to draw a separator line between the message label and the buttons in the dialog.
Default value: FALSE
Since 2.4