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