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 / ODF / Framewrk / FWPart / Sources / FWFctClp.cpp < prev    next >
Encoding:
Text File  |  1996-08-16  |  8.2 KB  |  252 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFctClp.cpp
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFCTCLP_H
  13. #include "FWFctClp.h"
  14. #endif
  15.  
  16. #ifndef FWITERS_H
  17. #include "FWIters.h"
  18. #endif
  19.  
  20. #ifndef FWFRMING_H
  21. #include "FWFrming.h"
  22. #endif
  23.  
  24. #ifndef FWUTIL_H
  25. #include "FWUtil.h"
  26. #endif
  27.  
  28. #ifndef FWPRTITE_H
  29. #include "FWPrtIte.h"
  30. #endif
  31.  
  32. // ----- OS Includes -----
  33.  
  34. #ifndef FWODGEOM_H
  35. #include "FWODGeom.h"
  36. #endif
  37.  
  38. // ----- OpenDoc Includes -----
  39.  
  40. #ifndef SOM_ODFacet_xh
  41. #include <Facet.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODShape_xh
  45. #include <Shape.xh>
  46. #endif
  47.  
  48. //========================================================================================
  49. // RunTime Info
  50. //========================================================================================
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment fw_embedding
  54. #endif
  55.  
  56. FW_DEFINE_AUTO(FW_CFacetClipper)
  57.  
  58. //========================================================================================
  59. //    class FW_CFacetClipper
  60. //========================================================================================
  61.  
  62. //----------------------------------------------------------------------------------------
  63. //    FW_CFacetClipper::FW_CFacetClipper
  64. //----------------------------------------------------------------------------------------
  65.  
  66. FW_CFacetClipper::FW_CFacetClipper(Environment* ev, FW_CPart* part):
  67.     fPart(part)
  68. {
  69. FW_UNUSED(ev);
  70.     FW_ASSERT(part);
  71. }
  72.  
  73. //----------------------------------------------------------------------------------------
  74. //    FW_CFacetClipper::~FW_CFacetClipper
  75. //----------------------------------------------------------------------------------------
  76.  
  77. FW_CFacetClipper::~FW_CFacetClipper()
  78. {
  79. }
  80.  
  81. //----------------------------------------------------------------------------------------
  82. //    FW_CFacetClipper::Clip
  83. //----------------------------------------------------------------------------------------
  84. //    limitShape is in content coordinate
  85.  
  86. void FW_CFacetClipper::Clip(Environment *ev, FW_CPresentation *presentation, ODShape* limitShape)
  87. {
  88.     FW_ASSERT(presentation);
  89.     
  90.     FW_CPresentationFrameIterator ite(ev, presentation);
  91.     for (FW_CEmbeddingFrame* frame = (FW_CEmbeddingFrame*)ite.First(ev); ite.IsNotComplete(ev); frame = (FW_CEmbeddingFrame*)ite.Next(ev))
  92.     {
  93.         Clip(ev, frame, limitShape);
  94.     }
  95. }
  96.  
  97. //----------------------------------------------------------------------------------------
  98. //    FW_CFacetClipper::Clip
  99. //----------------------------------------------------------------------------------------
  100. //    limitShape is in content coordinate
  101.  
  102. FW_DECLARE_THROW_POINT (FW_CFacetClipper_Clip);
  103.  
  104. void FW_CFacetClipper::Clip(Environment *ev, FW_CEmbeddingFrame* frame, ODShape* limitShape)
  105. {
  106.     FW_CFrameFacetIterator iter(ev, frame);
  107.     for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  108.     {
  109.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  110.         ClipEmbeddedFacets(ev, frame, facet, limitShape);
  111.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  112.     }
  113. }
  114.  
  115. //----------------------------------------------------------------------------------------
  116. //    FW_CFacetClipper::ClipEmbeddedFacets
  117. //----------------------------------------------------------------------------------------
  118.  
  119. void FW_CFacetClipper::ClipEmbeddedFacets(Environment *ev, 
  120.                                             FW_CEmbeddingFrame* embeddingFrame, 
  121.                                             ODFacet* containingFacet, 
  122.                                             ODShape* limitShape)
  123. {
  124.     FW_CAcquiredODShape aqLimitShape;
  125.  
  126.     // ----- Transform limitShape to frame coordinate -----
  127.     if (limitShape)
  128.     {
  129.         aqLimitShape = limitShape->Copy(ev);
  130.         FW_ContentToFrame(ev, embeddingFrame->GetODFrame(ev), aqLimitShape);
  131.         aqLimitShape->SetGeometryMode(ev, kODLoseGeometry);
  132.     }
  133.  
  134.     // ----- Calculate the working clip and intersect it with the limitShape -----
  135.     FW_CAcquiredODShape aqWorkingClip = AcquireWorkingClip(ev, embeddingFrame, containingFacet, aqLimitShape);
  136.     
  137.     // ----- Now iterates -----    
  138.     FW_CFacetIterator iter(ev, containingFacet, kODChildrenOnly, kODFrontToBack);
  139.     FW_Boolean doIt;
  140.     
  141.     for (ODFacet* embeddedFacet = iter.First(ev);
  142.          iter.IsNotComplete(ev);
  143.          embeddedFacet = iter.Next(ev))
  144.     {
  145.         doIt = TRUE;
  146.  
  147.         if (aqLimitShape != (ODShape*)NULL)
  148.         {
  149.             FW_CAcquiredODShape aqResult(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
  150.             
  151.             FW_CAcquiredODTransform aqTransform = embeddedFacet->AcquireExternalTransform(ev, NULL);
  152.             aqResult->Transform(ev, aqTransform);    // containing Frame Coordinate
  153.             
  154.             aqResult->SetGeometryMode(ev, kODLoseGeometry);
  155.  
  156.             aqResult->Intersect(ev, aqLimitShape);
  157.         
  158.             doIt = !aqResult->IsEmpty(ev);
  159.         }
  160.         
  161.         if (doIt)
  162.             ClipOneEmbeddedFacet(ev, embeddedFacet, aqWorkingClip);
  163.     }
  164. }
  165.  
  166. //----------------------------------------------------------------------------------------
  167. //    FW_CFacetClipper::ClipOneEmbeddedFacet
  168. //----------------------------------------------------------------------------------------
  169.  
  170. FW_DECLARE_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  171.  
  172. void FW_CFacetClipper::ClipOneEmbeddedFacet(Environment *ev, 
  173.                                             ODFacet* embeddedFacet, 
  174.                                             ODShape* workingClip)
  175. {    
  176.     // Although we don't modify this transform, we need to protect ourself against someone
  177.     // else changing it (in a threaded environment) between the time we use it now (A) and 
  178.     // at the exit of this method (B). This is not efficient.
  179.     FW_CAcquiredODTransform aqTransform = FW_CopyAndRelease (ev, 
  180.         embeddedFacet->AcquireWindowFrameTransform(ev, NULL));
  181.  
  182.     // ----- Transform my working clip to embedded frame coordinates -----
  183.     workingClip->InverseTransform(ev, aqTransform); // (A)
  184.     
  185.     FW_TRY
  186.     { 
  187.         // ----- Set the clip of embFrame -----
  188.         
  189.         FW_CAcquiredODShape aqEmbeddedClipShape(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
  190.         aqEmbeddedClipShape->SetGeometryMode(ev, kODLoseGeometry);
  191.         FW_CAcquiredODShape aqFrameShape = FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireFrameShape(ev, NULL));
  192.         aqFrameShape->SetGeometryMode(ev, kODLoseGeometry);
  193.     
  194.         aqEmbeddedClipShape->Intersect(ev, aqFrameShape);
  195.         aqEmbeddedClipShape->Intersect(ev, workingClip);
  196.         
  197.         FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  198.         
  199.         // This probably won't fail (it will release existing objects and acquire these)
  200.         embeddedFacet->ChangeGeometry(ev, aqEmbeddedClipShape, NULL, NULL);        // Set the clip of the embedded facet. embeddedClipShape is kept by the facet
  201.         
  202.         // ----- remove embeddedClipShape of the working clip -----
  203.         workingClip->Subtract(ev, aqEmbeddedClipShape);
  204.         
  205.         FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  206.     }
  207.     FW_CATCH_BEGIN
  208.     FW_CATCH_EVERYTHING () {
  209.         workingClip->Transform(ev, aqTransform); // (B)
  210.         FW_THROW_SAME ();
  211.     }
  212.     FW_CATCH_END
  213.     
  214.     // ----- Put back working clip in window coordinates -----
  215.     workingClip->Transform(ev, aqTransform); // (B)
  216. }
  217.  
  218. //----------------------------------------------------------------------------------------
  219. //    FW_CFacetClipper::AcquireWorkingClip
  220. //----------------------------------------------------------------------------------------
  221. // returns the working clip and intersect it with limitshape (Frame coordinate)
  222.  
  223. ODShape* FW_CFacetClipper::AcquireWorkingClip(Environment *ev, 
  224.                                              FW_CEmbeddingFrame* embeddingFrame, 
  225.                                              ODFacet* containingFacet,
  226.                                              ODShape* limitShape)
  227. {
  228.     FW_CPoint extent;
  229.     embeddingFrame->GetContentExtent(ev, extent);
  230.     FW_CRect extentRect(FW_kFixed0, FW_kFixed0, extent.x, extent.y);
  231.  
  232.     // ----- Create the working clip (use the content shape or extent rect if static canvas) -----
  233.     ODShape* workingClip;
  234.     if (containingFacet->GetCanvas(ev)->IsDynamic(ev))
  235.         workingClip = embeddingFrame->AcquireContentShape(ev);    // in Frame Coordinate
  236.     else
  237.     {
  238.         embeddingFrame->GetContentView(ev)->ViewContentToFrame(ev, extentRect);
  239.         workingClip = ::FW_NewODShape(ev, extentRect);
  240.     }
  241.     workingClip->SetGeometryMode(ev, kODLoseGeometry);
  242.     
  243.     if (limitShape)
  244.         limitShape->Intersect(ev, workingClip);
  245.     
  246.     // ----- Transform it into window coordinate -----
  247.     FW_CAcquiredODTransform aqWindowContentTransform(containingFacet->AcquireWindowFrameTransform(ev, NULL));
  248.     workingClip->Transform(ev, aqWindowContentTransform);        // now in window coordinate
  249.     
  250.     return workingClip;
  251. }
  252.