00001 /* 00002 * PROPRIETARY INFORMATION. This software is proprietary to 00003 * Side Effects Software Inc., and is not to be reproduced, 00004 * transmitted, or disclosed in any way without written permission. 00005 * 00006 * Produced by: 00007 * Luke Moore 00008 * Side Effects Software Inc 00009 * 477 Richmond Street West 00010 * Toronto, Ontario 00011 * Canada M5V 3E7 00012 * 416-504-9876 00013 * 00014 * NAME: UT_DelegatedUndo.h 00015 * 00016 * COMMENTS: 00017 * This class is the base class for undo objects that delegate their 00018 * work to someone else (the undo worker). It uses UT_UndoWorkerFinder's 00019 * to see if the undo worker has been deleted. 00020 * 00021 * See the comments in UT_UndoWorkerFinder.h for instructions on how 00022 * to use this class. 00023 */ 00024 00025 #ifndef __UT_DelegatedUndo_h__ 00026 #define __UT_DelegatedUndo_h__ 00027 00028 #include "UT_API.h" 00029 #include "UT_Undo.h" 00030 #include "UT_UndoWorkerFinder.h" 00031 00032 // Undo classes do not need to work with UT_DelegatedUndoBase directly. 00033 class UT_API UT_DelegatedUndoBase : public UT_Undo 00034 { 00035 public: 00036 UT_DelegatedUndoBase(int undo_worker_id); 00037 00038 // We can't undo or redo anything if our undo worker has been deleted. 00039 virtual bool isValid() { return opaqueUndoWorker() != 0; } 00040 00041 protected: 00042 void *opaqueUndoWorker(); 00043 00044 private: 00045 int myUndoWorkerId; 00046 }; 00047 00048 00049 // This templated class is a convenience class to avoid casting. 00050 template <class UndoWorker> 00051 class UT_DelegatedUndo : public UT_DelegatedUndoBase 00052 { 00053 public: 00054 UT_DelegatedUndo(const UT_UndoWorkerFinder<UndoWorker> &undo_worker_finder) 00055 : UT_DelegatedUndoBase(undo_worker_finder.undoWorkerId()) {} 00056 00057 protected: 00058 // A null pointer is returned if the undo work has been deleted. 00059 // The undo() and redo() methods will not be called when undoWorker() 00060 // returns null. 00061 UndoWorker *undoWorker() { return (UndoWorker *)opaqueUndoWorker(); } 00062 }; 00063 00064 00065 #endif
1.5.9