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 / FWPresen.cpp < prev    next >
Encoding:
Text File  |  1995-11-08  |  10.6 KB  |  379 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPresen.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 FWPRESEN_H
  13. #include "FWPresen.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWFRAME_H
  21. #include "FWFrame.h"
  22. #endif
  23.  
  24. #ifndef FWSELECT_H
  25. #include "FWSelect.h"
  26. #endif
  27.  
  28. #ifndef FWITERS_H
  29. #include "FWIters.h"
  30. #endif
  31.  
  32. #ifndef FWUTIL_H
  33. #include "FWUtil.h"
  34. #endif
  35.  
  36. #ifndef FWVIEWAS_H
  37. #include "FWViewAs.h"
  38. #endif
  39.  
  40. // ----- OS Layer -----
  41.  
  42. #ifndef FWODGEOM_H
  43. #include "FWODGeom.h"
  44. #endif
  45.  
  46. #ifndef FWWINDOW_H
  47. #include "FWWindow.h"
  48. #endif
  49.  
  50. // ----- Foundation Includes -----
  51.  
  52. #ifndef FWBNDSTR_H
  53. #include "FWBndStr.h"
  54. #endif
  55.  
  56. // ----- OpenDoc Includes -----
  57.  
  58. #ifndef SOM_ODSession_xh
  59. #include <ODSessn.xh>
  60. #endif
  61.  
  62. #ifndef SOM_ODFacet_xh
  63. #include <Facet.xh>
  64. #endif
  65.  
  66. #ifndef SOM_ODShape_xh
  67. #include <Shape.xh>
  68. #endif
  69.  
  70. #ifndef SOM_ODFrame_xh
  71. #include <Frame.xh>
  72. #endif
  73.  
  74. //========================================================================================
  75. // RunTime Info
  76. //========================================================================================
  77.  
  78. #if FW_LIB_EXPORT_PRAGMAS
  79. #pragma lib_export on
  80. #endif
  81.  
  82. #ifdef FW_BUILD_MAC
  83. #pragma segment fwpart2
  84. #endif
  85.  
  86. FW_DEFINE_CLASS_M0(FW_CPresentation)
  87.  
  88. //========================================================================================
  89. //    class FW_CPresentation
  90. //========================================================================================
  91.  
  92. //----------------------------------------------------------------------------------------
  93. //    FW_CPresentation::FW_CPresentation
  94. //----------------------------------------------------------------------------------------
  95.  
  96. FW_CPresentation::FW_CPresentation(Environment *ev, 
  97.                                 FW_CPart* thePart, 
  98.                                 FW_CSelection* selection,
  99.                                 ODTypeToken presentationType,
  100.                                 FW_Boolean sameViewTypeForEmbeddedFrames) :
  101.     fPart(thePart),
  102.     fFrames(NULL),
  103.     fSelection(selection),
  104.     fPresentationType(presentationType),
  105.     fViewInWindowFrame(NULL),
  106.     fViewAsThumbnail(NULL),
  107.     fViewAsSmallIcon(NULL),
  108.     fViewAsLargeIcon(NULL),
  109.     fSameViewTypeForEmbeddedFrames(sameViewTypeForEmbeddedFrames)
  110. {
  111.     FW_ASSERT(thePart);
  112.     
  113.     fFrames = new FW_CPrivOrderedCollection();
  114. }
  115.  
  116. //----------------------------------------------------------------------------------------
  117. //    FW_CPresentation::~FW_CPresentation
  118. //----------------------------------------------------------------------------------------
  119.  
  120. FW_CPresentation::~FW_CPresentation()
  121. {
  122.     FW_ASSERT(fViewAsThumbnail == NULL);        // Should already have been released
  123.     FW_ASSERT(fViewAsSmallIcon == NULL);
  124.     FW_ASSERT(fViewAsLargeIcon == NULL);
  125.  
  126.     delete fSelection;
  127.     
  128.     Environment* ev = somGetGlobalEnvironment();
  129.     
  130.     if (fFrames != NULL)
  131.     {
  132.         FW_CFrame* frame = (FW_CFrame*)fFrames->First();
  133.         while (frame != NULL)
  134.         {
  135.             PrivRemoveFrame(ev, frame);
  136.             frame = (FW_CFrame*)fFrames->First();
  137.         }
  138.         
  139.         delete fFrames;
  140.     }
  141. }
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    FW_CPresentation::Invalidate
  145. //----------------------------------------------------------------------------------------
  146. // invalidShape should be in content coordinates
  147.  
  148. void FW_CPresentation::Invalidate(Environment *ev, ODShape* invalidShape, ODFacet* skipFacet)
  149. {
  150.     FW_CAcquiredODShape aqWrkShape(::FW_NewODShape(ev));
  151.     FW_CPresentationFrameIterator ite(this);
  152.     for (FW_CFrame* frame = ite.First(); ite.IsNotComplete(); frame = ite.Next())
  153.     {
  154.         FW_CAcquiredODTransform aqInternalTransform = frame->AcquireInternalTransform(ev, NULL);
  155.         FW_CFrameFacetIterator facetIte(ev, frame);    
  156.         for (ODFacet* facet = facetIte.First(ev); facetIte.IsNotComplete(ev); facet = facetIte.Next(ev))
  157.         {
  158.             if (facet != skipFacet)
  159.             {
  160.                 if (invalidShape != NULL)
  161.                 {
  162.                     aqWrkShape->CopyFrom(ev, invalidShape);
  163.                     aqWrkShape->Transform(ev, aqInternalTransform);
  164.                     facet->Invalidate(ev, aqWrkShape, NULL);
  165.                 }
  166.                 else
  167.                 {
  168.                     FW_CAcquiredODShape aqClipShape = facet->AcquireAggregateClipShape(ev, NULL);
  169.                     facet->Invalidate(ev, aqClipShape, NULL);
  170.                 }
  171.             }
  172.         }
  173.     }
  174. }
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CPresentation::Validate
  178. //----------------------------------------------------------------------------------------
  179. // validShape should be in content coordinates
  180.  
  181. void FW_CPresentation::Validate(Environment *ev, ODShape* validShape, ODFacet* skipFacet)
  182. {
  183.     FW_CAcquiredODShape aqWrkShape(::FW_NewODShape(ev));
  184.     FW_CPresentationFrameIterator ite(this);
  185.     for (FW_CFrame* frame = ite.First(); ite.IsNotComplete(); frame = ite.Next())
  186.     {
  187.         FW_CAcquiredODTransform aqInternalTransform = frame->AcquireInternalTransform(ev, NULL);
  188.         FW_CFrameFacetIterator iter(ev, frame);    
  189.         for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  190.         {
  191.             if (facet != skipFacet)
  192.             {
  193.                 if (validShape != NULL)
  194.                 {
  195.                     aqWrkShape->CopyFrom(ev, validShape);
  196.                     aqWrkShape->Transform(ev, aqInternalTransform);
  197.                     facet->Validate(ev, aqWrkShape, NULL);
  198.                 }
  199.                 else
  200.                 {
  201.                     FW_CAcquiredODShape aqValidShape = facet->AcquireAggregateClipShape(ev, NULL);
  202.                     facet->Validate(ev, aqValidShape, NULL);
  203.                 }
  204.             }
  205.         }
  206.     }
  207. }
  208.  
  209. //----------------------------------------------------------------------------------------
  210. //    FW_CPresentation::Invalidate
  211. //----------------------------------------------------------------------------------------
  212. // invalidRect should be in content coordinates
  213.  
  214. void FW_CPresentation::Invalidate(Environment* ev, const FW_CRect& invalidRect, ODFacet* skipFacet)
  215. {
  216.     FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, invalidRect);
  217.     Invalidate(ev, aqShape, skipFacet);
  218. }
  219.  
  220. //----------------------------------------------------------------------------------------
  221. //    FW_CPresentation::Validate
  222. //----------------------------------------------------------------------------------------
  223. // validRect should be in content coordinates
  224.  
  225. void FW_CPresentation::Validate(Environment* ev, const FW_CRect& validRect, ODFacet* skipFacet)
  226. {
  227.     FW_CAcquiredODShape aqShape = ::FW_NewODShape(ev, validRect);
  228.     Validate(ev, aqShape, skipFacet);
  229. }
  230.  
  231. //----------------------------------------------------------------------------------------
  232. //    FW_CPresentation::PrivAddFrame
  233. //----------------------------------------------------------------------------------------
  234.  
  235. void FW_CPresentation::PrivAddFrame(Environment *ev, FW_CFrame* frame)
  236. {
  237.     fFrames->AddLast(frame);
  238.     frame->GetODFrame(ev)->Acquire(ev);
  239. }
  240.  
  241. //----------------------------------------------------------------------------------------
  242. //    FW_CPresentation::PrivRemoveFrame
  243. //----------------------------------------------------------------------------------------
  244.  
  245. void FW_CPresentation::PrivRemoveFrame(Environment *ev, FW_CFrame* frame)
  246. {
  247.     if (fViewInWindowFrame == frame)
  248.         fViewInWindowFrame = NULL;
  249.  
  250.     fFrames->Remove(frame);
  251.     frame->PrivReleaseODFrame(ev);
  252. }
  253.  
  254. //----------------------------------------------------------------------------------------
  255. //    FW_CPresentation::CountFrame
  256. //----------------------------------------------------------------------------------------
  257.  
  258. unsigned long FW_CPresentation::CountFrame(Environment *ev) const
  259. {
  260.     return fFrames->Count();
  261. }
  262.  
  263. //----------------------------------------------------------------------------------------
  264. //    FW_CPresentation::Embed
  265. //----------------------------------------------------------------------------------------
  266. // [HLX] need to add exception handling here
  267.  
  268. void FW_CPresentation::Embed(Environment *ev, 
  269.                             ODPart *odEmbeddedPart,
  270.                             ODFrame* odEmbeddedFrame,        // Might be null
  271.                             FW_MProxy* proxy,
  272.                             ODShape* frameShape,
  273.                             ODTypeToken viewType,
  274.                             ODTypeToken presentationType,
  275.                             ODID frameGroupID,
  276.                             FW_Boolean subFrame)
  277. {
  278.     FW_DEBUG_MESSAGE("FW_CPresentation::Embed  Should never have been called");
  279. }
  280.  
  281. //----------------------------------------------------------------------------------------
  282. //    FW_CPresentation::ViewInWindow
  283. //----------------------------------------------------------------------------------------
  284.  
  285. ODID FW_CPresentation::ViewInWindow(Environment* ev, FW_CFrame* sourceFrame, ODFacet* sourceFacet)
  286. {    
  287. FW_ASSERT(sourceFrame);
  288.  
  289.     FW_CWindow* window = NULL;
  290.     
  291.     if (fViewInWindowFrame != NULL)
  292.     {
  293.         window = fViewInWindowFrame->GetWindow(ev);
  294.     }
  295.     else
  296.     {
  297.         if (sourceFacet == NULL)
  298.         {
  299.             FW_CFrameFacetIterator ite(ev, sourceFrame);
  300.             sourceFacet = ite.First(ev);
  301.         }
  302.         FW_ASSERT(sourceFacet != NULL);
  303.         
  304.         window = sourceFrame->NewPartWindow(ev, sourceFacet);                        
  305.         window->Show(ev);    // ATTENTION: Show should be before Select
  306.         
  307.         FW_CAcquiredODWindow odWindow = window->AcquireODWindow(ev);
  308.         
  309.         fViewInWindowFrame = FW_CFrame::ODtoFWFrame(ev, odWindow->GetRootFacet(ev)->GetFrame(ev));
  310.         FW_ASSERT(fViewInWindowFrame != NULL);
  311.     }
  312.         
  313.     window->Select(ev);
  314.     
  315.     return window->GetID(ev);
  316. }
  317.  
  318. //----------------------------------------------------------------------------------------
  319. // FW_CPresentation::AcquireViewAs
  320. //----------------------------------------------------------------------------------------
  321.  
  322. FW_CViewAs* FW_CPresentation::AcquireViewAs(Environment* ev, FW_CFrame* frame, ODTypeToken viewAsToken)
  323. {
  324.     FW_ASSERT(viewAsToken == FW_CPart::gViewAsThumbnailToken ||
  325.             viewAsToken == FW_CPart::gViewAsSmallIconToken ||
  326.             viewAsToken == FW_CPart::gViewAsLargeIconToken);
  327.             
  328.     FW_CViewAs* viewAs = NULL;
  329.     if (viewAsToken == FW_CPart::gViewAsThumbnailToken)
  330.     {
  331.         if (fViewAsThumbnail == NULL)
  332.             fViewAsThumbnail = new FW_CViewAsThumbnail(ev, fPart);
  333.         else
  334.             fViewAsThumbnail->Acquire();
  335.             
  336.         viewAs = fViewAsThumbnail;
  337.     }
  338.     else if (viewAsToken == FW_CPart::gViewAsSmallIconToken)
  339.     {
  340.         if (fViewAsSmallIcon == NULL)
  341.             fViewAsSmallIcon = new FW_CViewAsSmallIcon(ev, fPart);
  342.         else
  343.             fViewAsSmallIcon->Acquire();
  344.             
  345.         viewAs = fViewAsSmallIcon;
  346.     }
  347.     else
  348.     {
  349.         if (fViewAsLargeIcon == NULL)
  350.             fViewAsLargeIcon = new FW_CViewAsLargeIcon(ev, fPart);
  351.         else
  352.             fViewAsLargeIcon->Acquire();
  353.             
  354.         viewAs = fViewAsLargeIcon;
  355.     }
  356.     
  357.     viewAs->Load(ev, frame);
  358.     return viewAs;
  359. }
  360.  
  361. //----------------------------------------------------------------------------------------
  362. // FW_CPresentation::AcquireViewAs
  363. //----------------------------------------------------------------------------------------
  364.  
  365. void FW_CPresentation::ReleaseViewAs(Environment* ev, FW_CViewAs* viewAs)
  366. {
  367.     FW_ASSERT(viewAs == fViewAsThumbnail || viewAs == fViewAsSmallIcon || viewAs == fViewAsLargeIcon);
  368.     
  369.     if (viewAs->Release() == 0)
  370.     {
  371.         if (viewAs == fViewAsThumbnail)
  372.             fViewAsThumbnail = NULL;
  373.         else if (viewAs == fViewAsSmallIcon)
  374.             fViewAsSmallIcon = NULL;
  375.         else
  376.             fViewAsLargeIcon = NULL;
  377.     }
  378. }
  379.