home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 April: Mac OS SDK / Dev.CD Apr 96 SDK / Dev.CD Apr 96 SDK1.toast / Development Kits (Disc 1) / OpenDoc / Sample Code / Sample Editors⁄Viewers / Text Editor / Source / ScriptRunnerSupport.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-12-13  |  5.1 KB  |  183 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        ScriptRunnerSupport.cpp
  3.  
  4.     Contains:    ScriptRunner support functions
  5.  
  6.     Written by:    Troy Gaul
  7.  
  8.     Copyright:    © 1995 by Apple Computer, Inc., all rights reserved.
  9. */
  10.  
  11. #ifndef _COMPILERDEFS_
  12. #include "CompDefs.h"
  13. #endif
  14.  
  15. #ifndef _SCRIPTRUNNERSUPPORT_
  16. #include <ScriptRunnerSupport.h>
  17. #endif
  18.  
  19. // -- OpenDoc Utilities --
  20.  
  21. #ifndef _EXCEPT_
  22. // Exceptions define several important macros (e.g. CHECKENV)
  23. // which are used in the SOM method dispatch glue. If Except.h
  24. // is not included early enough, exceptions may not be thrown
  25. // correctly when returning from a SOM method with "ev" parameter set.
  26. #include <Except.h>
  27. #endif
  28.  
  29. // -- OpenDoc Includes --
  30.  
  31. #ifndef _ODTYPES_
  32. #include <ODTypes.h>
  33. #endif
  34.  
  35. #ifndef SOM_ODPart_xh
  36. #include <Part.xh>
  37. #endif
  38.  
  39. #ifndef SOM_ODStorageUnit_xh
  40. #include <StorageU.xh>
  41. #endif
  42.  
  43. #ifndef SOM_ODDraft_xh
  44. #include <Draft.xh>
  45. #endif
  46.  
  47. #ifndef SOM_ODSession_xh
  48. #include <ODSessn.xh>
  49. #endif
  50.  
  51. #ifndef SOM_ODNameSpaceManager_xh
  52. #include <NmSpcMg.xh>
  53. #endif
  54.  
  55. #ifndef SOM_ODObjectNameSpace_xh
  56. #include <ObjectNS.xh>
  57. #endif
  58.  
  59. // --- OpenDoc Utilities ---
  60.  
  61. #ifndef _ODUTILS_
  62. #include "ODUtils.h"
  63. #endif
  64.  
  65. // --- Macintosh Includes ---
  66.  
  67. #ifndef __CODEFRAGMENTS__
  68. #include "CodeFragments.h"
  69. #endif
  70.  
  71. // -- ScriptRunner Includes --
  72.  
  73. #ifndef SOM_PaletteExt_xh
  74. #include "PaletteExt.xh"
  75. #endif
  76.  
  77. #ifndef SOM_Sample_ScriptRunnerAgent_xh
  78. #include "ScriptRunnerAgent.xh"
  79. #endif
  80.  
  81. #ifndef SOM_TextTransferExt_xh
  82. #include "TextTransferExt.xh"
  83. #endif
  84.  
  85.  
  86. //------------------------------------------------------------------------------
  87. // IsScriptRunnerLibAvailable
  88. //------------------------------------------------------------------------------
  89.  
  90. ODBoolean IsScriptRunnerLibAvailable(Environment* ev)
  91. {
  92.     // Since the text transfer extension is part of the ScriptRunner shared
  93.     // library, we just look for that in order to determine if the library
  94.     // is available.
  95.  
  96.     return IsTextTransferExtAvailable(ev);
  97. }
  98.  
  99. //------------------------------------------------------------------------------
  100. // IsScriptRunnerPlugInLibAvailable
  101. //------------------------------------------------------------------------------
  102.  
  103. ODBoolean IsScriptRunnerPlugInLibAvailable(Environment* ev)
  104. {
  105.     // Because we weak link to the ScriptRunner PlugIn's shared library, 
  106.     // we need to be able to determine at run time if the link was resolved 
  107.     // (that is, if ScriptRunner is installed on the user's machine).  In 
  108.     // order to do this, we evaluate a symbol from that shared library and 
  109.     // if it is not equal to kUnresolvedCFragSymbolAddress then we know the 
  110.     // library is available.
  111.  
  112.     return ((long) &Sample_ScriptRunnerAgentClassData != kUnresolvedCFragSymbolAddress);
  113. }
  114.  
  115. //------------------------------------------------------------------------------
  116. // IsTextTransferExtAvailable
  117. //------------------------------------------------------------------------------
  118.  
  119. ODBoolean IsTextTransferExtAvailable(Environment* ev)
  120. {
  121.     // Because we weak link to the ScriptRunner shared library, 
  122.     // we need to be able to determine at run time if the link was resolved 
  123.     // (that is, if ScriptRunner is installed on the user's machine).  In 
  124.     // order to do this, we evaluate a symbol from that shared library and 
  125.     // if it is not equal to kUnresolvedCFragSymbolAddress then we know the 
  126.     // library is available.
  127.  
  128.     return ((long) &TextTransferExtClassData != kUnresolvedCFragSymbolAddress);
  129. }
  130.  
  131. //------------------------------------------------------------------------------
  132. // IsScriptRunnerInstalled
  133. //------------------------------------------------------------------------------
  134.  
  135. ODBoolean IsScriptRunnerInstalled(Environment* ev, ODSession* session)
  136. {
  137.     // This routine checks not only for the existance of both of the required
  138.     // shared libraries, but it also looks to see if the proxy object was
  139.     // successfully installed into the namespace.  If this routine returns
  140.     // true, everything is set up and ready to go as far as ScriptRunner is
  141.     // concerned.
  142.  
  143.     return (IsScriptRunnerLibAvailable(ev) 
  144.             && IsScriptRunnerPlugInLibAvailable(ev)
  145.             && GetScriptRunnerAgent(ev, session) != kODNULL);
  146. }
  147.  
  148. //------------------------------------------------------------------------------
  149. // GetScriptRunnerAgent
  150. //------------------------------------------------------------------------------
  151.  
  152. Sample_ScriptRunnerAgent* GetScriptRunnerAgent(Environment* ev, ODSession* session)
  153. {
  154.     Sample_ScriptRunnerAgent* proxy = kODNULL;
  155.  
  156.     ODNameSpaceManager* nameSpMgr = session->GetNameSpaceManager(ev);
  157.     ODObjectNameSpace* objNameSpace = (ODObjectNameSpace*) 
  158.                             nameSpMgr->HasNameSpace(ev, kOSAScriptingTool);
  159.     
  160.     if ( objNameSpace != kODNULL )
  161.         objNameSpace->GetEntry(ev, kOSAScriptingTool, (ODObject**) &proxy);
  162.  
  163.     return proxy;
  164. }
  165.  
  166. //------------------------------------------------------------------------------
  167. // StartScriptRunner
  168. //------------------------------------------------------------------------------
  169.  
  170. Samples_PaletteExt* AcquireScriptRunner(Environment* ev, ODDraft* draft)
  171. {
  172.     Samples_PaletteExt* scriptPaletteExt = kODNULL;
  173.     ODSession* session = ODGetSession(ev, draft);
  174.  
  175.     if ( IsScriptRunnerInstalled(ev, session) )
  176.         scriptPaletteExt = (Samples_PaletteExt*) GetScriptRunnerAgent(ev, session)->
  177.                                                     AcquireScriptRunner(ev, draft);
  178.     
  179.     return scriptPaletteExt;
  180. }
  181.  
  182.  
  183.