Xfce Foundation Classes
 « Main Page | Index

MessageDialog


A message dialog is 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 MessageDialog from Gtk::Dialog without too much effort, but MessageDialog saves you 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.

To create a MessageDialog call one of the following constructors:

MessageDialog(Window *parent, DialogFlagsField flags);

MessageDialog(MessageType type, ButtonType buttons, Window *parent, DialogFlagsField flags);

MessageDialog(MessageType type, ButtonType buttons, const String& message, Window *parent, DialogFlagsField flags);

The first two constructors create a message dialog with no message. If you use either of these constructors you will need to explicitly call set_message() to set the message text. The third constructor sets all the fields at construction, including the message.

The 'type' argument is the message type and can be one of the following values from the Gtk::MessageType enum:
  • MESSAGE_INFO
  • MESSAGE_WARNING
  • MESSAGE_QUESTION
  • MESSAGE_ERROR
The 'buttons' argument is the set of buttons to display in the dialog and can be one of the following values from the Gtk::ButtonType enum:
  • BUTTONS_NONE
  • BUTTONS_OK,
  • BUTTONS_CLOSE
  • BUTTONS_CANCEL
  • BUTTONS_YES_NO
  • BUTTONS_OK_CANCEL
The 'parent' argument specifies the transient parent for the dialog and has a default value of null. The 'flags' argument specifies the dialog flags and can can be one or more of the following values from the Gtk::DialogFlags enum OR'd together:
  • DIALOG_MODAL
  • DIALOG_DESTROY_WITH_PARENT (the default)
  • DIALOG_NO_SEPARATOR
To set the message text call one of the following methods:

void set_message(const String& message);

void set_message(const char *message_format, ...);

The first method sets the message text from a String. The second method sets the message text from a character string formatted inline using sprintf-style formatting. For example, this is a message dialog used in the <demos/xfc-demo/appwindow.cc> file from the xfc-demo source code:

Gtk::MessageDialog *dialog(Gtk::MESSAGE_INFO, Gtk::BUTTONS_CLOSE, this);
dialog->set_message("You selected or toggled the \"%s\" menu item: \"%s\"", parent, item);
if (dialog->run())
    dialog->dispose();

To make it easy to format text in a message (changing colors, fonts, etc.), the message text can be provided in a simple markup format using the Pango text markup language (see Gtk::Label::set_markup()). To set the message using markup text call one of the following methods:

void set_markup(const String& message);

void set_markup(const char *message_format, ...);

To display a modal message dialog call the Gtk::Dialog::run method:

int run();


Copyright © 2004-2005 The XFC Development Team Top
XFC 4.4