home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWFctClp.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  6.7 KB  |  215 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFctClp.cpp
  4. //    Release Version:    $ 1.0d11 $
  5. //
  6. //    Copyright:    © 1995 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_ODShape_xh
  41. #include <Shape.xh>
  42. #endif
  43.  
  44. //========================================================================================
  45. // RunTime Info
  46. //========================================================================================
  47.  
  48. #if FW_LIB_EXPORT_PRAGMAS
  49. #pragma lib_export on
  50. #endif
  51.  
  52. #ifdef FW_BUILD_MAC
  53. #pragma segment fw_embedding
  54. #endif
  55.  
  56. FW_DEFINE_CLASS_M0(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_ASSERT(part);
  70. }
  71.  
  72. //----------------------------------------------------------------------------------------
  73. //    FW_CFacetClipper::~FW_CFacetClipper
  74. //----------------------------------------------------------------------------------------
  75.  
  76. FW_CFacetClipper::~FW_CFacetClipper()
  77. {
  78. }
  79.  
  80. //----------------------------------------------------------------------------------------
  81. //    FW_CFacetClipper::Clip
  82. //----------------------------------------------------------------------------------------
  83. //    limitShape is in content coordinate
  84.  
  85. void FW_CFacetClipper::Clip(Environment *ev, FW_CPresentation *presentation, ODShape* limitShape)
  86. {
  87.     FW_ASSERT(presentation);
  88.     
  89.     FW_CPresentationFrameIterator ite(presentation);
  90.     for (FW_CEmbeddingFrame* frame = (FW_CEmbeddingFrame*)ite.First(); ite.IsNotComplete(); frame = (FW_CEmbeddingFrame*)ite.Next())
  91.     {
  92.         Clip(ev, frame, limitShape);
  93.     }
  94. }
  95.  
  96. //----------------------------------------------------------------------------------------
  97. //    FW_CFacetClipper::Clip
  98. //----------------------------------------------------------------------------------------
  99. //    limitShape is in content coordinate
  100.  
  101. FW_DECLARE_THROW_POINT (FW_CFacetClipper_Clip);
  102.  
  103. void FW_CFacetClipper::Clip(Environment *ev, FW_CEmbeddingFrame* frame, ODShape* limitShape)
  104. {
  105.     FW_CFrameFacetIterator iter(ev, frame);
  106.     for (ODFacet* facet = (ODFacet*)iter.First(ev); iter.IsNotComplete(ev); facet = (ODFacet*)iter.Next(ev))
  107.     {
  108.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  109.         ClipEmbeddedFacets(ev, frame, facet, limitShape);
  110.         FW_CHECK_THROW_POINT (FW_CFacetClipper_Clip);
  111.     }
  112. }
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    FW_CFacetClipper::ClipEmbeddedFacets
  116. //----------------------------------------------------------------------------------------
  117.  
  118. void FW_CFacetClipper::ClipEmbeddedFacets(Environment *ev, 
  119.                                             FW_CEmbeddingFrame* embeddingFrame, 
  120.                                             ODFacet* containingFacet, 
  121.                                             ODShape* limitShape)
  122. {
  123.     FW_CAcquiredODShape aqLimitShape;
  124.     
  125.     // ----- Transform limitShape to frame coordinate -----
  126.     if (limitShape)
  127.     {
  128.         aqLimitShape = limitShape->Copy(ev);
  129.         FW_CAcquiredODTransform aqContentTransform = embeddingFrame->AcquireInternalTransform(ev, NULL);
  130.         aqLimitShape->Transform(ev, aqContentTransform);
  131.     }
  132.         
  133.     // ----- Use my extent as the start for the working clip shape -----    
  134.     FW_CPoint extent;
  135.     embeddingFrame->GetContentExtent(ev, extent);
  136.     FW_CAcquiredODShape aqWorkingClip = ::FW_NewODShape(ev, FW_CRect(FW_kZeroPoint, extent.x, extent.y));
  137.  
  138.     // ----- Transform it into window coordinate -----
  139.     {
  140.         FW_CAcquiredODTransform aqTransform = containingFacet->AcquireWindowContentTransform(ev, NULL);
  141.         aqWorkingClip->Transform(ev, aqTransform);
  142.     }
  143.     
  144.     FW_CFacetIterator iter(ev, containingFacet, kODChildrenOnly, kODFrontToBack);
  145.     FW_Boolean doIt;
  146.     
  147.     for (ODFacet* embeddedFacet = iter.First(ev);
  148.          iter.IsNotComplete(ev);
  149.          embeddedFacet = iter.Next(ev))
  150.     {
  151.         doIt = TRUE;
  152.  
  153.         if (aqLimitShape != (ODShape*)NULL)
  154.         {
  155.             FW_CAcquiredODShape aqResult(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
  156.             aqResult->Intersect(ev, aqLimitShape);
  157.             doIt = !aqResult->IsEmpty(ev);
  158.         }
  159.         
  160.         if (doIt)
  161.             ClipOneEmbeddedFacet(ev, embeddedFacet, aqWorkingClip);
  162.     }
  163. }
  164.  
  165. //----------------------------------------------------------------------------------------
  166. //    FW_CFacetClipper::ClipOneEmbeddedFacet
  167. //----------------------------------------------------------------------------------------
  168.  
  169. FW_DECLARE_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  170.  
  171. void FW_CFacetClipper::ClipOneEmbeddedFacet(Environment *ev, 
  172.                                             ODFacet* embeddedFacet, 
  173.                                             ODShape* workingClip)
  174. {    
  175.     // Although we don't modify this transform, we need to protect ourself against someone
  176.     // else changing it (in a threaded environment) between the time we use it now (A) and 
  177.     // at the exit of this method (B). This is not efficient.
  178.     FW_CAcquiredODTransform aqTransform = FW_CopyAndRelease (ev, 
  179.         embeddedFacet->AcquireWindowFrameTransform(ev, NULL));
  180.  
  181.     // ----- Transform my working clip to embedded frame coordinates -----
  182.     workingClip->InverseTransform(ev, aqTransform); // (A)
  183.     
  184.     FW_TRY
  185.     { 
  186.         // ----- Set the clip of embFrame -----
  187.         
  188.         FW_CAcquiredODShape aqEmbeddedClipShape(FW_CopyAndRelease(ev, embeddedFacet->GetFrame(ev)->AcquireUsedShape(ev, NULL)));
  189.         FW_CAcquiredODShape aqFrameShape = embeddedFacet->GetFrame(ev)->AcquireFrameShape(ev, NULL);
  190.         
  191.         aqEmbeddedClipShape->Intersect(ev, aqFrameShape);
  192.         aqEmbeddedClipShape->Intersect(ev, workingClip);
  193.         
  194.         FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  195.         
  196.         // This probably won't fail (it will release existing objects and acquire these)
  197.         embeddedFacet->ChangeGeometry(ev, aqEmbeddedClipShape, NULL, NULL);        // Set the clip of the embedded facet. embeddedClipShape is kept by the facet
  198.             
  199.         // ----- remove embeddedClipShape of the working clip -----
  200.         workingClip->Subtract(ev, aqEmbeddedClipShape);
  201.         
  202.         FW_CHECK_THROW_POINT (FW_CFacetClipper_ClipOneEmbeddedFacet);
  203.     }
  204.     FW_CATCH_BEGIN
  205.     FW_CATCH_EVERYTHING () {
  206.         workingClip->Transform(ev, aqTransform); // (B)
  207.         FW_THROW_SAME ();
  208.     }
  209.     FW_CATCH_END
  210.     
  211.     // ----- Put back working clip in window coordinates -----
  212.     workingClip->Transform(ev, aqTransform); // (B)
  213. }
  214.  
  215.