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: 155explicit ContentTab(ContentPage *page); 156ContentPage *page; 157~ContentTab() override; 158}; 159 160class ContentStack : public BaseStack { 161private: 162void disable_children(); 163void enable_children(); 164protected: 165std::function<bool(ContentPage*)> detach_handler; 166public: 167sigc::signal<bool(ContentPage*)> signal_detach; 168std::function<bool(ContentPage*)> get_detach_handler() const; 169std::shared_ptr<ContentManager> content_manager; 170std::shared_ptr<Gtk::DropTarget> drop_target; 171sigc::signal<void()> signal_leave_empty; 172explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr); 173void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type); 174void add_page(ContentPage &child); 175void remove_with_paned(); 176}; 177 178class 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 181private: 182ContentStack *stack; 183sigc::connection add_handler, remove_handler; 184std::shared_ptr<Gtk::DropTarget> drop_target; 185Gtk::ScrolledWindow *scrolled_window; 186Gtk::Box *tab_box; 187std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function; 188public: 189void update_buttons(); 190explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr); 191void set_orientation(Gtk::Orientation orientation); 192void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>); 193ContentStack *get_stack() const; 194~ContentTabBar() override; 195std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const; 196}; 197 198class ContentNotebook : public Gtk::Box { 199private: 200ContentStack *stack; 201ContentTabBar *switcher; 202Gtk::PositionType tab_position; 203public: 204ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP); 205Gtk::PositionType get_tab_position() const; 206ContentStack *get_stack() const; 207ContentTabBar *get_switcher() const; 208}; 209 210class ContentWindow : public Gtk::Window { 211private: 212ContentNotebook *notebook; 213public: 214ContentWindow(ContentNotebook *notebook); 215}; 216} // namespace gPanthera 217 218#endif // GPANTHERA_LIBRARY_H