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 // FIXME: Temporary Win32 special code to enable transient dialogs
101 if (prefs_get_int_attribute ( "options.dialogsontopwin32", "value", 0))
102 transient_policy = 2;
103 else
104 return;
105 #endif
107 if (!transient_policy)
108 return;
110 GtkWindow *dialog_win = GTK_WINDOW(_d->gobj());
112 if (_dialog.retransientize_suppress) {
113 /* if retransientizing of this dialog is still forbidden after
114 * previous call warning turned off because it was confusingly fired
115 * when loading many files from command line
116 */
118 // g_warning("Retranzientize aborted! You're switching windows too fast!");
119 return;
120 }
122 if (dialog_win)
123 {
124 _dialog.retransientize_suppress = true; // disallow other attempts to retranzientize this dialog
126 desktop->setWindowTransient (dialog_win);
128 /*
129 * This enables "aggressive" transientization,
130 * i.e. dialogs always emerging on top when you switch documents. Note
131 * however that this breaks "click to raise" policy of a window
132 * manager because the switched-to document will be raised at once
133 * (so that its transients also could raise)
134 */
135 if (transient_policy == 2 && ! _dialog._hiddenF12 && !_dialog._user_hidden) {
136 // without this, a transient window not always emerges on top
137 gtk_window_present (dialog_win);
138 }
139 }
141 // we're done, allow next retransientizing not sooner than after 120 msec
142 gtk_timeout_add (120, (GtkFunction) sp_retransientize_again, (gpointer) _d);
143 }
146 } // namespace Behavior
147 } // namespace Dialog
148 } // namespace UI
149 } // namespace Inkscape
151 /*
152 Local Variables:
153 mode:c++
154 c-file-style:"stroustrup"
155 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
156 indent-tabs-mode:nil
157 fill-column:99
158 End:
159 */
160 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :