MessageDialog


Object Hierarchy:

Gtk.MessageDialog Gtk.MessageDialog Gtk.MessageDialog Gtk.Dialog Gtk.Dialog Gtk.Dialog->Gtk.MessageDialog Gtk.Window Gtk.Window Gtk.Window->Gtk.Dialog Gtk.Bin Gtk.Bin Gtk.Bin->Gtk.Window Gtk.Container Gtk.Container Gtk.Container->Gtk.Bin Gtk.Widget Gtk.Widget Gtk.Widget->Gtk.Container GLib.InitiallyUnowned GLib.InitiallyUnowned GLib.InitiallyUnowned->Gtk.Widget GLib.Object GLib.Object GLib.Object->GLib.InitiallyUnowned Atk.Implementor Atk.Implementor Atk.Implementor->Gtk.MessageDialog Atk.Implementor->Gtk.Dialog Atk.Implementor->Gtk.Window Atk.Implementor->Gtk.Bin Atk.Implementor->Gtk.Container Atk.Implementor->Gtk.Widget Gtk.Buildable Gtk.Buildable Gtk.Buildable->Gtk.MessageDialog Gtk.Buildable->Gtk.Dialog Gtk.Buildable->Gtk.Window Gtk.Buildable->Gtk.Bin Gtk.Buildable->Gtk.Container Gtk.Buildable->Gtk.Widget

Description:

[ CCode ( type_id = "gtk_message_dialog_get_type ()" ) ]
public class MessageDialog : Dialog, Implementor, Buildable

MessageDialog presents a dialog with some message text.

It’s simply a convenience widget; you could construct the equivalent of MessageDialog from Dialog without too much effort, but MessageDialog saves typing.

One difference from Dialog is that MessageDialog 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 run, though you can also pass in the gtk_dialog_modal flag, run automatically makes the dialog modal and waits for the user to respond to it. run returns when any dialog button is clicked.

An example for using a modal dialog:

 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);
u might do a non-modal MessageDialog as follows:

An example for a non-modal dialog:

 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);
GtkMessageDialog as GtkBuildable

The GtkMessageDialog implementation of the GtkBuildable interface exposes the message area as an internal child with the name “message_area”.

GtkMessageDialog

Example: MessageDialog:

public class Application : Gtk.Window {
public Application () {
// Prepare Gtk.Window:
this.title = "My Gtk.MessageDialog";
this.window_position = Gtk.WindowPosition.CENTER;
this.destroy.connect (Gtk.main_quit);
this.set_default_size (350, 70);

// The MessageDialog
Gtk.MessageDialog msg = new Gtk.MessageDialog (this, Gtk.DialogFlags.MODAL, Gtk.MessageType.WARNING, Gtk.ButtonsType.OK_CANCEL, "My message!");
msg.response.connect ((response_id) => {
switch (response_id) {
case Gtk.ResponseType.OK:
print ("Ok\n");
break;
case Gtk.ResponseType.CANCEL:
print ("Cancel\n");
break;
case Gtk.ResponseType.DELETE_EVENT:
print ("Delete\n");
break;
}

msg.destroy();
});
msg.show ();
}

public static int main (string[] args) {
Gtk.init (ref args);

Application app = new Application ();
app.show_all ();
Gtk.main ();
return 0;
}
}

valac --pkg gtk+-3.0 Gtk.MessageDialog.vala


Namespace: Gtk
Package: gtk+-3.0

Content:

Properties:

Creation methods:

Methods:

Inherited Members:

All known members inherited from class Gtk.Window
All known members inherited from class Gtk.Bin
All known members inherited from class Gtk.Widget
All known members inherited from interface Atk.Implementor