home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc / OpenDoc Development / Debugging Support / OpenDoc™ Source Code / DocShell / RlShlEv.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-08-28  |  43.3 KB  |  1,557 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        RlShlEv.cpp
  3.  
  4.     Contains:    Apple Event handlers for the document shell.
  5.  
  6.     Owned by:    Eric House
  7.  
  8.     Copyright:    © 1994 - 1996 by Apple Computer, Inc., all rights reserved.
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <5>     7/11/96    TJ        Quit event does not return an error
  13.          <4>     6/20/96    JP        1339269: Made quit handle the saving
  14.                                     parameter too
  15.          <3>     5/31/96    jpa        T10012: Fixed 'oapp', 'odoc', 'pdoc'
  16.                                     handlers for app-style (CyberDog) process
  17.                                     model.
  18.          <2>      5/8/96    NP        1304875: Infinite Save Changes dialog boxes
  19.  
  20.     To Do:
  21.     In Progress:
  22.         
  23. */
  24.  
  25. #ifndef _PLFMDEF_
  26. #include <PlfmDef.h>
  27. #endif
  28.  
  29. #ifndef _SIHELPER_
  30. #include <SIHelper.h>
  31. #endif
  32.  
  33. #ifndef _ODPRCS_
  34. #include "ODPrcs.h"
  35. #endif
  36.  
  37. #ifndef SOM_ODSession_xh
  38. #include <ODSessn.xh>
  39. #endif
  40.  
  41. #ifndef _EXCEPT_
  42. #include <Except.h>
  43. #endif
  44.  
  45. #ifndef SOM_ShellSI_xh
  46. #include "ShellSI.xh"
  47. #endif
  48.  
  49. #ifndef _RLSHELL_
  50. #include "RlShell.h"
  51. #endif
  52.  
  53. #ifndef _SEUTILS_
  54. #include <SEUtils.h>
  55. #endif
  56.  
  57. #ifndef _SHPRPACC_
  58. #include "ShPrpAcc.h"
  59. #endif
  60.  
  61. #ifndef _SHLEVTHD_
  62. #include "ShlEvtHd.h"
  63. #endif
  64.  
  65. #ifndef _USERSRCM_
  66. #include <UseRsrcM.h>
  67. #endif
  68.  
  69. #ifndef _RLSHELL_
  70. #include "RlShell.h"
  71. #endif
  72.  
  73. #ifndef SOM_ODContainer_xh
  74. #include <ODCtr.xh>
  75. #endif
  76.  
  77. #ifndef _ODUTILS_
  78. #include <ODUtils.h>
  79. #endif
  80.  
  81. #ifndef _DOCUTILS_
  82. #include <DocUtils.h>
  83. #endif
  84.  
  85. #ifndef __ALIASES__
  86. #include <Aliases.h>
  87. #endif
  88.  
  89. #ifndef _PLFMFILE_
  90. #include <PlfmFile.h>
  91. #endif
  92.  
  93. #ifndef _ODDESUTL_
  94. #include <ODDesUtl.h>
  95. #endif
  96.  
  97. #ifndef SOM_ODDocument_xh
  98. #include <Document.xh>
  99. #endif
  100.  
  101. #ifndef SOM_ODNameResolver_xh
  102. #include <NamRslvr.xh>
  103. #endif
  104.  
  105. #ifndef SOM_ODWindowState_xh
  106. #include <WinStat.xh>
  107. #endif
  108.  
  109. #ifndef SOM_ODWindow_xh
  110. #include <Window.xh>
  111. #endif
  112.  
  113. #ifndef SOM_ODMessageInterface_xh
  114. #include <MssgIntf.xh>
  115. #endif
  116.  
  117. #ifndef SOM_ODDispatcher_xh
  118. #include <Disptch.xh>
  119. #endif
  120.  
  121. #ifndef SOM_ODWindowIterator_xh
  122. #include <WinIter.xh>
  123. #endif
  124.  
  125. #ifndef SOM_ODOSLToken_xh
  126. #include <ODOSLTkn.xh>
  127. #endif
  128.  
  129. #ifndef SOM_ODAppleEvent_xh
  130. #include <ODAplEvt.xh>
  131. #endif
  132.  
  133. #ifndef __ASREGISTRY__
  134. #include <ASRegistry.h>
  135. #endif
  136.  
  137. #ifndef __AEUserTermTypes__
  138. #include <AEUserTermTypes.h>
  139. #endif
  140.  
  141. #ifndef __APPLEEVENTS__
  142. #include <AppleEvents.h>
  143. #endif
  144.  
  145. #ifndef SOM_Module_OpenDoc_ODRegistry_defined
  146. #include "ODRgstry.xh"
  147. #endif
  148.  
  149. #ifndef __RESOURCES__
  150. #include <Resources.h>
  151. #endif
  152.  
  153. #ifndef _ODDEBUG_
  154. #include "ODDebug.h"
  155. #endif
  156.  
  157. #ifndef _TEMPOBJ_
  158. #include "TempObj.h"
  159. #endif
  160.  
  161. #ifndef SOM_Module_OpenDoc_StdDefs_defined
  162. #include <StdDefs.xh>
  163. #endif
  164.  
  165. #pragma segment ShellEvt
  166.  
  167. //==============================================================================
  168. // Constants
  169. //==============================================================================
  170.  
  171. #define STATICBUILD
  172.  
  173. const DescType kShellPropAccessor         = 0x73706163;    // 'spac';
  174. const DescType kShellSelfPropAccessor    = 0x7368656C;    // 'shel';
  175.  
  176. const DescType kShellEventHandler = 'shev';
  177.  
  178. //==============================================================================
  179. // Function Prototypes
  180. //==============================================================================
  181.  
  182. //void    CreateUniqueTmpFolderForFile(ODFileSpec* result, Str63 fileName);
  183.  
  184. #define HANDLER_PARAMS                                                     \
  185.     ODPart* thePart,                                                     \
  186.     ODAppleEvent* message,                                             \
  187.      ODAppleEvent* reply,                                                 \
  188.     ODSLong handlerRefcon
  189.  
  190. // pascal ODError HandleClone(HANDLER_PARAMS);
  191. pascal ODError HandleClose(HANDLER_PARAMS);
  192. // pascal ODError HandleCountEl(HANDLER_PARAMS);
  193. // pascal ODError HandleMake(HANDLER_PARAMS);
  194. // pascal ODError HandleDelete(HANDLER_PARAMS);
  195. // pascal ODError HandleDoExist(HANDLER_PARAMS);
  196. // pascal ODError HandleGetClsInfo(HANDLER_PARAMS);
  197. // pascal ODError HandleGetData(HANDLER_PARAMS);
  198. // pascal ODError HandleGetDataSz(HANDLER_PARAMS);
  199. // pascal ODError HandleGetEvnInfo(HANDLER_PARAMS);
  200. // pascal ODError HandleMove(HANDLER_PARAMS);
  201. // pascal ODError HandleOpen(HANDLER_PARAMS);
  202. // pascal ODError HandlePrint(HANDLER_PARAMS);
  203. pascal ODError HandleSave(HANDLER_PARAMS);
  204. // pascal ODError HandleSetData(HANDLER_PARAMS);
  205. pascal ODError HandleODActivate(HANDLER_PARAMS);
  206.  
  207. pascal ODError HandleGetAETE(HANDLER_PARAMS);
  208.  
  209. #undef HANDLER_PARAMS
  210.                 
  211. pascal ODError GetFileFromNULL(    ODPart*                part,
  212.                                 DescType            desiredClass,
  213.                                 ODOSLToken*            container,
  214.                                 DescType            containerClass,
  215.                                 DescType            form,
  216.                                 ODDesc*                selectionData,
  217.                                 ODOSLToken*            value,
  218.                                 ODSLong                refCon);
  219.  
  220.  
  221. ShellEventHandler* GetHandlerFromAEVT(AppleEvent* theAppleEvent,
  222.         RealShell* self);
  223. void GetDirectParam(RealShell* self, AppleEvent* theAppleEvent,
  224.         AEDesc* evtDp);
  225.  
  226. //==============================================================================
  227. // RealShell
  228. //==============================================================================
  229.  
  230. //-------------------------------------------------------------------------------------
  231. // Apple Event Initialization
  232. //-------------------------------------------------------------------------------------
  233.  
  234.  
  235. void RealShell::InitAE()
  236. {
  237.     Environment* ev = fEV;
  238.  
  239.     ShellSI* shellSemtInterface = new ShellSI;
  240.     THROW_IF_NULL(shellSemtInterface);
  241.     fSIHelper = new SIHelper;
  242.     fSIHelper->InitSIHelper(fSession, shellSemtInterface);
  243.     shellSemtInterface->InitCPlusSemanticInterface(ev, kODAppShell, fSIHelper,
  244.                                                 fSession);
  245.     fSession->SetShellSemtInterface(ev, shellSemtInterface);
  246.     shellSemtInterface->Release(ev); // SetShellSemtInterface acquires.
  247.  
  248.     ODObjectAccessorUPP newAccessor = 
  249.             NewODObjectAccessorProc( GetFileFromNULL );
  250.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallObjectAccessor( cFile, 
  251.                                         typeNull, newAccessor, (ODSLong)fSession );
  252.                                 
  253.     ODEventHandlerUPP newHandler = 
  254.             NewODEventHandlerProc( RealShell::HandleOpenAppEvent );
  255.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  256.                                 kAEOpenApplication,
  257.                                 newHandler,
  258.                                 (long)this);
  259.                                 
  260.     newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
  261.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  262.                                 kAEOpenDocuments,
  263.                                 newHandler,
  264.                                 (long)this);
  265.                                 
  266.     newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
  267.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  268.                                 kAEPrintDocuments,
  269.                                 newHandler ,
  270.                                 (long)this);
  271.                                 
  272.     newHandler = NewODEventHandlerProc( RealShell::HandleQuitEvent );
  273.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
  274.                                 kAEQuitApplication,
  275.                                 newHandler ,
  276.                                 (long)this);
  277.  
  278.     newHandler = NewODEventHandlerProc( RealShell::HandleLaunchFailedEvent );
  279.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
  280.                                 kCFMLaunchFailedEventClass,
  281.                                 kCFMLaunchFailedEventID,
  282.                                 newHandler ,
  283.                                 (long)this);
  284.  
  285.     newHandler = NewODEventHandlerProc( RealShell::HandleODActivate );
  286.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
  287.                                 kAEOpenDocSuite,
  288.                                 kODActivateEvent,
  289.                                 newHandler ,
  290.                                 (long)this);
  291.  
  292.     ODCoercionHandlerUPP fsSpecCoerceHdlr =
  293.             NewODDescCoercionHandlerProc( RealShell::CoerceToFSSpec );
  294.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler( typeAlias, typeFSS,
  295.             fsSpecCoerceHdlr, (long)this, kODTrue );
  296.                                 
  297. //    this->InstallObjectAccessors(shellSemtInterface);
  298.     
  299. /*
  300. ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler(typeChar, typeFSS,
  301.                                 (XMPCoercionHandler)Pathname2FSSpec, kNoRefCon,
  302.                                 kFromTypeIsNotDesc );
  303. */
  304.  
  305.     ODEventHandlerUPP eventHandlerUPP;
  306.     
  307. #ifdef TO_BE_DELETED
  308.     eventHandlerUPP = NewODEventHandlerProc(HandleClone);
  309.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClone,
  310.             eventHandlerUPP, (ODSLong)this);
  311. #endif /* TO_BE_DELETED */
  312.     
  313.     eventHandlerUPP = NewODEventHandlerProc(HandleClose);
  314.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClose,
  315.             eventHandlerUPP, (ODSLong)this);
  316.     
  317. #ifdef TO_BE_DELETED
  318.     eventHandlerUPP = NewODEventHandlerProc(HandleCountEl);
  319.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECountElements,
  320.             eventHandlerUPP, (ODSLong)this);
  321.  
  322.     eventHandlerUPP = NewODEventHandlerProc(HandleMake);
  323.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECreateElement,
  324.             eventHandlerUPP, (ODSLong)this);
  325.     
  326.     eventHandlerUPP = NewODEventHandlerProc(HandleDelete);
  327.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDelete,
  328.             eventHandlerUPP, (ODSLong)this);
  329.         
  330.     eventHandlerUPP = NewODEventHandlerProc(HandleDoExist);
  331.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
  332.             eventHandlerUPP, (ODSLong)this);
  333.         
  334.     eventHandlerUPP = NewODEventHandlerProc(HandleGetClsInfo);
  335.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetClassInfo,
  336.             eventHandlerUPP, (ODSLong)this);
  337.         
  338.     eventHandlerUPP = NewODEventHandlerProc(HandleGetData);
  339.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetData,
  340.             eventHandlerUPP, (ODSLong)this);
  341.         
  342.     eventHandlerUPP = NewODEventHandlerProc(HandleGetDataSz);
  343.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetDataSize,
  344.             eventHandlerUPP, (ODSLong)this);
  345.         
  346.     eventHandlerUPP = NewODEventHandlerProc(HandleGetEvnInfo);
  347.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetEventInfo,
  348.             eventHandlerUPP, (ODSLong)this);
  349.         
  350.     eventHandlerUPP = NewODEventHandlerProc(HandleMove);
  351.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEMove,
  352.             eventHandlerUPP, (ODSLong)this);
  353.         
  354.     eventHandlerUPP = NewODEventHandlerProc(HandleOpen);
  355.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEOpen,
  356.             eventHandlerUPP, (ODSLong)this);
  357.         
  358.     eventHandlerUPP = NewODEventHandlerProc(HandlePrint);
  359.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEPrint,
  360.             eventHandlerUPP, (ODSLong)this);
  361. #endif /* TO_BE_DELETED */
  362.         
  363.     eventHandlerUPP = NewODEventHandlerProc(HandleSave);
  364.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESave,
  365.             eventHandlerUPP, (ODSLong)this);
  366.         
  367. #ifdef TO_BE_DELETED
  368.     eventHandlerUPP = NewODEventHandlerProc(HandleSetData);
  369.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESetData,
  370.             eventHandlerUPP, (ODSLong)this);
  371. #endif /* TO_BE_DELETED */
  372.  
  373. //#ifndef STATICBUILD
  374.     // Just let AS get the resource directly if not ASLM.  In fact, we
  375.     // probably don't need this even in that case.
  376.     eventHandlerUPP = NewODEventHandlerProc(HandleGetAETE);
  377.     ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAEOpenDocSuite, kGetAETE,
  378.                                                 eventHandlerUPP,
  379.                                                 (ODSLong)this);
  380. //#endif /* STATICBUILD */
  381.  
  382. }
  383.  
  384.  
  385. void RealShell::HandleHighLevelEvent(ODEventData* event)
  386. {
  387.     Environment* ev = fEV;
  388.     ProcessSerialNumber myPSN,frontPSN;
  389.     ODBoolean active;
  390.     (void)GetCurrentProcess(&myPSN);
  391.     (void)GetFrontProcess(&frontPSN);
  392.     (void)SameProcess(&myPSN,&frontPSN,&active);
  393.     if (active)
  394.         this->UpdateMenus();
  395.  
  396.     if ( ((AEEventClass) event->message == 'aevt') && (*(AEEventID *) &(event->where) == 'odoc') )
  397.     {
  398.         // If the open document event was sent by the edition manager, the modifiers field
  399.         // of the event will be garbage.  This can cause AEProcessAppleEvent to return an error
  400.         // instead of calling one of our event handlers.
  401.         // We work around this by clearing the modifiers field.  Note that clearing the field
  402.         // is not correct if the event is larger than 64K; we take the chance that an 'odoc'
  403.         // event won't be this large. [cc 7/19/95] [Radar #1261856]
  404.         event->modifiers = 0;
  405.     }
  406.  
  407.     ODBoolean succeeded = fSession->GetMessageInterface(ev)->ProcessSemanticEvent(ev, event);
  408. }
  409.  
  410.  
  411. //-------------------------------------------------------------------------------------
  412. // Handling 'oapp' Events
  413. //-------------------------------------------------------------------------------------
  414.  
  415.  
  416. pascal ODError RealShell::HandleOpenAppEvent(ODPart* part,
  417.                                         ODAppleEvent* message,
  418.                                         ODAppleEvent* reply,
  419.                                         long refCon)
  420. {
  421.     /*    Called when a stub application is starting up the OpenDoc shell
  422.         at launch time -- e.g. CyberDog. */
  423.         
  424. ODUnused(part);
  425. ODUnused(message);
  426. ODUnused(reply);
  427.  
  428.     RealShell*    self = (RealShell*)refCon;
  429.     Environment* ev = self->fEV;
  430.     ODError    error = noErr;
  431.  
  432.     TRY
  433.  
  434.         // Determine location (FSSpec) of current app:
  435.         ProcessInfoRec info;
  436.         FSSpec appLoc;
  437.         self->GetCurrentProcessInfo(&info,NULL,&appLoc);
  438.         
  439.         TempPlatformFile file = new PlatformFile;
  440.         file->Specify(&appLoc);
  441.         self->OpenFile(file,kODTrue);    // Force it to open APPL
  442.     
  443.     CATCH_ALL
  444.         error = ErrorCode();
  445.         self->GetSession()->GetDispatcher(ev)->Exit(ev);
  446.         self->SetAEError(error);
  447.     ENDTRY
  448.  
  449.     return error;
  450. }
  451.  
  452.  
  453. //-------------------------------------------------------------------------------------
  454. // Handling 'odoc' and 'pdoc' Events
  455. //-------------------------------------------------------------------------------------
  456.  
  457.  
  458. void RealShell::FakePrintMenuEvent()
  459. {
  460.     Environment* ev = fEV;
  461.     ODDispatcher* dispatcher = this->GetSession()->GetDispatcher(ev);
  462.     
  463.     ODMenuID menu;
  464.     ODMenuItemID menuItem;
  465.     TempODMenuBar baseMenuBar = this->fWindowState->AcquireBaseMenuBar(ev);
  466.     baseMenuBar->GetMenuAndItem(ev, kODCommandPrint, &menu, &menuItem );
  467.     
  468.     ODEventData event;
  469.     event.message = (menu<<16) | menuItem;
  470.     event.what = kODEvtMenu;
  471.     // zero the rest of the fields
  472.     WASSERT( sizeof(Point) == sizeof(long) );    // this is gross but
  473.     *(long*)&event.where = 0L;
  474.     event.when = 0L;
  475.     event.modifiers = 0;
  476.     dispatcher->Dispatch(ev, &event);
  477. }
  478.  
  479.  
  480. pascal ODError RealShell::HandleOpenPrintDocsEvent(    ODPart* part,
  481.                                             ODAppleEvent* message,
  482.                                             ODAppleEvent* reply,
  483.                                             long refCon)
  484. {
  485. ODUnused(part);
  486. ODUnused(reply);
  487.  
  488.     RealShell*    self = (RealShell*)refCon;
  489.     Environment* ev = self->fEV;
  490.     ODSession* session = self->GetSession();
  491.     ODVolatile(session);
  492.     
  493.     long        itemsInList;
  494.     ODError    error = noErr;
  495.     AppleEvent    realMessage;
  496.     DescType eventID;
  497.     DescType ignoreType;
  498.     Size ignoreActual;
  499.  
  500.     TRY
  501.     
  502.     // get list of documents
  503.     realMessage.dataHandle = kODNULL;
  504.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  505.     TempAEDescStruct docList;
  506.     THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyDirectObject, typeAEList,
  507.             &docList));
  508.     THROW_IF_ERROR( AEGetAttributePtr( &realMessage, keyEventIDAttr, typeType,
  509.             &ignoreType, &eventID, sizeof(eventID), &ignoreActual ));
  510.     ODBoolean isPrint = eventID == kAEPrintDocuments;
  511.     if (MissingParams(&realMessage))
  512.         THROW( errAEParamMissed );
  513.     
  514.     // Iterate through all documents and open them:
  515.     THROW_IF_ERROR( AECountItems(&docList, &itemsInList ));
  516.     for (ODSLong index = 1; index <= itemsInList; index++) {
  517.         
  518.         ODFileSpec fileSpec;
  519.         AEKeyword key,type;
  520.         Size size;
  521.         OSErr err = AEGetNthPtr(&docList, index, typeFSS, &key,&type,
  522.                                 &fileSpec,sizeof(fileSpec),&size);
  523.         if (err == errAECoercionFail)
  524.         {
  525.             // We'll handle tokens here...
  526.             TempAEDescStruct coerceDesc, fileDesc;
  527.             ODOSLToken* tmpWrapper = new ODOSLToken();
  528.             THROW_IF_NULL(tmpWrapper);
  529.             TempODObject tempObj(tmpWrapper);
  530.             tmpWrapper->InitODOSLToken(ev);
  531.  
  532.             GetDirectParam(self, &realMessage, &coerceDesc);
  533.             THROW_IF_ERROR( AEDescToODDesc(&coerceDesc, tmpWrapper ) );
  534.             ODDesc* myToken;
  535.             ODNameResolver*    resolver = session->GetNameResolver(ev);
  536.             myToken = resolver->GetUserToken(ev, tmpWrapper);
  537.             AEDisposeDesc( &coerceDesc );
  538.             THROW_IF_ERROR( ODDescToAEDesc(myToken, &coerceDesc) );
  539.             THROW_IF_ERROR( AECoerceDesc(&coerceDesc, typeFSS, &fileDesc) );
  540.             ODBlockMove(*fileDesc.dataHandle,&fileSpec,sizeof(fileSpec));
  541.             err = noErr;
  542.         }
  543.         
  544.         // If printing, open each document in this process, then print and close it.
  545.         // If this is an application process (CyberDog), open all documents in this process.
  546.         // If this is a normal document process, open the first document in this process
  547.         //        if no document is open, and open the rest in separate processes.
  548.         if( !err ) {
  549.             TempPlatformFile file = new PlatformFile();
  550.             file->Specify(&fileSpec);
  551.             if( isPrint ) {
  552.                 ODDocument *doc = self->OpenFile(file);
  553.                 if( doc ) {
  554.                     self->FakePrintMenuEvent();
  555.                     if (ODCloseDocument(ev, session, doc))
  556.                         session->GetDispatcher(ev)->Exit(ev);
  557.                 }
  558.             } else if( self->fAPPLProcess || (index==1 && ODGetFirstOpenDocument(ev, session)==kODNULL) )
  559.                 self->OpenFile(file);
  560.             else
  561.                 self->OpenAnotherFile(file);
  562.         }
  563.     }
  564.  
  565.     CATCH_ALL
  566.         error = ErrorCode();
  567.         session->GetDispatcher(ev)->Exit(ev);
  568.         self->SetAEError(error);
  569.     ENDTRY
  570.     ODDisposeAppleEvent( &realMessage );
  571.  
  572.     return error;
  573. }    // HandleOpenPrintDocsEvent()
  574.  
  575. ////////////////////////////////////////////////////////////////////////////////
  576. //
  577. //        HandleQuitEvent
  578. //
  579. ////////////////////////////////////////////////////////////////////////////////
  580.  
  581. pascal ODError RealShell::HandleQuitEvent(    ODPart* /*part*/,
  582.                                         ODAppleEvent* message,
  583.                                         ODAppleEvent* /*reply*/,
  584.                                         long refCon)
  585. {
  586.     ODError            error        = noErr;
  587.     RealShell*        self        = (RealShell*)refCon;
  588.     Environment*    ev            = self->fEV;
  589.     ODSession*        session        = self->GetSession();
  590.     ODDescType        yesNoAsk    = kAEAsk;
  591.     ODDescType        theType;
  592.     ODSLong            theSize;
  593.     AEDesc            event;
  594.  
  595.     TRY
  596.         ODDescToAEDesc(message, &event);
  597.         error = AEGetParamPtr(&event, keyAESaveOptions, typeEnumerated, &theType, &yesNoAsk, sizeof(yesNoAsk), &theSize);
  598.         // we don't throw because we're quitting and don't care if there's an error
  599.         error = noErr;  // to keep it from being returned
  600.             
  601.         // In OpenDoc the 'QUIT' event means CloseDocument.
  602.         
  603.         RealShell* self = (RealShell*)refCon;
  604.         ODDocument* document = kODNULL;
  605.         while ((document = ODGetFirstOpenDocument(ev, session)) != kODNULL)
  606.         {
  607.             if (!self->CloseDocument(document, yesNoAsk))
  608.                 THROW(userCanceledErr);
  609.         }
  610.         session->GetDispatcher(ev)->Exit(ev);
  611.     CATCH_ALL
  612.         error = ErrorCode();
  613.     ENDTRY
  614.  
  615.     return error;
  616. }    // HandleQuitEvent()
  617.  
  618.  
  619. ////////////////////////////////////////////////////////////////////////////////
  620. //
  621. //        HandleLaunchFailedEvent
  622. //
  623. ////////////////////////////////////////////////////////////////////////////////
  624.  
  625. pascal ODError RealShell::HandleLaunchFailedEvent(    ODPart* part,
  626.                                         ODAppleEvent* message,
  627.                                         ODAppleEvent* reply,
  628.                                         long refCon)
  629. {
  630.     ODUnused(part);
  631.     ODUnused(reply);
  632.     
  633.     long launchErr;
  634.     ProcessSerialNumber psn;
  635.     Str255 appName, libName;
  636.     AppleEvent realMessage;
  637.  
  638.     THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
  639.     
  640.     //<eeh> any chance this can throw???
  641.     GetLaunchFailedParams(&realMessage, launchErr,&psn,appName,libName);
  642.     ODDisposeAppleEvent(&realMessage);
  643.  
  644.     RealShell *shell = (RealShell*)refCon;
  645.     shell->LaunchFailed(launchErr,psn,appName,libName);
  646.     return noErr;
  647. }
  648.  
  649.  
  650. void
  651. RealShell::LaunchFailed( ODSLong launchErr, const ProcessSerialNumber &psn,
  652.                          Str255 appName, Str255 libName )
  653. {
  654.     if( psn.lowLongOfPSN != kNoProcess ) {
  655.         Boolean result;
  656.         if( SameProcess(&psn,&fLastNewDocPSN,&result) == noErr && result != kODFalse ) {
  657.             // This is a new document we just created & launched; better delete it.
  658.             OSErr err= FSpDelete(&fLastNewDocSpec);
  659.             if( err )
  660.                 WARN("Error %d trying to delete new document",err);
  661.             fLastNewDocPSN.lowLongOfPSN = kNoProcess;
  662.             fLastNewDocSpec.name[0] = '\0';
  663.         }
  664.     }
  665.     
  666.     this->ExceptionAlert(launchErr,kODNULL);
  667. }
  668.  
  669.  
  670. ////////////////////////////////////////////////////////////////////////////////
  671. //
  672. //        HandleODActivateEvent
  673. //
  674. ////////////////////////////////////////////////////////////////////////////////
  675.  
  676. pascal ODError RealShell::HandleODActivate( ODPart* thePart, ODAppleEvent* message,
  677.         ODAppleEvent* reply, ODSLong handlerRefcon )
  678. {
  679.     ODUnused(thePart);
  680.     ODUnused(reply);
  681.     
  682.     ODError result = noErr;
  683.  
  684.     RealShell*    self = (RealShell*)handlerRefcon;
  685.     
  686.     ODFileSpec    fileSpec;
  687.     AppleEvent    realMessage;
  688.     DescType    unused1;
  689.     Size        unused2;
  690.     ODBoolean    wasPrintEvent = kODFalse;
  691.     ODBoolean    notAlreadyOpen = kODFalse;
  692.     boolean        quitAfterPrint = kODFalse;
  693.     TempODDraft draftToBringForward = kODNULL;
  694.  
  695.     realMessage.dataHandle = NULL;
  696.     TRY
  697.         THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
  698.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyDirectObject, typeFSS, 
  699.                 &unused1, (Ptr)&fileSpec, sizeof(fileSpec), &unused2));
  700.         DescType spawningEventID;
  701.         OSErr err = AEGetParamPtr(&realMessage, keyODActivateEventCause,
  702.                 typeType,  &unused1, (Ptr)&spawningEventID,
  703.                 sizeof(spawningEventID), &unused2 );
  704.         if ( err == noErr )
  705.             wasPrintEvent = spawningEventID == kAEPrintDocuments;
  706.         // else drop the error: id not present is ok.
  707.  
  708.         err = AEGetParamPtr( &realMessage, keyODRefnumFromResource,
  709.                 typeBoolean,  &unused1, (Ptr)&quitAfterPrint,
  710.                 sizeof(quitAfterPrint), &unused2 );
  711.         if ( err != noErr )
  712.             quitAfterPrint = kODFalse;
  713.  
  714.     CATCH_ALL
  715.         result = ErrorCode();
  716.     ENDTRY
  717.     ODDisposeAppleEvent(&realMessage);
  718.  
  719.     Environment* ev = self->fEV;
  720.     ODSession* session = self->GetSession();
  721.  
  722.     if ( result == noErr )
  723.     {
  724.         ODULong refNumCount, i;
  725.         ODSShort* refNums = kODNULL;
  726.         GetLocalPaths(&fileSpec, kDataFork, &refNumCount, &refNums);
  727.     
  728.         if (refNumCount != 0)
  729.         {
  730.             for ( i=0; i<refNumCount; ++i)
  731.             {
  732.                 ODDocument* doc = ODGetOpenDocumentFromRefNum(ev,
  733.                         session, refNums[i]);
  734.                 if ( doc != kODNULL )
  735.                 {
  736.                     draftToBringForward = ODGetTempDraftFromOpenDocument( ev,
  737.                             session, doc );
  738.                             
  739.                     if (draftToBringForward)
  740.                         draftToBringForward->Acquire(ev); // balance destructor of TempRef
  741.                     else
  742.                         draftToBringForward = 
  743.                             doc->AcquireDraft(ev,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
  744.                             
  745.                     break;        // exit for loop
  746.                 }
  747.             }
  748.         
  749.             if (refNums)
  750.                 DisposePtr((Ptr)refNums);
  751.         }
  752.         else        // *if* this process is supposed to handle this event at
  753.         {            // all, the ODActivate must have come because of a resource
  754.                     // fork.
  755.             short resRefNum = CurResFile();
  756.             if ( refNums != kODNULL )
  757.             {
  758.                 DisposePtr( (Ptr)refNums );
  759.                 refNums = kODNULL;
  760.             }
  761.             GetLocalPaths( &fileSpec, kResourceFork, &refNumCount, &refNums );
  762.             for ( i=0; i<refNumCount; ++i )
  763.             {
  764.                 if ( refNums[i] == resRefNum )    // it belongs in this process
  765.                 {
  766.                     TempPlatformFile file = new PlatformFile;
  767.                     file->Specify( &fileSpec );
  768.                     draftToBringForward = ODOpenFileDocument( ev, session, file,
  769.                         kODDPSharedWrite );
  770.  
  771.                     self->InstallShellPlugIns(draftToBringForward);
  772.                     notAlreadyOpen = kODTrue;
  773.                     break;
  774.                 }
  775.             }
  776.             if( refNums != kODNULL )
  777.                 DisposePtr( (Ptr)refNums );
  778.         }
  779.     }
  780.     
  781.     if ( draftToBringForward != kODNULL )
  782.     {
  783.         ProcessSerialNumber psn;
  784.         GetCurrentProcess(&psn);
  785.         SetFrontProcess(&psn);
  786.  
  787.         ODOpenDraft( ev, session, draftToBringForward );
  788.         if ( notAlreadyOpen )
  789.         {
  790.             // the plugin may have patched these....
  791.             self->fDispatcher = session->GetDispatcher(ev);
  792.             self->fWindowState = session->GetWindowState(ev);
  793.         }
  794.         if ( wasPrintEvent )
  795.         {
  796.             self->FakePrintMenuEvent();
  797.             if ( quitAfterPrint )
  798.             {
  799.                 // need to release draft's refcount *before* calling
  800.                 // ODCloseDocument (or check with Tantek to see if
  801.                 // assertion in ODCloseDocument can be removed.
  802.                 ODDocument* doc = draftToBringForward->GetDocument(ev);
  803.                 draftToBringForward->Release(ev);
  804.                 draftToBringForward = kODNULL;    // prevent another release by the TempRef
  805.                 ODBoolean wasLastDoc = ODCloseDocument( ev, session, doc );
  806.                 WASSERT( !wasLastDoc ); 
  807.             }
  808.         }
  809.     }
  810.  
  811.     return result;        // usually should be eventNotHandled?
  812. }    // HandleODActivate
  813.  
  814.  
  815. ////////////////////////////////////////////////////////////////////////////////
  816. //
  817. //        CoerceToFSSpec
  818. //
  819. ////////////////////////////////////////////////////////////////////////////////
  820.  
  821.  
  822. pascal ODError RealShell::CoerceToFSSpec( ODPart* thePart, ODDesc* theAEDesc,
  823.         DescType toType, ODSLong handlerRefCon, ODDesc* result )
  824. {
  825.     ODUnused(thePart);
  826.     RealShell*    self = (RealShell*)handlerRefCon;
  827.  
  828.     if (self->fAlreadyInCoercion)
  829.         return errAECoercionFail;
  830.     else
  831.         self->fAlreadyInCoercion = kODTrue;
  832.     ODError    error = noErr;
  833.  
  834.     TRY
  835.         TempAEDescStruct    realInDesc;
  836.         THROW_IF_ERROR( ODDescToAEDesc(theAEDesc, &realInDesc));
  837.         if (realInDesc.descriptorType == typeAlias)
  838.         {
  839.             // use the built-in coercion first
  840.             TempAEDescStruct tmpResult;
  841.             error = AECoerceDesc( &realInDesc, toType, &tmpResult );
  842.     
  843.             if ( error == noErr )
  844.                 THROW_IF_ERROR( AEDescToODDesc( &tmpResult, result ));
  845.         }
  846.  
  847.     CATCH_ALL
  848.         error = ErrorCode();
  849.     ENDTRY
  850.  
  851.     self->fAlreadyInCoercion = kODFalse;
  852.     return error;
  853. }    // CoerceToFSSpec()
  854.  
  855. //----------------------------------------------------------------------------------------
  856. // RealShell::SetAEError 
  857. //----------------------------------------------------------------------------------------
  858.  
  859. void RealShell::SetAEError(ODError error)
  860. {
  861.     fErrorFromOpenEvents = error;
  862. }
  863.  
  864. //----------------------------------------------------------------------------------------
  865. // RealShell::GetAEError 
  866. //----------------------------------------------------------------------------------------
  867.  
  868. ODError RealShell::GetAEError()
  869. {
  870.     return fErrorFromOpenEvents;
  871. }
  872.  
  873. //==============================================================================
  874. // Functions
  875. //==============================================================================
  876.  
  877. //------------------------------------------------------------------------------
  878. // HandleGetAETE
  879. //------------------------------------------------------------------------------
  880.  
  881.  
  882. pascal ODError HandleGetAETE(ODPart*        thePart,
  883.                 ODAppleEvent*    theAppleEvent,
  884.                 ODAppleEvent*    reply,
  885.                 ODSLong    handlerRefcon)
  886. {
  887. ODUnused(thePart);
  888. ODUnused(handlerRefcon);    
  889.  
  890.     AEDesc        theAETE = NULL_DESCRIPTOR_DEFINITION;
  891.     DescType    returnedType;
  892.     ODSize        actualSize;
  893.     ODSLong        languageCode;
  894.     ODError        result;
  895.     ODError        error = noErr;
  896.     
  897.     AppleEvent realMessage, realReply;
  898.     realMessage.dataHandle = realReply.dataHandle = NULL;
  899.  
  900.     TRY
  901.         THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
  902.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  903.  
  904.         result = AEGetParamPtr(&realMessage, keyDirectObject, typeLongInteger,
  905.                                &returnedType, (Ptr)&languageCode, sizeof(languageCode),
  906.                                (Size *)&actualSize);
  907.         ODDisposeAppleEvent(&realMessage);
  908.         THROW_IF_ERROR(result);
  909.         
  910.         TRY
  911.             CUsingLibraryResources    ref;
  912.             
  913.             theAETE.dataHandle = Get1Resource(typeAETE, (short)languageCode);
  914.             if (theAETE.dataHandle)
  915.             {
  916.                 theAETE.descriptorType = typeAETE;
  917.                 result = AEPutParamDesc(&realReply, keyAEResult, &theAETE);
  918.                 ReleaseResource(theAETE.dataHandle);
  919.                 THROW_IF_ERROR(result);
  920.             }
  921.         CATCH_ALL
  922.             error = ErrorCode();
  923.         ENDTRY
  924.                         
  925.         THROW_IF_ERROR(error);
  926.         
  927.         THROW_IF_ERROR(AEDescToODDesc(&realReply, reply));
  928.     CATCH_ALL
  929.         error = ErrorCode();
  930.     ENDTRY
  931.     AEDisposeDesc(&realReply);
  932.  
  933.     return error;
  934. }    // HandleGetAETE()
  935.  
  936.  
  937. //------------------------------------------------------------------------------
  938. // GetFileFromNULL
  939. //------------------------------------------------------------------------------
  940.  
  941. pascal ODError GetFileFromNULL(    ODPart*                part,
  942.                                 DescType            desiredClass,
  943.                                 ODOSLToken*            container,
  944.                                 DescType            containerClass,
  945.                                 DescType            form,
  946.                                 ODDesc*                selectionData,
  947.                                 ODOSLToken*            value,
  948.                                 ODSLong                refCon)
  949. {
  950.     Environment*            ev = somGetGlobalEnvironment();
  951.     ODSession*                session = (ODSession*)refCon;
  952.     ODNameResolver*            resolver = session->GetNameResolver(ev);
  953.     ODError                    error = noErr;
  954.     AEDesc                    aeAlias, tmp;
  955.     char                    state;
  956.  
  957.     TRY
  958.         // get the selectionData and coerce it into an fsspec
  959.         THROW_IF_ERROR(ODDescToAEDesc(selectionData, &tmp));
  960.         TempAEDesc tmpDesc(&tmp);
  961.         state = HGetState(tmp.dataHandle);
  962.         HLock(tmp.dataHandle);
  963.         THROW_IF_ERROR(NewAliasMinimalFromFullPath(GetHandleSize(tmp.dataHandle),
  964.                 *tmp.dataHandle, "\p", "\p",
  965.                 (AliasHandle*)&aeAlias.dataHandle ));
  966.         HSetState(tmp.dataHandle, state);
  967.         aeAlias.descriptorType = typeAlias;
  968.         TempAEDesc tmpDesc2(&aeAlias);
  969.         UpdateUserToken(ev, resolver, value, &aeAlias);
  970.     CATCH_ALL
  971.         error = ErrorCode();
  972.     ENDTRY
  973.  
  974.     return error;
  975. }    //    GetFileFromNULL
  976.  
  977. //------------------------------------------------------------------------------
  978. // HandleClone
  979. //------------------------------------------------------------------------------
  980.  
  981. #ifdef TO_BE_DELETED
  982. pascal ODError HandleClone( ODPart* thePart, ODAppleEvent* theAppleEvent,
  983.         ODAppleEvent* reply, ODSLong handlerRefcon )
  984. {
  985.     ODUnused(thePart);
  986.  
  987.     ODError    error = noErr;
  988.  
  989.     AppleEvent realMessage, realReply;
  990.     THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
  991.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  992.  
  993.     TRY
  994.  
  995.         ShellEventHandler* handlerObj = GetHandlerFromAEVT( &realMessage,
  996.                 (RealShell*)handlerRefcon );
  997.     
  998.         AEDesc cloneLocation;
  999.         THROW_IF_ERROR( AEGetParamDesc( &realMessage, keyAEInsertHere, 
  1000.                 typeInsertionLoc, &cloneLocation ) );
  1001.     
  1002.         AEDesc replyDp;
  1003.         handlerObj->Clone( &cloneLocation, &replyDp );
  1004.         delete handlerObj;
  1005.     
  1006.         THROW_IF_ERROR( AEPutParamDesc( &realReply, keyDirectObject, &replyDp ) );
  1007.  
  1008.     CATCH_ALL
  1009.         error = ErrorCode();
  1010.     ENDTRY
  1011.  
  1012.     return error;
  1013. }    // HandleClone()
  1014. #endif /* TO_BE_DELETED */
  1015.  
  1016. //------------------------------------------------------------------------------
  1017. // HandleClose
  1018. //------------------------------------------------------------------------------
  1019.  
  1020. pascal ODError HandleClose( ODPart* thePart, ODAppleEvent* message,
  1021.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1022. {
  1023.     ODUnused(thePart);
  1024.     ODUnused(reply);
  1025.  
  1026.     AEDesc theFile;
  1027.     ODError    error = noErr;
  1028.  
  1029.     AppleEvent realMessage, realReply;
  1030.     // can't use TempAEDescs for these because they don't call
  1031.     // ODDisposeAppleEvent
  1032.     realMessage.dataHandle = realReply.dataHandle = NULL;
  1033.  
  1034.     TRY
  1035.         THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1036.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1037.         OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
  1038.         TempAEDesc tmpDesc(&theFile);
  1039.         ThrowIfNotAbsent(err);
  1040.     
  1041.         DescType saveOptions = kAEAsk, typeFound;
  1042.         Size actualSize;
  1043.         err = AEGetParamPtr(&realMessage, keyAESaveOptions, typeEnumeration,
  1044.                 &typeFound, (Ptr)&saveOptions, sizeof(saveOptions), &actualSize);
  1045.         ThrowIfNotAbsent(err);
  1046.     
  1047.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1048.                 (RealShell*)handlerRefcon);
  1049.         handlerObj->Close(&theFile, saveOptions);
  1050.         delete handlerObj;
  1051.  
  1052.     CATCH_ALL
  1053.         error = ErrorCode();
  1054.     ENDTRY
  1055.  
  1056.     ODDisposeAppleEvent(&realMessage);
  1057.     ODDisposeAppleEvent(&realReply);
  1058.     return error;
  1059. }
  1060.  
  1061. //------------------------------------------------------------------------------
  1062. // HandleCountEl
  1063. //------------------------------------------------------------------------------
  1064.  
  1065. #ifdef TO_BE_DELETED
  1066. pascal ODError HandleCountEl(ODPart* thePart, ODAppleEvent* message, ODAppleEvent* reply,
  1067.         ODSLong handlerRefcon)
  1068. {
  1069.     ODUnused(thePart);
  1070.  
  1071.     ODError    error = noErr;
  1072.  
  1073.     AppleEvent realMessage, realReply;
  1074.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1075.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1076.  
  1077.     TRY
  1078.  
  1079.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1080.                 (RealShell*)handlerRefcon);
  1081.     
  1082.         DescType elemClass, typeFound;
  1083.         Size actualSize;
  1084.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
  1085.                 &typeFound, (Ptr)&elemClass, sizeof(elemClass), &actualSize));
  1086.     
  1087.         AEDesc replyDp;
  1088.         handlerObj->CountElements(elemClass, &replyDp);
  1089.         delete handlerObj;
  1090.     
  1091.         THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
  1092.  
  1093.     CATCH_ALL
  1094.         error = ErrorCode();
  1095.     ENDTRY
  1096.  
  1097.     return error;
  1098. }
  1099. #endif /* TO_BE_DELETED */
  1100.  
  1101. //------------------------------------------------------------------------------
  1102. // HandleMake
  1103. //------------------------------------------------------------------------------
  1104.  
  1105. #ifdef TO_BE_DELETED
  1106. pascal ODError HandleMake(ODPart* thePart, ODAppleEvent* message,
  1107.         ODAppleEvent* reply, ODSLong handlerRefcon)
  1108. {
  1109.     ODUnused(thePart);
  1110.     ODUnused(handlerRefcon);
  1111.     ODUnused(reply);
  1112.  
  1113.     DescType newObjClass, typeFound;
  1114.     Size actualSize;
  1115.     AEDesc insertHere, newObjectName;
  1116.     OSErr err;
  1117.     ODError    error = noErr;
  1118.  
  1119.     AppleEvent realMessage, realReply;
  1120.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1121.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1122.  
  1123.     TRY
  1124.     
  1125.         THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
  1126.                 &typeFound, (Ptr)&newObjClass, sizeof(newObjClass), &actualSize));
  1127.         THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEInsertHere,
  1128.                 typeInsertionLoc, &insertHere));
  1129.         err = AEGetParamDesc(&realMessage, 'type', typeChar, &newObjectName);
  1130.         if (err && (err != errAEDescNotFound))
  1131.             THROW(err);
  1132.     
  1133.         err = AEGetParamDesc(&realMessage, 'subj', typeChar, &newObjectName);
  1134.         if (err && (err != errAEDescNotFound))
  1135.             THROW(err);
  1136.  
  1137.     CATCH_ALL
  1138.         error = ErrorCode();
  1139.     ENDTRY
  1140.  
  1141.     return error;
  1142. }
  1143. #endif /* TO_BE_DELETED */
  1144.  
  1145. //------------------------------------------------------------------------------
  1146. // HandleDelete
  1147. //------------------------------------------------------------------------------
  1148.  
  1149. #ifdef TO_BE_DELETED
  1150. pascal ODError HandleDelete( ODPart* thePart, ODAppleEvent* message,
  1151.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1152. {
  1153.     ODUnused(thePart);
  1154.     ODUnused(reply);
  1155.     ODError error = noErr;
  1156.  
  1157.     AppleEvent realMessage, realReply;
  1158.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1159.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1160.  
  1161.     TRY
  1162.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1163.                 (RealShell*)handlerRefcon);
  1164.         handlerObj->Delete();
  1165.         delete handlerObj;
  1166.  
  1167.     CATCH_ALL
  1168.         error = ErrorCode();
  1169.     ENDTRY
  1170.  
  1171.     return error;
  1172. }
  1173. #endif /* TO_BE_DELETED */
  1174.  
  1175. //------------------------------------------------------------------------------
  1176. // HandleDoExist
  1177. //------------------------------------------------------------------------------
  1178.  
  1179. #ifdef TO_BE_DELETED
  1180. pascal ODError HandleDoExist( ODPart* thePart, ODAppleEvent* message,
  1181.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1182. {
  1183.     ODUnused(thePart);
  1184.     ODUnused(message);
  1185.     ODUnused(reply);
  1186.     ODUnused(handlerRefcon);
  1187.     return errAEEventNotHandled;
  1188. }
  1189. #endif /* TO_BE_DELETED */
  1190.  
  1191. //------------------------------------------------------------------------------
  1192. // HandleGetClsInfo
  1193. //------------------------------------------------------------------------------
  1194.  
  1195. #ifdef TO_BE_DELETED
  1196. pascal ODError HandleGetClsInfo( ODPart* thePart, ODAppleEvent* message,
  1197.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1198. {
  1199.     ODUnused(thePart);
  1200.     ODUnused(message);
  1201.     ODUnused(reply);
  1202.     ODUnused(handlerRefcon);
  1203.     return errAEEventNotHandled;
  1204. }
  1205. #endif /* TO_BE_DELETED */
  1206.  
  1207. //------------------------------------------------------------------------------
  1208. // HandleGetData
  1209. //------------------------------------------------------------------------------
  1210.  
  1211. #ifdef TO_BE_DELETED
  1212. pascal ODError HandleGetData( ODPart* thePart, ODAppleEvent* message,
  1213.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1214. {
  1215.     ODUnused(thePart);
  1216.     ODUnused(handlerRefcon);
  1217.  
  1218.     AEDesc evtDp;
  1219.     AEDesc replyDp;
  1220.     ODError    error = noErr;
  1221.  
  1222.     RealShell* self = (RealShell*)handlerRefcon;
  1223.     Environment* ev = somGetGlobalEnvironment();
  1224.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1225.  
  1226.     AppleEvent realMessage, realReply;
  1227.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1228.     THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1229.  
  1230. //    ODOSLToken* tmpWrapper = kODNULL;
  1231.     TRY
  1232.  
  1233.         replyDp.dataHandle = NULL;
  1234.         evtDp.dataHandle = NULL;
  1235.     
  1236.         GetDirectParam((RealShell*)handlerRefcon, &realMessage,
  1237.                 &evtDp);
  1238.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1239.         THROW_IF_NULL(tmpWrapper);
  1240.         TempODObject tempObj(tmpWrapper);
  1241.         tmpWrapper->InitODOSLToken(ev);
  1242.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1243.  
  1244.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1245.             THROW(errAEEventNotHandled);
  1246.         ODDesc* myTokenODDesc;
  1247.         myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1248.         AEDesc myToken;
  1249.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
  1250. //        ODDeleteObject(myTokenODDesc);
  1251.         
  1252.         switch( myToken.descriptorType )
  1253.         {
  1254.             case kShellSelfPropAccessor :
  1255.             case kShellPropAccessor :
  1256.                 ShellPropAccessor* accessorObj =
  1257.                         FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
  1258.                         ShellPropAccessor*);
  1259.                 accessorObj->GetPropertyData(&replyDp);
  1260.                 delete accessorObj;
  1261.                 break;
  1262.     
  1263.             default :
  1264.                 THROW(errAEEventNotHandled);
  1265.                 break;
  1266.         }
  1267.  
  1268.         THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
  1269.         THROW_IF_ERROR( AEDescToODDesc(&realReply, reply ) );
  1270.         
  1271.         AEDisposeDesc(&evtDp);
  1272.         AEDisposeDesc(&replyDp);
  1273.  
  1274.     CATCH_ALL
  1275.         error = ErrorCode();
  1276.     ENDTRY
  1277.  
  1278. //    ODDeleteObject(tmpWrapper);
  1279.     return error;
  1280. }    // HandleGetData();
  1281. #endif /* TO_BE_DELETED */
  1282.  
  1283.  
  1284. //------------------------------------------------------------------------------
  1285. // HandleGetDataSz
  1286. //------------------------------------------------------------------------------
  1287.  
  1288. #ifdef TO_BE_DELETED
  1289. pascal ODError HandleGetDataSz( ODPart* thePart, ODAppleEvent* message,
  1290.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1291. {
  1292.     ODUnused(thePart);
  1293.     ODUnused(message);
  1294.     ODUnused(reply);
  1295.     ODUnused(handlerRefcon);
  1296.     return errAEEventNotHandled;
  1297. }
  1298. #endif /* TO_BE_DELETED */
  1299.  
  1300. //------------------------------------------------------------------------------
  1301. // HandleGetEvnInfo
  1302. //------------------------------------------------------------------------------
  1303.  
  1304. #ifdef TO_BE_DELETED
  1305. pascal ODError HandleGetEvnInfo( ODPart* thePart, ODAppleEvent* message,
  1306.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1307. {
  1308.     ODUnused(thePart);
  1309.     ODUnused(message);
  1310.     ODUnused(reply);
  1311.     ODUnused(handlerRefcon);
  1312.     return errAEEventNotHandled;
  1313. }
  1314. #endif /* TO_BE_DELETED */
  1315.  
  1316. //------------------------------------------------------------------------------
  1317. // HandleMove
  1318. //------------------------------------------------------------------------------
  1319.  
  1320. #ifdef TO_BE_DELETED
  1321. pascal ODError HandleMove( ODPart* thePart, ODAppleEvent* message,
  1322.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1323. {
  1324.     ODUnused(thePart);
  1325.     ODUnused(message);
  1326.     ODUnused(reply);
  1327.     ODUnused(handlerRefcon);
  1328.     return errAEEventNotHandled;
  1329. }
  1330. #endif /* TO_BE_DELETED */
  1331.  
  1332. //------------------------------------------------------------------------------
  1333. // HandleOpen
  1334. //------------------------------------------------------------------------------
  1335.  
  1336. #ifdef TO_BE_DELETED
  1337. pascal ODError HandleOpen( ODPart* thePart, ODAppleEvent* message,
  1338.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1339. {
  1340.     ODUnused(thePart);
  1341.     ODUnused(message);
  1342.     ODUnused(reply);
  1343.     ODUnused(handlerRefcon);
  1344.     return errAEEventNotHandled;
  1345. }
  1346. #endif /* TO_BE_DELETED */
  1347.  
  1348. //------------------------------------------------------------------------------
  1349. // HandlePrint
  1350. //------------------------------------------------------------------------------
  1351.  
  1352. #ifdef TO_BE_DELETED
  1353. pascal ODError HandlePrint( ODPart* thePart, ODAppleEvent* message,
  1354.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1355. {
  1356.     ODUnused(thePart);
  1357.     ODUnused(message);
  1358.     ODUnused(reply);
  1359.     ODUnused(handlerRefcon);
  1360.     return errAEEventNotHandled;
  1361. }
  1362. #endif /* TO_BE_DELETED */
  1363.  
  1364. //------------------------------------------------------------------------------
  1365. // HandleSave
  1366. //------------------------------------------------------------------------------
  1367.  
  1368. pascal ODError HandleSave( ODPart* thePart, ODAppleEvent* message,
  1369.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1370. {
  1371.     ODUnused(thePart);
  1372.     ODUnused(reply);
  1373.     AEDesc theFile;
  1374.     ODError    error = noErr;
  1375.  
  1376.     AppleEvent realMessage, realReply;
  1377.     realMessage.dataHandle = realReply.dataHandle = NULL;
  1378.  
  1379.     TRY
  1380.         THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1381.         THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1382.  
  1383.         OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
  1384.         ThrowIfNotAbsent(err);
  1385.     
  1386.     //    keyAEFileType
  1387.     
  1388.         ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
  1389.                 (RealShell*)handlerRefcon);
  1390.         handlerObj->Save(&theFile /*,&theFileType*/);
  1391.         delete handlerObj;
  1392.  
  1393.     CATCH_ALL
  1394.         error = ErrorCode();
  1395.     ENDTRY
  1396.  
  1397.     ODDisposeAppleEvent(&realMessage);
  1398.     ODDisposeAppleEvent(&realReply);
  1399.     return error;
  1400. }    // HandleSave()
  1401.  
  1402. //------------------------------------------------------------------------------
  1403. // HandleSetData
  1404. //------------------------------------------------------------------------------
  1405.  
  1406. #ifdef TO_BE_DELETED
  1407. pascal ODError HandleSetData( ODPart* thePart, ODAppleEvent* message,
  1408.         ODAppleEvent* reply, ODSLong handlerRefcon )
  1409. {
  1410.     ODUnused(thePart);
  1411.     ODUnused(reply);
  1412.  
  1413.     AEDesc dataDesc;
  1414.     ODError    error = noErr;
  1415.  
  1416.     RealShell* self = (RealShell*)handlerRefcon;
  1417.     Environment* ev = somGetGlobalEnvironment();
  1418.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1419.  
  1420.     AppleEvent realMessage, realReply;
  1421.     THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
  1422. //    THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
  1423.  
  1424. //    ODOSLToken* tmpWrapper = kODNULL;
  1425.     TRY
  1426.  
  1427.         dataDesc.dataHandle = NULL;
  1428.         THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEData, typeWildCard,
  1429.                 &dataDesc));
  1430.     
  1431.         AEDesc evtDp;
  1432.         GetDirectParam( self, &realMessage, &evtDp );
  1433.         AEDisposeDesc( &realMessage );
  1434.     
  1435.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1436.         THROW_IF_NULL(tmpWrapper);
  1437.         TempODObject tempObj(tmpWrapper);
  1438.         tmpWrapper->InitODOSLToken(ev);
  1439.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1440.     
  1441.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1442.             THROW(errAEEventNotHandled);
  1443.         ODDesc* myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1444.         AEDesc myToken;
  1445.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken) );
  1446.     
  1447.         switch( myToken.descriptorType )
  1448.         {
  1449.             case kShellSelfPropAccessor :
  1450.             case kShellPropAccessor :
  1451.                 ShellPropAccessor* accessorObj =
  1452.                         FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
  1453.                         ShellPropAccessor*);
  1454.                 accessorObj->SetPropertyData(&dataDesc);
  1455.                 delete accessorObj;
  1456.                 break;
  1457.             default :
  1458.                 THROW(errAEEventNotHandled);
  1459.                 break;
  1460.         }
  1461.     
  1462.         AEDisposeDesc(&myToken);    
  1463.         AEDisposeDesc(&dataDesc);    
  1464.  
  1465.     CATCH_ALL
  1466.         AEDisposeDesc(&dataDesc);    
  1467.         error = ErrorCode();
  1468.     ENDTRY
  1469.  
  1470. //    ODDeleteObject(tmpWrapper);
  1471.     return error;
  1472. }    // HandleSetData()
  1473. #endif /* TO_BE_DELETED */
  1474.  
  1475.  
  1476. //******************************************************************************
  1477. // Utility functions
  1478. //******************************************************************************
  1479.  
  1480. ShellEventHandler* GetHandlerFromAEVT(AppleEvent* message,
  1481.         RealShell* self)
  1482. {
  1483.     Environment* ev = somGetGlobalEnvironment();
  1484.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1485.  
  1486.     AEDesc evtDp;
  1487.     THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
  1488.             &evtDp));
  1489.     TempAEDesc tmpdesc(&evtDp);
  1490.  
  1491.     ShellEventHandler* handlerObj;
  1492.     if (evtDp.descriptorType == typeNull)
  1493.     {
  1494.         handlerObj = new ShellEventHandler(typeNull, (ODObject*)self,
  1495.                 (ODSLong)self);
  1496.     }
  1497.     else
  1498.     {
  1499.         ODOSLToken* tmpWrapper = new ODOSLToken();
  1500.         THROW_IF_NULL(tmpWrapper);
  1501.         TempODObject tempObj(tmpWrapper);
  1502.         tmpWrapper->InitODOSLToken(ev);
  1503.         THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
  1504.     
  1505.         if( !resolver->IsODToken(ev, tmpWrapper) )
  1506.             THROW(errAEEventNotHandled);
  1507.         ODDesc* myTokenODDesc;
  1508.         myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
  1509.         AEDesc myToken;
  1510.         THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
  1511.  
  1512.         handlerObj = FIRSTBYTESFROMHANDLE(myToken.dataHandle,
  1513.                 ShellEventHandler*);
  1514.         AEDisposeDesc(&myToken);
  1515. //        ODDeleteObject(tmpWrapper);
  1516.     }
  1517.  
  1518. //    AEDisposeDesc(&evtDp);
  1519.     return handlerObj;
  1520. }    // GetHandlerFromAEVT()
  1521.  
  1522.  
  1523. //------------------------------------------------------------------------------
  1524. // GetDirectParam
  1525. //------------------------------------------------------------------------------
  1526.  
  1527. // THIS FUNCTION NEEDS A FIXIN' TO USE THE NEW WAY OF DOING DEFAULT ACCESSORS.
  1528.  
  1529. void GetDirectParam(RealShell* self, AppleEvent* message,
  1530.         AEDesc* evtDp)
  1531. {
  1532.     Environment* ev = somGetGlobalEnvironment();
  1533.     AEDesc localDP;
  1534.     THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
  1535.             &localDP));
  1536.  
  1537.     ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
  1538.  
  1539.     ODOSLToken* tmpWrapper = new ODOSLToken();
  1540.     THROW_IF_NULL(tmpWrapper);
  1541.     TempODObject tempObj(tmpWrapper);
  1542.     tmpWrapper->InitODOSLToken(ev);
  1543.     THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
  1544.  
  1545.     ODBoolean istoken = resolver->IsODToken(ev, tmpWrapper) ;
  1546. //    ODDeleteObject(tmpWrapper);
  1547.     if ( istoken )
  1548.     {
  1549.         *evtDp = localDP;
  1550.     }
  1551.     else
  1552.     {
  1553.         WARN("RlShlEv.cpp: GetDirectParam. Found a non-token.  About to throw.");
  1554.         THROW( errAEEventNotHandled );
  1555.     }
  1556. }    // GetDirectParam()
  1557.