home *** CD-ROM | disk | FTP | other *** search
- /*
- File: Window.cpp
-
- Contains: Implementation of class ODWindow
-
- Owned by: Chris Linn
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <6> 6/21/96 CSL 1356527: Doc windows are shown off-screen
- if monitor configuration changes.
- <5> 6/14/96 CSL 1316010: Document window disappears forever
- on save if WindowShaded
- <4> 5/24/96 jpa 1246074: Added missing SOM_CATCH_ALL's.
- <2> 3/15/96 VL 1302780: Added GetFacetUnderPointForDrag so
- that we can ignore selection when we try to
- find the facet under mouse point.
-
- To Do:
-
- In Progress:
-
- */
-
- #define ODWindow_Class_Source
-
-
-
- #ifndef _ALTPOINT_
- #include "AltPoint.h" // Use C++ savvy XMPPoint and XMPRect
- #endif
-
-
- #ifndef SOM_ODWindow_xih
- #define VARIABLE_MACROS
- #include <Window.xih>
- #endif
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODStorageSystem_xh
- #include <ODStor.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODArbitrator_xh
- #include <Arbitrat.xh>
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
-
- #ifndef SOM_ODFacetIterator_xh
- #include <FacetItr.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- #ifndef SOM_ODTransform_xh
- #include <Trnsform.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Foci_defined
- #include <Foci.xh>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _ITEXT_
- #include "IText.h"
- #endif
-
- #ifndef __TOOLUTILS__
- #include <ToolUtils.h>
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef __OSUTILS__
- #include <OSUtils.h> // SysBeep etc.
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include <StdTypes.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include <StdProps.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef __OCESTANDARDMAIL__
- #include <OCEStandardMail.h>
- #endif
-
- #ifndef __OCEERRORS__
- #include <OCEErrors.h>
- #endif
-
- #ifndef SOM_ODMenuBar_xh
- #include <MenuBar.xh>
- #endif
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _CONSTDEF_
- #include "ConstDef.h"
- #endif
-
- #ifndef __GESTALTEQU__
- #include <GestaltEqu.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef _DSPUTILM_
- #include "DspUtilM.h"
- #endif
-
- #pragma segment ODWindow
-
- #include "WindowB.cpp" // Platform-independent methods, if any
-
- #define ODDebugActivates 0
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- // Check ErrorDef.idl before adding any new codes here, to make sure they're unique.
- const ODError kODErrInvalidPlatformWindow = -29828;
- const ODError kODErrInvalidWindow = -29827;
-
- // TÇ: This error code was only being used in this file, and then only
- // for checking the _fPlatformWindow field of a window at the beginning of
- // methods. It didn't seem to have anything to do with the api.
- // That is why I made it private to this file.
- // perhaps the error that should be thrown is kODErrObjectNotInitialized?
- // kODErrInvalidWindow falls into the same category.
-
-
- //==============================================================================
- // Types
- //==============================================================================
-
- //=====================================================================================
- // ODWindow Methods
- //=====================================================================================
-
-
- //-------------------------------------------------------------------------------------
- // ODWindow: CommonInitWindow
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowCommonInitWindow(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","CommonInitWindow");
-
- SOM_TRY
-
- _fSession = (ODSession*) _fDraft->GetDocument(ev)->GetContainer(ev)->GetStorageSystem(ev)->GetSession(ev);
- _fArbitrator = _fSession->GetArbitrator(ev);
- _fSelectionFocus = _fSession->Tokenize(ev,kODSelectionFocus);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
-
- //-------------------------------------------------------------------------------------
- // ODWindow: InitWindow
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowInitWindow (ODWindow *somSelf, Environment *ev,
- ODPlatformWindow platformWindow,
- ODType frameType,
- ODBoolean isRootWindow,
- ODBoolean isResizable,
- ODBoolean isFloating,
- ODBoolean shouldSave,
- ODBoolean shouldDispose,
- ODPart* rootPart,
- ODTypeToken viewType,
- ODTypeToken presentation,
- ODFrame* sourceFrame)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","InitWindow");
-
- SOM_TRY
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fPlatformWindow = kODNULL;
- _fRootFacet = kODNULL;
- _fSourceFrame = kODNULL;
- _fSession = kODNULL;
- _fIsRootWindow = kODTrue;
- _fShouldSave = kODTrue;
- _fIsResizable = kODFalse;
- _fIsFloating = kODFalse;
- _fWasVisible = kODFalse;
- _fShouldShowLinks = kODFalse;
- _fArbitrator = kODNULL;
-
- _fStorageUnit = kODNULL;
- _fIsDirty = kODFalse;
- _fDraft = kODNULL;
-
- _fShouldAdjustOnOpen = kODFalse;
- _fInBackground = kODFalse;
- _fIsActive = kODFalse;
- _fSelectionFocus = 0;
- */
- _fShouldDispose = shouldDispose;
-
- somSelf->InitRefCntObject(ev);
-
- #if ODDebug
- if (shouldSave && ODISOStrEqual(frameType, kODNonPersistentFrameObject))
- WARN("InitWindow: shouldSave is TRUE, but root frame is nonpersistent ");
-
- #endif
-
- _fPlatformWindow = platformWindow;
- _fIsRootWindow = isRootWindow;
- _fIsResizable = isResizable;
- _fIsFloating = isFloating;
- if (sourceFrame)
- sourceFrame->Acquire(ev);
- _fSourceFrame = sourceFrame;
- _fDraft = rootPart->GetStorageUnit(ev)->GetDraft(ev);
- _fDraft->Acquire(ev);
- if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
- {
- shouldSave = kODFalse;
- frameType = kODNonPersistentFrameObject;
- }
-
- _fShouldSave = shouldSave;
-
- somSelf->CommonInitWindow(ev);
-
- somSelf->CreateRootFrame(ev, frameType, viewType, presentation, rootPart);
-
- _fIsDirty = kODTrue;
- _fShouldAdjustOnOpen = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
- //-------------------------------------------------------------------------------------
- // ODWindow: InitWindowForFrame
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowInitWindowForFrame (ODWindow *somSelf, Environment *ev,
- ODPlatformWindow platformWindow,
- ODFrame* frame,
- ODBoolean isRootWindow,
- ODBoolean isResizable,
- ODBoolean isFloating,
- ODBoolean shouldSave,
- ODBoolean shouldDispose,
- ODFrame* sourceFrame)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","InitWindow");
-
- SOM_TRY
-
- ASSERT(frame != kODNULL, kODErrInvalidFrame);
-
- /* Moved from somInit. SOM itself sets fields to zero
- _fPlatformWindow = kODNULL;
- _fRootFacet = kODNULL;
- _fSourceFrame = kODNULL;
- _fSession = kODNULL;
- _fIsRootWindow = kODTrue;
- _fShouldSave = kODTrue;
- _fIsResizable = kODFalse;
- _fIsFloating = kODFalse;
- _fWasVisible = kODFalse;
- _fShouldShowLinks = kODFalse;
- _fArbitrator = kODNULL;
-
- _fStorageUnit = kODNULL;
- _fIsDirty = kODFalse;
- _fDraft = kODNULL;
-
- _fShouldAdjustOnOpen = kODFalse;
- _fInBackground = kODFalse;
- _fSelectionFocus = 0;
- */
- _fShouldDispose = shouldDispose;
-
- somSelf->InitRefCntObject(ev);
-
- #if ODDebug
- if (shouldSave && (frame->GetStorageUnit(ev) == kODNULL))
- WARN("InitWindowForFrame: shouldSave is TRUE, but root frame is nonpersistent ");
-
- #endif
-
- _fPlatformWindow = platformWindow;
- _fIsRootWindow = isRootWindow;
- _fIsResizable = isResizable;
- _fIsFloating = isFloating;
- if (sourceFrame)
- sourceFrame->Acquire(ev);
- _fSourceFrame = sourceFrame;
- {
- TempODPart part = frame->AcquirePart(ev);
- _fDraft = part->GetStorageUnit(ev)->GetDraft(ev);
- _fDraft->Acquire(ev);
- }
-
- if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
- shouldSave = kODFalse;
-
- _fShouldSave = shouldSave;
-
- somSelf->CommonInitWindow(ev);
-
- if (frame)
- {
- frame->Acquire(ev);
- frame->SetWindow(ev, somSelf);
- }
- _fRootFrame = frame;
-
- _fIsDirty = kODFalse;
- _fShouldAdjustOnOpen = kODFalse;
-
- ODStorageUnit* frameSU = frame->GetStorageUnit(ev);
- if ((frameSU != kODNULL) && (_fDraft != kODNULL))
- {
- ODID windowPropsID = ODGetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef);
- if (windowPropsID != kODNULLID)
- {
- _fStorageUnit = _fDraft->AcquireStorageUnit(ev, windowPropsID);
- }
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Purge
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODSize SOMLINK ODWindowPurge(ODWindow *somSelf, Environment *ev,
- ODSize size)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Purge");
-
- ODSize purgeSize = 0;
-
- SOM_TRY
-
- purgeSize = parent_Purge(somSelf, ev, size);
-
- SOM_CATCH_ALL
- WARN("Error %ld trying to purge in ODWindowPurge",ErrorCode());
- SetErrorCode(kODNoError); // Eat the exception; Purge should not
- // propagate it because clients function
- // fine whether memory was purged or not.
- SOM_ENDTRY
-
- return purgeSize;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Release
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowRelease(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Release");
-
- SOM_TRY
-
- parent_Release(somSelf, ev);
- if (somSelf->GetRefCount(ev) == 0)
- _fSession->GetWindowState(ev)->ReleaseWindow(ev,somSelf);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: ~ODWindow
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowsomUninit (ODWindow *somSelf)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","somUninit");
-
- Environment* ev = somGetGlobalEnvironment();
- // • Get rid of our window
- if (_fPlatformWindow && _fShouldDispose)
- {
- if (((WindowRecord*)_fPlatformWindow)->windowKind == dialogKind)
- DisposeDialog(_fPlatformWindow);
- else
- DisposeWindow(_fPlatformWindow);
- _fPlatformWindow = kODNULL;
- }
-
- // Storage Unit must be released before draft
- ODSafeReleaseObject(_fStorageUnit);
- ODSafeReleaseObject(_fDraft);
- ODSafeReleaseObject(_fRootFrame);
- ODSafeReleaseObject(_fSourceFrame);
- } // SOMLINK ODWindowsomUninit
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetPlatformWindow
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODPlatformWindow SOMLINK ODWindowGetPlatformWindow(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetPlatformWindow");
-
- return _fPlatformWindow;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: AcquireSourceFrame
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODFrame* SOMLINK ODWindowAcquireSourceFrame(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
-
- SOM_TRY
-
- if (_fSourceFrame)
- _fSourceFrame->Acquire(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- return _fSourceFrame;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetSourceFrame
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetSourceFrame(ODWindow *somSelf, Environment *ev,
- ODFrame* frame)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","AcquireSourceFrame");
-
- SOM_TRY
-
- if (frame)
- frame->Acquire(ev);
- if (_fSourceFrame)
- _fSourceFrame->Release(ev);
-
- _fSourceFrame = frame;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetRootFrame
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODFrame* SOMLINK ODWindowGetRootFrame(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetRootFrame");
-
- return _fRootFrame;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetRootFacet
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODFacet* SOMLINK ODWindowGetRootFacet(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetRootFacet");
-
- return _fRootFacet;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: CreateRootFrame
- // PRIVATE
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowCreateRootFrame(ODWindow *somSelf, Environment *ev,
- ODType frameType,
- ODTypeToken viewType,
- ODTypeToken presentation,
- ODPart* rootPart)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","CreateRootFrame");
-
- ODShape* newShape = kODNULL;ODVolatile(newShape);
-
- SOM_TRY
-
- if (_fPlatformWindow)
- {
- Rect frameShape = _fPlatformWindow->portRect;
-
- TRY
-
- newShape = new ODShape; // Can't Use factory method because no frame is available yet
- THROW_IF_NULL(newShape);
- newShape->InitShape(ev);
-
- CATCH_ALL
- ODDeleteObject(newShape); newShape = kODNULL; // must delete before InitShape returns
- RERAISE;
- ENDTRY
-
- TempODShape tempShape = newShape; // ensures it's released
-
- ODRect r = _fPlatformWindow->portRect;
- newShape->SetRectangle(ev,&r);
- _fRootFrame = _fDraft->CreateFrame(ev, frameType, (ODFrame*)kODNULL,
- newShape, (ODCanvas*)kODNULL,
- rootPart, viewType, presentation,
- kODFalse, // isSubframe
- kODFalse); // isOverlaid
- _fRootFrame->SetWindow(ev, somSelf);
-
- if (rootPart && _fSourceFrame)
- rootPart->AttachSourceFrame(ev, _fRootFrame, _fSourceFrame);
- }
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- } // CreateRootFrame()
-
- //-------------------------------------------------------------------------------------
- // ODWindow: CreateRootFacet
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowCreateRootFacet(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","CreateRootFacet");
-
- ODShape* frameShape = kODNULL;
- ODShape* clipShape = kODNULL;
-
- SOM_TRY
-
- frameShape = _fRootFrame->AcquireFrameShape(ev, kODNULL);
- clipShape = frameShape->Copy(ev);
- ODReleaseObject(ev, frameShape);
-
- ODTransform* externalTransform = _fRootFrame->CreateTransform(ev);
-
- ODWindowState* windowState = _fSession->GetWindowState(ev);
- ODCanvas* rootCanvas = windowState->CreateCanvas(ev, kODQuickDraw,
- (ODPlatformCanvas) _fPlatformWindow,
- kODTrue, // isDynamic
- kODFalse); // isOffscreen
-
- _fRootFacet = windowState->CreateFacet(ev, _fRootFrame, clipShape, externalTransform, rootCanvas, kODNULL);
- ODReleaseObject(ev, clipShape);
- ODReleaseObject(ev, externalTransform);
-
- _fRootFrame->FacetAdded(ev,_fRootFacet);
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: AdjustWindowShape
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowAdjustWindowShape (ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","AdjustWindowShape");
-
- SOM_TRY
-
- if (_fPlatformWindow)
- {
- Rect contentRect = _fPlatformWindow->portRect;
- Rect growRect = contentRect;
- growRect.left = growRect.right - 15;
- growRect.top = growRect.bottom - 15;
-
- RgnHandle contentRgn = ODNewRgn();
- RgnHandle growRgn = ODNewRgn();
- RectRgn(contentRgn,&contentRect);
- RectRgn(growRgn,&growRect);
-
- if (_fIsResizable)
- DiffRgn(contentRgn,growRgn,contentRgn);
- ODDisposeHandle((Handle)growRgn);
-
- SetPort(_fPlatformWindow);
- // InvalRgn(contentRgn);
-
- ODShape* windowShape =_fRootFrame->CreateShape(ev);
- windowShape->SetPlatformShape(ev,kODQuickDraw, (ODPlatformShape)contentRgn);
- #ifdef TO_BE_DELETED
- ODTransform* xform = _fRootFacet->AcquireExternalTransform(ev);
- windowShape->InverseTransform(ev, xform); // JBS - must transform frameShape to facet coords
- ODReleaseObject(ev, xform);
- #endif // TO_BE_DELETED
- ODShape* tempShape = kODNULL;
- tempShape = windowShape->Copy(ev);
- _fRootFacet->GetFrame(ev)->ChangeFrameShape(ev, windowShape, kODNULL);
- _fRootFacet->ChangeGeometry(ev, tempShape, kODNULL, kODNULL);
- ODReleaseObject(ev, windowShape);
- ODReleaseObject(ev, tempShape);
- }
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- } // AdjustWindowShape
-
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Open
- //
- // Description
- //-------------------------------------------------------------------------------------
-
-
- SOM_Scope void SOMLINK ODWindowOpen (ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Open");
-
- SOM_TRY
-
- if (_fRootFacet == kODNULL)
- {
- somSelf->CreateRootFacet(ev);
- if ( _fShouldAdjustOnOpen )
- somSelf->AdjustWindowShape(ev);
- _fIsDirty = kODTrue;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Close
- //
- // Description
- //-------------------------------------------------------------------------------------
-
-
- SOM_Scope void SOMLINK ODWindowClose(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Close");
-
- SOM_TRY
-
- somSelf->Hide(ev);
- _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
-
- if ( _fRootFrame )
- {
- if ( _fRootFacet )
- {
- _fRootFrame->FacetRemoved(ev,_fRootFacet);
- _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
-
- ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
- ODDeleteObject(rootCanvas); // DMc - new
- ODDeleteObject(_fRootFacet);
- }
-
- _fRootFrame->Close(ev);
- _fRootFrame = kODNULL;
- }
-
- ODReleaseObject(ev, _fSourceFrame);
- _fIsDirty = kODTrue;
- somSelf->Release(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- } // Close()
-
- //-------------------------------------------------------------------------------------
- // ODWindow: CloseAndRemove
- //
- // Description
- //-------------------------------------------------------------------------------------
-
-
- SOM_Scope void SOMLINK ODWindowCloseAndRemove(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","CloseAndRemove");
-
- SOM_TRY
-
- if (_fPlatformWindow)
- {
- somSelf->Hide(ev);
- _fSession->GetWindowState(ev)->RemoveWindow(ev,somSelf);
-
- if ( _fRootFrame )
- {
- if ( _fRootFacet )
- {
- _fRootFrame->FacetRemoved(ev,_fRootFacet);
- _fSession->GetDispatcher(ev)->InvalidateFacetUnderMouse(ev);
-
- ODCanvas* rootCanvas = _fRootFacet->GetCanvas(ev); // DMc - new
- ODDeleteObject(rootCanvas); // DMc - new
- ODDeleteObject(_fRootFacet);
- }
-
- if (!HAS_WRITE_ACCESS(_fDraft->GetPermissions(ev)))
- {
- _fRootFrame->Close(ev);
- _fRootFrame = kODNULL;
- }
- else
- {
- _fRootFrame->Remove(ev);
- _fRootFrame = kODNULL;
- }
- }
-
- ODReleaseObject(ev, _fSourceFrame);
- somSelf->Release(ev);
- _fIsDirty = kODTrue;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- }
-
-
-
- //-------------------------------------------------------------------------------------
- // ODWindow: HandleActivateEvent
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- static void ODDrawGrowIcon(ODPlatformWindow window)
- {
- GrafPtr savePort;
-
- GetPort(&savePort);
- SetPort(window);
- Rect r = window->portRect;
- r.left = r.right - 15;
- r.top = r.bottom - 15;
- RgnHandle oldClip = kODNULL; ODVolatile(oldClip);
-
- TRY
- oldClip = ODNewRgn();
-
- GetClip(oldClip);
- ClipRect(&r);
- DrawGrowIcon(window);
- SetClip(oldClip);
-
- CATCH_ALL
- // Don't Reraise. Since this gets called when putting up
- // the low memory alert calls DeactivateFrontWindows #1280629
- ENDTRY
-
- ODDisposeHandle((Handle)oldClip);
- SetPort(savePort);
- }
-
- #if ODDebug
-
- // Validate windows in the debug build:
- #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
- // Only one of the next two lines should be active
- #define OD_SLAM_WINDOWS
- //#undef OD_SLAM_WINDOWS
-
- #else /* ODDebug */
-
- // Currently, these settings are the same as the debug ones
- #define OD_VALIDATE_WINDOW(w) ValidateWindow(w)
- // Only one of the next two lines should be active
- #define OD_SLAM_WINDOWS
- //#undef OD_SLAM_WINDOWS
-
- #endif /* ODDebug */
-
- static void ValidateWindow( ODPlatformWindow newWindow )
- {
- WindowPeek wp = (WindowPeek)newWindow;
- static RgnHandle rgn = kODNULL;
-
- if ( rgn == kODNULL )
- rgn = ODNewRgn();
-
- if ( wp->visible && wp->hilited ) // Test only visible, active windows
- {
- Rect titleBarRect = (**wp->strucRgn).rgnBBox;
- titleBarRect.bottom = (**wp->contRgn).rgnBBox.top - 1;
- short titleHeight = titleBarRect.bottom - titleBarRect.top;
-
- InsetRect( &titleBarRect, 4, 4 );
- if ( !EmptyRect( &titleBarRect ))
- {
- RectRgn( rgn, &titleBarRect );
- SectRgn( GetGrayRgn(), rgn, rgn );
- if ( EmptyRgn( rgn ))
- {
- #ifdef OD_SLAM_WINDOWS
- WARN( "This window's title bar is not on-screen. It will be moved." );
- MoveWindow( newWindow, 2, LMGetMBarHeight() + titleHeight + 2, false );
- #else
- WARN( "This window's title bar is not on-screen." );
- #endif
- }
- else
- SetRectRgn( rgn, 0, 0, 0, 0 );
- }
- }
- // Note: The region is not disposed--it's static so we can use it
- // next time instead of doing a relatively expensive allocation. We
- // depend on the Process Manager to clean up when the process terminates.
- }
-
- SOM_Scope void SOMLINK ODWindowHandleActivateEvent (ODWindow *somSelf, Environment *ev,
- ODEventData* theEvent)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","HandleActivateEvent");
-
- ODFrame* frame = kODNULL;
- ODFacetIterator* t = kODNULL; ODVolatile(t);
-
- SOM_TRY
-
- _fIsActive = (theEvent->modifiers & activeFlag == 1);
-
- if ( _fIsActive )
- OD_VALIDATE_WINDOW( (WindowPtr)theEvent->message );
-
- t = _fRootFacet->CreateFacetIterator(ev,
- kODBottomUp, kODBackToFront);
-
- for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
- {
- if (facet)
- {
- TRY{
- frame = facet->GetFrame(ev);
- TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
- if ((ODPart*)part)
- part->HandleEvent(ev,theEvent, frame, facet, kODNULL);
- }CATCH_ALL{
- // ignore exception
- }ENDTRY
- }
- }
- ODDeleteObject(t);
- if (somSelf->IsResizable(ev))
- ODDrawGrowIcon(_fPlatformWindow);
-
- SOM_CATCH_ALL
-
- ODDeleteObject(t);
-
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: HandleUpdateEvent
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowHandleUpdateEvent (ODWindow *somSelf, Environment *ev,
- ODEventData* theEvent)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","HandleUpdateEvent");
-
- ODUnused(theEvent);
-
- SOM_TRY
- somSelf->Update(ev);
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Update
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowUpdate(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Update");
-
- SOM_TRY
-
- if (_fPlatformWindow)
- {
- // #1248624 Failure handling should be further improved, but this should prevent
- // the infinite dialog problem
- TRY
- GrafPtr savePort;
-
- GetPort(&savePort);
- somSelf->PrepareCanvas(ev);
-
- TempODFrame activeFrame
- = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
- BeginUpdate(_fPlatformWindow); // this sets up the visRgn
-
- if (!EmptyRgn(_fPlatformWindow->visRgn)) // draw if updating needs to be done
- {
- // Let the part decide
- // EraseRgn (_fPlatformWindow->visRgn);
-
- {
- ODFacet* rootFacet = _fRootFacet;
-
- RgnHandle updateRgn = ODNewRgn();
- CopyRgn(_fPlatformWindow->visRgn, updateRgn);
- TempODShape updateShape = rootFacet->CreateShape(ev);
- updateShape->SetPlatformShape(ev,kODQuickDraw, updateRgn);
- TempODTransform xform = rootFacet->AcquireWindowFrameTransform(ev, kODNULL);
- updateShape->InverseTransform(ev, xform);
- rootFacet->Update(ev, updateShape, kODNULL);
- }
- // • Focus back on the window so that everything gets reset
- somSelf->PrepareCanvas(ev);
-
- // • After everything is back in shape we need to get the grow icon drawn
- if (somSelf->IsResizable(ev))
- ODDrawGrowIcon(_fPlatformWindow);
- }
- EndUpdate(_fPlatformWindow);
- somSelf->DrawActiveBorder(ev,activeFrame);
- SetPort(savePort);
-
- CATCH_ALL
- EndUpdate(_fPlatformWindow);
- ENDTRY
- }
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- } // SOMLINK ODWindowUpdate
-
- //-------------------------------------------------------------------------------------
- // ODWindow: DrawActiveBorder
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowDrawActiveBorder(ODWindow *somSelf, Environment *ev, ODFrame* frame)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","DrawActiveBorder");
-
- // !!! needs to draw border for all facets of active frame
- // Don't draw in background. Also need to invalidate
-
- SOM_TRY
-
- if ( !_fInBackground && frame && (frame != _fRootFrame) )
- {
- frame->DrawActiveBorder(ev);
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: PrepareCanvas
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowPrepareCanvas(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","PrepareCanvas");
-
- SOM_TRY
-
- if (_fPlatformWindow)
- {
- SetPort (_fPlatformWindow);
- SetOrigin(0,0);
- ClipRect (&_fPlatformWindow->portRect);
- }
- else
- ClipRect (&ODQDGlobals.thePort->portRect);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: IsResizable
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowIsResizable(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","IsResizable");
-
- return _fIsResizable;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: IsFloating
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowIsFloating(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","IsFloating");
-
- return _fIsFloating;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: IsRootWindow
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowIsRootWindow(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","IsRootWindow");
-
- return _fIsRootWindow;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: ShouldSave
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowShouldSave(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","ShouldSave");
-
- return _fShouldSave;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetShouldSave
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetShouldSave(ODWindow *somSelf, Environment *ev,
- ODBoolean shouldSave)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetShouldSave");
-
- _fShouldSave = shouldSave;
- _fIsDirty = kODTrue;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: ShouldShowLinks
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowShouldShowLinks(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","ShouldShowLinks");
-
- return _fShouldShowLinks;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetShouldShowLinks
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetShouldShowLinks(ODWindow *somSelf, Environment *ev,
- ODBoolean shouldShowLinks)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetShouldShowLinks");
-
- _fShouldShowLinks = shouldShowLinks;
- _fIsDirty = kODTrue;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: ShouldDispose
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowShouldDispose(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","ShouldDispose");
-
- return _fShouldDispose;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetFacetUnderPoint
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- typedef enum { kODForDragEvent, kODForMouseEvent } FacetSearchConstraint;
-
- ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
- ODPoint* windowPoint, FacetSearchConstraint constraint );
-
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetFacetUnderPoint
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODFacet* SOMLINK ODWindowGetFacetUnderPointForDrag(ODWindow *somSelf,
- Environment *ev, ODPoint* windowPoint)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetFacetUnderPointForDrag");
-
- ODFacet* foundFacet = kODNULL;
-
- SOM_TRY
- foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
- kODForDragEvent );
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return foundFacet;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetFacetUnderPoint
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODFacet* SOMLINK ODWindowGetFacetUnderPoint(ODWindow *somSelf,
- Environment *ev, ODPoint* windowPoint)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetFacetUnderPoint");
-
- ODFacet* foundFacet = kODNULL;
-
- SOM_TRY
- foundFacet = GetFacetUnderPointInternal( ev, _fRootFacet, windowPoint,
- kODForMouseEvent );
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return foundFacet;
- }
-
- //-------------------------------------------------------------------------------------
- // GetFacetUnderPointInternal
- //
- // Description
- // Utility function for the two GetFacetUnderPoint methods above.
- //-------------------------------------------------------------------------------------
- ODFacet* GetFacetUnderPointInternal( Environment *ev, ODFacet* rootFacet,
- ODPoint* windowPoint, FacetSearchConstraint constraint )
- {
- ODFacet* foundFacet = kODNULL;
- ODFacetIterator* t = kODNULL; ODVolatile(t);
- ODPoint framePoint;
-
- SOM_TRY
- //!!! Should use frameshape containment to prune search
- t = rootFacet->CreateFacetIterator(ev,
- kODTopDown, kODBackToFront);
-
- for ( ODFacet* facet = t->First(ev);
- t->IsNotComplete(ev);
- facet = t->Next(ev) )
- {
- // get windowPoint in frame coords for hit-testing
- { TempODTransform winToFrame = facet->AcquireWindowFrameTransform(ev, kODNULL);
- framePoint = *windowPoint;
- winToFrame->InvertPoint(ev, &framePoint);
- }
-
- if (facet->ContainsPoint(ev, &framePoint, kODNULL))
- {
- foundFacet = facet;
- #if 0 /* this is the old code */
- if (facet->GetFrame(ev)->IsFrozen(ev) || facet->IsSelected(ev))
- t->SkipChildren(ev);
- #else /* this is the new -- replaces above */
- if (facet->GetFrame(ev)->IsFrozen(ev))
- t->SkipChildren(ev);
- else if ( (constraint == kODForMouseEvent) && facet->IsSelected(ev))
- {
- t->SkipChildren(ev);
- }
- #endif
- }
- else
- t->SkipChildren(ev);
- }
- delete t;
-
- SOM_CATCH_ALL
-
- ODDeleteObject(t);
-
- SOM_ENDTRY
-
- return foundFacet;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: IsActive
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowIsActive(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","IsActive");
-
- ODBoolean isActive = _fIsActive && !_fInBackground;
-
- return isActive;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Show
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowShow(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Show");
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- if (!somSelf->IsShown(ev))
- _fSession->GetWindowState(ev)->ShowODWindow(ev,somSelf);
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Hide
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowHide(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Hide");
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- if (somSelf->IsShown(ev))
- {
- _fSession->GetWindowState(ev)->HideODWindow(ev,somSelf);
- _fIsDirty = kODTrue;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SuspendResume
- //
- // Send event to each visible window
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSuspendResume(ODWindow *somSelf, Environment *ev,
- ODEventData* event)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SuspendResume");
-
-
- const short kResumeMask = 0x01; // High byte suspend/resume event
- ODFrame* frame = kODNULL;
- ODFacetIterator* t = kODNULL; ODVolatile(t);
-
- _fInBackground = (event->message & kResumeMask) == 0;
-
- SOM_TRY
-
- somSelf->PrepareCanvas(ev);
- if (somSelf->IsResizable(ev))
- ODDrawGrowIcon(_fPlatformWindow);
-
- t = _fRootFacet->CreateFacetIterator(ev,
- kODTopDown, kODFrontToBack);
-
- for (ODFacet* facet = t->First(ev); t->IsNotComplete(ev); facet = t->Next(ev))
- {
- if (facet)
- {
- TRY{
- frame = facet->GetFrame(ev);
- TempODPart part = frame->AcquirePart(ev); // -- TÇ tempobj'd
- if ((ODPart*)part)
- part->HandleEvent(ev,event, frame, facet, kODNULL);
- }CATCH_ALL{
- // ignore exception
- }ENDTRY
- }
- }
- ODDeleteObject(t);
-
-
- TempODFrame activeFrame = _fSession->GetArbitrator(ev)->AcquireFocusOwner(ev,_fSelectionFocus);
- if (activeFrame)
- {
- if (_fInBackground)
- activeFrame->InvalidateActiveBorder(ev);
- else // Limitation of API: Can't call Invalidate twice, because shape gets released
- activeFrame->DrawActiveBorder(ev);
- }
-
-
-
- SOM_CATCH_ALL
-
- ODDeleteObject(t);
-
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Activate
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowActivate(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Activate");
-
- SOM_TRY
-
- // Floating window implementation relies on suppressing activate events
- // Part::HandleEvent expects them, so they're synthesize here.
- // They must be routed through the dispatcher, so they can be monitored/patched
- // The modifiers field is hacked to alert the dispatcher that this is
- // an OpenDoc-generated activate event.
-
- EventRecord event;
-
- SetActivateEvent(event, _fPlatformWindow, kODTrue);
-
- _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Deactivate
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowDeactivate(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Deactivate");
-
- SOM_TRY
-
- // Floating window implementation relies on suppressing activate events
- // Part::HandleEvent expects them, so they're synthesize here.
- // They must be routed through the dispatcher, so they can be monitored/patched
- // Bit 1 (starting from 0) of the modifiers field is set to alert the dispatcher
- // that this is an OpenDoc-generated activate event.
-
- EventRecord event;
-
- SetActivateEvent(event, _fPlatformWindow, kODFalse);
-
- _fSession->GetDispatcher(ev)->Dispatch(ev, &event);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Drag
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowDrag(ODWindow *somSelf, Environment *ev,
- Point* startPoint,
- Rect* draggingBounds)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Drag");
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- _fSession->GetWindowState(ev)->DragODWindow(ev,somSelf, startPoint, draggingBounds);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Select
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSelect(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Select");
-
- SOM_TRY
-
- if (_fInBackground)
- {
- ProcessSerialNumber current;
- OSErr err = GetCurrentProcess(¤t);
- if (err == noErr)
- SetFrontProcess(¤t);
- }
- _fSession->GetWindowState(ev)->SelectODWindow(ev,somSelf);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: IsShown
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowIsShown(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","IsShown");
-
- ODBoolean isShown = kODFalse;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- isShown = ((WindowRecord*)_fPlatformWindow)->visible;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return isShown;
- }
-
- //-------------------------------------------------------------------------------------
- // Protected methods
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowHasCloseBox(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","HasCloseBox");
-
- ODBoolean hasCloseBox = kODFalse;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL,kODErrInvalidPlatformWindow);
- hasCloseBox = ((WindowRecord*)_fPlatformWindow)->goAwayFlag;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return hasCloseBox;
- }
-
- SOM_Scope ODBoolean SOMLINK ODWindowHasZoomBox(ODWindow *somSelf, Environment *ev)
-
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","HasZoomBox");
-
- ODBoolean hasZoomBox = kODFalse;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
- hasZoomBox = ((WindowRecord*)_fPlatformWindow)->spareFlag;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return hasZoomBox;
- }
-
- SOM_Scope ODBoolean SOMLINK ODWindowHasGrowBox(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","HasGrowBox");
-
- ODBoolean hasGrowBox = kODFalse;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
- hasGrowBox = somSelf->IsResizable(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return hasGrowBox;
- }
-
- SOM_Scope ODSShort SOMLINK ODWindowGetProcID(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetProcID");
-
- short theID = 0;
- ResType theType;
- Str255 theName;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- GetResInfo(((WindowPeek)_fPlatformWindow)->windowDefProc, &theID, &theType, theName);
- short theVariant = GetWVariant(_fPlatformWindow);
- theID = theID*16 + theVariant;
- // return GetWVariant(_fPlatformWindow);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return theID;
-
- }
-
- SOM_Scope void SOMLINK ODWindowGetWindowBounds(ODWindow *somSelf, Environment *ev,
- Rect* bounds)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetWindowBounds");
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
-
- // This old code doesn't work when the window is shaded by WindowShade:
-
- //ODRgnHandle contRgn;
-
- //contRgn = ((WindowRecord*)_fPlatformWindow)->contRgn;
- //*bounds = (**contRgn).rgnBBox;
-
- // This new code works with WindowShade:
-
- const ODUShort kColorPort = 0xC000;
- ODBoolean isCGrafPort =
- (((CGrafPtr)_fPlatformWindow)->portVersion & kColorPort ) == kColorPort;
-
- if ( isCGrafPort )
- {
- CGrafPtr port = (CGrafPtr)_fPlatformWindow;
- bounds->left = port->portRect.left - (**(port->portPixMap)).bounds.left;
- bounds->top = port->portRect.top - (**(port->portPixMap)).bounds.top;
- bounds->right = bounds->left - port->portRect.left + port->portRect.right;
- bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
- }
- else // It's just a GrafPort
- {
- GrafPtr port = (GrafPtr)_fPlatformWindow;
- bounds->left = port->portRect.left - port->portBits.bounds.left;
- bounds->top = port->portRect.top - port->portBits.bounds.top;
- bounds->right = bounds->left - port->portRect.left + port->portRect.right;
- bounds->bottom = bounds->top - port->portRect.top + port->portRect.bottom;
- }
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- SOM_Scope ODSLong SOMLINK ODWindowGetRefCon(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetRefCon");
-
- ODSLong refCon = 0;
-
- SOM_TRY
-
- ASSERT(_fPlatformWindow != kODNULL, kODErrInvalidPlatformWindow);
- refCon = ((WindowRecord*)_fPlatformWindow)->refCon;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return refCon;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetWindowTitle
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetWindowTitle(ODWindow *somSelf, Environment *ev,
- char* title)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetWindowTitle");
-
- Str255 titleCopy;
-
- strcpy( (char*) &(titleCopy[1]), title);
- titleCopy[0] = strlen(title);
-
- SOM_TRY
-
- SetWTitle(_fPlatformWindow, titleCopy);
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetWasVisible
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetWasVisible(ODWindow *somSelf, Environment *ev,
- ODBoolean wasVisible)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetWasVisible");
-
- _fWasVisible = wasVisible;
- _fIsDirty = kODTrue;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetWasVisible
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODBoolean SOMLINK ODWindowGetWasVisible(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetWasVisible");
-
- return _fWasVisible;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: Externalize
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowExternalize(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","Externalize");
-
- // #1246478 Removing fIsDirty optimization, because clients can call GetPlatformWindow
- // and change things.
- //if ( !_fIsDirty )
- // return;
-
- SOM_TRY
-
- // Should Title be an ODIText?
-
- ODStorageUnit* su = _fStorageUnit;
-
- // No need to do these ASSERTs because the StdTypIO routines make sure
- // the appropriate property and value exist. -TÇ
- /*
- ASSERT(su->Exists(ev,kODPropWindowRect, kODRect, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowTitle, kODMacIText, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowProcID, kODSShort, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowIsVisible, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowHasCloseBox, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowHasZoomBox, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowIsResizable, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowIsRootWindow, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowIsFloating, kODBoolean, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropWindowRefCon, kODSLong, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropRootFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
- //ASSERT(su->Exists(ev,kODPropSourceFrame, kODStrongStorageUnitRef, 0), kODErrInvalidWindow);
- ASSERT(su->Exists(ev,kODPropShouldShowLinks, kODBoolean, 0), kODErrInvalidWindow);
- */
-
- // Externalize Window Manager properties
-
- // Externalize the bounds as a standard ODRect
-
- Rect r;
- somSelf->GetWindowBounds(ev,&r);
- ODRect odRect(r);
- ODSetRectProp(ev, su, kODPropWindowRect, kODRect, &odRect);
-
- // Externalize title as an IText
-
- Str255 title;
- GetWTitle(_fPlatformWindow, title);
-
- ODScriptCode script = FontToScript(GetAppFont());
- ODLangCode lang = GetScriptVariable(script, smScriptLang);
-
- ODIText* iText = CreateITextPString(script, lang, &title[0]);
- ODSetITextProp(ev, su, kODPropWindowTitle, kODMacIText, iText);
- DisposeIText(iText);
-
- ODSetSShortProp(ev, su, kODPropWindowProcID, kODSShort, somSelf->GetProcID(ev));
- ODSetBooleanProp(ev, su, kODPropWindowIsVisible, kODBoolean, somSelf->IsShown(ev));
- ODSetBooleanProp(ev, su, kODPropWindowHasCloseBox, kODBoolean, somSelf->HasCloseBox(ev));
- ODSetBooleanProp(ev, su, kODPropWindowHasZoomBox, kODBoolean, somSelf->HasZoomBox(ev));
- ODSetULongProp(ev, su, kODPropWindowRefCon, kODSLong, somSelf->GetRefCon(ev));
-
- // Other properties
-
- ODSetBooleanProp(ev, su, kODPropWindowIsResizable, kODBoolean, somSelf->IsResizable(ev));
- ODSetBooleanProp(ev, su, kODPropWindowIsFloating, kODBoolean, somSelf->IsFloating(ev));
- ODSetBooleanProp(ev, su, kODPropWindowIsRootWindow, kODBoolean, somSelf->IsRootWindow(ev));
-
- ODSetBooleanProp(ev, su, kODPropShouldShowLinks, kODBoolean, somSelf->ShouldShowLinks(ev));
-
- // root frame
-
- ODSetStrongSURefProp(ev, su, kODPropRootFrame, kODStrongStorageUnitRef, _fRootFrame->GetStorageUnit(ev)->GetID(ev));
-
- // Source Frame (this property is only written if the value is non-NULL)
-
- if (_fSourceFrame)
- {
- ODSetStrongSURefProp(ev, su, kODPropSourceFrame, kODStrongStorageUnitRef,
- _fSourceFrame->GetStorageUnit(ev)->GetID(ev));
- }
- else if (ODSUExistsThenFocus(ev, su ,kODPropSourceFrame, kODStrongStorageUnitRef))
- {
- su->Remove(ev);
- }
-
- // Annotate the root frame with the window properties
- ODStorageUnit* frameSU = _fRootFrame->GetStorageUnit(ev);
- ODSetStrongSURefProp(ev, frameSU, kODPropWindowProperties, kODStrongStorageUnitRef,
- su->GetID(ev));
-
- _fIsDirty = kODFalse;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetID
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODID SOMLINK ODWindowGetID(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetID");
-
- return _fID;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetID
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetID(ODWindow *somSelf, Environment *ev,
- ODID windowID)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetID");
-
- _fID = windowID;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: AcquireStorageUnit
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODStorageUnit* SOMLINK ODWindowGetStorageUnit(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetStorageUnit");
-
- SOM_TRY
-
- if (_fStorageUnit != kODNULL)
- _fStorageUnit->Internalize(ev);
-
- SOM_CATCH_ALL
- SOM_ENDTRY
-
- return _fStorageUnit;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: SetStorageUnit
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowSetStorageUnit(ODWindow *somSelf, Environment *ev, ODStorageUnit* su)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","SetStorageUnit");
-
- SOM_TRY
-
- _fStorageUnit = su;
- su->Acquire(ev);
-
- // These below calls are unnecessary because the StdTypIO routines make sure
- // the appropriate property and value exist. -TÇ
- /*
- ODSUAddPropValue(ev, kODPropWindowRect, kODRect);
- ODSUAddPropValue(ev, kODPropWindowTitle, kODMacIText);
- ODSUAddPropValue(ev, kODPropWindowProcID, kODSShort);
- ODSUAddPropValue(ev, kODPropWindowIsVisible, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowHasCloseBox, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowHasZoomBox, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowIsResizable, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowIsRootWindow, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowIsFloating, kODBoolean);
- ODSUAddPropValue(ev, kODPropWindowRefCon, kODSLong);
- ODSUAddPropValue(ev, kODPropRootFrame, kODStrongStorageUnitRef);
- ODSUAddPropValue(ev, kODPropShouldShowLinks, kODBoolean);
- */
-
- _fIsDirty = kODTrue;
-
- SOM_CATCH_ALL
- SOM_ENDTRY
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetDraft
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope ODDraft* SOMLINK ODWindowGetDraft(ODWindow *somSelf, Environment *ev)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetDraft");
-
- return _fDraft;
- }
-
- //-------------------------------------------------------------------------------------
- // ODWindow: GetWindowPoint
- //
- // Description
- //-------------------------------------------------------------------------------------
-
- SOM_Scope void SOMLINK ODWindowGetWindowPoint(ODWindow *somSelf, Environment *ev,
- Point* globalPoint, ODPoint* windowPoint)
- {
- ODWindowData *somThis = ODWindowGetData(somSelf);
- ODWindowMethodDebug("ODWindow","GetWindowPoint");
-
- Point localCopy = *globalPoint;
-
- GrafPtr curPort;
- GetPort(&curPort);
- SetPort(_fPlatformWindow);
- SetOrigin(0,0);
- GlobalToLocal(&localCopy);
- SetPort(curPort);
- *windowPoint = (ODPoint)localCopy;
- }
-