home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 October: Mac OS SDK / Dev.CD Oct 96 SDK / Dev.CD Oct 96 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / Draw / Sources / DrawCont.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  27.2 KB  |  885 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                DrawCont.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Mary Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "ODFDraw.hpp"
  13.  
  14. #ifndef DRAWCONT_H
  15. #include "DrawCont.h"
  16. #endif
  17.  
  18. #ifndef DRAWPART_H
  19. #include "DrawPart.h"
  20. #endif
  21.  
  22. #ifndef DRAWCLIP_H
  23. #include "DrawClip.h"
  24. #endif
  25.  
  26. #ifndef BASESHP_H
  27. #include "BaseShp.h"
  28. #endif
  29.  
  30. #ifndef GROUPSHP_H
  31. #include "GroupShp.h"
  32. #endif
  33.  
  34. #ifndef DRAWPRXY_H
  35. #include "DrawPrxy.h"
  36. #endif
  37.  
  38. #ifndef UTILS_H
  39. #include "Utils.h"
  40. #endif
  41.  
  42. #ifndef DRAWLINK_H
  43. #include "DrawLink.h"
  44. #endif
  45.  
  46. #ifndef DRWPRMSE_H
  47. #include "DrwPrmse.h"
  48. #endif
  49.  
  50. #ifndef DRAWSEL_H
  51. #include "DrawSel.h"
  52. #endif
  53.  
  54. // ----- Part Layer -----
  55.  
  56. #ifndef FWUTIL_H
  57. #include "FWUtil.h"
  58. #endif
  59.  
  60. #ifndef FWPRESEN_H
  61. #include "FWPresen.h"
  62. #endif
  63.  
  64. // ----- OS Layer -----
  65.  
  66. #ifndef FWRECT_H
  67. #include "FWRect.h"
  68. #endif
  69.  
  70. #ifndef FWODGEOM_H
  71. #include "FWODGeom.h"
  72. #endif
  73.  
  74. #ifndef FWSUSINK_H
  75. #include "FWSUSink.h"
  76. #endif
  77.  
  78. #ifndef FWBARRAY_H
  79. #include "FWBArray.h"
  80. #endif
  81.  
  82. #ifndef FWFILEAC_H
  83. #include "FWFileAc.h"
  84. #endif
  85.  
  86. #ifndef SLMixOS_H
  87. #include "SLMixOS.h"
  88. #endif
  89.  
  90. // ----- Foundation Layer -----
  91.  
  92. #ifndef FWSTREAM_H
  93. #include "FWStream.h"
  94. #endif
  95.  
  96. #ifndef FWSUSINK_H
  97. #include "FWSUSink.h"
  98. #endif
  99.  
  100. #ifndef FWMEMORY_H
  101. #include "FWMemory.h"
  102. #endif
  103.  
  104. // ----- OpenDoc Includes -----
  105.  
  106. #ifndef SOM_Module_OpenDoc_StdProps_defined
  107. #include <StdProps.xh>
  108. #endif
  109.  
  110. #ifndef SOM_ODTranslation_xh
  111. #include <Translt.xh>
  112. #endif
  113.  
  114. #ifndef SOM_ODShape_xh
  115. #include <Shape.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODStorageUnit_xh
  119. #include <StorageU.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODSession_xh
  123. #include <ODSessn.xh>
  124. #endif
  125.  
  126. //========================================================================================
  127. //    Runtime Information
  128. //========================================================================================
  129.  
  130. #ifdef FW_BUILD_MAC
  131. #pragma segment odfdraw
  132. #endif
  133.  
  134. FW_DEFINE_AUTO(CDrawPartContent)
  135. FW_DEFINE_AUTO(CDrawSelectionContent)
  136. FW_DEFINE_AUTO(CDrawUndoContent)
  137. FW_DEFINE_AUTO(CDrawPromiseContent)
  138. FW_DEFINE_AUTO(CDrawLinkContent)
  139. FW_DEFINE_AUTO(CDrawLinkSourceContent)
  140.  
  141. //========================================================================================
  142. //    class CDrawPartContent
  143. //========================================================================================
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    CDrawPartContent::CDrawPartContent
  147. //----------------------------------------------------------------------------------------
  148. //    CDrawPartContent constructor
  149.  
  150. CDrawPartContent::CDrawPartContent(Environment* ev, CDrawPart* part) :
  151.     CDrawContent(ev, part)
  152. {
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    CDrawPartContent::~CDrawPartContent
  157. //----------------------------------------------------------------------------------------
  158. //    CDrawPartContent destructor
  159.  
  160. CDrawPartContent::~CDrawPartContent()
  161. {
  162.     if (fShapeList)
  163.     {
  164.         CBaseShape* shape;
  165.         while ((shape = fShapeList->First()) != NULL)
  166.         {
  167.             fShapeList->Remove(shape);
  168.             delete shape;
  169.         }
  170.         fProxyShapeCount = 0;
  171.     }
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    CDrawPartContent::Externalize
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void CDrawPartContent::Externalize(Environment* ev,
  179.                                     ODStorageUnit* storageUnit, 
  180.                                     FW_EStorageKinds storageKind,
  181.                                     FW_CCloneInfo* cloneInfo)
  182. {
  183.     ExternalizeShapeList(ev, storageUnit, cloneInfo, FW_kFixed0, FW_kFixed0);
  184.         
  185.     // ----- Write links -----
  186.     CDrawLinkManager* linkMgr = (CDrawLinkManager*) fDrawPart->GetLinkManager(ev);
  187.     linkMgr->ExternalizeLinks(ev, storageUnit, cloneInfo);
  188.  
  189.     // ----- Write general information -----
  190.     fDrawPart->ExternalizeAnnotations(ev, storageUnit);
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    CDrawPartContent::Internalize
  195. //----------------------------------------------------------------------------------------
  196.  
  197. FW_Boolean CDrawPartContent::Internalize(Environment* ev,
  198.                                         ODStorageUnit* storageUnit, 
  199.                                         FW_EStorageKinds storageKind,
  200.                                         FW_CCloneInfo* cloneInfo)
  201. {    
  202.     InternalizeShapeList(ev, storageUnit, cloneInfo);
  203.     
  204.     // ----- Read links -----
  205.     CDrawLinkManager* linkMgr = (CDrawLinkManager*) fDrawPart->GetLinkManager(ev);
  206.     linkMgr->InternalizeLinks(ev, storageUnit);
  207.     
  208.     // ----- Read general information -----
  209.     fDrawPart->InternalizeAnnotations(ev, storageUnit);
  210.  
  211.     return true;
  212. }
  213.  
  214. //----------------------------------------------------------------------------------------
  215. //    CDrawPartContent::PostInternalizeShape
  216. //----------------------------------------------------------------------------------------
  217.  
  218. void CDrawPartContent::PostInternalizeShape(Environment* ev, const FW_CPoint& offset, CBaseShape* shape, short index)
  219. {
  220.     shape->OffsetShape(ev, -offset.x, -offset.y);
  221.     shape->SetExternalizationIndex(index);    // so links can find their shapes
  222. }
  223.  
  224. #if 0
  225. //----------------------------------------------------------------------------------------
  226. //    CDrawPartContent::SingleEmbeddedFrameInternalized
  227. //----------------------------------------------------------------------------------------
  228.  
  229. void CDrawPartContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  230.                                                       FW_CEmbeddingFrame* scopeFrame,
  231.                                                       ODPart* embeddedPart, 
  232.                                                       ODFrame* embeddedFrame,
  233.                                                       ODShape* suggestedShape,
  234.                                                       ODTypeToken viewType)
  235. {
  236.     CProxyShape* insertedShape = AddSingleEmbeddedFrame(ev, 
  237.                                                         scopeFrame,
  238.                                                         embeddedPart, 
  239.                                                         embeddedFrame, 
  240.                                                         suggestedShape, 
  241.                                                         viewType);
  242.  
  243.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  244.     insertedShape->GetUpdateBox(ev, aqTempShape);
  245.  
  246.     FW_CPresentation* presentation = fDrawPart->GetMainPresentation();
  247.     CDrawFacetClipper facetClipper(ev, fDrawPart);
  248.     facetClipper.Clip(ev, presentation, aqTempShape);
  249.  
  250.     presentation->Invalidate(ev, aqTempShape);
  251. }
  252. #endif
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    CDrawPartContent::MoveBackward
  256. //----------------------------------------------------------------------------------------
  257.  
  258. FW_Boolean CDrawPartContent::MoveBackward(Environment* ev)
  259. {
  260.     FW_Boolean didIt = FALSE;
  261.  
  262.     CBaseShape* shape = fShapeList->First();
  263.     CBaseShape* previous = NULL;
  264.     while (shape != NULL)
  265.     {
  266.         if (shape->IsSelectedShape() && previous != NULL && !previous->IsSelectedShape())
  267.         {
  268.             fShapeList->Remove(shape);
  269.             fShapeList->AddBefore(previous, shape);            
  270.             shape->MovedBefore(ev, previous);
  271.             shape = previous;            
  272.             didIt = TRUE;
  273.         }
  274.         else
  275.             previous = shape;
  276.         
  277.         shape = fShapeList->After(shape);
  278.     }
  279.  
  280.     return didIt;
  281. }
  282.  
  283. //----------------------------------------------------------------------------------------
  284. //    CDrawPartContent::MoveForward
  285. //----------------------------------------------------------------------------------------
  286.  
  287. FW_Boolean CDrawPartContent::MoveForward(Environment* ev)
  288. {
  289.     FW_Boolean didIt = FALSE;
  290.     
  291.     CBaseShape* shape = fShapeList->Last();
  292.     CBaseShape* next = NULL;
  293.     while (shape != NULL)
  294.     {
  295.         if (shape->IsSelectedShape() && next != NULL && !next->IsSelectedShape())
  296.         {
  297.             fShapeList->Remove(shape);
  298.             fShapeList->AddAfter(next, shape);            
  299.             shape->MovedAfter(ev, next);
  300.             shape = next;            
  301.             didIt = TRUE;
  302.         }
  303.         else
  304.             next = shape;
  305.             
  306.         shape = fShapeList->Before(shape);
  307.     }
  308.         
  309.     return didIt;
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    CDrawPartContent::MoveToBack
  314. //----------------------------------------------------------------------------------------
  315.  
  316. void CDrawPartContent::MoveToBack(Environment* ev)
  317. {
  318.     CShapeCollection extract;
  319.     ExtractSelection(ev, &extract);
  320.     
  321.     CShapeCollectionIterator ite(&extract);
  322.     for (CBaseShape* shape = ite.Last(); ite.IsNotComplete(); shape = ite.Previous())
  323.     {
  324.         fShapeList->AddFirst(shape);
  325.         shape->MovedFirst(ev);
  326.     }
  327. }
  328.  
  329. //----------------------------------------------------------------------------------------
  330. //    CDrawPartContent::MoveToFront
  331. //----------------------------------------------------------------------------------------
  332.  
  333. void CDrawPartContent::MoveToFront(Environment* ev)
  334. {
  335.     CShapeCollection extract;
  336.     ExtractSelection(ev, &extract);
  337.     
  338.     CShapeCollectionIterator ite(&extract);
  339.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  340.     {
  341.         fShapeList->AddLast(shape);
  342.         shape->MovedLast(ev);
  343.     }
  344. }
  345.  
  346. //----------------------------------------------------------------------------------------
  347. //    CDrawPartContent::ExtractSelection
  348. //----------------------------------------------------------------------------------------
  349.  
  350. void CDrawPartContent::ExtractSelection(Environment* ev, CShapeCollection* extract)
  351. {
  352.     // ----- Create the extract list -----
  353.     CShapeCollectionIterator ite(fShapeList);
  354.     CBaseShape* shape;
  355.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  356.     {
  357.         if (shape->IsSelectedShape())
  358.             extract->AddLast(shape);
  359.     }
  360.         
  361.     // ----- Remove then from the shape list -----
  362.     CShapeCollectionIterator ite2(extract);
  363.     for (shape = ite2.First(); ite2.IsNotComplete(); shape = ite2.Next())
  364.     {
  365.         fShapeList->Remove(shape);
  366.     }
  367. }
  368.  
  369. //----------------------------------------------------------------------------------------
  370. //    CDrawPartContent::NewShape
  371. //----------------------------------------------------------------------------------------
  372.  
  373. CBaseShape* CDrawPartContent::NewShape(Environment* ev, unsigned short shapeType)
  374. {    
  375.     CBaseShape *theShape = NULL;
  376.  
  377.     FW_ASSERT(shapeType != kProxyShape);        // We should never create a proxyShape this way
  378.     
  379.     switch (shapeType)
  380.     {
  381.         case kLineShape:
  382.             theShape = FW_NEW(CLineShape, ());
  383.             break;
  384.             
  385.         case kTextShape:
  386.             theShape = FW_NEW(CTextShape, ());
  387.             break;
  388.         
  389.         case kRectShape:
  390.             theShape = FW_NEW(CRectShape, ());
  391.             break;
  392.             
  393.         case kOvalShape:
  394.             theShape = FW_NEW(COvalShape, ());
  395.             break;
  396.             
  397.         case kRRectShape:
  398.             theShape = FW_NEW(CRoundRectShape, ());
  399.             break;
  400.     }
  401.     
  402.     return theShape;
  403. }
  404.  
  405. //========================================================================================
  406. //    class CDrawSelectionContent
  407. //========================================================================================
  408.  
  409. //----------------------------------------------------------------------------------------
  410. //    CDrawSelectionContent::CDrawSelectionContent
  411. //----------------------------------------------------------------------------------------
  412. //    CDrawSelectionContent constructor
  413.  
  414. CDrawSelectionContent::CDrawSelectionContent(Environment* ev, CDrawPart* part, CDrawSelection* selection)
  415. :    CDrawContent(ev, part),
  416.     fDrawSelection(selection)
  417. {
  418. }
  419.  
  420. //----------------------------------------------------------------------------------------
  421. //    CDrawSelectionContent::~CDrawSelectionContent
  422. //----------------------------------------------------------------------------------------
  423. //    CDrawSelectionContent destructor
  424.  
  425. CDrawSelectionContent::~CDrawSelectionContent()
  426. {
  427. }
  428.  
  429. //----------------------------------------------------------------------------------------
  430. //    CDrawSelectionContent::Internalize
  431. //----------------------------------------------------------------------------------------
  432.  
  433. FW_Boolean CDrawSelectionContent::Internalize(Environment* ev,
  434.                                             ODStorageUnit* storageUnit, 
  435.                                             FW_EStorageKinds storageKind,
  436.                                             FW_CCloneInfo* cloneInfo)
  437. {
  438.     if (!storageUnit->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev), 0))
  439.         return false;
  440.         
  441.     // ----- [HLX] force promises to be fulfilled, otherwise bug in locks
  442.     storageUnit->Focus(ev, kODPropContents, kODPosUndefined, fDrawPart->GetPartKind(ev), 0, kODPosUndefined);
  443.     storageUnit->GetSize(ev);
  444.  
  445.     // ----- Read in the shapes -----
  446.     InternalizeShapeList(ev, storageUnit, cloneInfo);
  447.     
  448.     return true;
  449. }
  450.  
  451. //----------------------------------------------------------------------------------------
  452. //    CDrawSelectionContent::Externalize
  453. //----------------------------------------------------------------------------------------
  454.  
  455. void CDrawSelectionContent::Externalize(Environment* ev,
  456.                                         ODStorageUnit* storageUnit, 
  457.                                         FW_EStorageKinds storageKind,
  458.                                         FW_CCloneInfo* cloneInfo)
  459. {
  460.     FW_CRect selectRect;
  461.     fDrawSelection->GetDragRect(selectRect);
  462.     
  463.     // ----- Make a copy of myself -----
  464.     CDrawPromiseContent* promisedContent = FW_NEW(CDrawPromiseContent, (ev, fDrawPart, this, selectRect));
  465.  
  466.     // ----- Create a promise object -----
  467.     CDrawSelectionPromise* promise = new CDrawSelectionPromise(ev, storageKind, cloneInfo, promisedContent);
  468.     
  469.     // ----- Promise my data type and a PICT -----
  470.     promise->Promise(ev, storageUnit, kODPropContents, fDrawPart->GetPartKind(ev));
  471. #ifdef FW_BUILD_MAC
  472.     promise->Promise(ev, storageUnit, kODPropContents, FW_CPart::gMacPICTDataType);
  473. #endif
  474. }
  475.  
  476. //----------------------------------------------------------------------------------------
  477. //    CDrawSelectionContent::SingleEmbeddedFrameInternalized
  478. //----------------------------------------------------------------------------------------
  479.  
  480. void CDrawSelectionContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  481.                                                           FW_CEmbeddingFrame* scopeFrame,
  482.                                                           ODPart* embeddedPart, 
  483.                                                           ODFrame* embeddedFrame,
  484.                                                           ODShape* suggestedShape,
  485.                                                           ODTypeToken viewType)
  486. {
  487.     fDrawSelection->CloseSelection(ev);
  488.     CProxyShape* insertedShape = AddSingleEmbeddedFrame(ev, 
  489.                                                         scopeFrame, 
  490.                                                         embeddedPart, 
  491.                                                         embeddedFrame, 
  492.                                                         suggestedShape, 
  493.                                                         viewType);    
  494.     PostInternalizeShape(ev, FW_kZeroPoint, insertedShape, 1);                                        
  495. }
  496.  
  497. //----------------------------------------------------------------------------------------
  498. //    CDrawSelectionContent::PostInternalizeShape
  499. //----------------------------------------------------------------------------------------
  500.  
  501. void CDrawSelectionContent::PostInternalizeShape(Environment* ev, const FW_CPoint& offset, CBaseShape* shape, short index)
  502. {
  503.     shape->SetExternalizationIndex(index);    // so links can find their shapes
  504.  
  505.     // ----- Add the shape to the right places -----
  506.     fDrawPart->AddShapeToPart(ev, shape);    // Add to the part data
  507.     
  508.     // ----- Shape has already been added to the selection list (fShapeList)
  509.     fDrawSelection->ShapeAdded(ev, shape);
  510. }
  511.  
  512. //----------------------------------------------------------------------------------------
  513. //    CDrawSelectionContent::CreateDataFrameShape
  514. //----------------------------------------------------------------------------------------
  515.  
  516. ODShape* CDrawSelectionContent::CreateDataFrameShape(Environment* ev) const
  517. {
  518.     FW_CRect selectionRect;
  519.     fDrawSelection->GetDragRect(selectionRect);
  520.     selectionRect.Place(FW_kZeroPoint);
  521.     
  522.     ODShape* selectionShape = ::FW_NewODShape(ev, selectionRect);
  523.     return selectionShape;
  524. }
  525.  
  526. //========================================================================================
  527. //    class CDrawUndoContent
  528. //========================================================================================
  529.  
  530. //----------------------------------------------------------------------------------------
  531. //    CDrawUndoContent::CDrawUndoContent
  532. //----------------------------------------------------------------------------------------
  533. //    CDrawUndoContent constructor
  534.  
  535. CDrawUndoContent::CDrawUndoContent(Environment* ev, CDrawSelection* selection) :
  536.     CDrawContent(ev, selection->GetDrawContent(ev)),
  537.     fDrawSelection(selection)
  538. {
  539. }
  540.  
  541. //----------------------------------------------------------------------------------------
  542. //    CDrawUndoContent::~CDrawUndoContent
  543. //----------------------------------------------------------------------------------------
  544. //    CDrawUndoContent destructor
  545.  
  546. CDrawUndoContent::~CDrawUndoContent()
  547. {
  548. }
  549.  
  550. //----------------------------------------------------------------------------------------
  551. //    CDrawUndoContent::RemoveShapeSelection
  552. //----------------------------------------------------------------------------------------
  553.  
  554. void CDrawUndoContent::RemoveShapeSelection(Environment *ev)
  555. {
  556.     // Select the saved shapes
  557.     fDrawSelection->SelectContent(ev, this);
  558.  
  559.     // Clear the selected shapes
  560.     fDrawSelection->ClearSelection(ev);
  561.  
  562.     // Notify everybody
  563.     fDrawSelection->SelectionChanged(ev);
  564. }
  565.  
  566. //----------------------------------------------------------------------------------------
  567. //    CDrawUndoContent::RestoreShapeSelection
  568. //----------------------------------------------------------------------------------------
  569.  
  570. void CDrawUndoContent::RestoreShapeSelection(Environment *ev)
  571. {
  572.     // Add the saved shapes back into the part
  573.     CDrawContentShapeIterator ite(this);
  574.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  575.     {
  576.         shape->RestoreShape(ev, fDrawPart);
  577.     }
  578.  
  579.     // Redraw the restored shapes
  580.     RedrawShapes(ev);
  581.  
  582.     // Select the saved shapes
  583.     fDrawSelection->SelectContent(ev, this);
  584.  
  585.     // Notify everybody
  586.     fDrawSelection->SelectionChanged(ev);
  587. }
  588.  
  589. //----------------------------------------------------------------------------------------
  590. //    CDrawUndoContent::DeleteSavedShapes
  591. //----------------------------------------------------------------------------------------
  592.  
  593. void CDrawUndoContent::DeleteSavedShapes(Environment *ev)
  594. {
  595.     CBaseShape* shape;
  596.     
  597.     // Before deleting the shapes, make sure they are not promised
  598.     CDrawContentShapeIterator ite(this);
  599.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  600.     {
  601.         shape->CheckPromise(ev, fDrawPart);
  602.     }
  603.     
  604.     // ----- Delete all the saved shapes -----
  605.     while ((shape = GetFirstShape()) != NULL)
  606.     {
  607.         RemoveShape(ev, shape);
  608.         delete shape;
  609.     }        
  610. }
  611.  
  612. //----------------------------------------------------------------------------------------
  613. //    CDrawUndoContent::RemoveFromLinks
  614. //----------------------------------------------------------------------------------------
  615. void CDrawUndoContent::RemoveFromLinks(Environment* ev)
  616. {
  617.     // Remove the saved shapes from any link sources they're in
  618.     CDrawContentShapeIterator it(this);
  619.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  620.     {
  621.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  622.         if (linkSource)
  623.         {
  624.             linkSource->RemoveShape(ev, shape);
  625.         }
  626.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  627.         if (link)
  628.         {
  629.             fDrawPart->GetLinkManager(ev)->BreakDestinationLink(ev, link);
  630.         }
  631.     }
  632. }
  633.  
  634. //----------------------------------------------------------------------------------------
  635. //    CDrawUndoContent::RestoreLinks
  636. //----------------------------------------------------------------------------------------
  637. void CDrawUndoContent::RestoreLinks(Environment* ev)
  638. {
  639.     // Add the saved shapes back into any link sources they were in
  640.     CDrawContentShapeIterator it(this);
  641.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  642.     {
  643.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  644.         if (linkSource)
  645.         {
  646.             linkSource->AddShape(ev, shape);
  647.         }
  648.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  649.         if (link)
  650.         {
  651.             fDrawPart->GetLinkManager(ev)->RestoreDestinationLink(ev, link);
  652.         }
  653.     }
  654. }
  655.  
  656. //----------------------------------------------------------------------------------------
  657. //    CDrawUndoContent::DeleteEmptyLinkSources
  658. //----------------------------------------------------------------------------------------
  659. void CDrawUndoContent::DeleteEmptyLinkSources(Environment* ev)
  660. {
  661.     // Check for link sources left empty because all their shapes were removed
  662.     FW_CLinkManager* linkMgr = fDrawPart->GetLinkManager(ev);
  663.  
  664.     CDrawContentShapeIterator it(this);
  665.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  666.     {
  667.         CDrawPublishLink* linkSource = shape->GetPublishLink();
  668.         if (linkSource && linkSource->IsEmpty())
  669.         {
  670.             linkMgr->BreakSourceLink(ev, linkSource);
  671.             delete linkSource;
  672.         }
  673.     }
  674. }
  675.  
  676. //----------------------------------------------------------------------------------------
  677. //    CDrawUndoContent::DeleteSavedShapesAndLinks
  678. //----------------------------------------------------------------------------------------
  679. void CDrawUndoContent::DeleteSavedShapesAndLinks(Environment* ev)
  680. {
  681.     CBaseShape* shape;
  682.     
  683.     // Before deleting the shapes, make sure they are not promised
  684.     CDrawContentShapeIterator ite(this);
  685.     for (shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  686.     {
  687.         shape->CheckPromise(ev, fDrawPart);
  688.     }
  689.     
  690.     // ----- Delete all the saved shapes -----
  691.     while ((shape = GetFirstShape()) != NULL)
  692.     {
  693.         RemoveShape(ev, shape);
  694.         // Check for an orphaned link and delete it
  695.         CDrawSubscribeLink* link = shape->GetSubscribeLink();
  696.         if (link)
  697.             delete link;    // deletes the shape
  698.         else
  699.             delete shape;
  700.     }        
  701. }
  702.  
  703. //========================================================================================
  704. //    class CDrawPromiseContent
  705. //========================================================================================
  706.  
  707. //----------------------------------------------------------------------------------------
  708. //    CDrawPromiseContent::CDrawPromiseContent
  709. //----------------------------------------------------------------------------------------
  710. //    CDrawPromiseContent constructor
  711.  
  712. CDrawPromiseContent::CDrawPromiseContent(Environment* ev, 
  713.                                         CDrawPart* part, 
  714.                                         CDrawSelectionContent* selectedContent,
  715.                                         const FW_CRect& selectedRect) :
  716.     CDrawContent(ev, part),
  717.     fSelectedRect(selectedRect)
  718. {
  719.     CDrawContentShapeIterator ite(selectedContent);
  720.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  721.     {
  722.         this->AddShape(ev, shape);
  723.     }
  724. }
  725.  
  726. //----------------------------------------------------------------------------------------
  727. //    CDrawPromiseContent::~CDrawPromiseContent
  728. //----------------------------------------------------------------------------------------
  729. //    CDrawPromiseContent destructor
  730.  
  731. CDrawPromiseContent::~CDrawPromiseContent()
  732. {
  733. }
  734.  
  735. //----------------------------------------------------------------------------------------
  736. //    CDrawPromiseContent::Externalize
  737. //----------------------------------------------------------------------------------------
  738.  
  739. void CDrawPromiseContent::Externalize(Environment* ev,
  740.                                         ODStorageUnit* storageUnit, 
  741.                                         FW_EStorageKinds storageKind,
  742.                                         FW_CCloneInfo* cloneInfo)
  743. {
  744.     ExternalizeShapeList(ev, storageUnit, cloneInfo, fSelectedRect.left, fSelectedRect.top);
  745. }
  746.  
  747. //----------------------------------------------------------------------------------------
  748. //    CDrawPromiseContent::IsOKtoWrite
  749. //----------------------------------------------------------------------------------------
  750.  
  751. FW_Boolean CDrawPromiseContent::IsOKtoWrite(Environment* ev, CBaseShape* shape)
  752. {
  753.     return TRUE;
  754. }
  755.  
  756. //========================================================================================
  757. //    class CDrawLinkSourceContent
  758. //========================================================================================
  759.  
  760. //----------------------------------------------------------------------------------------
  761. //    CDrawLinkSourceContent::CDrawLinkSourceContent
  762. //----------------------------------------------------------------------------------------
  763. //    CDrawLinkSourceContent constructor
  764.  
  765. CDrawLinkSourceContent::CDrawLinkSourceContent(Environment* ev, CDrawPart* part, CDrawContent* selectedContent)
  766. :    CDrawContent(ev, part)
  767. {
  768.     if (selectedContent)
  769.     {
  770.         CDrawContentShapeIterator it(selectedContent);
  771.         for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  772.         {
  773.             this->AddShape(ev, shape);    // make sure fProxyShapeCount is incremented appropriately
  774.         }
  775.     }
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    CDrawLinkSourceContent::~CDrawLinkSourceContent
  780. //----------------------------------------------------------------------------------------
  781. //    CDrawLinkSourceContent destructor
  782.  
  783. CDrawLinkSourceContent::~CDrawLinkSourceContent()
  784. {
  785. }
  786.  
  787. //----------------------------------------------------------------------------------------
  788. //    CDrawLinkSourceContent::Externalize
  789. //----------------------------------------------------------------------------------------
  790.  
  791. void CDrawLinkSourceContent::Externalize(Environment* ev,
  792.                                          ODStorageUnit* storageUnit, 
  793.                                          FW_EStorageKinds storageKind,
  794.                                          FW_CCloneInfo* cloneInfo)
  795. {
  796.     ExternalizeShapeList(ev, storageUnit, cloneInfo, FW_kFixed0, FW_kFixed0);
  797. }
  798.  
  799. //========================================================================================
  800. //    class CDrawLinkContent
  801. //========================================================================================
  802.  
  803. //----------------------------------------------------------------------------------------
  804. //    CDrawLinkContent::CDrawLinkContent
  805. //----------------------------------------------------------------------------------------
  806. //    CDrawLinkContent constructor
  807.  
  808. CDrawLinkContent::CDrawLinkContent(Environment* ev, CDrawPart* part, CDrawSubscribeLink* link)
  809. :    CDrawContent(ev, part),
  810.     fLink(link)
  811. {
  812.     // This constructor is called when a new destination link is created
  813. }
  814.  
  815. //----------------------------------------------------------------------------------------
  816. //    CDrawLinkContent::CDrawLinkContent
  817. //----------------------------------------------------------------------------------------
  818. //    CDrawLinkContent constructor
  819.  
  820. CDrawLinkContent::CDrawLinkContent(Environment* ev, CDrawSubscribeLink* link, CDrawLinkContent* content)
  821. :    CDrawContent(ev, content),
  822.     fLink(link)
  823. {
  824.     // This constructor is called when a link is updated (not the first time)
  825. }
  826.  
  827. //----------------------------------------------------------------------------------------
  828. //    CDrawLinkContent::~CDrawLinkContent
  829. //----------------------------------------------------------------------------------------
  830. //    CDrawLinkContent destructor
  831.  
  832. CDrawLinkContent::~CDrawLinkContent()
  833. {
  834. }
  835.  
  836. //----------------------------------------------------------------------------------------
  837. //    CDrawLinkContent::GroupShapes
  838. //----------------------------------------------------------------------------------------
  839. void CDrawLinkContent::GroupShapes(Environment* ev, CGroupShape* group)
  840. {
  841.     // Add our shapes to the group shape
  842.     CDrawContentShapeIterator it(this);
  843.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  844.     {
  845.         group->AddShape(shape);
  846.     }
  847. }
  848.  
  849. //----------------------------------------------------------------------------------------
  850. //    CDrawLinkContent::Internalize
  851. //----------------------------------------------------------------------------------------
  852. FW_Boolean CDrawLinkContent::Internalize(Environment* ev,
  853.                                          ODStorageUnit* storageUnit, 
  854.                                          FW_EStorageKinds storageKind,
  855.                                          FW_CCloneInfo* cloneInfo)
  856. {
  857.     if (!storageUnit->Exists(ev, kODPropContents, fDrawPart->GetPartKind(ev), 0))
  858.         return false;
  859.         
  860.     // ----- Read in the shapes -----
  861.     InternalizeShapeList(ev, storageUnit, cloneInfo);
  862.     return true;
  863. }
  864.  
  865. //----------------------------------------------------------------------------------------
  866. //    CDrawLinkContent::SingleEmbeddedFrameInternalized
  867. //----------------------------------------------------------------------------------------
  868.  
  869. void CDrawLinkContent::SingleEmbeddedFrameInternalized(Environment* ev, 
  870.                                                        FW_CEmbeddingFrame* scopeFrame,
  871.                                                        ODPart* embeddedPart, 
  872.                                                        ODFrame* embeddedFrame,
  873.                                                        ODShape* suggestedShape,
  874.                                                        ODTypeToken viewType)
  875. {
  876.     CProxyShape* newShape = AddSingleEmbeddedFrame(ev, 
  877.                                                    scopeFrame, 
  878.                                                    embeddedPart, 
  879.                                                    embeddedFrame, 
  880.                                                    suggestedShape, 
  881.                                                    viewType);
  882.     PostInternalizeShape(ev, FW_kZeroPoint, newShape, 1);                                                
  883. }
  884.  
  885.