GtkMessageDialog — A convenient message window
GtkButtonsType | buttons | Write / Construct Only |
GtkWidget * | message-area | Read |
GtkMessageType | message-type | Read / Write / Construct |
char * | secondary-text | Read / Write |
gboolean | secondary-use-markup | Read / Write |
char * | text | Read / Write |
gboolean | use-markup | Read / Write |
struct | GtkMessageDialog |
enum | GtkMessageType |
enum | GtkButtonsType |
GObject ╰── GInitiallyUnowned ╰── GtkWidget ╰── GtkWindow ╰── GtkDialog ╰── GtkMessageDialog
GtkMessageDialog implements GtkAccessible, GtkBuildable, GtkConstraintTarget, GtkNative, GtkShortcutManager and GtkRoot.
#include <gtk/gtk.h>
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.
The easiest way to do a modal message dialog is to use the GTK_DIALOG_MODAL
flag, which will call gtk_window_set_modal()
internally. The dialog will prevent interaction with the parent window until it's hidden or destroyed. You can use the “response” signal to know when the user dismissed the dialog.
An example for using a modal dialog:
You might do a non-modal GtkMessageDialog simply by omitting the GTK_DIALOG_MODAL
flag:
The GtkMessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name “message_area”.
GtkWidget * gtk_message_dialog_new (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const char *message_format
,...
);
Creates a new message dialog, which is a simple dialog with 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.
parent | transient parent, or | [allow-none] |
flags | flags | |
type | type of message | |
buttons | set of buttons to use | |
message_format | printf()-style format string, or | [allow-none] |
... | arguments for |
GtkWidget * gtk_message_dialog_new_with_markup (GtkWindow *parent
,GtkDialogFlags flags
,GtkMessageType type
,GtkButtonsType buttons
,const char *message_format
,...
);
Creates a new message dialog, which is a simple dialog with some text that 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.
parent | transient parent, or | [allow-none] |
flags | flags | |
type | type of message | |
buttons | set of buttons to use | |
message_format | printf()-style format string, or | [allow-none] |
... | arguments for |
a new GtkMessageDialog
void gtk_message_dialog_set_markup (GtkMessageDialog *message_dialog
,const char *str
);
Sets the text of the message dialog to be str
, which is marked up with the Pango text markup language.
message_dialog | ||
str | markup string (see Pango markup format) |
void gtk_message_dialog_format_secondary_text (GtkMessageDialog *message_dialog
,const char *message_format
,...
);
Sets the secondary text of the message dialog to be message_format
(with printf()
-style).
message_dialog | ||
message_format | printf()-style format string, or | [allow-none] |
... | arguments for |
void gtk_message_dialog_format_secondary_markup (GtkMessageDialog *message_dialog
,const char *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.
GtkDialogFlags flags = GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_MODAL; 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 (dialog, "response", G_CALLBACK (gtk_window_destroy), NULL);
message_dialog | ||
message_format | printf()-style markup string (see Pango markup format), or | |
... | arguments for |
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.
message_dialog |
struct GtkMessageDialog;
The type of message being displayed in the dialog.
GTK_MESSAGE_INFO | Informational message | |
GTK_MESSAGE_WARNING | Non-fatal warning message | |
GTK_MESSAGE_QUESTION | Question requiring a choice | |
GTK_MESSAGE_ERROR | Fatal error message | |
GTK_MESSAGE_OTHER | None of the above |
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.
GTK_BUTTONS_NONE | no buttons at all | |
GTK_BUTTONS_OK | an OK button | |
GTK_BUTTONS_CLOSE | a Close button | |
GTK_BUTTONS_CANCEL | a Cancel button | |
GTK_BUTTONS_YES_NO | Yes and No buttons | |
GTK_BUTTONS_OK_CANCEL | OK and Cancel buttons |
“buttons”
property“buttons” GtkButtonsType
The buttons shown in the message dialog.
Owner: GtkMessageDialog
Flags: Write / Construct Only
Default value: GTK_BUTTONS_NONE
“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.
Owner: GtkMessageDialog
Flags: Read
“message-type”
property“message-type” GtkMessageType
The type of the message.
Owner: GtkMessageDialog
Flags: Read / Write / Construct
Default value: GTK_MESSAGE_INFO
“secondary-text”
property“secondary-text” char *
The secondary text of the message dialog.
Owner: GtkMessageDialog
Flags: Read / Write
Default value: NULL
“secondary-use-markup”
property“secondary-use-markup” gboolean
TRUE
if the secondary text of the dialog includes Pango markup. See pango_parse_markup()
.
Owner: GtkMessageDialog
Flags: Read / Write
Default value: FALSE
“text”
property“text” char *
The primary text of the message dialog. If the dialog has a secondary text, this will appear as the title.
Owner: GtkMessageDialog
Flags: Read / Write
Default value: ""
“use-markup”
property“use-markup” gboolean
TRUE
if the primary text of the dialog includes Pango markup. See pango_parse_markup()
.
Owner: GtkMessageDialog
Flags: Read / Write
Default value: FALSE
© 2005–2020 The GNOME Project
Licensed under the GNU Lesser General Public License version 2.1 or later.
https://developer.gnome.org/gtk4/4.0/GtkMessageDialog.html