home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ScriptRunnerSupport.cpp
-
- Contains: ScriptRunner support functions
-
- Written by: Troy Gaul
-
- Copyright: © 1995 by Apple Computer, Inc., all rights reserved.
- */
-
- #ifndef _COMPILERDEFS_
- #include "CompDefs.h"
- #endif
-
- #ifndef _SCRIPTRUNNERSUPPORT_
- #include <ScriptRunnerSupport.h>
- #endif
-
- // -- OpenDoc Utilities --
-
- #ifndef _EXCEPT_
- // Exceptions define several important macros (e.g. CHECKENV)
- // which are used in the SOM method dispatch glue. If Except.h
- // is not included early enough, exceptions may not be thrown
- // correctly when returning from a SOM method with "ev" parameter set.
- #include <Except.h>
- #endif
-
- // -- OpenDoc Includes --
-
- #ifndef _ODTYPES_
- #include <ODTypes.h>
- #endif
-
- #ifndef SOM_ODPart_xh
- #include <Part.xh>
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include <StorageU.xh>
- #endif
-
- #ifndef SOM_ODDraft_xh
- #include <Draft.xh>
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include <NmSpcMg.xh>
- #endif
-
- #ifndef SOM_ODObjectNameSpace_xh
- #include <ObjectNS.xh>
- #endif
-
- // --- OpenDoc Utilities ---
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- // --- Macintosh Includes ---
-
- #ifndef __CODEFRAGMENTS__
- #include "CodeFragments.h"
- #endif
-
- // -- ScriptRunner Includes --
-
- #ifndef SOM_PaletteExt_xh
- #include "PaletteExt.xh"
- #endif
-
- #ifndef SOM_Sample_ScriptRunnerAgent_xh
- #include "ScriptRunnerAgent.xh"
- #endif
-
- #ifndef SOM_TextTransferExt_xh
- #include "TextTransferExt.xh"
- #endif
-
-
- //------------------------------------------------------------------------------
- // IsScriptRunnerLibAvailable
- //------------------------------------------------------------------------------
-
- ODBoolean IsScriptRunnerLibAvailable(Environment* ev)
- {
- // Since the text transfer extension is part of the ScriptRunner shared
- // library, we just look for that in order to determine if the library
- // is available.
-
- return IsTextTransferExtAvailable(ev);
- }
-
- //------------------------------------------------------------------------------
- // IsScriptRunnerPlugInLibAvailable
- //------------------------------------------------------------------------------
-
- ODBoolean IsScriptRunnerPlugInLibAvailable(Environment* ev)
- {
- // Because we weak link to the ScriptRunner PlugIn's shared library,
- // we need to be able to determine at run time if the link was resolved
- // (that is, if ScriptRunner is installed on the user's machine). In
- // order to do this, we evaluate a symbol from that shared library and
- // if it is not equal to kUnresolvedCFragSymbolAddress then we know the
- // library is available.
-
- return ((long) &Sample_ScriptRunnerAgentClassData != kUnresolvedCFragSymbolAddress);
- }
-
- //------------------------------------------------------------------------------
- // IsTextTransferExtAvailable
- //------------------------------------------------------------------------------
-
- ODBoolean IsTextTransferExtAvailable(Environment* ev)
- {
- // Because we weak link to the ScriptRunner shared library,
- // we need to be able to determine at run time if the link was resolved
- // (that is, if ScriptRunner is installed on the user's machine). In
- // order to do this, we evaluate a symbol from that shared library and
- // if it is not equal to kUnresolvedCFragSymbolAddress then we know the
- // library is available.
-
- return ((long) &TextTransferExtClassData != kUnresolvedCFragSymbolAddress);
- }
-
- //------------------------------------------------------------------------------
- // IsScriptRunnerInstalled
- //------------------------------------------------------------------------------
-
- ODBoolean IsScriptRunnerInstalled(Environment* ev, ODSession* session)
- {
- // This routine checks not only for the existance of both of the required
- // shared libraries, but it also looks to see if the proxy object was
- // successfully installed into the namespace. If this routine returns
- // true, everything is set up and ready to go as far as ScriptRunner is
- // concerned.
-
- return (IsScriptRunnerLibAvailable(ev)
- && IsScriptRunnerPlugInLibAvailable(ev)
- && GetScriptRunnerAgent(ev, session) != kODNULL);
- }
-
- //------------------------------------------------------------------------------
- // GetScriptRunnerAgent
- //------------------------------------------------------------------------------
-
- Sample_ScriptRunnerAgent* GetScriptRunnerAgent(Environment* ev, ODSession* session)
- {
- Sample_ScriptRunnerAgent* proxy = kODNULL;
-
- ODNameSpaceManager* nameSpMgr = session->GetNameSpaceManager(ev);
- ODObjectNameSpace* objNameSpace = (ODObjectNameSpace*)
- nameSpMgr->HasNameSpace(ev, kOSAScriptingTool);
-
- if ( objNameSpace != kODNULL )
- objNameSpace->GetEntry(ev, kOSAScriptingTool, (ODObject**) &proxy);
-
- return proxy;
- }
-
- //------------------------------------------------------------------------------
- // StartScriptRunner
- //------------------------------------------------------------------------------
-
- Samples_PaletteExt* AcquireScriptRunner(Environment* ev, ODDraft* draft)
- {
- Samples_PaletteExt* scriptPaletteExt = kODNULL;
- ODSession* session = ODGetSession(ev, draft);
-
- if ( IsScriptRunnerInstalled(ev, session) )
- scriptPaletteExt = (Samples_PaletteExt*) GetScriptRunnerAgent(ev, session)->
- AcquireScriptRunner(ev, draft);
-
- return scriptPaletteExt;
- }
-
-
-