1 /**
2 * \brief A dockable dialog implementation.
3 *
4 * Author:
5 * Gustav Broberg <broberg@kth.se>
6 *
7 * Copyright (C) 2007 Authors
8 *
9 * Released under GNU GPL. Read the file 'COPYING' for more information.
10 */
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
17 #include "dock-behavior.h"
18 #include "inkscape.h"
19 #include "desktop.h"
20 #include "interface.h"
21 #include "widgets/icon.h"
22 #include "ui/widget/dock.h"
23 #include "verbs.h"
24 #include "dialog.h"
25 #include "prefs-utils.h"
26 #include "dialogs/dialog-events.h"
28 #include <gtkmm/invisible.h>
29 #include <gtkmm/label.h>
30 #include <gtkmm/stock.h>
32 #include <gtk/gtk.h>
34 namespace Inkscape {
35 namespace UI {
36 namespace Dialog {
37 namespace Behavior {
40 DockBehavior::DockBehavior(Dialog &dialog) :
41 Behavior(dialog),
42 _dock_item(*SP_ACTIVE_DESKTOP->getDock(),
43 Inkscape::Verb::get(dialog._verb_num)->get_id(), dialog._title.c_str(),
44 (Inkscape::Verb::get(dialog._verb_num)->get_image() ?
45 Inkscape::Verb::get(dialog._verb_num)->get_image() : ""),
46 static_cast<Widget::DockItem::State>(
47 prefs_get_int_attribute (_dialog._prefs_path, "state",
48 UI::Widget::DockItem::DOCKED_STATE)))
49 {
50 // Connect signals
51 _signal_hide_connection = signal_hide().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::Behavior::DockBehavior::_onHide));
52 _dock_item.signal_state_changed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::Behavior::DockBehavior::_onStateChanged));
54 if (_dock_item.getState() == Widget::DockItem::FLOATING_STATE) {
55 if (Gtk::Window *floating_win = _dock_item.getWindow())
56 sp_transientize(GTK_WIDGET(floating_win->gobj()));
57 }
58 }
60 DockBehavior::~DockBehavior()
61 {
62 }
65 Behavior *
66 DockBehavior::create(Dialog &dialog)
67 {
68 return new DockBehavior(dialog);
69 }
72 DockBehavior::operator Gtk::Widget &()
73 {
74 return _dock_item.getWidget();
75 }
77 GtkWidget *
78 DockBehavior::gobj()
79 {
80 return _dock_item.gobj();
81 }
83 Gtk::VBox *
84 DockBehavior::get_vbox()
85 {
86 return _dock_item.get_vbox();
87 }
89 void
90 DockBehavior::present()
91 {
92 bool was_attached = _dock_item.isAttached();
94 _dock_item.present();
96 if (!was_attached)
97 _dialog.read_geometry();
98 }
100 void
101 DockBehavior::hide()
102 {
103 _signal_hide_connection.block();
104 _dock_item.hide();
105 _signal_hide_connection.unblock();
106 }
108 void
109 DockBehavior::show()
110 {
111 _dock_item.show();
112 }
114 void
115 DockBehavior::show_all_children()
116 {
117 get_vbox()->show_all_children();
118 }
120 void
121 DockBehavior::get_position(int &x, int &y)
122 {
123 _dock_item.get_position(x, y);
124 }
126 void
127 DockBehavior::get_size(int &width, int &height)
128 {
129 _dock_item.get_size(width, height);
130 }
132 void
133 DockBehavior::resize(int width, int height)
134 {
135 _dock_item.resize(width, height);
136 }
138 void
139 DockBehavior::move(int x, int y)
140 {
141 _dock_item.move(x, y);
142 }
144 void
145 DockBehavior::set_position(Gtk::WindowPosition position)
146 {
147 _dock_item.set_position(position);
148 }
150 void
151 DockBehavior::set_size_request(int width, int height)
152 {
153 _dock_item.set_size_request(width, height);
154 }
156 void
157 DockBehavior::size_request(Gtk::Requisition &requisition)
158 {
159 _dock_item.size_request(requisition);
160 }
162 void
163 DockBehavior::set_title(Glib::ustring title)
164 {
165 _dock_item.set_title(title);
166 }
168 void
169 DockBehavior::set_sensitive(bool sensitive)
170 {
171 // TODO check this. Seems to be bad that we ignore the parameter
172 get_vbox()->set_sensitive();
173 }
176 void
177 DockBehavior::_onHide()
178 {
179 _dialog.save_geometry();
180 _dialog._user_hidden = true;
181 prefs_set_int_attribute (_dialog._prefs_path, "state", _dock_item.getPrevState());
182 }
184 void
185 DockBehavior::_onStateChanged(Widget::DockItem::State /*prev_state*/,
186 Widget::DockItem::State new_state)
187 {
188 // TODO probably need to avoid window calls unless the state is different. Check.
189 prefs_set_int_attribute (_dialog._prefs_path, "state", new_state);
191 if (new_state == Widget::DockItem::FLOATING_STATE) {
192 if (Gtk::Window *floating_win = _dock_item.getWindow())
193 sp_transientize(GTK_WIDGET(floating_win->gobj()));
194 }
195 }
197 void
198 DockBehavior::onHideF12()
199 {
200 _dialog.save_geometry();
201 hide();
202 }
204 void
205 DockBehavior::onShowF12()
206 {
207 present();
208 }
210 void
211 DockBehavior::onShutdown()
212 {
213 prefs_set_int_attribute (_dialog._prefs_path, "state", _dock_item.getPrevState());
214 }
216 void
217 DockBehavior::onDesktopActivated(SPDesktop *desktop)
218 {
219 gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
221 #ifdef WIN32 // Win32 special code to enable transient dialogs
222 transient_policy = 2;
223 #endif
225 if (!transient_policy)
226 return;
228 Gtk::Window *floating_win = _dock_item.getWindow();
230 if (floating_win) {
232 if (_dialog.retransientize_suppress) {
233 /* if retransientizing of this dialog is still forbidden after
234 * previous call warning turned off because it was confusingly fired
235 * when loading many files from command line
236 */
238 // g_warning("Retranzientize aborted! You're switching windows too fast!");
239 return;
240 }
242 if (GtkWindow *dialog_win = floating_win->gobj()) {
244 _dialog.retransientize_suppress = true; // disallow other attempts to retranzientize this dialog
246 desktop->setWindowTransient (dialog_win);
248 /*
249 * This enables "aggressive" transientization,
250 * i.e. dialogs always emerging on top when you switch documents. Note
251 * however that this breaks "click to raise" policy of a window
252 * manager because the switched-to document will be raised at once
253 * (so that its transients also could raise)
254 */
255 if (transient_policy == 2 && ! _dialog._hiddenF12 && !_dialog._user_hidden) {
256 // without this, a transient window not always emerges on top
257 gtk_window_present (dialog_win);
258 }
259 }
261 // we're done, allow next retransientizing not sooner than after 120 msec
262 gtk_timeout_add (120, (GtkFunction) sp_retransientize_again, (gpointer) floating_win);
263 }
264 }
267 /* Signal wrappers */
269 Glib::SignalProxy0<void>
270 DockBehavior::signal_show() { return _dock_item.signal_show(); }
272 Glib::SignalProxy0<void>
273 DockBehavior::signal_hide() { return _dock_item.signal_hide(); }
275 Glib::SignalProxy1<bool, GdkEventAny *>
276 DockBehavior::signal_delete_event() { return _dock_item.signal_delete_event(); }
278 Glib::SignalProxy0<void>
279 DockBehavior::signal_drag_begin() { return _dock_item.signal_drag_begin(); }
281 Glib::SignalProxy1<void, bool>
282 DockBehavior::signal_drag_end() { return _dock_item.signal_drag_end(); }
285 } // namespace Behavior
286 } // namespace Dialog
287 } // namespace UI
288 } // namespace Inkscape
290 /*
291 Local Variables:
292 mode:c++
293 c-file-style:"stroustrup"
294 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
295 indent-tabs-mode:nil
296 fill-column:99
297 End:
298 */
299 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :