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 / Table / Sources / Commands.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  24.0 KB  |  736 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. #ifndef COMMANDS_H
  11. #include "Commands.h"
  12. #endif
  13.  
  14. #ifndef FRAME_H
  15. #include "Frame.h"
  16. #endif
  17.  
  18. #ifndef PART_H
  19. #include "Part.h"
  20. #endif
  21.  
  22. #ifndef SELECTION_H
  23. #include "Selection.h"
  24. #endif
  25.  
  26. #ifndef PROXY_H
  27. #include "Proxy.h"
  28. #endif
  29.  
  30. #ifndef LINKING_H
  31. #include "Linking.h"
  32. #endif
  33.  
  34. #ifndef CONTENT_H
  35. #include "Content.h"
  36. #endif
  37.  
  38. // ----- Framework Includes -----
  39.  
  40. #ifndef FWPART_H
  41. #include "FWPart.h"
  42. #endif
  43.  
  44. #ifndef FWFRAME_H
  45. #include "FWFrame.h"
  46. #endif
  47.  
  48. #ifndef FWSELECT_H
  49. #include "FWSelect.h"
  50. #endif
  51.  
  52. #ifndef FWBARRAY_H
  53. #include "FWBArray.h"
  54. #endif
  55.  
  56. #ifndef FWFRMING_H
  57. #include "FWFrming.h"
  58. #endif
  59.  
  60. #ifndef FWLNKMGR_H
  61. #include "FWLnkMgr.h"
  62. #endif
  63.  
  64. // ----- OpenDoc Includes -----
  65.  
  66. #ifndef SOM_Module_OpenDoc_Commands_defined
  67. #include <CmdDefs.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODLinkSource_xh
  71. #include <LinkSrc.xh>
  72. #endif
  73.  
  74. #ifndef SOM_ODLinkSpec_xh
  75. #include <LinkSpec.xh>
  76. #endif
  77.  
  78. //========================================================================================
  79. //    Runtime Info
  80. //========================================================================================
  81.  
  82. #ifdef FW_BUILD_MAC
  83. #pragma segment odfTable
  84. #endif
  85.  
  86. FW_DEFINE_AUTO(CCellDragCommand)
  87. FW_DEFINE_AUTO(CCellDropCommand)
  88. FW_DEFINE_AUTO(CTableEditCommand)
  89. FW_DEFINE_AUTO(CTableInsertCommand)
  90. FW_DEFINE_AUTO(CBreakLinkSourceCommand)
  91. FW_DEFINE_AUTO(CBreakLinkCommand)
  92.  
  93. //========================================================================================
  94. //    class CCellDragCommand
  95. //========================================================================================
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    CCellDragCommand constructor
  99. //----------------------------------------------------------------------------------------
  100.  
  101. CCellDragCommand::CCellDragCommand(    Environment* ev,
  102.                                     CTableContent* tableContent,
  103.                                     FW_CFrame* frame,
  104.                                     CTableSelection* selection) : 
  105.     FW_CDragCommand(ev, frame, FW_kCanUndo),
  106.     fTableContent(tableContent),
  107.     fTableSelection(selection),
  108.     fSavedProxy(NULL)
  109. {
  110.     fDragCell = selection->GetSelectedCell();
  111. }
  112.  
  113. //----------------------------------------------------------------------------------------
  114. //    CCellDragCommand destructor
  115. //----------------------------------------------------------------------------------------
  116.  
  117. CCellDragCommand::~CCellDragCommand()
  118. {
  119. }
  120.  
  121. //---------------------------------------------------------------------------------------
  122. //    CCellDragCommand::UndoIt
  123. //---------------------------------------------------------------------------------------
  124. void CCellDragCommand::UndoIt(Environment* ev)
  125. {
  126.     FW_ASSERT(fSavedProxy);
  127.  
  128.     // Restore saved proxy to the table
  129.     fSavedProxy->AttachEmbeddedFrames(ev);
  130.     fTableContent->AddProxy(fSavedProxy);
  131.     fTableSelection->SelectProxy(ev, fSavedProxy);
  132. }
  133.  
  134. //---------------------------------------------------------------------------------------
  135. //    CCellDragCommand::RedoIt
  136. //---------------------------------------------------------------------------------------
  137. void CCellDragCommand::RedoIt(Environment* ev)
  138. {
  139.     // Remove saved proxy, again
  140.     fTableSelection->SelectProxy(ev, fSavedProxy);
  141.     fTableSelection->ClearSelection(ev);
  142. }
  143.  
  144. //---------------------------------------------------------------------------------------
  145. //    CCellDragCommand::SaveUndoState
  146. //---------------------------------------------------------------------------------------
  147. void CCellDragCommand::SaveUndoState(Environment* ev)
  148. {
  149.     // Save the proxy for the part that was dragged
  150.     fSavedProxy = fTableContent->CellToProxy(fDragCell);
  151. }
  152.  
  153. //---------------------------------------------------------------------------------------
  154. //    CCellDragCommand::FreeUndoState
  155. //---------------------------------------------------------------------------------------
  156. void CCellDragCommand::FreeUndoState(Environment* ev)
  157. {
  158.     FW_ASSERT(fSavedProxy);
  159.     
  160.     delete fSavedProxy;
  161.     fSavedProxy = NULL;
  162. }
  163.  
  164. //========================================================================================
  165. //    class CCellDropCommand
  166. //========================================================================================
  167.  
  168. //----------------------------------------------------------------------------------------
  169. //    CCellDropCommand constructor
  170. //----------------------------------------------------------------------------------------
  171.  
  172. CCellDropCommand::CCellDropCommand(    Environment* ev,
  173.                                     CTablePart* itsPart,
  174.                                     CTableContent* tableContent,
  175.                                     CTableFrame* frame,
  176.                                     ODDragItemIterator* dropInfo, 
  177.                                     ODFacet* odFacet,
  178.                                     const FW_CPoint& dropPoint,
  179.                                     const CCell& dropCell,
  180.                                     const CCell& draggedCell) : 
  181.     FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
  182.     fTablePart(itsPart),
  183.     fTableContent(tableContent),
  184.     fTableFrame(frame),
  185.     fDropCell(dropCell),
  186.     fDraggedCell(draggedCell),
  187.     fSavedProxy(NULL)
  188. {
  189.     // If this was a Cmd-drag, set the selection to the dropCell for DoDroppedPasteAs
  190.     ODDragAndDrop* drag = itsPart->GetSession(ev)->GetDragAndDrop(ev);
  191.     unsigned long attributes = drag->GetDragAttributes(ev);
  192.     if (attributes & kODDropIsPasteAs)
  193.         fTableFrame->SelectCell(ev, fDropCell);
  194.  
  195.     FW_END_CONSTRUCTOR
  196. }
  197.  
  198. //----------------------------------------------------------------------------------------
  199. //    CCellDropCommand destructor
  200. //----------------------------------------------------------------------------------------
  201.  
  202. CCellDropCommand::~CCellDropCommand()
  203. {
  204. }
  205.  
  206. //----------------------------------------------------------------------------------------
  207. // CCellDropCommand::DoDrop
  208. //----------------------------------------------------------------------------------------
  209.  
  210. FW_Boolean CCellDropCommand::DoDrop(Environment* ev, 
  211.                                     ODStorageUnit* dropSU, 
  212.                                     const FW_CPoint& mouseDownOffset,
  213.                                     const FW_CPoint& dropPoint,
  214.                                     FW_Boolean isDropMove,
  215.                                     short itemNumber)
  216. {
  217.     if (itemNumber > 1)        // can only drop one item in a cell
  218.         return false;
  219.  
  220.     fTableFrame->SelectCell(ev, fDropCell);
  221.     
  222.     return FW_CDropCommand::DoDrop(ev, dropSU, mouseDownOffset, dropPoint, isDropMove, itemNumber);
  223. }
  224.  
  225. //----------------------------------------------------------------------------------------
  226. // CCellDropCommand::DoDroppedInSameFrame
  227. //----------------------------------------------------------------------------------------
  228.  
  229. FW_Boolean CCellDropCommand::DoDroppedInSameFrame(Environment* ev, 
  230.                                                   ODStorageUnit* dropSU, 
  231.                                                   const FW_CPoint& mouseDownOffset, 
  232.                                                   const FW_CPoint& dropPoint)
  233. {
  234.     FW_UNUSED(dropSU);
  235.     FW_UNUSED(mouseDownOffset);
  236.     FW_UNUSED(dropPoint);
  237.     
  238.     FW_ASSERT(fDropCell != fDraggedCell);
  239.         
  240.     // Move the frame's cell
  241.     
  242.     CTableProxy* proxy = fTableContent->CellToProxy(fDraggedCell);
  243.     FW_ASSERT(proxy);
  244.  
  245.     fTableFrame->MoveProxy(ev, proxy, fDropCell);
  246.     fTablePart->ProxyMoved(ev, fDraggedCell, fDropCell);
  247.  
  248.     return TRUE;
  249. }
  250.  
  251. //---------------------------------------------------------------------------------------
  252. //    CCellDropCommand::UndoIt
  253. //---------------------------------------------------------------------------------------
  254. void CCellDropCommand::UndoIt(Environment* ev)
  255. {
  256.     FW_ASSERT(fSavedProxy);
  257.  
  258.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  259.     {
  260.         // move the dropped part back to the cell it came from
  261.         fTableFrame->MoveProxy(ev, fSavedProxy, fDraggedCell);
  262.     }
  263.     else    // part was dropped here from outside
  264.     {
  265.         // remove the dropped cell from the table
  266.         CTableSelection* selection = fTableFrame->GetSelection(ev);
  267.         selection->SelectProxy(ev, fSavedProxy);
  268.         selection->ClearSelection(ev);
  269.     }
  270. }
  271.  
  272. //---------------------------------------------------------------------------------------
  273. //    CCellDropCommand::RedoIt
  274. //---------------------------------------------------------------------------------------
  275. void CCellDropCommand::RedoIt(Environment* ev)
  276. {
  277.     if (this->IsDragMoveInSameFrame(ev))    // simple move from one cell to another
  278.     {
  279.         // move the dropped part to the cell it was dropped in
  280.         fTableFrame->MoveProxy(ev, fSavedProxy, fDropCell);
  281.     }
  282.     else    // part was dropped here from outside
  283.     {
  284.         // re-drop the cell
  285.         fSavedProxy->AttachEmbeddedFrames(ev);
  286.         fTableContent->AddProxy(fSavedProxy);
  287.         fTableFrame->SelectCell(ev, fDropCell);
  288.     }
  289. }
  290.  
  291. //---------------------------------------------------------------------------------------
  292. //    CCellDropCommand::SaveRedoState
  293. //---------------------------------------------------------------------------------------
  294. void CCellDropCommand::SaveRedoState(Environment* ev)
  295. {
  296.     // Save the proxy for the part that was just dropped
  297.     fSavedProxy = fTableContent->CellToProxy(fDropCell);
  298. }
  299.  
  300. //---------------------------------------------------------------------------------------
  301. //    CCellDropCommand::FreeRedoState
  302. //---------------------------------------------------------------------------------------
  303. void CCellDropCommand::FreeRedoState(Environment* ev)
  304. {
  305.     // Delete the saved proxy
  306.     delete fSavedProxy;
  307. }
  308.  
  309. //========================================================================================
  310. // CTableEditCommand class
  311. //========================================================================================
  312.  
  313. //---------------------------------------------------------------------------------------
  314. // CTableEditCommand constructor
  315. //---------------------------------------------------------------------------------------
  316. CTableEditCommand::CTableEditCommand(Environment* ev,
  317.                                      ODCommandID id,
  318.                                      CTablePart* itsPart, 
  319.                                      CTableContent* tableContent,
  320.                                      FW_CFrame* frame, 
  321.                                      CTableSelection* selection) :
  322.     FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
  323.     fTablePart(itsPart),
  324.     fTableContent(tableContent),
  325.     fTableSelection(selection),
  326.     fSavedProxy(NULL)
  327. {
  328. }
  329.  
  330. //---------------------------------------------------------------------------------------
  331. // CTableEditCommand destructor
  332. //---------------------------------------------------------------------------------------
  333. CTableEditCommand::~CTableEditCommand()
  334. {
  335. }
  336.  
  337. //---------------------------------------------------------------------------------------
  338. //    CTableEditCommand::UndoIt
  339. //---------------------------------------------------------------------------------------
  340. void CTableEditCommand::UndoIt(Environment* ev)
  341. {
  342.     FW_CClipboardCommand::UndoIt(ev);    // call inherited
  343.  
  344.     switch (GetCommandID(ev))
  345.     {
  346.         case kODCommandCut:
  347.         case kODCommandClear:
  348.             this->RestoreSelection(ev);
  349.             break;
  350.  
  351.         case kODCommandPaste:
  352.             this->RemoveSelection(ev);
  353.             break;
  354.  
  355.         case kODCommandPasteAs:
  356.             this->UndoPasteAs(ev);
  357.     }    
  358. }
  359.  
  360. //---------------------------------------------------------------------------------------
  361. //    CTableEditCommand::RedoIt
  362. //---------------------------------------------------------------------------------------
  363. void CTableEditCommand::RedoIt(Environment* ev)    // Override
  364. {
  365.     FW_CClipboardCommand::RedoIt(ev);    // call inherited
  366.  
  367.     switch (GetCommandID(ev))
  368.     {
  369.         case kODCommandCut:
  370.         case kODCommandClear:
  371.             this->RemoveSelection(ev);
  372.             break;
  373.  
  374.         case kODCommandPaste:
  375.             this->RestoreSelection(ev);
  376.             break;
  377.  
  378.         case kODCommandPasteAs:
  379.             this->RedoPasteAs(ev);
  380.             break;    
  381.     }    
  382. }
  383.  
  384. //----------------------------------------------------------------------------------------
  385. //    CTableEditCommand::SaveUndoState
  386. //----------------------------------------------------------------------------------------
  387. void CTableEditCommand::SaveUndoState(Environment* ev)    // Override
  388. {
  389.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  390.         this->SaveSelection(ev);
  391. }
  392.  
  393. //----------------------------------------------------------------------------------------
  394. //    CTableEditCommand::FreeUndoState (doneState == kODDone)
  395. //----------------------------------------------------------------------------------------
  396. void CTableEditCommand::FreeUndoState(Environment* ev)    // Override
  397. {
  398.     if (GetCommandID(ev) == kODCommandCut || GetCommandID(ev) == kODCommandClear)
  399.         this->DeleteSavedProxy(ev);
  400. }
  401.  
  402. //----------------------------------------------------------------------------------------
  403. //    CTableEditCommand::SaveRedoState
  404. //----------------------------------------------------------------------------------------
  405. void CTableEditCommand::SaveRedoState(Environment* ev)    // Override
  406. {
  407.     if (GetCommandID(ev) == kODCommandPaste)
  408.     {
  409.         this->SaveSelection(ev);
  410.     }
  411.     else if (GetCommandID(ev) == kODCommandPasteAs)
  412.     {
  413.         fPasteAsCell = fTableSelection->GetSelectedCell();
  414.         // If a link was created don't save the proxy
  415.         if (!WasLinkCreated(ev))
  416.             this->SaveSelection(ev);
  417.     }
  418. }
  419.  
  420. //----------------------------------------------------------------------------------------
  421. //    CTableEditCommand::WasLinkCreated
  422. //----------------------------------------------------------------------------------------
  423. FW_Boolean CTableEditCommand::WasLinkCreated(Environment* ev)
  424. {
  425.     return (GetNewLink(ev) != NULL);
  426. }
  427.  
  428. //----------------------------------------------------------------------------------------
  429. //    CTableEditCommand::FreeRedoState (doneState == kODUndone)
  430. //----------------------------------------------------------------------------------------
  431. void CTableEditCommand::FreeRedoState(Environment* ev)    // Override
  432. {
  433.     if (GetCommandID(ev) == kODCommandPaste)
  434.     {
  435.         this->DeleteSavedProxy(ev);
  436.     }
  437.     else if (GetCommandID(ev) == kODCommandPasteAs)
  438.     {
  439.         if (!WasLinkCreated(ev))
  440.             this->DeleteSavedProxy(ev);
  441.     }
  442. }
  443.  
  444. //---------------------------------------------------------------------------------------
  445. //    CTableEditCommand::SaveSelection
  446. //---------------------------------------------------------------------------------------
  447. void CTableEditCommand::SaveSelection(Environment* ev)
  448. {
  449.     //--- The selection is a single embedded frame ---
  450.     CCell cell = fTableSelection->GetSelectedCell();            // selected cell
  451.     fSavedProxy = fTableContent->CellToProxy(cell);
  452. }
  453.  
  454. //---------------------------------------------------------------------------------------
  455. //    CTableEditCommand::RestoreSelection
  456. //---------------------------------------------------------------------------------------
  457.  
  458. void CTableEditCommand::RestoreSelection(Environment* ev)
  459. {
  460.     // Re-attach the proxy's frames
  461.     fSavedProxy->AttachEmbeddedFrames(ev);
  462.  
  463.     // Add the saved proxy back into the table part
  464.     fTableContent->AddProxy(fSavedProxy);
  465.  
  466.     // Select it
  467.     fTableSelection->CloseSelection(ev);
  468.     fTableSelection->SelectProxy(ev, fSavedProxy);
  469.     fTableSelection->InvalidateSelection(ev);
  470.  
  471.     // Notify part
  472.     fTablePart->PartChanged(ev);
  473. }
  474.  
  475. //---------------------------------------------------------------------------------------
  476. //    CTableEditCommand::RemoveSelection
  477. //---------------------------------------------------------------------------------------
  478. void CTableEditCommand::RemoveSelection(Environment* ev)
  479. {
  480.     // Make sure the saved proxy is selected
  481.     fTableSelection->CloseSelection(ev);
  482.     fTableSelection->SelectProxy(ev, fSavedProxy);
  483.  
  484.     // Save the selected proxy
  485.     this->SaveSelection(ev);
  486.     
  487.     // Clear the selection, which includes detaching the proxy frames.
  488.     fTableSelection->ClearSelection(ev);
  489.  
  490.     // Notify part
  491.     fTablePart->PartChanged(ev);
  492. }
  493.  
  494. //---------------------------------------------------------------------------------------
  495. //    CTableEditCommand::DeleteSavedProxy
  496. //---------------------------------------------------------------------------------------
  497. void CTableEditCommand::DeleteSavedProxy(Environment* ev)
  498. {
  499.     FW_ASSERT(fSavedProxy);
  500.  
  501.     delete fSavedProxy;
  502.     fSavedProxy = NULL;
  503. }
  504.  
  505. //---------------------------------------------------------------------------------------
  506. // CTableEditCommand::UndoPasteAs
  507. //---------------------------------------------------------------------------------------
  508. void CTableEditCommand::UndoPasteAs(Environment* ev)
  509. {
  510.     //--- Break the link, if there is one ---
  511.     if (WasLinkCreated(ev))
  512.     {
  513.         //--- Remove the proxy frame ---
  514.         CTableProxy* proxy = fTableContent->CellToProxy(fPasteAsCell);
  515.         proxy->RemoveEmbeddedFrames(ev);
  516.         fTableContent->RemoveProxy(proxy);
  517.         delete proxy;
  518.     }
  519.     else    // just like a normal Paste command
  520.         this->RemoveSelection(ev);
  521.  
  522.     //--- Force redraw ---
  523.     GetFrame(ev)->GetPresentation(ev)->Invalidate(ev);
  524.  
  525.     // Notify part
  526.     fTablePart->PartChanged(ev);
  527. }
  528.  
  529. //---------------------------------------------------------------------------------------
  530. // CTableEditCommand::RedoPasteAs
  531. //---------------------------------------------------------------------------------------
  532. void CTableEditCommand::RedoPasteAs(Environment* ev)
  533. {
  534.     if (!WasLinkCreated(ev))
  535.         this->RestoreSelection(ev);
  536.  
  537.     // Notify part
  538.     fTablePart->PartChanged(ev);
  539. }
  540.  
  541. //========================================================================================
  542. // CTableInsertCommand class
  543. //========================================================================================
  544.  
  545. //---------------------------------------------------------------------------------------
  546. // CTableInsertCommand constructor
  547. //---------------------------------------------------------------------------------------
  548. CTableInsertCommand::CTableInsertCommand(Environment* ev,
  549.                                          FW_CEmbeddingFrame* frame,
  550.                                          const FW_PFileSpecification& fileSpec,
  551.                                          CTablePart* itsPart,
  552.                                          const CCell& insertCell)
  553. :    FW_CInsertCommand(ev, frame, fileSpec, FW_kCanUndo),
  554.     fTablePart(itsPart),
  555.     fTableContent(NULL),
  556.     fInsertedProxy(NULL),
  557.     fInsertCell(insertCell)
  558. {
  559.     fTableContent = itsPart->GetTableContent(ev);
  560. }
  561.  
  562. //---------------------------------------------------------------------------------------
  563. // CTableInsertCommand destructor
  564. //---------------------------------------------------------------------------------------
  565. CTableInsertCommand::~CTableInsertCommand()
  566. {
  567. }
  568.  
  569. //---------------------------------------------------------------------------------------
  570. //    CTableInsertCommand::UndoIt
  571. //---------------------------------------------------------------------------------------
  572. void CTableInsertCommand::UndoIt(Environment* ev)
  573. {
  574.     // remove the inserted part
  575.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  576.     selection->Select(ev, fInsertCell);
  577.     selection->ClearSelection(ev);
  578. }
  579.  
  580. //---------------------------------------------------------------------------------------
  581. //    CTableInsertCommand::RedoIt
  582. //---------------------------------------------------------------------------------------
  583. void CTableInsertCommand::RedoIt(Environment* ev)
  584. {
  585.     // re-insert the part
  586.     fInsertedProxy->AttachEmbeddedFrames(ev);
  587.     fTableContent->AddProxy(fInsertedProxy);
  588.     CTableSelection* selection = fTablePart->GetTableSelection(ev);
  589.     selection->Select(ev, fInsertCell);
  590. }
  591.  
  592. //---------------------------------------------------------------------------------------
  593. //    CTableInsertCommand::CommitUndone
  594. //---------------------------------------------------------------------------------------
  595. void CTableInsertCommand::CommitUndone(Environment* ev)
  596. {
  597.     delete fInsertedProxy;
  598. }
  599.  
  600. //---------------------------------------------------------------------------------------
  601. //    CTableInsertCommand::SaveRedoState
  602. //---------------------------------------------------------------------------------------
  603. void CTableInsertCommand::SaveRedoState(Environment* ev)
  604. {
  605.     fInsertedProxy = fTableContent->CellToProxy(fInsertCell);
  606. }
  607.  
  608. //========================================================================================
  609. // Constants for CBreakLinkSourceCommand and CBreakLinkCommand
  610. //========================================================================================
  611.  
  612. const ODCommandID kBreakLinkSourceID = 12345;
  613. const ODCommandID kBreakLinkID = 56789;
  614.  
  615. //========================================================================================
  616. // CBreakLinkSourceCommand class
  617. //========================================================================================
  618.  
  619. //---------------------------------------------------------------------------------------
  620. // CBreakLinkSourceCommand constructor
  621. //---------------------------------------------------------------------------------------
  622. CBreakLinkSourceCommand::CBreakLinkSourceCommand(Environment* ev,
  623.                                                  FW_CFrame* frame, 
  624.                                                  CTableLinkSource* linkSource) :
  625.     FW_CCommand(ev, kBreakLinkSourceID, frame, FW_kCanUndo),
  626.     fLinkSource(linkSource)
  627. {
  628.     this->SetMenuStrings(ev, "Restore Link", "Break Link");
  629. }
  630.  
  631. //---------------------------------------------------------------------------------------
  632. // CBreakLinkSourceCommand destructor
  633. //---------------------------------------------------------------------------------------
  634. CBreakLinkSourceCommand::~CBreakLinkSourceCommand()
  635. {
  636. }
  637.  
  638. //---------------------------------------------------------------------------------------
  639. // CBreakLinkSourceCommand::DoIt
  640. //---------------------------------------------------------------------------------------
  641. void CBreakLinkSourceCommand::DoIt(Environment* ev)
  642. {
  643.     //-- Break the link --
  644.     GetPart(ev)->GetLinkManager(ev)->BreakSourceLink(ev, fLinkSource);
  645.     GetPart(ev)->Changed(ev);
  646. }
  647.  
  648. //---------------------------------------------------------------------------------------
  649. //    CBreakLinkSourceCommand::UndoIt
  650. //---------------------------------------------------------------------------------------
  651. void CBreakLinkSourceCommand::UndoIt(Environment* ev)
  652. {
  653.     //-- Restore the broken link --
  654.     GetPart(ev)->GetLinkManager(ev)->RestoreSourceLink(ev, fLinkSource);
  655.     GetPart(ev)->Changed(ev);
  656. }
  657.  
  658. //---------------------------------------------------------------------------------------
  659. //    CBreakLinkSourceCommand::RedoIt
  660. //---------------------------------------------------------------------------------------
  661. void CBreakLinkSourceCommand::RedoIt(Environment* ev)
  662. {
  663.     this->DoIt(ev);    // just DoIt
  664. }
  665.  
  666. //---------------------------------------------------------------------------------------
  667. //    CBreakLinkSourceCommand::CommitDone
  668. //---------------------------------------------------------------------------------------
  669. void CBreakLinkSourceCommand::CommitDone(Environment* ev)
  670. {
  671.     // Delete the saved link source only if the command was not undone
  672.     delete fLinkSource;
  673. }
  674.  
  675. //========================================================================================
  676. // CBreakLinkCommand class
  677. //========================================================================================
  678.  
  679. //---------------------------------------------------------------------------------------
  680. // CBreakLinkCommand constructor
  681. //---------------------------------------------------------------------------------------
  682. CBreakLinkCommand::CBreakLinkCommand(Environment* ev,
  683.                                      FW_CFrame* frame, 
  684.                                      CTableLink* linkDestination) :
  685.     FW_CCommand(ev, kBreakLinkID, frame, FW_kCanUndo),
  686.     fLink(linkDestination)
  687. {
  688.     this->SetMenuStrings(ev, "Restore Link", "Break Link");
  689. }
  690.  
  691. //---------------------------------------------------------------------------------------
  692. // CBreakLinkCommand destructor
  693. //---------------------------------------------------------------------------------------
  694. CBreakLinkCommand::~CBreakLinkCommand()
  695. {
  696. }
  697.  
  698. //---------------------------------------------------------------------------------------
  699. // CBreakLinkCommand::DoIt
  700. //---------------------------------------------------------------------------------------
  701. void CBreakLinkCommand::DoIt(Environment* ev)
  702. {
  703.     //-- Break the link --
  704.     GetPart(ev)->GetLinkManager(ev)->BreakDestinationLink(ev, fLink);
  705.     GetPart(ev)->Changed(ev);
  706. }
  707.  
  708. //---------------------------------------------------------------------------------------
  709. // CBreakLinkCommand::UndoIt
  710. //---------------------------------------------------------------------------------------
  711. void CBreakLinkCommand::UndoIt(Environment* ev)
  712. {
  713.     //-- Restore the broken link --
  714.     GetPart(ev)->GetLinkManager(ev)->RestoreDestinationLink(ev, fLink);
  715.     GetPart(ev)->Changed(ev);
  716. }
  717.  
  718. //---------------------------------------------------------------------------------------
  719. // CBreakLinkCommand::RedoIt
  720. //---------------------------------------------------------------------------------------
  721. void CBreakLinkCommand::RedoIt(Environment* ev)
  722. {
  723.     this->DoIt(ev);    // just DoIt
  724. }
  725.  
  726. //---------------------------------------------------------------------------------------
  727. // CBreakLinkCommand::CommitDone
  728. //---------------------------------------------------------------------------------------
  729. void CBreakLinkCommand::CommitDone(Environment* ev)
  730. {
  731.     // Delete the saved link destination only if the command was not undone
  732.     delete fLink;
  733. }
  734.  
  735.  
  736.