Debian Codegraph @

gtk/src/dialog.hg

raw
1 /* Copyright (C) 1998-2002 The gtkmm Development Team
2 *
3 * This library is free software; you can redistribute it and/or
4 * modify it under the terms of the GNU Lesser General Public
5 * License as published by the Free Software Foundation; either
6 * version 2.1 of the License, or (at your option) any later version.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public
14 * License along with this library; if not, see <https://www.gnu.org/licenses/>.
15 */
16
17 #include <vector>
18
19 #include <gtkmm/window.h>
20 #include <gtkmm/box.h>
21 #include <gtkmm/button.h>
22 #include <gtkmm/buttonbox.h>
23 #include <gtkmm/headerbar.h>
24
25 _DEFS(gtkmm,gtk)
26 _PINCLUDE(gtkmm/private/window_p.h)
27
28 namespace Gtk
29 {
30
31 /** @defgroup Dialogs Dialogs
32 */
33
34 _CC_INCLUDE(gtk/gtk.h)
35 _WRAP_ENUM(DialogFlags, GtkDialogFlags, decl_prefix GTKMM_API)
36 _WRAP_ENUM(ResponseType, GtkResponseType, decl_prefix GTKMM_API)
37
38 /** Create popup windows.
39 *
40 * Dialog boxes are a convenient way to prompt the user for a small amount
41 * of input, eg. to display a message, ask a question, or anything else that
42 * does not require extensive effort on the user's part.
43 *
44 * gtkmm treats a dialog as a window split vertically. The top section is a
45 * vertical Gtk::Box, and is where widgets such as a Gtk::Label or a Gtk::Entry should be
46 * packed. The bottom area is known as the action_area. This is generally
47 * used for packing buttons into the dialog which may perform functions such
48 * as cancel, ok, or apply.
49 *
50 * The dialog can be 'modal' (that is, one which freezes the rest of the
51 * application from user input) - this can be specified in the Gtk::Dialog
52 * constructor.
53 *
54 * When adding buttons using add_button(), clicking the button will emit
55 * signal_response() with a "response id" you specified. You are encouraged
56 * to use the Gtk::ResponseType enum. If a dialog receives a delete event,
57 * the "response" signal will be emitted with a response id of
58 * Gtk::RESPONSE_DELETE_EVENT.
59 *
60 * If you want to block waiting for a dialog to return before returning control
61 * flow to your code, you can call run(). This function enters a
62 * recursive main loop and waits for the user to respond to the dialog, returning
63 * the response ID corresponding to the button the user clicked.
64 *
65 * @ingroup Dialogs
66 */
67 class GTKMM_API Dialog : public Window
68 {
69 _CLASS_GTKOBJECT(Dialog,GtkDialog,GTK_DIALOG,Gtk::Window,GtkWindow,,,GTKMM_API)
70 _UNMANAGEABLE
71 _IGNORE(gtk_dialog_add_buttons)
72 public:
73 _CTOR_DEFAULT()
74 explicit Dialog(const Glib::ustring& title, bool modal = false);
75 Dialog(const Glib::ustring& title, Gtk::Window& parent, bool modal = false);
76 /** @newin{3,16}
77 */
78 Dialog(const Glib::ustring& title, DialogFlags flags);
79 /** @newin{3,16}
80 */
81 Dialog(const Glib::ustring& title, Gtk::Window& parent, DialogFlags flags);
82
83 _WRAP_METHOD(void add_action_widget(Widget& child, int response_id), gtk_dialog_add_action_widget)
84 _WRAP_METHOD(Button* add_button(const Glib::ustring& button_text, int response_id), gtk_dialog_add_button)
85 _WRAP_METHOD(Button* add_button(const Gtk::StockID& stock_id, int response_id), gtk_dialog_add_button, deprecated "Use the add_button() that takes a Glib::ustring instead.")
86 _WRAP_METHOD(void set_response_sensitive(int response_id, bool setting = true), gtk_dialog_set_response_sensitive)
87 _WRAP_METHOD(void set_default_response(int response_id), gtk_dialog_set_default_response)
88 _WRAP_METHOD(Widget* get_widget_for_response(int response_id), gtk_dialog_get_widget_for_response)
89 _WRAP_METHOD(const Widget* get_widget_for_response(int response_id) const, gtk_dialog_get_widget_for_response, constversion)
90 _WRAP_METHOD(int get_response_for_widget(const Gtk::Widget& widget) const, gtk_dialog_get_response_for_widget)
91
92 _WRAP_METHOD(static bool alternative_button_order(const Glib::RefPtr<const Gdk::Screen>& screen), gtk_alternative_dialog_button_order, deprecated "This should no longer be used.")
93
94 _DEPRECATE_IFDEF_START
95 /** Sets an alternative button order. If the gtk-alternative-button-order
96 * setting is set to true, the dialog buttons are reordered according to
97 * the order of the response ids in @a new_order.
98 *
99 * By default, GTK+ dialogs use the button order advocated by the Gnome
100 * <a href="https://developer.gnome.org/hig/">Human Interface Guidelines</a>
101 * with the affirmative button at the far
102 * right, and the cancel button left of it. But the builtin GTK+ dialogs
103 * and MessageDialog<!-- -->s do provide an alternative button order,
104 * which is more suitable on some platforms, e.g. Windows.
105 *
106 * Use this function after adding all the buttons to your dialog.
107 *
108 * @param new_order an array of response ids of the dialog's buttons.
109 *
110 * @newin{2,6}
111 *
112 * @deprecated "This should no longer be used."
113 */
114 void set_alternative_button_order_from_array(const std::vector<int>& new_order);
115 _IGNORE(gtk_dialog_set_alternative_button_order_from_array, gtk_dialog_set_alternative_button_order)
116 _DEPRECATE_IFDEF_END
117
118 _WRAP_METHOD(void response(int response_id), gtk_dialog_response)
119
120 /** Blocks in a recursive main loop until the dialog either emits the
121 * Gtk::Dialog::signal_response() signal, or is destroyed. If the dialog is
122 * destroyed during the call to run(), run() returns
123 * Gtk::RESPONSE_NONE. Otherwise, it returns the response ID from the
124 * signal_response() signal emission.
125 *
126 * Before entering the recursive main loop, run() calls
127 * Gtk::Widget::show() on the dialog for you. Note that you still
128 * need to show any children of the dialog yourself.
129 *
130 * During run(), the default behavior of Gtk::Widget::signal_delete_event()
131 * is disabled; if the dialog receives the signal_delete_event() signal, it will not be
132 * destroyed as windows usually are, and run() will return
133 * Gtk::RESPONSE_DELETE_EVENT. Also, during run() the dialog
134 * will be modal. You can force run() to return at any time by
135 * calling response() to emit the signal_response() signal. Destroying
136 * the dialog during run() is a very bad idea, because your
137 * post-run code won’t know whether the dialog was destroyed or not.
138 *
139 * After run() returns, you are responsible for hiding or
140 * destroying the dialog if you wish to do so.
141 *
142 * Typical usage of this function might be:
143 * @code
144 * int result = dialog.run();
145 * switch (result)
146 * {
147 * case Gtk::RESPONSE_ACCEPT:
148 * do_application_specific_something();
149 * break;
150 * default:
151 * do_nothing_since_dialog_was_cancelled();
152 * break;
153 * }
154 * @endcode
155 *
156 * Note that even though the recursive main loop gives the effect of a
157 * modal dialog (it prevents the user from interacting with other
158 * windows in the same window group while the dialog is run), callbacks
159 * such as timeouts, IO channel watches, DnD drops, etc, will
160 * be triggered during a run() call.
161 *
162 * @return Response ID.
163 */
164 _WRAP_METHOD(int run(), gtk_dialog_run)
165
166 // This previously returned an HButtonBox*, which broke on Maemo Fremantle.
167 // Changed post-2.18.2
168 _WRAP_METHOD(ButtonBox* get_action_area(), gtk_dialog_get_action_area, deprecated "Direct access to the action area is discouraged. Use add_button(), etc.")
169 _WRAP_METHOD(const ButtonBox* get_action_area() const, gtk_dialog_get_action_area, constversion, deprecated "Direct access to the action area is discouraged. Use add_button(), etc.")
170
171 _WRAP_METHOD(Box* get_vbox(), gtk_dialog_get_content_area, deprecated "Use get_content_area() instead.")
172 _WRAP_METHOD(const Box* get_vbox() const, gtk_dialog_get_content_area, constversion, deprecated "Use get_content_area() instead.")
173
174 _WRAP_METHOD(Box* get_content_area(), gtk_dialog_get_content_area)
175 _WRAP_METHOD(const Box* get_content_area() const, gtk_dialog_get_content_area, constversion)
176
177 _WRAP_METHOD(HeaderBar* get_header_bar(), gtk_dialog_get_header_bar) // transfer none
178 _WRAP_METHOD(const HeaderBar* get_header_bar() const, gtk_dialog_get_header_bar, constversion) // transfer none
179
180 _WRAP_SIGNAL(void response(int response_id), "response")
181
182 //_WRAP_PROPERTY("has-separator", bool) //deprecated.
183 _WRAP_PROPERTY("use-header-bar", bool)
184
185 _IGNORE_SIGNAL("close")
186 };
187
188 } //namespace Gtk