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