Class: Gtk::Dialog

Inherits:
Object
  • Object
show all
Defined in:
(unknown)

Instance Method Summary collapse

Instance Method Details

#action_areaGtk::Box

Returns the action area of dialog.

Returns:

#add_action_widget(child, response_id) ⇒ nil

Adds an activatable widget to the action area of a Gtk::Dialog, connecting a signal handler that will emit the Gtk::Dialog::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 Gtk::Dialog struct.

Parameters:

  • child (Gtk::Widget)

    an activatable widget

  • response_id (Integer)

    response ID for child

Returns:

  • (nil)

#add_button(button_text, response_id) ⇒ Gtk::Widget

Adds a button with the given text and sets things up so that clicking the button will emit the Gtk::Dialog::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.

Parameters:

  • button_text (String)

    text of button

  • response_id (Integer)

    response ID for the button

Returns:

  • (Gtk::Widget)

    the Gtk::Button widget that was added

#add_buttons(first_button_text, array) ⇒ nil

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

Parameters:

  • first_button_text (String)

    button text

  • array (Array)

    response ID for first button, then more text-response_id pairs

Returns:

  • (nil)

#content_areaGtk::Box

Returns the content area of dialog.

Returns:

  • (Gtk::Box)

    the content area Gtk::Box.

#default_response=(response_id) ⇒ nil

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.

Parameters:

  • response_id (Integer)

    a response ID

Returns:

  • (nil)

#get_response_for_widget(widget) ⇒ Integer

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

Parameters:

  • widget (Gtk::Widget)

    a widget in the action area of dialog

Returns:

  • (Integer)

    the response id of widget, or %GTK_RESPONSE_NONE if widget doesn’t have a response id set.

#get_widget_for_response(response_id) ⇒ Gtk::Widget

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

Parameters:

  • response_id (Integer)

    the response ID used by the dialog widget

Returns:

  • (Gtk::Widget)

    the widget button that uses the given response_id, or nil.

#header_barGtk::HeaderBar

Returns the header bar of dialog. Note that the headerbar is only used by the dialog if the Gtk::Dialog:use-header-bar property is true.

Returns:

#newGtk::Widget

Creates a new dialog box.

Widgets should not be packed into this Gtk::Window directly, but into the vbox and action_area, as described above.

Returns:

#new_with_buttons(title, parent, flags, first_button_text, array) ⇒ Gtk::Widget

Creates a new Gtk::Dialog with title title (or nil for the default title; see gtk_window_set_title()) and transient parent parent (or nil for none; see gtk_window_set_transient_for()). The flags argument can be used to make the dialog modal (#GTK_DIALOG_MODAL) and/or to have it destroyed along with its transient parent (#GTK_DIALOG_DESTROY_WITH_PARENT). After flags, button text/response ID pairs should be listed, with a nil pointer ending the list. Button text can be arbitrary text. A response ID can be any positive number, or one of the values in the Gtk::ResponseType enumeration. If the user clicks one of these dialog buttons, Gtk::Dialog will emit the #GtkDialog::response signal with the corresponding response ID. If a Gtk::Dialog receives the #GtkWidget::delete-event signal, it will emit ::response with a response ID of #GTK_RESPONSE_DELETE_EVENT. However, destroying a dialog does not emit the ::response signal; so be careful relying on ::response when using the #GTK_DIALOG_DESTROY_WITH_PARENT 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:

GtkWidget *main_app_window; // Window the dialog should show up on
GtkWidget *dialog;
GtkDialogFlags flags = GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT;
dialog = gtk_dialog_new_with_buttons ("My dialog",
                                      main_app_window,
                                      flags,
                                      _("_OK"),
                                      GTK_RESPONSE_ACCEPT,
                                      _("_Cancel"),
                                      GTK_RESPONSE_REJECT,
                                      NULL);

Parameters:

  • title (String)

    Title of the dialog, or nil

  • parent (Gtk::Window)

    Transient parent of the dialog, or nil

  • flags (Gtk::DialogFlags)

    from Gtk::DialogFlags

  • first_button_text (String)

    text to go in first button, or nil

  • array (Array)

    response ID for first button, then additional buttons, ending with nil

Returns:

#response(response_id) ⇒ nil

Emits the Gtk::Dialog::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 gtk_dialog_run() will be monitoring the ::response signal and take appropriate action.

Parameters:

  • response_id (Integer)

    response ID

Returns:

  • (nil)

#runInteger

Blocks in a recursive main loop until the dialog either emits the Gtk::Dialog::response signal, or is destroyed. If the dialog is destroyed during the call to gtk_dialog_run(), gtk_dialog_run() returns #GTK_RESPONSE_NONE. Otherwise, it returns the response ID from the ::response signal emission.

Before entering the recursive main loop, gtk_dialog_run() calls gtk_widget_show() on the dialog for you. Note that you still need to show any children of the dialog yourself.

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

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

Typical usage of this function might be:

GtkWidget *dialog = gtk_dialog_new ();
// Set up dialog...

int 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);

Note that even though the recursive main loop gives the effect of a modal dialog (it prevents the user from interacting with other windows in the same window group while the dialog is run), callbacks such as timeouts, IO channel watches, DND drops, etc, will be triggered during a gtk_dialog_run() call.

Returns:

  • (Integer)

    response ID

#set_alternative_button_order(first_response_id, array) ⇒ nil

Sets an alternative button order. If the Gtk::Settings: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](library.gnome.org/devel/hig-book/stable/) with the affirmative button at the far right, and the cancel button left of it. But the builtin GTK+ dialogs and Gtk::MessageDialogs 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:

cancel_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                       _("_Cancel"),
                                       GTK_RESPONSE_CANCEL);

ok_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                   _("_OK"),
                                   GTK_RESPONSE_OK);

gtk_widget_grab_default (ok_button);

help_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
                                     _("_Help"),
                                     GTK_RESPONSE_HELP);

gtk_dialog_set_alternative_button_order (GTK_DIALOG (dialog),
                                         GTK_RESPONSE_OK,
                                         GTK_RESPONSE_CANCEL,
                                         GTK_RESPONSE_HELP,
                                         -1);

Parameters:

  • first_response_id (Integer)

    a response id used by one dialog’s buttons

  • array (Array)

    a list of more response ids of dialog’s buttons, terminated by -1

Returns:

  • (nil)

#set_alternative_button_order_from_array(n_params, new_order) ⇒ nil

Sets an alternative button order. If the Gtk::Settings: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 gtk_dialog_set_alternative_button_order() for more information.

This function is for use by language bindings.

Parameters:

  • n_params (Integer)

    the number of response ids in new_order

  • new_order (Array<Integer>)

    an array of response ids of dialog’s buttons

Returns:

  • (nil)

#set_response_sensitive(response_id, setting) ⇒ nil

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.

Parameters:

  • response_id (Integer)

    a response ID

  • setting (TrueClass)

    true for sensitive

Returns:

  • (nil)

#use_header_barInteger

true if the dialog uses a Gtk::HeaderBar for action buttons instead of the action-area.

For technical reasons, this property is declared as an integer property, but you should only set it to true or false.

Returns:

  • (Integer)

    use-header-bar

#use_header_bar=(use_header_bar) ⇒ Integer

true if the dialog uses a Gtk::HeaderBar for action buttons instead of the action-area.

For technical reasons, this property is declared as an integer property, but you should only set it to true or false.

Parameters:

  • use_header_bar (Integer)

Returns:

  • (Integer)

    use-header-bar

  • (Integer)

    use-header-bar