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 / ODF / Framewrk / FWPart / FWFrming.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  23.1 KB  |  745 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFrming.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWFrameW.hpp"
  11.  
  12. #ifndef FWFRMING_H
  13. #include "FWFrming.h"
  14. #endif
  15.  
  16. #ifndef FWPARTNG_H
  17. #include "FWPartng.h"
  18. #endif
  19.  
  20. #ifndef FWPXYFRM_H
  21. #include "FWPxyFrm.h"
  22. #endif
  23.  
  24. #ifndef FWPROXY_H
  25. #include "FWProxy.h"
  26. #endif
  27.  
  28. #ifndef FWUTIL_H
  29. #include "FWUtil.h"
  30. #endif
  31.  
  32. #ifndef FWITERS_H
  33. #include "FWIters.h"
  34. #endif
  35.  
  36. #ifndef FWPRESEN_H
  37. #include "FWPresen.h"
  38. #endif
  39.  
  40. #ifndef FWSELECT_H
  41. #include "FWSelect.h"
  42. #endif
  43.  
  44. #ifndef FWTRACKR_H
  45. #include "FWTrackr.h"
  46. #endif
  47.  
  48. #ifndef FWPRTITE_H
  49. #include "FWPrtIte.h"
  50. #endif
  51.  
  52. #ifndef FWFILEOP_H
  53. #include "FWFileOp.h"
  54. #endif
  55.  
  56. #ifndef FWEMBUTL_H
  57. #include "FWEmbUtl.h"
  58. #endif
  59.  
  60. #ifndef FWPXYITE_H
  61. #include "FWPxyIte.h"
  62. #endif
  63.  
  64. #ifndef FWINSCMD_H
  65. #include "FWInsCmd.h"
  66. #endif
  67.  
  68. #ifndef FWSESION_H
  69. #include "FWSesion.h"
  70. #endif
  71.  
  72. // ----- OS Layer -----
  73.  
  74. #ifndef FWODGEOM_H
  75. #include "FWODGeom.h"
  76. #endif
  77.  
  78. #ifndef FWMNUBAR_H
  79. #include "FWMnuBar.h"
  80. #endif
  81.  
  82. #ifndef FWEVENT_H
  83. #include "FWEvent.h"
  84. #endif
  85.  
  86. #ifndef FWCURSOR_H
  87. #include "FWCursor.h"
  88. #endif
  89.  
  90. #ifndef SLODFSTR_H
  91. #include "SLODFStr.h"
  92. #endif
  93.  
  94. #ifndef SLODFSTR_K
  95. #include "SLODFStr.k"
  96. #endif
  97.  
  98. // ----- OpenDoc Includes -----
  99.  
  100. #ifndef SOM_ODArbitrator_xh
  101. #include <Arbitrat.xh>
  102. #endif
  103.  
  104. #ifndef SOM_Module_OpenDoc_Commands_defined
  105. #include <CmdDefs.xh>
  106. #endif
  107.  
  108. #ifndef SOM_ODDispatcher_xh
  109. #include <Disptch.xh>
  110. #endif
  111.  
  112. #ifndef SOM_ODDraft_xh
  113. #include <Draft.xh>
  114. #endif
  115.  
  116. #ifndef SOM_ODFacet_xh
  117. #include <Facet.xh>
  118. #endif
  119.  
  120. #ifndef SOM_ODInfo_xh
  121. #include <Info.xh>
  122. #endif
  123.  
  124. #ifndef SOM_ODSession_xh
  125. #include <ODSessn.xh>
  126. #endif
  127.  
  128. //========================================================================================
  129. // RunTime Info
  130. //========================================================================================
  131.  
  132. #ifdef FW_BUILD_MAC
  133. #pragma segment fw_embedding
  134. #endif
  135.  
  136. FW_DEFINE_CLASS_M1(FW_CEmbeddingFrame, FW_CFrame)
  137. FW_DEFINE_AUTO(FW_CEmbeddingFrame)
  138.  
  139. //========================================================================================
  140. //    class FW_CEmbeddingFrame
  141. //========================================================================================
  142.  
  143. //----------------------------------------------------------------------------------------
  144. //    FW_CEmbeddingFrame::FW_CEmbeddingFrame
  145. //----------------------------------------------------------------------------------------
  146.  
  147. FW_CEmbeddingFrame::FW_CEmbeddingFrame(Environment* ev,
  148.                                         ODFrame* odFrame, 
  149.                                         FW_CPresentation* presentation,
  150.                                         FW_CEmbeddingPart* part) :
  151.     FW_CFrame(ev, odFrame, presentation, part)
  152. {
  153. }
  154.  
  155. //----------------------------------------------------------------------------------------
  156. //    FW_CEmbeddingFrame::~FW_CEmbeddingFrame
  157. //----------------------------------------------------------------------------------------
  158.  
  159. FW_CEmbeddingFrame::~FW_CEmbeddingFrame()
  160. {
  161. }
  162.  
  163. //----------------------------------------------------------------------------------------
  164. //    FW_CEmbeddingFrame::EmbeddedFrameRequested    
  165. //----------------------------------------------------------------------------------------
  166. // Override should return a proxy and a modified suggestedFrameShape
  167.  
  168. FW_MProxy* FW_CEmbeddingFrame::EmbeddedFrameRequested(Environment *ev,
  169.                                                     FW_MProxy* baseProxy,
  170.                                                     ODFrame* baseFrame,
  171.                                                     ODShape* frameShape,
  172.                                                     ODPart* embeddedPart,
  173.                                                     ODTypeToken viewType,
  174.                                                     ODTypeToken presentation,
  175.                                                     ODID frameGroupID,
  176.                                                     FW_Boolean isOverlaid,
  177.                                                     FW_Boolean isSubFrame)
  178. {
  179. FW_UNUSED(ev);
  180. FW_UNUSED(baseProxy);
  181. FW_UNUSED(baseFrame);
  182. FW_UNUSED(frameShape);
  183. FW_UNUSED(embeddedPart);
  184. FW_UNUSED(viewType);
  185. FW_UNUSED(presentation);
  186. FW_UNUSED(frameGroupID);
  187. FW_UNUSED(isOverlaid);
  188. FW_UNUSED(isSubFrame);
  189.  
  190.     return NULL;
  191. }
  192.  
  193. //----------------------------------------------------------------------------------------
  194. //    FW_CEmbeddingFrame::GetProxy    
  195. //----------------------------------------------------------------------------------------
  196.  
  197. FW_MProxy* FW_CEmbeddingFrame::GetProxy(Environment *ev, ODFrame* embeddedFrame) const
  198. {
  199.     return ((FW_CEmbeddingPart*)GetPart(ev))->GetProxy(ev, embeddedFrame);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    FW_CEmbeddingFrame::PrivCreateEmbeddedFrame
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_DECLARE_THROW_POINT (FW_CEmbeddingFrame_PrivCreateEmbeddedFrame);
  207.  
  208. ODFrame* FW_CEmbeddingFrame::PrivCreateEmbeddedFrame(Environment* ev,
  209.                                                         ODType frameType,
  210.                                                         ODPart *embeddedODPart,
  211.                                                         ODShape* frameShape,    
  212.                                                         ODCanvas* biasCanvas,    // can be null
  213.                                                         ODTypeToken viewType,
  214.                                                         ODTypeToken presentationType,
  215.                                                         FW_Boolean isOverlaid,
  216.                                                         FW_Boolean subFrame)
  217. {
  218.     FW_ASSERT(embeddedODPart);
  219.     
  220.     if (presentationType == 0)
  221.         presentationType = FW_CSession::Tokenize(ev, kODPresDefault);
  222.         
  223.     // ----- Normalize the frameShape -----
  224.     FW_CRect box;
  225.     frameShape->GetBoundingBox(ev, (ODRect*)&box);
  226.     if (box.TopLeft() != FW_kZeroPoint)
  227.     {
  228.         FW_CAcquiredODTransform temp = ::FW_NewODTransform(ev, -box.TopLeft());
  229.         frameShape->Transform(ev, temp);
  230.     }
  231.     
  232.     // ----- create the new frame
  233.     ODFrame* embeddedODFrame = GetPart(ev)->GetDraft(ev)->CreateFrame(ev, 
  234.                                                                     frameType,
  235.                                                                     GetODFrame(ev), 
  236.                                                                     frameShape, 
  237.                                                                     biasCanvas,
  238.                                                                     embeddedODPart, 
  239.                                                                     viewType, 
  240.                                                                     presentationType, 
  241.                                                                     subFrame, 
  242.                                                                     isOverlaid);
  243.                                                             
  244.     // Testing: can the caller deal with this method failing?
  245.     FW_CHECK_THROW_POINT (FW_CEmbeddingFrame_PrivCreateEmbeddedFrame);
  246.     
  247.     return embeddedODFrame;
  248. }
  249.  
  250. //----------------------------------------------------------------------------------------
  251. //    FW_CEmbeddingFrame::GetPart
  252. //----------------------------------------------------------------------------------------
  253.  
  254. FW_CEmbeddingPart* FW_CEmbeddingFrame::GetPart(Environment *ev) const
  255. {
  256.     return (FW_CEmbeddingPart*)FW_CFrame::GetPart(ev);
  257. }
  258.  
  259. //----------------------------------------------------------------------------------------
  260. //    FW_CEmbeddingFrame::FrameAdded
  261. //----------------------------------------------------------------------------------------
  262.  
  263. void FW_CEmbeddingFrame::FrameAdded(Environment* ev, ODFrame* odFrame, FW_Boolean fromStorage)
  264. {
  265.     // ----- Call inherited -----
  266.     FW_CFrame::FrameAdded(ev, odFrame, fromStorage);
  267.  
  268.     if (!fromStorage)
  269.     {
  270.         // Set the containing frame of any orphan embedded frames
  271.         FW_CPartProxyFrameIterator ite(GetPart(ev));
  272.         for (FW_CProxyFrame* proxyFrame = ite.First(); ite.IsNotComplete(); proxyFrame = ite.Next())
  273.         {
  274.             if (proxyFrame->IsOrphan(ev))
  275.                 proxyFrame->SetContainingFrame(ev, this);
  276.         }
  277.     }
  278. }
  279.  
  280. //----------------------------------------------------------------------------------------
  281. //    FW_CEmbeddingFrame::PrivAttachSourceFrame
  282. //----------------------------------------------------------------------------------------
  283. //    FW_CEmbeddingFrame::AttachSourceFrame should not be called if sourceFrame == NULL
  284.  
  285. void FW_CEmbeddingFrame::PrivAttachSourceFrame(Environment* ev, FW_CFrame* sourceFrame)
  286. {
  287.     // Call inherited first to set the fSourceFrame field
  288.     FW_CFrame::PrivAttachSourceFrame(ev, sourceFrame);
  289.     
  290.     FW_ASSERT(sourceFrame != NULL);
  291.  
  292.     // ----- If I am an embedding frame, sourceFrame must be too
  293.     FW_CEmbeddingFrame* embeddingSourceFrame = FW_DYNAMIC_CAST(FW_CEmbeddingFrame, sourceFrame);
  294.     FW_ASSERT(embeddingSourceFrame);
  295.  
  296.     // ----- Duplicate all the embedded frames of sourceFrame -----
  297.     // ----- PrivCreateEmbeddedFrame doesn't create facets, wait for FacetAdded to duplicate my facets -----
  298.     FW_CFrameProxyFrameIterator iter(ev, embeddingSourceFrame);
  299.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  300.     {    
  301.         FW_Boolean wasInMemory = proxyFrame->IsFrameInMemory(ev);
  302.         
  303.         // ----- get the embedded frame -----
  304.         ODFrame* odEmbeddedSourceFrame = proxyFrame->GetFrame(ev);        
  305.         
  306.         // ----- get the embedded part -----
  307.         FW_CAcquiredODPart aqODEmbeddedPart = odEmbeddedSourceFrame->AcquirePart(ev);
  308.     
  309.         // ----- Create the embedded Frame (proxyFrame) -----
  310.         FW_CAcquiredODShape aqFrameShapeCopy(FW_CopyAndRelease(ev, odEmbeddedSourceFrame->AcquireFrameShape(ev, NULL)));
  311.         
  312.         FW_CAcquiredODFrame embeddedODFrame = PrivCreateEmbeddedFrame(ev,
  313.                                                             kODFrameObject,    // Always create embedded frames persistent
  314. //                                                            IsPersistent(ev) ? kODFrameObject : kODNonPersistentFrameObject,
  315.                                                             aqODEmbeddedPart,
  316.                                                             aqFrameShapeCopy,
  317.                                                             NULL,                                    // bias Canvas
  318.                                                             odEmbeddedSourceFrame->GetViewType(ev),
  319.                                                             odEmbeddedSourceFrame->GetPresentation(ev),
  320.                                                             odEmbeddedSourceFrame->IsOverlaid(ev),
  321.                                                             odEmbeddedSourceFrame->IsSubframe(ev));
  322.         
  323.         // ----- Create the proxyFrame -----
  324.         FW_CProxyFrame* newProxyFrame = proxyFrame->GetProxy(ev)->PrivNewProxyFrame(ev, GetPart(ev), this, embeddedODFrame, FALSE);
  325.  
  326.         // ----- Set the frame group
  327.         newProxyFrame->PrivSetFrameGroup(ev, odEmbeddedSourceFrame->GetFrameGroup(ev));
  328.         
  329.         // ----- Notify the Embedded frame-----
  330.         aqODEmbeddedPart->AttachSourceFrame(ev, newProxyFrame->GetFrame(ev), odEmbeddedSourceFrame);
  331.                 
  332.         // ----- If was not in memory Release back the embedded frame -----
  333.         if (!wasInMemory)
  334.             proxyFrame->Release(ev);
  335.     }
  336. }
  337.  
  338. //----------------------------------------------------------------------------------------
  339. //    FW_CEmbeddingFrame::PrivRemoveEmbeddedFrame
  340. //----------------------------------------------------------------------------------------
  341.  
  342. void FW_CEmbeddingFrame::PrivRemoveEmbeddedFrame(Environment* ev, FW_CProxyFrame* proxyFrame)
  343. {
  344.     //     If called means that the embedded frame is in memory
  345.     //    Be sure it is in memory
  346.     ODFrame* odEmbeddedFrame = proxyFrame->GetFrame(ev);
  347.  
  348.     // ----- Detach the proxyframe -----
  349.     proxyFrame->PrivDetach(ev);
  350.  
  351.     // ----- remove it from the proxy (will delete it) -----
  352.     proxyFrame->GetProxy(ev)->PrivDeleteProxyFrame(ev, proxyFrame);
  353. }
  354.  
  355. //----------------------------------------------------------------------------------------
  356. //    FW_CEmbeddingFrame::FrameRemoved
  357. //----------------------------------------------------------------------------------------
  358. //    I should not have to worry about my embedded facets because before the frame is removed
  359. //    its facets should have been removed, removing the embedded facets
  360.  
  361. void FW_CEmbeddingFrame::FrameRemoved(Environment* ev, FW_Boolean toStorage)
  362. {
  363.     // ----- Collect the proxyFrames in a temporary collections -----
  364.     FW_TOrderedCollection<FW_CProxyFrame> tempCollect;
  365.     FW_CProxyFrame*  proxyFrame;
  366.     
  367.     FW_CFrameProxyFrameIterator ite1(ev, this);
  368.     for (proxyFrame = ite1.First(ev); ite1.IsNotComplete(ev); proxyFrame = ite1.Next(ev))
  369.     {
  370.         tempCollect.AddLast(proxyFrame);
  371.     }
  372.  
  373.     // ----- Now we can call close or remove
  374.     FW_TOrderedCollectionIterator<FW_CProxyFrame> ite2(&tempCollect);
  375.     for (proxyFrame = ite2.First(); ite2.IsNotComplete(); proxyFrame = ite2.Next())
  376.     {
  377.         if (toStorage)
  378.             proxyFrame->PrivClose(ev);
  379.         else
  380.             this->PrivRemoveEmbeddedFrame(ev, proxyFrame);
  381.     }
  382.     
  383.     // Don't have to call tempCollect.RemoveAll() because the __dt does it
  384.     
  385.     // ----- Call inherited -----
  386.     FW_CFrame::FrameRemoved(ev, toStorage);
  387. }
  388.  
  389. //----------------------------------------------------------------------------------------
  390. //    FW_CEmbeddingFrame::FacetAdded
  391. //----------------------------------------------------------------------------------------
  392. //    When overridden call inherited::FacetAdded FIRST
  393.  
  394. void FW_CEmbeddingFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  395. {    
  396.     // ----- Call inherited first
  397.     FW_CFrame::FacetAdded(ev, facet, facetCount);
  398.     
  399.     // ----- Add facets to each one of my embedded frame (that are in memory) -----
  400.     if (GetViewType(ev) == FW_CPart::fgViewAsFrameToken)
  401.     {
  402.         FW_CFrameProxyFrameIterator ite(ev, this);
  403.         for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  404.         {
  405.             proxyFrame->CreateFacets(ev, this, facet);
  406.         }
  407.     }
  408. }
  409.  
  410. //----------------------------------------------------------------------------------------
  411. //    FW_CEmbeddingFrame::FacetRemoved
  412. //----------------------------------------------------------------------------------------
  413. //    When overridden call inherited::FacetRemoved LAST
  414.  
  415. void FW_CEmbeddingFrame::FacetRemoved(Environment* ev, ODFacet* facet, unsigned short facetCount)
  416. {
  417.     // ----- Remove Embedded Facets
  418.     FW_CFrameProxyFrameIterator ite(ev, this);
  419.     for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  420.         proxyFrame->RemoveFacets(ev, this, facet);
  421.     
  422.     // ----- Call inherited
  423.     FW_CFrame::FacetRemoved(ev, facet, facetCount);
  424. }
  425.  
  426. //----------------------------------------------------------------------------------------
  427. //    FW_CEmbeddingFrame::HasASelectedEmbeddedFacet
  428. //----------------------------------------------------------------------------------------
  429.  
  430. FW_Boolean FW_CEmbeddingFrame::HasASelectedEmbeddedFacet(Environment* ev) const
  431. {
  432.     FW_CFrameProxyFrameIterator iter(ev, this);
  433.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  434.     {
  435.         if (proxyFrame->GetProxy(ev)->GetSelectState(ev))
  436.             return TRUE;
  437.     }
  438.     
  439.     return FALSE;
  440. }
  441.  
  442. //----------------------------------------------------------------------------------------
  443. //    FW_CEmbeddingFrame::HandleAdjustMenus
  444. //----------------------------------------------------------------------------------------
  445.  
  446. FW_Handled FW_CEmbeddingFrame::HandleAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  447.                                             FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  448. {
  449.     PrivSetInfoCommandAdjusted(ev, false);
  450.  
  451.     if (hasMenuFocus)
  452.     {
  453.         FW_CString infoString;
  454.         FW_Boolean hasSelectedEmbeddedFacets = false;
  455.  
  456.         //--- Check for Link Info and Selection Info ---
  457.         FW_Boolean gotInfo = PrivGetInfoString(ev, GetPresentation(ev)->GetSelection(ev), infoString);
  458.         if (!gotInfo || infoString.IsEmpty())
  459.         {
  460.             hasSelectedEmbeddedFacets = HasASelectedEmbeddedFacet(ev);
  461.  
  462.             //--- Adjust the Show Part Info item ---
  463.             if (hasSelectedEmbeddedFacets)
  464.             {
  465.                 ::FW_PrivLoadODFString(ev, FW_kPartInfoString, infoString);
  466.                 menuBar->SetItemString(ev, kODCommandGetPartInfo, infoString);
  467.                 PrivSetInfoCommandAdjusted(ev, true);    // so that FW_CFrame::HandleAdjustMenus doesn't change it
  468.                 gotInfo = true;
  469.             }
  470.         }
  471.         else
  472.         {
  473.             menuBar->SetItemString(ev, kODCommandGetPartInfo, infoString);
  474.             PrivSetInfoCommandAdjusted(ev, true);    // so that FW_CFrame::HandleAdjustMenus doesn't go thru the whole thing again
  475.         }
  476.         menuBar->EnableCommand(ev, kODCommandGetPartInfo, gotInfo);
  477.  
  478.         menuBar->EnableCommand(ev, kODCommandOpen, hasSelectedEmbeddedFacets);
  479.         menuBar->EnableCommand(ev, kODCommandInsert, !GetPart(ev)->IsReadOnly(ev));
  480.  
  481. #ifdef FW_BUILD_WIN
  482.         GetPart(ev)->WinEnableEmbedMenu(ev, menuBar);
  483. #endif
  484.     }
  485.     
  486.     return FW_CFrame::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  487. }
  488.  
  489. //----------------------------------------------------------------------------------------
  490. //    FW_CEmbeddingFrame::HandleMenu
  491. //----------------------------------------------------------------------------------------
  492.  
  493. FW_Handled FW_CEmbeddingFrame::HandleMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  494. {
  495.     FW_Handled result = FW_kHandled;
  496.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  497.     
  498. #ifdef FW_BUILD_WIN
  499.     ODPart *embeddedPart = GetPart(ev)->WinCreateEmbeddedPartFromCommand(ev, commandID);
  500.     if (embeddedPart != NULL)
  501.     {
  502.         this->EmbedSingleFrame(ev, embeddedPart, NULL, NULL, GetPresentation(ev)->GetDefaultEmbeddedFrameViewType(ev));
  503.         return FW_kHandled;
  504.     }
  505. #endif
  506.  
  507.     FW_CSelection* selection = this->GetPresentation(ev)->GetSelection(ev);
  508.     switch (commandID)
  509.     {
  510.         case kODCommandInsert:
  511.             {
  512.                 FW_ASSERT(!GetPart(ev)->IsReadOnly(ev));
  513.  
  514. #ifdef FW_BUILD_WIN
  515.                 FW_COpenFileParameters openFileParameters;    // Uses default open file parameters
  516.                 DoInsert(ev, openFileParameters);
  517. #endif            
  518. #ifdef FW_BUILD_MAC
  519.                 FW_COpenFileParameters openFileParameters(&FW_MacInsertFilterProc);            // Allows only odtm documents
  520.                 DoInsert(ev, openFileParameters);
  521. #endif            
  522.             }
  523.             break;
  524.             
  525.         case kODCommandGetPartInfo:
  526.             ShowPartInfo(ev);
  527.             break;
  528.             
  529.         case kODCommandOpen:
  530.             OpenSelection(ev);
  531.             break;
  532.  
  533.         default:
  534.             result = FW_CFrame::HandleMenu(ev, theMenuEvent);
  535.     };
  536.     
  537.     return result;
  538. }
  539.  
  540. //----------------------------------------------------------------------------------------
  541. //    FW_CEmbeddingFrame::NewInsertCommand
  542. //----------------------------------------------------------------------------------------
  543.  
  544. FW_CInsertCommand* FW_CEmbeddingFrame::NewInsertCommand(Environment* ev, const FW_PFileSpecification& fileSpec)
  545. {
  546. FW_UNUSED(ev);
  547. FW_UNUSED(fileSpec);
  548.  
  549.     FW_DEBUG_MESSAGE("NewInsertCommand: subclass responsability");
  550.     return NULL;
  551. }
  552.  
  553. //----------------------------------------------------------------------------------------
  554. //    FW_CEmbeddingFrame::DoInsert
  555. //----------------------------------------------------------------------------------------
  556.  
  557. void FW_CEmbeddingFrame::DoInsert(Environment* ev, FW_COpenFileParameters& openFileParameters)
  558. {
  559.     FW_PFileSpecification fileSpec(ev, FW_CChooseFile::ChooseFileToOpen(openFileParameters));
  560.     
  561.     if (fileSpec != NULL)
  562.     {
  563.         FW_CInsertCommand* cmd = this->NewInsertCommand(ev, fileSpec);
  564.         if (cmd)
  565.             cmd->Execute(ev);
  566.     }
  567. }
  568.  
  569. //----------------------------------------------------------------------------------------
  570. //    FW_CEmbeddingFrame::OpenSelection
  571. //----------------------------------------------------------------------------------------
  572.  
  573. void FW_CEmbeddingFrame::OpenSelection(Environment* ev)
  574. {
  575.     //     I need to collect first the proxyframe that I want to open because opening the first 
  576.     //    window will unselect the other one
  577.     
  578.     FW_CProxyFrame* proxyFrame;
  579.     
  580.     FW_TOrderedCollection<FW_CProxyFrame> temp;
  581.  
  582.     FW_CFrameProxyFrameIterator iter(ev, this);
  583.     for (proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  584.     {
  585.         if (proxyFrame->GetProxy(ev)->GetSelectState(ev))
  586.             temp.AddLast(proxyFrame);
  587.     }
  588.     
  589.     FW_TOrderedCollectionIterator<FW_CProxyFrame> iter2(&temp);
  590.     for (proxyFrame = iter2.First(); iter2.IsNotComplete(); proxyFrame =  iter2.Next())
  591.     {
  592.         proxyFrame->GetProxy(ev)->OpenInWindow(ev, proxyFrame);
  593.     }
  594.     
  595.     // the destructor of temp will call RemoveAll
  596. }
  597.  
  598. //----------------------------------------------------------------------------------------
  599. //    FW_CEmbeddingFrame::ShowPartInfo
  600. //----------------------------------------------------------------------------------------
  601.  
  602. FW_Handled FW_CEmbeddingFrame::ShowPartInfo(Environment* ev)
  603. {
  604.     FW_Boolean handledIt = FW_CFrame::ShowPartInfo(ev);
  605.     if (handledIt)
  606.         return handledIt;
  607.  
  608.     FW_CFrameProxyFrameIterator iter(ev, this);
  609.     for (FW_CProxyFrame* proxyFrame = iter.First(ev); iter.IsNotComplete(ev); proxyFrame = iter.Next(ev))
  610.     {
  611.         FW_MProxy *proxy = proxyFrame->GetProxy(ev);
  612.         FW_ASSERT(proxy);
  613.         
  614.         if (proxy->GetSelectState(ev))
  615.         {
  616.             // ----- Try first the active facet -----
  617.             ODFacet* facet = this->GetActiveFacet(ev);
  618.             
  619.             // ----- If not Active facet try the first facet -----
  620.             if (facet == NULL)
  621.             {
  622.                 FW_CFrameFacetIterator iteFrame(ev, this);
  623.                 facet = iteFrame.First(ev);
  624.             }
  625.             FW_ASSERT(facet != NULL);
  626.             
  627.             // [HLX] We are passing the first facet but we need to be a little bit more smart 
  628.             // about that. We should pass the selected one or if there is no selection do it on ourself
  629.             FW_CEmbeddedODFacetsIterator ite(ev, proxy, facet, kODFrontToBack);
  630.             ODFacet* firstEmbeddedFacet = ite.First(ev);
  631.             FW_ASSERT(firstEmbeddedFacet != NULL);
  632.             
  633.             ODFrame* embeddedFrame = proxyFrame->GetFrame(ev);
  634.             ODTypeToken oldViewType = embeddedFrame->GetViewType(ev);
  635.  
  636.             FW_CSession::GetInfo(ev)->ShowPartFrameInfo(ev, firstEmbeddedFacet, !GetPart(ev)->IsReadOnly(ev));
  637.  
  638.             ODTypeToken newViewType = embeddedFrame->GetViewType(ev);
  639.             
  640.             // ----- Propagate the view type to other sibling frames -----
  641.             if (oldViewType != newViewType)
  642.             {
  643.                 FW_CProxyEmbeddedFrameIterator iter2(ev, proxy);
  644.                 for (ODFrame* sibling = iter2.First(ev); iter2.IsNotComplete(ev); sibling = iter2.Next(ev))
  645.                 {
  646.                     sibling->ChangeViewType(ev, newViewType);
  647.                 }
  648.             }
  649.             handledIt = FW_kHandled;
  650.         }
  651.     }
  652.  
  653.     return handledIt;
  654. }
  655.  
  656. //----------------------------------------------------------------------------------------
  657. //    FW_CEmbeddingFrame::ViewTypeChanged
  658. //----------------------------------------------------------------------------------------
  659.  
  660. void FW_CEmbeddingFrame::ViewTypeChanged(Environment* ev, ODTypeToken newViewType, ODTypeToken oldViewType)
  661. {
  662.     FW_CFrame::ViewTypeChanged(ev, newViewType, oldViewType);
  663.     
  664.     FW_CFrameProxyFrameIterator ite(ev, this);
  665.     for (FW_CProxyFrame* proxyframe = ite.First(ev); ite.IsNotComplete(ev); proxyframe = ite.Next(ev))
  666.     {
  667.         if (oldViewType == FW_CPart::fgViewAsFrameToken)
  668.             proxyframe->RemoveAllFacets(ev);
  669.         else
  670.             proxyframe->CreateAllFacets(ev);
  671.     }
  672. }
  673.  
  674. //----------------------------------------------------------------------------------------
  675. //    FW_CEmbeddingFrame::AdjustCursor
  676. //----------------------------------------------------------------------------------------
  677.  
  678. FW_Handled FW_CEmbeddingFrame::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint, ODEventInfo* eventInfo)
  679. {
  680. FW_UNUSED(eventInfo);
  681.  
  682.     // ----- Test if mouse on the active border of an embedded facet -----
  683.     FW_Handled handled = FW_kNotHandled;
  684.     
  685.     ODArbitrator* arbitrator =  FW_CSession::GetArbitrator(ev);
  686.     FW_CAcquiredODFrame aqActiveFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::fgSelectionFocusToken);
  687.     if (aqActiveFrame != NULL)
  688.     {
  689.         FW_CODFrameFacetIterator iter(ev, aqActiveFrame);
  690.         
  691.         FW_CPoint windowMouse(theMousePoint);
  692.         FW_FrameToWindow(ev, odFacet, windowMouse);
  693.         
  694.         for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  695.         {
  696.             FW_CPoint temp(windowMouse);
  697.             FW_WindowToFrame(ev, facet, temp);
  698.             ODPoint odFramePoint = temp;
  699.             
  700.             if (facet->ActiveBorderContainsPoint(ev, &odFramePoint, NULL))
  701.             {
  702.                 handled = FW_kHandled;
  703.                 break;
  704.             } 
  705.         }
  706.     }
  707.     
  708.     if (handled)
  709.         FW_gOpenHandCursor.Select();
  710.     
  711.     return handled;
  712. }
  713.  
  714. //----------------------------------------------------------------------------------------
  715. //    FW_CEmbeddingFrame::ODtoFWEmbeddingFrame
  716. //----------------------------------------------------------------------------------------
  717.  
  718. FW_CEmbeddingFrame* FW_CEmbeddingFrame::ODtoFWEmbeddingFrame(Environment* ev, ODFrame* odFrame)
  719. {
  720.     FW_CEmbeddingFrame* frame = NULL;
  721.     
  722.     if (odFrame)
  723.     {
  724.         FW_CFrame* fwframe = (FW_CFrame*)odFrame->GetPartInfo(ev);
  725.         frame = fwframe ? FW_DYNAMIC_CAST(FW_CEmbeddingFrame, fwframe) : NULL;
  726.     }
  727.     
  728.     return frame;
  729. }
  730.  
  731. //---------------------------------------------------------------------------------------
  732. //    FW_CEmbeddingFrame::PrivStartStopDragging
  733. //---------------------------------------------------------------------------------------
  734. //    call from FW_CDragCommand::BeginDrag
  735.  
  736. void FW_CEmbeddingFrame::PrivStartStopDragging(Environment *ev, FW_EPrivDraggingFlags dragFlags)
  737. {
  738.     FW_CFrameProxyFrameIterator ite(ev, this);
  739.     for (FW_CProxyFrame* proxyFrame = ite.First(ev); ite.IsNotComplete(ev); proxyFrame = ite.Next(ev))
  740.     {
  741.         // FW_CProxyFrame is doing the right check before setting the embedded ODFrame
  742.         proxyFrame->PrivSetDragging(ev, dragFlags); 
  743.     }    
  744. }
  745.