// This file is part of VSTGUI. It is subject to the license terms // in the LICENSE file found in the top-level directory of this // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE #pragma once #include "iaction.h" #if VSTGUI_LIVE_EDITING #include "uiselection.h" #include "../iviewfactory.h" #include "../iuidescription.h" #include "../../lib/ccolor.h" #include "../../lib/cgradient.h" #include #include #include #include #include namespace VSTGUI { class UIViewFactory; class IUIDescription; class UIDescription; class CViewContainer; class CView; //----------------------------------------------------------------------------- class Action : public IAction { public: using Func = std::function; Action (const std::string& name, Func&& perform, Func&& undo) : name (name), performAction (std::move (perform)), undoAction (std::move (undo)) { } UTF8StringPtr getName () override { return name.data (); } void perform () override { performAction (); } void undo () override { undoAction (); } private: std::string name; Func performAction; Func undoAction; }; //----------------------------------------------------------------------------- template class BaseSelectionOperation : public IAction, protected std::list { public: BaseSelectionOperation (UISelection* selection) : selection (selection) {} protected: SharedPointer selection; }; //----------------------------------------------------------------------------- class SizeToFitOperation : public BaseSelectionOperation, CRect> > { public: SizeToFitOperation (UISelection* selection); ~SizeToFitOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; }; //----------------------------------------------------------------------------- class UnembedViewOperation : public BaseSelectionOperation > { public: UnembedViewOperation (UISelection* selection, const IViewFactory* factory); ~UnembedViewOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: void collectSubviews (CViewContainer* container, bool deep); const IViewFactory* factory; SharedPointer containerView; CViewContainer* parent; }; //----------------------------------------------------------------------------- class EmbedViewOperation : public BaseSelectionOperation, CRect> > { public: EmbedViewOperation (UISelection* selection, CViewContainer* newContainer); ~EmbedViewOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer newContainer; CViewContainer* parent; }; //----------------------------------------------------------------------------- class ViewCopyOperation : public IAction, protected std::list > { public: ViewCopyOperation (UISelection* copySelection, UISelection* workingSelection, CViewContainer* parent, const CPoint& offset, IUIDescription* desc); ~ViewCopyOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer parent; SharedPointer copySelection; SharedPointer workingSelection; std::list > oldSelectedViews; }; //----------------------------------------------------------------------------- class ViewSizeChangeOperation : public BaseSelectionOperation, CRect> > { public: ViewSizeChangeOperation (UISelection* selection, bool sizing, bool autosizingEnabled); ~ViewSizeChangeOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; bool didChange (); protected: bool first; bool sizing; bool autosizing; }; //---------------------------------------------------------------------------------------------------- struct DeleteOperationViewAndNext { DeleteOperationViewAndNext (CView* view, CView* nextView) : view (view), nextView (nextView) {} DeleteOperationViewAndNext (const DeleteOperationViewAndNext& copy) : view (copy.view), nextView (copy.nextView) {} SharedPointer view; SharedPointer nextView; }; //---------------------------------------------------------------------------------------------------- class DeleteOperation : public IAction, protected std::multimap, DeleteOperationViewAndNext> { public: DeleteOperation (UISelection* selection); ~DeleteOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer selection; }; //----------------------------------------------------------------------------- class InsertViewOperation : public IAction { public: InsertViewOperation (CViewContainer* parent, CView* view, UISelection* selection); ~InsertViewOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer parent; SharedPointer view; SharedPointer selection; }; //----------------------------------------------------------------------------- class TransformViewTypeOperation : public IAction { public: TransformViewTypeOperation (UISelection* selection, CView* view, IdStringPtr viewClassName, UIDescription* desc, const IViewFactory* factory); ~TransformViewTypeOperation () override; UTF8StringPtr getName () override; void exchangeSubViews (CViewContainer* src, CViewContainer* dst); void perform () override; void undo () override; protected: SharedPointer view; CView* newView; int32_t insertIndex; SharedPointer parent; SharedPointer selection; const IViewFactory* factory; SharedPointer description; }; //----------------------------------------------------------------------------- class AttributeChangeAction : public IAction, protected std::map, std::string> { public: AttributeChangeAction (UIDescription* desc, UISelection* selection, const std::string& attrName, const std::string& attrValue); ~AttributeChangeAction () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: void updateSelection (); UIDescription* desc; SharedPointer selection; std::string attrName; std::string attrValue; std::string name; }; //---------------------------------------------------------------------------------------------------- class MultipleAttributeChangeAction : public IAction, public std::vector, std::string> > { public: MultipleAttributeChangeAction (UIDescription* description, const std::list& views, IViewCreator::AttrType attrType, UTF8StringPtr oldValue, UTF8StringPtr newValue); UTF8StringPtr getName () override { return "multiple view attribute changes"; } void perform () override; void undo () override; protected: void setAttributeValue (UTF8StringPtr value); static void collectAllSubViews (CView* view, std::list& views); void collectViewsWithAttributeValue (const IViewFactory* viewFactory, IUIDescription* desc, CView* startView, IViewCreator::AttrType type, const std::string& value); SharedPointer description; std::string oldValue; std::string newValue; }; //---------------------------------------------------------------------------------------------------- class TagChangeAction : public IAction { public: TagChangeAction (UIDescription* description, UTF8StringPtr name, UTF8StringPtr newTagString, bool remove, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; bool isAddTag () const { return isNewTag; } protected: SharedPointer description; std::string name; std::string newTag; std::string originalTag; bool remove; bool performOrUndo; bool isNewTag; }; //---------------------------------------------------------------------------------------------------- class TagNameChangeAction : public IAction { public: TagNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string oldName; std::string newName; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class ColorChangeAction : public IAction { public: ColorChangeAction (UIDescription* description, UTF8StringPtr name, const CColor& color, bool remove, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; bool isAddColor () const { return isNewColor; } protected: SharedPointer description; std::string name; CColor newColor; CColor oldColor; bool remove; bool performOrUndo; bool isNewColor; }; //---------------------------------------------------------------------------------------------------- class ColorNameChangeAction : public IAction { public: ColorNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string oldName; std::string newName; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class BitmapChangeAction : public IAction { public: BitmapChangeAction (UIDescription* description, UTF8StringPtr name, UTF8StringPtr path, bool remove, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; bool isAddBitmap () const { return isNewBitmap; } protected: SharedPointer description; std::string name; std::string path; std::string originalPath; bool remove; bool performOrUndo; bool isNewBitmap; }; //---------------------------------------------------------------------------------------------------- class BitmapNameChangeAction : public IAction { public: BitmapNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string oldName; std::string newName; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class NinePartTiledBitmapChangeAction : public IAction { public: NinePartTiledBitmapChangeAction (UIDescription* description, UTF8StringPtr name, const CRect* rect, bool performOrUndo); ~NinePartTiledBitmapChangeAction () override; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string name; CRect* oldRect; CRect* newRect; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class MultiFrameBitmapChangeAction : public IAction { public: MultiFrameBitmapChangeAction (UIDescription* description, UTF8StringPtr name, const CMultiFrameBitmapDescription* desc, bool performOrUndo); ~MultiFrameBitmapChangeAction () override; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string name; std::unique_ptr oldDesc; std::unique_ptr newDesc; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class BitmapFilterChangeAction : public IAction { public: BitmapFilterChangeAction (UIDescription* description, UTF8StringPtr bitmapName, const std::list >& attributes, bool performOrUndo); ~BitmapFilterChangeAction () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string bitmapName; std::list > newAttributes; std::list > oldAttributes; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class GradientChangeAction : public IAction { public: GradientChangeAction (UIDescription* description, UTF8StringPtr name, CGradient* gradient, bool remove, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; bool isAddGradient () const { return originalGradient == 0; } protected: SharedPointer description; std::string name; SharedPointer gradient; SharedPointer originalGradient; bool remove; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class GradientNameChangeAction : public IAction { public: GradientNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string oldName; std::string newName; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class FontChangeAction : public IAction { public: FontChangeAction (UIDescription* description, UTF8StringPtr name, CFontRef font, bool remove, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; bool isAddFont () const { return originalFont == 0; } protected: SharedPointer description; std::string name; std::string alternativeNames; SharedPointer font; SharedPointer originalFont; bool remove; bool performOrUndo; }; //---------------------------------------------------------------------------------------------------- class FontNameChangeAction : public IAction { public: FontNameChangeAction (UIDescription* description, UTF8StringPtr oldName, UTF8StringPtr newName, bool performOrUndo); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string oldName; std::string newName; bool performOrUndo; }; //----------------------------------------------------------------------------- class AlternateFontChangeAction : public IAction { public: AlternateFontChangeAction (UIDescription* description, UTF8StringPtr fontName, UTF8StringPtr newAlternateFontNames); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; std::string fontName; std::string newAlternateFontNames; std::string oldAlternateFontNames; }; //----------------------------------------------------------------------------- class HierarchyMoveViewOperation : public IAction { public: HierarchyMoveViewOperation (CView* view, UISelection* selection, int32_t dir); ~HierarchyMoveViewOperation () override = default; UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer view; SharedPointer parent; SharedPointer selection; int32_t dir; }; //----------------------------------------------------------------------------- class TemplateNameChangeAction : public IAction { public: TemplateNameChangeAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr oldName, UTF8StringPtr newName); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; IActionPerformer* actionPerformer; std::string oldName; std::string newName; }; //----------------------------------------------------------------------------- class CreateNewTemplateAction : public IAction { public: CreateNewTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr name, UTF8StringPtr baseViewClassName); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; IActionPerformer* actionPerformer; SharedPointer view; std::string name; std::string baseViewClassName; }; //----------------------------------------------------------------------------- class DuplicateTemplateAction : public IAction { public: DuplicateTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, UTF8StringPtr name, UTF8StringPtr dupName); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; IActionPerformer* actionPerformer; SharedPointer view; std::string name; std::string dupName; }; //----------------------------------------------------------------------------- class DeleteTemplateAction : public IAction { public: DeleteTemplateAction (UIDescription* description, IActionPerformer* actionPerformer, CView* view, UTF8StringPtr name); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; IActionPerformer* actionPerformer; SharedPointer view; SharedPointer attributes; std::string name; }; //----------------------------------------------------------------------------- class ChangeFocusDrawingAction : public IAction { public: ChangeFocusDrawingAction (UIDescription* description, const FocusDrawingSettings& newSettings); UTF8StringPtr getName () override; void perform () override; void undo () override; protected: SharedPointer description; FocusDrawingSettings oldSettings; FocusDrawingSettings newSettings; }; //----------------------------------------------------------------------------- class ChangeTemplateMinMaxAction : public IAction { public: ChangeTemplateMinMaxAction (UIDescription* description, UTF8StringPtr templateName, CPoint minSize, CPoint maxSize); UTF8StringPtr getName () override; void perform () override; void undo () override; private: void setMinMaxSize (CPoint minimum, CPoint maximum); SharedPointer description; std::string templateName; CPoint minSize; CPoint maxSize; CPoint oldMinSize; CPoint oldMaxSize; }; //----------------------------------------------------------------------------- } // VSTGUI #endif // VSTGUI_LIVE_EDITING