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; 143Gtk::Widget *get_tab_widget() const; 144void redock(ContentStack *stack); 145void set_tab_widget(Gtk::Widget *tab_widget); 146ContentStack *get_stack() const; 147void lose_visibility(); 148}; 149 150class ContentTab : public Gtk::ToggleButton { 151private: 152std::shared_ptr<Gtk::DragSource> drag_source; 153std::shared_ptr<Gtk::DropTarget> drop_target; 154Glib::Value<ContentPage*> value; 155Glib::RefPtr<Gio::Menu> context_menu = Gio::Menu::create(); 156sigc::connection drag_end_handler; 157sigc::connection drag_cancel_handler; 158void update_active_style(); 159sigc::connection active_style_handler; 160public: 161void close(); 162explicit ContentTab(ContentPage *page); 163ContentPage *page; 164~ContentTab() override; 165}; 166 167class ContentStack : public BaseStack { 168private: 169void disable_children(); 170void enable_children(); 171protected: 172std::function<bool(ContentPage*)> detach_handler; 173public: 174sigc::signal<bool(ContentPage*)> signal_detach; 175std::function<bool(ContentPage*)> get_detach_handler() const; 176std::shared_ptr<ContentManager> content_manager; 177std::shared_ptr<Gtk::DropTarget> drop_target; 178sigc::signal<void()> signal_leave_empty; 179explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr); 180void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type); 181void add_page(ContentPage &child); 182void remove_with_paned(); 183}; 184 185class ContentTabBar : public Gtk::Box { 186// Dragging a tab to an empty space should split the view; 187// dragging a tab outside the window should pop it out with user-defined behaviour 188private: 189ContentStack *stack; 190sigc::connection add_handler, remove_handler; 191std::shared_ptr<Gtk::DropTarget> drop_target; 192Gtk::ScrolledWindow *scrolled_window; 193Gtk::Box *tab_box; 194std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function; 195public: 196void update_buttons(); 197explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> extra_child_function = nullptr); 198void set_orientation(Gtk::Orientation orientation); 199void set_extra_child_function(std::function<Gtk::Widget*(gPanthera::ContentTabBar*)>); 200ContentStack *get_stack() const; 201~ContentTabBar() override; 202std::function<Gtk::Widget*(gPanthera::ContentTabBar*)> get_extra_child_function() const; 203}; 204 205class ContentNotebook : public Gtk::Box { 206private: 207ContentStack *stack; 208ContentTabBar *switcher; 209Gtk::PositionType tab_position; 210public: 211ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP); 212Gtk::PositionType get_tab_position() const; 213ContentStack *get_stack() const; 214ContentTabBar *get_switcher() const; 215}; 216 217class ContentWindow : public Gtk::Window { 218private: 219ContentNotebook *notebook; 220public: 221ContentWindow(ContentNotebook *notebook); 222}; 223} // namespace gPanthera 224 225#endif // GPANTHERA_LIBRARY_H