GTK docking interfaces and more

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.12 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
Gtk::PopoverMenu *popover = nullptr;
164
public:
165
void close();
166
explicit ContentTab(ContentPage *page);
167
ContentPage *page;
168
~ContentTab() override;
169
};
170
171
class ContentStack : public BaseStack {
172
private:
173
void disable_children();
174
void enable_children();
175
protected:
176
std::function<bool(ContentPage*)> detach_handler;
177
public:
178
sigc::signal<bool(ContentPage*)> signal_detach;
179
std::function<bool(ContentPage*)> get_detach_handler() const;
180
std::shared_ptr<ContentManager> content_manager;
181
std::shared_ptr<Gtk::DropTarget> drop_target;
182
sigc::signal<void()> signal_leave_empty;
183
explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr);
184
void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type);
185
void add_page(ContentPage &child);
186
void remove_with_paned();
187
};
188
189
class ContentTabBar : public Gtk::Box {
190
// Dragging a tab to an empty space should split the view;
191
// dragging a tab outside the window should pop it out with user-defined behaviour
192
private:
193
ContentStack *stack;
194
sigc::connection add_handler, remove_handler;
195
std::shared_ptr<Gtk::DropTarget> drop_target;
196
Gtk::ScrolledWindow *scrolled_window;
197
Gtk::Box *tab_box;
198
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function;
199
public:
200
void update_buttons();
201
explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr);
202
void set_orientation(Gtk::Orientation orientation);
203
void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>);
204
ContentStack *get_stack() const;
205
~ContentTabBar() override;
206
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const;
207
};
208
209
class ContentNotebook : public Gtk::Box {
210
private:
211
ContentStack *stack;
212
ContentTabBar *switcher;
213
Gtk::PositionType tab_position;
214
public:
215
ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP);
216
Gtk::PositionType get_tab_position() const;
217
ContentStack *get_stack() const;
218
ContentTabBar *get_switcher() const;
219
};
220
221
class ContentWindow : public Gtk::Window {
222
private:
223
ContentNotebook *notebook;
224
public:
225
ContentWindow(ContentNotebook *notebook);
226
};
227
} // namespace gPanthera
228
229
#endif // GPANTHERA_LIBRARY_H