summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/dock-behavior.cpp
blob: 9ea9d0727d6619cacc2020a13a7e639250be2a9e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
// SPDX-License-Identifier: GPL-2.0-or-later
/**
 * @file
 * A dockable dialog implementation.
 */
/* Author:
 *   Gustav Broberg <broberg@kth.se>
 *
 * Copyright (C) 2007 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#include "dock-behavior.h"
#include "inkscape.h"
#include "desktop.h"
#include "ui/widget/dock.h"
#include "verbs.h"
#include "dialog.h"
#include "ui/dialog-events.h"

namespace Inkscape {
namespace UI {
namespace Dialog {
namespace Behavior {


DockBehavior::DockBehavior(Dialog &dialog) :
    Behavior(dialog),
    _dock_item(*SP_ACTIVE_DESKTOP->getDock(),
               Inkscape::Verb::get(dialog._verb_num)->get_id(), dialog._title.c_str(),
               (Inkscape::Verb::get(dialog._verb_num)->get_image() ?
                Inkscape::Verb::get(dialog._verb_num)->get_image() : ""),
               static_cast<Widget::DockItem::State>(
                   Inkscape::Preferences::get()->getInt(_dialog._prefs_path + "/state",
                                            UI::Widget::DockItem::DOCKED_STATE)),
                static_cast<GdlDockPlacement>(
                    Inkscape::Preferences::get()->getInt(_dialog._prefs_path + "/placement",
                                             GDL_DOCK_TOP)))

{
    // Connect signals
    _signal_hide_connection = signal_hide().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::Behavior::DockBehavior::_onHide));
    signal_show().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::Behavior::DockBehavior::_onShow));
    _dock_item.signal_state_changed().connect(sigc::mem_fun(*this, &Inkscape::UI::Dialog::Behavior::DockBehavior::_onStateChanged));
    if (_dock_item.getState() == Widget::DockItem::FLOATING_STATE) {
        if (Gtk::Window *floating_win = _dock_item.getWindow()) {
            sp_transientize(GTK_WIDGET(floating_win->gobj()));
        }
    }
}

DockBehavior::~DockBehavior()
= default;


Behavior *
DockBehavior::create(Dialog &dialog)
{
    return new DockBehavior(dialog);
}


DockBehavior::operator Gtk::Widget &()
{
    return _dock_item.getWidget();
}

GtkWidget *
DockBehavior::gobj()
{
    return _dock_item.gobj();
}

Gtk::VBox *
DockBehavior::get_vbox()
{
    return _dock_item.get_vbox();
}

void
DockBehavior::present()
{
    bool was_attached = _dock_item.isAttached();

    _dock_item.present();

    if (!was_attached)
        _dialog.read_geometry();
}

void
DockBehavior::hide()
{
    _signal_hide_connection.block();
    _dock_item.hide();
    _signal_hide_connection.unblock();
}

void
DockBehavior::show()
{
    _dock_item.show();
}

void
DockBehavior::show_all_children()
{
    get_vbox()->show_all_children();
}

void
DockBehavior::get_position(int &x, int &y)
{
    _dock_item.get_position(x, y);
}

void
DockBehavior::get_size(int &width, int &height)
{
    _dock_item.get_size(width, height);
}

void
DockBehavior::resize(int width, int height)
{
    _dock_item.resize(width, height);
}

void
DockBehavior::move(int x, int y)
{
    _dock_item.move(x, y);
}

void
DockBehavior::set_position(Gtk::WindowPosition position)
{
    _dock_item.set_position(position);
}

void
DockBehavior::set_size_request(int width, int height)
{
    _dock_item.set_size_request(width, height);
}

void
DockBehavior::size_request(Gtk::Requisition &requisition)
{
    _dock_item.size_request(requisition);
}

void
DockBehavior::set_title(Glib::ustring title)
{
    _dock_item.set_title(title);
}

void DockBehavior::set_sensitive(bool sensitive)
{
    // TODO check this. Seems to be bad that we ignore the parameter
    get_vbox()->set_sensitive();
}


void
DockBehavior::_onHide()
{
    _dialog.save_geometry();
    _dialog._user_hidden = true;
}

void
DockBehavior::_onShow()
{
    _dialog._user_hidden = false;
}

void
DockBehavior::_onStateChanged(Widget::DockItem::State /*prev_state*/,
                              Widget::DockItem::State new_state)
{
// TODO probably need to avoid window calls unless the state is different. Check.

    if (new_state == Widget::DockItem::FLOATING_STATE) {
        if (Gtk::Window *floating_win = _dock_item.getWindow())
            sp_transientize(GTK_WIDGET(floating_win->gobj()));
    }
}

void
DockBehavior::onHideF12()
{
    _dialog.save_geometry();
    hide();
}

void
DockBehavior::onShowF12()
{
    present();
}

void
DockBehavior::onShutdown()
{
    int visible = _dock_item.isIconified() || !_dialog._user_hidden;
    int status = (_dock_item.getState() == Inkscape::UI::Widget::DockItem::UNATTACHED) ? _dock_item.getPrevState() : _dock_item.getState();
    _dialog.save_status( visible, status, _dock_item.getPlacement() );
}

void
DockBehavior::onDesktopActivated(SPDesktop *desktop)
{
    Inkscape::Preferences *prefs = Inkscape::Preferences::get();
    gint transient_policy = prefs->getIntLimited( "/options/transientpolicy/value", 1, 0, 2);

#ifdef _WIN32 // Win32 special code to enable transient dialogs
    transient_policy = 2;
#endif

    if (!transient_policy)
        return;

    Gtk::Window *floating_win = _dock_item.getWindow();

    if (floating_win) {

        if (_dialog.retransientize_suppress) {
            /* if retransientizing of this dialog is still forbidden after
             * previous call warning turned off because it was confusingly fired
             * when loading many files from command line
             */

            // g_warning("Retranzientize aborted! You're switching windows too fast!");
            return;
        }

        if (GtkWindow *dialog_win = floating_win->gobj()) {

            _dialog.retransientize_suppress = true; // disallow other attempts to retranzientize this dialog

            desktop->setWindowTransient (dialog_win);

            /*
             * This enables "aggressive" transientization,
             * i.e. dialogs always emerging on top when you switch documents. Note
             * however that this breaks "click to raise" policy of a window
             * manager because the switched-to document will be raised at once
             * (so that its transients also could raise)
             */
            if (transient_policy == 2 && ! _dialog._hiddenF12 && !_dialog._user_hidden) {
                // without this, a transient window not always emerges on top
                gtk_window_present (dialog_win);
            }
        }

        // we're done, allow next retransientizing not sooner than after 120 msec
        g_timeout_add (120, (GSourceFunc) sp_retransientize_again, (gpointer) &_dialog);
    }
}


/* Signal wrappers */

Glib::SignalProxy0<void>
DockBehavior::signal_show() { return _dock_item.signal_show(); }

Glib::SignalProxy0<void>
DockBehavior::signal_hide() { return _dock_item.signal_hide(); }

Glib::SignalProxy1<bool, GdkEventAny *>
DockBehavior::signal_delete_event() { return _dock_item.signal_delete_event(); }

Glib::SignalProxy0<void>
DockBehavior::signal_drag_begin() { return _dock_item.signal_drag_begin(); }

Glib::SignalProxy1<void, bool>
DockBehavior::signal_drag_end() { return _dock_item.signal_drag_end(); }


} // namespace Behavior
} // namespace Dialog
} // namespace UI
} // namespace Inkscape

/*
  Local Variables:
  mode:c++
  c-file-style:"stroustrup"
  c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
  indent-tabs-mode:nil
  fill-column:99
  End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :