From 05a87703ed43afad142b093a60853afa69747bf4 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Wed, 30 Jan 2008 06:35:51 +0000 Subject: [PATCH] Added a very early rough sketch of Aegilib (Aegisub's future subtitles manipulation library) Originally committed to SVN as r1857. --- aegilib/aegilib.vcproj | 259 +++++++++++++++++++++++++ aegilib/include/aegilib/action.h | 61 ++++++ aegilib/include/aegilib/aegilib.h | 43 ++++ aegilib/include/aegilib/aegistring.h | 43 ++++ aegilib/include/aegilib/controller.h | 0 aegilib/include/aegilib/file.h | 55 ++++++ aegilib/include/aegilib/format.h | 67 +++++++ aegilib/include/aegilib/manipulator.h | 64 ++++++ aegilib/include/aegilib/model.h | 77 ++++++++ aegilib/include/aegilib/notification.h | 48 +++++ aegilib/include/aegilib/view.h | 54 ++++++ aegilib/src/action.cpp | 54 ++++++ aegilib/src/manipulator.cpp | 76 ++++++++ aegilib/src/model.cpp | 84 ++++++++ aegilib/src/prec.cpp | 1 + aegilib/src/prec.h | 16 ++ aegilib/src/view.cpp | 42 ++++ 17 files changed, 1044 insertions(+) create mode 100644 aegilib/aegilib.vcproj create mode 100644 aegilib/include/aegilib/action.h create mode 100644 aegilib/include/aegilib/aegilib.h create mode 100644 aegilib/include/aegilib/aegistring.h create mode 100644 aegilib/include/aegilib/controller.h create mode 100644 aegilib/include/aegilib/file.h create mode 100644 aegilib/include/aegilib/format.h create mode 100644 aegilib/include/aegilib/manipulator.h create mode 100644 aegilib/include/aegilib/model.h create mode 100644 aegilib/include/aegilib/notification.h create mode 100644 aegilib/include/aegilib/view.h create mode 100644 aegilib/src/action.cpp create mode 100644 aegilib/src/manipulator.cpp create mode 100644 aegilib/src/model.cpp create mode 100644 aegilib/src/prec.cpp create mode 100644 aegilib/src/prec.h create mode 100644 aegilib/src/view.cpp diff --git a/aegilib/aegilib.vcproj b/aegilib/aegilib.vcproj new file mode 100644 index 000000000..df8209ed3 --- /dev/null +++ b/aegilib/aegilib.vcproj @@ -0,0 +1,259 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/aegilib/include/aegilib/action.h b/aegilib/include/aegilib/action.h new file mode 100644 index 000000000..ca3097a16 --- /dev/null +++ b/aegilib/include/aegilib/action.h @@ -0,0 +1,61 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once + +namespace Aegilib { + // The different types of actions available + enum ActionType { + ACTION_INSERT, + ACTION_REMOVE + }; + + // Action class + // This is a modification event + class Action { + private: + ActionType type; + void* data; + int par1; + + public: + Action(); + Action(ActionType type,void* data,int par1); + + ActionType GetType() { return type; } + void* GetData() { return data; } + int GetLineNumber() { return par1; } + }; +}; diff --git a/aegilib/include/aegilib/aegilib.h b/aegilib/include/aegilib/aegilib.h new file mode 100644 index 000000000..201a78c30 --- /dev/null +++ b/aegilib/include/aegilib/aegilib.h @@ -0,0 +1,43 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include "model.h" +#include "view.h" +#include "controller.h" +#include "notification.h" +#include "aegistring.h" +#include "format.h" +#include "manipulator.h" diff --git a/aegilib/include/aegilib/aegistring.h b/aegilib/include/aegilib/aegistring.h new file mode 100644 index 000000000..563d289d7 --- /dev/null +++ b/aegilib/include/aegilib/aegistring.h @@ -0,0 +1,43 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once + +namespace Aegilib { + + // Define the string type used throughout this library + typedef wxString String; + +}; diff --git a/aegilib/include/aegilib/controller.h b/aegilib/include/aegilib/controller.h new file mode 100644 index 000000000..e69de29bb diff --git a/aegilib/include/aegilib/file.h b/aegilib/include/aegilib/file.h new file mode 100644 index 000000000..82587b4f8 --- /dev/null +++ b/aegilib/include/aegilib/file.h @@ -0,0 +1,55 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include "aegistring.h" + +namespace Aegilib { + + // File reader interface + class FileReader { + public: + virtual String ReadLineFromFile() = 0; + virtual bool HasMoreLines() = 0; + virtual String GetCurrentEncoding() = 0; + }; + + // File writer interface + class FileWriter { + public: + virtual void WriteLineToFile(String line,bool addLineBreak=true) = 0; + }; + +}; diff --git a/aegilib/include/aegilib/format.h b/aegilib/include/aegilib/format.h new file mode 100644 index 000000000..e02b9ef96 --- /dev/null +++ b/aegilib/include/aegilib/format.h @@ -0,0 +1,67 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include "aegistring.h" + +namespace Aegilib { + // Prototypes + class FormatHandler; + + // Format interface + class Format { + public: + virtual ~Format(); + + virtual String GetName() const = 0; + virtual String GetExtensionWildcard() const = 0; + virtual const FormatHandler& GetHandler() const = 0; + + virtual bool CanStoreText() const { return false; } + virtual bool CanStoreImages() const { return false; } + virtual bool CanUseTime() const { return false; } + virtual bool CanUseFrames() const { return false; } + + virtual bool HasStyles() const { return false; } + virtual bool HasMargins() const { return false; } + virtual bool HasActors() const { return false; } + virtual bool HasUserField() const { return false; } + virtual String GetUserFieldName() const { return _T(""); } + + virtual int GetTimingPrecision() const { return 10; } // In milliseconds + virtual int GetMaxTime() const { return 36000000-10; } // In milliseconds, default 9h 59min 59.99s + }; + +}; diff --git a/aegilib/include/aegilib/manipulator.h b/aegilib/include/aegilib/manipulator.h new file mode 100644 index 000000000..a6e516bb7 --- /dev/null +++ b/aegilib/include/aegilib/manipulator.h @@ -0,0 +1,64 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include +#include "action.h" +#include "aegistring.h" + +namespace Aegilib { + + // Manipulator class + class Manipulator { + friend class Model; + friend class std::list; + + private: + String actionName; + Model &model; + std::list actions; + bool valid; + + Manipulator(); + + public: + Manipulator(Model &model,String actionName); + ~Manipulator(); + + void AddAction(const Action &action); + void Flush(); + }; + +}; diff --git a/aegilib/include/aegilib/model.h b/aegilib/include/aegilib/model.h new file mode 100644 index 000000000..aa144afbd --- /dev/null +++ b/aegilib/include/aegilib/model.h @@ -0,0 +1,77 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include +#include "manipulator.h" +#include "file.h" + +namespace Aegilib { + // Prototypes + class View; + class Notification; + class Format; + + // Model class + // Stores the subtitle data + class Model { + friend class Manipulator; + typedef std::list ViewList; + typedef std::list ActionStack; + + private: + ActionStack undoStack; + ActionStack redoStack; + ViewList listeners; + bool readOnly; + + void ProcessActionList(const Manipulator &actionList,bool insertInStack); + Manipulator CreateAntiManipulator(const Manipulator &manipulator); + void DispatchNotifications(const Notification ¬ification) const; + + public: + const Format& GetFormat() const; + void AddListener(View *listener); + + void LoadFile(FileReader &file); + void SaveFile(FileWriter &file); + + bool CanUndo(String owner=_T("")) const; + bool CanRedo(String owner=_T("")) const; + bool Undo(String owner=_T("")); + bool Redo(String owner=_T("")); + }; + +}; diff --git a/aegilib/include/aegilib/notification.h b/aegilib/include/aegilib/notification.h new file mode 100644 index 000000000..540248a93 --- /dev/null +++ b/aegilib/include/aegilib/notification.h @@ -0,0 +1,48 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include "model.h" +#include "notification.h" + +namespace Aegilib { + + // Notification class + class Notification { + public: + std::vector lines; + }; + +}; diff --git a/aegilib/include/aegilib/view.h b/aegilib/include/aegilib/view.h new file mode 100644 index 000000000..ff72c49cb --- /dev/null +++ b/aegilib/include/aegilib/view.h @@ -0,0 +1,54 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#pragma once +#include "aegistring.h" +#include + +namespace Aegilib { + // Prototypes + class Model; + class Notification; + + // View interface + // Implement this to listen to modifications in a model + class View { + public: + virtual ~View(); + + void Register(Model &model); + virtual void Notify(const Notification ¬ification) = 0; + }; +}; diff --git a/aegilib/src/action.cpp b/aegilib/src/action.cpp new file mode 100644 index 000000000..efde1fde1 --- /dev/null +++ b/aegilib/src/action.cpp @@ -0,0 +1,54 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#include "action.h" +using namespace Aegilib; + + +/////////////////////// +// Default constructor +Action::Action() +{ +} + + +////////////////////////////// +// Initialization constructor +Action::Action(ActionType _type,void* _data,int _par1) +{ + type = _type; + data = _data; + par1 = _par1; +} diff --git a/aegilib/src/manipulator.cpp b/aegilib/src/manipulator.cpp new file mode 100644 index 000000000..82e5b3731 --- /dev/null +++ b/aegilib/src/manipulator.cpp @@ -0,0 +1,76 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#include "aegilib.h" +using namespace Aegilib; + + +/////////////// +// Constructor +Manipulator::Manipulator(Model &_model,String _actionName) +: model(_model) +{ + actionName = _actionName; + valid = true; +} + + +////////////// +// Destructor +Manipulator::~Manipulator() +{ + Flush(); +} + + +////////////////////////////// +// Add an action to the queue +void Manipulator::AddAction(const Action &action) +{ + if (!valid) throw 0; // TODO + actions.push_back(action); +} + + +//////////////////////////////// +// Flush the queue to the model +void Manipulator::Flush() +{ + if (valid) { + model.ProcessActionList(*this,false); + actions.clear(); + valid = false; + } +} diff --git a/aegilib/src/model.cpp b/aegilib/src/model.cpp new file mode 100644 index 000000000..e63919e5e --- /dev/null +++ b/aegilib/src/model.cpp @@ -0,0 +1,84 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#include "aegilib.h" +using namespace Aegilib; + + +///////////////////////////////////////////////////////// +// Adds a listener to be notified whenever things change +void Model::AddListener(View *listener) +{ + wxASSERT(listener); + listeners.push_back(listener); +} + + +//////////////////////// +// Notify all listeners +void Model::DispatchNotifications(const Notification ¬ification) const +{ + for (ViewList::const_iterator cur=listeners.begin();cur!=listeners.end();cur++) { + (*cur)->Notify(notification); + } +} + + +//////////////////////////// +// Processes an action list +void Model::ProcessActionList(const Manipulator &actionList,bool insertInStack) +{ + // Inserts the opposite into the undo stack + if (insertInStack) { + undoStack.push_back(CreateAntiManipulator(actionList)); + redoStack.clear(); + } + + // Do action + // TODO + + // Notify listeners + DispatchNotifications(Notification()); +} + + +//////////////////////////////////////////////////////////////////////// +// Create an anti-manipulator to undo the actions made by a manipulator +Manipulator Model::CreateAntiManipulator(const Manipulator &src) +{ + Manipulator dst(*this,src.actionName); + // TODO + return dst; +} diff --git a/aegilib/src/prec.cpp b/aegilib/src/prec.cpp new file mode 100644 index 000000000..62e187a96 --- /dev/null +++ b/aegilib/src/prec.cpp @@ -0,0 +1 @@ +#include "prec.h" diff --git a/aegilib/src/prec.h b/aegilib/src/prec.h new file mode 100644 index 000000000..d7665d826 --- /dev/null +++ b/aegilib/src/prec.h @@ -0,0 +1,16 @@ +#pragma once +#define WIN32_LEAN_AND_MEAN + +// Standard Library +#include +#include +#include + +// wxWidgets +#ifdef _MSC_VER +#pragma warning(disable: 6011) +#endif +#include +#ifdef _MSC_VER +#pragma warning(default: 6011) +#endif diff --git a/aegilib/src/view.cpp b/aegilib/src/view.cpp new file mode 100644 index 000000000..328d94215 --- /dev/null +++ b/aegilib/src/view.cpp @@ -0,0 +1,42 @@ +// Copyright (c) 2008, Rodrigo Braz Monteiro +// All rights reserved. +// +// Redistribution and use in source and binary forms, with or without +// modification, are permitted provided that the following conditions are met: +// +// * Redistributions of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// * Redistributions in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// * Neither the name of the Aegisub Group nor the names of its contributors +// may be used to endorse or promote products derived from this software +// without specific prior written permission. +// +// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE +// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR +// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF +// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS +// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN +// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) +// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +// POSSIBILITY OF SUCH DAMAGE. +// +// ----------------------------------------------------------------------------- +// +// AEGISUB/AEGILIB +// +// Website: http://www.aegisub.net +// Contact: mailto:amz@aegisub.net +// + +#include "aegilib.h" +using namespace Aegilib; + +void View::Register(Model &model) +{ + model.AddListener(this); +}