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