Code

The dialog to panel refactoring:
[inkscape.git] / src / ui / dialog / dock-behavior.cpp
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()
103     _signal_hide_connection.block();
104     _dock_item.hide();
105     _signal_hide_connection.unblock();
108 void
109 DockBehavior::show() 
110
111     _dock_item.show();
114 void 
115 DockBehavior::show_all_children()
117     get_vbox()->show_all_children();
120 void 
121 DockBehavior::get_position(int &x, int &y)
122
123     _dock_item.get_position(x, y);
126 void 
127 DockBehavior::get_size(int &width, int &height)
128
129     _dock_item.get_size(width, height);
132 void
133 DockBehavior::resize(int width, int height) 
135     _dock_item.resize(width, height);
138 void
139 DockBehavior::move(int x, int y)
141     _dock_item.move(x, y);
144 void
145 DockBehavior::set_position(Gtk::WindowPosition position)
147     _dock_item.set_position(position);
150 void
151 DockBehavior::set_size_request(int width, int height)
153     _dock_item.set_size_request(width, height);
156 void 
157 DockBehavior::size_request(Gtk::Requisition &requisition)
158
159     _dock_item.size_request(requisition);
162 void
163 DockBehavior::set_title(Glib::ustring title)
165     _dock_item.set_title(title);
168 void
169 DockBehavior::set_sensitive(bool sensitive)
171     get_vbox()->set_sensitive();
175 void
176 DockBehavior::_onHide()
178     _dialog.save_geometry();
179     _dialog._user_hidden = true;
180     prefs_set_int_attribute (_dialog._prefs_path, "state", _dock_item.getPrevState());
183 void
184 DockBehavior::_onStateChanged(Widget::DockItem::State prev_state, 
185                               Widget::DockItem::State new_state)
187     prefs_set_int_attribute (_dialog._prefs_path, "state", new_state);
189     if (new_state == Widget::DockItem::FLOATING_STATE) {
190         if (Gtk::Window *floating_win = _dock_item.getWindow())
191             sp_transientize(GTK_WIDGET(floating_win->gobj()));
192     }
195 void
196 DockBehavior::onHideF12()
198     _dialog.save_geometry();
199     hide();
202 void
203 DockBehavior::onShowF12()
205     present();
208 void
209 DockBehavior::onShutdown()
211     prefs_set_int_attribute (_dialog._prefs_path, "state", _dock_item.getPrevState());
214 void
215 DockBehavior::onDesktopActivated(SPDesktop *desktop)
217     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
219 #ifdef WIN32 // FIXME: Temporary Win32 special code to enable transient dialogs
220     if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
221         transient_policy = 2;
222     else    
223         return;
224 #endif        
226     if (!transient_policy) 
227         return;
229     Gtk::Window *floating_win = _dock_item.getWindow();
231     if (floating_win) {
233         if (_dialog.retransientize_suppress) {
234             /* if retransientizing of this dialog is still forbidden after
235              * previous call warning turned off because it was confusingly fired
236              * when loading many files from command line
237              */
239             // g_warning("Retranzientize aborted! You're switching windows too fast!");
240             return;
241         }
243         if (GtkWindow *dialog_win = floating_win->gobj()) {
245             _dialog.retransientize_suppress = true; // disallow other attempts to retranzientize this dialog
246             
247             desktop->setWindowTransient (dialog_win);
249             /*
250              * This enables "aggressive" transientization,
251              * i.e. dialogs always emerging on top when you switch documents. Note
252              * however that this breaks "click to raise" policy of a window
253              * manager because the switched-to document will be raised at once
254              * (so that its transients also could raise)
255              */
256             if (transient_policy == 2 && ! _dialog._hiddenF12 && !_dialog._user_hidden) {
257                 // without this, a transient window not always emerges on top
258                 gtk_window_present (dialog_win);
259             }
260         }
262         // we're done, allow next retransientizing not sooner than after 120 msec
263         gtk_timeout_add (120, (GtkFunction) sp_retransientize_again, (gpointer) floating_win);
264     }
268 /* Signal wrappers */
270 Glib::SignalProxy0<void> 
271 DockBehavior::signal_show() { return _dock_item.signal_show(); }
273 Glib::SignalProxy0<void> 
274 DockBehavior::signal_hide() { return _dock_item.signal_hide(); }
276 Glib::SignalProxy1<bool, GdkEventAny *> 
277 DockBehavior::signal_delete_event() { return _dock_item.signal_delete_event(); }
279 Glib::SignalProxy0<void>
280 DockBehavior::signal_drag_begin() { return _dock_item.signal_drag_begin(); }
282 Glib::SignalProxy1<void, bool>
283 DockBehavior::signal_drag_end() { return _dock_item.signal_drag_end(); }
286 } // namespace Behavior
287 } // namespace Dialog
288 } // namespace UI
289 } // namespace Inkscape
291 /*
292   Local Variables:
293   mode:c++
294   c-file-style:"stroustrup"
295   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
296   indent-tabs-mode:nil
297   fill-column:99
298   End:
299 */
300 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :