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