home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / FWCmd.h < prev    next >
Encoding:
Text File  |  1996-09-17  |  10.8 KB  |  327 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWCmd.h
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #ifndef FWCMD_H
  11. #define FWCMD_H
  12.  
  13. // ----- Foundation Includes -----
  14.  
  15. #ifndef FWSTDDEF_H
  16. #include "FWStdDef.h"
  17. #endif
  18.  
  19. #ifndef FWEXCLIB_H
  20. #include "FWExcLib.h"
  21. #endif
  22.  
  23. // ----- OpenDoc Includes -----
  24.  
  25. #ifndef FWODTYPS_H
  26. #include "FWODTyps.h"
  27. #endif
  28.  
  29. #ifndef SOM_ODUndo_xh
  30. #include <Undo.xh>
  31. #endif
  32.  
  33. //==============================================================================
  34. //    Forward Declarations
  35. //==============================================================================
  36.  
  37. class FW_CPart;
  38. class FW_CFrame;
  39. class FW_CString;
  40. class FW_CPresentation;
  41. class ODUndo;
  42.  
  43. //==============================================================================
  44. //    Constants
  45. //==============================================================================
  46.  
  47. #define FW_kCanUndo TRUE
  48. #define FW_kCantUndo FALSE
  49.  
  50. //==============================================================================
  51. // class FW_CCommand
  52. //==============================================================================
  53.  
  54. class FW_CCommand
  55. {
  56.   public:
  57.     FW_DECLARE_AUTO(FW_CCommand)
  58.  
  59.   public:
  60.  
  61. //------------------------------------------------------------------------
  62. // --- Initialization/Destruction ---
  63.  
  64.     FW_CCommand(Environment* ev,
  65.                 ODCommandID id,
  66.                 FW_CFrame* frame,
  67.                 FW_Boolean canUndo);
  68.     virtual ~ FW_CCommand();
  69.  
  70. //------------------------------------------------------------------------
  71. // --- Command API ---
  72.  
  73.     FW_Boolean Execute(Environment* ev, FW_Boolean deleteIfNotUndoable = TRUE);
  74.         // Execute the command by calling DoIt, 
  75.         // and take care of OpenDoc Undo/Redo paperwork if necessary.
  76.         // Return TRUE if the command is on the OpenDoc undo stack. The command
  77.         // is automatically deleted if not undoable unless deleteIfNotUndoable is
  78.         // set to false
  79.  
  80.     virtual void DoIt(Environment* ev) = 0;
  81.         // Must be overridden by all commands
  82.  
  83. //------------------------------------------------------------------------
  84. // --- API for Undo-able Commands ---
  85.  
  86.     virtual void UndoIt(Environment* ev);
  87.     virtual void RedoIt(Environment* ev);
  88.         // Undo-able commands must override
  89.         // Default does nothing
  90.  
  91.     virtual void CommitDone(Environment* ev);
  92.         // Called just before the command is deleted.
  93.         // doneState values are kODDone or kODRedone (ODTypes.h)
  94.         // Default calls FreeUndoState
  95.  
  96.     virtual void CommitUndone(Environment* ev);
  97.         // Called just before the command is deleted.
  98.         // doneState value is kODUndone (ODTypes.h)
  99.         // Default calls FreeRedoState
  100.  
  101.     virtual void SaveUndoState(Environment* ev);
  102.     virtual void SaveRedoState(Environment* ev);
  103.         // Save state of data for later undo and redo
  104.         // Default does nothing
  105.  
  106.     virtual void FreeUndoState(Environment* ev);
  107.     virtual void FreeRedoState(Environment* ev);
  108.         // delete data saved for undo and redo
  109.         // Default does nothing
  110.  
  111. //------------------------------------------------------------------------
  112. // --- New API ---
  113. public:
  114.     ODActionType        GetActionType(Environment* ev) const;
  115.  
  116.     FW_Boolean            GetCanUndo(Environment* ev) const;
  117.     void                SetCanUndo(Environment* ev, FW_Boolean canUndo);
  118.     
  119.     FW_Boolean            GetCausesChange(Environment* ev) const;
  120.     void                SetCausesChange(Environment* ev, FW_Boolean causesChange);
  121.     
  122.     ODCommandID            GetCommandID(Environment* ev) const;
  123.     void                SetCommandID(Environment* ev, ODCommandID id);
  124.     
  125.     ODName*                GetUndoString(Environment* ev);
  126.     ODName*                GetRedoString(Environment* ev);
  127.     
  128.     FW_CPresentation*    GetPresentation(Environment* ev) const;
  129.     FW_CFrame*            GetSourceFrame(Environment* ev) const;
  130.     FW_CFrame*            GetFrame(Environment* ev) const;
  131.     FW_CPart*            GetPart(Environment* ev) const;
  132.     
  133.     FW_Boolean            HasAddedAction(Environment* ev) const;
  134.  
  135.     void                SetActionType(Environment* ev, ODActionType actionType);
  136.  
  137.     static void        AddEndAction(Environment* ev, short undoMsgID, FW_CPart* part);
  138.     virtual void         HandleUndo(Environment* ev);
  139.     virtual void         HandleRedo(Environment* ev);
  140.  
  141.     virtual void         PropagateChanges(Environment* ev,  ODUpdateID id = kODUnknownUpdate);
  142.  
  143.  
  144. protected:
  145.     void                SetMenuStrings(Environment* ev,
  146.                                    const FW_CString& undoString,
  147.                                    const FW_CString& redoString);
  148.     void                SetMenuStrings(Environment* ev,
  149.                                    char* undoChars,
  150.                                    char* redoChars);
  151.     void                SetMenuStringsFromResource(Environment* ev, 
  152.                                                short stringResourceID, 
  153.                                                short undoStringID, 
  154.                                                short redoStringID);
  155.                             // Call one of these to set up menu strings for Undo and Redo
  156.  
  157.     void                AddAction(Environment* ev, 
  158.                               ODActionType actionType, 
  159.                               octet* dataPtr, 
  160.                               unsigned long dataSize,
  161.                               ODName* undoActionLabel,
  162.                               ODName* redoActionLabel);
  163.                             // Call ODUndo::AddActionToHistory; used for transactions
  164.  
  165.     virtual FW_Boolean    IsOKtoEdit(Environment* ev);
  166.                             // Checks whether it's OK to change this part and frame
  167.  
  168. //------------------------------------------------------------------------
  169. //    Implementation Only
  170. //
  171. private:
  172.     void            PrivLoadDefaultUndoStrings(Environment* ev);    
  173.     void            PrivDisposeUndoStrings();
  174.     
  175. //------------------------------------------------------------------------
  176. // --- Data Members ---
  177. private:
  178.     FW_Boolean            fCanUndo;                // Default = TRUE
  179.     FW_Boolean            fCausesChange;            // Default = TRUE
  180.     ODCommandID            fCommandID;
  181.     ODActionType        fActionType;            // Default = kODSingleAction
  182.  
  183.     ODName*                fUndoString;            // string for Undo menu item
  184.     ODName*                fRedoString;            // string for Redo menu item
  185.  
  186.     FW_CPart*            fPart;    
  187.     FW_CFrame*            fFrame;                    // Original Command Frame (might not be valid during Undo/Redo)
  188.     FW_CPresentation*    fPresentation; 
  189.     FW_CFrame*            fSourceFrame;
  190.     
  191.     FW_Boolean            fHasAddedAction;        // TRUE if this command has called AddAction
  192.  
  193.     // Don't allow commands to be copied or returned from functions
  194.     FW_CCommand(const FW_CCommand& command);            // Copy constructor
  195.     FW_CCommand& operator=(const FW_CCommand& command);    // Assignment operator
  196. };
  197.  
  198. //========================================================================================
  199. //    FW_CCommand Inlines
  200. //========================================================================================
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CCommand::GetActionType
  204. //----------------------------------------------------------------------------------------
  205. inline ODActionType FW_CCommand::GetActionType(Environment*) const
  206. {
  207.     return fActionType;
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CCommand::GetCanUndo
  212. //----------------------------------------------------------------------------------------
  213. inline FW_Boolean FW_CCommand::GetCanUndo(Environment*) const
  214. {
  215.     return fCanUndo;
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CCommand::SetCanUndo
  220. //----------------------------------------------------------------------------------------
  221. inline void FW_CCommand::SetCanUndo(Environment*, FW_Boolean canUndo)
  222. {
  223.     fCanUndo = canUndo;
  224. }
  225.  
  226. //----------------------------------------------------------------------------------------
  227. //    FW_CCommand::GetCausesChange
  228. //----------------------------------------------------------------------------------------
  229. inline FW_Boolean FW_CCommand::GetCausesChange(Environment*) const
  230. {
  231.     return fCausesChange;
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CCommand::SetCausesChange
  236. //----------------------------------------------------------------------------------------
  237. inline void FW_CCommand::SetCausesChange(Environment*, FW_Boolean causesChange)
  238. {
  239.     fCausesChange = causesChange;
  240. }
  241.  
  242. //----------------------------------------------------------------------------------------
  243. //    FW_CCommand::GetCommandID
  244. //----------------------------------------------------------------------------------------
  245. inline ODCommandID FW_CCommand::GetCommandID(Environment*) const
  246. {
  247.     return fCommandID;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CCommand::SetCommandID
  252. //----------------------------------------------------------------------------------------
  253. inline void FW_CCommand::SetCommandID(Environment*, ODCommandID id)
  254. {
  255.     fCommandID = id;
  256. }
  257.  
  258. //----------------------------------------------------------------------------------------
  259. //    FW_CCommand::GetUndoString
  260. //----------------------------------------------------------------------------------------
  261. inline ODName* FW_CCommand::GetUndoString(Environment* ev)
  262. {
  263.     if (!fUndoString)
  264.         PrivLoadDefaultUndoStrings(ev);
  265.     return fUndoString;
  266. }
  267.  
  268. //----------------------------------------------------------------------------------------
  269. //    FW_CCommand::GetRedoString
  270. //----------------------------------------------------------------------------------------
  271. inline ODName* FW_CCommand::GetRedoString(Environment* ev)
  272. {
  273.     if (!fRedoString)
  274.         PrivLoadDefaultUndoStrings(ev);
  275.     return fRedoString;
  276. }
  277.  
  278. //----------------------------------------------------------------------------------------
  279. //    FW_CCommand::HasAddedAction
  280. //----------------------------------------------------------------------------------------
  281. inline FW_Boolean FW_CCommand::HasAddedAction(Environment*) const
  282. {
  283.     return fHasAddedAction;
  284. }
  285.  
  286. //----------------------------------------------------------------------------------------
  287. //    FW_CCommand::SetActionType
  288. //----------------------------------------------------------------------------------------
  289. inline void FW_CCommand::SetActionType(Environment*, ODActionType actionType)
  290. {
  291.     fActionType = actionType;
  292. }
  293.  
  294. //----------------------------------------------------------------------------------------
  295. //    FW_CCommand::GetPart
  296. //----------------------------------------------------------------------------------------
  297. inline FW_CPart* FW_CCommand::GetPart(Environment*) const
  298. {
  299.     return fPart;
  300. }
  301.  
  302. //----------------------------------------------------------------------------------------
  303. //    FW_CCommand::GetFrame
  304. //----------------------------------------------------------------------------------------
  305. inline FW_CFrame* FW_CCommand::GetFrame(Environment*) const
  306. {
  307.     return fFrame;
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. //    FW_CCommand::GetSourceFrame
  312. //----------------------------------------------------------------------------------------
  313. inline FW_CFrame* FW_CCommand::GetSourceFrame(Environment*) const
  314. {
  315.     return fSourceFrame;
  316. }
  317.  
  318. //----------------------------------------------------------------------------------------
  319. //    FW_CCommand::GetPresentation
  320. //----------------------------------------------------------------------------------------
  321. inline FW_CPresentation* FW_CCommand::GetPresentation(Environment*) const
  322. {
  323.     return fPresentation;
  324. }
  325.  
  326. #endif
  327.