GTK docking interfaces

By using this site, you agree to have cookies stored on your device, strictly for functional purposes, such as storing your session and preferences.

Dismiss

 gpanthera.hh

View raw Download
text/x-c++ • 7.95 kiB
C++ source, ASCII text
        
            
1
#ifndef GPANTHERA_LIBRARY_H
2
#define GPANTHERA_LIBRARY_H
3
4
#include <gtkmm.h>
5
#include <glibmm.h>
6
#include <glibmm/ustring.h>
7
#include <utility>
8
#include <vector>
9
#include <memory>
10
11
namespace gPanthera {
12
void init();
13
// Utility function to create a signal that fires when a context menu is requested
14
sigc::signal<void(double, double)> add_context_menu(Gtk::Widget &widget);
15
16
class DockStack;
17
class DockWindow;
18
class LayoutManager;
19
20
class DockablePane : public Gtk::Box {
21
private:
22
Gtk::Label label;
23
Glib::ustring name;
24
Gtk::Image *icon;
25
DockStack *stack = nullptr;
26
DockWindow *window = nullptr;
27
std::unique_ptr<Gtk::HeaderBar> header;
28
Gtk::Widget *child;
29
Glib::RefPtr<Gio::SimpleActionGroup> action_group;
30
public:
31
DockWindow *get_window() const;
32
std::shared_ptr<LayoutManager> layout;
33
Glib::RefPtr<Gio::Menu> header_menu = Gio::Menu::create();
34
DockStack *last_stack = nullptr;
35
DockablePane(std::shared_ptr<LayoutManager> layout, Gtk::Widget &child, const Glib::ustring &name, const Glib::ustring &label, Gtk::Image *icon, DockStack *stack = nullptr, Gtk::Widget *custom_header = nullptr);
36
Gtk::Stack *get_stack() const;
37
Glib::ustring get_identifier() const;
38
Gtk::Image *get_icon() const;
39
Gtk::Label *get_label();
40
void redock(DockStack *stack);
41
void pop_out();
42
Gtk::Widget *get_child() const;
43
};
44
45
class DockWindow : public Gtk::Window {
46
private:
47
DockablePane *pane;
48
public:
49
explicit DockWindow(DockablePane *pane);
50
};
51
52
class LayoutManager : public Glib::ObjectBase {
53
private:
54
public:
55
std::vector<DockablePane*> panes;
56
std::vector<DockStack*> stacks;
57
sigc::signal<void(DockablePane*)> signal_pane_moved;
58
LayoutManager();
59
std::string get_layout_as_json() const;
60
61
void restore_json_layout(const std::string& json_string);
62
63
void add_pane(DockablePane *pane);
64
65
void add_stack(DockStack *stack);
66
void remove_pane(DockablePane *pane);
67
void remove_stack(DockStack *stack);
68
};
69
70
class BaseStack : public Gtk::Stack {
71
public:
72
sigc::signal<void(Gtk::Widget*)> signal_child_added;
73
sigc::signal<void(Gtk::Widget*)> signal_child_removed;
74
BaseStack();
75
void add(Gtk::Widget &child, const Glib::ustring &name);
76
void remove(Gtk::Widget &child);
77
void add(Gtk::Widget &child);
78
void add(Gtk::Widget &child, const Glib::ustring &name, const Glib::ustring &title) = delete;
79
};
80
81
class DockStack : public BaseStack {
82
private:
83
public:
84
std::shared_ptr<LayoutManager> layout;
85
Glib::ustring name;
86
std::string id;
87
explicit DockStack(std::shared_ptr<LayoutManager> layout, const Glib::ustring &name, const std::string &id);
88
89
void add_pane(DockablePane &child);
90
};
91
92
class DockButton : public Gtk::ToggleButton {
93
private:
94
sigc::connection active_style_handler;
95
std::shared_ptr<Gtk::DragSource> drag_source;
96
Glib::Value<DockablePane*> value;
97
void update_active_style();
98
public:
99
DockablePane *pane;
100
explicit DockButton(DockablePane *pane);
101
~DockButton() override;
102
};
103
104
class DockStackSwitcher : public Gtk::Box {
105
private:
106
DockStack *stack;
107
sigc::connection add_handler, remove_handler;
108
std::shared_ptr<Gtk::DropTarget> drop_target;
109
public:
110
void update_buttons();
111
explicit DockStackSwitcher(DockStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL);
112
DockStack *get_stack() const;
113
~DockStackSwitcher() override;
114
};
115
116
class ContentStack;
117
class ContentPage;
118
119
class ContentManager : public Glib::ObjectBase {
120
private:
121
ContentPage *last_operated_page = nullptr;
122
public:
123
ContentPage *get_last_operated_page() const;
124
void set_last_operated_page(ContentPage *page);
125
sigc::signal<void(ContentPage*)> signal_page_operated;
126
std::vector<ContentStack*> stacks;
127
ContentManager();
128
129
void add_stack(ContentStack *stack);
130
void remove_stack(ContentStack *stack);
131
};
132
133
class ContentPage : public Gtk::Overlay {
134
protected:
135
ContentStack *stack = nullptr;
136
Gtk::Widget *child;
137
public:
138
Gtk::Widget *tab_widget;
139
std::shared_ptr<ContentManager> content_manager;
140
ContentStack *last_stack = nullptr;
141
ContentPage(std::shared_ptr<ContentManager> content_manager, ContentStack *stack, Gtk::Widget *child, Gtk::Widget *tab_widget);
142
sigc::signal<bool()> signal_close;
143
Gtk::Widget *get_tab_widget() const;
144
void redock(ContentStack *stack);
145
void set_tab_widget(Gtk::Widget *tab_widget);
146
ContentStack *get_stack() const;
147
void lose_visibility();
148
};
149
150
class ContentTab : public Gtk::ToggleButton {
151
private:
152
std::shared_ptr<Gtk::DragSource> drag_source;
153
std::shared_ptr<Gtk::DropTarget> drop_target;
154
Glib::Value<ContentPage*> value;
155
Glib::RefPtr<Gio::Menu> context_menu = Gio::Menu::create();
156
sigc::connection drag_end_handler;
157
sigc::connection drag_cancel_handler;
158
void update_active_style();
159
sigc::connection active_style_handler;
160
public:
161
void close();
162
explicit ContentTab(ContentPage *page);
163
ContentPage *page;
164
~ContentTab() override;
165
};
166
167
class ContentStack : public BaseStack {
168
private:
169
void disable_children();
170
void enable_children();
171
protected:
172
std::function<bool(ContentPage*)> detach_handler;
173
public:
174
sigc::signal<bool(ContentPage*)> signal_detach;
175
std::function<bool(ContentPage*)> get_detach_handler() const;
176
std::shared_ptr<ContentManager> content_manager;
177
std::shared_ptr<Gtk::DropTarget> drop_target;
178
sigc::signal<void()> signal_leave_empty;
179
explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr);
180
void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type);
181
void add_page(ContentPage &child);
182
void remove_with_paned();
183
};
184
185
class ContentTabBar : public Gtk::Box {
186
// Dragging a tab to an empty space should split the view;
187
// dragging a tab outside the window should pop it out with user-defined behaviour
188
private:
189
ContentStack *stack;
190
sigc::connection add_handler, remove_handler;
191
std::shared_ptr<Gtk::DropTarget> drop_target;
192
Gtk::ScrolledWindow *scrolled_window;
193
Gtk::Box *tab_box;
194
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function;
195
public:
196
void update_buttons();
197
explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr);
198
void set_orientation(Gtk::Orientation orientation);
199
void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>);
200
ContentStack *get_stack() const;
201
~ContentTabBar() override;
202
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const;
203
};
204
205
class ContentNotebook : public Gtk::Box {
206
private:
207
ContentStack *stack;
208
ContentTabBar *switcher;
209
Gtk::PositionType tab_position;
210
public:
211
ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP);
212
Gtk::PositionType get_tab_position() const;
213
ContentStack *get_stack() const;
214
ContentTabBar *get_switcher() const;
215
};
216
217
class ContentWindow : public Gtk::Window {
218
private:
219
ContentNotebook *notebook;
220
public:
221
ContentWindow(ContentNotebook *notebook);
222
};
223
} // namespace gPanthera
224
225
#endif // GPANTHERA_LIBRARY_H