home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / Draw / Sources / ClipCmds.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  9.0 KB  |  320 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                ClipCmds.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Henri Lamiraux
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef CLIPCMDS_H
  15. #include "ClipCmds.h"
  16. #endif
  17.  
  18. #ifndef DRAWCONT_H
  19. #include "DrawCont.h"
  20. #endif
  21.  
  22. #ifndef DRAWSEL_H
  23. #include "DrawSel.h"
  24. #endif
  25.  
  26. #ifndef BASESHP_H
  27. #include "BaseShp.h"
  28. #endif
  29.  
  30. #ifndef BOUNDSHP_H
  31. #include "BoundShp.h"
  32. #endif
  33.  
  34. #ifndef LINESHP_H
  35. #include "LineShp.h"
  36. #endif
  37.  
  38. #ifndef OVALSHP_H
  39. #include "OvalShp.h"
  40. #endif
  41.  
  42. #ifndef RECTSHP_H
  43. #include "RectShp.h"
  44. #endif
  45.  
  46. #ifndef RRECTSHP_H
  47. #include "RRectShp.h"
  48. #endif
  49.  
  50. #ifndef TEXTSHP_H
  51. #include "TextShp.h"
  52. #endif
  53.  
  54. #ifndef DRAWPART_H
  55. #include "DrawPart.h"
  56. #endif
  57.  
  58. #ifndef DRAWFRM_H
  59. #include "DrawFrm.h"
  60. #endif
  61.  
  62. #ifndef DRAWLINK_H
  63. #include "DrawLink.h"
  64. #endif
  65.  
  66. // ----- FrameWork Includes -----
  67.  
  68. #ifndef FWPRESEN_H
  69. #include "FWPresen.h"
  70. #endif
  71.  
  72. // ----- OS Includes -----
  73.  
  74. #ifndef FWORDCOL_H
  75. #include "FWOrdCol.h"
  76. #endif
  77.  
  78. // ----- OpenDoc Includes -----
  79.  
  80. #ifndef SOM_Module_OpenDoc_Commands_defined
  81. #include <CmdDefs.xh>
  82. #endif
  83.  
  84. //========================================================================================
  85. // RunTime Info
  86. //========================================================================================
  87.  
  88. #ifdef FW_BUILD_MAC
  89. #pragma segment odfdrawcommand
  90. #endif
  91.  
  92. FW_DEFINE_AUTO(CDrawClipboardCommand)
  93.  
  94. //========================================================================================
  95. // CDrawClipboardCommand
  96. //========================================================================================
  97.  
  98. //----------------------------------------------------------------------------------------
  99. //    CDrawClipboardCommand constructor
  100. //----------------------------------------------------------------------------------------
  101.  
  102. CDrawClipboardCommand::CDrawClipboardCommand(Environment* ev, 
  103.                                             ODCommandID commandID,
  104.                                             CDrawPart* part, 
  105.                                             CDrawFrame* frame, 
  106.                                             CDrawSelection* selection,
  107.                                             FW_Boolean canUndo) :
  108.     FW_CClipboardCommand(ev, commandID, frame, canUndo),
  109.         fDrawPart(part),
  110.         fDrawSelection(selection),
  111.         fUndoContent(NULL),
  112.         fSavedLink(NULL)
  113. {
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CDrawClipboardCommand destructor
  118. //----------------------------------------------------------------------------------------
  119.  
  120. CDrawClipboardCommand::~CDrawClipboardCommand()
  121. {
  122.     delete fUndoContent;
  123. }
  124.  
  125. //----------------------------------------------------------------------------------------
  126. //    CDrawClipboardCommand::SaveUndoState
  127. //----------------------------------------------------------------------------------------
  128. void CDrawClipboardCommand::SaveUndoState(Environment* ev)    // Override
  129. {
  130.     ODCommandID commandID = GetCommandID(ev);
  131.     
  132.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  133.     {
  134.         FW_ASSERT(fUndoContent == NULL);
  135.         fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawSelection));
  136.     }
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    CDrawClipboardCommand::SaveRedoState
  141. //----------------------------------------------------------------------------------------
  142. void CDrawClipboardCommand::SaveRedoState(Environment* ev)    // Override
  143. {
  144.     if (this->IsPasteWithoutLink(ev))
  145.     {
  146.         FW_ASSERT(fUndoContent == NULL);
  147.         fUndoContent = FW_NEW(CDrawUndoContent, (ev, fDrawSelection));
  148.     }    
  149. }
  150.  
  151. //----------------------------------------------------------------------------------------
  152. //    CDrawClipboardCommand::FreeUndoState
  153. //----------------------------------------------------------------------------------------
  154. void CDrawClipboardCommand::FreeUndoState(Environment* ev)    // Override
  155. {
  156.     ODCommandID commandID = GetCommandID(ev);
  157.     
  158.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  159.         fUndoContent->DeleteSavedShapesAndLinks(ev);
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    CDrawClipboardCommand::FreeRedoState
  164. //----------------------------------------------------------------------------------------
  165. void CDrawClipboardCommand::FreeRedoState(Environment* ev)    // Override
  166. {
  167.     if (this->IsPasteWithoutLink(ev))
  168.         fUndoContent->DeleteSavedShapes(ev);
  169. }
  170.  
  171. //----------------------------------------------------------------------------------------
  172. //    CDrawClipboardCommand::UndoIt
  173. //----------------------------------------------------------------------------------------
  174. void CDrawClipboardCommand::UndoIt(Environment* ev)    // Override
  175. {
  176.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  177.  
  178.     switch (GetCommandID(ev))
  179.     {
  180.         case kODCommandCut:
  181.         case kODCommandClear:
  182.             fUndoContent->RestoreShapeSelection(ev);
  183.             fUndoContent->RestoreLinks(ev);
  184.             break;
  185.  
  186.         case kODCommandPasteAs:
  187.             if (fSavedLink)
  188.             {
  189.                 GetDrawLinkManager(ev)->UndoPasteAs(ev, fSavedLink);
  190.                 GetPresentation(ev)->Invalidate(ev);
  191.                 break;
  192.             }    
  193.         //    else fall through to kODCommandPaste
  194.  
  195.         case kODCommandPaste:
  196.             fUndoContent->RemoveShapeSelection(ev);
  197.             break;
  198.     }    
  199. }
  200.  
  201. //----------------------------------------------------------------------------------------
  202. //    CDrawClipboardCommand::RedoIt
  203. //----------------------------------------------------------------------------------------
  204. void CDrawClipboardCommand::RedoIt(Environment* ev)    // Override
  205. {
  206.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  207.  
  208.     switch (GetCommandID(ev))
  209.     {
  210.         case kODCommandCut:
  211.         case kODCommandClear:
  212.             fUndoContent->RemoveShapeSelection(ev);
  213.             fUndoContent->RemoveFromLinks(ev);
  214.             break;
  215.  
  216.         case kODCommandPasteAs:
  217.             if (fSavedLink)
  218.             {
  219.                 GetDrawLinkManager(ev)->RedoPasteAs(ev, fSavedLink);
  220.                 GetPresentation(ev)->Invalidate(ev);
  221.                 break;
  222.             }    
  223.         //    else fall through to kODCommandPaste
  224.  
  225.         case kODCommandPaste:
  226.             fUndoContent->RestoreShapeSelection(ev);
  227.             break;
  228.     }    
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    CDrawClipboardCommand::PreCommand
  233. //----------------------------------------------------------------------------------------
  234.  
  235. void CDrawClipboardCommand::PreCommand(Environment* ev)
  236. {
  237.     ODCommandID commandID = GetCommandID(ev);
  238.     
  239.     if (commandID == kODCommandPaste || commandID == kODCommandPasteAs)
  240.         fDrawSelection->CloseSelection(ev);
  241. }
  242.  
  243. //----------------------------------------------------------------------------------------
  244. //    CDrawClipboardCommand::CommandDone
  245. //----------------------------------------------------------------------------------------
  246.  
  247. void CDrawClipboardCommand::CommandDone(Environment* ev)
  248. {
  249.     ODCommandID commandID = GetCommandID(ev);
  250.  
  251.     if (commandID == kODCommandPaste)
  252.         fDrawSelection->CenterSelection(ev, GetFrame(ev));
  253.     else if (commandID == kODCommandPasteAs)
  254.     {
  255.         fSavedLink = (CDrawSubscribeLink*)GetNewLink(ev);
  256.         if (fSavedLink)
  257.         {
  258.             // Select the newly-subscribed shapes
  259.             fSavedLink->SelectShapes(ev);
  260.         
  261.             // Offset the selection, saving the offset for later updates
  262.             FW_CPoint offset = fDrawSelection->CenterSelection(ev, GetFrame(ev));
  263.         
  264.             // Save information about newly-created link
  265.             fSavedLink->SetUpdateOffset(ev, offset);
  266.         }
  267.     }
  268.     else if (commandID == kODCommandCut || commandID == kODCommandClear)
  269.     {
  270.         fUndoContent->RemoveFromLinks(ev);
  271.     }
  272. }
  273.  
  274. //----------------------------------------------------------------------------------------
  275. //    CDrawClipboardCommand::IsPasteWithoutLink
  276. //----------------------------------------------------------------------------------------
  277.  
  278. FW_Boolean CDrawClipboardCommand::IsPasteWithoutLink(Environment* ev) const
  279. {
  280.     if (GetCommandID(ev) == kODCommandPaste)
  281.         return TRUE;
  282.     if (GetCommandID(ev) == kODCommandPasteAs)
  283.         return (fSavedLink == NULL);
  284.         
  285.     return FALSE;
  286. }
  287.  
  288. //----------------------------------------------------------------------------------------
  289. //    CDrawClipboardCommand::GetDrawLinkManager
  290. //----------------------------------------------------------------------------------------
  291.  
  292. CDrawLinkManager* CDrawClipboardCommand::GetDrawLinkManager(Environment* ev) const
  293. {
  294.     return (CDrawLinkManager*)GetPart(ev)->GetLinkManager(ev);
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    CDrawClipboardCommand::CommitUndone
  299. //----------------------------------------------------------------------------------------
  300.  
  301. void CDrawClipboardCommand::CommitUndone(Environment* ev)    // Override
  302. {
  303.     if (fSavedLink == NULL)
  304.         FW_CClipboardCommand::CommitUndone(ev);
  305. }
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    CDrawClipboardCommand::CommitDone
  309. //----------------------------------------------------------------------------------------
  310. void CDrawClipboardCommand::CommitDone(Environment* ev)    // Override
  311. {
  312.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  313.     {
  314.         // Delete link sources left empty because all their shapes were removed
  315.         fUndoContent->DeleteEmptyLinkSources(ev);
  316.     }
  317.  
  318.     FW_CClipboardCommand::CommitDone(ev);    // calls FreeUndoState
  319. }
  320.