home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-08-16 | 21.7 KB | 697 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWWindow.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWFrameW.hpp"
-
- #ifndef FWWINDOW_H
- #include "FWWindow.h"
- #endif
-
- #ifndef FWPART_H
- #include "FWPart.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWWINPRO_H
- #include "FWWinPro.h"
- #endif
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- #ifndef FWFCTINF_H
- #include "FWFctInf.h"
- #endif
-
- // ----- Foundation Layer -----
-
- #ifndef FWSTRING_H
- #include "FWString.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- //========================================================================================
- // Runtime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment fwwindow
- #endif
-
- FW_DEFINE_CLASS_M0(FW_CWindow)
-
- //========================================================================================
- // CLASS FW_CWindow
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- FW_CPart* thePart,
- ODTypeToken viewType,
- FW_CPresentation* presentation,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- FW_WindowStyle style) :
- fGraphicDevice(NULL),
- fSession(thePart->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- FW_UNUSED(viewType);
- FW_CString32 windowTitle(""); // the title doesn't matter
-
- ODWindow* odWindow = PrivCreateODWindow(ev,
- thePart,
- NULL,
- TRUE, // persistent
- FW_CPart::gViewAsFrameToken,
- presentation,
- windowTitle,
- interiorSize,
- position,
- style);
- PrivOpenWindow(ev, odWindow);
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- odWindow->Release(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- FW_CPart* thePart,
- ODFrame* parentFrame,
- FW_Boolean persistent,
- ODTypeToken viewType,
- FW_CPresentation* presentation,
- const FW_CString& windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- FW_WindowStyle style) :
- fGraphicDevice(NULL),
- fSession(thePart->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- ODWindow* odWindow = PrivCreateODWindow(ev,
- thePart,
- parentFrame,
- persistent,
- viewType,
- presentation,
- windowTitle,
- interiorSize,
- position,
- style);
-
- PrivOpenWindow(ev, odWindow);
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- odWindow->Release(ev);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev,
- FW_CPart* thePart,
- ODFrame* odFrame) :
- fGraphicDevice(NULL),
- fSession(thePart->GetSession(ev)),
- fWindowID(kODNULLID)
- {
- PrivCreateODWindowForFrame(ev, thePart, odFrame);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::FW_CWindow(Environment* ev, FW_CPart* thePart, ODID windowID) :
- fGraphicDevice(NULL),
- fSession(thePart->GetSession(ev)),
- fWindowID(windowID)
- {
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::~FW_CWindow
- //----------------------------------------------------------------------------------------
-
- FW_CWindow::~FW_CWindow()
- {
- if (fGraphicDevice != 0)
- FW_PrivGDev_Release(fGraphicDevice);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::AcquireODWindow
- //----------------------------------------------------------------------------------------
-
- ODWindow* FW_CWindow::AcquireODWindow(Environment* ev) const
- {
- ODID windowID = GetID(ev);
- FW_ASSERT(windowID != kODNULLID);
-
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR3
- return fSession->GetWindowState(ev)->AcquireWindow(ev, windowID);
- #else
- return fSession->GetWindowState(ev)->GetWindow(ev, windowID);
- #endif
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Show
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Show(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- aqODWindow->Show(ev);
-
- // Because hidden floating window are sent to the back
- if (IsFloating(ev))
- Select(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowTitle
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::GetWindowTitle(Environment* ev, FW_CString& windowTitle) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_GetWindowTitle(aqODWindow->GetPlatformWindow(ev), windowTitle, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowTitle
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::SetWindowTitle(Environment* ev, const FW_CString& windowTitle)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_SetWindowTitle(aqODWindow->GetPlatformWindow(ev), windowTitle, &error);
- FW_FailOnError(error);
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivCreateODWindowForFrame
- //---------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivCreateODWindowForFrame(Environment* ev,
- FW_CPart* thePart,
- ODFrame* odFrame)
- {
- #if FW_OPENDOC_VERSION >= FW_OPENDOC_DR2
-
- FW_CWindowProperties props;
- FW_Boolean hasWinProp = props.ReadWindowProperties(ev, odFrame);
-
- ODPlatformWindow platformWindow = NULL;
-
- #ifdef FW_BUILD_MAC
- FW_CPoint interiorSize(props.fBoundsRect.right - props.fBoundsRect.left,
- props.fBoundsRect.bottom - props.fBoundsRect.top);
- FW_CPoint position(props.fBoundsRect.left, props.fBoundsRect.top);
-
- platformWindow = FW_PrivMacCreatePlatformWindow(ev,
- props.fMacTitle,
- interiorSize,
- position, // ATTENTION: position is the inside position
- props.fMacProcID,
- props.fMacHasCloseBox,
- (long)this);
- #endif
-
- #ifdef FW_BUILD_WIN
- FW_DEBUG_MESSAGE("Not Implemented Yet!");
- #endif
-
- ODWindowState* windowState = thePart->GetSession(ev)->GetWindowState(ev);
-
- ODWindow* odWindow = windowState->RegisterWindowForFrame(ev,
- platformWindow,
- odFrame,
- props.fIsRootWindow, // Keeps draft open
- #ifdef FW_BUILD_MAC
- FALSE, // On the Mac we handle the resizing ourself
- #else
- props.fIsResizable, // Is resizable
- #endif
- props.fIsFloating, // Is floating
- TRUE, // should save
- #ifdef FW_BUILD_MAC
- TRUE, // should dispose
- #endif
- props.fSourceFrame);
-
- SetID(ev, odWindow->GetID(ev));
-
- FW_PlatformError error;
- FW_Boolean changed = FW_FitWindowToScreen(odWindow->GetPlatformWindow(ev), &error);
- FW_FailOnError(error);
-
- odWindow->Open(ev); // Attention fWindowID has to be set before calling Open
- if (!hasWinProp || changed)
- odWindow->AdjustWindowShape(ev);
-
- odWindow->Release(ev);
- #else
- FW_DEBUG_MESSAGE("Should not be called with this version");
- #endif
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivCreateODWindow
- //---------------------------------------------------------------------------------------
-
- ODWindow* FW_CWindow::PrivCreateODWindow(Environment* ev,
- FW_CPart* thePart,
- ODFrame* parentFrame,
- FW_Boolean persistent,
- ODTypeToken viewType,
- FW_CPresentation* presentation,
- const FW_CString& windowTitle,
- const FW_CPoint& interiorSize,
- const FW_CPoint& position,
- FW_WindowStyle style)
- {
- ODWindowState* windowState = thePart->GetSession(ev)->GetWindowState(ev);
-
- FW_PlatformError error;
- #ifdef FW_BUILD_MAC
- unsigned short procID = FW_PrivMacStyleToProcId(style);
-
- Str255 pascalTitle;
- windowTitle.ExportPascal(pascalTitle);
-
- FW_CPoint tempSize(FW_IntToFixed(100), FW_IntToFixed(100));
- FW_CPoint tempPos = tempSize;
- ODPlatformWindow platformWindow = FW_PrivMacCreatePlatformWindow(ev,
- pascalTitle,
- tempSize,
- tempPos,
- procID,
- (FW_kHasCloseBox & style) != 0,
- (long)this);
-
- // Set the right size
- ::SizeWindow(platformWindow, FW_FixedToInt(interiorSize.x), FW_FixedToInt(interiorSize.y), TRUE);
-
- // because MacCreatePlatformWindow is called with the inside position
- FW_CRect borderSize;
- FW_GetWindowBorderSize(platformWindow, borderSize, &error);
- FW_FailOnError(error);
- ::MoveWindow(platformWindow,
- FW_FixedToInt(position.x + borderSize.left),
- FW_FixedToInt(position.y + borderSize.top),
- FALSE);
-
- FW_FitWindowToScreen(platformWindow, &error);
- FW_FailOnError(error);
- #endif
-
- #ifdef FW_BUILD_WIN
- DWORD windowFlags = FW_PrivWindStyleToWindowsFlags(style);
-
- ODPlatformWindow platformWindow = windowState->CreatePlatformWindow(ev, (style & FW_kFloatingWindow) != 0, windowFlags | WS_CLIPSIBLINGS);
-
- // Associate window pointer with the platform window
- if (platformWindow != NULL)
- {
- ::SetProp(platformWindow, "ODF:Window", (HANDLE) this);
- }
- #endif
-
- // ----- Create and return the wrapper window
- ODWindow* odWindow = windowState->RegisterWindow(ev,
- platformWindow,
- persistent ? kODFrameObject : kODNonPersistentFrameObject,
- (parentFrame == NULL) && ((FW_kFloatingWindow & style) == 0), // root window
- #ifdef FW_BUILD_MAC
- FALSE, // On the Mac we handle the resizing ourself
- #else
- (FW_kResizeable & style) != 0,
- #endif
- (FW_kFloatingWindow & style) != 0,
- persistent, // shouldSave (shouldSave and persistent should always have the same value)
- #ifdef FW_BUILD_MAC
- TRUE, // should dispose
- #endif
- thePart->GetODPart(ev),
- viewType,
- presentation->GetPresentationType(ev),
- parentFrame);
-
- return odWindow;
- }
-
- //---------------------------------------------------------------------------------------
- // FW_CWindow::PrivOpenWindow
- //---------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivOpenWindow(Environment* ev, ODWindow* odWindow)
- {
- SetID(ev, odWindow->GetID(ev));
-
- FW_PlatformError error;
- FW_FitWindowToScreen(odWindow->GetPlatformWindow(ev), &error);
- FW_FailOnError(error);
-
- odWindow->Open(ev); // Attention fWindowID has to be set before calling Open
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetGraphicDevice
- //----------------------------------------------------------------------------------------
-
- FW_HGDevice FW_CWindow::GetGraphicDevice(Environment* ev) const
- {
- FW_CWindow* self = (FW_CWindow *)this;
-
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
-
- ODFacet* rootFacet = aqODWindow->GetRootFacet(ev);
- FW_HGDevice device = FW_GetFacetGraphicDevice(ev, rootFacet);
-
- if (device == NULL)
- {
- if (fGraphicDevice == NULL) // We never asked for it
- {
- self->fGraphicDevice = FW_PrivGDev_CreateFromODCanvas(ev, rootFacet->GetCanvas(ev));
- FW_FailOnEvError(ev);
- }
- device = fGraphicDevice;
- }
-
- return device;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowSize
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::SetWindowSize(Environment* ev, const FW_CPoint& interiorSize)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_SetWindowSize(aqODWindow->GetPlatformWindow(ev), interiorSize, &error);
- FW_FailOnError(error);
-
- // ----- Notify the ODWindow -----
- if (aqODWindow->GetRootFacet(ev) != NULL)
- aqODWindow->AdjustWindowShape(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetWindowPosition
- //----------------------------------------------------------------------------------------
- // newPosition is the position of the exterior top left corner of the window. This is
- // different from the Mac API where MoveWindow takes the inside top left corner
- // of the window. For once the Windows API makes more sense.
-
- void FW_CWindow::SetWindowPosition(Environment* ev, const FW_CPoint& newPosition)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_SetWindowPosition(aqODWindow->GetPlatformWindow(ev), newPosition, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::WindowToScreen
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::WindowToScreen(Environment* ev,
- FW_CPoint* points,
- unsigned short nbPoint)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_FailOnError(FW_WindowToScreen(aqODWindow->GetPlatformWindow(ev), points, nbPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::ScreenToWindow
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::ScreenToWindow(Environment* ev,
- FW_CPoint* points,
- unsigned short nbPoint)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_FailOnError(FW_ScreenToWindow(aqODWindow->GetPlatformWindow(ev), points, nbPoint));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::FitToScreen
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::FitToScreen(Environment* ev)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_FitWindowToScreen(aqODWindow->GetPlatformWindow(ev), &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowSize
- //----------------------------------------------------------------------------------------
- // Returns the inside size of the window
-
- void FW_CWindow::GetWindowSize(Environment* ev, FW_CPoint& interiorSize) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_GetWindowSize(aqODWindow->GetPlatformWindow(ev), interiorSize, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetWindowPosition
- //----------------------------------------------------------------------------------------
- // Returns the outside position of the window
-
- void FW_CWindow::GetWindowPosition(Environment* ev, FW_CPoint& position) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_GetWindowPosition(aqODWindow->GetPlatformWindow(ev), position, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsFloating
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsFloating(Environment* ev) const
- {
- FW_UNUSED(ev);
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsActive
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsActive(Environment* ev) const
- {
- if (GetID(ev) != kODNULLID)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- return aqODWindow->IsActive(ev);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetID
- //----------------------------------------------------------------------------------------
-
- ODID FW_CWindow::GetID(Environment* ev) const
- {
- FW_UNUSED(ev);
- return fWindowID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::SetID
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::SetID(Environment* ev, ODID windowID)
- {
- FW_UNUSED(ev);
- FW_ASSERT(fWindowID == kODNULLID || fWindowID == windowID);
- fWindowID = windowID;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetPlatformWindow
- //----------------------------------------------------------------------------------------
-
- ODPlatformWindow FW_CWindow::GetPlatformWindow(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- return aqODWindow->GetPlatformWindow(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::GetBorderSize
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::GetBorderSize(Environment* ev, FW_CRect &borderSize) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- FW_PlatformError error;
- FW_GetWindowBorderSize(aqODWindow->GetPlatformWindow(ev), borderSize, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Close
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Close(Environment* ev)
- {
- if (GetID(ev) != kODNULLID)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- aqODWindow->Close(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::CloseAndRemove
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::CloseAndRemove(Environment* ev)
- {
- if (GetID(ev) != kODNULLID)
- {
- // Don't use a FW_CAcquiredODWindow object here because CloseAndRemove
- // already releases it
- ODWindow* odWindow = AcquireODWindow(ev);
- FW_ASSERT(odWindow);
- odWindow->CloseAndRemove(ev);
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Select
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Select(Environment* ev) const
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- aqODWindow->Select(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::IsShown
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_CWindow::IsShown(Environment* ev) const
- {
- if (GetID(ev) != kODNULLID)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- return aqODWindow->IsShown(ev);
- }
- else
- return FALSE;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CWindow::Hide
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::Hide(Environment* ev)
- {
- if (GetID(ev) != kODNULLID)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
- aqODWindow->Hide(ev);
- }
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CWindow::PrivMacDoZoom
- //----------------------------------------------------------------------------------------
-
- void FW_CWindow::PrivMacDoZoom(Environment* ev,
- const FW_CPoint& zoomedSize,
- const FW_CRect& borderSize,
- const FW_CRect& screenRect,
- unsigned long message)
- {
- FW_CAcquiredODWindow aqODWindow = AcquireODWindow(ev);
- FW_ASSERT((ODWindow*)aqODWindow != NULL);
-
- ODPlatformWindow platformWindow = aqODWindow->GetPlatformWindow(ev);
-
- FW_PlatformError error;
- FW_PrivMacDoZoom(platformWindow, zoomedSize, borderSize, screenRect, message, &error);
- FW_FailOnError(error);
-
- aqODWindow->AdjustWindowShape(ev);
- }
- #endif
-
-