home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-22 | 50.2 KB | 1,734 lines | [TEXT/MPS ] |
- /*
- File: RlShlEv.cpp
-
- Contains: Apple Event handlers for the document shell.
-
- Owned by: Eric House
-
- Copyright: © 1994 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <63> 10/26/95 eeh 1296308: check for null draftToBringForward
- <62> 10/12/95 eeh 1287143: handle activate events where
- document isn't open
- <61> 9/13/95 TÇ 1249149 FB2: Memory leak/crash fixes
- <60> 9/11/95 NP 1272294: Messaging code cleanup.
- <59> 9/8/95 TÇ 1282092 FB2: Shell must check nil after SOM
- new
- <58> 9/5/95 TÇ FBs: 1266428, 1274419, 1274421, 1274423,
- 1274429, 1274435 Fixed the Shell to handle
- multiple documents in a process. Needed for
- CyberDog.
- <57> 8/26/95 TÇ 1279063 FB3: must check results of SOM
- operator new
- <56> 8/25/95 JP 1272288: Added HandleGetAETE
- <55> 8/23/95 NP 1276287: Move constant kODAppShell.
- <54> 8/22/95 eeh 1230007: use tempobjs
- <53> 8/16/95 NP 1273600: FB: ShellSI is not ref-counted
- correctly.
- <52> 8/15/95 TÇ 1262179 FB: Shell calls BlockMove() in many
- places
- <51> 8/12/95 TÇ 1276806 Optimization: use kODFalse instead
- of kODTrue in comparisons
- <50> 8/8/95 jpa Document file synchronization [1259401]
- <49> 8/2/95 VL 1270320: Changed PlatformFile to
- TempPlatformFile.
- <48> 7/25/95 DM #1270320: Memory leak fixes.
- <47> 7/20/95 CC 1238642, 1244151: HandleHighLevelEvent:
- Clear modifiers field of open document
- Apple event to work around Edition mgr bug.
- <46> 7/3/95 eeh 1264701: don't dispose tokens returned by
- GetUserToken!
- <45> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <44> 6/22/95 EL #1261759: Do not call adjust menu when
- processing high level event in the
- background.
- <43> 6/1/95 jpa Added 2nd param to ExceptionAlert()
- [1242839]
- <42> 5/26/95 RR #1251403: Multithreading naming support
- <41> 5/21/95 NP 1248898: GetUserToken, ODDescToAEDesc, etc.
- recipe change.
- <40> 5/17/95 RR #1250135/1250137/1250143 Getters increment
- refcount
- <39> 5/17/95 TÇ 1249144 BB: OpenDoc Shell doesn't handle
- failures in the open documents event
- correctly.
- <38> 5/16/95 JP 1238991: Shell must supply an accessor for
- file from null.
- <36> 4/24/95 eeh 1240662: check keyODActivateEventCause,
- call FakePrintMenuEvent
- <35> 4/15/95 TÇ #1216915 With help from JP: DR/BB:Trying to
- open a document that is already open causes
- an error.
- <34> 4/14/95 TÇ #1235279 BB: InfoUtil & StdTypIO functions
- should take Environment* and SU* when
- possible
- <33> 4/10/95 TÇ #1226675 Option-Close does not close all
- Windows
- <32> 4/7/95 eeh 1221297: HandleOpenPrintDocsEvent from ODOC
- handler
- <31> 3/31/95 TÇ 1204755 BB: Canceling save dialog when
- Restart is chosen doesn't work correctly.
- Works now. Even with shutdown.
- <30> 3/13/95 NP 1223765: Add ODSession parameter to
- InitSIHelper.
- <29> 3/2/95 eeh 1214783: more cleanup
- <28> 2/21/95 eeh 1214783: cleanup
- <27> 2/20/95 TÇ #1210979 BB: 5-$ Bugs need to be evaluated
- and removed from Shell
- #1221861 BB: Incomplete AOCE support needs
- to be removed from OpenDoc
- <26> 2/13/95 eeh #1217393: fix GetHandlerFromAEVT
- <25> 2/3/95 eeh 1217393: use new ODDesc etc.
- <24> 1/27/95 NP 1213948: Fix event handlers.
- <23> 1/25/95 eeh 1211798: make event handlers "pascal"
- <22> 1/22/95 NP GetUserToken et al signature changed
- because of change to AE types.
- <21> 1/16/95 eeh 1211798: use new method of dealing with
- tokens (GetUserToken etc.)
- <20> 1/9/95 NP 1194880: SemtIntf name changes.
- <19> 12/5/94 jpa Catch CFM errors opening new documents.
- [1158966]
- <18> 11/15/94 NP 1199847,1199053-Commented out some code
- that uses an obsolete method and put a WARN
- in. Fixed event handlers.
- <17> 10/13/94 NP 1189812: Changed several callbacks to
- pascal conventions.
- <16> 9/29/94 RA 1189812: Mods for 68K build.
- <15> 9/22/94 eeh #1185445 save draft after attaching mailer.
- <14> 9/15/94 NP 1186778: Changed token handling code.
- <13> 9/8/94 eeh #1185443: changes to HandleOpenDocsEvent.
- <12> 9/2/94 eeh moved mailer-specific stuff to RlShlMlr.cpp
- in the process of fixing 1150934 and
- 1167302
- <11> 8/29/94 TÇ fixed header
- <10> 8/29/94 TÇ #1183567 StdTypIO routine implementation &
- fixup
- <9> 8/20/94 DO 1169445: now returning scripting size resource
- <8> 8/15/94 JBS 1181156: UI API Cleanup
- <7> 8/13/94 NP 1180819-Adjusted calls to
- InstallEventHandler.
- <6> 7/27/94 eeh install CoerceToFSSpec, but a version that
- doesn't throw
- <5> 7/26/94 eeh don't install coercions (temp fix)
- <4> 7/14/94 TÇ fixed references to ASLMBILD and
- uncommented calls to info functions
- <3> 7/13/94 TÇ removed some xmps
- <2> 6/30/94 TÇ uncommented references to GetNameResolver
- etc.
- <1> 6/30/94 TÇ first checked in
- <0> 6/29/94 SV SOMverted
- <12> 5/10/94 TÇ #1162405 Removed explicit ASLM dependency
- for using resources
- <11> 4/12/94 eeh bug #1154546: make HandleQuit close windows
- <10> 3/28/94 CG 1153547: Renamed XMPSessn.h to XMPSessM.h
- <9> 3/26/94 NP 1153509. Messaging not PowerPC ready.
- <8> 3/25/94 eeh Moved InstallEventHandlers() code into
- InitAE() (no bug# yet)
- <7> 3/25/94 eeh bug #1153053: More changes for PPC
- nativity.
- <6> 3/24/94 eeh bug #1153053: Changes for PPC nativity
- (incomplete)
- <5> 3/16/94 eeh bug #1149649: HandleOpenDocsEvent now deals
- with launches for OCE Reply
- <4> 3/8/94 eeh bug# 1149508: nuked installation of gdut
- handler
- <3> 2/24/94 TÇ fix #1145435. Save and Revert to Saved
- menu items are now enabled properly (only
- when there are changes to a draft)
- brand new documents which have never been
- saved are deleted when closed. cleaned up
- a few more comments.
- <2> 2/15/94 TÇ fix #1144029 and some cleanup
- <19> 2/8/94 TÇ Throw -> THROW & some code clean up
- <18> 2/7/94 TÇ fixes to compile with PPC Headers
- <17> 1/17/94 NP Semantic Events callbacks API changes.
- <16> 1/15/94 RR WinState.h->WinStat.h,
- Dispatch.h->Disptch.h
- <15> 1/13/94 eeh removed dead code in GetAllAETEResources
- <14> 1/11/94 eeh backed out reading all the library files in
- ASLM HandleGetAETE
- <13> 12/17/93 eeh fixed HandleGetAETE to work under ASLM.
- (Reading all the library files will need to
- be backed out.)
- <12> 12/9/93 eeh filled in Make, Save, Close and
- CountElements -- partially
- <11> 11/30/93 JA Rearranged #includes for new "frame"
- constant fix.
- <10> 11/22/93 SS Added typecasts for latest headers
- <9> 11/15/93 eeh Implemented Get&SetData (sorta), and added
- stubs for the rest of the Core
- <8> 11/12/93 CG Added the HandleGetAETE AE handler and
- GetAllAETEResources -- not yet tested with
- ASLM build!!!!
- <7> 10/18/93 NP Added pragma unused statements.
- <6> 10/11/93 NP Commented out installation of event
- handler.
- <5> 10/8/93 TÇ comment out references to PROTOTYPEBUILD
- <3> 9/23/93 TÇ #include <SemtIntf.xh> so that it would
- compile in the implementation
- <2> 9/8/93 NP blah blah blah.
- <1> 9/7/93 NP first checked in
-
- To Do:
- In Progress:
-
- */
-
- #ifndef _PLFMDEF_
- #include <PlfmDef.h>
- #endif
-
- #ifndef _SIHELPER_
- #include <SIHelper.h>
- #endif
-
- #ifndef _ODPRCS_
- #include "ODPrcs.h"
- #endif
-
- #ifndef SOM_ODSession_xh
- #include <ODSessn.xh>
- #endif
-
- #ifndef _EXCEPT_
- #include <Except.h>
- #endif
-
- #ifndef SOM_ShellSI_xh
- #include "ShellSI.xh"
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef _SEUTILS_
- #include <SEUtils.h>
- #endif
-
- #ifndef _SHPRPACC_
- #include "ShPrpAcc.h"
- #endif
-
- #ifndef _SHLEVTHD_
- #include "ShlEvtHd.h"
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _RLSHELL_
- #include "RlShell.h"
- #endif
-
- #ifndef SOM_ODContainer_xh
- #include <ODCtr.xh>
- #endif
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef __ALIASES__
- #include <Aliases.h>
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef _ODDESUTL_
- #include <ODDesUtl.h>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef SOM_ODNameResolver_xh
- #include <NamRslvr.xh>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef SOM_ODMessageInterface_xh
- #include <MssgIntf.xh>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef SOM_ODWindowIterator_xh
- #include <WinIter.xh>
- #endif
-
- #ifndef SOM_ODOSLToken_xh
- #include <ODOSLTkn.xh>
- #endif
-
- #ifndef SOM_ODAppleEvent_xh
- #include <ODAplEvt.xh>
- #endif
-
- #ifndef __ASREGISTRY__
- #include <ASRegistry.h>
- #endif
-
- #ifndef __AEUserTermTypes__
- #include <AEUserTermTypes.h>
- #endif
-
- #ifndef __APPLEEVENTS__
- #include <AppleEvents.h>
- #endif
-
- #ifndef SOM_Module_OpenDoc_ODRegistry_defined
- #include "ODRgstry.xh"
- #endif
-
- #ifndef __RESOURCES__
- #include <Resources.h>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include <StdDefs.xh>
- #endif
-
- #pragma segment ShellEvt
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define STATICBUILD
-
- const DescType kShellPropAccessor = 0x73706163; // 'spac';
- const DescType kShellSelfPropAccessor = 0x7368656C; // 'shel';
-
- const DescType kShellEventHandler = 'shev';
-
- //==============================================================================
- // Function Prototypes
- //==============================================================================
-
- //void CreateUniqueTmpFolderForFile(ODFileSpec* result, Str63 fileName);
-
- #define HANDLER_PARAMS \
- ODPart* thePart, \
- ODAppleEvent* message, \
- ODAppleEvent* reply, \
- ODSLong handlerRefcon
-
- // pascal ODError HandleClone(HANDLER_PARAMS);
- pascal ODError HandleClose(HANDLER_PARAMS);
- // pascal ODError HandleCountEl(HANDLER_PARAMS);
- // pascal ODError HandleMake(HANDLER_PARAMS);
- // pascal ODError HandleDelete(HANDLER_PARAMS);
- // pascal ODError HandleDoExist(HANDLER_PARAMS);
- // pascal ODError HandleGetClsInfo(HANDLER_PARAMS);
- // pascal ODError HandleGetData(HANDLER_PARAMS);
- // pascal ODError HandleGetDataSz(HANDLER_PARAMS);
- // pascal ODError HandleGetEvnInfo(HANDLER_PARAMS);
- // pascal ODError HandleMove(HANDLER_PARAMS);
- // pascal ODError HandleOpen(HANDLER_PARAMS);
- // pascal ODError HandlePrint(HANDLER_PARAMS);
- pascal ODError HandleSave(HANDLER_PARAMS);
- // pascal ODError HandleSetData(HANDLER_PARAMS);
- pascal ODError HandleODActivate(HANDLER_PARAMS);
-
- pascal ODError HandleGetAETE(HANDLER_PARAMS);
-
- #undef HANDLER_PARAMS
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon);
-
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* theAppleEvent,
- RealShell* self);
- void GetDirectParam(RealShell* self, AppleEvent* theAppleEvent,
- AEDesc* evtDp);
-
- //==============================================================================
- // RealShell
- //==============================================================================
-
- //-------------------------------------------------------------------------------------
- // Apple Event Support
- //-------------------------------------------------------------------------------------
-
-
- void RealShell::InitAE()
- {
- Environment* ev = fEV;
-
- ShellSI* shellSemtInterface = new ShellSI;
- THROW_IF_NULL(shellSemtInterface);
- fSIHelper = new SIHelper;
- fSIHelper->InitSIHelper(fSession, shellSemtInterface);
- shellSemtInterface->InitCPlusSemanticInterface(ev, kODAppShell, fSIHelper,
- fSession);
- fSession->SetShellSemtInterface(ev, shellSemtInterface);
- shellSemtInterface->Release(ev); // SetShellSemtInterface acquires.
-
- ODObjectAccessorUPP newAccessor =
- NewODObjectAccessorProc( GetFileFromNULL );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallObjectAccessor( cFile,
- typeNull, newAccessor, (ODSLong)fSession );
-
- ODEventHandlerUPP newHandler =
- NewODEventHandlerProc( RealShell::HandleOpenAppEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenApplication,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEOpenDocuments,
- newHandler,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleOpenPrintDocsEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEPrintDocuments,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleQuitEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler( kCoreEventClass,
- kAEQuitApplication,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleLaunchFailedEvent );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kCFMLaunchFailedEventClass,
- kCFMLaunchFailedEventID,
- newHandler ,
- (long)this);
-
- newHandler = NewODEventHandlerProc( RealShell::HandleODActivate );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(
- kAEOpenDocSuite,
- kODActivateEvent,
- newHandler ,
- (long)this);
-
- ODCoercionHandlerUPP fsSpecCoerceHdlr =
- NewODDescCoercionHandlerProc( RealShell::CoerceToFSSpec );
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler( typeAlias, typeFSS,
- fsSpecCoerceHdlr, (long)this, kODTrue );
-
- // this->InstallObjectAccessors(shellSemtInterface);
-
- /*
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallCoercionHandler(typeChar, typeFSS,
- (XMPCoercionHandler)Pathname2FSSpec, kNoRefCon,
- kFromTypeIsNotDesc );
- */
-
- ODEventHandlerUPP eventHandlerUPP;
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleClone);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClone,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleClose);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEClose,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleCountEl);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECountElements,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMake);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAECreateElement,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDelete);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDelete,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleDoExist);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEDoObjectsExist,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetClsInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetClassInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetData,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetDataSz);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetDataSize,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleGetEvnInfo);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEGetEventInfo,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleMove);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEMove,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandleOpen);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEOpen,
- eventHandlerUPP, (ODSLong)this);
-
- eventHandlerUPP = NewODEventHandlerProc(HandlePrint);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAEPrint,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- eventHandlerUPP = NewODEventHandlerProc(HandleSave);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESave,
- eventHandlerUPP, (ODSLong)this);
-
- #ifdef TO_BE_DELETED
- eventHandlerUPP = NewODEventHandlerProc(HandleSetData);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAECoreSuite, kAESetData,
- eventHandlerUPP, (ODSLong)this);
- #endif /* TO_BE_DELETED */
-
- //#ifndef STATICBUILD
- // Just let AS get the resource directly if not ASLM. In fact, we
- // probably don't need this even in that case.
- eventHandlerUPP = NewODEventHandlerProc(HandleGetAETE);
- ((SIHelper*)shellSemtInterface->GetSIHelper(ev))->InstallEventHandler(kAEOpenDocSuite, kGetAETE,
- eventHandlerUPP,
- (ODSLong)this);
- //#endif /* STATICBUILD */
-
- }
-
-
- void RealShell::HandleHighLevelEvent(ODEventData* event)
- {
- Environment* ev = fEV;
- ProcessSerialNumber myPSN,frontPSN;
- ODBoolean active;
- (void)GetCurrentProcess(&myPSN);
- (void)GetFrontProcess(&frontPSN);
- (void)SameProcess(&myPSN,&frontPSN,&active);
- if (active)
- this->UpdateMenus();
-
- if ( ((AEEventClass) event->message == 'aevt') && (*(AEEventID *) &(event->where) == 'odoc') )
- {
- // If the open document event was sent by the edition manager, the modifiers field
- // of the event will be garbage. This can cause AEProcessAppleEvent to return an error
- // instead of calling one of our event handlers.
- // We work around this by clearing the modifiers field. Note that clearing the field
- // is not correct if the event is larger than 64K; we take the chance that an 'odoc'
- // event won't be this large. [cc 7/19/95] [Radar #1261856]
- event->modifiers = 0;
- }
-
- ODBoolean succeeded = fSession->GetMessageInterface(ev)->ProcessSemanticEvent(ev, event);
- }
-
-
- pascal ODError RealShell::HandleOpenAppEvent(ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(message);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODError error = noErr;
-
- TRY
-
- // Create a new stationery document on OAPP
- /*
- self->OpenFile(self->New());
- self->Open();
- */
- self->New();
- self->GetSession()->GetDispatcher(ev)->Exit(ev);
-
- CATCH_ALL
- error = ErrorCode();
- self->GetSession()->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
-
- return error;
- }
-
- void RealShell::FakePrintMenuEvent()
- {
- Environment* ev = fEV;
- ODDispatcher* dispatcher = this->GetSession()->GetDispatcher(ev);
-
- ODMenuID menu;
- ODMenuItemID menuItem;
- TempODMenuBar baseMenuBar = this->fWindowState->AcquireBaseMenuBar(ev);
- baseMenuBar->GetMenuAndItem(ev, kODCommandPrint, &menu, &menuItem );
-
- ODEventData event;
- event.message = (menu<<16) | menuItem;
- event.what = kODEvtMenu;
- // zero the rest of the fields
- WASSERT( sizeof(Point) == sizeof(long) ); // this is gross but
- *(long*)&event.where = 0L;
- event.when = 0L;
- event.modifiers = 0;
- dispatcher->Dispatch(ev, &event);
- }
-
- pascal ODError RealShell::HandleOpenPrintDocsEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- ODVolatile(session);
-
- ODFileSpec aFile;
-
- long itemsInList;
- AEKeyword aDocKeyword;
- AEDesc aFileSpecDesc;
- OSErr err;
- ODError error = noErr;
- AppleEvent realMessage;
- DescType eventID;
- DescType ignoreType;
- Size ignoreActual;
-
- TRY
- // get list of documents
- realMessage.dataHandle = kODNULL;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- AEDesc docList;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyDirectObject, typeAEList,
- &docList));
- TempAEDesc tmpDesc(&docList);
- THROW_IF_ERROR( AEGetAttributePtr( &realMessage, keyEventIDAttr, typeType,
- &ignoreType, &eventID, sizeof(eventID), &ignoreActual ));
- ODBoolean isPrint = eventID == kAEPrintDocuments;
- if (MissingParams(&realMessage))
- THROW( errAEParamMissed );
-
- // count number of documents to open
- THROW_IF_ERROR( AECountItems(&docList, &itemsInList ));
- WASSERT( itemsInList == 1 );
-
- ODSLong indexStart;
- TempPlatformFile file = kODNULL;
-
- if (ODGetFirstOpenDocument(ev, session)==kODNULL)
- {
- // Get FSSpec for first (hopefully only) document
- THROW_IF_ERROR(err = AEGetNthDesc(&docList, 1, typeFSS,
- &aDocKeyword, &aFileSpecDesc));
- ODBlockMove(*(aFileSpecDesc.dataHandle), (Ptr)&aFile, sizeof(aFile));
- AEDisposeDesc(&aFileSpecDesc);
- indexStart = 2;
- file = new PlatformFile;
- file->Specify(&aFile);
- } else {
- indexStart = 1;
- }
-
- // spawn shell processes to handle extra documents
- for (ODSLong index = indexStart; index <= itemsInList; index++)
- {
- ODFileSpec extraFile;
- // ONLY HANDLING FSSPECS HERE!
- err = AEGetNthDesc(&docList, index, typeFSS, &aDocKeyword,
- &aFileSpecDesc);
- // We'll handle tokens here...
-
- if (err == errAECoercionFail)
- {
- AEDesc coerceDesc = NULL_DESCRIPTOR_DEFINITION;
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
-
- TRY
- GetDirectParam(self, &realMessage, &coerceDesc);
- TempAEDesc tmpCD( &coerceDesc );
- THROW_IF_ERROR( AEDescToODDesc(&coerceDesc, tmpWrapper ) );
- ODDesc* myToken;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- myToken = resolver->GetUserToken(ev, tmpWrapper);
- AEDisposeDesc( &coerceDesc );
- THROW_IF_ERROR( ODDescToAEDesc(myToken, &coerceDesc) );
- THROW_IF_ERROR( AECoerceDesc(&coerceDesc, typeFSS, &aFileSpecDesc) );
- // ODDeleteObject(tmpWrapper);
- err = noErr;
- CATCH_ALL
- // ODDeleteObject(tmpWrapper);
- // There was an error coercing to FSSpec and we couldn't deal.
- // Should we do anything? Do we care?
- // RERAISE;
- ENDTRY
- }
- if (!err)
- ODBlockMove(*(aFileSpecDesc.dataHandle), (Ptr)&extraFile, sizeof(extraFile));
-
- AEDisposeDesc(&aFileSpecDesc);
-
- if (!err)
- {
- TempPlatformFile file = new PlatformFile();
- file->Specify(&extraFile);
- self->OpenAnotherFile(file );
- // ODDeleteObject(file); // temp auto-deletes
- }
- else
- ;
- // There was an error with open/printing an additional document
- // Should we do anything? Do we care?
- }
-
- // AEDisposeDesc(&docList);
- if (file!=kODNULL) {
-
- self->OpenFile(file);
-
- if ( isPrint ) // make it print, then quit
- {
- self->FakePrintMenuEvent();
- if (ODCloseDocument(ev, session, ODGetFirstOpenDocument(ev, session)))
- session->GetDispatcher(ev)->Exit(ev);
- }
- }
-
- CATCH_ALL
- error = ErrorCode();
- session->GetDispatcher(ev)->Exit(ev);
- self->SetAEError(error);
- ENDTRY
- ODDisposeAppleEvent( &realMessage );
-
- return error;
- } // HandleOpenPrintDocsEvent()
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleQuitEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleQuitEvent( ODPart* /*part*/,
- ODAppleEvent* /*message*/,
- ODAppleEvent* /*reply*/,
- long refCon)
- {
- ODError error = noErr;
- RealShell* self = (RealShell*)refCon;
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
- // AEDesc theFile = { typeNull, kODNULL };
-
- TRY
- // In OpenDoc the 'QUIT' event means CloseDocument.
- // $$$$$ WILL CONTINUE TO ASK EVEN IF YOU CANCEL THE SAVE CHANGES? DIALOG.
-
- RealShell* self = (RealShell*)refCon;
- ODDocument* document = kODNULL;
- while ((document = ODGetFirstOpenDocument(ev, session)) != kODNULL)
- self->CloseDocument(ODGetActiveDocument(ev, self->GetSession()), kAEAsk);
- session->GetDispatcher(ev)->Exit(ev);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleQuitEvent()
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleLaunchFailedEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleLaunchFailedEvent( ODPart* part,
- ODAppleEvent* message,
- ODAppleEvent* reply,
- long refCon)
- {
- ODUnused(part);
- ODUnused(reply);
-
- long launchErr;
- ProcessSerialNumber psn;
- Str255 appName, libName;
- AppleEvent realMessage;
-
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
-
- //<eeh> any chance this can throw???
- GetLaunchFailedParams(&realMessage, launchErr,&psn,appName,libName);
- ODDisposeAppleEvent(&realMessage);
-
- RealShell *shell = (RealShell*)refCon;
- shell->LaunchFailed(launchErr,psn,appName,libName);
- return noErr;
- }
-
-
- void
- RealShell::LaunchFailed( ODSLong launchErr, const ProcessSerialNumber &psn,
- Str255 appName, Str255 libName )
- {
- if( psn.lowLongOfPSN != kNoProcess ) {
- Boolean result;
- if( SameProcess(&psn,&fLastNewDocPSN,&result) == noErr && result != kODFalse ) {
- // This is a new document we just created & launched; better delete it.
- OSErr err= FSpDelete(&fLastNewDocSpec);
- if( err )
- WARN("Error %d trying to delete new document",err);
- fLastNewDocPSN.lowLongOfPSN = kNoProcess;
- fLastNewDocSpec.name[0] = '\0';
- }
- }
-
- this->ExceptionAlert(launchErr,kODNULL);
- }
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // HandleODActivateEvent
- //
- ////////////////////////////////////////////////////////////////////////////////
-
- pascal ODError RealShell::HandleODActivate( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- ODError result = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
-
- ODFileSpec fileSpec;
- AppleEvent realMessage;
- DescType unused1;
- Size unused2;
- ODBoolean wasPrintEvent = kODFalse;
- ODBoolean notAlreadyOpen = kODFalse;
- boolean quitAfterPrint = kODFalse;
- TempODDraft draftToBringForward = kODNULL;
-
- realMessage.dataHandle = NULL;
- TRY
- THROW_IF_ERROR(ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyDirectObject, typeFSS,
- &unused1, (Ptr)&fileSpec, sizeof(fileSpec), &unused2));
- DescType spawningEventID;
- OSErr err = AEGetParamPtr(&realMessage, keyODActivateEventCause,
- typeType, &unused1, (Ptr)&spawningEventID,
- sizeof(spawningEventID), &unused2 );
- if ( err == noErr )
- wasPrintEvent = spawningEventID == kAEPrintDocuments;
- // else drop the error: id not present is ok.
-
- err = AEGetParamPtr( &realMessage, keyODRefnumFromResource,
- typeBoolean, &unused1, (Ptr)&quitAfterPrint,
- sizeof(quitAfterPrint), &unused2 );
- if ( err != noErr )
- quitAfterPrint = kODFalse;
-
- CATCH_ALL
- result = ErrorCode();
- ENDTRY
- ODDisposeAppleEvent(&realMessage);
-
- Environment* ev = self->fEV;
- ODSession* session = self->GetSession();
-
- if ( result == noErr )
- {
- ODULong refNumCount, i;
- ODSShort* refNums = kODNULL;
- GetLocalPaths(&fileSpec, kDataFork, &refNumCount, &refNums);
-
- if (refNumCount != 0)
- {
- for ( i=0; i<refNumCount; ++i)
- {
- ODDocument* doc = ODGetOpenDocumentFromRefNum(ev,
- session, refNums[i]);
- if ( doc != kODNULL )
- {
- draftToBringForward = ODGetTempDraftFromOpenDocument( ev,
- session, doc );
-
- if (draftToBringForward)
- draftToBringForward->Acquire(ev); // balance destructor of TempRef
- else
- draftToBringForward =
- doc->AcquireDraft(ev,kODDPReadOnly,0,kODNULL,kODPosTop,kODFalse);
-
- break; // exit for loop
- }
- }
-
- if (refNums)
- DisposePtr((Ptr)refNums);
- }
- else // *if* this process is supposed to handle this event at
- { // all, the ODActivate must have come because of a resource
- // fork.
- short resRefNum = CurResFile();
- if ( refNums != kODNULL )
- {
- DisposePtr( (Ptr)refNums );
- refNums = kODNULL;
- }
- GetLocalPaths( &fileSpec, kResourceFork, &refNumCount, &refNums );
- for ( i=0; i<refNumCount; ++i )
- {
- if ( refNums[i] == resRefNum ) // it belongs in this process
- {
- TempPlatformFile file = new PlatformFile;
- file->Specify( &fileSpec );
- draftToBringForward = ODOpenFileDocument( ev, session, file,
- kODDPSharedWrite );
-
- self->InstallShellPlugIns(draftToBringForward);
- notAlreadyOpen = kODTrue;
- break;
- }
- }
- if( refNums != kODNULL )
- DisposePtr( (Ptr)refNums );
- }
- }
-
- if ( draftToBringForward != kODNULL )
- {
- ProcessSerialNumber psn;
- GetCurrentProcess(&psn);
- SetFrontProcess(&psn);
-
- ODOpenDraft( ev, session, draftToBringForward );
- if ( notAlreadyOpen )
- {
- // the plugin may have patched these....
- self->fDispatcher = session->GetDispatcher(ev);
- self->fWindowState = session->GetWindowState(ev);
- }
- if ( wasPrintEvent )
- {
- self->FakePrintMenuEvent();
- if ( quitAfterPrint )
- {
- // need to release draft's refcount *before* calling
- // ODCloseDocument (or check with Tantek to see if
- // assertion in ODCloseDocument can be removed.
- ODDocument* doc = draftToBringForward->GetDocument(ev);
- draftToBringForward->Release(ev);
- draftToBringForward = kODNULL; // prevent another release by the TempRef
- ODBoolean wasLastDoc = ODCloseDocument( ev, session, doc );
- WASSERT( !wasLastDoc );
- }
- }
- }
-
- return result; // usually should be eventNotHandled?
- } // HandleODActivate
-
-
- ////////////////////////////////////////////////////////////////////////////////
- //
- // CoerceToFSSpec
- //
- ////////////////////////////////////////////////////////////////////////////////
-
-
- pascal ODError RealShell::CoerceToFSSpec( ODPart* thePart, ODDesc* theAEDesc,
- DescType toType, ODSLong handlerRefCon, ODDesc* result )
- {
- ODUnused(thePart);
- RealShell* self = (RealShell*)handlerRefCon;
-
- if (self->fAlreadyInCoercion)
- return errAECoercionFail;
- else
- self->fAlreadyInCoercion = kODTrue;
- ODError error = noErr;
-
- TRY
- AEDesc realInDesc;
- THROW_IF_ERROR( ODDescToAEDesc(theAEDesc, &realInDesc));
- TempAEDesc tmpDesc(&realInDesc);
- if (realInDesc.descriptorType == typeAlias)
- {
- // use the built-in coercion first
- AEDesc tmpResult;
- error = AECoerceDesc( &realInDesc, toType, &tmpResult );
-
- if ( error == noErr )
- {
- TempAEDesc tmpDesc(&tmpResult);
- THROW_IF_ERROR( AEDescToODDesc( &tmpResult, result ));
- }
- }
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- self->fAlreadyInCoercion = kODFalse;
- return error;
- } // CoerceToFSSpec()
-
- //----------------------------------------------------------------------------------------
- // RealShell::SetAEError
- //----------------------------------------------------------------------------------------
-
- void RealShell::SetAEError(ODError error)
- {
- fErrorFromOpenEvents = error;
- }
-
- //----------------------------------------------------------------------------------------
- // RealShell::GetAEError
- //----------------------------------------------------------------------------------------
-
- ODError RealShell::GetAEError()
- {
- return fErrorFromOpenEvents;
- }
-
- //==============================================================================
- // Functions
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // HandleGetAETE
- //------------------------------------------------------------------------------
-
-
- pascal ODError HandleGetAETE(ODPart* thePart,
- ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc theAETE = NULL_DESCRIPTOR_DEFINITION;
- DescType returnedType;
- ODSize actualSize;
- ODSLong languageCode;
- ODError result;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- result = AEGetParamPtr(&realMessage, keyDirectObject, typeLongInteger,
- &returnedType, (Ptr)&languageCode, sizeof(languageCode),
- (Size *)&actualSize);
- ODDisposeAppleEvent(&realMessage);
- THROW_IF_ERROR(result);
-
- TRY
- CUsingLibraryResources ref;
-
- theAETE.dataHandle = Get1Resource(typeAETE, (short)languageCode);
- if (theAETE.dataHandle)
- {
- theAETE.descriptorType = typeAETE;
- result = AEPutParamDesc(&realReply, keyAEResult, &theAETE);
- ReleaseResource(theAETE.dataHandle);
- THROW_IF_ERROR(result);
- }
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- THROW_IF_ERROR(error);
-
- THROW_IF_ERROR(AEDescToODDesc(&realReply, reply));
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
- AEDisposeDesc(&realReply);
-
- return error;
- } // HandleGetAETE()
-
-
- //------------------------------------------------------------------------------
- // GetFileFromNULL
- //------------------------------------------------------------------------------
-
- pascal ODError GetFileFromNULL( ODPart* part,
- DescType desiredClass,
- ODOSLToken* container,
- DescType containerClass,
- DescType form,
- ODDesc* selectionData,
- ODOSLToken* value,
- ODSLong refCon)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSession* session = (ODSession*)refCon;
- ODNameResolver* resolver = session->GetNameResolver(ev);
- ODError error = noErr;
- AEDesc aeAlias, tmp;
- char state;
-
- TRY
- // get the selectionData and coerce it into an fsspec
- THROW_IF_ERROR(ODDescToAEDesc(selectionData, &tmp));
- TempAEDesc tmpDesc(&tmp);
- state = HGetState(tmp.dataHandle);
- HLock(tmp.dataHandle);
- THROW_IF_ERROR(NewAliasMinimalFromFullPath(GetHandleSize(tmp.dataHandle),
- *tmp.dataHandle, "\p", "\p",
- (AliasHandle*)&aeAlias.dataHandle ));
- HSetState(tmp.dataHandle, state);
- aeAlias.descriptorType = typeAlias;
- TempAEDesc tmpDesc2(&aeAlias);
- UpdateUserToken(ev, resolver, value, &aeAlias);
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // GetFileFromNULL
-
- //------------------------------------------------------------------------------
- // HandleClone
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleClone( ODPart* thePart, ODAppleEvent* theAppleEvent,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(theAppleEvent, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT( &realMessage,
- (RealShell*)handlerRefcon );
-
- AEDesc cloneLocation;
- THROW_IF_ERROR( AEGetParamDesc( &realMessage, keyAEInsertHere,
- typeInsertionLoc, &cloneLocation ) );
-
- AEDesc replyDp;
- handlerObj->Clone( &cloneLocation, &replyDp );
- delete handlerObj;
-
- THROW_IF_ERROR( AEPutParamDesc( &realReply, keyDirectObject, &replyDp ) );
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- } // HandleClone()
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleClose
- //------------------------------------------------------------------------------
-
- pascal ODError HandleClose( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- // can't use TempAEDescs for these because they don't call
- // ODDisposeAppleEvent
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- TempAEDesc tmpDesc(&theFile);
- ThrowIfNotAbsent(err);
-
- DescType saveOptions = kAEAsk, typeFound;
- Size actualSize;
- err = AEGetParamPtr(&realMessage, keyAESaveOptions, typeEnumeration,
- &typeFound, (Ptr)&saveOptions, sizeof(saveOptions), &actualSize);
- ThrowIfNotAbsent(err);
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Close(&theFile, saveOptions);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- }
-
- //------------------------------------------------------------------------------
- // HandleCountEl
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleCountEl(ODPart* thePart, ODAppleEvent* message, ODAppleEvent* reply,
- ODSLong handlerRefcon)
- {
- ODUnused(thePart);
-
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
-
- DescType elemClass, typeFound;
- Size actualSize;
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&elemClass, sizeof(elemClass), &actualSize));
-
- AEDesc replyDp;
- handlerObj->CountElements(elemClass, &replyDp);
- delete handlerObj;
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMake
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMake(ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon)
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
- ODUnused(reply);
-
- DescType newObjClass, typeFound;
- Size actualSize;
- AEDesc insertHere, newObjectName;
- OSErr err;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
-
- THROW_IF_ERROR(AEGetParamPtr(&realMessage, keyAEObjectClass, typeType,
- &typeFound, (Ptr)&newObjClass, sizeof(newObjClass), &actualSize));
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEInsertHere,
- typeInsertionLoc, &insertHere));
- err = AEGetParamDesc(&realMessage, 'type', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- err = AEGetParamDesc(&realMessage, 'subj', typeChar, &newObjectName);
- if (err && (err != errAEDescNotFound))
- THROW(err);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDelete
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDelete( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- TRY
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Delete();
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- return error;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleDoExist
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleDoExist( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetClsInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetClsInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(handlerRefcon);
-
- AEDesc evtDp;
- AEDesc replyDp;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- replyDp.dataHandle = NULL;
- evtDp.dataHandle = NULL;
-
- GetDirectParam((RealShell*)handlerRefcon, &realMessage,
- &evtDp);
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
- // ODDeleteObject(myTokenODDesc);
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->GetPropertyData(&replyDp);
- delete accessorObj;
- break;
-
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- THROW_IF_ERROR(AEPutParamDesc(&realReply, keyDirectObject, &replyDp));
- THROW_IF_ERROR( AEDescToODDesc(&realReply, reply ) );
-
- AEDisposeDesc(&evtDp);
- AEDisposeDesc(&replyDp);
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleGetData();
- #endif /* TO_BE_DELETED */
-
-
- //------------------------------------------------------------------------------
- // HandleGetDataSz
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetDataSz( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleGetEvnInfo
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleGetEvnInfo( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleMove
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleMove( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleOpen
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleOpen( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandlePrint
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandlePrint( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(message);
- ODUnused(reply);
- ODUnused(handlerRefcon);
- return errAEEventNotHandled;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // HandleSave
- //------------------------------------------------------------------------------
-
- pascal ODError HandleSave( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
- AEDesc theFile;
- ODError error = noErr;
-
- AppleEvent realMessage, realReply;
- realMessage.dataHandle = realReply.dataHandle = NULL;
-
- TRY
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- OSErr err = AEGetParamDesc(&realMessage, keyAEFile, typeFSS, &theFile);
- ThrowIfNotAbsent(err);
-
- // keyAEFileType
-
- ShellEventHandler* handlerObj = GetHandlerFromAEVT(&realMessage,
- (RealShell*)handlerRefcon);
- handlerObj->Save(&theFile /*,&theFileType*/);
- delete handlerObj;
-
- CATCH_ALL
- error = ErrorCode();
- ENDTRY
-
- ODDisposeAppleEvent(&realMessage);
- ODDisposeAppleEvent(&realReply);
- return error;
- } // HandleSave()
-
- //------------------------------------------------------------------------------
- // HandleSetData
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- pascal ODError HandleSetData( ODPart* thePart, ODAppleEvent* message,
- ODAppleEvent* reply, ODSLong handlerRefcon )
- {
- ODUnused(thePart);
- ODUnused(reply);
-
- AEDesc dataDesc;
- ODError error = noErr;
-
- RealShell* self = (RealShell*)handlerRefcon;
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AppleEvent realMessage, realReply;
- THROW_IF_ERROR( ODDescToAEDesc(message, &realMessage));
- // THROW_IF_ERROR( ODDescToAEDesc(reply, &realReply));
-
- // ODOSLToken* tmpWrapper = kODNULL;
- TRY
-
- dataDesc.dataHandle = NULL;
- THROW_IF_ERROR(AEGetParamDesc(&realMessage, keyAEData, typeWildCard,
- &dataDesc));
-
- AEDesc evtDp;
- GetDirectParam( self, &realMessage, &evtDp );
- AEDisposeDesc( &realMessage );
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken) );
-
- switch( myToken.descriptorType )
- {
- case kShellSelfPropAccessor :
- case kShellPropAccessor :
- ShellPropAccessor* accessorObj =
- FIRSTBYTESFROMHANDLE((&myToken)->dataHandle,
- ShellPropAccessor*);
- accessorObj->SetPropertyData(&dataDesc);
- delete accessorObj;
- break;
- default :
- THROW(errAEEventNotHandled);
- break;
- }
-
- AEDisposeDesc(&myToken);
- AEDisposeDesc(&dataDesc);
-
- CATCH_ALL
- AEDisposeDesc(&dataDesc);
- error = ErrorCode();
- ENDTRY
-
- // ODDeleteObject(tmpWrapper);
- return error;
- } // HandleSetData()
- #endif /* TO_BE_DELETED */
-
-
- //******************************************************************************
- // Utility functions
- //******************************************************************************
-
- ShellEventHandler* GetHandlerFromAEVT(AppleEvent* message,
- RealShell* self)
- {
- Environment* ev = somGetGlobalEnvironment();
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- AEDesc evtDp;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &evtDp));
- TempAEDesc tmpdesc(&evtDp);
-
- ShellEventHandler* handlerObj;
- if (evtDp.descriptorType == typeNull)
- {
- handlerObj = new ShellEventHandler(typeNull, (ODObject*)self,
- (ODSLong)self);
- }
- else
- {
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&evtDp, tmpWrapper ) );
-
- if( !resolver->IsODToken(ev, tmpWrapper) )
- THROW(errAEEventNotHandled);
- ODDesc* myTokenODDesc;
- myTokenODDesc = resolver->GetUserToken(ev, tmpWrapper);
- AEDesc myToken;
- THROW_IF_ERROR( ODDescToAEDesc(myTokenODDesc, &myToken ));
-
- handlerObj = FIRSTBYTESFROMHANDLE(myToken.dataHandle,
- ShellEventHandler*);
- AEDisposeDesc(&myToken);
- // ODDeleteObject(tmpWrapper);
- }
-
- // AEDisposeDesc(&evtDp);
- return handlerObj;
- } // GetHandlerFromAEVT()
-
-
- //------------------------------------------------------------------------------
- // GetDirectParam
- //------------------------------------------------------------------------------
-
- // THIS FUNCTION NEEDS A FIXIN' TO USE THE NEW WAY OF DOING DEFAULT ACCESSORS.
-
- void GetDirectParam(RealShell* self, AppleEvent* message,
- AEDesc* evtDp)
- {
- Environment* ev = somGetGlobalEnvironment();
- AEDesc localDP;
- THROW_IF_ERROR(AEGetParamDesc(message, keyDirectObject, typeWildCard,
- &localDP));
-
- ODNameResolver* resolver = self->GetSession()->GetNameResolver(ev);
-
- ODOSLToken* tmpWrapper = new ODOSLToken();
- THROW_IF_NULL(tmpWrapper);
- TempODObject tempObj(tmpWrapper);
- tmpWrapper->InitODOSLToken(ev);
- THROW_IF_ERROR( AEDescToODDesc(&localDP, tmpWrapper ) );
-
- ODBoolean istoken = resolver->IsODToken(ev, tmpWrapper) ;
- // ODDeleteObject(tmpWrapper);
- if ( istoken )
- {
- *evtDp = localDP;
- }
- else
- {
- WARN("RlShlEv.cpp: GetDirectParam. Found a non-token. About to throw.");
- THROW( errAEEventNotHandled );
- }
- } // GetDirectParam()
-