summaryrefslogtreecommitdiffstats
path: root/src/ui/widget/dock-item.h
blob: be7ac77d2b8115b0e943dea31910ee8a4ad76142 (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
// SPDX-License-Identifier: GPL-2.0-or-later
/*
 * Author:
 *   Gustav Broberg <broberg@kth.se>
 *
 * Copyright (C) 2007 Authors
 *
 * Released under GNU GPL v2+, read the file 'COPYING' for more information.
 */


#ifndef INKSCAPE_UI_WIGET_DOCK_ITEM_H
#define INKSCAPE_UI_WIGET_DOCK_ITEM_H

#include <gtkmm/box.h>
#include <gtkmm/frame.h>
#include <gtkmm/window.h>

#include <gdl/gdl.h>

namespace Gtk {
	class HButtonBox;
}

namespace Inkscape {
namespace UI {
namespace Widget {

class Dock;

/**
 * A custom wrapper around gdl-dock-item.
 */
class DockItem {

public:

    enum State { UNATTACHED,                // item not bound to the dock (a temporary state)
                 FLOATING_STATE,            // item not in its dock (but can be docked in other,
                                            // e.g. floating, docks)
                 DOCKED_STATE,              // item in its assigned dock
                 ICONIFIED_DOCKED_STATE,    // item iconified in its assigned dock from dock
                 ICONIFIED_FLOATING_STATE}; // item iconified in its assigned dock from float

    DockItem(Dock& dock, const Glib::ustring& name, const Glib::ustring& long_name, 
             const Glib::ustring& icon_name, State state, GdlDockPlacement placement);

    ~DockItem();

    Gtk::Widget& getWidget();
    GtkWidget *gobj();

    Gtk::VBox *get_vbox();

    void get_position(int& x, int& y);
    void get_size(int& width, int& height);

    void resize(int width, int height);
    void move(int x, int y);
    void set_position(Gtk::WindowPosition);
    void set_size_request(int width, int height);
    void size_request(Gtk::Requisition& requisition);
    void set_title(Glib::ustring title);

    bool isAttached() const;
    bool isFloating() const;
    bool isIconified() const;
    State getState() const;
    State getPrevState() const;
    GdlDockPlacement getPlacement() const;

    Gtk::Window *getWindow();   //< gives the parent window, if the dock item has one (i.e. it's floating)

    void hide();
    void show();
    void iconify();
    void show_all();

    void present();

    void grab_focus();

    Glib::SignalProxy0<void> signal_show();
    Glib::SignalProxy0<void> signal_hide();
    Glib::SignalProxy1<bool, GdkEventAny *> signal_delete_event();
    Glib::SignalProxy0<void> signal_drag_begin();
    Glib::SignalProxy1<void, bool> signal_drag_end();
    Glib::SignalProxy0<void> signal_realize();

    sigc::signal<void, State, State> signal_state_changed();

private:
    Dock &_dock;              //< parent dock

    State _prev_state;        //< last known state

    int _prev_position;

    Gtk::Window *_window;     //< reference to floating window, if any 
    int _x, _y;               //< last known position of window, if floating

    bool _grab_focus_on_realize;   //< if the dock item should grab focus on the next realize

    GtkWidget *_gdl_dock_item;
    Glib::RefPtr<Gdk::Pixbuf> _icon_pixbuf;

    /** Interface widgets, will be packed like 
     * gdl_dock_item -> _frame -> _dock_item_box
     */
    Gtk::Frame _frame;
    Gtk::VBox _dock_item_box;

    /** Internal signal handlers */
    void _onHide();
    void _onHideWindow();
    void _onShow();
    void _onDragBegin();
    void _onDragEnd(bool cancelled);
    void _onRealize();

    bool _onKeyPress(GdkEventKey *event);
    void _onStateChanged(State prev_state, State new_state);
    bool _onDeleteEvent(GdkEventAny *event);

    sigc::connection _signal_key_press_event_connection;

    /** GdlDockItem signal proxy structures */
    static const Glib::SignalProxyInfo _signal_show_proxy;
    static const Glib::SignalProxyInfo _signal_hide_proxy;
    static const Glib::SignalProxyInfo _signal_delete_event_proxy;

    static const Glib::SignalProxyInfo _signal_drag_begin_proxy;
    static const Glib::SignalProxyInfo _signal_drag_end_proxy;
    static const Glib::SignalProxyInfo _signal_realize_proxy;

    static gboolean _signal_delete_event_callback(GtkWidget *self, GdkEventAny *event, void *data);
    static void _signal_drag_end_callback(GtkWidget* self, gboolean p0, void* data);

    sigc::signal<void, State, State> _signal_state_changed;

    DockItem() = delete;
};

} // namespace Widget
} // namespace UI
} // namespace Inkscape

#endif // INKSCAPE_UI_WIGET_DOCK_ITEM_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 :