home *** CD-ROM | disk | FTP | other *** search
- /*
- File: SEPriv.cpp
-
- Contains: xxx put contents here xxx
-
- Owned by: Nick Pilch
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <9> 6/30/95 JP Acquire when creating standard part token
- <8> 6/19/95 eeh 1246443: add PartFrameFromStandardPartToken
- etc.
- <7> 6/13/95 JP Changed AcquireActiveWindow to
- AcquireFrontRootWindow
- <6> 5/26/95 RR #1251403: Multithreading naming support
- <5> 5/21/95 NP 1248898: GetUserToken, ODDescToAEDesc, etc.
- recipe change. Add SetUserODToken for
- setting user ODDesc in an OSLToken.
- <4> 5/17/95 RR #1250135/1250137/1250143 Getters increment
- refcount
- <3> 4/25/95 NP 1186795, 1237220, 1240571: Fixed whose
- clauses by allowing swapping in count proc.
- <2> 4/25/95 JP 1237938: Added ODRgstry.xh include for
- kODStandardPartTokenType
- <1> 4/14/95 NP first checked in
-
- To Do:
- */
-
- #ifndef _SEPRIV_
- #include "SEPriv.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include "ODSessn.xh"
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- ODFrame* FrameFromStandardPartToken(AEDesc* token)
- {
- ODFrame* frame;
- PartFrameFromStandardPartToken( token, kODNULL, &frame );
- return frame;
- #if 0
- WASSERT(token->descriptorType == kODStandardPartTokenType);
- WASSERT(token->dataHandle != kODNULL);
- StandardPartToken spt = FIRSTBYTESFROMHANDLE(
- token->dataHandle, StandardPartToken );
- return spt.fFrame;
- #endif
- }
-
- ODPart* PartFromStandardPartToken(AEDesc* token)
- {
- ODPart* part;
- PartFrameFromStandardPartToken( token, &part, kODNULL );
- return part;
- #if 0
- WASSERT(token->descriptorType == kODStandardPartTokenType);
- WASSERT(token->dataHandle != kODNULL);
- StandardPartToken spt = FIRSTBYTESFROMHANDLE(
- token->dataHandle, StandardPartToken );
- return spt.fPart;
- #endif
- }
-
- void PartFrameFromStandardPartToken(AEDesc* token, ODPart** part,
- ODFrame** frame)
- {
- ODBoolean coerced = kODFalse;
- if ( token->descriptorType != kODStandardPartTokenType ) // dup. only if must
- {
- AEDesc coercedToken;
- THROW_IF_ERROR( AECoerceDesc( token, kODStandardPartTokenType,
- &coercedToken ) );
- coerced = kODTrue;
- token = &coercedToken;
- }
- WASSERT(token->descriptorType == kODStandardPartTokenType);
- WASSERT(token->dataHandle != kODNULL);
- WASSERT( GetHandleSize(token->dataHandle) == sizeof(StandardPartToken) );
- StandardPartToken spt = FIRSTBYTESFROMHANDLE(
- token->dataHandle, StandardPartToken );
- if ( part )
- *part = spt.fPart;
- if ( frame )
- *frame = spt.fFrame;
- if ( coerced )
- (void)AEDisposeDesc( token );
- }
-
- ODBoolean CanBeStandardPartToken( AEDesc* token )
- {
- ODBoolean result = (token->descriptorType == kODStandardPartTokenType) &&
- (GetHandleSize(token->dataHandle) == sizeof(StandardPartToken));
- if ( !result )
- {
- AEDesc coercedToken;
- OSErr err = AECoerceDesc( token, kODStandardPartTokenType,
- &coercedToken );
- result = (err == noErr) &&
- (coercedToken.descriptorType == kODStandardPartTokenType) &&
- (GetHandleSize(coercedToken.dataHandle)
- == sizeof(StandardPartToken));
- (void)AEDisposeDesc( &coercedToken );
- }
- return result;
- }
-
- OSErr CreateStandardPartToken( ODFrame* frame, ODPart* part, AEDesc* newToken )
- {
- StandardPartToken spt;
- Environment* ev = somGetGlobalEnvironment();
-
- // refcount the objects since we're saving them
- if (frame)
- frame->Acquire(ev);
- if (part)
- part->Acquire(ev);
-
- spt.fFrame = frame;
- spt.fPart = part;
- return AECreateDesc( kODStandardPartTokenType, &spt, sizeof(spt),
- newToken );
- }
-
- ODFrame* GetDefaultRootFrameToSwapTo(Environment *ev, ODSession* session)
- {
- ODWindow* odWindow = session->GetWindowState(ev)->AcquireFrontRootWindow(ev);
- ODFrame* rootFrame = odWindow ? odWindow->GetRootFrame(ev) : kODNULL;
- ODReleaseObject(ev, odWindow);
- return rootFrame;
- }
-
- //------------------------------------------------------------------------------
- // SetUserODToken
- //
- // Set the "user" token in the token that the OSL passes around.
- //
- // The userToken is the first four bytes.
- //------------------------------------------------------------------------------
-
- void SetUserODToken(OSLToken* oslToken, ODDesc* odDesc)
- {
- *((ODDesc**)(*(oslToken->dataHandle))) = odDesc;
- }
-
-