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 / FWFrame.cpp < prev    next >
Encoding:
Text File  |  1996-04-25  |  63.3 KB  |  2,059 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFrame.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 FWFRAME_H
  13. #include "FWFrame.h"
  14. #endif
  15.  
  16. #ifndef FWPART_H
  17. #include "FWPart.h"
  18. #endif
  19.  
  20. #ifndef FWPRESEN_H
  21. #include "FWPresen.h"
  22. #endif
  23.  
  24. #ifndef FWPRTITE_H
  25. #include "FWPrtIte.h"
  26. #endif
  27.  
  28. #ifndef FWPRHDLR_H
  29. #include "FWPrHdlr.h"
  30. #endif
  31.  
  32. #ifndef FWCLPCMD_H
  33. #include "FWClpCmd.h"
  34. #endif
  35.  
  36. #ifndef FWSELECT_H
  37. #include "FWSelect.h"
  38. #endif
  39.  
  40. #ifndef FWMNUBAR_H
  41. #include "FWMnuBar.h"
  42. #endif
  43.  
  44. #ifndef SLMACOS_H
  45. #include "SLMacOS.h"
  46. #endif
  47.  
  48. #ifndef FWFLOWIN_H
  49. #include "FWFloWin.h"
  50. #endif
  51.  
  52. #ifndef FWODGEOM_H
  53. #include "FWODGeom.h"
  54. #endif
  55.  
  56. #ifndef FWITERS_H
  57. #include "FWIters.h"
  58. #endif
  59.  
  60. #ifndef FWVIEWAS_H
  61. #include "FWViewAs.h"
  62. #endif
  63.  
  64. #ifndef FWCURSOR_H
  65. #include "FWCursor.h"
  66. #endif
  67.  
  68. #ifndef FWBARRAY_H
  69. #include "FWBArray.h"
  70. #endif
  71.  
  72. #ifndef FWSCROLR_H
  73. #include "FWScrolr.h"
  74. #endif
  75.  
  76. #ifndef FWCNTRHW_H
  77. #include "FWCntrHW.h"
  78. #endif
  79.  
  80. #ifndef FWUTIL_H
  81. #include "FWUtil.h"
  82. #endif
  83.  
  84. #ifndef FWIDLE_H
  85. #include "FWIdle.h"
  86. #endif
  87.  
  88. #ifndef FWCONTXT_H
  89. #include "FWContxt.h"
  90. #endif
  91.  
  92. #ifndef FWRESOUR_H
  93. #include "FWResour.h"
  94. #endif
  95.  
  96. #ifndef FWRGNSHP_H
  97. #include "FWRgnShp.h"
  98. #endif
  99.  
  100. // ----- OpenDoc Includes -----
  101.  
  102. #ifndef SOM_ODSession_xh
  103. #include <ODSessn.xh>
  104. #endif
  105.  
  106. #ifndef SOM_Module_OpenDoc_Commands_defined
  107. #include <CmdDefs.xh>
  108. #endif
  109.  
  110. #ifndef SOM_ODFacet_xh
  111. #include <Facet.xh>
  112. #endif
  113.  
  114. #ifndef SOM_Module_OpenDoc_StdTypes_defined
  115. #include <StdTypes.xh>
  116. #endif
  117.  
  118. #ifndef SOM_ODArbitrator_xh
  119. #include <Arbitrat.xh>
  120. #endif
  121.  
  122. #ifndef SOM_ODStorageUnitView_xh
  123. #include <SUView.xh>
  124. #endif
  125.  
  126. #ifndef SOM_ODClipboard_xh
  127. #include <Clipbd.xh>
  128. #endif
  129.  
  130. #ifndef SOM_Module_OpenDoc_StdProps_defined
  131. #include <StdProps.xh>
  132. #endif
  133.  
  134. #if defined(__MWERKS__) && GENERATING68K
  135. // A hack to work around a bug
  136. #pragma import list somGetGlobalEnvironment
  137. #endif
  138.  
  139. //========================================================================================
  140. // RunTime Info
  141. //========================================================================================
  142.  
  143. #ifdef FW_BUILD_MAC
  144. #pragma segment FW_FrameSegment
  145. #endif
  146.  
  147. //========================================================================================
  148. //    Template Instantiations
  149. //========================================================================================
  150.  
  151. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CFrame)
  152. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CFrame)
  153.  
  154. #ifdef FW_USE_TEMPLATE_PRAGMAS
  155.  
  156. #pragma template_access public
  157. #pragma template FW_TOrderedCollection<FW_CFrame>
  158. #pragma template FW_TOrderedCollectionIterator<FW_CFrame>
  159.  
  160. #endif
  161.  
  162. //========================================================================================
  163. //    Constant
  164. //========================================================================================
  165.  
  166. typedef long FW_FrameVersion;
  167. const FW_FrameVersion FW_kFrameVersion = 0;
  168.  
  169. //========================================================================================
  170. //    class FW_CFrame
  171. //========================================================================================
  172.  
  173. FW_DEFINE_AUTO(FW_CFrame)
  174. FW_DEFINE_CLASS_M1(FW_CFrame, FW_CSuperView)
  175.  
  176. //----------------------------------------------------------------------------------------
  177. //    FW_CFrame::FW_CFrame
  178. //----------------------------------------------------------------------------------------
  179.  
  180. FW_CFrame::FW_CFrame(Environment *ev,
  181.                     ODFrame* odFrame, 
  182.                     FW_CPresentation* presentation, 
  183.                     FW_CPart* part,
  184.                     FW_ResourceId id) :
  185.     FW_CSuperView(ev),        
  186.     fFrameID(odFrame->GetID(ev)),
  187.     fODFrame(odFrame),
  188.     fPart(part),
  189.     fResourceId(id),
  190.     fContentView(NULL),
  191.     fGetFrontClicks(TRUE),
  192.     fNeedsFoci(FALSE),
  193.     fHasSelectionFocus(FALSE),
  194.     fActiveFacet(NULL),
  195.     fCanBeActiveFrame(TRUE),    
  196.     fPresentation(presentation),
  197.     fWindow(NULL),
  198.     fFacetCount(0),
  199.     fPreviousViewType(odFrame->GetViewType(ev)),
  200.     fViewAs(NULL),
  201.     fIdler(NULL),
  202.     fDraggable(NULL),
  203.     fDroppable(NULL),
  204.     fScroller(NULL),    
  205.     fViewUnderCursor(NULL),
  206.     fRequestedFrame(FALSE),    
  207.     fInSharedWindow(FALSE),
  208. #ifdef FW_BUILD_WIN
  209.     fShadowWindow(NULL),
  210. #endif    
  211.     fInternalTransformRealigmentNeeded(FALSE),
  212.     fContentViewOffset(FW_kZeroPoint),
  213.     fSubViewsCreated(FALSE),
  214.     fSourceFrame(this),
  215.     fDroppableState(FW_kFrameDroppable)
  216. {
  217.     FW_ASSERT(fODFrame);
  218.     FW_ASSERT(fPart != NULL);
  219.     
  220.     // Frame is the default target of the event handling chain
  221.     // (it will be the Content View later if one is created)
  222.     fTarget = this;
  223.     
  224.     this->SetNextEventHandler(ev, part);
  225.  
  226.     fNeedsFoci = odFrame->IsRoot(ev);
  227.     
  228.     SetViewId(ev, fPresentation->GetPresentationType(ev));
  229.     
  230.     // ----- force to be view as frame if root -----
  231.     if (fPreviousViewType != FW_CPart::gViewAsFrameToken && IsRoot(ev))
  232.         fODFrame->SetViewType(ev, FW_CPart::gViewAsFrameToken);
  233.  
  234.     // ----- Set the frame's view Bounds to its shape bounds
  235.     FW_CRect frameRect;
  236.     PrivGetFrameShapeBounds(ev, frameRect);
  237.     PrivSetBounds(ev, frameRect);
  238.     PrivSetExtent(ev, frameRect.Size());    
  239.  
  240.     // ----- By default the frame is the ContentView
  241.     PrivSetIsContentView(ev, TRUE);
  242.     fContentView = (FW_CSuperView*)this;
  243.     
  244.     FW_END_CONSTRUCTOR
  245. }
  246.  
  247. //----------------------------------------------------------------------------------------
  248. //    FW_CFrame::~FW_CFrame
  249. //----------------------------------------------------------------------------------------
  250.  
  251. FW_CFrame::~FW_CFrame()
  252. {
  253.     FW_START_DESTRUCTOR
  254.  
  255.     Environment* ev = somGetGlobalEnvironment();
  256.     
  257.     FW_ASSERT(fIdler == NULL);    // subclass must delete idler it created
  258.  
  259.     FW_ASSERT(fWindow == NULL);    // should have been deleted in FrameRemoved
  260.     
  261.     if (fViewAs && fPresentation)
  262.         fPresentation->PrivReleaseViewAs(fViewAs);
  263.  
  264.     // Delete first all subviews before deleting the scroller. 
  265.     DeleteSubViews(ev);
  266.     
  267.     // Now I can delete the scroller (if any)    
  268.     delete fScroller;
  269. }
  270.  
  271. //----------------------------------------------------------------------------------------
  272. //    FW_CFrame::FrameRemoved
  273. //----------------------------------------------------------------------------------------
  274. // Notification
  275.  
  276. void FW_CFrame::FrameRemoved(Environment* ev, FW_Boolean toStorage)
  277. {
  278. FW_UNUSED(toStorage);
  279.  
  280. //    if (toStorage && fIdler)    [LSD] why this test?
  281.     if (fIdler)
  282.         fIdler->UnregisterIdle(ev);
  283.         
  284.     // ----- Relinquish what ever focus we have
  285.     RelinquishFocusSet(ev);
  286.         
  287.     // ----- Check that the window has been deleted -----
  288.     FW_ASSERT(fFacetCount == 0);    
  289.     FW_ASSERT(fWindow == NULL);    // When the frame is removed it should not have any facets. fWindow
  290.                                 // should already be null (see FacetRemoved)
  291.     
  292.     fODFrame = NULL;            // Don't have an ODFFrame anymore
  293. }
  294.  
  295. //----------------------------------------------------------------------------------------
  296. //    FW_CFrame::FrameAdded
  297. //----------------------------------------------------------------------------------------
  298. // Notification
  299.  
  300. void FW_CFrame::FrameAdded(Environment* ev, ODFrame* odFrame, FW_Boolean fromStorage)
  301. {
  302. FW_UNUSED(fromStorage);
  303.         
  304.     // In the case of frame in a shared window fODFrame can be NULL
  305.     FW_ASSERT(fODFrame == odFrame || fODFrame == NULL);
  306.     fODFrame = odFrame;
  307.     
  308.     // ----- Add it to the presentation -----
  309.     fPresentation->PrivAddFrame(ev, this);
  310.     
  311.     // ----- Initialize printing handler -----
  312.     FW_CPrintHandler* printHandler = NewPrintHandler(ev);
  313.     if (printHandler != NULL)
  314.         AdoptEventHandler(ev, printHandler);
  315. }
  316.  
  317. //----------------------------------------------------------------------------------------
  318. // FW_CFrame::GetTarget
  319. //----------------------------------------------------------------------------------------
  320.  
  321. FW_MEventHandler* FW_CFrame::GetTarget(Environment* ev) const
  322. {
  323. FW_UNUSED(ev);
  324.  
  325.     return fTarget;        // cannot be NULL
  326. }
  327.  
  328. //----------------------------------------------------------------------------------------
  329. // FW_CFrame::SetTarget
  330. //----------------------------------------------------------------------------------------
  331.  
  332. void FW_CFrame::SetTarget(Environment* ev, FW_MEventHandler* theTarget)
  333. {
  334. FW_UNUSED(ev);
  335.  
  336.     FW_ASSERT(theTarget != NULL);
  337.     fTarget = theTarget;
  338. }
  339.  
  340. //----------------------------------------------------------------------------------------
  341. // FW_CFrame::WantsToBeTarget
  342. //----------------------------------------------------------------------------------------
  343.  
  344. FW_Boolean FW_CFrame::WantsToBeTarget(Environment* ev)
  345. {
  346. FW_UNUSED(ev);
  347.  
  348.     return TRUE;
  349. }
  350.  
  351. //----------------------------------------------------------------------------------------
  352. //    FW_CFrame::HandleMenu
  353. //----------------------------------------------------------------------------------------
  354.  
  355. FW_Boolean FW_CFrame::HandleMenu(Environment* ev, const FW_CMenuEvent& theMenuEvent)
  356. {
  357.     FW_Boolean result = TRUE;
  358.     FW_CClipboardCommand* cmd;
  359.     ODCommandID commandID = theMenuEvent.GetCommandID(ev);
  360.     
  361.     switch (commandID)
  362.     {
  363.         case kODCommandViewAsWin:
  364.             fPresentation->OpenPartWindow(ev, this, NULL);
  365.             break;
  366.         
  367.         case kODCommandCut:
  368.         case kODCommandCopy:
  369.         case kODCommandPaste:
  370.         case kODCommandPasteAs:
  371.         case kODCommandClear:
  372.             cmd = this->NewClipboardCommand(ev, commandID);
  373.             if (cmd)
  374.                 cmd->Execute(ev);
  375.             break;
  376.                         
  377.         case kODCommandSelectAll:
  378.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  379.             if (selection)
  380.                 selection->SelectAll(ev);
  381.             break;
  382.             
  383.         default:
  384.             result = FW_CSuperView::HandleMenu(ev, theMenuEvent);    
  385.     }
  386.     
  387.     return result;
  388. }
  389.  
  390. //----------------------------------------------------------------------------------------
  391. //    FW_CFrame::NewPartWindow
  392. //----------------------------------------------------------------------------------------
  393.  
  394. FW_CWindow* FW_CFrame::NewPartWindow(Environment* ev, ODFacet* sourceFacet)
  395. {
  396.     FW_CRect frameBounds = GetBounds(ev);
  397.     FW_FrameToWindow(ev, sourceFacet, frameBounds);
  398.  
  399.     GetWindow(ev)->WindowToScreen(ev, frameBounds);
  400.     frameBounds.Offset(FW_IntToFixed(20), FW_IntToFixed(20));
  401.     
  402.     FW_CString255 partName;
  403.     fPart->GetPartName(ev, partName);
  404.     
  405.     return new FW_CWindow(ev, 
  406.                         fPart,
  407.                         fODFrame,
  408.                         FALSE,                            // persistent frame
  409.                         FW_CPart::gViewAsFrameToken,
  410.                         GetPresentation(ev),
  411.                         partName,
  412.                         frameBounds.Size(),
  413.                         frameBounds.TopLeft(),
  414.                         FW_kDocumentWindow);
  415. }
  416.  
  417. //----------------------------------------------------------------------------------------
  418. //    FW_CFrame::NewClipboardCommand
  419. //----------------------------------------------------------------------------------------
  420.  
  421. FW_CClipboardCommand* FW_CFrame::NewClipboardCommand(Environment* ev, ODCommandID commandID)
  422. {
  423. FW_UNUSED(ev);
  424. FW_UNUSED(commandID);
  425.     // [LSD] removed the assert to be more flexible in Form's CEditCmd class
  426.     //         user should check the return value before calling command->Execute(ev) 
  427. //    FW_DEBUG_MESSAGE("Your need to override FW_CFrame::NewClipboardCommand to create a command");
  428.     return NULL;
  429. }
  430.  
  431. //----------------------------------------------------------------------------------------
  432. //    FW_CFrame::InstallMenus
  433. //----------------------------------------------------------------------------------------
  434. //     By default call the part with the part menuBar
  435.  
  436. void FW_CFrame::InstallMenus(Environment *ev)
  437. {
  438.     GetPart(ev)->InstallMenus(ev, GetPart(ev)->GetMenuBar(ev));
  439. }
  440.  
  441. #ifdef FW_BUILD_MAC
  442. //----------------------------------------------------------------------------------------
  443. //    FW_CFrame::HandleWindowEvent
  444. //----------------------------------------------------------------------------------------
  445.  
  446. FW_Boolean FW_CFrame::HandleWindowEvent(Environment* ev, const FW_CMacWindowEvent& windowEvent)
  447. {
  448.     FW_Boolean handled = TRUE;
  449.     
  450.     unsigned long message = windowEvent.GetMessage();
  451.     switch (windowEvent.GetMessage())
  452.     {
  453.         case inZoomIn:
  454.         case inZoomOut:
  455.             {    
  456.                 ODPlatformWindow platformWindow = GetWindow(ev)->GetPlatformWindow(ev);
  457.                 
  458.                 // ----- Get the size of the window border -----
  459.                 FW_CRect borderSize;
  460.                 FW_PlatformError error;
  461.                 FW_GetWindowBorderSize(platformWindow, borderSize, &error);
  462.                 FW_FailOnError(error);
  463.                 
  464.                 // ----- Find out where the window would like to be zoomed out to 
  465.                 FW_CRect screenRect;
  466.                 ::FW_MacGetMaxIntersectedDevice(platformWindow, screenRect, &error);
  467.                 FW_FailOnError(error);
  468.                 screenRect.Inset(FW_IntToFixed(3), FW_IntToFixed(3));    // leave space around window structure area
  469.             
  470.                 // ----- call the part to get a custom size (interior size) -----
  471.                 FW_CPoint proposedSize(screenRect.Width() - borderSize.left - borderSize.right, 
  472.                                        screenRect.Height() - borderSize.top - borderSize.bottom);
  473.                 this->AdjustZoomedWindowSize(ev, proposedSize);
  474.                 
  475.                 fWindow->PrivMacDoZoom(ev, proposedSize, borderSize, screenRect, message);
  476.             }
  477.             break;
  478.         
  479.         case inGrow:
  480.             PrivMacInGrowBox(ev, windowEvent);
  481.             break;
  482.  
  483.         case inGoAway:
  484.              if (fWindow->IsFloating(ev)) 
  485.                 fWindow->Hide(ev);
  486.             else
  487.                 handled = FALSE;
  488.             break;
  489.             
  490.         default:
  491.             handled = FALSE;
  492.     }
  493.     
  494.     return handled;
  495. }
  496. #endif
  497.  
  498. //----------------------------------------------------------------------------------------
  499. // FW_CFrame::AdjustZoomedWindowSize
  500. //----------------------------------------------------------------------------------------
  501. //    proposedSize is the interior size of the window
  502.  
  503. void FW_CFrame::AdjustZoomedWindowSize(Environment *ev, FW_CPoint& proposedSize)
  504. {
  505. FW_UNUSED(ev);
  506. FW_UNUSED(proposedSize);
  507. }
  508.  
  509. //----------------------------------------------------------------------------------------
  510. // FW_CFrame::AdjustWindowGrowLimits
  511. //----------------------------------------------------------------------------------------
  512. //    proposedSize is the interior size of the window
  513.  
  514. void FW_CFrame::AdjustWindowGrowLimits(Environment* ev, FW_CPoint& minSize, FW_CPoint& maxSize)
  515. {
  516. FW_UNUSED(ev);
  517. FW_UNUSED(minSize);
  518. FW_UNUSED(maxSize);
  519. }
  520.  
  521. //----------------------------------------------------------------------------------------
  522. //    FW_CFrame::HandleAdjustMenus
  523. //----------------------------------------------------------------------------------------
  524.  
  525. FW_Boolean FW_CFrame::HandleAdjustMenus(Environment* ev, FW_CMenuBar* menuBar, 
  526.                                         FW_Boolean hasMenuFocus, FW_Boolean isRoot)
  527. {
  528.     if (hasMenuFocus)
  529.     {
  530.         // ----- Only if the target is the content view -----
  531.         if (GetTarget(ev) == fContentView)    
  532.         {
  533.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  534.             FW_Boolean hasSelection = selection && !selection->IsEmpty(ev);
  535.         
  536.             // ----- Edit Menu -----
  537.             // If read only clear, cut past items will be disabled in FW_CPart::HandleAdjustMenus
  538.             menuBar->EnableCommand(ev, kODCommandClear, hasSelection);
  539.             menuBar->EnableCommand(ev, kODCommandCut, hasSelection);
  540.             menuBar->EnableCommand(ev, kODCommandCopy, hasSelection);
  541.             
  542.             menuBar->EnableCommand(ev, kODCommandPasteAs, HasPropertyOnClipboard(ev, kODPropLinkSpec, kODLinkSpec));
  543.         }
  544.         
  545.         menuBar->EnableCommand(ev, kODCommandViewAsWin, !IsTopFrame(ev));
  546.     }
  547.     
  548.     return FW_CSuperView::HandleAdjustMenus(ev, menuBar, hasMenuFocus, isRoot);
  549. }
  550.  
  551. //----------------------------------------------------------------------------------------
  552. //    FW_CFrame::IsTopFrame
  553. //----------------------------------------------------------------------------------------
  554. //    IsTopFrame returns true if this frame is a sub-frame of the root frame
  555.  
  556. FW_Boolean FW_CFrame::IsTopFrame(Environment* ev) const
  557. {
  558.     if (IsRoot(ev))
  559.         return TRUE;
  560.     
  561.     FW_CAcquiredODFrame aqContainingFrame = AcquireContainingFrame(ev);
  562.     return IsSubframe(ev) && aqContainingFrame->IsRoot(ev);
  563. }
  564.  
  565. //----------------------------------------------------------------------------------------
  566. //    FW_CFrame::IsSiblingFrameOf
  567. //----------------------------------------------------------------------------------------
  568. //    Look if both frames are from the same part and have the same presentation. Returns FALSE
  569. //    if otherODFrame is NULL.
  570.  
  571. FW_Boolean FW_CFrame::IsSiblingFrameOf(Environment *ev, ODFrame* otherODFrame) const
  572. {
  573.     if (otherODFrame == NULL)
  574.         return FALSE;
  575.         
  576.     FW_CAcquiredODPart otherPart = otherODFrame->AcquirePart(ev);
  577.     if (GetODPart(ev) == otherPart)
  578.     {
  579.         FW_CFrame* otherFrame = FW_CFrame::ODtoFWFrame(ev, otherODFrame);
  580.         return GetPresentation(ev) == otherFrame->GetPresentation(ev);
  581.     }
  582.     
  583.     return FALSE;
  584. }
  585.  
  586. //----------------------------------------------------------------------------------------
  587. //    FW_CFrame::HasSamePartEditorAs
  588. //----------------------------------------------------------------------------------------
  589. //    Look if the presentation of the otherFrame is the same as mine. Returns TRUE even if they
  590. //    have two different instances of the editor.
  591.  
  592. FW_Boolean FW_CFrame::HasSamePartEditorAs(Environment *ev, ODFrame* otherFrame) const
  593. {
  594.     if (otherFrame != NULL)
  595.     {
  596.         ODTypeToken proposedToken = otherFrame->GetPresentation(ev);
  597.         FW_CPartPresentationIterator ite(fPart);
  598.         for (FW_CPresentation* presentation = ite.First();
  599.             ite.IsNotComplete();
  600.             presentation = ite.Next())
  601.         {
  602.             if (presentation->GetPresentationType(ev) == proposedToken)
  603.                 return TRUE;
  604.         }
  605.     }
  606.     
  607.     return FALSE;
  608. }
  609.  
  610. //----------------------------------------------------------------------------------------
  611. //    FW_CFrame::FocusStateChanged
  612. //----------------------------------------------------------------------------------------
  613. //    When overridden, call inherited::FocusStateChanged FIRST
  614.  
  615. void FW_CFrame::FocusStateChanged(Environment *ev, ODTypeToken focus, FW_Boolean newState, ODFrame* newOwner)
  616. {
  617.     if (focus == FW_CPart::gSelectionFocusToken)
  618.     {
  619.         fPart->PrivSetLastActiveFrame(this);
  620.  
  621.         ODWindowState* windowState =  fPart->GetSession(ev)->GetWindowState(ev);
  622.         
  623.         if (newState)
  624.         {
  625.             fHasSelectionFocus = TRUE;
  626.             GetTarget(ev)->ActivateTarget(ev);
  627.             
  628.             // Handle case of multiple parts sharing the same floating windows
  629.             FW_CFloatingWindow::TransferOwnership(ev, windowState, fPart->GetODPart(ev));
  630.             
  631.             // Show the floating windows except if frame has modal focus (i.e. Dialogs)
  632.             if (!HasModalFocus(ev))
  633.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, windowState, TRUE);
  634.         }
  635.         else
  636.         {
  637.             //     Close the selection if I become deactive and the newOwner is not NULL and
  638.             //    not one of my sibling and there is not drag pending
  639.             FW_CSelection* selection = fPresentation->GetSelection(ev);
  640.             if (selection && !this->IsSiblingFrameOf(ev, newOwner) && !fPresentation->PrivIsDragPending())
  641.                 selection->CloseSelection(ev);
  642.  
  643.             fHasSelectionFocus = FALSE;
  644.             GetTarget(ev)->DeactivateTarget(ev);
  645.             
  646.             if (!HasSamePartEditorAs(ev, newOwner))
  647.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, windowState, FALSE);
  648.         }
  649.     }
  650.     else if (focus == FW_CPart::gMenuFocusToken)
  651.     {
  652.         if (newState)
  653.             InstallMenus(ev);
  654.     }
  655. }
  656.  
  657. //----------------------------------------------------------------------------------------
  658. //    FW_CFrame::CanBeActiveFrame
  659. //----------------------------------------------------------------------------------------
  660.  
  661. FW_Boolean FW_CFrame::CanBeActiveFrame(Environment* ev) const
  662. {
  663.     FW_ASSERT(GetWindow(ev) != NULL);
  664.     return fCanBeActiveFrame && !GetWindow(ev)->IsFloating(ev) && !IsFrozen(ev) && (GetViewType(ev) == FW_CPart::gViewAsFrameToken);
  665. }
  666.  
  667. //----------------------------------------------------------------------------------------
  668. //    FW_CFrame::ODtoFWFrame
  669. //----------------------------------------------------------------------------------------
  670.  
  671. FW_CFrame* FW_CFrame::ODtoFWFrame(Environment *ev, ODFrame* odFrame)
  672. {
  673.     return odFrame ? (FW_CFrame*)odFrame->GetPartInfo(ev) : NULL;
  674. }
  675.  
  676. //----------------------------------------------------------------------------------------
  677. //     FW_CFrame::FrameShapeChanged
  678. //----------------------------------------------------------------------------------------
  679. //    When overridden, call inherited::FrameShapeChanged first
  680.  
  681. void FW_CFrame::FrameShapeChanged(Environment* ev)
  682. {
  683.     FW_CRect frameRect;
  684.     PrivGetFrameShapeBounds(ev, frameRect);
  685.     FW_CPoint newSize = frameRect.Size();
  686.     
  687.     if (GetViewType(ev) == FW_CPart::gViewAsFrameToken)
  688.     {
  689. #ifdef FW_BUILD_WIN
  690.         MoveSizeShadowWindow(ev);
  691. #endif
  692.         // Change the size and refresh modified region.  (This will in turn call SetExtent 
  693.         // and adjust the layout of subviews if the frame is not the content view)
  694.         SetSize(ev, newSize, TRUE);
  695.     }
  696.     else
  697.     {
  698.         // Use the FW_CView method to avoid resizing the frame's subviews
  699.         // when it's not displayed as a frame
  700.         FW_CView::SetSize(ev, newSize, TRUE);
  701.     }
  702.     
  703.     UpdateUsedAndActiveShapes(ev);
  704. }
  705.  
  706. //----------------------------------------------------------------------------------------
  707. //    FW_CFrame::SetActiveFacet
  708. //----------------------------------------------------------------------------------------
  709.  
  710. void FW_CFrame::SetActiveFacet(Environment* ev, ODFacet*  activeFacet)
  711. {
  712. FW_UNUSED(ev);
  713.     fActiveFacet = activeFacet;
  714. }
  715.  
  716. //----------------------------------------------------------------------------------------
  717. //    FW_CFrame::UpdateUsedAndActiveShapes
  718. //----------------------------------------------------------------------------------------
  719.  
  720. void FW_CFrame::UpdateUsedAndActiveShapes(Environment* ev)
  721. {
  722.     // ----- Used Shape -----
  723.     UpdateUsedShape(ev);
  724.  
  725.     // ----- Update Active Shape for every facets -----
  726.     FW_CFrameFacetIterator iter(ev, this);
  727.     for (ODFacet* facet = iter.First(ev); iter.IsNotComplete(ev); facet = iter.Next(ev))
  728.     {
  729.         UpdateActiveShape(ev, facet);
  730.     }
  731. }
  732.  
  733. //----------------------------------------------------------------------------------------
  734. //    FW_CFrame::UpdateUsedShape
  735. //----------------------------------------------------------------------------------------
  736.  
  737. void FW_CFrame::UpdateUsedShape(Environment* ev)
  738. {
  739.     // ----- Used Shape -----
  740.     FW_CAcquiredODShape aqUsedShape;
  741.     
  742.     PrivCreateViewAs(ev);
  743.     if (fViewAs == NULL)
  744.     {
  745.         //    ----- By default the used shape is the frame shape
  746.         FW_CAcquiredODShape aqFrameShape = FW_CopyAndRelease(ev, AcquireFrameShape(ev, NULL));
  747.         aqUsedShape = AdjustUsedShape(ev, aqFrameShape);
  748.     }
  749.     else
  750.     {
  751.         aqUsedShape = fViewAs->CalcUsedShape(ev);        // returns a copy            
  752.     }
  753.     
  754.     // ----- if aqUsedShape is NULL OpenDoc will use the frame shape
  755.     ChangeUsedShape(ev, aqUsedShape, NULL);        
  756. }
  757.  
  758. //----------------------------------------------------------------------------------------
  759. //    FW_CFrame::UpdateActiveShape
  760. //----------------------------------------------------------------------------------------
  761.  
  762. void FW_CFrame::UpdateActiveShape(Environment* ev, ODFacet* facet)
  763. {
  764.     FW_CAcquiredODShape aqActiveShape;
  765.     
  766.     // ---- the Active shape is a copy of the Used shape by default
  767.     FW_CAcquiredODShape aqProposedActiveShape = FW_CopyAndRelease(ev, AcquireUsedShape(ev));
  768.     
  769.     PrivCreateViewAs(ev);
  770.     if (fViewAs == NULL) 
  771.         aqActiveShape = AdjustActiveShape(ev, facet, aqProposedActiveShape);
  772.     else
  773.         aqActiveShape = aqProposedActiveShape;
  774.         
  775.     facet->ChangeActiveShape(ev, aqActiveShape, NULL);    
  776. }
  777.  
  778. //----------------------------------------------------------------------------------------
  779. //    FW_CFrame::AdjustUsedShape
  780. //----------------------------------------------------------------------------------------
  781. //    suggestedUsedShape is the frame shape. The default implementation returns NULL because
  782. //    we don't want to maintain our own used shape.
  783.  
  784. ODShape* FW_CFrame::AdjustUsedShape(Environment* ev, ODShape* suggestedUsedShape)
  785. {
  786. FW_UNUSED(ev);
  787. FW_UNUSED(suggestedUsedShape);
  788.     return NULL;
  789. }
  790.  
  791. //----------------------------------------------------------------------------------------
  792. //    FW_CFrame::AdjustActiveShape
  793. //----------------------------------------------------------------------------------------
  794. //    suggestedActiveShape is the used shape. The default implementation returns NULL because
  795. //    we don't want to maintain an active shape
  796.  
  797. ODShape* FW_CFrame::AdjustActiveShape(Environment* ev, ODFacet* facet, ODShape* suggestedActiveShape)
  798. {
  799. FW_UNUSED(ev);
  800. FW_UNUSED(facet);
  801. FW_UNUSED(suggestedActiveShape);
  802.     return NULL;
  803. }
  804.  
  805. //----------------------------------------------------------------------------------------
  806. //    FW_CFrame::RequestFrameShape
  807. //----------------------------------------------------------------------------------------
  808.  
  809. FW_Boolean FW_CFrame::RequestFrameShape(Environment *ev, ODShape* shape, ODCanvas* biasCanvas)
  810. {
  811.     FW_CAcquiredODShape aqOldFrameShape = FW_CopyAndRelease(ev, AcquireFrameShape(ev, biasCanvas));
  812.     
  813.     FW_CAcquiredODShape aqNewFrameShape = fODFrame->RequestFrameShape(ev, shape, biasCanvas);
  814.     
  815.     FW_Boolean changed = !aqNewFrameShape->IsSameAs(ev, aqOldFrameShape);
  816.     
  817.     if (changed)
  818.         FrameShapeChanged(ev); 
  819.     
  820.     return changed;
  821. }
  822.  
  823. //----------------------------------------------------------------------------------------
  824. //     FW_CFrame::FacetAdded
  825. //----------------------------------------------------------------------------------------
  826. //    When overridden call inherited::FacetAdded FIRST
  827.  
  828. void FW_CFrame::FacetAdded(Environment* ev, ODFacet* facet, unsigned short facetCount)
  829. {        
  830.     // ----- Install the newest facet as the active facet of this frame
  831.     this->SetActiveFacet(ev, facet);
  832.     
  833.     // ----- Create the window wrapper -----
  834.     // ----- We have to wait for facet added because 
  835.     // ----- at FrameAdded it is too early
  836.     FW_CAcquiredODWindow aqODWindow = fODFrame->AcquireWindow(ev);
  837.     this->PrivCreateWindow(ev, aqODWindow);    // Might not create a FW_CWindow if already has one    
  838.  
  839.     // ----- for floating windows: remove all the foci by setting an empty set.
  840.     if (aqODWindow->IsFloating(ev))
  841.     {
  842.         GetPresentation(ev)->AdoptFocusSet(ev, NULL);
  843.     }
  844.     
  845.     // ----- Create the Shadow Window for Windows
  846. #ifdef FW_BUILD_WIN
  847.     CreateShadowWindow(ev);
  848. #endif    
  849.  
  850.     // ----- First facet: update used shape and create the sub-views
  851.     if (facetCount == 1)
  852.     {
  853.         UpdateUsedShape(ev);
  854.         
  855.         // Create views only once during the frame's life!
  856.         if (!fSubViewsCreated)
  857.         {
  858.             if (fResourceId != 0)
  859.             {
  860.                 // Automatic view creation from resources
  861.                 CreateSubViewsFromResource(ev, fResourceId);
  862.             }
  863.             else
  864.             {
  865.                 // Manual view creation
  866.                 CreateSubViews(ev);
  867.             }
  868.             fSubViewsCreated = TRUE;
  869.         }
  870.         
  871.         if (fInternalTransformRealigmentNeeded)
  872.             PrivRealignInternalTransform(ev);
  873.     }
  874.  
  875.     // ----- Give my frame a chance to update the active shape of the facet -----
  876.     UpdateActiveShape(ev, facet);
  877.     
  878.     // ----- Finally invalidate the content of the facet so it will be redrawn -----
  879.     FW_CAcquiredODShape aqUsedShape = AcquireUsedShape(ev); 
  880.     facet->Invalidate(ev, aqUsedShape, NULL);
  881. }
  882.  
  883. //----------------------------------------------------------------------------------------
  884. //     FW_CFrame::FacetRemoved
  885. //----------------------------------------------------------------------------------------
  886. //    When overridden call inherited::FacetRemoved last
  887.  
  888. void FW_CFrame::FacetRemoved(Environment* ev, ODFacet* odFacet, unsigned short facetCount)
  889. {
  890.     if (this->GetActiveFacet(ev) == odFacet)
  891.     {
  892.         FW_CFrameFacetIterator iter(ev, this);
  893.         this->SetActiveFacet(ev, iter.First(ev));
  894.     }
  895.     
  896.     // ----- Delete the fWindow if it was the last facet -----
  897.     if (facetCount == 1)
  898.     {
  899.         FW_ASSERT(fWindow);
  900.         
  901.         if (!fWindow->IsFloating(ev))    // If floating window the part has to release
  902.             delete fWindow;
  903.         
  904.         fWindow = NULL;
  905.     }
  906. }
  907.  
  908. //----------------------------------------------------------------------------------------
  909. //    FW_CFrame::GetWindow
  910. //----------------------------------------------------------------------------------------
  911.  
  912. FW_CWindow* FW_CFrame::GetWindow(Environment* ev) const
  913. {
  914. FW_UNUSED(ev);
  915.     return fWindow;
  916. }
  917.  
  918. //----------------------------------------------------------------------------------------
  919. //    FW_CFrame::ViewTypeChanged
  920. //----------------------------------------------------------------------------------------
  921.  
  922. void FW_CFrame::ViewTypeChanged(Environment* ev, 
  923.                                 ODTypeToken newViewType, 
  924.                                 ODTypeToken oldViewType)
  925. {
  926. FW_UNUSED(oldViewType);
  927.     Invalidate(ev);
  928.     
  929.     if (fViewAs != NULL)
  930.         fPresentation->PrivReleaseViewAs(fViewAs);
  931.     fViewAs = NULL;
  932.     
  933.     PrivCreateViewAs(ev);
  934.         
  935.     UpdateUsedAndActiveShapes(ev);
  936.     
  937.     Invalidate(ev);
  938.     
  939.     // ----- Only If I have an associated FW_MDroppableFrame -----
  940.     if (fDroppable)
  941.         fODFrame->SetDroppable(ev, FW_MDroppableFrame::PrivDroppableStateToBoolean(fDroppableState, newViewType));
  942. }
  943.  
  944. //----------------------------------------------------------------------------------------
  945. //    FW_CFrame::BuildThumbnail
  946. //----------------------------------------------------------------------------------------
  947. //    By default does nothing
  948.  
  949. void FW_CFrame::BuildThumbnail(Environment* ev, FW_CGraphicContext& gc, FW_CRect& usedRect)
  950. {
  951. FW_UNUSED(ev);
  952. FW_UNUSED(gc);
  953. FW_UNUSED(usedRect);
  954. }
  955.  
  956. //----------------------------------------------------------------------------------------
  957. //    FW_CFrame::GetIcon
  958. //----------------------------------------------------------------------------------------
  959. //    By default returns the part icon
  960.  
  961. FW_CIcon FW_CFrame::GetIcon(Environment* ev, short iconSize) const
  962. {
  963.     FW_CSharedLibraryResourceFile resourceFile(ev, fPart->GetPartInstance(ev));
  964.     FW_CIcon icon(resourceFile, fPart->GetViewAsIconID(ev), iconSize);
  965.     
  966.     return icon;
  967. }
  968.  
  969. //----------------------------------------------------------------------------------------
  970. //    FW_CFrame::PresentationChanged
  971. //----------------------------------------------------------------------------------------
  972.  
  973. void FW_CFrame::PresentationChanged(Environment* ev)
  974. {    
  975. FW_UNUSED(ev);
  976.     SetViewId(ev, fPresentation->GetPresentationType(ev));
  977. }
  978.  
  979. //----------------------------------------------------------------------------------------
  980. //    FW_CFrame::SequenceChanged
  981. //----------------------------------------------------------------------------------------
  982.  
  983. void FW_CFrame::SequenceChanged(Environment* ev)
  984. {    
  985. FW_UNUSED(ev);
  986. }
  987.  
  988. //----------------------------------------------------------------------------------------
  989. //    FW_CFrame::HandleActivateEvent
  990. //----------------------------------------------------------------------------------------
  991.  
  992. void FW_CFrame::HandleActivateEvent(Environment* ev, const FW_CActivateEvent& theActivateEvent)
  993. {
  994.     if (theActivateEvent.IsActivating(ev))
  995.     {
  996.         if (fNeedsFoci) 
  997.             PrivActivateFrame(ev, theActivateEvent.GetFacet(ev));
  998.     }
  999.     else
  1000.     {
  1001.         fNeedsFoci = fHasSelectionFocus;
  1002.     }
  1003.     
  1004.     FW_CSuperView::HandleActivateEvent(ev, theActivateEvent);
  1005. }
  1006.  
  1007. //----------------------------------------------------------------------------------------
  1008. //    FW_CFrame::HandleSuspendResumeEvent
  1009. //----------------------------------------------------------------------------------------
  1010.  
  1011. FW_Boolean FW_CFrame::HandleSuspendResumeEvent(Environment* ev, const FW_CSuspendResumeEvent& theResumeSuspendEvent)
  1012. {
  1013.     FW_Boolean backToForeground = !theResumeSuspendEvent.IsGoingToBackground(ev);
  1014.     
  1015.     // [LSD] see later to use keyFocus and menuFocus instead for target management
  1016.     if (HasSelectionFocus(ev))
  1017.     {
  1018.         if (backToForeground) {
  1019.             GetTarget(ev)->ActivateTarget(ev);
  1020.         } else {
  1021.             GetTarget(ev)->DeactivateTarget(ev);
  1022.         }
  1023.     }
  1024.  
  1025.     if (GetWindow(ev)->IsFloating(ev) && IsRoot(ev))
  1026.     {
  1027.         ODWindowState* windowState = fPart->GetSession(ev)->GetWindowState(ev);
  1028.         // ----- We have to test that this frame belongs to the part with the selection focus
  1029.         ODArbitrator* arbitrator =  fPart->GetSession(ev)->GetArbitrator(ev);
  1030.         FW_CAcquiredODFrame aqODFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::gSelectionFocusToken);
  1031.         if (aqODFrame != NULL)
  1032.         {
  1033.             FW_CAcquiredODPart aqODPart = aqODFrame->AcquirePart(ev);
  1034.             if (aqODPart == fPart->GetODPart(ev))
  1035.             {
  1036.                 ODWindowState* windowState = fPart->GetSession(ev)->GetWindowState(ev);
  1037.                 FW_CFloatingWindow::HideShowFloatingWindows(ev, windowState, backToForeground);
  1038.             }
  1039.         }
  1040.     }
  1041.     
  1042.     return FALSE;
  1043. }
  1044.  
  1045. //----------------------------------------------------------------------------------------
  1046. //    FW_CFrame::HandleMouseEnter
  1047. //----------------------------------------------------------------------------------------
  1048. // where is in frame coordinate
  1049.  
  1050. FW_Boolean FW_CFrame::HandleMouseEnter(Environment *ev, ODFacet* odFacet, const FW_CPoint& where)
  1051. {
  1052.     fViewUnderCursor = GetViewContaining(ev, odFacet, where);
  1053.     if (fViewUnderCursor == NULL)
  1054.         return FALSE;
  1055.  
  1056.     if (!fViewUnderCursor->AdjustCursor(ev, odFacet, where))
  1057.         FW_gArrowCursor.Select();
  1058.  
  1059.     return (fViewUnderCursor->IsEnabled(ev)) ? 
  1060.         fViewUnderCursor->DoMouseEnter(ev, odFacet, where) : FALSE;
  1061. }
  1062.  
  1063. //----------------------------------------------------------------------------------------
  1064. //    FW_CFrame::HandleMouseLeave
  1065. //----------------------------------------------------------------------------------------
  1066.  
  1067. FW_Boolean FW_CFrame::HandleMouseLeave(Environment *ev, ODFacet* odFacet)
  1068. {
  1069.     FW_gArrowCursor.Select();
  1070.     
  1071.     FW_Boolean result = fViewUnderCursor ? fViewUnderCursor->DoMouseLeave(ev, odFacet) : FALSE;
  1072.  
  1073.     fViewUnderCursor = NULL;
  1074.     
  1075.     return result;
  1076. }
  1077.  
  1078. //----------------------------------------------------------------------------------------
  1079. //    FW_CFrame::HandleMouseWithin
  1080. //----------------------------------------------------------------------------------------
  1081. // where is in frame coordinate
  1082.  
  1083. FW_Boolean FW_CFrame::HandleMouseWithin(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
  1084. {
  1085.     FW_CView* viewUnderCursor = GetViewContaining(ev, odFacet, theMousePoint);
  1086.     if (viewUnderCursor == NULL)
  1087.         return FALSE;
  1088.         
  1089.     if (viewUnderCursor != fViewUnderCursor)
  1090.     {
  1091.         if (fViewUnderCursor != NULL)
  1092.             fViewUnderCursor->DoMouseLeave(ev, odFacet);
  1093.         
  1094.         viewUnderCursor->DoMouseEnter(ev, odFacet, theMousePoint);
  1095.     }
  1096.     else
  1097.         viewUnderCursor->DoMouseWithin(ev, odFacet, theMousePoint);
  1098.         
  1099.     fViewUnderCursor = viewUnderCursor;
  1100.     
  1101.     if (!fViewUnderCursor->AdjustCursor(ev, odFacet, theMousePoint))
  1102.         FW_gArrowCursor.Select();
  1103.         
  1104.     return TRUE;
  1105. }
  1106.  
  1107. //----------------------------------------------------------------------------------------
  1108. //    FW_CFrame::GeometryChanged
  1109. //----------------------------------------------------------------------------------------
  1110. //    the geometry (clip shape or external transform) of one of my facet or one of my
  1111. //    embedding facet as changed
  1112.  
  1113. void FW_CFrame::GeometryChanged(Environment *ev,
  1114.                                 ODFacet* odFacet,
  1115.                                 FW_Boolean clipShapeChanged,
  1116.                                 FW_Boolean externalTransformChanged)
  1117. {
  1118. FW_UNUSED(ev);
  1119. FW_UNUSED(odFacet);
  1120. FW_UNUSED(clipShapeChanged);
  1121. FW_UNUSED(externalTransformChanged);
  1122.  
  1123. #ifdef FW_BUILD_WIN
  1124.     MoveSizeShadowWindow(ev);
  1125. #endif
  1126. }
  1127.  
  1128. //----------------------------------------------------------------------------------------
  1129. //    FW_CFrame::HandleDraw
  1130. //----------------------------------------------------------------------------------------
  1131. // invalidShape is in frame coordinate
  1132.  
  1133. FW_Boolean FW_CFrame::HandleDraw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1134. {
  1135.     //     if the facet doesn't have a graphicdevice it is not one of my facet anymore
  1136.     //    That means that FacetRemoved has been called but my container is still trying
  1137.     //    do draw me.[HLX] Might be a bug in OpenDoc. Might have been fixed in DR4
  1138.     if (FW_GetFacetGraphicDevice(ev, odFacet) == NULL)
  1139.         return TRUE;
  1140.         
  1141. #ifdef FW_BUILD_WIN
  1142.     // [HLX] bug in windows? the invalidShape is in pixels instead of points
  1143.     aqInvalidShape->Outset(ev, ff(1));    // [HLX] Because of rounding errors
  1144.     FW_CGraphicDevice *device = FW_GetFacetGraphicDevice(ev, odFacet);
  1145.     device->PixelToPoint(ev, aqInvalidShape);
  1146. #endif
  1147.     
  1148.     // ----- Check if the fViewAs has been created
  1149.     PrivCreateViewAs(ev);
  1150.     if (fViewAs == NULL)
  1151.     {
  1152.         FW_CSuperView::HandleDraw(ev, odFacet, invalidShape);
  1153.         
  1154.         // ----- If hilited state draw the hilite state
  1155.         if (odFacet->GetHighlight(ev) == kODFullHighlight)
  1156.             DrawHighlight(ev, odFacet, kODFullHighlight, invalidShape);
  1157.     }
  1158.     else
  1159.     {
  1160.         fViewAs->Draw(ev, this, odFacet, invalidShape);
  1161.     }
  1162.  
  1163.     return TRUE;
  1164. }
  1165.  
  1166. //----------------------------------------------------------------------------------------
  1167. //    FW_CFrame::Draw
  1168. //----------------------------------------------------------------------------------------
  1169. // invalidShape is in content coordinate
  1170.  
  1171. void FW_CFrame::Draw(Environment *ev, ODFacet* odFacet, ODShape* invalidShape)
  1172. {
  1173. FW_UNUSED(ev);
  1174. FW_UNUSED(odFacet);
  1175. FW_UNUSED(invalidShape);
  1176. }
  1177.  
  1178. //----------------------------------------------------------------------------------------
  1179. //    FW_CFrame::DrawHighlight
  1180. //----------------------------------------------------------------------------------------
  1181.  
  1182. void FW_CFrame::DrawHighlight(Environment *ev, ODFacet* facet, ODHighlight hilite, ODShape* invalidShape)
  1183. {
  1184.     FW_CFrameContext fc(ev, facet, invalidShape);
  1185.     FW_CAcquiredODShape usedShape = AcquireUsedShape(ev);
  1186.     if (hilite == kODFullHighlight)
  1187.         FW_CRegionShape::RenderRegion(fc, usedShape, FW_kFill, FW_CInk(FW_kHilite));
  1188.     else if (hilite == kODNoHighlight || hilite == kODDimHighlight)
  1189.     {
  1190. #ifdef FW_BUILD_MAC
  1191.         FW_CRegionShape::RenderRegion(fc, usedShape, FW_kFill, FW_CInk(FW_kHilite));    
  1192. #endif
  1193. #ifdef FW_BUILD_WIN
  1194.         facet->Invalidate(ev, NULL, NULL);    // NULL for the shape is fine
  1195. #endif    
  1196.     }
  1197. }
  1198.  
  1199. //----------------------------------------------------------------------------------------
  1200. //    FW_CFrame::HighlightChanged
  1201. //----------------------------------------------------------------------------------------
  1202.  
  1203. void FW_CFrame::HighlightChanged(Environment *ev, ODFacet* facet)
  1204. {
  1205.     // In the Icon/Thumbnail case just invalidate the facet
  1206.     if (GetViewType(ev) != FW_CPart::gViewAsFrameToken)
  1207.         facet->Invalidate(ev, NULL, NULL);    // NULL for the shape is fine
  1208.     else
  1209.         DrawHighlight(ev, facet, facet->GetHighlight(ev), NULL);
  1210. }
  1211.  
  1212. //----------------------------------------------------------------------------------------
  1213. //    FW_CFrame::AdjustCursor
  1214. //----------------------------------------------------------------------------------------
  1215. // where is in frame coordinate
  1216.  
  1217. FW_Boolean FW_CFrame::AdjustCursor(Environment *ev, ODFacet* odFacet, const FW_CPoint& theMousePoint)
  1218. {
  1219. FW_UNUSED(ev);
  1220. FW_UNUSED(odFacet);
  1221. FW_UNUSED(theMousePoint);
  1222.     return FALSE;
  1223. }
  1224.  
  1225. //----------------------------------------------------------------------------------------
  1226. //    FW_CFrame::GetODPart
  1227. //----------------------------------------------------------------------------------------
  1228.  
  1229. ODPart* FW_CFrame::GetODPart(Environment* ev) const
  1230. {
  1231.     return fPart->GetODPart(ev);
  1232. }
  1233.  
  1234. //----------------------------------------------------------------------------------------
  1235. //    FW_CFrame::SetContentView
  1236. //----------------------------------------------------------------------------------------
  1237.  
  1238. void FW_CFrame::SetContentView(Environment* ev, FW_CSuperView* view) 
  1239. {
  1240.     // SetContentView can only be called once to changed fContentView
  1241.     // which was initialized to the frame itself
  1242.     FW_ASSERT(IsContentView(ev) == TRUE);
  1243.     
  1244.     if (view != this) 
  1245.     {
  1246.         PrivSetIsContentView(ev, FALSE);
  1247.         fContentView = view;
  1248.  
  1249.         // Make the content view the default target for menu and keyboard events
  1250.         fTarget = fContentView;
  1251.  
  1252.         FW_CRect bounds = view->GetBounds(ev);
  1253.         FW_CSuperView* superView = view->GetSuperView(ev);
  1254.         if (superView)
  1255.             superView->ViewContentToFrame(ev, bounds);
  1256.  
  1257.         PrivContentViewLocationChanged(ev, bounds.TopLeft());
  1258.     }
  1259. }
  1260.  
  1261. //----------------------------------------------------------------------------------------
  1262. //    FW_CFrame::AdoptScroller
  1263. //----------------------------------------------------------------------------------------
  1264.  
  1265. void FW_CFrame::AdoptScroller(Environment* ev, FW_CScroller* scroller)
  1266. {
  1267.     // [LSD] Set the content view's scrolling flag in case it wasn't set in ctor
  1268.     //         To be reviewed.
  1269.     FW_CSuperView* contentView = GetContentView(ev);  // could be the frame itself
  1270.     if (contentView->IsScrolling(ev) == false)
  1271.     {
  1272.         contentView->SetScrollingInX(ev, true);
  1273.         contentView->SetScrollingInY(ev, true);
  1274.     }
  1275.     
  1276. #ifdef FW_DEBUG
  1277.     scroller->PrivCheckFrame(ev);
  1278. #endif        
  1279.     
  1280.     // [LSD] don't allow to change an existing scroller for now
  1281.     FW_ASSERT(fScroller == NULL);
  1282.     fScroller = scroller;
  1283.     
  1284.     PrivUpdateScrollParameters(ev);
  1285. }
  1286.  
  1287. //----------------------------------------------------------------------------------------
  1288. //    FW_CFrame::ExternalizeFrame
  1289. //----------------------------------------------------------------------------------------
  1290.  
  1291. void FW_CFrame::ExternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1292. {
  1293.     // ----- Write first a version number
  1294.     FW_CByteArray byteArray(&FW_kFrameVersion, sizeof(FW_FrameVersion));
  1295.     storageUnitView->SetValue(ev, byteArray);
  1296.  
  1297.     // ----- Write content view offset
  1298.     byteArray.Set(&fContentViewOffset, sizeof(fContentViewOffset));
  1299.     storageUnitView->SetValue(ev, byteArray);
  1300.  
  1301.     // ----- Write requestedFrame flag
  1302.     byteArray.Set(&fRequestedFrame, sizeof(fRequestedFrame));
  1303.     storageUnitView->SetValue(ev, byteArray);
  1304. }
  1305.  
  1306. //----------------------------------------------------------------------------------------
  1307. //    FW_CFrame::InternalizeFrame
  1308. //----------------------------------------------------------------------------------------
  1309.  
  1310. void FW_CFrame::InternalizeFrame(Environment* ev, ODStorageUnitView* storageUnitView)
  1311. {
  1312.     FW_CByteArray byteArray;
  1313.  
  1314.     // ----- Read first a version number
  1315.     FW_FrameVersion version;
  1316.     storageUnitView->GetValue(ev, sizeof(FW_FrameVersion), byteArray);
  1317.     byteArray.CopyBuffer(&version, sizeof(FW_FrameVersion));
  1318.     FW_ASSERT(version == FW_kFrameVersion);
  1319.     
  1320.     // ----- Read content view offset
  1321.     storageUnitView->GetValue(ev, sizeof(fContentViewOffset), byteArray);
  1322.     byteArray.CopyBuffer(&fContentViewOffset, sizeof(fContentViewOffset));
  1323.     
  1324.     // ----- Read requestedFrame flag
  1325.     storageUnitView->GetValue(ev, sizeof(fRequestedFrame), byteArray);
  1326.     byteArray.CopyBuffer(&fRequestedFrame, sizeof(fRequestedFrame));
  1327.     
  1328.     // ----- The Internal transform needs to be realign because
  1329.     // the view layout may have changed
  1330.     fInternalTransformRealigmentNeeded = TRUE;
  1331. }
  1332.  
  1333. //----------------------------------------------------------------------------------------
  1334. //    FW_CFrame::GetContentExtent
  1335. //----------------------------------------------------------------------------------------
  1336.  
  1337. void FW_CFrame::GetContentExtent(Environment* ev, FW_CPoint& extent) const
  1338. {
  1339.     extent = GetContentView(ev)->GetExtent(ev);
  1340. }
  1341.  
  1342. //----------------------------------------------------------------------------------------
  1343. //    FW_CFrame::AcquireContentShape
  1344. //----------------------------------------------------------------------------------------
  1345. //    return the content shape in Frame coordinates
  1346.  
  1347. ODShape* FW_CFrame::AcquireContentShape(Environment *ev)
  1348. {    
  1349.     FW_CSuperView* contentView = GetContentView(ev);
  1350.     
  1351.     FW_CRect contentRect(contentView->GetBounds(ev));
  1352.     
  1353.     FW_CSuperView* superView = contentView->GetSuperView(ev);
  1354.     if (superView)
  1355.         superView->ViewContentToFrame(ev, contentRect);
  1356.     
  1357.     return FW_NewODShape(ev, contentRect);
  1358. }
  1359.  
  1360. //----------------------------------------------------------------------------------------
  1361. //    FW_CFrame::GetFocusSet
  1362. //----------------------------------------------------------------------------------------
  1363.  
  1364. ODFocusSet* FW_CFrame::GetFocusSet(Environment* ev) const
  1365. {
  1366.     return fPresentation->GetFocusSet(ev);
  1367. }
  1368.  
  1369. //----------------------------------------------------------------------------------------
  1370. //    FW_CFrame::BeginRelinquishFocus
  1371. //----------------------------------------------------------------------------------------
  1372.  
  1373. FW_Boolean FW_CFrame::BeginRelinquishFocus(Environment *ev, ODTypeToken focus, ODFrame* proposedFrame)
  1374. {
  1375. FW_UNUSED(ev);
  1376. FW_UNUSED(focus);
  1377. FW_UNUSED(proposedFrame);
  1378.     return TRUE;
  1379. }
  1380.  
  1381. //----------------------------------------------------------------------------------------
  1382. //    FW_CFrame::AbortRelinquishFocus
  1383. //----------------------------------------------------------------------------------------
  1384.  
  1385. void FW_CFrame::AbortRelinquishFocus(Environment *ev, ODTypeToken focus, ODFrame* proposedFrame)
  1386. {
  1387. FW_UNUSED(ev);
  1388. FW_UNUSED(focus);
  1389. FW_UNUSED(proposedFrame);
  1390. }
  1391.  
  1392. //----------------------------------------------------------------------------------------
  1393. //    FW_CFrame::ClonePartInfo
  1394. //----------------------------------------------------------------------------------------
  1395.  
  1396. void FW_CFrame::ClonePartInfo(Environment* ev, 
  1397.                             ODDraftKey key,
  1398.                             ODInfoType partInfo,
  1399.                             ODStorageUnitView* storageUnitView,
  1400.                             ODFrame* scope)
  1401. {
  1402. FW_UNUSED(ev);
  1403. FW_UNUSED(key);
  1404. FW_UNUSED(partInfo);
  1405. FW_UNUSED(storageUnitView);
  1406. FW_UNUSED(scope);
  1407.     // Don't do anything for now
  1408. }
  1409.  
  1410. #ifdef FW_BUILD_WIN
  1411. //----------------------------------------------------------------------------------------
  1412. //    FW_CFrame::CreateShadowWindow
  1413. //----------------------------------------------------------------------------------------
  1414. // Create a transparent Window so that we get a chance to handle messages sent by Windows
  1415. // controls to their parent Window.
  1416.  
  1417. void FW_CFrame::CreateShadowWindow(Environment *ev)
  1418. {
  1419.     ODPlatformWindow parentHWnd = fWindow->GetPlatformWindow(ev);
  1420. #ifdef FW_BUILD_WIN16
  1421.     HINSTANCE hInstance = (HINSTANCE)GetWindowWord(parentHWnd, GWW_HINSTANCE);
  1422. #endif
  1423. #ifdef FW_BUILD_WIN32
  1424.     HINSTANCE hInstance = (HINSTANCE)GetWindowLong(parentHWnd, GWL_HINSTANCE);
  1425. #endif
  1426.     
  1427.     WNDCLASS wc;
  1428.     
  1429.     if (!GetClassInfo(hInstance, "ShadowWindow", &wc))
  1430.     {
  1431.         wc.style = CS_DBLCLKS;
  1432.         wc.lpfnWndProc = ShadowWindowProc;
  1433.         wc.cbClsExtra = 0;
  1434.         wc.cbWndExtra = 4;
  1435.         wc.hInstance = hInstance;
  1436.         wc.hIcon = NULL;
  1437.         wc.hCursor = LoadCursor(NULL, IDC_ARROW);
  1438.         wc.hbrBackground = NULL;
  1439.         wc.lpszMenuName = NULL;
  1440.         wc.lpszClassName = "ShadowWindow";
  1441.         
  1442.         if (!RegisterClass(&wc))
  1443.             return;
  1444.     }
  1445.     
  1446.     fShadowWindow = CreateWindowEx(WS_EX_TRANSPARENT, "ShadowWindow", "",
  1447.                                    WS_CHILD | WS_VISIBLE, 0, 0, 0, 0,
  1448.                                    parentHWnd, NULL, hInstance, (LPSTR) this);
  1449.     MoveSizeShadowWindow(ev);
  1450. }
  1451. #endif
  1452.  
  1453. #ifdef FW_BUILD_WIN
  1454. //----------------------------------------------------------------------------------------
  1455. //    FW_CFrame::MoveSizeShadowWindow
  1456. //----------------------------------------------------------------------------------------
  1457.  
  1458. void FW_CFrame::MoveSizeShadowWindow(Environment* ev)
  1459. {
  1460.     if (fShadowWindow != NULL)
  1461.     {
  1462.         ODFacet* facet = GetActiveFacet(ev);
  1463.         FW_CAcquiredODShape aqShape(FW_CopyAndRelease(ev, facet->AcquireActiveShape(ev, NULL)));
  1464.         FW_CAcquiredODTransform aqExternalTransform = facet->AcquireExternalTransform(ev, NULL);
  1465.         aqShape->Transform(ev, aqExternalTransform);
  1466.         
  1467.         FW_CRect bBox;
  1468.         aqShape->GetBoundingBox(ev, &bBox);
  1469.         
  1470.         // Shape bounding box is in 72dpi, need to convert to pixels
  1471.         if(!IsRoot(ev))
  1472.         {
  1473.             // [KVV] ??? This is only necessary for non-root frames
  1474.         
  1475.             HDC hDC = ::GetDC(NULL);
  1476.             int xRes = ::GetDeviceCaps(hDC, LOGPIXELSX);
  1477.             int yRes = ::GetDeviceCaps(hDC, LOGPIXELSY);
  1478.             ::ReleaseDC(NULL, hDC);
  1479.             
  1480.             FW_Fixed xScale = FW_FixDiv(ff(xRes), ff(72));
  1481.             FW_Fixed yScale = FW_FixDiv(ff(yRes), ff(72));
  1482.             
  1483.             bBox.left     = FW_FixMul(bBox.left,    xScale);
  1484.             bBox.top     = FW_FixMul(bBox.top,    yScale);
  1485.             bBox.right     = FW_FixMul(bBox.right,    xScale);
  1486.             bBox.bottom    = FW_FixMul(bBox.bottom,yScale);
  1487.         }
  1488.         
  1489.         FW_SPlatformRect wndRect = bBox.AsPlatformRect();
  1490.         
  1491.         ::MoveWindow(fShadowWindow, wndRect.left, wndRect.top,
  1492.                        wndRect.right - wndRect.left, wndRect.bottom - wndRect.top, TRUE);
  1493.     }
  1494. }
  1495. #endif
  1496.  
  1497. #ifdef FW_BUILD_WIN
  1498. //----------------------------------------------------------------------------------------
  1499. //    FW_CFrame::ShadowWindowProc
  1500. //----------------------------------------------------------------------------------------
  1501.  
  1502. LRESULT CALLBACK FW_CFrame::ShadowWindowProc(HWND hWnd, UINT msg,
  1503.                                              WPARAM wParam, LPARAM lParam)
  1504. {
  1505.     switch (msg)
  1506.     {
  1507. #ifdef FW_DEBUG
  1508.         // ----- Frame the shadow window for ease of debugging
  1509.         case WM_PAINT:
  1510.             {
  1511.                 PAINTSTRUCT ps;
  1512.                 HDC hDC = ::BeginPaint(hWnd, &ps);
  1513.                 
  1514.                 if(::GetPrivateProfileInt("Debug", "ShadowWindow Outline", FALSE, "ODF.ini"))
  1515.                 {
  1516.                     static const char pattern[8][2] = 
  1517.                     {
  1518.                         { 0xAA, 0x00 },
  1519.                         { 0x55, 0x00 },
  1520.                         { 0xAA, 0x00 },
  1521.                         { 0x55, 0x00 },
  1522.                         { 0xAA, 0x00 },
  1523.                         { 0x55, 0x00 },
  1524.                         { 0xAA, 0x00 },
  1525.                         { 0x55, 0x00 }
  1526.                     };
  1527.                     
  1528.                     HBITMAP hBitmap = ::CreateBitmap(8, 8, 1, 1, pattern);
  1529.     
  1530.                     HBRUSH hBrush = ::CreatePatternBrush(hBitmap);
  1531.     
  1532.                     ::SetTextColor(hDC, RGB(0xFF, 0x00, 0xFF));
  1533.                     
  1534.                     RECT rc;
  1535.                     ::GetClientRect(hWnd, &rc);
  1536.                     
  1537.                     HRGN hRgn = ::CreateRectRgnIndirect(&rc);
  1538.                     
  1539.                     ::FrameRgn(hDC, hRgn, hBrush, 3, 3);
  1540.                     
  1541.                     ::DeleteObject(hRgn);
  1542.                     ::DeleteObject(hBrush);
  1543.                     ::DeleteObject(hBitmap);
  1544.                 }
  1545.  
  1546.                 ::EndPaint(hWnd, &ps);
  1547.             }
  1548.             return 0;
  1549. #endif
  1550.  
  1551.         case WM_CREATE:
  1552.             SetWindowLong(hWnd, 0, (long) ((LPCREATESTRUCT) lParam)->lpCreateParams);
  1553.             return 0;
  1554.             
  1555.         case WM_NCHITTEST:
  1556.             return HTTRANSPARENT;
  1557.             
  1558.         case WM_COMMAND:
  1559.             switch (HIWORD(wParam))
  1560.             {
  1561.                 case BN_CLICKED:
  1562.                     {
  1563.                         HWND hButton = HWND(lParam);
  1564.                         
  1565.                         // If this is a window
  1566.                         if (hButton != NULL && ::IsWindow(hButton))
  1567.                         {
  1568.                             // Get the scroll bar helper
  1569.                             FW_CPrivWinButtonHelper* buttonHelper =
  1570.                                 FW_DYNAMIC_CAST(FW_CPrivWinButtonHelper, FW_CPrivWinControlHelper::HWNDToHelper(hButton));
  1571.         
  1572.                             // Tell the button to update itself and the pane
  1573.                             buttonHelper->HandleButtonMessage();
  1574.                             return 0L;
  1575.                         }
  1576.                     }
  1577.                     break;
  1578.             }
  1579.             break;
  1580.             
  1581.         case WM_HSCROLL:
  1582.         case WM_VSCROLL:
  1583.             {
  1584.                 HWND hBar = HWND(lParam);
  1585.  
  1586.                 // If this is not a scroll bar control, but a Windows
  1587.                 // window scroll bar, pass it to Windows wndproc
  1588.                 if (hBar == NULL)
  1589.                 {
  1590.                     FW_DEBUG_MESSAGE("Warning: ODF does not use Window scroll bars!");
  1591.                     break;
  1592.                 }
  1593.  
  1594.                 // If this is a window
  1595.                 if (hBar != NULL && ::IsWindow(hBar))
  1596.                 {
  1597.                     // Get the scroll bar helper
  1598.                     FW_CPrivWinScrollBarHelper* sbHelper =
  1599.                         FW_DYNAMIC_CAST(FW_CPrivWinScrollBarHelper, FW_CPrivWinControlHelper::HWNDToHelper(hBar));
  1600.  
  1601.                     // Tell the scroll bar to update itself and the pane
  1602.                     if (sbHelper != NULL)
  1603.                     {
  1604.                         sbHelper->HandleScrollMessage(LOWORD(wParam), HIWORD(wParam));
  1605.                         return 0L;
  1606.                     }
  1607.                 }
  1608.                 break;
  1609.             }
  1610.     }
  1611.     
  1612.     return DefWindowProc(hWnd, msg, wParam, lParam);
  1613. }
  1614. #endif
  1615.  
  1616. //----------------------------------------------------------------------------------------
  1617. //    FW_CFrame::HasModalFocus
  1618. //----------------------------------------------------------------------------------------
  1619.  
  1620. FW_Boolean FW_CFrame::HasModalFocus(Environment* ev) const
  1621. {
  1622.     FW_CAcquiredODFrame aqODFrame = fPart->GetSession(ev)->GetArbitrator(ev)->AcquireFocusOwner(ev, FW_CPart::gModalFocusToken);
  1623.     return aqODFrame == fODFrame;
  1624. }
  1625.  
  1626. //----------------------------------------------------------------------------------------
  1627. //    FW_CFrame::HasPropertyOnClipboard
  1628. //----------------------------------------------------------------------------------------
  1629.  
  1630. FW_Boolean FW_CFrame::HasPropertyOnClipboard(Environment* ev, ODPropertyName propertyName, ODValueType type)
  1631. {
  1632.     ODSession* session = GetPart(ev)->GetSession(ev);
  1633.     ODArbitrator* arbitrator = session->GetArbitrator(ev);
  1634.     FW_CAcquiredODFrame aqODFrame = arbitrator->AcquireFocusOwner(ev, FW_CPart::gClipboardFocusToken);
  1635.     
  1636.     if ((aqODFrame == fODFrame) || (arbitrator->RequestFocus(ev, FW_CPart::gClipboardFocusToken, fODFrame)) )
  1637.     {    
  1638.         ODStorageUnit* su = session->GetClipboard(ev)->GetContentStorageUnit(ev);
  1639.         return su->Exists(ev, propertyName, type, 0);
  1640.     }
  1641.     else
  1642.     {
  1643.         return FALSE;
  1644.     }
  1645. }
  1646.  
  1647. //----------------------------------------------------------------------------------------
  1648. //    FW_CFrame::ChangeInternalTransform
  1649. //----------------------------------------------------------------------------------------
  1650.  
  1651. void FW_CFrame::ChangeInternalTransform(Environment* ev, ODTransform* internalTransform, ODCanvas* biasCanvas)
  1652. {
  1653.     // *LSD2  hack can be removed after DR4 ?
  1654. #ifdef FW_BUILD_MAC
  1655.     // [HLX] Temporary because of a bug in OpenDoc
  1656.     //    ChangeInternalTransform changes the clip and the origin and does not restore it
  1657.     GrafPtr port;
  1658.     ::GetPort(&port);    
  1659.     Point origin;
  1660.     origin.h = port->portRect.left;
  1661.     origin.v = port->portRect.top;
  1662.     ODRgnHandle clipRgn = ::NewRgn();
  1663.     ::GetClip(clipRgn);
  1664. #endif
  1665.     
  1666.     fODFrame->ChangeInternalTransform(ev, internalTransform, biasCanvas);
  1667.  
  1668. #ifdef FW_BUILD_MAC
  1669.     // [HLX] Temporary because of a bug in OpenDoc
  1670.     ::SetPort(port);
  1671.     ::SetClip(clipRgn);
  1672.     ::DisposeRgn(clipRgn);
  1673.     ::SetOrigin(-origin.h, -origin.v);
  1674. #endif
  1675.     
  1676.     // Now invalidate all the views Internal transforms
  1677.     PrivInvalidateViewIternalTransform(ev);
  1678. }
  1679.  
  1680. //----------------------------------------------------------------------------------------
  1681. //    FW_CFrame::ContainingPartPropertiesUpdated
  1682. //----------------------------------------------------------------------------------------
  1683.  
  1684. void FW_CFrame::ContainingPartPropertiesUpdated(Environment *ev, ODStorageUnit* propertyUnit)
  1685. {
  1686. FW_UNUSED(ev);
  1687. FW_UNUSED(propertyUnit);
  1688. }
  1689.  
  1690. //----------------------------------------------------------------------------------------
  1691. //    FW_CFrame::AcquireContainingPartProperties
  1692. //----------------------------------------------------------------------------------------
  1693.  
  1694. ODStorageUnit* FW_CFrame::AcquireContainingPartProperties(Environment* ev)
  1695. {
  1696. FW_UNUSED(ev);
  1697.  
  1698.     return NULL;
  1699. }
  1700.  
  1701. //----------------------------------------------------------------------------------------
  1702. //    FW_CFrame::NewPrintHandler
  1703. //----------------------------------------------------------------------------------------
  1704.  
  1705. FW_CPrintHandler* FW_CFrame::NewPrintHandler(Environment* ev)
  1706. {
  1707. FW_UNUSED(ev);
  1708.  
  1709.     return NULL;
  1710. }
  1711.  
  1712. //----------------------------------------------------------------------------------------
  1713. // FW_CFrame::SetLocation
  1714. //----------------------------------------------------------------------------------------
  1715.  
  1716. void FW_CFrame::SetLocation(Environment* ev, const FW_CPoint& location, FW_Boolean redraw)
  1717. {
  1718. FW_UNUSED(ev);
  1719. FW_UNUSED(location);
  1720. FW_UNUSED(redraw);
  1721.  
  1722.     FW_DEBUG_MESSAGE("Can't call SetLocation on a FW_CFrame");
  1723. }
  1724.  
  1725. //----------------------------------------------------------------------------------------
  1726. //     FW_CFrame::RelinquishFocusSet
  1727. //----------------------------------------------------------------------------------------
  1728. //    Usually should not have to be overriden. Can be overriden for special case
  1729.  
  1730. void FW_CFrame::RelinquishFocusSet(Environment *ev)
  1731. {
  1732.     ODArbitrator* arbitrator = fPart->GetSession(ev)->GetArbitrator(ev);
  1733.     arbitrator->RelinquishFocusSet(ev, GetFocusSet(ev), GetODFrame(ev));
  1734. }
  1735.  
  1736. //----------------------------------------------------------------------------------------
  1737. //     FW_CFrame::RequestFocusSet
  1738. //----------------------------------------------------------------------------------------
  1739. //    Usually should not have to be overriden. Can be overriden for special case
  1740.  
  1741. FW_Boolean FW_CFrame::RequestFocusSet(Environment *ev)
  1742. {
  1743.     ODArbitrator* arbitrator = fPart->GetSession(ev)->GetArbitrator(ev);
  1744.     return arbitrator->RequestFocusSet(ev, GetFocusSet(ev), GetODFrame(ev));
  1745. }
  1746.  
  1747. //----------------------------------------------------------------------------------------
  1748. // FW_CFrame::HandleIdle
  1749. //----------------------------------------------------------------------------------------
  1750.  
  1751. FW_Boolean FW_CFrame::HandleIdle(Environment* ev, const FW_CNullEvent& theNullEvent)
  1752. {
  1753.     if (IsInLimbo(ev)) return false;        // don't idle if we're in limbo
  1754.  
  1755.     return DoIdle(ev, theNullEvent);    
  1756. }
  1757.  
  1758. //========================================================================================
  1759. // Implementation Only API
  1760. //========================================================================================
  1761.  
  1762. //----------------------------------------------------------------------------------------
  1763. //    FW_CFrame::PrivCreateWindow
  1764. //----------------------------------------------------------------------------------------
  1765.  
  1766. FW_CWindow* FW_CFrame::PrivCreateWindow(Environment* ev, ODWindow* odWindow)
  1767. {
  1768.     FW_ASSERT(odWindow);
  1769. //    FW_ASSERT(fWindow == NULL || fWindow->GetID(ev) == odWindow->GetID(ev));
  1770.     
  1771.     // ----- Test first if this frame was in another window -----
  1772.     if (fWindow != NULL && fWindow->GetID(ev) != odWindow->GetID(ev))
  1773.     {
  1774.         delete fWindow;
  1775.         fWindow = NULL;
  1776.     }
  1777.     
  1778.     if (fWindow == NULL)
  1779.     {
  1780.         ODPlatformWindow platformWindow = odWindow->GetPlatformWindow(ev);
  1781.         
  1782.         FW_CWindow* fwWindow = NULL;
  1783.         
  1784.         if (IsRoot(ev))
  1785.         {
  1786. #ifdef FW_BUILD_MAC
  1787.             fwWindow = (FW_CWindow*) ::GetWRefCon(platformWindow);
  1788. #endif
  1789.  
  1790. #ifdef FW_BUILD_WIN
  1791.             fwWindow = (FW_CWindow*) ::GetProp(platformWindow, "ODF:Window");
  1792. #endif
  1793.         }
  1794.         
  1795.         if (fwWindow != NULL)
  1796.             fWindow = fwWindow;
  1797.         else
  1798.             fWindow = new FW_CWindow(ev, fPart, odWindow->GetID(ev));
  1799.     }
  1800.  
  1801.     fInSharedWindow = IsRoot(ev) && fWindow->IsFloating(ev);
  1802.     
  1803.     return fWindow;
  1804. }
  1805.  
  1806. //----------------------------------------------------------------------------------------
  1807. //    FW_CFrame::PrivSetDroppable
  1808. //----------------------------------------------------------------------------------------
  1809.  
  1810. void FW_CFrame::PrivSetDroppable(Environment *ev, FW_MDroppableFrame* droppable, FW_Boolean isDroppable)
  1811. {
  1812.     fDroppable = droppable;
  1813.     fODFrame->SetDroppable(ev, isDroppable);
  1814. }
  1815.  
  1816. #ifdef FW_BUILD_MAC
  1817. //----------------------------------------------------------------------------------------
  1818. //    FW_CFrame::PrivMacInGrowBox
  1819. //----------------------------------------------------------------------------------------
  1820.  
  1821.  void FW_CFrame::PrivMacInGrowBox(Environment* ev, const FW_CMacWindowEvent& windowEvent)
  1822.  {    
  1823.     FW_CRect growLimits(FW_IntToFixed(64), FW_IntToFixed(64), FW_IntToFixed(32000), FW_IntToFixed(32000));
  1824.     this->AdjustWindowGrowLimits(ev, growLimits[FW_kTopLeft], growLimits[FW_kBotRight]);
  1825.     
  1826.     // If minimum is lareger than maximun then do something
  1827.     if (growLimits.left > growLimits.right)
  1828.         growLimits.left = growLimits.right;
  1829.     if (growLimits.top > growLimits.bottom)
  1830.         growLimits.top = growLimits.bottom;
  1831.                     
  1832.      ODEventData* eventData = ((FW_CMacWindowEvent&)windowEvent).GetPlatformEvent();
  1833.      FW_CAcquiredODWindow aqODWindow = fWindow->AcquireODWindow(ev);
  1834.     
  1835.     FW_PlatformError error;
  1836.     FW_Boolean result = FW_PrivMacTrackResizeWindow(aqODWindow->GetPlatformWindow(ev), 
  1837.                                      growLimits,
  1838.                                      eventData->where,
  1839.                                      &error);
  1840.      FW_FailOnError(error);
  1841.      if (result)
  1842.      {
  1843.         aqODWindow->AdjustWindowShape(ev);
  1844.     }
  1845. }
  1846. #endif
  1847.  
  1848. //----------------------------------------------------------------------------------------
  1849. //     FW_CFrame::PrivActivateFrame
  1850. //----------------------------------------------------------------------------------------
  1851.  
  1852. void FW_CFrame::PrivActivateFrame(Environment *ev, ODFacet* activatedFacet)
  1853.     if (CanBeActiveFrame(ev))
  1854.     {
  1855.         SetActiveFacet(ev, activatedFacet);
  1856.         
  1857.         if (fHasSelectionFocus == FALSE)
  1858.         {
  1859.             if (RequestFocusSet(ev))
  1860.             {
  1861.                 fNeedsFoci = FALSE;
  1862.                 
  1863.                 FW_CFocusSetIterator iter(ev, this);
  1864.                 for( ODTypeToken token=iter.First(ev); iter.IsNotComplete(ev); token=iter.Next(ev) ) {
  1865.                     FocusStateChanged(ev, token, TRUE, NULL);            
  1866.                 }
  1867.             }
  1868.         }
  1869.     }
  1870. }
  1871.  
  1872. //----------------------------------------------------------------------------------------
  1873. //    FW_CFrame::PrivGetFrameShapeBounds
  1874. //----------------------------------------------------------------------------------------
  1875.  
  1876. void FW_CFrame::PrivGetFrameShapeBounds(Environment* ev, FW_CRect& rect) const
  1877. {
  1878.     FW_CAcquiredODShape aqODShape = AcquireFrameShape(ev, NULL);
  1879.     rect = FW_GetShapeBoundingBox(ev, aqODShape);
  1880. }
  1881.  
  1882. //----------------------------------------------------------------------------------------
  1883. //     FW_CFrame::PrivFacetRemoved
  1884. //----------------------------------------------------------------------------------------
  1885.  
  1886. void FW_CFrame::PrivFacetRemoved(Environment* ev, ODFacet* facet)
  1887. {
  1888.     FW_ASSERT(fFacetCount > 0);
  1889.     
  1890.     FacetRemoved(ev, facet, fFacetCount);
  1891.     
  1892.     // ----- One less facet -----
  1893.     fFacetCount--;
  1894. }
  1895.  
  1896. //----------------------------------------------------------------------------------------
  1897. //     FW_CFrame::PrivFacetAdded
  1898. //----------------------------------------------------------------------------------------
  1899.  
  1900. void FW_CFrame::PrivFacetAdded(Environment* ev, ODFacet* facet)
  1901. {
  1902.     // ----- One more facet -----
  1903.     fFacetCount++;    
  1904.  
  1905.     FacetAdded(ev, facet, fFacetCount);
  1906. }
  1907.  
  1908. //----------------------------------------------------------------------------------------
  1909. //    FW_CFrame::PrivAttachSourceFrame
  1910. //----------------------------------------------------------------------------------------
  1911. //    FW_CFrame::PrivAttachSourceFrame should not be called if sourceFrame == NULL
  1912.  
  1913. void FW_CFrame::PrivAttachSourceFrame(Environment* ev, FW_CFrame* sourceFrame)
  1914. {
  1915.     FW_ASSERT(sourceFrame != NULL);
  1916.     FW_ASSERT(fSourceFrame == this);    // fSourceFrame is set to this in the constructor
  1917.     
  1918.     fSourceFrame = sourceFrame->GetSourceFrame(ev);
  1919. }
  1920.  
  1921. //----------------------------------------------------------------------------------------
  1922. //     FW_CFrame::PrivActiveWindowOnMouseDown
  1923. //----------------------------------------------------------------------------------------
  1924.  
  1925. FW_Boolean FW_CFrame::PrivActiveWindowOnMouseDown(Environment* ev, ODFacet* facet, FW_Boolean clickedInFrame)
  1926. {
  1927.     if (!GetWindow(ev)->IsFloating(ev))
  1928.     {
  1929.         FW_Boolean windowUnselected = !GetWindow(ev)->IsActive(ev);
  1930.         
  1931.         // ----- Select the window if not already selected -----
  1932.         if (windowUnselected)
  1933.             GetWindow(ev)->Select(ev);        
  1934.         
  1935.         // ----- active frame on mousedown only if clicked in the frame -----
  1936.         if (clickedInFrame == TRUE && fHasSelectionFocus == FALSE)
  1937.             PrivActivateFrame(ev, facet);
  1938.         
  1939.         // ----- If the window was unselected and I don't want the ----- 
  1940.         // ----- first click just return TRUE;
  1941.         if (windowUnselected && !GetFrontClicks(ev))
  1942.                 return TRUE;
  1943.     }
  1944.     
  1945.     return FALSE;
  1946. }
  1947.  
  1948. //----------------------------------------------------------------------------------------
  1949. //    FW_CFrame::PrivUpdateScrollParameters
  1950. //----------------------------------------------------------------------------------------
  1951.  
  1952. void FW_CFrame::PrivUpdateScrollParameters(Environment* ev, FW_Boolean notify)
  1953. {
  1954.     if (fScroller && !fInternalTransformRealigmentNeeded)
  1955.         fScroller->UpdateScrollParameters(ev, notify);
  1956. }
  1957.  
  1958. //----------------------------------------------------------------------------------------
  1959. //    FW_CFrame::PrivContentViewLocationChanged
  1960. //----------------------------------------------------------------------------------------
  1961.  
  1962. void FW_CFrame::PrivContentViewLocationChanged(Environment* ev, const FW_CPoint& newLocation)
  1963. {
  1964.     if (fContentViewOffset != newLocation)
  1965.     {
  1966.         FW_CAcquiredODTransform aqFrameInternalTransform = AcquireInternalTransform(ev);
  1967.         aqFrameInternalTransform->MoveBy(ev, (ODPoint*)&(-fContentViewOffset));
  1968.         aqFrameInternalTransform->MoveBy(ev, (ODPoint*)&newLocation);
  1969.         ChangeInternalTransform(ev, aqFrameInternalTransform);
  1970.         
  1971.         fContentViewOffset = newLocation;
  1972.     }
  1973. }
  1974.  
  1975. //----------------------------------------------------------------------------------------
  1976. // FW_CFrame::PrivRealignInternalTransform
  1977. //----------------------------------------------------------------------------------------
  1978. //    This is call when a document is reopened. Because the internal transform is saved by OpenDoc
  1979. //    and the InternalTransform contains the offset of the ContentView, if this offset is not
  1980. //    the same when the document is reopened I need to realign the Internal transform
  1981. void FW_CFrame::PrivRealignInternalTransform(Environment* ev)
  1982. {
  1983.     FW_ASSERT(fContentView);
  1984.     
  1985.     FW_CRect bounds = fContentView->GetBounds(ev);
  1986.     FW_CSuperView* contentViewParent = fContentView->GetSuperView(ev);
  1987.     if (contentViewParent)
  1988.         contentViewParent->ViewContentToFrame(ev, bounds);
  1989.     
  1990.     PrivContentViewLocationChanged(ev, bounds.TopLeft());
  1991.     
  1992.     fInternalTransformRealigmentNeeded = FALSE;
  1993.  
  1994.     PrivUpdateScrollParameters(ev, FALSE);    // Don't want to notify
  1995. }
  1996.  
  1997. //---------------------------------------------------------------------------------------
  1998. //    FW_CFrame::PrivDragging
  1999. //---------------------------------------------------------------------------------------
  2000.  
  2001. void FW_CFrame::PrivDragging(Environment *ev, FW_Boolean state)
  2002. {
  2003. FW_UNUSED(ev);
  2004. FW_UNUSED(state);
  2005.     // No embedded frames
  2006. }
  2007.  
  2008. //----------------------------------------------------------------------------------------
  2009. // FW_CFrame::PrivCreateSubViewsFromStream
  2010. //----------------------------------------------------------------------------------------
  2011.  
  2012. void FW_CFrame::PrivCreateSubViewsFromStream(Environment* ev, FW_CReadableStream& stream)
  2013. {
  2014.     FW_PREREGISTER_RUNTIME_OBJECT(stream, 
  2015.                                 this, 
  2016.                                 FW_kPreregisteredFrameObject);
  2017.                                 
  2018.     FW_CSuperView::PrivCreateSubViewsFromStream(ev, stream);
  2019.  
  2020.     short count;
  2021.     stream >> count;
  2022.     FW_ASSERT(count >= 0);
  2023.     FW_ASSERT(count <= 1);
  2024.     if (count == 1)
  2025.     {
  2026.         FW_CPrivBaseScroller* scroller;
  2027.         FW_READ_DYNAMIC_OBJECT(stream, &scroller, FW_CPrivBaseScroller);
  2028.         
  2029.         // [HLX] I am always dealing with a FW_CScroller
  2030.         AdoptScroller(ev, (FW_CScroller*)scroller);    
  2031.     }
  2032. }
  2033.  
  2034. //----------------------------------------------------------------------------------------
  2035. // FW_CFrame::PrivButtonAttached
  2036. //----------------------------------------------------------------------------------------
  2037.  
  2038. void FW_CFrame::PrivButtonAttached(Environment* ev, FW_CButton* button)
  2039. {
  2040. FW_UNUSED(ev);
  2041. FW_UNUSED(button);
  2042.     // Nothing to do look at FW_CDialogFrame
  2043. }
  2044.  
  2045. //----------------------------------------------------------------------------------------
  2046. // FW_CFrame::PrivCreateViewAs
  2047. //----------------------------------------------------------------------------------------
  2048. // Call in places where the viewas object might not be yet created 
  2049.  
  2050. void FW_CFrame::PrivCreateViewAs(Environment* ev)
  2051. {
  2052.     ODTypeToken viewType = GetViewType(ev);
  2053.     if (viewType != FW_CPart::gViewAsFrameToken && fViewAs == NULL)
  2054.     {
  2055.         fViewAs = fPresentation->PrivAcquireViewAs(ev, this, viewType);
  2056.     }
  2057. }
  2058.