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

  1. //========================================================================================
  2. //
  3. //    File:                FWPrstng.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 FWPRSTNG_H
  13. #include "FWPrstng.h"
  14. #endif
  15.  
  16. #ifndef FWPARTNG_H
  17. #include "FWPartng.h"
  18. #endif
  19.  
  20. #ifndef FWFRMING_H
  21. #include "FWFrming.h"
  22. #endif
  23.  
  24. #ifndef FWSLCING_H
  25. #include "FWSlcing.h"
  26. #endif
  27.  
  28. #ifndef FWITERS_H
  29. #include "FWIters.h"
  30. #endif
  31.  
  32. #ifndef FWPXYFRM_H
  33. #include "FWPxyFrm.h"
  34. #endif
  35.  
  36. // ----- OpenDoc Includes -----
  37.  
  38. #ifndef SOM_ODSession_xh
  39. #include <ODSessn.xh>
  40. #endif
  41.  
  42. #ifndef SOM_ODShape_xh
  43. #include <Shape.xh>
  44. #endif
  45.  
  46. //========================================================================================
  47. // RunTime Info
  48. //========================================================================================
  49.  
  50. #if FW_LIB_EXPORT_PRAGMAS
  51. #pragma lib_export on
  52. #endif
  53.  
  54. #ifdef FW_BUILD_MAC
  55. #pragma segment fw_embedding
  56. #endif
  57.  
  58. FW_DEFINE_CLASS_M1(FW_CEmbeddingPresentation, FW_CPresentation)
  59.  
  60. //========================================================================================
  61. //    class FW_CEmbeddingPresentation
  62. //========================================================================================
  63.  
  64. //----------------------------------------------------------------------------------------
  65. //    FW_CEmbeddingPresentation::FW_CEmbeddingPresentation
  66. //----------------------------------------------------------------------------------------
  67.  
  68. FW_CEmbeddingPresentation::FW_CEmbeddingPresentation(Environment *ev, 
  69.                                                     FW_CEmbeddingPart* thePart, 
  70.                                                     FW_CEmbeddingSelection* selection,
  71.                                                     ODTypeToken presentationType,
  72.                                                     FW_Boolean sameViewTypeForEmbeddedFrames) :
  73.     FW_CPresentation(ev, thePart, selection, presentationType, sameViewTypeForEmbeddedFrames)
  74. {
  75. }
  76.  
  77. //----------------------------------------------------------------------------------------
  78. //    FW_CEmbeddingPresentation::~FW_CEmbeddingPresentation
  79. //----------------------------------------------------------------------------------------
  80.  
  81. FW_CEmbeddingPresentation::~FW_CEmbeddingPresentation()
  82. {
  83. }
  84.  
  85. //----------------------------------------------------------------------------------------
  86. //    FW_CEmbeddingPresentation::Embed
  87. //----------------------------------------------------------------------------------------
  88.  
  89. FW_DECLARE_THROW_POINT (FW_CEmbeddingPresentation_Embed);
  90.  
  91. void FW_CEmbeddingPresentation::Embed(Environment *ev, 
  92.                                     ODPart *odEmbeddedPart,
  93.                                     ODFrame* odEmbeddedFrame,        // Might be null
  94.                                     FW_MProxy* proxy,
  95.                                     ODShape* frameShape,
  96.                                     ODTypeToken viewType,
  97.                                     ODTypeToken presentationType,
  98.                                     ODID frameGroupID,
  99.                                     FW_Boolean subFrame)
  100. {
  101. /*    Exception Handling
  102.     If an exception is thrown while we are partway through creating frames then we
  103.     have destroy all previously created frames.
  104. */
  105.     FW_ASSERT(odEmbeddedPart);
  106.     FW_ASSERT(frameShape);
  107.     FW_ASSERT(proxy);
  108.     
  109.     ODFrame* passedInFrame = NULL;
  110.     ODFrame* sourceFrame = NULL;
  111.     ODFrame* newEmbeddedFrame = NULL;
  112.         
  113.     // ----- Create an embedded frame for each of my display frame -----        
  114.     FW_TRY { // loop protection
  115.     FW_CPresentationFrameIterator ite(this);
  116.     for (FW_CEmbeddingFrame* embeddingFrame = (FW_CEmbeddingFrame*)ite.First(); ite.IsNotComplete(); embeddingFrame = (FW_CEmbeddingFrame*)ite.Next())
  117.     {
  118.         FW_CAcquiredODShape aqItsShape(frameShape->Copy(ev));
  119.         
  120.         FW_CAcquiredProxyFrame aqProxyFrame;
  121.         
  122.         // ----- Create the frame -----
  123.         FW_Boolean isEmbeddedFrame = FALSE;
  124.         if (odEmbeddedFrame != NULL)
  125.         {
  126.             FW_CAcquiredODFrame aqContainingFrame = odEmbeddedFrame->AcquireContainingFrame(ev);
  127.             isEmbeddedFrame = (aqContainingFrame == embeddingFrame->GetODFrame(ev));
  128.         }
  129.             
  130.         if (isEmbeddedFrame)
  131.         {
  132.             odEmbeddedFrame->SetViewType(ev, viewType);
  133.             odEmbeddedFrame->SetPresentation(ev, presentationType == NULL ? GetPart(ev)->GetSession(ev)->Tokenize(ev, kODPresDefault) : presentationType);
  134.             odEmbeddedFrame->SetFrameGroup(ev, frameGroupID);
  135.             odEmbeddedFrame->SetSubframe(ev, subFrame);
  136.                     
  137.             newEmbeddedFrame = odEmbeddedFrame;
  138.             passedInFrame = odEmbeddedFrame;
  139.             odEmbeddedFrame = NULL;                    // We used it. Next time around we want to create a new frame
  140.             
  141.             aqProxyFrame = new FW_CProxyFrame(ev, (FW_CEmbeddingPart*)GetPart(ev), proxy, embeddingFrame, newEmbeddedFrame);
  142.             
  143.             // Change the frame shape after we have a proxyFrame (only if neccessary)
  144.             FW_CAcquiredODShape aqFrameShape = newEmbeddedFrame->AcquireFrameShape(ev, NULL);
  145.             if (!aqFrameShape->IsSameAs(ev, aqItsShape))
  146.                 newEmbeddedFrame->ChangeFrameShape(ev, aqItsShape, NULL);
  147.         }
  148.         else
  149.         {
  150.             aqProxyFrame = embeddingFrame->PrivCreateEmbeddedFrame(ev, 
  151.                                                                 embeddingFrame->IsPersistent(ev) ? kODFrameObject : kODNonPersistentFrameObject, 
  152.                                                                 odEmbeddedPart,
  153.                                                                 proxy, 
  154.                                                                 aqItsShape, 
  155.                                                                 NULL, 
  156.                                                                 viewType, 
  157.                                                                 presentationType, 
  158.                                                                 frameGroupID, 
  159.                                                                 FALSE, 
  160.                                                                 subFrame);
  161.             newEmbeddedFrame = aqProxyFrame->GetFrame(ev);
  162.         }
  163.         
  164.         FW_TRY
  165.         {
  166.             // ----- Attach source frames if needed -----
  167.             // If we are creating two or more frames at the same time then this tells the embedded part
  168.             // that those frames are supposed to display the same content.
  169.             if (sourceFrame)
  170.                 odEmbeddedPart->AttachSourceFrame(ev, newEmbeddedFrame, sourceFrame);
  171.             sourceFrame = newEmbeddedFrame;
  172.             
  173.             // ----- Create its facets -----
  174.             // We have to make sure not to leave a dangling frame if this fails
  175.             FW_CHECK_THROW_POINT (FW_CEmbeddingPresentation_Embed);
  176.             // XXX if isEmbedded frame then we shouldn't destroy it (since we didn't create it)            
  177.             embeddingFrame->PrivCreateEmbeddedFacets(ev, proxy, aqProxyFrame);
  178.         }
  179.         FW_CATCH_BEGIN
  180.         FW_CATCH_EVERYTHING () {
  181.             // aqProxyFrame has increased the refount of the proxy frame; this will bother
  182.             // the PrivRemoveEmbeddedFrame code, which asserts it to be 1 at some point.
  183.             FW_CProxyFrame * proxyFrame = aqProxyFrame;
  184.             aqProxyFrame = (FW_CProxyFrame*) kODNULL;
  185.             embeddingFrame->PrivRemoveEmbeddedFrame (ev, proxyFrame);
  186.             FW_THROW_SAME ();
  187.         }
  188.         FW_CATCH_END
  189.     }
  190.     } // FW_TRY loop protection
  191.     FW_CATCH_BEGIN
  192.     FW_CATCH_EVERYTHING () {
  193.         // Work in reverse to clean up everything from previous passes through the loop. 
  194.         // That is if we completed two loops and failed partway through loop 3, assume that loop 3
  195.         // was cleaned up properly (in try/catch block above) and undo loops 1 and 2.
  196.         // XXX Should we release passedInFrame since we didn't create it?
  197.         // XXX not implemented
  198.         FW_THROW_SAME ();
  199.     }
  200.     FW_CATCH_END
  201.     
  202.     // ----- If we haven't use odEmbeddedFrame there is a problem -----
  203.     FW_ASSERT(odEmbeddedFrame == NULL);
  204. }
  205.