W Wrapl, The Programming Language

Libraries:Gtk:Gtk:Dialog

Types

T

Inherits from:

Dialog boxes are a convenient way to prompt the user for a small amount of input, e.g. to display a message, ask a question, or anything else that does not require extensive effort on the user's part.

GTK+ treats a dialog as a window split vertically. The top section is a Gtk.Gtk.VBox.T, and is where widgets such as a Gtk.Gtk.Label.T or a Gtk.Gtk.Entry.T should be packed. The bottom area is known as the action_area. This is generally used for packing buttons into the dialog which may perform functions such as cancel, ok, or apply. The two areas are separated by a Gtk.Gtk.HSeparator.T.

T boxes are created with a call to gtk_dialog_new() or gtk_dialog_new_with_buttons(). gtk_dialog_new_with_buttons() is recommended; it allows you to set the dialog title, some convenient flags, and add simple buttons.

If 'dialog' is a newly created dialog, the two primary areas of the window can be accessed through GetContentArea and GetActionArea, as can be seen from the example, below.

A 'modal' dialog (that is, one which freezes the rest of the application from user input), can be created by calling Gtk.Gtk.Window.SetModal on the dialog. Use the GTK_WINDOW() macro to cast the widget returned from gtk_dialog_new() into a Gtk.Gtk.Window.T. When using gtk_dialog_new_with_buttons() you can also pass the Gtk.Gtk.DialogFlags.Modal flag to make a dialog modal.

If you add buttons to T using gtk_dialog_new_with_buttons(), AddButton, AddButtons, or AddActionWidget, clicking the button will emit a signal called "response" with a response ID that you specified. GTK+ will never assign a meaning to positive response IDs; these are entirely user-defined. But for convenience, you can use the response IDs in the Gtk.Gtk.ResponseType.T enumeration (these all have values less than zero). If a dialog receives a delete event, the "response" signal will be emitted with a response ID of Gtk.Gtk.ResponseType.DeleteEvent.

If you want to block waiting for a dialog to return before returning control flow to your code, you can call Run. This function enters a recursive main loop and waits for the user to respond to the dialog, returning the response ID corresponding to the button the user clicked.

For the simple dialog in the following example, in reality you'd probably use Gtk.Gtk.MessageDialog.T to save yourself some effort. But you'd need to create the dialog contents manually if you had more than a simple message in the dialog.

Example 6. Simple GtkDialog usage.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* Function to open a dialog box displaying the message provided. */
void quick_message (gchar *message) {
   GtkWidget *dialog, *label, *content_area;
   /* Create the widgets */
   dialog = gtk_dialog_new_with_buttons ("Message",
                                         main_application_window,
                                         GTK_DIALOG_DESTROY_WITH_PARENT,
                                         GTK_STOCK_OK,
                                         GTK_RESPONSE_NONE,
                                         NULL);
   content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
   label = gtk_label_new (message);
   /* Ensure that the dialog box is destroyed when the user responds. */
   g_signal_connect_swapped (dialog,
                             "response",
                             G_CALLBACK (gtk_widget_destroy),
                             dialog);
   /* Add the label, and show everything we've added to the dialog. */
   gtk_container_add (GTK_CONTAINER (content_area), label);
   gtk_widget_show_all (dialog);
}



GtkDialog as GtkBuildable

The GtkDialog implementation of the GtkBuildable interface exposes the vbox and action_area as internal children with the names "vbox" and "action_area".

GtkDialog supports a custom <action-widgets> element, which can contain multiple <action-widget> elements. The "response" attribute specifies a numeric response, and the content of the element is the id of widget (which should be a child of the dialogs action_area).

Example 7. A GtkDialog UI definition fragment.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<object class="GtkDialog" id="dialog1">
  <child internal-child="vbox">"
    <object class="GtkVBox" id="vbox">
      <child internal-child="action_area">
        <object class="GtkHButtonBox" id="button_box">
          <child>
            <object class="GtkButton" id="button_cancel"/>
          </child>
          <child>
            <object class="GtkButton" id="button_ok"/>
          </child>
        </object>
      </child>
    </object>
  </child>
  <action-widgets>
    <action-widget response="3">button_ok</action-widget>
    <action-widget response="-5">button_cancel</action-widget>
  </action-widgets>
</object>




Constants

Nil : T

Functions

GetType() : Gtk.GObject.Type.T



New() : Gtk.Gtk.Dialog.T

Creates a new dialog box. Widgets should not be packed into this Gtk.Gtk.Window.T directly, but into the vbox and action_area, as described above.

Returns a new T.


NewWithButtons(title @ Std.String.T, parent @ Gtk.Gtk.Window.T, flags @ Std.Integer.SmallT, first_button_text @ Std.String.T, ... @ Std.Object.T) : Gtk.Gtk.Dialog.T

Creates a new T with title title (or NULL for the default title; see Gtk.Gtk.Window.SetTitle) and transient parent parent (or NULL for none; see Gtk.Gtk.Window.SetTransientFor). The flags argument can be used to make the dialog modal (Gtk.Gtk.DialogFlags.Modal) and/or to have it destroyed along with its transient parent (Gtk.Gtk.DialogFlags.DestroyWithParent). After flags, button text/response ID pairs should be listed, with a NULL pointer ending the list. Button text can be either a stock ID such as GTK_STOCK_OK, or some arbitrary text. A response ID can be any positive number, or one of the values in the Gtk.Gtk.ResponseType.T enumeration. If the user clicks one of these dialog buttons, T will emit the "response" signal with the corresponding response ID. If a T receives the "delete-event" signal, it will emit ::response with a response ID of Gtk.Gtk.ResponseType.DeleteEvent. However, destroying a dialog does not emit the ::response signal; so be careful relying on ::response when using the Gtk.Gtk.DialogFlags.DestroyWithParent flag. Buttons are from left to right, so the first button in the list will be the leftmost button in the dialog.

Here's a simple example:



Methods

:AddActionWidget(self @ T, child @ Gtk.Gtk.Widget.T, response_id @ Std.Integer.SmallT) : Std.Object.T

Adds an activatable widget to the action area of a T, connecting a signal handler that will emit the "response" signal on the dialog when the widget is activated. The widget is appended to the end of the dialog's action area. If you want to add a non-activatable widget, simply pack it into the action_area field of the T struct.

dialog a T
child an activatable widget
response_id response ID for child


:AddButton(self @ T, button_text @ Std.String.T, response_id @ Std.Integer.SmallT) : Gtk.Gtk.Widget.T

Adds a button with the given text (or a stock button, if button_text is a stock ID) and sets things up so that clicking the button will emit the "response" signal with the given response_id. The button is appended to the end of the dialog's action area. The button widget is returned, but usually you don't need it.

dialog a T
button_text text of button, or stock ID
response_id response ID for the button
Returns the button widget that was added. [transfer none]


:AddButtons(self @ T, first_button_text @ Std.String.T, ... @ Std.Object.T) : Std.Object.T

Adds more buttons, same as calling AddButton repeatedly. The variable argument list should be NULL-terminated as with gtk_dialog_new_with_buttons(). Each button must have both text and response ID.

dialog a T
first_button_text button text or stock ID


:GetActionArea(self @ T) : Gtk.Gtk.Widget.T

Returns the action area of dialog.

dialog a T
Returns the action area. [transfer none]


:GetContentArea(self @ T) : Gtk.Gtk.Widget.T

Returns the content area of dialog.

dialog a T
Returns the content area Gtk.Gtk.VBox.T. [transfer none]


:GetHasSeparator(self @ T) : Std.Symbol.T

Warning

GetHasSeparator has been deprecated since version 2.22 and should not be used in newly-written code. This function will be removed in GTK+ 3



:GetResponseForWidget(self @ T, widget @ Gtk.Gtk.Widget.T) : Std.Integer.SmallT

Gets the response id of a widget in the action area of a dialog.

dialog a T
widget a widget in the action area of dialog
Returns the response id of widget, or Gtk.Gtk.ResponseType.None if widget doesn't have a response id set.


:GetWidgetForResponse(self @ T, response_id @ Std.Integer.SmallT) : Gtk.Gtk.Widget.T

Gets the widget button that uses the given response ID in the action area of a dialog.

dialog a T
response_id the response ID used by the dialog widget
Returns the widget button that uses the given response_id, or NULL. [transfer none]


:Response(self @ T, response_id @ Std.Integer.SmallT) : Std.Object.T

Emits the "response" signal with the given response ID. Used to indicate that the user has responded to the dialog in some way; typically either you or Run will be monitoring the ::response signal and take appropriate action.

dialog a T
response_id response ID


:Run(self @ T) : Std.Integer.SmallT

Blocks in a recursive main loop until the dialog either emits the "response" signal, or is destroyed. If the dialog is destroyed during the call to Run, Run returns Gtk.Gtk.ResponseType.None. Otherwise, it returns the response ID from the ::response signal emission.

Before entering the recursive main loop, Run calls Gtk.Gtk.Widget.Show on the dialog for you. Note that you still need to show any children of the dialog yourself.

During Run, the default behavior of "delete-event" is disabled; if the dialog receives ::delete_event, it will not be destroyed as windows usually are, and Run will return Gtk.Gtk.ResponseType.DeleteEvent. Also, during Run the dialog will be modal. You can force Run to return at any time by calling Response to emit the ::response signal. Destroying the dialog during Run is a very bad idea, because your post-run code won't know whether the dialog was destroyed or not.

After Run returns, you are responsible for hiding or destroying the dialog if you wish to do so.

Typical usage of this function might be:

1
2
3
4
5
6
7
8
9
10
11
gint result = gtk_dialog_run (GTK_DIALOG (dialog));
switch (result)
  {
    case GTK_RESPONSE_ACCEPT:
       do_application_specific_something ();
       break;
    default:
       do_nothing_since_dialog_was_cancelled ();
       break;
  }
gtk_widget_destroy (dialog);


:SetAlternativeButtonOrder(self @ T, first_response_id @ Std.Integer.SmallT, ... @ Std.Object.T) : Std.Object.T

Sets an alternative button order. If the "gtk-alternative-button-order" setting is set to TRUE, the dialog buttons are reordered according to the order of the response ids passed to this function.

By default, GTK+ dialogs use the button order advocated by the Gnome Human Interface Guidelines with the affirmative button at the far right, and the cancel button left of it. But the builtin GTK+ dialogs and Gtk.Gtk.MessageDialog.Ts do provide an alternative button order, which is more suitable on some platforms, e.g. Windows.

Use this function after adding all the buttons to your dialog, as the following example shows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                       GTK_STOCK_CANCEL,
                                       GTK_RESPONSE_CANCEL);
 
ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                   GTK_STOCK_OK,
                                   GTK_RESPONSE_OK);
  
gtk_widget_grab_default (ok_button);
  
help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                     GTK_STOCK_HELP,
                                     GTK_RESPONSE_HELP);
 
gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                         GTK_RESPONSE_OK,
                                         GTK_RESPONSE_CANCEL,
                                         GTK_RESPONSE_HELP,
                                         -1);


:SetAlternativeButtonOrderFromArray(self @ T, n_params @ Std.Integer.SmallT, new_order @ Std.Object.T) : Std.Object.T

Sets an alternative button order. If the "gtk-alternative-button-order" setting is set to TRUE, the dialog buttons are reordered according to the order of the response ids in new_order.

See SetAlternativeButtonOrder for more information.

This function is for use by language bindings.

dialog a T
n_params the number of response ids in new_order
new_order an array of response ids of dialog's buttons. [array length=n_params]


:SetDefaultResponse(self @ T, response_id @ Std.Integer.SmallT) : Std.Object.T

Sets the last widget in the dialog's action area with the given response_id as the default widget for the dialog. Pressing "Enter" normally activates the default widget.

dialog a T
response_id a response ID


:SetHasSeparator(self @ T, setting @ Std.Symbol.T) : Std.Object.T

Warning

SetHasSeparator has been deprecated since version 2.22 and should not be used in newly-written code. This function will be removed in GTK+ 3



:SetResponseSensitive(self @ T, response_id @ Std.Integer.SmallT, setting @ Std.Symbol.T) : Std.Object.T

Calls gtk_widget_set_sensitive (widget, setting) for each widget in the dialog's action area with the given response_id. A convenient way to sensitize/desensitize dialog buttons.

dialog a T
response_id a response ID
setting TRUE for sensitive