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 / Draw / Sources / Content.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  21.8 KB  |  780 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Content.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "ODFDraw.hpp"
  11.  
  12. #ifndef CONTENT_H
  13. #include "Content.h"
  14. #endif
  15.  
  16. #ifndef DRAWPART_H
  17. #include "DrawPart.h"
  18. #endif
  19.  
  20. #ifndef DRAWCLIP_H
  21. #include "DrawClip.h"
  22. #endif
  23.  
  24. #ifndef BASESHP_H
  25. #include "BaseShp.h"
  26. #endif
  27.  
  28. #ifndef GROUPSHP_H
  29. #include "GroupShp.h"
  30. #endif
  31.  
  32. #ifndef DRAWPRXY_H
  33. #include "DrawPrxy.h"
  34. #endif
  35.  
  36. #ifndef UTILS_H
  37. #include "Utils.h"
  38. #endif
  39.  
  40. #ifndef DRAWLINK_H
  41. #include "DrawLink.h"
  42. #endif
  43.  
  44. #ifndef DRWPRMSE_H
  45. #include "DrwPrmse.h"
  46. #endif
  47.  
  48. #ifndef DRAWSEL_H
  49. #include "DrawSel.h"
  50. #endif
  51.  
  52. // ----- Part Layer -----
  53.  
  54. #ifndef FWUTIL_H
  55. #include "FWUtil.h"
  56. #endif
  57.  
  58. #ifndef FWPRESEN_H
  59. #include "FWPresen.h"
  60. #endif
  61.  
  62. #ifndef FWKIND_H
  63. #include "FWKind.h"
  64. #endif
  65.  
  66. // ----- OS Layer -----
  67.  
  68. #ifndef FWSUUTIL_H
  69. #include "FWSUUtil.h"
  70. #endif
  71.  
  72. #ifndef FWRECT_H
  73. #include "FWRect.h"
  74. #endif
  75.  
  76. #ifndef FWODGEOM_H
  77. #include "FWODGeom.h"
  78. #endif
  79.  
  80. #ifndef FWSUSINK_H
  81. #include "FWSUSink.h"
  82. #endif
  83.  
  84. #ifndef FWBARRAY_H
  85. #include "FWBArray.h"
  86. #endif
  87.  
  88. #ifndef FWFILEAC_H
  89. #include "FWFileAc.h"
  90. #endif
  91.  
  92. #ifndef SLMixOS_H
  93. #include "SLMixOS.h"
  94. #endif
  95.  
  96. #ifndef FWPICTUR_H
  97. #include "FWPictur.h"
  98. #endif
  99.  
  100. // ----- Foundation Layer -----
  101.  
  102. #ifndef FWSTREAM_H
  103. #include "FWStream.h"
  104. #endif
  105.  
  106. #ifndef FWSUSINK_H
  107. #include "FWSUSink.h"
  108. #endif
  109.  
  110. #ifndef FWMEMORY_H
  111. #include "FWMemory.h"
  112. #endif
  113.  
  114. // ----- OpenDoc Includes -----
  115.  
  116. #ifndef SOM_Module_OpenDoc_StdProps_defined
  117. #include <StdProps.xh>
  118. #endif
  119.  
  120. #ifndef SOM_ODTranslation_xh
  121. #include <Translt.xh>
  122. #endif
  123.  
  124. #ifndef SOM_ODShape_xh
  125. #include <Shape.xh>
  126. #endif
  127.  
  128. #ifndef SOM_ODStorageUnit_xh
  129. #include <StorageU.xh>
  130. #endif
  131.  
  132. #ifndef SOM_ODSession_xh
  133. #include <ODSessn.xh>
  134. #endif
  135.  
  136. //========================================================================================
  137. //    Runtime Information
  138. //========================================================================================
  139.  
  140. #ifdef FW_BUILD_MAC
  141. #pragma segment odfdraw2
  142. #endif
  143.  
  144. FW_DEFINE_AUTO(CDrawContent)
  145. FW_DEFINE_AUTO(CDrawContentShapeIterator)
  146. FW_DEFINE_AUTO(CSemanticShapeElementIterator)
  147.  
  148. //========================================================================================
  149. //    class CDrawContent
  150. //========================================================================================
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    CDrawContent::CDrawContent
  154. //----------------------------------------------------------------------------------------
  155. //    CDrawContent constructor
  156.  
  157. CDrawContent::CDrawContent(Environment* ev, CDrawPart* part, const FW_CRect& contentRect) :
  158.     FW_CEmbeddingContent(ev, part),
  159.     fShapeList(NULL),
  160.     fDrawPart(part),
  161.     fProxyShapeCount(0),
  162.     fContentRect(contentRect)
  163. {
  164.     fShapeList = FW_NEW(CShapeCollection, ());
  165.     
  166.     FW_END_CONSTRUCTOR
  167. }
  168.  
  169. //----------------------------------------------------------------------------------------
  170. //    CDrawContent::CDrawContent
  171. //----------------------------------------------------------------------------------------
  172.  
  173. CDrawContent::CDrawContent(Environment* ev, CDrawPart* part, CDrawContent* other) :
  174.     FW_CEmbeddingContent(ev, part),
  175.     fShapeList(NULL),
  176.     fDrawPart(part),
  177.     fProxyShapeCount(0),
  178.     fContentRect(FW_kZeroRect)
  179. {
  180.     fShapeList = FW_NEW(CShapeCollection, ());
  181.  
  182.     if (other != NULL)
  183.     {
  184.         fContentRect = other->fContentRect;
  185.         
  186.         CDrawContentShapeIterator ite(other);
  187.         for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  188.         {
  189.             this->AddShape(ev, shape);
  190.         }
  191.     }
  192.     
  193.     FW_END_CONSTRUCTOR
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    CDrawContent::~CDrawContent
  198. //----------------------------------------------------------------------------------------
  199. //    CDrawContent destructor
  200.  
  201. CDrawContent::~CDrawContent()
  202. {
  203.     FW_START_DESTRUCTOR
  204.     delete fShapeList;
  205. }
  206.  
  207. //----------------------------------------------------------------------------------------
  208. //    CDrawContent::AddShape
  209. //----------------------------------------------------------------------------------------
  210.  
  211. void CDrawContent::AddShape(Environment* ev, CBaseShape* shape, CBaseShape* nextShape)
  212. {
  213.     if (fShapeList->Contains(shape)) return;    // don't add shape twice
  214.  
  215.     if (nextShape == NULL)
  216.         fShapeList->AddLast(shape);
  217.     else
  218.         fShapeList->AddBefore(nextShape, shape);
  219.  
  220.     if (shape->GetShapeType() == kProxyShape)
  221.     {
  222.         fProxyShapeCount++;
  223.     }
  224.     else if (shape->GetShapeType() == kGroupShape)    // thanks, Troy!
  225.     {
  226.         fProxyShapeCount += ((CGroupShape*) shape)->CountProxyShapes(ev);
  227.     }
  228. }
  229.  
  230. //----------------------------------------------------------------------------------------
  231. //    CDrawContent::RemoveShape
  232. //----------------------------------------------------------------------------------------
  233.  
  234. void CDrawContent::RemoveShape(Environment* ev, CBaseShape* shape)
  235. {
  236.     fShapeList->Remove(shape);
  237.  
  238.     if (shape->GetShapeType() == kProxyShape)
  239.     {
  240.         fProxyShapeCount--;
  241.     }
  242.     else if (shape->GetShapeType() == kGroupShape)
  243.     {
  244.         fProxyShapeCount -= ((CGroupShape*) shape)->CountProxyShapes(ev);
  245.             // ••• Ultimately, this might not be quite right.  
  246.             //     If a proxy is removed from the group before the group is 
  247.             //       removed from the content, the count here could be wrong.
  248.     }
  249. }
  250.  
  251. //----------------------------------------------------------------------------------------
  252. //    CDrawContent::RemoveShapeFromContent
  253. //----------------------------------------------------------------------------------------
  254.  
  255. void CDrawContent::RemoveShapeFromContent(Environment* ev, CBaseShape* shape)
  256. {
  257.     RemoveShape(ev, shape);
  258.     shape->Removed(ev);  // notify shape
  259. }
  260.  
  261. //----------------------------------------------------------------------------------------
  262. //    CDrawContent::Count
  263. //----------------------------------------------------------------------------------------
  264.  
  265. unsigned long CDrawContent::CountShapes() const
  266. {
  267.     return fShapeList->Count();
  268. }
  269.  
  270. //----------------------------------------------------------------------------------------
  271. //    CDrawContent::Count
  272. //----------------------------------------------------------------------------------------
  273.  
  274. void CDrawContent::EmptyShapes(Environment* ev)
  275. {
  276. FW_UNUSED(ev);
  277.     if (fShapeList)
  278.     {
  279.         fShapeList->RemoveAll();
  280.         fProxyShapeCount = 0;
  281.     }
  282. }
  283.  
  284. //----------------------------------------------------------------------------------------
  285. //    CDrawContent::GetFirstShape
  286. //----------------------------------------------------------------------------------------
  287.  
  288. CBaseShape* CDrawContent::GetFirstShape() const
  289. {
  290.     return fShapeList->First();
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    CDrawContent::GetShapeAfter
  295. //----------------------------------------------------------------------------------------
  296. CBaseShape* CDrawContent::GetShapeAfter(CBaseShape* shape) const
  297. {
  298.     return fShapeList->After(shape);
  299. }
  300.  
  301. //----------------------------------------------------------------------------------------
  302. //    CDrawContent::IsEmpty
  303. //----------------------------------------------------------------------------------------
  304.  
  305. FW_Boolean CDrawContent::IsEmpty() const
  306. {
  307.     return (fShapeList->Count() == 0);
  308. }
  309.  
  310. //----------------------------------------------------------------------------------------
  311. //    CDrawContent::CalcUpdateShape
  312. //----------------------------------------------------------------------------------------
  313.  
  314. ODShape* CDrawContent::CalcUpdateShape(Environment* ev)
  315. {
  316.     if (this->IsEmpty())
  317.         return NULL;
  318.  
  319.     ODShape* updateShape = ::FW_NewODShape(ev);
  320.  
  321.     FW_CAcquiredODShape aqTempShape = ::FW_NewODShape(ev);
  322.     FW_Boolean first = TRUE;
  323.  
  324.     CDrawContentShapeIterator ite(this);
  325.     for (CBaseShape* shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  326.     {
  327.         shape->GetUpdateBox(ev, aqTempShape);
  328.         if (first)
  329.             updateShape->CopyFrom(ev, aqTempShape);
  330.         else
  331.             updateShape->Union(ev, aqTempShape);
  332.                         
  333.         first = FALSE;
  334.     }
  335.  
  336.     return updateShape;
  337. }
  338.  
  339. //----------------------------------------------------------------------------------------
  340. //    CDrawContent::RedrawShapes
  341. //----------------------------------------------------------------------------------------
  342.  
  343. void CDrawContent::RedrawShapes(Environment* ev)
  344. {
  345.     // Calculate the update shape and invalidate it
  346.     FW_CAcquiredODShape updateShape = CalcUpdateShape(ev);
  347.     if (updateShape != NULL) 
  348.         this->RedrawShape(ev, updateShape);
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    CDrawContent::RedrawShape
  353. //----------------------------------------------------------------------------------------
  354.  
  355. void CDrawContent::RedrawShape(Environment* ev, CBaseShape* shape)
  356. {
  357.     FW_CAcquiredODShape updateShape = ::FW_NewODShape(ev);
  358.     
  359.     shape->GetUpdateBox(ev, updateShape);
  360.     this->RedrawShape(ev, updateShape);
  361. }
  362.  
  363. //----------------------------------------------------------------------------------------
  364. //    CDrawContent::RedrawShape
  365. //----------------------------------------------------------------------------------------
  366.  
  367. void CDrawContent::RedrawShape(Environment* ev, ODShape* odShape)
  368. {
  369.     FW_CPresentation* presentation = fDrawPart->GetMainPresentation();
  370.     CDrawFacetClipper facetClipper(fDrawPart);
  371.     facetClipper.Clip(ev, presentation, odShape);
  372.     presentation->Invalidate(ev, odShape);
  373. }
  374.  
  375. //----------------------------------------------------------------------------------------
  376. //    CDrawContent::OffsetShapes
  377. //----------------------------------------------------------------------------------------
  378.  
  379. void CDrawContent::OffsetShapes(Environment* ev, const FW_CPoint& offset)
  380. {
  381.     CShapeCollectionIterator it(fShapeList);
  382.     for (CBaseShape* shape = it.First(); it.IsNotComplete(); shape = it.Next())
  383.     {
  384.         shape->OffsetShape(ev, offset.x, offset.y);
  385.     }
  386. }
  387.  
  388. //----------------------------------------------------------------------------------------
  389. //    CDrawContent::IsOKtoWrite
  390. //----------------------------------------------------------------------------------------
  391.  
  392. FW_Boolean CDrawContent::IsOKtoWrite(Environment* ev, CBaseShape* shape)
  393. {
  394. FW_UNUSED(ev);
  395. FW_UNUSED(shape);
  396.     return TRUE;    // the default
  397. }
  398.  
  399. //----------------------------------------------------------------------------------------
  400. //    CDrawContent::PostInternalizeShape
  401. //----------------------------------------------------------------------------------------
  402.  
  403. void CDrawContent::PostInternalizeShape(Environment* ev, 
  404.                                         const FW_CPoint& offset, 
  405.                                         CBaseShape* shape, 
  406.                                         short i)
  407. {
  408. FW_UNUSED(ev);
  409. FW_UNUSED(offset);
  410. FW_UNUSED(shape);
  411. FW_UNUSED(i);
  412.     // Default is to do nothing
  413. }
  414.  
  415. //----------------------------------------------------------------------------------------
  416. //    CDrawContent::ExternalizeShapeList
  417. //----------------------------------------------------------------------------------------
  418.  
  419. void CDrawContent::ExternalizeShapeList(Environment* ev,
  420.                                         ODStorageUnit* storageUnit, 
  421.                                         FW_CCloneInfo* cloneInfo,
  422.                                         FW_Fixed offsetX,
  423.                                         FW_Fixed offsetY)
  424. {
  425.     // ----- Create an archive for our shapes -----
  426.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fDrawPart->GetPartKind(ev)->GetType(ev));
  427.     CDrawWritableStream archive(ev, suSink, suSink, cloneInfo);
  428.     
  429.     // ----- Write number of shapes -----
  430.     unsigned long count = fShapeList->Count();
  431.     archive << count;
  432.     
  433.     // ----- Write top, left offsets -----
  434.     archive << offsetX;
  435.     archive << offsetY;
  436.  
  437.     // ----- Write shapes -----
  438.     short extIndex = 1;    // externalization index, used by links to identify shapes
  439.     CShapeCollectionIterator ite(fShapeList);
  440.     for (CBaseShape* theShape = ite.First(); ite.IsNotComplete(); theShape = ite.Next())
  441.     {
  442.         if (this->IsOKtoWrite(ev, theShape))
  443.         {
  444.             FW_WRITE_DYNAMIC_OBJECT(archive, theShape, CBaseShape);
  445.             theShape->SetExternalizationIndex(extIndex++);    // so links can write their shapes' indices
  446.         }
  447.     }    
  448.     
  449.     FW_SUDeleteEndOfFocusedValue(ev, storageUnit);
  450. }
  451.  
  452. //----------------------------------------------------------------------------------------
  453. //    CDrawContent::InternalizeShapeList
  454. //----------------------------------------------------------------------------------------
  455.  
  456. void CDrawContent::InternalizeShapeList(Environment* ev,
  457.                                         ODStorageUnit* storageUnit, 
  458.                                         FW_CCloneInfo* cloneInfo)
  459. {
  460.     // ----- Create an Archive for our shapes -----
  461.     FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, fDrawPart->GetPartKind(ev)->GetType(ev));
  462.     FW_PBufferedSink sink(ev, suSink);
  463.     CDrawReadableStream archive(ev, fDrawPart, sink, suSink, cloneInfo);
  464.     
  465.     // ----- Read number of shapes -----
  466.     unsigned long count;
  467.     archive >> count;
  468.  
  469.     // ----- Read top left offset -----
  470.     FW_CPoint offset;
  471.     archive >> offset.x;
  472.     archive >> offset.y;
  473.  
  474.     for (short i = 1; i<=count; i++)
  475.     {
  476.         CBaseShape* theShape = NULL;
  477.         FW_READ_DYNAMIC_OBJECT(archive, &theShape, CBaseShape);
  478.         FW_ASSERT(theShape);
  479.         
  480.         // ----- Add the shape to the shape list -----
  481.         this->AddShape(ev, theShape);
  482.  
  483.         // ----- Do whatever else needs to be done to the shape -----
  484.         this->PostInternalizeShape(ev, offset, theShape, i);
  485.     }
  486. }
  487.  
  488. //----------------------------------------------------------------------------------------
  489. //    CDrawPartContent::ExternalizeKind
  490. //----------------------------------------------------------------------------------------
  491.  
  492. void CDrawContent::ExternalizeKind(Environment* ev,
  493.                                     ODStorageUnit* storageUnit, 
  494.                                     FW_CKind* kind,
  495.                                     FW_StorageKinds storageKind,
  496.                                     FW_CPromise* promise,
  497.                                     FW_CCloneInfo* cloneInfo)
  498. {
  499. FW_UNUSED(kind);
  500.  
  501.     if (promise)
  502.     {
  503.         promise->Promise(ev, storageUnit, kODPropContents, kind->GetType(ev));    // just promise
  504.     }
  505.     else if (kind->IsPartKind(ev))
  506.     {
  507.         ExternalizeShapeList(ev, storageUnit, cloneInfo, fContentRect.left, fContentRect.top);
  508.         
  509.         if (storageKind == FW_kPartStorage)
  510.         {
  511.             // ----- Write links -----
  512.             CDrawLinkManager* linkMgr = (CDrawLinkManager*) fDrawPart->GetLinkManager(ev);
  513.             linkMgr->ExternalizeLinks(ev, storageUnit, cloneInfo);
  514.         }
  515.     }
  516.     else if (kind->IsEqual(ev, 'PICT', kODPlatformDataType))
  517.     {
  518.         FW_CPicture picture;
  519.         
  520.         {
  521.             FW_CPictureContext pc(ev, picture, fContentRect.Width(), fContentRect.Height());
  522.             
  523.             // ----- Draw all the shapes -----
  524.             CDrawContentShapeIterator ite(this);
  525.             for (CBaseShape *shape = ite.First(); ite.IsNotComplete(); shape = ite.Next())
  526.             {
  527.                 if (shape->GetShapeType() != kProxyShape)
  528.                 {
  529.                     shape->OffsetShape(ev, -fContentRect.left, -fContentRect.top);
  530.                     shape->RenderShape(ev, NULL, pc);
  531.                     shape->OffsetShape(ev, fContentRect.left, fContentRect.top);
  532.                 }
  533.             }
  534.         }
  535.         
  536.         FW_PlatformPict platformPict = picture.GetPlatformPict();
  537.  
  538.         unsigned long pictSize = FW_CMemoryManager::GetSystemHandleSize((FW_PlatformHandle)platformPict);
  539.     
  540.         FW_CAcquireLockedSystemHandle lockedHandle((FW_PlatformHandle)platformPict);
  541.  
  542.         FW_PStorageUnitSink suSink(ev, storageUnit, kODPropContents, kind->GetType(ev));
  543.         FW_CWritableStream stream(suSink);
  544.         stream.Write(lockedHandle.GetPointer(), pictSize);
  545.     }
  546. #ifdef FW_DEBUG
  547.     else
  548.         FW_DEBUG_MESSAGE("CDrawPromiseContent::ExternalizeKind - unkown kind");
  549. #endif
  550. }
  551.  
  552. //----------------------------------------------------------------------------------------
  553. //    CDrawContent::InternalizeKind
  554. //----------------------------------------------------------------------------------------
  555.  
  556. FW_Boolean CDrawContent::InternalizeKind(Environment* ev,
  557.                                             ODStorageUnit* storageUnit, 
  558.                                             FW_CKind* kind,
  559.                                             FW_StorageKinds storageKind,
  560.                                             FW_CCloneInfo* cloneInfo)
  561. {    
  562.     if (kind->IsPartKind(ev))
  563.     {
  564.         // ----- [HLX] force promises to be fulfilled, otherwise bug in locks - OpenDoc Bug???
  565.         if (storageKind != FW_kPartStorage)
  566.         {
  567.             storageUnit->Focus(ev, kODPropContents, kODPosUndefined, kind->GetType(ev), 0, kODPosUndefined);
  568.             storageUnit->GetSize(ev);
  569.         }
  570.         
  571.         InternalizeShapeList(ev, storageUnit, cloneInfo);
  572.     
  573.         // ----- Read links -----
  574.         if (storageKind == FW_kPartStorage)
  575.         {
  576.             CDrawLinkManager* linkMgr = (CDrawLinkManager*)fDrawPart->GetLinkManager(ev);
  577.             linkMgr->InternalizeLinks(ev, storageUnit);
  578.         }
  579.     }
  580. #ifdef FW_DEBUG
  581.     else
  582.         FW_DEBUG_MESSAGE("CDrawPromiseContent::ExternalizeKind - unkown kind");
  583. #endif
  584.  
  585.     return true;
  586. }
  587.  
  588. //----------------------------------------------------------------------------------------
  589. //    CDrawContent::IsDataOnlyOneProxy
  590. //----------------------------------------------------------------------------------------
  591.  
  592. FW_MProxy* CDrawContent::IsDataOnlyOneProxy(Environment* ev) const
  593. {
  594. FW_UNUSED(ev);
  595.     if (fProxyShapeCount == 1 && CountShapes() == 1)    
  596.     {
  597.         CBaseShape* shape = GetFirstShape();
  598.         FW_ASSERT(shape != NULL);
  599.         
  600.         if( shape->GetShapeType() == kGroupShape)
  601.         {
  602.             FW_ASSERT(FW_DYNAMIC_CAST(CGroupShape, shape));
  603.             shape = ((CGroupShape*)shape)->GetFirstShape();
  604.         }
  605.         
  606.         FW_ASSERT(FW_DYNAMIC_CAST(CProxyShape, shape));
  607.         return (CProxyShape*)shape;
  608.     }
  609.     
  610.     return NULL;
  611. }
  612.  
  613. //----------------------------------------------------------------------------------------
  614. //    CDrawContent::AddSingleEmbeddedFrame
  615. //----------------------------------------------------------------------------------------
  616.  
  617. CProxyShape* CDrawContent::AddSingleEmbeddedFrame(Environment* ev, 
  618.                                                   FW_CEmbeddingFrame* scopeFrame,
  619.                                                   ODPart* embeddedPart, 
  620.                                                   ODFrame* embeddedFrame,
  621.                                                   ODShape* suggestedShape,
  622.                                                   ODTypeToken viewType)
  623. {
  624.     // ----- Step 2: Calculate the default shape rect
  625.     FW_CRect shapeRect;
  626.     if (suggestedShape)
  627.     {
  628.         shapeRect = FW_GetShapeBoundingBox(ev, suggestedShape);
  629.         shapeRect.Offset(-shapeRect.left, -shapeRect.top);
  630.     }
  631.     else
  632.     {
  633.         shapeRect.SetInt(0, 0, 80, 80);
  634.     }
  635.  
  636.     // ----- Step 3: Calculate the shape of the embedded frame -----    
  637.     FW_CAcquiredODShape aqFrameShape = ::FW_NewODShape(ev, shapeRect);
  638.     
  639.     // ----- Step 4: Calculate its position -----
  640.     // ----- We are placing it in the middle of the content view -----
  641.     FW_CRect frameBounds = scopeFrame->GetContentView(ev)->GetBoundsInContent(ev);
  642.     shapeRect.PlaceInCenterOf(frameBounds);
  643.     
  644.     // ----- Step 5: Create the proxy shape -----
  645.     CProxyShape* proxyShape = FW_NEW(CProxyShape, (ev, shapeRect, fDrawPart));
  646.     // Make sure that if an exception occurs before we complete this method that
  647.     // we dispose of the shape
  648.     
  649.     FW_TRY
  650.     {
  651.         proxyShape->Embed(ev, 
  652.                         scopeFrame->GetPresentation(ev),
  653.                         embeddedPart, 
  654.                         embeddedFrame,
  655.                         kODFrameObject,        // I want persistent frames
  656.                         aqFrameShape,
  657.                         viewType,
  658.                         NULL,        // no presentation
  659.                         0,            // group id
  660.                         FALSE,        // IsOverlaid
  661.                         FALSE);        // sub frame
  662.     }
  663.     FW_CATCH_BEGIN
  664.     FW_CATCH_EVERYTHING () {
  665.         // cleanup for Step 5
  666.         delete proxyShape;
  667.         FW_THROW_SAME ();
  668.     }
  669.     FW_CATCH_END
  670.  
  671.     // Step 6: ----- Add the shape to our list -----
  672.     this->AddShape(ev, proxyShape);
  673.     
  674.     return proxyShape;
  675. }
  676.  
  677. //========================================================================================
  678. //    class CDrawContentShapeIterator
  679. //========================================================================================
  680.  
  681. //----------------------------------------------------------------------------------------
  682. //    CDrawContentShapeIterator::CDrawContentShapeIterator
  683. //----------------------------------------------------------------------------------------
  684.  
  685. CDrawContentShapeIterator::CDrawContentShapeIterator(CDrawContent* content) :
  686.     CShapeCollectionIterator(content->fShapeList)
  687. {
  688.     FW_END_CONSTRUCTOR
  689. }
  690.  
  691. //----------------------------------------------------------------------------------------
  692. //    CDrawContentShapeIterator::~CDrawContentShapeIterator
  693. //----------------------------------------------------------------------------------------
  694.  
  695. CDrawContentShapeIterator::~CDrawContentShapeIterator()
  696. {
  697.     FW_START_DESTRUCTOR
  698. }
  699.  
  700. //========================================================================================
  701. //    class CSemanticShapeElementIterator
  702. //========================================================================================
  703.  
  704. //----------------------------------------------------------------------------------------
  705. //    CSemanticShapeElementIterator::CSemanticShapeElementIterator
  706. //----------------------------------------------------------------------------------------
  707.  
  708. CSemanticShapeElementIterator::CSemanticShapeElementIterator(CDrawContent* content,
  709.                                                             ODDescType desiredClass) :
  710.     fImplementation(content->fShapeList),
  711.     fDesiredClass(desiredClass)
  712. {
  713.     FW_END_CONSTRUCTOR
  714. }
  715.  
  716. //----------------------------------------------------------------------------------------
  717. //    CSemanticShapeElementIterator::~CSemanticShapeElementIterator
  718. //----------------------------------------------------------------------------------------
  719.  
  720. CSemanticShapeElementIterator::~CSemanticShapeElementIterator()
  721. {
  722.     FW_START_DESTRUCTOR
  723. }
  724.  
  725. //----------------------------------------------------------------------------------------
  726. //    CSemanticShapeElementIterator::First
  727. //----------------------------------------------------------------------------------------
  728.  
  729. FW_MScriptable* CSemanticShapeElementIterator::First()
  730. {
  731.     FW_MScriptable* element = fImplementation.First();
  732.     while (element && !IsDesiredClass(element))
  733.         element = Next();
  734.     
  735.     return element;
  736. }
  737.  
  738. //----------------------------------------------------------------------------------------
  739. //    CSemanticShapeElementIterator::Next
  740. //----------------------------------------------------------------------------------------
  741.  
  742. FW_MScriptable* CSemanticShapeElementIterator::Next()
  743. {
  744.     FW_MScriptable* element = fImplementation.Next();
  745.     while (element && !IsDesiredClass(element))
  746.         element = fImplementation.Next();
  747.     
  748.     return element;
  749. }
  750.  
  751. //----------------------------------------------------------------------------------------
  752. //    CSemanticShapeElementIterator::IsDesiredClass
  753. //----------------------------------------------------------------------------------------
  754.  
  755. FW_Boolean CSemanticShapeElementIterator::IsDesiredClass(FW_MScriptable* element) const
  756. {
  757.     FW_Boolean result;
  758.     
  759.     switch (fDesiredClass)
  760.     {
  761.         case typeWildCard:
  762.         case kShapeClass:
  763.             result = TRUE;
  764.             break;
  765.         
  766.         case cOval:
  767.         case cLine:
  768.         case cRectangle:
  769.         case cRoundedRectangle:
  770.             result = (fDesiredClass == element->GetObjectClass());
  771.             break;
  772.             
  773.         default:
  774.             result = FALSE;
  775.             break;
  776.     }
  777.     
  778.     return result;
  779. }
  780.