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 / Container / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  28.5 KB  |  870 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Commands.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "Container.hpp"
  11.  
  12. #ifndef COMMANDS_H
  13. #include "Commands.h"
  14. #endif
  15.  
  16. #ifndef DEFINES_K
  17. #include "Defines.k"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef CONTENT_H
  25. #include "Content.h"
  26. #endif
  27.  
  28. #ifndef FRAME_H
  29. #include "Frame.h"
  30. #endif
  31.  
  32. #ifndef SELECT_H
  33. #include "Select.h"
  34. #endif
  35.  
  36. #ifndef PROXY_H
  37. #include "Proxy.h"
  38. #endif
  39.  
  40. #ifndef FWFRAME_H
  41. #include "FWFrame.h"
  42. #endif
  43.  
  44. #ifndef FWPRESEN_H
  45. #include "FWPresen.h"
  46. #endif
  47.  
  48. #ifndef FWFCTCLP_H
  49. #include "FWFctClp.h"
  50. #endif
  51.  
  52. #ifndef FWMEMMGR_H
  53. #include "FWMemMgr.h"
  54. #endif
  55.  
  56. #ifndef FWSOMENV_H
  57. #include "FWSOMEnv.h"
  58. #endif
  59.  
  60. // ----- OpenDoc Includes -----
  61.  
  62. #ifndef SOM_Module_OpenDoc_Commands_defined
  63. #include <CmdDefs.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODShape_xh
  67. #include <Shape.xh>
  68. #endif
  69.  
  70. //========================================================================================
  71. // Runtime Information
  72. //========================================================================================
  73.  
  74. #ifdef FW_BUILD_MAC
  75. #pragma segment odfcontainer
  76. #endif
  77.  
  78. FW_DEFINE_AUTO(CClipboardCommand)
  79. FW_DEFINE_AUTO(CDragCommand)
  80. FW_DEFINE_AUTO(CDropCommand)
  81. FW_DEFINE_AUTO(CInsertCommand)
  82. FW_DEFINE_AUTO(CResizeCommand)
  83. FW_DEFINE_AUTO(CViewAsCommand)
  84. FW_DEFINE_AUTO(CSetBackgroundColorCommand)
  85.  
  86. //========================================================================================
  87. // CClipboardCommand
  88. //========================================================================================
  89.  
  90. //----------------------------------------------------------------------------------------
  91. //    CClipboardCommand constructor
  92. //----------------------------------------------------------------------------------------
  93.  
  94. CClipboardCommand::CClipboardCommand(Environment* ev, 
  95.                                      ODCommandID commandID,
  96.                                      CContainerPart* part, 
  97.                                      CContainerFrame* frame, 
  98.                                      CContainerSelection* selection,
  99.                                      FW_Boolean canUndo) :
  100.     FW_CClipboardCommand(ev, commandID, frame, canUndo),
  101.         fContainerPart(part),
  102.         fContainerSelection(selection),
  103.         fUndoContent(NULL)
  104. {
  105. }
  106.  
  107. //----------------------------------------------------------------------------------------
  108. //    CClipboardCommand destructor
  109. //----------------------------------------------------------------------------------------
  110.  
  111. CClipboardCommand::~CClipboardCommand()
  112. {
  113.     delete fUndoContent;
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    CClipboardCommand::SaveUndoState
  118. //----------------------------------------------------------------------------------------
  119. void CClipboardCommand::SaveUndoState(Environment* ev)    // Override
  120. {
  121.     ODCommandID commandID = GetCommandID(ev);
  122.     
  123.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  124.     {
  125.         FW_ASSERT(fUndoContent == NULL);
  126.         fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  127.     }
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    CClipboardCommand::SaveRedoState
  132. //----------------------------------------------------------------------------------------
  133. void CClipboardCommand::SaveRedoState(Environment* ev)    // Override
  134. {
  135.     if (GetCommandID(ev) == kODCommandPaste)
  136.     {
  137.         FW_ASSERT(fUndoContent == NULL);
  138.         fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  139.     }    
  140. }
  141.  
  142. //----------------------------------------------------------------------------------------
  143. //    CClipboardCommand::FreeUndoState
  144. //----------------------------------------------------------------------------------------
  145. void CClipboardCommand::FreeUndoState(Environment* ev)    // Override
  146. {
  147.     ODCommandID commandID = GetCommandID(ev);
  148.     
  149.     if (commandID == kODCommandCut || commandID == kODCommandClear)
  150.         fUndoContent->DeleteSavedProxies(ev);
  151. }
  152.  
  153. //----------------------------------------------------------------------------------------
  154. //    CClipboardCommand::FreeRedoState
  155. //----------------------------------------------------------------------------------------
  156. void CClipboardCommand::FreeRedoState(Environment* ev)    // Override
  157. {
  158.     if (GetCommandID(ev) == kODCommandPaste)
  159.         fUndoContent->DeleteSavedProxies(ev);
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    CClipboardCommand::UndoIt
  164. //----------------------------------------------------------------------------------------
  165. void CClipboardCommand::UndoIt(Environment* ev)    // Override
  166. {
  167.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  168.  
  169.     switch (GetCommandID(ev))
  170.     {
  171.         case kODCommandCut:
  172.         case kODCommandClear:
  173.             fUndoContent->RestoreProxySelection(ev);
  174.             break;
  175.  
  176.         case kODCommandPaste:
  177.             fUndoContent->RemoveProxySelection(ev);
  178.             break;
  179.     }    
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    CClipboardCommand::RedoIt
  184. //----------------------------------------------------------------------------------------
  185. void CClipboardCommand::RedoIt(Environment* ev)    // Override
  186. {
  187.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  188.  
  189.     switch (GetCommandID(ev))
  190.     {
  191.         case kODCommandCut:
  192.         case kODCommandClear:
  193.             fUndoContent->RemoveProxySelection(ev);
  194.             break;
  195.  
  196.         case kODCommandPaste:
  197.             fUndoContent->RestoreProxySelection(ev);
  198.             break;
  199.     }    
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CClipboardCommand::PreCommand
  204. //----------------------------------------------------------------------------------------
  205.  
  206. void CClipboardCommand::PreCommand(Environment* ev)
  207. {
  208.     if (GetCommandID(ev) == kODCommandPaste)
  209.         fContainerSelection->CloseSelection(ev);
  210. }
  211.  
  212. //----------------------------------------------------------------------------------------
  213. //    CClipboardCommand::CommandDone
  214. //----------------------------------------------------------------------------------------
  215.  
  216. void CClipboardCommand::CommandDone(Environment* ev)
  217. {
  218.     if (GetCommandID(ev) == kODCommandPaste)
  219.         fContainerSelection->CenterSelection(ev, GetFrame(ev));
  220. }
  221.  
  222. //========================================================================================
  223. // class CDragCommand
  224. //========================================================================================
  225.  
  226. //----------------------------------------------------------------------------------------
  227. //    CDragCommand constructor
  228. //----------------------------------------------------------------------------------------
  229. CDragCommand::CDragCommand(Environment* ev,
  230.                            CContainerPart* part,
  231.                            FW_CFrame* frame,
  232.                            CContainerSelection* selection,
  233.                            FW_Boolean canUndo)
  234.     : FW_CDragCommand(ev, frame, canUndo),
  235.         fContainerPart(part),
  236.         fContainerSelection(selection),
  237.         fDraggedContent(NULL)
  238. {
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    CDragCommand destructor
  243. //----------------------------------------------------------------------------------------
  244.  
  245. CDragCommand::~CDragCommand()
  246. {
  247.     delete fDraggedContent;        // Will call remove all if necessary
  248.     fDraggedContent = NULL;
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    CDragCommand::SaveUndoState
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void CDragCommand::SaveUndoState(Environment* ev)    // Override
  256. {
  257.     FW_ASSERT(fDraggedContent == NULL);    
  258.     fDraggedContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    CDragCommand::UndoIt
  263. //----------------------------------------------------------------------------------------
  264.  
  265. void CDragCommand::UndoIt(Environment* ev)    // Override
  266. {
  267.     // ----- Add the dragged proxies back into the part
  268.     CContentProxyIterator ite(fDraggedContent);
  269.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  270.     {
  271.         fContainerPart->AttachProxy(ev, proxy);
  272.     }
  273.  
  274.     // ----- Add the saved proxies to the selection
  275.     fContainerSelection->SelectContent(ev, fDraggedContent);
  276.     
  277.     // ----- Invalidate 
  278.     GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    CDragCommand::RedoIt
  283. //----------------------------------------------------------------------------------------
  284.  
  285. void CDragCommand::RedoIt(Environment* ev)    // Override
  286. {
  287.     // Select saved proxies
  288.     fContainerSelection->SelectContent(ev, fDraggedContent);
  289.  
  290.     fContainerSelection->ClearSelection(ev); // clear them, again
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    CDragCommand::FreeUndoState
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void CDragCommand::FreeUndoState(Environment* ev)    // Override
  298. {
  299.     // Delete the dragged proxies - they're gone forever
  300.     fDraggedContent->DeleteSavedProxies(ev);
  301. }
  302.  
  303. //========================================================================================
  304. // class CDropCommand
  305. //========================================================================================
  306.  
  307. //----------------------------------------------------------------------------------------
  308. //    CDropCommand constructor
  309. //----------------------------------------------------------------------------------------
  310. CDropCommand::CDropCommand(Environment* ev,
  311.                            CContainerPart* part,
  312.                            FW_CFrame* frame,
  313.                            ODDragItemIterator* dropInfo, 
  314.                            ODFacet* facet, 
  315.                            const FW_CPoint& dropPoint,
  316.                            FW_Boolean canUndo)
  317.     : FW_CDropCommand(ev, frame, dropInfo, facet, dropPoint, canUndo),
  318.         fContainerPart(part),
  319.         fDropDelta(FW_kZeroPoint),
  320.         fDroppedContent(NULL),
  321.         fContainerSelection((CContainerSelection*)frame->GetPresentation(ev)->GetSelection(ev))
  322. {
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    CDropCommand destructor
  327. //----------------------------------------------------------------------------------------
  328.  
  329. CDropCommand::~CDropCommand()
  330. {
  331.     delete fDroppedContent;
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. //    CDropCommand::DoDrop
  336. //----------------------------------------------------------------------------------------
  337. FW_Boolean CDropCommand::DoDrop(Environment* ev, 
  338.                                 ODStorageUnit* dropSU, 
  339.                                 const FW_CPoint& mouseDownOffset, 
  340.                                 const FW_CPoint& dropPoint,
  341.                                 FW_Boolean isDropMove,
  342.                                 short itemNumber)
  343. {
  344.     if (itemNumber == 1)
  345.         fContainerSelection->CloseSelection(ev);
  346.     
  347.     FW_Boolean result = FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
  348.     
  349.     if (result)
  350.     {    
  351.         fContainerSelection->CalcCache(ev);
  352.         
  353.         FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
  354.         
  355.         FW_CRect box = fContainerSelection->GetDragRect(ev);
  356.  
  357.         fContainerSelection->OffsetSelection(ev, newPosition.x - box.left, newPosition.y - box.top);
  358.         
  359.         ODShape* updateShape = fContainerSelection->GetUpdateShape(ev);
  360.         
  361.         // ----- Calculate clip -----
  362.         FW_CFacetClipper facetClipper;
  363.         facetClipper.Clip(ev, fContainerSelection->GetPresentation(ev), updateShape);    
  364.  
  365.         // ----- Invalidate -----
  366.         GetPresentation(ev)->Invalidate(ev, updateShape);
  367.         
  368.         // ----- If I am not the active part I should not have a selection -----
  369.         if (!fContainerPart->HasSelectionFocus(ev))
  370.             fContainerSelection->CloseSelection(ev);
  371.     }
  372.     
  373.     return result;
  374. }
  375.  
  376. //----------------------------------------------------------------------------------------
  377. //    CDropCommand::DoDroppedInSameFrame
  378. //----------------------------------------------------------------------------------------
  379. FW_Boolean CDropCommand::DoDroppedInSameFrame(Environment* ev, 
  380.                                               ODStorageUnit* dropSU, 
  381.                                               const FW_CPoint& mouseDownOffset,
  382.                                               const FW_CPoint& dropPoint)
  383. {
  384.     FW_UNUSED(dropSU);
  385.     
  386.     FW_CPoint newPosition(dropPoint.x - mouseDownOffset.x, dropPoint.y - mouseDownOffset.y);
  387.             
  388.     FW_CRect box = fContainerSelection->GetDragRect(ev);
  389.  
  390.     fDropDelta = newPosition - box.TopLeft();
  391.     this->OffsetSelection(ev, fDropDelta);
  392.  
  393.     return TRUE;
  394. }
  395.  
  396. //----------------------------------------------------------------------------------------
  397. //    CDropCommand::SaveRedoState
  398. //----------------------------------------------------------------------------------------
  399.  
  400. void CDropCommand::SaveRedoState(Environment* ev)    // Override
  401. {
  402.     // Save proxies that were just dropped
  403.     FW_ASSERT(fDroppedContent == NULL);
  404.     fDroppedContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  405. }
  406.  
  407. //----------------------------------------------------------------------------------------
  408. //    CDropCommand::UndoIt
  409. //----------------------------------------------------------------------------------------
  410. void CDropCommand::UndoIt(Environment* ev)    // Override
  411. {
  412.     if (this->IsDragMoveInSameFrame(ev))    // it's a drag-move
  413.     {
  414.         // select dropped proxies and move them back to the original position
  415.         fContainerSelection->SelectContent(ev, fDroppedContent);
  416.         this->OffsetSelection(ev, -fDropDelta);
  417.         fContainerSelection->SelectionChanged(ev);    // need more than this for redraw???
  418.     }
  419.     else
  420.     {
  421.         // select dropped proxies and remove them from the document
  422.         fContainerSelection->SelectContent(ev, fDroppedContent);
  423.         fContainerSelection->ClearSelection(ev);
  424.     }
  425. }
  426.  
  427. //----------------------------------------------------------------------------------------
  428. //    CDropCommand::RedoIt
  429. //----------------------------------------------------------------------------------------
  430. void CDropCommand::RedoIt(Environment* ev)    // Override
  431. {
  432.     if (this->IsDragMoveInSameFrame(ev))    // it's a drag-move
  433.     {
  434.         // select dropped proxies and move them to new position
  435.         fContainerSelection->SelectContent(ev, fDroppedContent);
  436.         this->OffsetSelection(ev, fDropDelta);
  437.     }
  438.     else    // dropped proxies are copies
  439.     {
  440.         // add dropped proxies back into document
  441.         this->RestoreDroppedProxies(ev);
  442.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  443.     }
  444.     fContainerSelection->SelectionChanged(ev);
  445. }
  446.  
  447. //----------------------------------------------------------------------------------------
  448. //    CDropCommand::RestoreDroppedProxies
  449. //----------------------------------------------------------------------------------------
  450.  
  451. void CDropCommand::RestoreDroppedProxies(Environment* ev)
  452. {
  453.     // Add the dropped proxies back into the part
  454.     CContentProxyIterator ite(fDroppedContent);
  455.     for (CProxy* proxy = ite.First(); ite.IsNotComplete(); proxy = ite.Next())
  456.     {
  457.         fContainerPart->AttachProxy(ev, proxy);
  458.     }
  459.  
  460.     // Add the saved proxies to the selection
  461.     fContainerSelection->SelectContent(ev, fDroppedContent);
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. //    CDropCommand::OffsetSelection
  466. //----------------------------------------------------------------------------------------
  467.  
  468. void CDropCommand::OffsetSelection(Environment* ev, const FW_CPoint& delta)
  469. {
  470.     if (delta != FW_kZeroPoint)
  471.     {
  472.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  473.         fContainerSelection->OffsetSelection(ev, delta.x, delta.y);
  474.         GetPresentation(ev)->Invalidate(ev, fContainerSelection->GetUpdateShape(ev));
  475.     }
  476. }
  477.  
  478. //----------------------------------------------------------------------------------------
  479. //    CDropCommand::FreeRedoState
  480. //----------------------------------------------------------------------------------------
  481. void CDropCommand::FreeRedoState(Environment* ev)    // Override
  482. {
  483.     fDroppedContent->DeleteSavedProxies(ev);
  484. }
  485.  
  486. //========================================================================================
  487. // CInsertCommand
  488. //========================================================================================
  489.  
  490. //----------------------------------------------------------------------------------------
  491. //    CInsertCommand constructor
  492. //----------------------------------------------------------------------------------------
  493.  
  494. CInsertCommand::CInsertCommand(Environment* ev, 
  495.                                CContainerFrame* frame, 
  496.                                const FW_PFileSpecification& fileSpec, 
  497.                                CContainerSelection* selection,
  498.                                FW_Boolean canUndo) :
  499.     FW_CInsertCommand(ev, frame, fileSpec, canUndo),
  500.     fUndoContent(NULL),
  501.     fContainerSelection(selection)
  502. {
  503. }
  504.  
  505. //----------------------------------------------------------------------------------------
  506. //    CInsertCommand destructor
  507. //----------------------------------------------------------------------------------------
  508.  
  509. CInsertCommand::~CInsertCommand()
  510. {
  511.     delete fUndoContent;
  512. }
  513.  
  514. //----------------------------------------------------------------------------------------
  515. //    CInsertCommand::PreCommand
  516. //----------------------------------------------------------------------------------------
  517.  
  518. void CInsertCommand::PreCommand(Environment* ev)
  519. {
  520.     fContainerSelection->CloseSelection(ev);
  521. }
  522.  
  523. //----------------------------------------------------------------------------------------
  524. //    CInsertCommand::CommandDone
  525. //----------------------------------------------------------------------------------------
  526.  
  527. void CInsertCommand::CommandDone(Environment* ev)
  528. {
  529.     fContainerSelection->CenterSelection(ev, GetFrame(ev));
  530. }
  531.  
  532. //----------------------------------------------------------------------------------------
  533. //    CInsertCommand::SaveRedoState
  534. //----------------------------------------------------------------------------------------
  535.  
  536. void CInsertCommand::SaveRedoState(Environment* ev)
  537. {
  538.     FW_ASSERT(fUndoContent == NULL);
  539.     fUndoContent = FW_NEW(CUndoContent, (ev, fContainerSelection));
  540. }
  541.  
  542. //----------------------------------------------------------------------------------------
  543. //    CInsertCommand::FreeRedoState
  544. //----------------------------------------------------------------------------------------
  545.  
  546. void CInsertCommand::FreeRedoState(Environment* ev)
  547. {
  548.     fUndoContent->DeleteSavedProxies(ev);
  549. }
  550.  
  551. //----------------------------------------------------------------------------------------
  552. //    CInsertCommand::UndoIt
  553. //----------------------------------------------------------------------------------------
  554.  
  555. void CInsertCommand::UndoIt(Environment* ev)
  556. {
  557.     FW_CInsertCommand::UndoIt(ev);
  558.     fUndoContent->RemoveProxySelection(ev);
  559. }
  560.  
  561. //----------------------------------------------------------------------------------------
  562. //    CInsertCommand::RedoIt
  563. //----------------------------------------------------------------------------------------
  564.  
  565. void CInsertCommand::RedoIt(Environment* ev)
  566. {
  567.     FW_CInsertCommand::RedoIt(ev);
  568.     fUndoContent->RestoreProxySelection(ev);
  569. }
  570.  
  571. //========================================================================================
  572. // CResizeCommand
  573. //========================================================================================
  574.  
  575. //----------------------------------------------------------------------------------------
  576. //    CResizeCommand constructor
  577. //----------------------------------------------------------------------------------------
  578. CResizeCommand::CResizeCommand(Environment* ev, 
  579.                                          CContainerPart* part, 
  580.                                          FW_CFrame* frame,
  581.                                          CContainerSelection* selection,
  582.                                          const FW_CRect& srcRect,
  583.                                          const FW_CRect& dstRect) 
  584. :    FW_CCommand(ev, cResizeCommand, frame, FW_kCanUndo),
  585.     fContainerPart(part),
  586.     fContainerSelection(selection),
  587.     fSourceRect(srcRect),
  588.     fDestRect(dstRect),
  589.     fUpdateShape(NULL),
  590.     fChangedContent(NULL)
  591. {
  592.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoResizeMsg, kRedoResizeMsg);
  593.     FW_END_CONSTRUCTOR    
  594. }
  595.  
  596. //----------------------------------------------------------------------------------------
  597. //    CResizeCommand destructor
  598. //----------------------------------------------------------------------------------------
  599. CResizeCommand::~CResizeCommand()
  600. {
  601.     FW_START_DESTRUCTOR
  602.     delete fChangedContent;
  603.     
  604.     if (fUpdateShape)
  605.     {
  606.         FW_SOMEnvironment ev;
  607.         fUpdateShape->Release(ev);
  608.     }
  609.     fUpdateShape = NULL;
  610. }
  611.  
  612. //----------------------------------------------------------------------------------------
  613. //    CResizeCommand::DoIt
  614. //----------------------------------------------------------------------------------------
  615. void CResizeCommand::DoIt(Environment* ev)    // Override
  616. {
  617.     // Copy selected proxy pointers to our content object
  618.     FW_ASSERT(fChangedContent == NULL);
  619.     fChangedContent = FW_NEW(CBaseContent, (ev, fContainerSelection->GetSelectionContent(ev)));
  620.  
  621.     FW_ASSERT(fUpdateShape == NULL);
  622.     fUpdateShape = fChangedContent->CalcUpdateShape(ev);
  623.  
  624.     this->ResizeProxies(ev, fSourceRect, fDestRect);
  625.  
  626.     {
  627.         FW_CAcquiredODShape tempShape = fChangedContent->CalcUpdateShape(ev);
  628.         fUpdateShape->Union(ev, tempShape);
  629.     }
  630.  
  631.     this->Redraw(ev, kODDone);
  632. }
  633.  
  634. //----------------------------------------------------------------------------------------
  635. //    CResizeCommand::UndoIt
  636. //----------------------------------------------------------------------------------------
  637. void CResizeCommand::UndoIt(Environment* ev)    // Override
  638. {
  639.     this->ResizeProxies(ev, fDestRect, fSourceRect);
  640.     this->Redraw(ev, kODUndone);
  641. }
  642.  
  643. //----------------------------------------------------------------------------------------
  644. //    CResizeCommand::RedoIt
  645. //----------------------------------------------------------------------------------------
  646. void CResizeCommand::RedoIt(Environment* ev)    // Override
  647. {
  648.     this->ResizeProxies(ev, fSourceRect, fDestRect);
  649.     this->Redraw(ev, kODRedone);
  650. }
  651.  
  652. //----------------------------------------------------------------------------------------
  653. //    CResizeCommand::ResizeProxies
  654. //----------------------------------------------------------------------------------------
  655. void CResizeCommand::ResizeProxies(Environment* ev, const FW_CRect& srcRect, const FW_CRect& dstRect)
  656. {
  657.     //--- Resize each proxy ---
  658.     CContentProxyIterator it(fChangedContent);
  659.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  660.     {
  661.         proxy->ResizeProxy(ev, srcRect, dstRect);
  662.     }
  663. }
  664.  
  665. //----------------------------------------------------------------------------------------
  666. //    CResizeCommand::Redraw
  667. //----------------------------------------------------------------------------------------
  668. void CResizeCommand::Redraw(Environment* ev, ODDoneState doneState)
  669. {
  670. FW_UNUSED(doneState);
  671.     FW_CPresentation* presentation = fContainerPart->GetMainPresentation();
  672.     presentation->Invalidate(ev, fUpdateShape);
  673.     
  674.     FW_CFacetClipper facetClipper;
  675.     facetClipper.Clip(ev, presentation, fUpdateShape);
  676.  
  677.     // Select the resized proxies
  678.     fContainerSelection->SelectContent(ev, fChangedContent);
  679.     fContainerSelection->SelectionChanged(ev);    // Notify everybody
  680. }
  681.  
  682. //========================================================================================
  683. // CViewAsCommand
  684. //========================================================================================
  685.  
  686. //----------------------------------------------------------------------------------------
  687. //    CViewAsCommand constructor
  688. //----------------------------------------------------------------------------------------
  689. CViewAsCommand::CViewAsCommand(Environment* ev, 
  690.                                 CContainerPart* part,
  691.                                 FW_CFrame* frame,
  692.                                 CContainerSelection* selection,
  693.                                 ODTypeToken newViewAs) 
  694. :    FW_CCommand(ev, cViewAsCommand, frame, FW_kCanUndo),
  695.     fContainerPart(part),
  696.     fContainerSelection(selection),
  697.     fNewViewAs(newViewAs),
  698.     fOldViewAs(NULL),
  699.     fChangedContent(NULL),
  700.     fUpdateShape(NULL)
  701. {
  702.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoEmbedAsMsg, kRedoEmbedAsMsg);
  703.     FW_END_CONSTRUCTOR    
  704. }
  705.  
  706. //----------------------------------------------------------------------------------------
  707. //    CViewAsCommand destructor
  708. //----------------------------------------------------------------------------------------
  709.  
  710. CViewAsCommand::~CViewAsCommand()
  711. {
  712.     FW_START_DESTRUCTOR
  713.     
  714.     if (fOldViewAs)
  715.         FW_CMemoryManager::FreeBlock(fOldViewAs);
  716.     
  717.     delete fChangedContent;
  718.  
  719.     if (fUpdateShape)
  720.     {
  721.         FW_SOMEnvironment ev;
  722.         fUpdateShape->Release(ev);
  723.     }
  724.     fUpdateShape = NULL;
  725. }
  726.  
  727. //----------------------------------------------------------------------------------------
  728. //    CViewAsCommand::DoIt
  729. //----------------------------------------------------------------------------------------
  730.  
  731. void CViewAsCommand::DoIt(Environment* ev)    // Override
  732. {
  733.     // Copy selected proxy pointers to our content object
  734.     FW_ASSERT(fChangedContent == NULL);
  735.     fChangedContent = FW_NEW(CBaseContent, (ev, fContainerSelection->GetSelectionContent(ev)));
  736.  
  737.     fOldViewAs = (ODTypeToken*)FW_CMemoryManager::AllocateBlock(fContainerSelection->Count() * sizeof(ODTypeToken));
  738.     
  739.     short n = 0;
  740.     CContentProxyIterator it(fChangedContent);
  741.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  742.     {
  743.         fOldViewAs[n] = proxy->GetViewAs();
  744.         n++;
  745.     }
  746.     
  747.     FW_ASSERT(fUpdateShape == NULL);
  748.     fUpdateShape = fChangedContent->CalcUpdateShape(ev);
  749.  
  750.     this->ChangeEmbeddedViewAs(ev, FALSE);
  751.  
  752.     {
  753.         FW_CAcquiredODShape tempShape = fChangedContent->CalcUpdateShape(ev);
  754.         fUpdateShape->Union(ev, tempShape);
  755.     }
  756.  
  757.     this->Redraw(ev);
  758. }
  759.  
  760. //----------------------------------------------------------------------------------------
  761. //    CViewAsCommand::UndoIt
  762. //----------------------------------------------------------------------------------------
  763.  
  764. void CViewAsCommand::UndoIt(Environment* ev)    // Override
  765. {
  766.     this->ChangeEmbeddedViewAs(ev, TRUE);
  767.     this->Redraw(ev);
  768. }
  769.  
  770. //----------------------------------------------------------------------------------------
  771. //    CViewAsCommand::RedoIt
  772. //----------------------------------------------------------------------------------------
  773.  
  774. void CViewAsCommand::RedoIt(Environment* ev)    // Override
  775. {
  776.     this->ChangeEmbeddedViewAs(ev, FALSE);
  777.     this->Redraw(ev);
  778. }
  779.  
  780. //----------------------------------------------------------------------------------------
  781. //    CViewAsCommand::ChangeEmbeddedViewAs
  782. //----------------------------------------------------------------------------------------
  783.  
  784. void CViewAsCommand::ChangeEmbeddedViewAs(Environment* ev, FW_Boolean undo)
  785. {
  786.     short n = 0;
  787.     //--- Resize each proxy ---
  788.     CContentProxyIterator it(fChangedContent);
  789.     for (CProxy* proxy = it.First(); it.IsNotComplete(); proxy = it.Next())
  790.     {
  791.         proxy->ChangeViewAs(ev, undo ? fOldViewAs[n] : fNewViewAs);
  792.         n++;
  793.     }
  794. }
  795.  
  796. //----------------------------------------------------------------------------------------
  797. //    CViewAsCommand::Redraw
  798. //----------------------------------------------------------------------------------------
  799.  
  800. void CViewAsCommand::Redraw(Environment* ev)
  801. {
  802.     FW_CPresentation* presentation = fContainerPart->GetMainPresentation();
  803.     presentation->Invalidate(ev, fUpdateShape);
  804.     
  805.     FW_CFacetClipper facetClipper;
  806.     facetClipper.Clip(ev, presentation, fUpdateShape);
  807.  
  808.     // Select the resized proxies
  809.     fContainerSelection->SelectContent(ev, fChangedContent);
  810.     fContainerSelection->SelectionChanged(ev);    // Notify everybody
  811. }
  812.  
  813. //========================================================================================
  814. // class CSetBackgroundColorCommand
  815. //========================================================================================
  816.  
  817. //----------------------------------------------------------------------------------------
  818. //    CSetBackgroundColorCommand::CSetBackgroundColorCommand
  819. //----------------------------------------------------------------------------------------
  820.  
  821. CSetBackgroundColorCommand::CSetBackgroundColorCommand(Environment* ev,
  822.                                                     CContainerPart* part,
  823.                                                     FW_CColor& newBackgroundColor) :
  824.     FW_CCommand(ev, cSetBackgroundColor, part->GetLastActiveFrame(ev), TRUE),
  825.     fContainerPart(part),
  826.     fOldColor(),
  827.     fNewColor(newBackgroundColor)
  828. {
  829.     fOldColor = fContainerPart->GetBackgroundColor();
  830.     SetMenuStringsFromResource(ev, kUndoStrings, kUndoSetBackColorMsg, kRedoSetBackColorMsg);
  831.     
  832.     FW_END_CONSTRUCTOR
  833. }
  834.  
  835. //----------------------------------------------------------------------------------------
  836. //    CSetBackgroundColorCommand::~CSetBackgroundColorCommand
  837. //----------------------------------------------------------------------------------------
  838.  
  839. CSetBackgroundColorCommand::~CSetBackgroundColorCommand()
  840. {
  841.     FW_START_DESTRUCTOR
  842. }
  843.  
  844. //----------------------------------------------------------------------------------------
  845. //    CSetBackgroundColorCommand::DoIt
  846. //----------------------------------------------------------------------------------------
  847.  
  848. void CSetBackgroundColorCommand::DoIt(Environment* ev)
  849. {
  850.     fContainerPart->SetBackgroundColor(ev, fNewColor);
  851. }
  852.  
  853. //----------------------------------------------------------------------------------------
  854. //    CSetBackgroundColorCommand::UndoIt
  855. //----------------------------------------------------------------------------------------
  856.  
  857. void CSetBackgroundColorCommand::UndoIt(Environment* ev)
  858. {
  859.     fContainerPart->SetBackgroundColor(ev, fOldColor);
  860. }
  861.  
  862. //----------------------------------------------------------------------------------------
  863. //    CSetBackgroundColorCommand::RedoIt
  864. //----------------------------------------------------------------------------------------
  865.  
  866. void CSetBackgroundColorCommand::RedoIt(Environment* ev)
  867. {
  868.     fContainerPart->SetBackgroundColor(ev, fNewColor);
  869. }
  870.