Code

Removed Win32 keep-dialogs-on-top preference, now set permanently to true
[inkscape.git] / src / ui / dialog / floating-behavior.cpp
1 /**
2  * \brief A floating 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  */
12 #include <gtkmm/stock.h>
13 #include <gtk/gtk.h>
15 #include "floating-behavior.h"
16 #include "dialog.h"
18 #include "application/application.h"
19 #include "application/editor.h"
20 #include "inkscape.h"
21 #include "desktop.h"
22 #include "dialogs/dialog-events.h"
23 #include "interface.h"
24 #include "prefs-utils.h"
25 #include "verbs.h"
27 namespace Inkscape {
28 namespace UI {
29 namespace Dialog {
30 namespace Behavior {
32 FloatingBehavior::FloatingBehavior(Dialog &dialog) :
33     Behavior(dialog),
34     _d (new Gtk::Dialog(_dialog._title))
35 {
36     hide();
37     _d->set_has_separator(false);
39     signal_delete_event().connect(sigc::mem_fun(_dialog, &Inkscape::UI::Dialog::Dialog::_onDeleteEvent));
41     sp_transientize(GTK_WIDGET(_d->gobj()));
42     _dialog.retransientize_suppress = false;
43 }
45 FloatingBehavior::~FloatingBehavior() 
46
47     delete _d;
48 }
50 Behavior *
51 FloatingBehavior::create(Dialog &dialog)
52 {
53     return new FloatingBehavior(dialog);
54 }
56 inline FloatingBehavior::operator Gtk::Widget &()                          { return *_d; }
57 inline GtkWidget *FloatingBehavior::gobj()                                { return GTK_WIDGET(_d->gobj()); }
58 inline Gtk::VBox* FloatingBehavior::get_vbox()                            { return _d->get_vbox(); }
59 inline void FloatingBehavior::present()                                   { _d->present(); }
60 inline void FloatingBehavior::hide()                                      { _d->hide(); }
61 inline void FloatingBehavior::show()                                      { _d->show(); }
62 inline void FloatingBehavior::show_all_children()                         { _d->show_all_children(); }
63 inline void FloatingBehavior::resize(int width, int height)               { _d->resize(width, height); }
64 inline void FloatingBehavior::move(int x, int y)                          { _d->move(x, y); }
65 inline void FloatingBehavior::set_position(Gtk::WindowPosition position)  { _d->set_position(position); }
66 inline void FloatingBehavior::set_size_request(int width, int height)     { _d->set_size_request(width, height); }
67 inline void FloatingBehavior::size_request(Gtk::Requisition &requisition) { _d->size_request(requisition); }
68 inline void FloatingBehavior::get_position(int &x, int &y)                { _d->get_position(x, y); }
69 inline void FloatingBehavior::get_size(int &width, int &height)           { _d->get_size(width, height); }
70 inline void FloatingBehavior::set_title(Glib::ustring title)              { _d->set_title(title); }
71 inline void FloatingBehavior::set_sensitive(bool sensitive)               { _d->set_sensitive(sensitive); }
73 Glib::SignalProxy0<void> FloatingBehavior::signal_show() { return _d->signal_show(); }
74 Glib::SignalProxy0<void> FloatingBehavior::signal_hide() { return _d->signal_hide(); }
75 Glib::SignalProxy1<bool, GdkEventAny *> FloatingBehavior::signal_delete_event () { return _d->signal_delete_event(); }
78 void
79 FloatingBehavior::onHideF12()
80 {
81     _dialog.save_geometry();
82     hide();
83 }
85 void
86 FloatingBehavior::onShowF12()
87 {
88     show();
89     _dialog.read_geometry();
90 }
92 void
93 FloatingBehavior::onShutdown() {}
95 void
96 FloatingBehavior::onDesktopActivated (SPDesktop *desktop)
97 {
98     gint transient_policy = prefs_get_int_attribute_limited ( "options.transientpolicy", "value", 1, 0, 2);
100 #ifdef WIN32 // Win32 special code to enable transient dialogs
101     transient_policy = 2;
102 #endif        
104     if (!transient_policy) 
105         return;
107     GtkWindow *dialog_win = GTK_WINDOW(_d->gobj());
109     if (_dialog.retransientize_suppress) {
110          /* if retransientizing of this dialog is still forbidden after
111           * previous call warning turned off because it was confusingly fired
112           * when loading many files from command line
113           */
115          // g_warning("Retranzientize aborted! You're switching windows too fast!");
116         return;
117     }
119     if (dialog_win)
120     {
121         _dialog.retransientize_suppress = true; // disallow other attempts to retranzientize this dialog
123         desktop->setWindowTransient (dialog_win);
125         /*
126          * This enables "aggressive" transientization,
127          * i.e. dialogs always emerging on top when you switch documents. Note
128          * however that this breaks "click to raise" policy of a window
129          * manager because the switched-to document will be raised at once
130          * (so that its transients also could raise)
131          */
132         if (transient_policy == 2 && ! _dialog._hiddenF12 && !_dialog._user_hidden) {
133             // without this, a transient window not always emerges on top
134             gtk_window_present (dialog_win);
135         }
136     }
138     // we're done, allow next retransientizing not sooner than after 120 msec
139     gtk_timeout_add (120, (GtkFunction) sp_retransientize_again, (gpointer) _d);
143 } // namespace Behavior
144 } // namespace Dialog
145 } // namespace UI
146 } // namespace Inkscape
148 /*
149   Local Variables:
150   mode:c++
151   c-file-style:"stroustrup"
152   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
153   indent-tabs-mode:nil
154   fill-column:99
155   End:
156 */
157 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :