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++ • 8.08 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
sigc::signal<void(bool)> signal_control_status_changed;
144
void close();
145
Gtk::Widget *get_tab_widget() const;
146
void redock(ContentStack *stack);
147
void set_tab_widget(Gtk::Widget *tab_widget);
148
ContentStack *get_stack() const;
149
void lose_visibility();
150
};
151
152
class ContentTab : public Gtk::ToggleButton {
153
private:
154
std::shared_ptr<Gtk::DragSource> drag_source;
155
std::shared_ptr<Gtk::DropTarget> drop_target;
156
Glib::Value<ContentPage*> value;
157
Glib::RefPtr<Gio::Menu> context_menu = Gio::Menu::create();
158
sigc::connection drag_end_handler;
159
sigc::connection drag_cancel_handler;
160
void update_active_style();
161
sigc::connection active_style_handler;
162
sigc::connection control_status_handler;
163
public:
164
void close();
165
explicit ContentTab(ContentPage *page);
166
ContentPage *page;
167
~ContentTab() override;
168
};
169
170
class ContentStack : public BaseStack {
171
private:
172
void disable_children();
173
void enable_children();
174
protected:
175
std::function<bool(ContentPage*)> detach_handler;
176
public:
177
sigc::signal<bool(ContentPage*)> signal_detach;
178
std::function<bool(ContentPage*)> get_detach_handler() const;
179
std::shared_ptr<ContentManager> content_manager;
180
std::shared_ptr<Gtk::DropTarget> drop_target;
181
sigc::signal<void()> signal_leave_empty;
182
explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr);
183
void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type);
184
void add_page(ContentPage &child);
185
void remove_with_paned();
186
};
187
188
class ContentTabBar : public Gtk::Box {
189
// Dragging a tab to an empty space should split the view;
190
// dragging a tab outside the window should pop it out with user-defined behaviour
191
private:
192
ContentStack *stack;
193
sigc::connection add_handler, remove_handler;
194
std::shared_ptr<Gtk::DropTarget> drop_target;
195
Gtk::ScrolledWindow *scrolled_window;
196
Gtk::Box *tab_box;
197
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function;
198
public:
199
void update_buttons();
200
explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr);
201
void set_orientation(Gtk::Orientation orientation);
202
void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>);
203
ContentStack *get_stack() const;
204
~ContentTabBar() override;
205
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const;
206
};
207
208
class ContentNotebook : public Gtk::Box {
209
private:
210
ContentStack *stack;
211
ContentTabBar *switcher;
212
Gtk::PositionType tab_position;
213
public:
214
ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP);
215
Gtk::PositionType get_tab_position() const;
216
ContentStack *get_stack() const;
217
ContentTabBar *get_switcher() const;
218
};
219
220
class ContentWindow : public Gtk::Window {
221
private:
222
ContentNotebook *notebook;
223
public:
224
ContentWindow(ContentNotebook *notebook);
225
};
226
} // namespace gPanthera
227
228
#endif // GPANTHERA_LIBRARY_H