home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 11.2 KB | 374 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFloWin.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWFLOWIN_H
- #include "FWFloWin.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWSHDWIN_H
- #include "FWShdWin.h"
- #endif
-
- #ifndef FWFRAME_H
- #include "FWFrame.h"
- #endif
-
- // ----- Foundation Includes -----
-
- #ifndef FWEXCLIB_H
- #include "FWExcLib.h"
- #endif
-
- #ifndef FWRESACC_H
- #include "FWResAcc.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODInfo_xh
- #include <Info.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #if defined(__MWERKS__) && GENERATING68K
- // A hack to work around a bug
- #pragma import list somGetGlobalEnvironment
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwwindow
- #endif
-
- //========================================================================================
- // Static Members
- //========================================================================================
-
- FW_TOrderedCollection<FW_CPrivSharedWindow>* FW_CFloatingWindow::gSharedWindows = NULL;
-
- //========================================================================================
- // Struct FW_SPrivWindowParameters
- //========================================================================================
- // This structure is used by FW_CFloatingWindow when the creation of the ODWindow is differed until
- // the window is shown
-
- struct FW_SWindowParameters {
-
- FW_DECLARE_AUTO(FW_SWindowParameters) // because there is a FW_CString255 field which is
- // an autodestruct
-
- FW_CPart* fThePart;
- ODFrame* fParentFrame;
- FW_Boolean fPersistent;
- ODTypeToken fViewType;
- FW_CPresentation* fPresentation;
- FW_CString255 fWindowTitle;
- FW_CPoint fInteriorSize;
- FW_CPoint fPosition;
- FW_WindowStyle fStyle;
- };
-
- //========================================================================================
- // Template Instantiations
- //========================================================================================
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollectionIterator, FW_CFloatingWindow)
- FW_DEFINE_AUTO_TEMPLATE(FW_TOrderedCollection, FW_CFloatingWindow)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TOrderedCollection<FW_CFloatingWindow>
- #pragma template FW_TOrderedCollectionIterator<FW_CFloatingWindow>
-
- #endif
-
- //========================================================================================
- // struct FW_SWindowParameters
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_SWindowParameters)
-
- //========================================================================================
- // CLASS FW_CFloatingWindow
- //========================================================================================
-
- FW_DEFINE_CLASS_M1(FW_CFloatingWindow, FW_CWindow)
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::FW_CFloatingWindow
- //----------------------------------------------------------------------------------------
-
- FW_CFloatingWindow::FW_CFloatingWindow(Environment* ev,
- FW_CPart* part,
- FW_CPresentation* presentation,
- const FW_CString& windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- FW_Boolean hasCloseBox) :
- FW_CWindow(ev, part, (ODID)kODNULLID),
- fWindowParameters(NULL),
- fSharedWindow(NULL),
- fRootFrame(NULL),
- fPart(part)
- {
- FW_ASSERT(presentation != NULL);
- ODTypeToken presentationType = presentation->GetPresentationType(ev);
-
- if (gSharedWindows == NULL)
- gSharedWindows = FW_NEW(FW_TOrderedCollection<FW_CPrivSharedWindow>, ());
- else
- {
- FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(gSharedWindows);
- for (FW_CPrivSharedWindow* sharedRec = ite.First();
- ite.IsNotComplete();
- sharedRec = ite.Next())
- {
- if (sharedRec->GetPresentationType() == presentationType)
- {
- fSharedWindow = sharedRec;
- SetID(ev, fSharedWindow->GetWindowID());
- break;
- }
- }
- }
-
- // ----- If no record yet then create one -----
- if (fSharedWindow == NULL)
- {
- fSharedWindow = new FW_CPrivSharedWindow(presentationType);
- gSharedWindows->AddLast(fSharedWindow);
- }
-
- fSharedWindow->AddWindow(this);
-
- // ----- If the window has not yet been created then save the parameters for later -----
- if (fSharedWindow->GetWindowID() == kODNULLID)
- {
- fWindowParameters = FW_NEW(FW_SWindowParameters, ());
- fWindowParameters->fThePart = part;
- fWindowParameters->fParentFrame = NULL;
- fWindowParameters->fPersistent = FALSE;
- fWindowParameters->fViewType = FW_CPart::gViewAsFrameToken;
- fWindowParameters->fPresentation = presentation;
- fWindowParameters->fWindowTitle = windowTitle;
- fWindowParameters->fInteriorSize = interiorSize;
- fWindowParameters->fPosition = position;
- fWindowParameters->fStyle = FW_kFloatingWindow | (hasCloseBox ? FW_kHasCloseBox : 0);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::~FW_CFloatingWindow
- //----------------------------------------------------------------------------------------
-
- FW_CFloatingWindow::~FW_CFloatingWindow()
- {
- Environment* ev = somGetGlobalEnvironment();
-
- if (fRootFrame && (fRootFrame->GetODFrame(ev) == NULL))
- delete fRootFrame; // the RooFrame is owned by the window if its ODFrame is NULL
-
- delete fWindowParameters; // fine even if NULL
-
- if (fSharedWindow != NULL)
- {
- fSharedWindow->RemoveWindow(this);
-
- if (fSharedWindow->CountWindow() == 0)
- {
- gSharedWindows->Remove(fSharedWindow);
- delete fSharedWindow; // will delete fWindowList
-
- if (gSharedWindows->Count() == 0)
- {
- delete gSharedWindows;
- gSharedWindows = NULL;
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::AcquireODWindow
- //----------------------------------------------------------------------------------------
-
- ODWindow* FW_CFloatingWindow::AcquireODWindow(Environment* ev) const
- {
- if (fSharedWindow->GetWindowID() == kODNULLID)
- {
- FW_ASSERT(fWindowParameters != NULL);
-
- FW_CFloatingWindow* self = (FW_CFloatingWindow*)this;
-
- ODWindow* odWindow = self->PrivCreateODWindow(ev,
- fWindowParameters->fThePart,
- fWindowParameters->fParentFrame,
- fWindowParameters->fPersistent,
- fWindowParameters->fViewType,
- fWindowParameters->fPresentation,
- fWindowParameters->fWindowTitle,
- fWindowParameters->fInteriorSize,
- fWindowParameters->fPosition,
- fWindowParameters->fStyle);
-
- self->SetID(ev, odWindow->GetID(ev));
-
- self->PrivOpenWindow(ev, odWindow);
-
- delete fWindowParameters;
- self->fWindowParameters = NULL;
-
- self->fRootFrame = FW_CFrame::ODtoFWFrame(ev, odWindow->GetRootFrame(ev));
-
- return odWindow;
- }
- else
- return FW_CWindow::AcquireODWindow(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::IsFloating
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CFloatingWindow::IsFloating(Environment* ev) const
- {
- FW_UNUSED(ev);
- return TRUE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::TransferOwnership
- //----------------------------------------------------------------------------------------
-
- void FW_CFloatingWindow::TransferOwnership(Environment* ev,
- ODWindowState* windowState,
- ODPart* newOwner)
- {
- FW_ASSERT(newOwner != NULL);
-
- if (gSharedWindows == NULL)
- return;
-
- FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::gSharedWindows);
- for (FW_CPrivSharedWindow* sharedWindow = ite.First();
- ite.IsNotComplete();
- sharedWindow = ite.Next())
- {
- if (sharedWindow->GetWindowID() != kODNULLID)
- {
- FW_CAcquiredODWindow aqODWindow = windowState->AcquireWindow(ev, sharedWindow->GetWindowID());
- ODFrame* rootFrame = aqODWindow->GetRootFrame(ev);
- FW_CAcquiredODPart oldOwner = rootFrame->AcquirePart(ev);
- if (newOwner != oldOwner)
- {
- rootFrame->Acquire(ev); // Release on rootframe is called before acquire
- FW_CAcquiredODFrame aqFrame(rootFrame);
-
- // ----- find the right FW_CFloating Window
- FW_CFloatingWindow* newFloatingWindow = sharedWindow->GetFloatingWindow(ev, newOwner);
-
- // ----- Set the RefCon field (this is where FW_CFrame will find the FW_CWindow pointer)
- #ifdef FW_BUILD_MAC
- ::SetWRefCon(aqODWindow->GetPlatformWindow(ev), (long)newFloatingWindow);
- #endif
- #ifdef FW_BUILD_WIN
- ::SetProp(aqODWindow->GetPlatformWindow(ev), "ODF:Window", (HANDLE)newFloatingWindow);
- #endif
-
- // ----- Change the owner of the frame -----
- rootFrame->ChangePart(ev, newOwner);
-
- // ----- cache the FW_CFrame -----
- FW_ASSERT(newFloatingWindow->GetID(ev) == sharedWindow->GetWindowID());
- if (newFloatingWindow->fRootFrame == NULL)
- newFloatingWindow->fRootFrame = FW_CFrame::ODtoFWFrame(ev, rootFrame);
- #ifdef FW_DEBUG
- else
- FW_ASSERT(newFloatingWindow->fRootFrame == FW_CFrame::ODtoFWFrame(ev, rootFrame));
- #endif
- // ----- Force an update if shown -----
- if (aqODWindow->IsShown(ev))
- aqODWindow->Update(ev);
- }
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::GetID
- //----------------------------------------------------------------------------------------
-
- ODID FW_CFloatingWindow::GetID(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fSharedWindow->GetWindowID();
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFloatingWindow::SetID
- //----------------------------------------------------------------------------------------
-
- void FW_CFloatingWindow::SetID(Environment* ev, ODID windowID)
- {
- fSharedWindow->SetWindowID(windowID);
- FW_CWindow::SetID(ev, windowID);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CFloatingWindow::HideShowFloatingWindows
- //---------------------------------------------------------------------------------------
-
- void FW_CFloatingWindow::HideShowFloatingWindows(Environment *ev, ODWindowState* windowState, FW_Boolean state)
- {
- FW_TOrderedCollectionIterator<FW_CPrivSharedWindow> ite(FW_CFloatingWindow::gSharedWindows);
- for (FW_CPrivSharedWindow* sharedWindow = ite.First();
- ite.IsNotComplete();
- sharedWindow = ite.Next())
- {
- sharedWindow->HideShow(ev, windowState, state);
- }
- }
-