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 / FWWindow / FWFloWin.cpp next >
Encoding:
Text File  |  1996-09-17  |  11.4 KB  |  378 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWFloWin.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 FWFLOWIN_H
  13. #include "FWFloWin.h"
  14. #endif
  15.  
  16. #ifndef FWACQUIR_H
  17. #include "FWAcquir.h"
  18. #endif
  19.  
  20. #ifndef FWPART_H
  21. #include "FWPart.h"
  22. #endif
  23.  
  24. #ifndef FWPRESEN_H
  25. #include "FWPresen.h"
  26. #endif
  27.  
  28. #ifndef FWSHDWIN_H
  29. #include "FWShdWin.h"
  30. #endif
  31.  
  32. #ifndef FWFRAME_H
  33. #include "FWFrame.h"
  34. #endif
  35.  
  36. #ifndef FWSESION_H
  37. #include "FWSesion.h"
  38. #endif
  39.  
  40. // ----- Foundation Includes -----
  41.  
  42. #ifndef FWEXCLIB_H
  43. #include "FWExcLib.h"
  44. #endif
  45.  
  46. #ifndef   FWRESACC_H
  47. #include "FWResAcc.h"
  48. #endif
  49.  
  50. #ifndef FWSOMENV_H
  51. #include "FWSOMEnv.h"
  52. #endif
  53.  
  54. // ----- OpenDoc Includes -----
  55.  
  56. #ifndef SOM_ODWindow_xh
  57. #include <Window.xh>
  58. #endif
  59.  
  60. #ifndef SOM_ODStorageUnit_xh
  61. #include <StorageU.xh>
  62. #endif
  63.  
  64. #ifndef SOM_ODWindowState_xh
  65. #include <WinStat.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODInfo_xh
  69. #include <Info.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODPart_xh
  73. #include <Part.xh>
  74. #endif
  75.  
  76. //========================================================================================
  77. //    Runtime Info
  78. //========================================================================================
  79.  
  80. #ifdef FW_BUILD_MAC
  81. #pragma segment fwwindow
  82. #endif
  83.  
  84. //========================================================================================
  85. //    Static Members
  86. //========================================================================================
  87.  
  88. FW_TOrderedCollection<FW_CPrivSharedWindow>* FW_CFloatingWindow::fgSharedWindows = NULL;
  89.  
  90. //========================================================================================
  91. // Struct FW_SPrivWindowParameters
  92. //========================================================================================
  93. //    This structure is used by FW_CFloatingWindow when the creation of the ODWindow is differed until
  94. //    the window is shown
  95.  
  96. struct FW_SWindowParameters {
  97.  
  98.     FW_DECLARE_AUTO(FW_SWindowParameters)        // because there is a FW_CString255 field which is 
  99.                                                 // an autodestruct
  100.     
  101.     FW_CPart*                 fThePart;
  102.     ODFrame*                fParentFrame;
  103.     FW_Boolean                fPersistent;
  104.     ODTypeToken             fViewType;
  105.     FW_CPresentation*         fPresentation;
  106.     FW_CString255             fWindowTitle;
  107.     FW_CPoint                 fInteriorSize;
  108.     FW_CPoint                 fPosition;
  109.     FW_WindowStyle             fStyle;
  110. };
  111.  
  112. //========================================================================================
  113. //    Template Instantiations
  114. //========================================================================================
  115.  
  116. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CFloatingWindow)
  117. FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CFloatingWindow)
  118.  
  119. #ifdef FW_USE_TEMPLATE_PRAGMAS
  120.  
  121. #pragma template_access public
  122. #pragma template FW_TOrderedCollection<FW_CFloatingWindow>
  123. #pragma template FW_TOrderedCollectionIterator<FW_CFloatingWindow>
  124.  
  125. #endif
  126.  
  127. //========================================================================================
  128. // struct FW_SWindowParameters
  129. //========================================================================================
  130.  
  131. FW_DEFINE_AUTO(FW_SWindowParameters)
  132.  
  133. //========================================================================================
  134. // CLASS FW_CFloatingWindow
  135. //========================================================================================
  136.  
  137. FW_DEFINE_CLASS_M1(FW_CFloatingWindow, FW_CWindow)
  138.  
  139. //----------------------------------------------------------------------------------------
  140. // FW_CFloatingWindow::FW_CFloatingWindow
  141. //----------------------------------------------------------------------------------------
  142.  
  143. FW_CFloatingWindow::FW_CFloatingWindow(Environment* ev, 
  144.                                         FW_CPart* part,
  145.                                         FW_CPresentation* presentation,
  146.                                         const FW_CString& windowTitle,
  147.                                         const FW_CPoint& interiorSize,
  148.                                         const FW_CPoint& position,
  149.                                         FW_Boolean hasCloseBox) :
  150.     FW_CWindow(ev, (ODID)kODNULLID),
  151.     fWindowParameters(NULL),
  152.     fSharedWindow(NULL),
  153.     fRootFrame(NULL),
  154.     fPart(part)
  155. {    
  156.     FW_ASSERT(presentation != NULL);
  157.     ODTypeToken presentationType = presentation->GetPresentationType(ev);
  158.     const ODDraft* draft = part->GetDraft(ev);
  159.  
  160.     if (fgSharedWindows == NULL)
  161.         fgSharedWindows = FW_NEW(FW_TOrderedCollection<FW_CPrivSharedWindow>, ());
  162.     else
  163.     {    
  164.         FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(fgSharedWindows);
  165.         for (FW_CPrivSharedWindow* sharedRec = ite.First();
  166.              ite.IsNotComplete();
  167.              sharedRec = ite.Next())
  168.         {
  169.             if ((sharedRec->GetPresentationType() == presentationType) && (sharedRec->GetDraft() == draft))
  170.             {
  171.                 fSharedWindow = sharedRec;
  172.                 SetID(ev, fSharedWindow->GetWindowID());
  173.                 break;
  174.             }
  175.         }
  176.     }
  177.     
  178.     // ----- If no record yet then create one -----
  179.     if (fSharedWindow == NULL)
  180.     {
  181.         fSharedWindow = new FW_CPrivSharedWindow(presentationType, draft);
  182.         fgSharedWindows->AddLast(fSharedWindow);
  183.     }
  184.  
  185.     fSharedWindow->AddWindow(this);
  186.  
  187.     // ----- If the window has not yet been created then save the parameters for later -----
  188.     if (fSharedWindow->GetWindowID() == kODNULLID)
  189.     {
  190.         fWindowParameters = FW_NEW(FW_SWindowParameters, ());
  191.         fWindowParameters->fThePart            = part;
  192.         fWindowParameters->fParentFrame     = NULL;
  193.         fWindowParameters->fPersistent         = FALSE;
  194.         fWindowParameters->fViewType         = FW_CPart::fgViewAsFrameToken;
  195.         fWindowParameters->fPresentation     = presentation;
  196.         fWindowParameters->fWindowTitle     = windowTitle;
  197.         fWindowParameters->fInteriorSize     = interiorSize;
  198.         fWindowParameters->fPosition         = position;
  199.         fWindowParameters->fStyle             = FW_kFloatingWindow | (hasCloseBox ? FW_kHasCloseBox : 0);
  200.     }
  201. }
  202.  
  203. //----------------------------------------------------------------------------------------
  204. // FW_CFloatingWindow::~FW_CFloatingWindow
  205. //----------------------------------------------------------------------------------------
  206.  
  207. FW_CFloatingWindow::~FW_CFloatingWindow()
  208. {
  209.     FW_SOMEnvironment ev;
  210.     
  211.     if (fRootFrame && (fRootFrame->GetODFrame(ev) == NULL))
  212.         delete fRootFrame;            // the RooFrame is owned by the window if its ODFrame is NULL
  213.             
  214.     delete fWindowParameters;        // fine even if NULL
  215.  
  216.     if (fSharedWindow != NULL)
  217.     {
  218.         fSharedWindow->RemoveWindow(this);
  219.         
  220.         if (fSharedWindow->CountWindow() == 0)
  221.         {
  222.             fgSharedWindows->Remove(fSharedWindow);                
  223.             delete fSharedWindow;    // will delete fWindowList
  224.             
  225.             if (fgSharedWindows->Count() == 0)
  226.             {
  227.                 delete fgSharedWindows;
  228.                 fgSharedWindows = NULL;
  229.             }
  230.         }
  231.     }
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. // FW_CFloatingWindow::AcquireODWindow
  236. //----------------------------------------------------------------------------------------
  237.  
  238. ODWindow* FW_CFloatingWindow::AcquireODWindow(Environment* ev) const
  239. {
  240.     if (fSharedWindow->GetWindowID() == kODNULLID)
  241.     {
  242.         FW_ASSERT(fWindowParameters != NULL);
  243.         
  244.         FW_CFloatingWindow* self = (FW_CFloatingWindow*)this;        
  245.  
  246.         ODWindow* odWindow = self->PrivCreateODWindow(ev, 
  247.                                                     fWindowParameters->fThePart, 
  248.                                                     fWindowParameters->fParentFrame, 
  249.                                                     fWindowParameters->fPersistent, 
  250.                                                     fWindowParameters->fViewType,
  251.                                                     fWindowParameters->fPresentation, 
  252.                                                     fWindowParameters->fWindowTitle, 
  253.                                                     fWindowParameters->fInteriorSize, 
  254.                                                     fWindowParameters->fPosition,
  255.                                                     fWindowParameters->fStyle);
  256.         
  257.         self->SetID(ev, odWindow->GetID(ev));
  258.  
  259.         self->PrivOpenWindow(ev, odWindow);
  260.  
  261.         delete fWindowParameters;
  262.         self->fWindowParameters = NULL;    
  263.  
  264.         self->fRootFrame = FW_CFrame::ODtoFWFrame(ev, odWindow->GetRootFrame(ev));
  265.         
  266.         return odWindow;
  267.     }
  268.     else
  269.         return FW_CWindow::AcquireODWindow(ev);
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. // FW_CFloatingWindow::IsFloating
  274. //----------------------------------------------------------------------------------------
  275.  
  276. FW_Boolean FW_CFloatingWindow::IsFloating(Environment* ev) const
  277. {
  278. FW_UNUSED(ev);
  279.     return TRUE;
  280. }
  281.  
  282. //----------------------------------------------------------------------------------------
  283. // FW_CFloatingWindow::TransferOwnership
  284. //----------------------------------------------------------------------------------------
  285.  
  286. void FW_CFloatingWindow::TransferOwnership(Environment* ev, ODPart* newOwner)
  287. {
  288.     FW_ASSERT(newOwner != NULL);
  289.     
  290.     if (fgSharedWindows == NULL)
  291.         return;
  292.     
  293.     ODWindowState* windowState = FW_CSession::GetWindowState(ev);
  294.     ODStorageUnit* su = newOwner->GetStorageUnit(ev);
  295.     const ODDraft* draft = su ? su->GetDraft(ev) : NULL;
  296.     
  297.     FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::fgSharedWindows);
  298.     for (FW_CPrivSharedWindow* sharedWindow = ite.First();
  299.          ite.IsNotComplete();
  300.          sharedWindow = ite.Next())
  301.     {
  302.         if (sharedWindow->GetWindowID() != kODNULLID && sharedWindow->GetDraft() == draft)
  303.         {
  304.             FW_CAcquiredODWindow aqODWindow = windowState->AcquireWindow(ev, sharedWindow->GetWindowID());
  305.             ODFrame* rootFrame = aqODWindow->GetRootFrame(ev);
  306.             FW_CAcquiredODPart oldOwner = rootFrame->AcquirePart(ev);
  307.             if (newOwner != oldOwner)
  308.             {
  309.                 rootFrame->Acquire(ev);    // Release on rootframe is called before acquire                
  310.                 FW_CAcquiredODFrame aqFrame(rootFrame);
  311.                 
  312.                 // ----- find the right FW_CFloating Window
  313.                 FW_CFloatingWindow* newFloatingWindow = sharedWindow->GetFloatingWindow(ev, newOwner);
  314.                 
  315.                 if (newFloatingWindow != NULL)
  316.                 {
  317.                     // ----- Set the RefCon field (this is where FW_CFrame will find the FW_CWindow pointer)
  318. #ifdef FW_BUILD_MAC
  319.                     ::SetWRefCon(aqODWindow->GetPlatformWindow(ev), (long)newFloatingWindow);
  320. #endif
  321. #ifdef FW_BUILD_WIN
  322.                     ::SetProp(aqODWindow->GetPlatformWindow(ev), "ODF:Window", (HANDLE)newFloatingWindow);
  323. #endif
  324.  
  325.                     // ----- Change the owner of the frame -----
  326.                     rootFrame->ChangePart(ev, newOwner);
  327.                 
  328.                     // ----- cache the FW_CFrame -----
  329.                     FW_ASSERT(newFloatingWindow->GetID(ev) == sharedWindow->GetWindowID());
  330.                     if (newFloatingWindow->fRootFrame == NULL)
  331.                         newFloatingWindow->fRootFrame = FW_CFrame::ODtoFWFrame(ev, rootFrame);
  332. #ifdef FW_DEBUG
  333.                     else
  334.                         FW_ASSERT(newFloatingWindow->fRootFrame == FW_CFrame::ODtoFWFrame(ev, rootFrame));
  335. #endif        
  336.                     // ----- Force an update if shown -----        
  337.                     if (aqODWindow->IsShown(ev))
  338.                         aqODWindow->Update(ev);
  339.                 }
  340.             }
  341.         }
  342.     }
  343. }
  344.  
  345. //----------------------------------------------------------------------------------------
  346. // FW_CFloatingWindow::GetID
  347. //----------------------------------------------------------------------------------------
  348.  
  349. ODID FW_CFloatingWindow::GetID(Environment* ev) const
  350. {
  351. FW_UNUSED(ev);
  352.     return fSharedWindow->GetWindowID();
  353. }
  354.  
  355. //----------------------------------------------------------------------------------------
  356. // FW_CFloatingWindow::SetID
  357. //----------------------------------------------------------------------------------------
  358.  
  359. void FW_CFloatingWindow::SetID(Environment* ev, ODID windowID)
  360. {
  361.     fSharedWindow->SetWindowID(windowID);    
  362.     FW_CWindow::SetID(ev, windowID);
  363. }
  364.  
  365. //---------------------------------------------------------------------------------------
  366. //    FW_CFloatingWindow::HideShowFloatingWindows
  367. //---------------------------------------------------------------------------------------
  368.  
  369. void FW_CFloatingWindow::HideShowFloatingWindows(Environment *ev, FW_Boolean state, ODPart* part)
  370. {            
  371.     FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::fgSharedWindows);
  372.     
  373.     for (FW_CPrivSharedWindow* sharedWindow = ite.First(); ite.IsNotComplete(); sharedWindow = ite.Next())
  374.     {
  375.         sharedWindow->HideShow(ev, state, part);
  376.     }
  377. }
  378.