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 / Embed / Sources / Proxy.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  11.2 KB  |  408 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Proxy.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Author:                M.Boetcher
  7. //
  8. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #include "Embed.hpp"
  13.  
  14. // ----- Embed Part Includes -----
  15.  
  16. #ifndef PROXY_H
  17. #include "Proxy.h"
  18. #endif
  19.  
  20. #ifndef PART_H
  21. #include "Part.h"
  22. #endif
  23.  
  24. #ifndef FRAME_H
  25. #include "Frame.h"
  26. #endif
  27.  
  28. #ifndef DEFINES_K
  29. #include "Defines.k"
  30. #endif
  31.  
  32. // ----- ODF Includes -----
  33.  
  34. #ifndef FWFRMING_H
  35. #include "FWFrming.h"
  36. #endif
  37.  
  38. #ifndef FWUTIL_H
  39. #include "FWUtil.h"
  40. #endif
  41.  
  42. #ifndef FWPRESEN_H
  43. #include "FWPresen.h"
  44. #endif
  45.  
  46. #ifndef FWFCTCLP_H
  47. #include "FWFctClp.h"
  48. #endif
  49.  
  50. #ifndef FWODGEOM_H
  51. #include "FWODGeom.h"
  52. #endif
  53.  
  54. #ifndef FWITERS_H
  55. #include "FWIters.h"
  56. #endif
  57.  
  58. #ifndef FWPXYITE_H
  59. #include "FWPxyIte.h"
  60. #endif
  61.  
  62. #ifndef FWMENUS_K
  63. #include "FWMenus.k"
  64. #endif
  65.  
  66. // ----- OpenDoc Includes -----
  67.  
  68. #ifndef SOM_ODShape_xh
  69. #include <Shape.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODTransform_xh
  73. #include <Trnsform.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODSession_xh
  77. #include <ODSessn.xh>
  78. #endif
  79.  
  80. //========================================================================================
  81. // RunTime Info
  82. //========================================================================================
  83.  
  84. #ifdef FW_BUILD_MAC
  85. #pragma segment odfembed
  86. #endif
  87.  
  88. //========================================================================================
  89. //    class CEmbedProxy
  90. //========================================================================================
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    CEmbedProxy constructors
  94. //----------------------------------------------------------------------------------------
  95.  
  96. CEmbedProxy::CEmbedProxy(Environment* ev, CEmbedPart* part) :
  97.     FW_MProxy(ev, part),
  98.     fPart(part)
  99. {
  100. }
  101.  
  102. //----------------------------------------------------------------------------------------
  103. //    CEmbedProxy::~CEmbedProxy
  104. //----------------------------------------------------------------------------------------
  105.  
  106. CEmbedProxy::~CEmbedProxy()
  107. {
  108. }
  109.  
  110. //----------------------------------------------------------------------------------------
  111. //    CEmbedProxy::AdjustBorderShape
  112. //----------------------------------------------------------------------------------------
  113. void CEmbedProxy::AdjustBorderShape(Environment* ev, 
  114.                                     FW_CEmbeddingFrame* embeddingFrame, 
  115.                                     ODFacet* embeddedFacet, 
  116.                                     ODShape* shape)
  117. {
  118. FW_UNUSED(embeddingFrame);
  119. FW_UNUSED(embeddedFacet);
  120.  
  121.     // Don't draw border shape when there are 4 facets because it looks too messy
  122.     if (shape != 0 && fPart->FacetNumber() != cOneFacet)
  123.         shape->Reset(ev);
  124. }
  125.  
  126. //----------------------------------------------------------------------------------------
  127. //    CEmbedProxy::UsedShapeChanged
  128. //----------------------------------------------------------------------------------------
  129. //    Used shape of an embedded frame changed. Just invalidate and recalculate its clip
  130.  
  131. void CEmbedProxy::UsedShapeChanged(Environment* ev,
  132.                                    FW_CEmbeddingFrame* embeddingFrame,
  133.                                    ODFrame* odEmbeddedFrame)
  134. {
  135. FW_UNUSED(odEmbeddedFrame);
  136.  
  137.     // ----- Recalculate the clip -----
  138.     if (fPart->FacetNumber() == cOneFacet)
  139.     {
  140.         // ----- Use the standard facet clipper 
  141.         FW_CFacetClipper clipper;
  142.         clipper.Clip(ev, embeddingFrame);
  143.     }
  144.     else
  145.     {
  146.         //     I cannot use the standard facet clipper because it only works for one facet
  147.         //    Because I know in which order the facets were created I can just iterates 
  148.         FW_CRect clipRects[4];
  149.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  150.         
  151.         short rotation = fPart->GetRotation();
  152.         
  153.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  154.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  155.         {
  156.             short facetID = 0;
  157.             FW_CFacetIterator ite2(ev, facet);
  158.             for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
  159.             {
  160.                 FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
  161.     
  162.                 FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
  163.                 
  164.                 // Update the facet clip shape
  165.                 embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
  166.                 facetID++;
  167.             }
  168.         }
  169.     }
  170.  
  171.     embeddingFrame->Invalidate(ev);
  172. }
  173.  
  174. //----------------------------------------------------------------------------------------
  175. //    CEmbedProxy::RotateFacets
  176. //----------------------------------------------------------------------------------------
  177.  
  178. void CEmbedProxy::RotateFacets(Environment* ev, short rotation)
  179. {
  180.     // Loop on all proxy frames
  181.     FW_CProxyProxyFrameIterator ite(this);
  182.     for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  183.     {
  184.         FW_CEmbeddingFrame* embeddingFrame = proxyFrame->GetContainingFrame(ev);
  185.         if (embeddingFrame == NULL)
  186.             continue;
  187.         
  188.         FW_CRect clipRects[4];
  189.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  190.  
  191.         // Loop on all facets of the embedding frame
  192.         FW_CFrameFacetIterator ite(ev, embeddingFrame);
  193.         for (ODFacet* facet = ite.First(ev); ite.IsNotComplete(ev); facet = ite.Next(ev))
  194.         {
  195.             // Loop on the 4 embedded facets of each embedding facet
  196.             FW_CFacetIterator ite2(ev, facet);
  197.             short facetID = 0;
  198.             for (ODFacet* embeddedFacet = ite2.First(ev); ite2.IsNotComplete(ev); embeddedFacet = ite2.Next(ev))
  199.             {
  200.                 FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRects[facetID]);
  201.                 FW_CAcquiredODShape aqClipShape = FW_NewODShape(ev, clipRects[facetID]);
  202.                 
  203.                 // Change the facet's external transform
  204.                 // [LSD] normally I should not have to set the clip shape here since it 
  205.                 //        doesn't change.  But if I don't do it the facets are not always 
  206.                 //      drawn... OpenDoc bug in ChangeGeometry?
  207.                 embeddedFacet->ChangeGeometry(ev, aqClipShape, externalTransform, NULL);
  208.                 facetID++;
  209.             }
  210.         }
  211.         embeddingFrame->Invalidate(ev);
  212.     }    
  213. }
  214.  
  215. //----------------------------------------------------------------------------------------
  216. //    CEmbedProxy::FrameShapeRequested
  217. //----------------------------------------------------------------------------------------
  218. //    We always want the embedded frame to have our frame shape
  219.  
  220. ODShape* CEmbedProxy::FrameShapeRequested(Environment* ev, 
  221.                                         FW_CEmbeddingFrame* embeddingFrame, 
  222.                                         ODFrame* odEmbeddedFrame, 
  223.                                         ODShape* requestedFrameShape)
  224. {
  225. FW_UNUSED(requestedFrameShape);
  226. FW_UNUSED(odEmbeddedFrame);
  227.  
  228.     return ((CEmbedFrame*)embeddingFrame)->CreateFrameShape(ev);     // No FW_CAcquiredODShape because we are returning it
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    CEmbedProxy::GetExternalTransform
  233. //----------------------------------------------------------------------------------------
  234.  
  235. ODTransform* CEmbedProxy::GetExternalTransform(Environment* ev, short rotation, short facetID, const FW_CRect& clipRect)
  236. {
  237.     FW_CPoint origin(kBorder, kBorder);
  238.     FW_Fixed x = clipRect.Width() + kBorder;
  239.     FW_Fixed y = clipRect.Height() + kBorder;
  240.     
  241.     short position = (rotation + facetID) %4;
  242.     switch (position)
  243.     {
  244.         case 0:
  245.             switch (facetID)
  246.             {
  247.                 case 1:
  248.                     origin.x -= x;
  249.                     break;
  250.                 case 3:
  251.                     origin.y -= y;
  252.                     break;
  253.                 case 2:
  254.                     origin.x -= x;
  255.                     origin.y -= y;
  256.                     break;                    
  257.             }
  258.             break; 
  259.         case 1:
  260.             switch (facetID)
  261.             {
  262.                 case 0:
  263.                     origin.x += x;
  264.                     break;
  265.                 case 3:
  266.                     origin.x += x;
  267.                     origin.y -= y;
  268.                     break;
  269.                 case 2:
  270.                     origin.y -= y;
  271.                     break;                    
  272.             }
  273.             break; 
  274.         case 3:
  275.             switch (facetID)
  276.             {
  277.                 case 0:
  278.                     origin.y += y;
  279.                     break;
  280.                 case 1:
  281.                     origin.x -= x;
  282.                     origin.y += y;
  283.                     break;
  284.                 case 2:
  285.                     origin.x -= x;
  286.                     break;                    
  287.             }
  288.             break; 
  289.         case 2:
  290.             switch (facetID)
  291.             {
  292.                 case 0:
  293.                     origin.x += x;
  294.                     origin.y += y;
  295.                     break;
  296.                 case 1:
  297.                     origin.y += y;
  298.                     break;
  299.                 case 3:
  300.                     origin.x += x;
  301.                     break;                    
  302.             }
  303.             break; 
  304.     }
  305.     
  306.     return ::FW_NewODTransform(ev, origin);
  307. }
  308.  
  309. //----------------------------------------------------------------------------------------
  310. //    CEmbedFrame::CreateOneFacet
  311. //----------------------------------------------------------------------------------------
  312.  
  313. ODFacet* CEmbedProxy::CreateOneFacet(Environment* ev, 
  314.                                     ODFacet* embeddingFacet, 
  315.                                     ODFrame* embeddedFrame, 
  316.                                     ODFacet* sibling,
  317.                                     short rotation,
  318.                                     short facetID,
  319.                                     const FW_CRect& clipRect)
  320. {
  321.     FW_CAcquiredODTransform externalTransform = GetExternalTransform(ev, rotation, facetID, clipRect);
  322.     FW_CAcquiredODShape clipShape = ::FW_NewODShape(ev, clipRect);
  323.     
  324.     return CreateFacet(ev,
  325.                     embeddingFacet,
  326.                     embeddedFrame,
  327.                     clipShape,
  328.                     externalTransform,
  329.                     NULL,                    // Canvas
  330.                     NULL,                    // biasCanvas
  331.                     sibling,                // siblingFacet
  332.                     kODFrameInFront);
  333. }
  334.  
  335. //----------------------------------------------------------------------------------------
  336. //    CEmbedProxy::EmbeddedFacetBounds
  337. //----------------------------------------------------------------------------------------
  338.  
  339. void CEmbedProxy::EmbeddedFacetBounds(Environment* ev, FW_CEmbeddingFrame* frame, FW_CRect* clipRects)
  340. {
  341.     FW_CRect bounds = frame->GetBounds(ev);
  342.     bounds.Place(FW_kFixed0, FW_kFixed0);
  343.     bounds.Inset(kBorder);
  344.  
  345.     FW_CRect embeddedBounds = bounds;
  346.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  347.  
  348.     FW_CPoint embeddedMiddle(FW_Half(embeddedBounds.left + embeddedBounds.right), FW_Half(embeddedBounds.top + embeddedBounds.bottom));
  349.     
  350.     FW_CPoint middle(FW_Half(bounds.left + bounds.right), FW_Half(bounds.top + bounds.bottom));
  351.  
  352.     clipRects[0].Set(FW_kFixed0, FW_kFixed0, embeddedMiddle.x - kHalfBorder, embeddedMiddle.y - kHalfBorder);
  353.     clipRects[1].Set(embeddedMiddle.x + kHalfBorder, FW_kFixed0, embeddedBounds.right, embeddedMiddle.y - kHalfBorder);
  354.     clipRects[2].Set(embeddedMiddle.x + kHalfBorder, embeddedMiddle.y + kHalfBorder, embeddedBounds.right, embeddedBounds.bottom);
  355.     clipRects[3].Set(FW_kFixed0, embeddedMiddle.y + kHalfBorder, embeddedMiddle.x - kHalfBorder, embeddedBounds.bottom);
  356. }
  357.  
  358. //----------------------------------------------------------------------------------------
  359. //    CEmbedProxy::CreateFacets
  360. //----------------------------------------------------------------------------------------
  361.  
  362. short CEmbedProxy::CreateFacets(Environment* ev,
  363.                                 FW_CEmbeddingFrame* embeddingFrame,
  364.                                 ODFacet* embeddingFacet,
  365.                                 ODFrame* embeddedFrame,
  366.                                 ODShape* proposedClipShape)
  367. {
  368. FW_UNUSED(proposedClipShape);
  369.     FW_CRect bounds = embeddingFrame->GetBounds(ev);
  370.     bounds.Place(FW_kFixed0, FW_kFixed0);
  371.     bounds.Inset(kBorder);
  372.  
  373.     FW_CRect embeddedBounds = bounds;
  374.     embeddedBounds.Place(FW_kFixed0, FW_kFixed0);
  375.  
  376.     short nbFacet;
  377.     if (fPart->FacetNumber() == cOneFacet)
  378.     {
  379.         CreateOneFacet(ev, embeddingFacet, embeddedFrame, NULL, 0, 0, embeddedBounds);
  380.         nbFacet = 1;
  381.     }
  382.     else
  383.     {
  384.         FW_CRect clipRects[4];
  385.         EmbeddedFacetBounds(ev, embeddingFrame, clipRects);
  386.         short rotation = fPart->GetRotation();
  387.         
  388.         ODFacet* siblingFacet = NULL;
  389.         for (short facetID = 0; facetID < 4; facetID++)
  390.         {
  391.             ODFacet* newFacet = CreateOneFacet(ev, 
  392.                                                 embeddingFacet, 
  393.                                                 embeddedFrame, 
  394.                                                 siblingFacet,
  395.                                                 rotation,
  396.                                                 facetID,
  397.                                                 clipRects[facetID]);
  398.             if (siblingFacet == NULL)
  399.                 siblingFacet = newFacet;
  400.         }
  401.         
  402.         nbFacet = 4;
  403.     }
  404.     
  405.     return nbFacet;
  406. }
  407.  
  408.