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 Development Framework / ODFDev / Button / Sources / Actions.cpp next >
Encoding:
Text File  |  1996-04-25  |  20.4 KB  |  668 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                Actions.h
  4. //    Release Version:    $ ODF 1 $
  5. //
  6. //    Author:                Jim Lloyd
  7. //
  8. //    Copyright:            (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  9. //
  10. //========================================================================================
  11.  
  12. #ifndef ACTIONS_H
  13. #include "Actions.h"
  14. #endif
  15.  
  16. #ifndef DEFINES_K
  17. #include "Defines.k"
  18. #endif
  19.  
  20. #ifndef BINDING_K
  21. #include "Binding.k"
  22. #endif
  23.  
  24. #ifndef ENVIRONS_H
  25. #include "Environs.h"
  26. #endif
  27.  
  28. // ----- OS Layer -----
  29.  
  30. #ifndef FWPART_H
  31. #include "FWPart.h"
  32. #endif
  33.  
  34. #ifndef FWBARRAY_H
  35. #include "FWBArray.h"
  36. #endif
  37.  
  38. #ifndef FWMEMMGR_H
  39. #include "FWMemMgr.h"
  40. #endif
  41.  
  42. #ifndef FWMEMHLP_H
  43. #include "FWMemHlp.h"
  44. #endif
  45.  
  46. #ifndef FWMEMHLP_H
  47. #include "FWMemHlp.h"
  48. #endif
  49.  
  50. #ifndef FWFILESP_H
  51. #include "FWFileSp.h"
  52. #endif
  53.  
  54. #ifndef FWRESOUR_H
  55. #include "FWResour.h"
  56. #endif
  57.  
  58. // ----- OpenDoc Includes -----
  59.  
  60. #ifndef FWODTYPS_H
  61. #include "FWODTyps.h"
  62. #endif
  63.  
  64. #ifndef SOM_Module_OpenDoc_StdProps_defined
  65. #include <StdProps.xh>
  66. #endif
  67.  
  68. #ifndef SOM_ODStorageUnit_xh
  69. #include <StorageU.xh>
  70. #endif
  71.  
  72. #ifndef SOM_ODTranslation_xh
  73. #include <Translt.xh>
  74. #endif
  75.  
  76. #ifndef SOM_ODSession_xh
  77. #include <ODSessn.xh>
  78. #endif
  79.  
  80. #ifndef SOM_ODDragItemIterator_xh
  81. #include <DgItmIt.xh>
  82. #endif
  83.  
  84. // ----- Macintosh Includes -----
  85.  
  86. #if defined(FW_BUILD_MAC) && !defined(__DRAG__)
  87. #include <Drag.h>
  88. #endif
  89.  
  90. #if defined(FW_BUILD_MAC) && !defined(__SOUND__)
  91. #include <Sound.h>
  92. #endif
  93.  
  94. //========================================================================================
  95. //    Static Allocations
  96. //========================================================================================
  97.  
  98. ComponentInstance CScriptAction::fgComponentInstance;
  99.  
  100. //========================================================================================
  101. //    Runtime information
  102. //========================================================================================
  103.  
  104. #ifdef FW_BUILD_MAC
  105. #pragma segment odfbutton
  106. #endif
  107.  
  108. //========================================================================================
  109. //    class CAction
  110. //========================================================================================
  111.  
  112. FW_DEFINE_CLASS_M0(CAction)
  113.  
  114. //----------------------------------------------------------------------------------------
  115. //    CAction::CAction
  116. //----------------------------------------------------------------------------------------
  117.  
  118. CAction::CAction()
  119. {
  120. }
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    CAction::~CAction
  124. //----------------------------------------------------------------------------------------
  125.  
  126. CAction::~CAction()
  127. {
  128. }
  129.  
  130. //----------------------------------------------------------------------------------------
  131. //    CAction::IsInStorage
  132. //----------------------------------------------------------------------------------------
  133.  
  134. FW_Boolean CAction::IsInStorage(Environment* ev, ODStorageUnit* storage)
  135. {
  136.     return storage->Exists(ev, kODPropContents, kODFButtonKind, 0);
  137. }
  138.  
  139. //----------------------------------------------------------------------------------------
  140. //    CAction::CreateFromStorage
  141. //----------------------------------------------------------------------------------------
  142.  
  143. CAction* CAction::CreateFromStorage(Environment* ev, ODStorageUnit* storage)
  144. {
  145.     CAction* action;
  146.     FW_PStorageUnitSink sink(ev, storage, kODPropContents, kODFButtonKind);
  147.     FW_CReadableStream stream(sink);
  148.     FW_READ_DYNAMIC_OBJECT(stream, &action, CAction);
  149.     return action;
  150. }
  151.  
  152. //----------------------------------------------------------------------------------------
  153. //    CAction::WriteToStorage
  154. //----------------------------------------------------------------------------------------
  155.  
  156. void CAction::WriteToStorage(Environment* ev, CAction* action, ODStorageUnit* storage)
  157. {
  158.     FW_PStorageUnitSink sink(ev, storage, kODPropContents, kODFButtonKind);
  159.     FW_CWritableStream stream(sink);
  160.     FW_WRITE_DYNAMIC_OBJECT(stream, action, CAction);
  161. }
  162.  
  163. //========================================================================================
  164. //    class CSoundAction
  165. //========================================================================================
  166.  
  167. FW_DEFINE_CLASS_M1(CSoundAction, CAction)
  168.  
  169. const FW_ClassTypeConstant LSoundAction = FW_TYPE_CONSTANT('S','N','D','A');
  170. FW_REGISTER_ARCHIVABLE_CLASS(LSoundAction, CSoundAction, CSoundAction::Read, 0, 0, CSoundAction::Write)
  171.  
  172. //----------------------------------------------------------------------------------------
  173. //    CSoundAction::CSoundAction
  174. //----------------------------------------------------------------------------------------
  175.  
  176. CSoundAction::CSoundAction(Environment* ev, ODStorageUnit* storage)
  177.     : fSoundHandle(0)
  178. {
  179.     Internalize(ev, storage);
  180. }
  181.  
  182. //----------------------------------------------------------------------------------------
  183. //    CSoundAction::CSoundAction
  184. //----------------------------------------------------------------------------------------
  185.  
  186. CSoundAction::CSoundAction(Environment* ev, FW_CReadableStream& stream)
  187.     : fSoundHandle(0)
  188. {
  189.     InternalizeFromStream(ev, stream);
  190. }
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    CSoundAction::~CSoundAction
  194. //----------------------------------------------------------------------------------------
  195.  
  196. CSoundAction::~CSoundAction()
  197. {
  198.     if (fSoundHandle)
  199.         ::DisposeHandle(fSoundHandle);
  200. }
  201.  
  202. //----------------------------------------------------------------------------------------
  203. //    CSoundAction::IsInStorage
  204. //----------------------------------------------------------------------------------------
  205.  
  206. FW_Boolean CSoundAction::IsInStorage(Environment* ev, ODStorageUnit* storage)
  207. {
  208.     FW_Boolean result = false;
  209.     if (storage->Exists(ev, kODPropContents, kSoundScrapKind, 0))        // 'snd ' on Scrap
  210.         result = true;
  211.     else if (storage->Exists(ev, kODPropContents, kSoundFileKind, 0))    // sound file
  212.         result = true;
  213.     return result;
  214. }
  215.  
  216. //----------------------------------------------------------------------------------------
  217. //    CSoundAction::Internalize
  218. //----------------------------------------------------------------------------------------
  219.  
  220. void CSoundAction::Internalize(Environment* ev, ODStorageUnit* storage)
  221. {
  222.     FW_Boolean internalized = FALSE;
  223.     
  224.     if (storage->Exists(ev, kODPropContents, kSoundScrapKind, 0))
  225.     {
  226.         // Mac 'snd ' in Scrap
  227.         storage->Focus(ev, 
  228.                         kODPropContents, 
  229.                         kODPosUndefined, 
  230.                         kSoundScrapKind, 
  231.                         0,
  232.                         kODPosUndefined);
  233.         ODStorageUnitView* view = storage->CreateView(ev);
  234.         {
  235.         FW_PStorageUnitSink sink(ev, view);
  236.         FW_CReadableStream stream(sink);
  237.         InternalizeFromStream(ev, stream);
  238.         }
  239.         delete view;
  240.         
  241.     }
  242.     else if (storage->Exists(ev, kODPropContents, kSoundFileKind, 0))    
  243.     {
  244.         // Mac sound file
  245.         storage->Focus(ev, 
  246.                         kODPropContents, 
  247.                         kODPosUndefined, 
  248.                         FW_CPart::gMachfsDataType, 
  249.                         0, 
  250.                         kODPosUndefined);
  251.         InternalizeSoundFile(ev, storage);
  252.     }
  253. }
  254.  
  255. //----------------------------------------------------------------------------------------
  256. //    CSoundAction::InternalizeFromStream
  257. //----------------------------------------------------------------------------------------
  258.  
  259. void CSoundAction::InternalizeFromStream(Environment* ev, FW_CReadableStream& stream)
  260. {
  261.     FW_OSink*    sink = stream.GetSink();
  262.     unsigned long size = sink->GetReadableBytes(ev);
  263.     if (size > 0)
  264.     {
  265.         FW_CAcquireTemporarySystemHandle handle(size);
  266.         stream.Read(handle.GetPointer(), size);
  267.         fSoundHandle = handle.GetPlatformHandle();
  268.         handle.Orphan();
  269.     }
  270. }
  271.  
  272. //----------------------------------------------------------------------------------------
  273. //    CSoundAction::InternalizeSound
  274. //----------------------------------------------------------------------------------------
  275. #if 0
  276. void CSoundAction::InternalizeSound(Environment* ev, ODStorageUnit* storage)
  277. {
  278.     // Assume the storage unit is already focused
  279.     unsigned long size = storage->GetSize(ev);
  280.     if (size > 0)
  281.     {
  282.         FW_CAcquireTemporarySystemHandle handle(size);
  283.         FW_CByteArray byteArray;
  284.         storage->GetValue(ev, size, byteArray);
  285.         byteArray.CopyBuffer(handle.GetPointer(), size);
  286.         fSoundHandle = handle.GetPlatformHandle();
  287.         handle.Orphan();
  288.     }
  289. }
  290. #endif
  291.  
  292. //----------------------------------------------------------------------------------------
  293. //    CSoundAction::InternalizeSoundFile
  294. //----------------------------------------------------------------------------------------
  295.  
  296. void CSoundAction::InternalizeSoundFile(Environment* ev, ODStorageUnit* storage)
  297. {
  298.     // StorageUnit should already be Focused on HFSFlavor
  299.     unsigned long hfsSize = storage->GetSize(ev);
  300.     if (hfsSize > 0)
  301.     {
  302.         // Get the HFS flavor
  303.         HFSFlavor hfsInfo;
  304.         FW_CByteArray byteArray;
  305.         storage->GetValue(ev, sizeof(HFSFlavor), byteArray);
  306.         byteArray.CopyBuffer(&hfsInfo, sizeof(HFSFlavor));
  307.         
  308.         // Create platform independent file spec
  309.         FW_PFileSpecification fileSpec(ev, hfsInfo.fileSpec);
  310.         
  311.         // Open the resource file
  312.         FW_PResourceFile resourceFile(ev, fileSpec);
  313.  
  314.         // Get any (i.e the first) sound resource
  315.         const FW_ResourceType resourceType = 'snd ';
  316.         const FW_ResourceId resourceId = 1;
  317.         Handle sound = ::Get1IndResource(resourceType, resourceId);
  318.                                         
  319.         if (sound != NULL)
  320.         {
  321.             // if succeeded, detach the handle and keep it
  322.             ::DetachResource(sound);
  323.             fSoundHandle = sound;
  324.         }
  325.         else
  326.         {
  327.             // No sound resource loaded, throw an exception
  328.             FW_FailOnError(::ResError());
  329.             FW_Failure(resNotFound);
  330.         }
  331.     }
  332. }
  333.  
  334. //----------------------------------------------------------------------------------------
  335. //    CSoundAction::Externalize
  336. //----------------------------------------------------------------------------------------
  337.  
  338. void CSoundAction::Externalize(Environment* ev, ODStorageUnit* storage)
  339. {
  340.     if (fSoundHandle != NULL)
  341.     {
  342.         if (!storage->Exists(ev, kODPropContents, kSoundScrapKind, 0))
  343.             storage->AddValue(ev, kSoundScrapKind);
  344.     
  345.         storage->Focus(ev, kODPropContents, kODPosUndefined, kSoundScrapKind, 0, kODPosUndefined);
  346.         ODStorageUnitView* view = storage->CreateView(ev);
  347.         {
  348.         FW_PStorageUnitSink sink(ev, view);
  349.         FW_CWritableStream stream(sink);
  350.         ExternalizeToStream(ev, stream);
  351.         }
  352.         delete view;
  353.     }
  354. }
  355.  
  356. //----------------------------------------------------------------------------------------
  357. //    CSoundAction::ExternalizeToStream
  358. //----------------------------------------------------------------------------------------
  359.  
  360. void CSoundAction::ExternalizeToStream(Environment* ev, FW_CWritableStream& stream)
  361. {
  362.     if (fSoundHandle != NULL)
  363.     {
  364.         FW_CAcquireLockedSystemHandle lock(fSoundHandle);
  365.         stream.Write(*fSoundHandle, FW_CMemoryManager::GetSystemHandleSize(fSoundHandle));
  366.     }
  367. }
  368.  
  369. //----------------------------------------------------------------------------------------
  370. // CSoundAction::DoIt
  371. //----------------------------------------------------------------------------------------
  372.  
  373. void CSoundAction::DoIt()
  374. {
  375.     if (fSoundHandle != NULL)
  376.     {
  377.         FW_CAcquireLockedSystemHandle lock(fSoundHandle);
  378.         ::SndPlay(NULL, (SndListHandle)fSoundHandle, TRUE);
  379.     }
  380. }
  381.  
  382. //----------------------------------------------------------------------------------------
  383. // CSoundAction::Read
  384. //----------------------------------------------------------------------------------------
  385.  
  386. void* CSoundAction::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  387. {
  388.     FW_SOMEnvironment ev;
  389.     return new CSoundAction(ev, stream);
  390. }
  391.  
  392. //----------------------------------------------------------------------------------------
  393. // CSoundAction::Write
  394. //----------------------------------------------------------------------------------------
  395.  
  396. void CSoundAction::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  397. {
  398.     FW_SOMEnvironment ev;
  399.     CSoundAction* action = (CSoundAction*) object;
  400.     action->ExternalizeToStream(ev, stream);
  401. }
  402.  
  403. //========================================================================================
  404. //    class CScriptAction
  405. //========================================================================================
  406.  
  407. FW_DEFINE_CLASS_M1(CScriptAction, CAction)
  408.  
  409. const FW_ClassTypeConstant LScriptAction = FW_TYPE_CONSTANT('S','C','R','A');
  410. FW_REGISTER_ARCHIVABLE_CLASS(LScriptAction, CScriptAction, CScriptAction::Read, 0, 0, CScriptAction::Write)
  411.  
  412. //----------------------------------------------------------------------------------------
  413. //    CScriptAction::CScriptAction
  414. //----------------------------------------------------------------------------------------
  415.  
  416. CScriptAction::CScriptAction(Environment* ev, ODStorageUnit* storage)
  417.     : fScriptHandle(0)
  418. {
  419.     Internalize(ev, storage);
  420. }
  421.  
  422. //----------------------------------------------------------------------------------------
  423. //    CScriptAction::CScriptAction
  424. //----------------------------------------------------------------------------------------
  425.  
  426. CScriptAction::CScriptAction(Environment* ev, FW_CReadableStream& stream)
  427.     : fScriptHandle(0)
  428. {
  429.     InternalizeFromStream(ev, stream);
  430. }
  431.  
  432. //----------------------------------------------------------------------------------------
  433. //    CScriptAction::~CScriptAction
  434. //----------------------------------------------------------------------------------------
  435.  
  436. CScriptAction::~CScriptAction()
  437. {
  438.     if (fScriptHandle)
  439.         ::DisposeHandle(fScriptHandle);
  440.     ReleaseScriptingComponent();
  441. }
  442.  
  443. //----------------------------------------------------------------------------------------
  444. //    CScriptAction::IsInStorage
  445. //----------------------------------------------------------------------------------------
  446.  
  447. FW_Boolean CScriptAction::IsInStorage(Environment* ev, ODStorageUnit* storage)
  448. {
  449.     FW_Boolean result = false;
  450.     if (storage->Exists(ev, kODPropContents, kScriptScrapKind, 0))        // 'scpt' on Scrap
  451.         result = true;
  452.     else if (storage->Exists(ev, kODPropContents, kScriptFileKind, 0))    // compiled script file
  453.         result = true;
  454.     return result;
  455. }
  456.  
  457. //----------------------------------------------------------------------------------------
  458. //    CScriptAction::Internalize
  459. //----------------------------------------------------------------------------------------
  460.  
  461. void CScriptAction::Internalize(Environment* ev, ODStorageUnit* storage)
  462. {
  463.     FW_Boolean internalized = FALSE;
  464.     
  465.     if (storage->Exists(ev, kODPropContents, kScriptScrapKind, 0))
  466.     {
  467.         // 'scpt' on Scrap
  468.         storage->Focus(ev, kODPropContents, kODPosUndefined, kScriptScrapKind, 0, kODPosUndefined);
  469.         ODStorageUnitView* view = storage->CreateView(ev);
  470.         {
  471.         FW_PStorageUnitSink sink(ev, view);
  472.         FW_CReadableStream stream(sink);
  473.         InternalizeFromStream(ev, stream);
  474.         }
  475.         delete view;
  476.     }
  477.     else if (storage->Exists(ev, kODPropContents, kScriptFileKind, 0))    // compiled script file
  478.     {
  479.         storage->Focus(ev, kODPropContents, kODPosUndefined, FW_CPart::gMachfsDataType, 0, kODPosUndefined);
  480.         InternalizeScriptFile(ev, storage);
  481.     }
  482. }
  483.  
  484. //----------------------------------------------------------------------------------------
  485. //    CScriptAction::InternalizeFromStream
  486. //----------------------------------------------------------------------------------------
  487.  
  488. void CScriptAction::InternalizeFromStream(Environment* ev, FW_CReadableStream& stream)
  489. {
  490.     FW_OSink*    sink = stream.GetSink();
  491.     unsigned long size = sink->GetReadableBytes(ev);
  492.     if (size > 0)
  493.     {
  494.         FW_CAcquireTemporarySystemHandle handle(size);
  495.         stream.Read(handle.GetPointer(), size);
  496.         fScriptHandle = handle.GetPlatformHandle();
  497.         handle.Orphan();
  498.     }
  499. }
  500.  
  501. //----------------------------------------------------------------------------------------
  502. //    CScriptAction::InternalizeScript
  503. //----------------------------------------------------------------------------------------
  504. #if 0
  505. void CScriptAction::InternalizeScript(Environment* ev, ODStorageUnit* storage)
  506. {
  507.     // Assume the storage unit is already focused
  508.     unsigned long size = storage->GetSize(ev);
  509.     if (size > 0)
  510.     {
  511.         FW_CAcquireTemporarySystemHandle handle(size);
  512.         FW_CByteArray byteArray;
  513.         storage->GetValue(ev, size, byteArray);
  514.         byteArray.CopyBuffer(handle.GetPointer(), size);
  515.         fScriptHandle = handle.GetPlatformHandle();
  516.         handle.Orphan();
  517.     }
  518. }
  519. #endif
  520.  
  521. //----------------------------------------------------------------------------------------
  522. //    CScriptAction::InternalizeScriptFile
  523. //----------------------------------------------------------------------------------------
  524.  
  525. void CScriptAction::InternalizeScriptFile(Environment* ev, ODStorageUnit* storage)
  526. {
  527.     // StorageUnit should already be Focused on HFSFlavor
  528.     unsigned long hfsSize = storage->GetSize(ev);
  529.     if (hfsSize > 0)
  530.     {
  531.         // Get the HFS flavor
  532.         HFSFlavor hfsInfo;
  533.         FW_CByteArray byteArray;
  534.         storage->GetValue(ev, sizeof(HFSFlavor), byteArray);
  535.         byteArray.CopyBuffer(&hfsInfo, sizeof(HFSFlavor));
  536.         
  537.         // Make the file specification
  538.         FW_PFileSpecification fileSpec(ev, hfsInfo.fileSpec);
  539.         
  540.         // Acquire an opened resource file, 
  541.         // will be closed automatically
  542.         FW_PResourceFile resourceFile(ev, fileSpec);
  543.         
  544.         // Acquire an opened resource, 
  545.         // will be released automatically
  546.         FW_PResource resource(ev, resourceFile, 128, 'scpt');
  547.         FW_CAcquireResourceData lockedResource(ev, resource);
  548.         
  549.         // Copy the resource data into a new handle
  550.         FW_CAcquireTemporarySystemHandle lockedHandle(lockedResource.GetSize());
  551.         FW_CMemoryManager::CopyMemory(lockedResource.GetData(), lockedHandle.GetPointer(), lockedResource.GetSize());
  552.         fScriptHandle = lockedHandle.GetPlatformHandle();
  553.         lockedHandle.Orphan();
  554.     }
  555. }
  556.  
  557. //----------------------------------------------------------------------------------------
  558. //    CScriptAction::Externalize
  559. //----------------------------------------------------------------------------------------
  560.  
  561. void CScriptAction::Externalize(Environment* ev, ODStorageUnit* storage)
  562. {
  563.     if (fScriptHandle != NULL)
  564.     {
  565.         if (!storage->Exists(ev, kODPropContents, kScriptScrapKind, 0))
  566.             storage->AddValue(ev, kScriptScrapKind);
  567.     
  568.         storage->Focus(ev, kODPropContents, kODPosUndefined, kScriptScrapKind, 0, kODPosUndefined);
  569.         ODStorageUnitView* view = storage->CreateView(ev);
  570.         {
  571.             FW_PStorageUnitSink sink(ev, view);
  572.             FW_CWritableStream stream(sink);
  573.             ExternalizeToStream(ev, stream);
  574.         }
  575.         delete view;
  576.     }
  577. }
  578.  
  579. //----------------------------------------------------------------------------------------
  580. //    CScriptAction::ExternalizeToStream
  581. //----------------------------------------------------------------------------------------
  582.  
  583. void CScriptAction::ExternalizeToStream(Environment* ev, FW_CWritableStream& stream)
  584. {
  585.     if (fScriptHandle != NULL)
  586.     {
  587.         FW_CAcquireLockedSystemHandle lock(fScriptHandle);
  588.         stream.Write(*fScriptHandle, FW_CMemoryManager::GetSystemHandleSize(fScriptHandle));
  589.     }
  590. }
  591.  
  592. //----------------------------------------------------------------------------------------
  593. //    LoadAndExecuteScript
  594. //----------------------------------------------------------------------------------------
  595. // This function was lifted almost verbatim from
  596. // IM:IAC, page 10-16. (Actually, I used MPTA, but it says 
  597. // the code is on the above page)
  598.  
  599. void CScriptAction::LoadAndExecuteScript(Handle scriptData)
  600. {
  601.     AEDesc scriptDesc;
  602.     OSAID scriptID;
  603.     OSAID resultID;
  604.     OSAError error;
  605.     
  606.     if (!HasAppleScript())
  607.     {
  608.         FW_CString32 name("ODFButton");
  609.         FW_CString message;
  610.         FW_SOMEnvironment ev;
  611.         FW_CSharedLibraryResourceFile resFile(ev);
  612.         
  613.         ::FW_LoadStringByID(ev, resFile, kButtonDialogStrings, MULTISTRINGRES, kNoAppleScriptMsg, message);
  614.         ::FW_NoteAlert(name, message);
  615.     }
  616.     else
  617.     {    
  618.         // load the script data
  619.         scriptDesc.descriptorType = typeOSAGenericStorage;
  620.         scriptDesc.dataHandle = scriptData;
  621.         
  622.         ComponentInstance componentInstance = GetScriptingComponent();
  623.         
  624.         error = ::OSALoad(componentInstance, &scriptDesc, kOSAModeNull, &scriptID);
  625.         
  626.         if (error == noErr)
  627.         { 
  628.             // execute the compiled script in the default context                 
  629.             error = ::OSAExecute(componentInstance, scriptID, kOSANullScript, kOSAModeNull, &resultID);
  630.             error = ::OSADispose(componentInstance, scriptID);
  631.             error = ::OSADispose(componentInstance, resultID);
  632.         }
  633.     }
  634. }
  635.  
  636.  
  637. //----------------------------------------------------------------------------------------
  638. // CScriptAction::DoIt
  639. //----------------------------------------------------------------------------------------
  640.  
  641. void CScriptAction::DoIt()
  642. {
  643.     if (fScriptHandle != NULL)
  644.         LoadAndExecuteScript(fScriptHandle);
  645. }
  646.  
  647. //----------------------------------------------------------------------------------------
  648. // CScriptAction::Read
  649. //----------------------------------------------------------------------------------------
  650.  
  651. void* CScriptAction::Read(FW_CReadableStream& stream, FW_ClassTypeConstant type)
  652. {
  653.     FW_SOMEnvironment ev;
  654.     return new CScriptAction(ev, stream);
  655. }
  656.  
  657. //----------------------------------------------------------------------------------------
  658. // CScriptAction::Write
  659. //----------------------------------------------------------------------------------------
  660.  
  661. void CScriptAction::Write(FW_CWritableStream& stream, FW_ClassTypeConstant type, const void *object)
  662. {
  663.     FW_SOMEnvironment ev;
  664.     CScriptAction* action = (CScriptAction*) object;
  665.     action->ExternalizeToStream(ev, stream);
  666. }
  667.  
  668.