Dialogs

The Dialog widget is very simple, and is actually just a window with a few things pre-packed into it for you. The structure for a Dialog is:

struct GtkDialog
{
      GtkWindow window;
    
      GtkWidget *vbox;
      GtkWidget *action_area;
};

So you see, it simply creates a window, and then packs a vbox into the top, which contains a separator and then an hbox called the "action_area".

The Dialog widget can be used for pop-up messages to the user, and other similar tasks. There are two functions to create a new Dialog.

GtkWidget *gtk_dialog_new( void );

GtkWidget *gtk_dialog_new_with_buttons( const gchar    *title,
                                        GtkWindow      *parent,
                                        GtkDialogFlags  flags, 
                                        const gchar    *first_button_text,
                                        ... );

The first function will create an empty dialog, and it is now up to you to use it. You could pack a button in the action_area by doing something like this:

    button = ...
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->action_area),
                        button, TRUE, TRUE, 0);
    gtk_widget_show (button);

And you could add to the vbox area by packing, for instance, a label in it, try something like this:

    label = gtk_label_new ("Dialogs are groovy");
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG (window)->vbox),
                        label, TRUE, TRUE, 0);
    gtk_widget_show (label);

As an example in using the dialog box, you could put two buttons in the action_area, a Cancel button and an Ok button, and a label in the vbox area, asking the user a question or giving an error etc. Then you could attach a different signal to each of the buttons and perform the operation the user selects.

If the simple functionality provided by the default vertical and horizontal boxes in the two areas doesn't give you enough control for your application, then you can simply pack another layout widget into the boxes provided. For example, you could pack a table into the vertical box.

The more complicated _new_with_buttons() variant allows to set one or more of the following flags.

GTK_DIALOG_MODAL

make the dialog modal.

GTK_DIALOG_DESTROY_WITH_PARENT

ensures that the dialog window is destroyed together with the specified parent.

GTK_DIALOG_NO_SEPARATOR

omits the separator between the vbox and the action_area.