home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 July: Mac OS SDK / Dev.CD Jul 96 SDK / Dev.CD Jul 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc Source Code / Messaging / SEPriv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-04-22  |  4.3 KB  |  165 lines  |  [TEXT/BROW]

  1. /*
  2.     File:        SEPriv.cpp
  3.  
  4.     Contains:    xxx put contents here xxx
  5.  
  6.     Owned by:    Nick Pilch
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <9>     6/30/95    JP        Acquire when creating standard part token
  13.          <8>     6/19/95    eeh        1246443: add PartFrameFromStandardPartToken
  14.                                     etc.
  15.          <7>     6/13/95    JP        Changed AcquireActiveWindow to
  16.                                     AcquireFrontRootWindow
  17.          <6>     5/26/95    RR        #1251403: Multithreading naming support
  18.          <5>     5/21/95    NP        1248898: GetUserToken, ODDescToAEDesc, etc.
  19.                                     recipe change. Add SetUserODToken for
  20.                                     setting user ODDesc in an OSLToken.
  21.          <4>     5/17/95    RR        #1250135/1250137/1250143 Getters increment
  22.                                     refcount
  23.          <3>     4/25/95    NP        1186795, 1237220, 1240571: Fixed whose
  24.                                     clauses by allowing swapping in count proc.
  25.          <2>     4/25/95    JP        1237938: Added ODRgstry.xh include for
  26.                                     kODStandardPartTokenType
  27.          <1>     4/14/95    NP        first checked in
  28.  
  29.     To Do:
  30. */
  31.  
  32. #ifndef _SEPRIV_
  33. #include "SEPriv.h"
  34. #endif
  35.  
  36. #ifndef SOM_ODSession_xh
  37. #include "ODSessn.xh"
  38. #endif
  39.  
  40. #ifndef SOM_ODWindowState_xh
  41. #include <WinStat.xh>
  42. #endif
  43.  
  44. #ifndef SOM_ODWindow_xh
  45. #include <Window.xh>
  46. #endif
  47.  
  48. #ifndef _SEUTILS_
  49. #include "SEUtils.h"
  50. #endif
  51.  
  52. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  53. #include "ODRgstry.xh"
  54. #endif
  55.  
  56. ODFrame* FrameFromStandardPartToken(AEDesc* token)
  57. {
  58.     ODFrame* frame;
  59.     PartFrameFromStandardPartToken( token, kODNULL, &frame );
  60.     return frame;
  61. #if 0
  62.     WASSERT(token->descriptorType == kODStandardPartTokenType);
  63.     WASSERT(token->dataHandle != kODNULL);
  64.     StandardPartToken spt = FIRSTBYTESFROMHANDLE(
  65.             token->dataHandle, StandardPartToken );
  66.     return spt.fFrame;
  67. #endif
  68. }
  69.  
  70. ODPart* PartFromStandardPartToken(AEDesc* token)
  71. {
  72.     ODPart* part;
  73.     PartFrameFromStandardPartToken( token, &part, kODNULL );
  74.     return part;
  75. #if 0
  76.     WASSERT(token->descriptorType == kODStandardPartTokenType);
  77.     WASSERT(token->dataHandle != kODNULL);
  78.     StandardPartToken spt = FIRSTBYTESFROMHANDLE(
  79.             token->dataHandle, StandardPartToken );
  80.     return spt.fPart;
  81. #endif
  82. }
  83.  
  84. void PartFrameFromStandardPartToken(AEDesc* token, ODPart** part,
  85.         ODFrame** frame)
  86. {
  87.     ODBoolean coerced = kODFalse;
  88.      if ( token->descriptorType != kODStandardPartTokenType )    // dup. only if must
  89.     {
  90.         AEDesc coercedToken;
  91.         THROW_IF_ERROR( AECoerceDesc( token, kODStandardPartTokenType,
  92.                 &coercedToken ) );
  93.         coerced = kODTrue;
  94.         token = &coercedToken;
  95.     }
  96.     WASSERT(token->descriptorType == kODStandardPartTokenType);
  97.     WASSERT(token->dataHandle != kODNULL);
  98.     WASSERT( GetHandleSize(token->dataHandle) == sizeof(StandardPartToken) );
  99.     StandardPartToken spt = FIRSTBYTESFROMHANDLE(
  100.             token->dataHandle, StandardPartToken );
  101.     if ( part )
  102.         *part = spt.fPart;
  103.     if ( frame )
  104.         *frame = spt.fFrame;
  105.     if ( coerced )
  106.         (void)AEDisposeDesc( token );
  107. }
  108.  
  109. ODBoolean CanBeStandardPartToken( AEDesc* token )
  110. {
  111.     ODBoolean result = (token->descriptorType == kODStandardPartTokenType) &&
  112.         (GetHandleSize(token->dataHandle) == sizeof(StandardPartToken));
  113.     if ( !result )
  114.     {
  115.         AEDesc coercedToken;
  116.         OSErr err = AECoerceDesc( token, kODStandardPartTokenType,
  117.                 &coercedToken );
  118.         result = (err == noErr) &&
  119.                 (coercedToken.descriptorType == kODStandardPartTokenType) &&
  120.                 (GetHandleSize(coercedToken.dataHandle)
  121.                         == sizeof(StandardPartToken));
  122.         (void)AEDisposeDesc( &coercedToken );
  123.     }
  124.     return result;
  125. }
  126.  
  127. OSErr CreateStandardPartToken( ODFrame* frame, ODPart* part, AEDesc* newToken )
  128. {
  129.     StandardPartToken    spt;
  130.     Environment*        ev = somGetGlobalEnvironment();
  131.     
  132.     // refcount the objects since we're saving them
  133.     if (frame)
  134.         frame->Acquire(ev);
  135.     if (part)
  136.         part->Acquire(ev);
  137.     
  138.     spt.fFrame = frame;
  139.     spt.fPart = part;
  140.     return AECreateDesc( kODStandardPartTokenType, &spt, sizeof(spt),
  141.         newToken );
  142. }
  143.  
  144. ODFrame* GetDefaultRootFrameToSwapTo(Environment *ev, ODSession* session)
  145. {
  146.     ODWindow* odWindow = session->GetWindowState(ev)->AcquireFrontRootWindow(ev);
  147.     ODFrame* rootFrame = odWindow ? odWindow->GetRootFrame(ev) : kODNULL;
  148.     ODReleaseObject(ev, odWindow);
  149.     return rootFrame;
  150. }
  151.  
  152. //------------------------------------------------------------------------------
  153. // SetUserODToken
  154. //
  155. //    Set the "user" token in the token that the OSL passes around.
  156. //
  157. //    The userToken is the first four bytes.
  158. //------------------------------------------------------------------------------
  159.  
  160. void SetUserODToken(OSLToken* oslToken, ODDesc* odDesc)
  161. {
  162.     *((ODDesc**)(*(oslToken->dataHandle))) = odDesc;
  163. }
  164.  
  165.