summaryrefslogtreecommitdiffstats
path: root/src/ui/dialog/dialog.h
blob: 012bbc6383ac0a04dcc92462e81dc2fed36a86af (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
// SPDX-License-Identifier: GPL-2.0-or-later
/** @file
 * @brief Base class for dialogs in Inkscape
 */
/* Authors:
 *   Bryce W. Harrington <bryce@bryceharrington.org>
 *   Gustav Broberg <broberg@kth.se>
 *   Kris De Gussem <Kris.DeGussem@gmail.com>
 *
 * Copyright (C) 2004--2007 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */

#ifndef INKSCAPE_DIALOG_H
#define INKSCAPE_DIALOG_H

#include "dock-behavior.h"
#include "floating-behavior.h"

class SPDesktop;
struct InkscapeApplication;

namespace Inkscape {
class Selection;
}

namespace Inkscape {
namespace UI {
namespace Dialog {

enum BehaviorType { FLOATING, DOCK };

gboolean sp_retransientize_again(gpointer dlgPtr);
void sp_dialog_shutdown(GObject *object, gpointer dlgPtr);

/**
 * Base class for Inkscape dialogs.
 * 
 * UI::Dialog::Dialog is a base class for all dialogs in Inkscape.  The
 * purpose of this class is to provide a unified place for ensuring
 * style and behavior. Specifically, this class provides functionality
 * for saving and restoring the size and position of dialogs (through
 * the user's preferences file).
 *
 * It also provides some general purpose signal handlers for things like
 * showing and hiding all dialogs.
 *
 * Fundamental parts of the dialog's behavior are controlled by
 * a UI::Dialog::Behavior subclass instance connected to the dialog.
 *
 * @see UI::Widget::Panel panel class from which the dialogs are actually derived from.
 * @see UI::Dialog::DialogManager manages the dialogs within inkscape.
 * @see UI::Dialog::PanelDialog which links Panel and Dialog together in a dockable and floatable dialog.
 */
class Dialog {

public:

    /**
     * Constructor.
     * 
     * @param behavior_factory floating or docked.
     * @param prefs_path characteristic path for loading/saving dialog position.
     * @param verb_num the dialog verb.
     */
    Dialog(Behavior::BehaviorFactory behavior_factory, const char *prefs_path = nullptr,
           int verb_num = 0, Glib::ustring apply_label = "");

    virtual ~Dialog();

    virtual void onDesktopActivated(SPDesktop*);
    virtual void onShutdown();

    /* Hide and show dialogs */
    virtual void onHideF12();
    virtual void onShowF12();

    virtual operator Gtk::Widget &();
    virtual GtkWidget *gobj();
    virtual void present();
    virtual Gtk::Box *get_vbox();
    virtual void show();
    virtual void hide();
    virtual void show_all_children();
    virtual void set_size_request(int, int);
    virtual void size_request(Gtk::Requisition &);
    virtual void get_position(int &x, int &y);
    virtual void get_size(int &width, int &height);
    virtual void resize(int width, int height);
    virtual void move(int x, int y);
    virtual void set_position(Gtk::WindowPosition position);
    virtual void set_title(Glib::ustring title);
    virtual void set_sensitive(bool sensitive=true);

    virtual Glib::SignalProxy0<void> signal_show();
    virtual Glib::SignalProxy0<void> signal_hide();

    bool           _user_hidden; // when it is closed by the user, to prevent repopping on f12
    bool           _hiddenF12;

    /**
     * Read window position from preferences.
     */
    void           read_geometry();
    
    /**
     * Save window position to preferences.
     */
    void           save_geometry();
    void           save_status(int visible, int state, int placement);

    bool retransientize_suppress; // when true, do not retransientize (prevents races when switching new windows too fast)

protected:
    Glib::ustring const _prefs_path;
    int            _verb_num;
    Glib::ustring  _title;
    Glib::ustring  _apply_label;
    SPDesktop *    _desktop;
    bool           _is_active_desktop;

    virtual void   _handleResponse(int response_id);

    virtual bool   _onDeleteEvent (GdkEventAny*);
    virtual bool   _onEvent(GdkEvent *event);
    virtual bool   _onKeyPress(GdkEventKey *event);

    virtual void   _apply();
    
    /* Closes the dialog window.
     *
     * This code sends a delete_event to the dialog,
     * instead of just destroying it, so that the
     * dialog can do some housekeeping, such as remember
     * its position.
     */
    virtual void   _close();
    virtual void   _defocus();

    Inkscape::Selection*   _getSelection();

    sigc::connection _desktop_activated_connection;
    sigc::connection _dialogs_hidden_connection;
    sigc::connection _dialogs_unhidden_connection;
    sigc::connection _shutdown_connection;
    sigc::connection _change_theme_connection;

  private:
    Behavior::Behavior* _behavior;

    Dialog() = delete; // no constructor without params

    Dialog(Dialog const &d) = delete;            // no copy
    Dialog& operator=(Dialog const &d) = delete; // no assign

    friend class Behavior::FloatingBehavior;
    friend class Behavior::DockBehavior;
};

void sp_add_top_window_classes(Gtk::Widget *widg);
} // namespace Dialog
} // namespace UI
} // namespace Inkscape



#endif //INKSCAPE_DIALOG_H

/*
  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 :