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; 111 112class ContentManager : public Glib::ObjectBase { 113private: 114public: 115std::vector<ContentStack*> stacks; 116ContentManager(); 117 118void add_stack(ContentStack *stack); 119void remove_stack(ContentStack *stack); 120}; 121 122class ContentPage : public Gtk::Overlay { 123private: 124Gtk::Widget *tab_widget; 125ContentStack *stack = nullptr; 126Gtk::Widget *child; 127public: 128std::shared_ptr<ContentManager> content_manager; 129ContentStack *last_stack = nullptr; 130ContentPage(std::shared_ptr<ContentManager> content_manager, ContentStack *stack, Gtk::Widget *child, Gtk::Widget *tab_widget); 131sigc::signal<bool()> signal_close; 132Gtk::Widget *get_tab_widget() const; 133void redock(ContentStack *stack); 134void set_tab_widget(Gtk::Widget *tab_widget); 135ContentStack *get_stack() const; 136void lose_visibility(); 137}; 138 139class ContentTab : public Gtk::ToggleButton { 140private: 141std::shared_ptr<Gtk::DragSource> drag_source; 142std::shared_ptr<Gtk::DropTarget> drop_target; 143Glib::Value<ContentPage*> value; 144Glib::RefPtr<Gio::Menu> context_menu = Gio::Menu::create(); 145sigc::connection drag_end_handler; 146sigc::connection drag_cancel_handler; 147void update_active_style(); 148sigc::connection active_style_handler; 149public: 150explicit ContentTab(ContentPage *page); 151ContentPage *page; 152~ContentTab() override; 153}; 154 155class ContentStack : public BaseStack { 156protected: 157std::function<bool(ContentPage*)> detach_handler; 158public: 159sigc::signal<bool(ContentPage*)> signal_detach; 160std::function<bool(ContentPage*)> get_detach_handler() const; 161std::shared_ptr<ContentManager> content_manager; 162std::shared_ptr<Gtk::DropTarget> drop_target; 163sigc::signal<void()> signal_leave_empty; 164explicit ContentStack(std::shared_ptr<ContentManager> content_manager, std::function<bool(ContentPage*)> detach_handler = nullptr); 165void make_paned(Gtk::Orientation orientation, Gtk::PackType pack_type); 166void add_page(ContentPage &child); 167void remove_with_paned(); 168}; 169 170class ContentTabBar : public Gtk::Box { 171// TODO; should be similar to DockStackSwitcher 172// Dragging a tab to an empty space should split the view; 173// dragging a tab outside the window should pop it out with user-defined behaviour 174private: 175ContentStack *stack; 176sigc::connection add_handler, remove_handler; 177std::shared_ptr<Gtk::DropTarget> drop_target; 178Gtk::ScrolledWindow *scrolled_window; 179Gtk::Box *tab_box; 180std::function<Gtk::Widget*(Gtk::Widget*)> extra_child_function; 181public: 182void update_buttons(); 183explicit ContentTabBar(ContentStack *stack, Gtk::Orientation orientation = Gtk::Orientation::HORIZONTAL, std::function<Gtk::Widget*(Gtk::Widget*)> extra_child_function = nullptr); 184void set_orientation(Gtk::Orientation orientation); 185void set_extra_child_function(std::function<Gtk::Widget(Gtk::Widget *)> function); 186ContentStack *get_stack() const; 187~ContentTabBar() override; 188std::function<Gtk::Widget*(Gtk::Widget*)> get_extra_child_function() const; 189}; 190 191class ContentNotebook : public Gtk::Box { 192private: 193ContentStack *stack; 194ContentTabBar *switcher; 195Gtk::PositionType tab_position; 196public: 197ContentNotebook(ContentStack *stack, ContentTabBar *switcher, Gtk::PositionType tab_position = Gtk::PositionType::TOP); 198Gtk::PositionType get_tab_position() const; 199ContentStack *get_stack() const; 200ContentTabBar *get_switcher() const; 201}; 202 203class ContentWindow : public Gtk::Window { 204private: 205ContentNotebook *notebook; 206public: 207ContentWindow(ContentNotebook *notebook); 208}; 209} // namespace gPanthera 210 211#endif // GPANTHERA_LIBRARY_H