hold.h

Go to the documentation of this file.
00001 //*****************************************************************************
00002 // Copyright 1994, 2009 Autodesk, Inc.  All rights reserved.
00003 //
00004 // Use of this software is subject to the terms of the Autodesk license agreement
00005 // provided at the time of installation or download, or which otherwise accompanies 
00006 // this software in either electronic or hard copy form.   
00007 //
00008 //*****************************************************************************
00009 //
00010 //  FILE: hold.h
00011 //  DESCRIPTION:    Describes the hold system objects 
00012 //  CREATED BY: Dan Silva
00013 //
00014 //*****************************************************************************
00015 
00016 #pragma once
00017 
00018 #include "maxheap.h"
00019 #include "baseinterface.h"
00020 #include "strclass.h"
00021 
00022 #define RESTOBJ_DOES_REFERENCE_POINTER      1 // cmd ID for RestoreObj::Execute
00023 #define RESTOBJ_GOING_TO_DELETE_POINTER     2 // cmd ID for RestoreObj::Execute
00024 #define REFTARG_AUTO_DELETED                10 // cmd ID for HoldStore::Execute
00025 
00026 #define HOLD_SYSTEM_EMPTY                   1 // cmd ID for Hold::Execute - return 1 if hold system is definitely empty
00027 #define HOLD_POINTER_IS_MANAGER             2 // cmd ID for Hold::Execute - return 1 if arg1 is a pointer to the undo manager
00028 #define HOLD_SUPERLEVEL                     3 // cmd ID for Hold::Execute - return Hold.superLevel
00029 
00030 class HoldStore;
00035 class RestoreObj : public InterfaceServer {
00036     friend class HoldStore;
00037     friend class GenUndoObject;
00038     friend class CheckForFlush;
00039         RestoreObj *next,*prev;
00040     public:
00041         RestoreObj() { next = prev = NULL; }
00042         virtual ~RestoreObj() {};
00057         virtual void Restore(int isUndo)=0;
00061         virtual void Redo()=0;
00068         virtual int Size() { return sizeof(RestoreObj); }
00074         virtual void EndHold() { }
00080         virtual MSTR Description() { return MSTR(_M("---")); }
00088         virtual INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0)
00089         {
00090             UNUSED_PARAM(cmd);
00091             UNUSED_PARAM(arg1);
00092             UNUSED_PARAM(arg2);
00093             UNUSED_PARAM(arg3);
00094             return -1;
00095         }
00096     };
00097 
00103 class Hold : public BaseInterfaceServer {
00104     HoldStore *holdStore, *holdList;
00105     int undoEnabled;
00106     int superLevel;
00107     int putCount;
00108     HoldStore *ResetStore();
00109     void Init();
00110     void AddOpToUndoMgr(MCHAR *name,int id);
00111     public:
00112         CoreExport Hold();
00113         CoreExport ~Hold();
00126         CoreExport void Put(RestoreObj *rob);
00142         CoreExport void Begin();
00145         CoreExport void Suspend();    // temporarly suspend holding
00146         CoreExport int IsSuspended();
00149         CoreExport void Resume();    // resume holding
00164         CoreExport int  Holding();  // are we holding?
00169         CoreExport int  Restoring(int& isUndo);
00172         CoreExport int  Redoing();
00176         CoreExport int  RestoreOrRedoing();
00177 
00181         CoreExport void DisableUndo();  // prevents Undo when Accept is called.
00185         CoreExport void EnableUndo();
00189         CoreExport BOOL IsUndoDisabled();
00190 
00193         CoreExport int GetBeginDepth();
00194 
00200         CoreExport void Restore();  // Restore changes from holdStore. 
00205         CoreExport void Release();  // Tosses out holdStore. 
00206 
00207         // 3 ways to terminate the Begin()...
00212         CoreExport void End();  // toss holdStore.
00220         CoreExport void Accept(int nameID); // record Undo (if enabled), End();
00225         CoreExport void Accept(MCHAR *name);
00229         CoreExport void Cancel();   // Restore changes, End() 
00230 
00231         //      
00232         // Group several Begin-End lists into a single Super-group.
00259         CoreExport void SuperBegin();
00268         CoreExport void SuperAccept(int nameID);
00275         CoreExport void SuperAccept(MCHAR *name);
00282         CoreExport void SuperCancel();
00285         CoreExport int GetSuperBeginDepth();
00286 
00287 
00288         // Get the number of times Put() has been called in the current session of MAX
00291         CoreExport int GetGlobalPutCount();
00292 
00293         CoreExport INT_PTR Execute(int cmd, ULONG_PTR arg1=0, ULONG_PTR arg2=0, ULONG_PTR arg3=0);
00294 
00303         CoreExport DWORD_PTR Size() const;
00304 
00305     protected:
00306         friend HoldStore;
00307         unsigned flags;
00308         enum {
00309             kInRestore,
00310             kInUndo,
00311             kInRedo
00312         };
00313     };
00314 
00315 
00316 
00317 extern CoreExport Hold theHold;
00318 
00319 CoreExport void EnableUndoDebugPrintout(BOOL onoff);
00320 
00321 // A class to help control the hold system. Create an instance of this class, and when it is
00322 // destructed any hold suspends are resumed. Makes it safe in case a throw occurs after the suspend,
00323 // but before the resume
00324 class HoldSuspend: public MaxHeapOperators {
00325 public:
00326     HoldSuspend(BOOL suspendNow = TRUE) : suspendCount(0) {
00327         if (suspendNow) {
00328             this->Suspend();
00329         }
00330     }
00331     ~HoldSuspend()  {
00332         while(suspendCount > 0) {
00333             this->Resume();
00334         }
00335     }
00336     void Suspend() {
00337         if (suspendCount == 0) 
00338             theHold.Suspend ();
00339         suspendCount++;
00340     }
00341     void Resume() {
00342         if (suspendCount == 1) 
00343             theHold.Resume();
00344         if (suspendCount > 0) 
00345             suspendCount--;
00346     }
00347 
00348 private:
00349     int suspendCount;
00350 
00351 };                    
00352 
00353 
00354