home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc Development Framework / ODFDev / ODF / Framewrk / FWPart / Sources / FWPrstng.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  7.2 KB  |  208 lines  |  [TEXT/MPS ]

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