.\" Automatically generated by Pod::Man 4.10 (Pod::Simple 3.35) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Gtk2::Dialog 3pm" .TH Gtk2::Dialog 3pm "2019-09-16" "perl v5.28.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Gtk2::Dialog \- wrapper for GtkDialog .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 6 \& # create a new dialog with some buttons \- one stock, one not. \& $dialog = Gtk2::Dialog\->new ($title, $parent_window, $flags, \& \*(Aqgtk\-cancel\*(Aq => \*(Aqcancel\*(Aq, \& \*(AqDo it\*(Aq => \*(Aqok\*(Aq); \& # create window contents for yourself. \& $dialog\->get_content_area ()\->add ($some_widget); \& \& $dialog\->set_default_response (\*(Aqok\*(Aq); \& \& # show and interact modally \-\- blocks until the user \& # activates a response. \& $response = $dialog\->run; \& if ($response eq \*(Aqok\*(Aq) { \& do_the_stuff (); \& } \& \& # activating a response does not destroy the window, \& # that\*(Aqs up to you. \& $dialog\->destroy; .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" Dialog boxes are a convenient way to prompt the user for a small amount of input, eg. to display a message, ask a question, or anything else that does not require extensive effort on the user's part. .PP \&\s-1GTK+\s0 treats a dialog as a window split vertically. The top section is a Gtk2::VBox, and is where widgets such as a Gtk2::Label or a Gtk2::Entry should be packed. The bottom area is known as the \*(L"action_area\*(R". 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 Gtk2::HSeparator. .PP GtkDialog boxes are created with a call to \f(CW\*(C`Gtk2::Dialog\->new\*(C'\fR. The multi-argument form (and its alias, \f(CW\*(C`new_with_buttons\*(C'\fR is recommended; it allows you to set the dialog title, some convenient flags, and add simple buttons all in one go. .PP If \fI\f(CI$dialog\fI\fR is a newly created dialog, the two primary areas of the window can be accessed as \f(CW\*(C`$dialog\->get_content_area ()\*(C'\fR and \&\f(CW\*(C`$dialog\->get_action_area ()\*(C'\fR, as can be seen from the example, below. .PP A 'modal' dialog (that is, one which freezes the rest of the application from user input), can be created by calling the Gtk2::Window method \f(CW\*(C`set_modal\*(C'\fR on the dialog. You can also pass the 'modal' flag to \f(CW\*(C`new\*(C'\fR. .PP If you add buttons to GtkDialog using \f(CW\*(C`new\*(C'\fR, \f(CW\*(C`new_with_buttons\*(C'\fR, \&\f(CW\*(C`add_button\*(C'\fR, \f(CW\*(C`add_buttons\*(C'\fR, or \f(CW\*(C`add_action_widget\*(C'\fR, clicking the button will emit a signal called \*(L"response\*(R" with a response \s-1ID\s0 that you specified. \&\s-1GTK+\s0 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 Gtk2::ResponseType enumeration. If a dialog receives a delete event, the \&\*(L"response\*(R" signal will be emitted with a response \s-1ID\s0 of 'delete\-event'. .PP If you want to block waiting for a dialog to return before returning control flow to your code, you can call \f(CW\*(C`$dialog\->run\*(C'\fR. This function enters a recursive main loop and waits for the user to respond to the dialog, returning the response \s-1ID\s0 corresponding to the button the user clicked. .PP For the simple dialog in the following example, in reality you'd probably use Gtk2::MessageDialog 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. .PP .Vb 1 \& # Function to open a dialog box displaying the message provided. \& \& sub quick_message { \& my $message = shift; \& my $dialog = Gtk2::Dialog\->new (\*(AqMessage\*(Aq, $main_app_window, \& \*(Aqdestroy\-with\-parent\*(Aq, \& \*(Aqgtk\-ok\*(Aq => \*(Aqnone\*(Aq); \& my $label = Gtk2::Label\->new (message); \& $dialog\->get_content_area ()\->add ($label); \& \& # Ensure that the dialog box is destroyed when the user responds. \& $dialog\->signal_connect (response => sub { $_[0]\->destroy }); \& \& $dialog\->show_all; \& } .Ve .SS "Delete, Close and Destroy" .IX Subsection "Delete, Close and Destroy" In the default keybindings the \*(L"Esc\*(R" key calls the \f(CW\*(C`close\*(C'\fR action signal. The default in that signal is to synthesise a \f(CW\*(C`delete\-event\*(C'\fR like a window manager close would do. .PP A delete-event first runs the \f(CW\*(C`response\*(C'\fR signal with \s-1ID\s0 \&\f(CW"delete\-event"\fR, but the handler there can't influence the default destroy behaviour of the \f(CW\*(C`delete\-event\*(C'\fR signal. See Gtk2::Window for notes on destroy vs hide. .PP If you add your own \*(L"Close\*(R" button to the dialog, perhaps using the builtin \f(CW\*(C`close\*(C'\fR response \s-1ID,\s0 you must make your \f(CW\*(C`response\*(C'\fR signal handler do whatever's needed for closing. Often a good thing is just to run the \f(CW\*(C`close\*(C'\fR action signal the same as the Esc key. .PP .Vb 4 \& sub my_response_handler { \& my ($dialog, $response) = @_; \& if ($response eq \*(Aqclose\*(Aq) { \& $self\->signal_emit (\*(Aqclose\*(Aq); \& \& } elsif ... \& } .Ve .SH "HIERARCHY" .IX Header "HIERARCHY" .Vb 8 \& Glib::Object \& +\-\-\-\-Glib::InitiallyUnowned \& +\-\-\-\-Gtk2::Object \& +\-\-\-\-Gtk2::Widget \& +\-\-\-\-Gtk2::Container \& +\-\-\-\-Gtk2::Bin \& +\-\-\-\-Gtk2::Window \& +\-\-\-\-Gtk2::Dialog .Ve .SH "INTERFACES" .IX Header "INTERFACES" .Vb 2 \& Glib::Object::_Unregistered::AtkImplementorIface \& Gtk2::Buildable .Ve .SH "METHODS" .IX Header "METHODS" .ie n .SS "$widget = Gtk2::Dialog\->\fBnew\fP;" .el .SS "\f(CW$widget\fP = Gtk2::Dialog\->\fBnew\fP;" .IX Subsection "$widget = Gtk2::Dialog->new;" .ie n .SS "$widget = Gtk2::Dialog\->\fBnew\fP ($title, $parent, $flags, ...)" .el .SS "\f(CW$widget\fP = Gtk2::Dialog\->\fBnew\fP ($title, \f(CW$parent\fP, \f(CW$flags\fP, ...)" .IX Subsection "$widget = Gtk2::Dialog->new ($title, $parent, $flags, ...)" .IP "\(bu" 4 \&... (list) of button-text => response-id pairs. .IP "\(bu" 4 \&\f(CW$flags\fR (Gtk2::DialogFlags) interesting properties .IP "\(bu" 4 \&\f(CW$parent\fR (Gtk2::Window or undef) make the new dialog transient for this window .IP "\(bu" 4 \&\f(CW$title\fR (string) window title .PP The multi-argument form takes the same list of text => response-id pairs as \&\f(CW\*(C`$dialog\->add_buttons\*(C'\fR. Do not pack widgets directly into the window; add them to \f(CW\*(C`$dialog\->get_content_area ()\*(C'\fR. .PP Here's a simple example: .PP .Vb 5 \& $dialog = Gtk2::Dialog\->new (\*(AqA cool dialog\*(Aq, \& $main_app_window, \& [qw/modal destroy\-with\-parent/], \& \*(Aqgtk\-ok\*(Aq => \*(Aqaccept\*(Aq, \& \*(Aqgtk\-cancel\*(Aq => \*(Aqreject\*(Aq); .Ve .ie n .SS "$widget = Gtk2::Dialog\->\fBnew_with_buttons\fP ($title, $parent, $flags, ...)" .el .SS "\f(CW$widget\fP = Gtk2::Dialog\->\fBnew_with_buttons\fP ($title, \f(CW$parent\fP, \f(CW$flags\fP, ...)" .IX Subsection "$widget = Gtk2::Dialog->new_with_buttons ($title, $parent, $flags, ...)" .IP "\(bu" 4 \&... (list) of button-text => response-id pairs. .PP Alias for the multi-argument version of \f(CW\*(C`Gtk2::Dialog\->new\*(C'\fR. .ie n .SS "widget = $dialog\->\fBget_action_area\fP" .el .SS "widget = \f(CW$dialog\fP\->\fBget_action_area\fP" .IX Subsection "widget = $dialog->get_action_area" .ie n .SS "$dialog\->\fBadd_action_widget\fP ($child, $response_id)" .el .SS "\f(CW$dialog\fP\->\fBadd_action_widget\fP ($child, \f(CW$response_id\fP)" .IX Subsection "$dialog->add_action_widget ($child, $response_id)" .IP "\(bu" 4 \&\f(CW$child\fR (Gtk2::Widget) .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .ie n .SS "widget = $dialog\->\fBadd_button\fP ($button_text, $response_id)" .el .SS "widget = \f(CW$dialog\fP\->\fBadd_button\fP ($button_text, \f(CW$response_id\fP)" .IX Subsection "widget = $dialog->add_button ($button_text, $response_id)" .IP "\(bu" 4 \&\f(CW$button_text\fR (string) may be arbitrary text with mnenonics, or stock ids .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .PP Returns the created button. .ie n .SS "$dialog\->\fBadd_buttons\fP (...)" .el .SS "\f(CW$dialog\fP\->\fBadd_buttons\fP (...)" .IX Subsection "$dialog->add_buttons (...)" .IP "\(bu" 4 \&... (list) of button-text => response-id pairs .PP Like calling \f(CW\*(C`$dialog\->add_button\*(C'\fR repeatedly, except you don't get the created widgets back. The buttons go from left to right, so the first button added will be the left-most one. .ie n .SS "$dialog\->\fBset_alternative_button_order\fP (...)" .el .SS "\f(CW$dialog\fP\->\fBset_alternative_button_order\fP (...)" .IX Subsection "$dialog->set_alternative_button_order (...)" .IP "\(bu" 4 \&... (list) .PP Since: gtk+ 2.6 .ie n .SS "widget = $dialog\->\fBget_content_area\fP" .el .SS "widget = \f(CW$dialog\fP\->\fBget_content_area\fP" .IX Subsection "widget = $dialog->get_content_area" .ie n .SS "$dialog\->\fBset_default_response\fP ($response_id)" .el .SS "\f(CW$dialog\fP\->\fBset_default_response\fP ($response_id)" .IX Subsection "$dialog->set_default_response ($response_id)" .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .ie n .SS "boolean = $dialog\->\fBget_has_separator\fP" .el .SS "boolean = \f(CW$dialog\fP\->\fBget_has_separator\fP" .IX Subsection "boolean = $dialog->get_has_separator" .ie n .SS "$dialog\->\fBset_has_separator\fP ($setting)" .el .SS "\f(CW$dialog\fP\->\fBset_has_separator\fP ($setting)" .IX Subsection "$dialog->set_has_separator ($setting)" .IP "\(bu" 4 \&\f(CW$setting\fR (boolean) .ie n .SS "$dialog\->\fBresponse\fP ($response_id)" .el .SS "\f(CW$dialog\fP\->\fBresponse\fP ($response_id)" .IX Subsection "$dialog->response ($response_id)" .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .PP Emit the response signal, as though the user had clicked on the button with \&\fI\f(CI$response_id\fI\fR. .ie n .SS "scalar = $dialog\->\fBget_response_for_widget\fP ($widget)" .el .SS "scalar = \f(CW$dialog\fP\->\fBget_response_for_widget\fP ($widget)" .IX Subsection "scalar = $dialog->get_response_for_widget ($widget)" .IP "\(bu" 4 \&\f(CW$widget\fR (Gtk2::Widget) .PP Since: gtk+ 2.8 .ie n .SS "$dialog\->\fBset_response_sensitive\fP ($response_id, $setting)" .el .SS "\f(CW$dialog\fP\->\fBset_response_sensitive\fP ($response_id, \f(CW$setting\fP)" .IX Subsection "$dialog->set_response_sensitive ($response_id, $setting)" .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .IP "\(bu" 4 \&\f(CW$setting\fR (boolean) .PP Enable or disable an action button by its \fI\f(CI$response_id\fI\fR. .ie n .SS "$responsetype = $dialog\->\fBrun\fP" .el .SS "\f(CW$responsetype\fP = \f(CW$dialog\fP\->\fBrun\fP" .IX Subsection "$responsetype = $dialog->run" 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 \&\f(CW\*(C`$dialog\->run\*(C'\fR, the function returns '\s-1GTK_RESPONSE_NONE\s0' ('none'). Otherwise, it returns the response \s-1ID\s0 from the \*(L"response\*(R" signal emission. Before entering the recursive main loop, \f(CW\*(C`$dialog\->run\*(C'\fR calls \&\f(CW\*(C`$widget\->show\*(C'\fR on \fI\f(CI$dialog\fI\fR for you. Note that you still need to show any children of the dialog yourself. .PP During \f(CW\*(C`run\*(C'\fR, the default behavior of \*(L"delete_event\*(R" is disabled; if the dialog receives \*(L"delete_event\*(R", it will not be destroyed as windows usually are, and \f(CW\*(C`run\*(C'\fR will return 'delete\-event'. Also, during \f(CW\*(C`run\*(C'\fR the dialog will be modal. You can force \f(CW\*(C`run\*(C'\fR to return at any time by calling \f(CW\*(C`$dialog\->response\*(C'\fR to emit the \*(L"response\*(R" signal. Destroying the dialog during \f(CW\*(C`run\*(C'\fR is a very bad idea, because your post-run code won't know whether the dialog was destroyed or not. .PP After \f(CW\*(C`run\*(C'\fR returns, you are responsible for hiding or destroying the dialog if you wish to do so. .PP Typical usage of this function might be: .PP .Vb 6 \& if (\*(Aqaccept\*(Aq eq $dialog\->run) { \& do_application_specific_something (); \& } else { \& do_nothing_since_dialog_was_cancelled (); \& } \& $dialog\->destroy; .Ve .ie n .SS "widget = $dialog\->\fBget_widget_for_response\fP ($response_id)" .el .SS "widget = \f(CW$dialog\fP\->\fBget_widget_for_response\fP ($response_id)" .IX Subsection "widget = $dialog->get_widget_for_response ($response_id)" .IP "\(bu" 4 \&\f(CW$response_id\fR (Gtk2::ResponseType) .PP Since: gtk+ 2.20 .SH "PROPERTIES" .IX Header "PROPERTIES" .IP "'has\-separator' (boolean : default false : readable / writable / private)" 4 .IX Item "'has-separator' (boolean : default false : readable / writable / private)" The dialog has a separator bar above its buttons .SH "STYLE PROPERTIES" .IX Header "STYLE PROPERTIES" .IP "'action\-area\-border' (integer : default 5 : readable / private)" 4 .IX Item "'action-area-border' (integer : default 5 : readable / private)" Width of border around the button area at the bottom of the dialog .IP "'button\-spacing' (integer : default 6 : readable / private)" 4 .IX Item "'button-spacing' (integer : default 6 : readable / private)" Spacing between buttons .IP "'content\-area\-border' (integer : default 2 : readable / private)" 4 .IX Item "'content-area-border' (integer : default 2 : readable / private)" Width of border around the main dialog area .IP "'content\-area\-spacing' (integer : default 0 : readable / private)" 4 .IX Item "'content-area-spacing' (integer : default 0 : readable / private)" Spacing between elements of the main dialog area .SH "SIGNALS" .IX Header "SIGNALS" .IP "\fBclose\fR (Gtk2::Dialog)" 4 .IX Item "close (Gtk2::Dialog)" .PD 0 .IP "\fBresponse\fR (Gtk2::Dialog, integer)" 4 .IX Item "response (Gtk2::Dialog, integer)" .PD .PP Note that currently in a Perl subclass of \f(CW\*(C`Gtk2::Dialog\*(C'\fR a class closure, ie. class default signal handler, for the \f(CW\*(C`response\*(C'\fR signal will be called with the response \s-1ID\s0 just as an integer, it's not turned into an enum string like \f(CW"ok"\fR the way a handler setup with \&\f(CW\*(C`signal_connect\*(C'\fR receives. .PP Hopefully this will change in the future, so don't count on it. In the interim the easiest thing to do is install your default handler in \&\f(CW\*(C`INIT_INSTANCE\*(C'\fR with a \f(CW\*(C`signal_connect\*(C'\fR. (The subtleties of what order handlers are called in will differ, but often that doesn't matter.) .SH "ENUMS AND FLAGS" .IX Header "ENUMS AND FLAGS" .SS "flags Gtk2::DialogFlags" .IX Subsection "flags Gtk2::DialogFlags" .IP "\(bu" 4 \&'modal' / '\s-1GTK_DIALOG_MODAL\s0' .IP "\(bu" 4 \&'destroy\-with\-parent' / '\s-1GTK_DIALOG_DESTROY_WITH_PARENT\s0' .IP "\(bu" 4 \&'no\-separator' / '\s-1GTK_DIALOG_NO_SEPARATOR\s0' .SS "enum Gtk2::ResponseType" .IX Subsection "enum Gtk2::ResponseType" The response type is somewhat abnormal as far as gtk2\-perl enums go. In C, this enum lists named, predefined integer values for a field that is other composed of whatever integer values you like. In Perl, we allow this to be either one of the string constants listed here or any positive integer value. For example, 'ok', 'cancel', 4, and 42 are all valid response ids. You cannot use arbitrary string values, they must be integers. Be careful, because unknown string values tend to be mapped to 0. .IP "\(bu" 4 \&'none' / '\s-1GTK_RESPONSE_NONE\s0' .IP "\(bu" 4 \&'reject' / '\s-1GTK_RESPONSE_REJECT\s0' .IP "\(bu" 4 \&'accept' / '\s-1GTK_RESPONSE_ACCEPT\s0' .IP "\(bu" 4 \&'delete\-event' / '\s-1GTK_RESPONSE_DELETE_EVENT\s0' .IP "\(bu" 4 \&'ok' / '\s-1GTK_RESPONSE_OK\s0' .IP "\(bu" 4 \&'cancel' / '\s-1GTK_RESPONSE_CANCEL\s0' .IP "\(bu" 4 \&'close' / '\s-1GTK_RESPONSE_CLOSE\s0' .IP "\(bu" 4 \&'yes' / '\s-1GTK_RESPONSE_YES\s0' .IP "\(bu" 4 \&'no' / '\s-1GTK_RESPONSE_NO\s0' .IP "\(bu" 4 \&'apply' / '\s-1GTK_RESPONSE_APPLY\s0' .IP "\(bu" 4 \&'help' / '\s-1GTK_RESPONSE_HELP\s0' .SH "SEE ALSO" .IX Header "SEE ALSO" Gtk2, Glib::Object, Glib::InitiallyUnowned, Gtk2::Object, Gtk2::Widget, Gtk2::Container, Gtk2::Bin, Gtk2::Window .SH "COPYRIGHT" .IX Header "COPYRIGHT" Copyright (C) 2003\-2011 by the gtk2\-perl team. .PP This software is licensed under the \s-1LGPL.\s0 See Gtk2 for a full notice.