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