gpanthera.hh
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
std::string id;
82
explicit DockStack(std::shared_ptr<LayoutManager> layout, const Glib::ustring &name, const std::string &id);
83
84
void add_pane(DockablePane &child);
85
};
86
87
class DockButton : public Gtk::ToggleButton {
88
private:
89
sigc::connection active_style_handler;
90
std::shared_ptr<Gtk::DragSource> drag_source;
91
Glib::Value<DockablePane*> value;
92
void update_active_style();
93
public:
94
DockablePane *pane;
95
explicit DockButton(DockablePane *pane);
96
~DockButton() override;
97
};
98
99
class DockStackSwitcher : public Gtk::Box {
100
private:
101
DockStack *stack;
102
sigc::connection add_handler, remove_handler;
103
std::shared_ptr<Gtk::DropTarget> drop_target;
104
public:
105
void update_buttons();
106
explicit DockStackSwitcher(DockStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL);
107
DockStack *get_stack() const;
108
~DockStackSwitcher() override;
109
};
110
111
class ContentStack;
112
class ContentPage;
113
114
class ContentManager : public Glib::ObjectBase {
115
private:
116
ContentPage *last_operated_page = nullptr;
117
public:
118
ContentPage *get_last_operated_page() const;
119
void set_last_operated_page(ContentPage *page);
120
sigc::signal<void(ContentPage*)> signal_page_operated;
121
std::vector<ContentStack*> stacks;
122
ContentManager();
123
124
void add_stack(ContentStack *stack);
125
void remove_stack(ContentStack *stack);
126
};
127
128
class ContentPage : public Gtk::Overlay {
129
protected:
130
ContentStack *stack = nullptr;
131
Gtk::Widget *child;
132
public:
133
Gtk::Widget *tab_widget;
134
std::shared_ptr<ContentManager> content_manager;
135
ContentStack *last_stack = nullptr;
136
ContentPage(std::shared_ptr<ContentManager> content_manager, ContentStack *stack, Gtk::Widget *child, Gtk::Widget *tab_widget);
137
sigc::signal<bool()> signal_close;
138
Gtk::Widget *get_tab_widget() const;
139
void redock(ContentStack *stack);
140
void set_tab_widget(Gtk::Widget *tab_widget);
141
ContentStack *get_stack() const;
142
void lose_visibility();
143
};
144
145
class ContentTab : public Gtk::ToggleButton {
146
private:
147
std::shared_ptr<Gtk::DragSource> drag_source;
148
std::shared_ptr<Gtk::DropTarget> drop_target;
149
Glib::Value<ContentPage*> value;
150
Glib::RefPtr<Gio::Menu> context_menu = Gio::Menu::create();
151
sigc::connection drag_end_handler;
152
sigc::connection drag_cancel_handler;
153
void update_active_style();
154
sigc::connection active_style_handler;
155
public:
156
void close();
157
explicit ContentTab(ContentPage *page);
158
ContentPage *page;
159
~ContentTab() override;
160
};
161
162
class ContentStack : public BaseStack {
163
private:
164
void disable_children();
165
void enable_children();
166
protected:
167
std::function<bool(ContentPage*)> detach_handler;
168
public:
169
sigc::signal<bool(ContentPage*)> signal_detach;
170
std::function<bool(ContentPage*)> get_detach_handler() const;
171
std::shared_ptr<ContentManager> content_manager;
172
std::shared_ptr<Gtk::DropTarget> drop_target;
173
sigc::signal<void()> signal_leave_empty;
174
explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr);
175
void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type);
176
void add_page(ContentPage &child);
177
void remove_with_paned();
178
};
179
180
class ContentTabBar : public Gtk::Box {
181
// Dragging a tab to an empty space should split the view;
182
// dragging a tab outside the window should pop it out with user-defined behaviour
183
private:
184
ContentStack *stack;
185
sigc::connection add_handler, remove_handler;
186
std::shared_ptr<Gtk::DropTarget> drop_target;
187
Gtk::ScrolledWindow *scrolled_window;
188
Gtk::Box *tab_box;
189
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function;
190
public:
191
void update_buttons();
192
explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr);
193
void set_orientation(Gtk::Orientation orientation);
194
void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>);
195
ContentStack *get_stack() const;
196
~ContentTabBar() override;
197
std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const;
198
};
199
200
class ContentNotebook : public Gtk::Box {
201
private:
202
ContentStack *stack;
203
ContentTabBar *switcher;
204
Gtk::PositionType tab_position;
205
public:
206
ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP);
207
Gtk::PositionType get_tab_position() const;
208
ContentStack *get_stack() const;
209
ContentTabBar *get_switcher() const;
210
};
211
212
class ContentWindow : public Gtk::Window {
213
private:
214
ContentNotebook *notebook;
215
public:
216
ContentWindow(ContentNotebook *notebook);
217
};
218
} // namespace gPanthera
219
220
#endif // GPANTHERA_LIBRARY_H