| 1 | // Aseprite |
| 2 | // Copyright (C) 2022 Igara Studio S.A. |
| 3 | // Copyright (C) 2001-2018 David Capello |
| 4 | // |
| 5 | // This program is distributed under the terms of |
| 6 | // the End-User License Agreement for Aseprite. |
| 7 | |
| 8 | #ifndef APP_UI_WORKSPACE_H_INCLUDED |
| 9 | #define APP_UI_WORKSPACE_H_INCLUDED |
| 10 | #pragma once |
| 11 | |
| 12 | #include "app/ui/input_chain_element.h" |
| 13 | #include "app/ui/tabs.h" |
| 14 | #include "app/ui/workspace_panel.h" |
| 15 | #include "obs/signal.h" |
| 16 | #include "ui/widget.h" |
| 17 | |
| 18 | namespace app { |
| 19 | class WorkspaceTabs; |
| 20 | |
| 21 | class Workspace : public ui::Widget |
| 22 | , public app::InputChainElement { |
| 23 | public: |
| 24 | typedef WorkspaceViews::iterator iterator; |
| 25 | |
| 26 | static ui::WidgetType Type(); |
| 27 | |
| 28 | Workspace(); |
| 29 | ~Workspace(); |
| 30 | |
| 31 | void setTabsBar(WorkspaceTabs* tabs); |
| 32 | |
| 33 | iterator begin() { return m_views.begin(); } |
| 34 | iterator end() { return m_views.end(); } |
| 35 | |
| 36 | void addView(WorkspaceView* view, int pos = -1); |
| 37 | void addViewToPanel(WorkspacePanel* panel, WorkspaceView* view, bool from_drop, int pos); |
| 38 | void removeView(WorkspaceView* view); |
| 39 | |
| 40 | // Closes the given view. Returns false if the user cancels the |
| 41 | // operation. |
| 42 | bool closeView(WorkspaceView* view, bool quitting); |
| 43 | |
| 44 | WorkspaceView* activeView(); |
| 45 | void setActiveView(WorkspaceView* view); |
| 46 | void setMainPanelAsActive(); |
| 47 | bool canSelectOtherTab() const; |
| 48 | void selectNextTab(); |
| 49 | void selectPreviousTab(); |
| 50 | void duplicateActiveView(); |
| 51 | |
| 52 | void updateTabs(); |
| 53 | |
| 54 | // Set the preview of what could happen if we drop the given |
| 55 | // "view" at the "pos"? |
| 56 | DropViewPreviewResult setDropViewPreview(const gfx::Point& pos, |
| 57 | WorkspaceView* view, WorkspaceTabs* tabs); |
| 58 | void removeDropViewPreview(); |
| 59 | |
| 60 | // Returns true if the view was docked inside the workspace. |
| 61 | DropViewAtResult dropViewAt(const gfx::Point& screenPos, |
| 62 | WorkspaceView* view, |
| 63 | const bool clone); |
| 64 | |
| 65 | // InputChainElement impl |
| 66 | void onNewInputPriority(InputChainElement* element, |
| 67 | const ui::Message* msg) override; |
| 68 | bool onCanCut(Context* ctx) override; |
| 69 | bool onCanCopy(Context* ctx) override; |
| 70 | bool onCanPaste(Context* ctx) override; |
| 71 | bool onCanClear(Context* ctx) override; |
| 72 | bool onCut(Context* ctx) override; |
| 73 | bool onCopy(Context* ctx) override; |
| 74 | bool onPaste(Context* ctx) override; |
| 75 | bool onClear(Context* ctx) override; |
| 76 | void onCancel(Context* ctx) override; |
| 77 | |
| 78 | WorkspacePanel* mainPanel() { return &m_mainPanel; } |
| 79 | |
| 80 | obs::signal<void()> ActiveViewChanged; |
| 81 | |
| 82 | protected: |
| 83 | void onPaint(ui::PaintEvent& ev) override; |
| 84 | void onResize(ui::ResizeEvent& ev) override; |
| 85 | |
| 86 | private: |
| 87 | WorkspacePanel* getViewPanel(WorkspaceView* view); |
| 88 | WorkspacePanel* getPanelAt(const gfx::Point& pos); |
| 89 | WorkspaceTabs* getTabsAt(const gfx::Point& pos); |
| 90 | |
| 91 | WorkspacePanel m_mainPanel; |
| 92 | WorkspaceTabs* m_tabs; |
| 93 | WorkspaceViews m_views; |
| 94 | WorkspacePanel* m_activePanel; |
| 95 | WorkspacePanel* m_dropPreviewPanel; |
| 96 | WorkspaceTabs* m_dropPreviewTabs; |
| 97 | }; |
| 98 | |
| 99 | } // namespace app |
| 100 | |
| 101 | #endif |
| 102 | |