home *** CD-ROM | disk | FTP | other *** search
- /*
- File: ShlEvtHd.cp
-
- Contains: Shell event handlers (and others, for now)
-
- Owned by: Eric House
-
- Copyright: © 1993 - 1995 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <18> 9/9/95 TJ Included TempObj.h
- <17> 9/8/95 TÇ 1281096 FB2:Many constants in ODTypesB
- without kOD prefix!
- <16> 9/8/95 TÇ 1282092 FB2: Shell must check nil after SOM
- new
- <15> 9/5/95 TÇ FBs: 1266428, 1274419, 1274421, 1274423,
- 1274429, 1274435 Fixed the Shell to handle
- multiple documents in a process. Needed for
- CyberDog.
- <14> 8/25/95 eeh 1263528: cleanup
- <13> 8/22/95 eeh 1230007: refbal-inspired cleanup
- <12> 8/15/95 TÇ 1262179 FB: Shell calls BlockMove() in many
- places
- <11> 6/25/95 TÇ 1242642 BB: Turn on ODDebug warning if
- refcount is wrong in
- ODRefCntObjectsomUninit.
- <10> 5/26/95 RR #1251403: Multithreading naming support
- <9> 5/25/95 jpa Fixed usage of ODDebug. [1253321]
- <8> 4/27/95 eeh 1240648: pass kODNULL to SaveACopyAs
- <7> 3/21/95 JP 1192027: Include ODRgstry & change some
- constant names
- <6> 2/21/95 eeh 1214783: cleanup
- <5> 2/20/95 TÇ #1210979 BB: 5-$ Bugs need to be evaluated
- and removed from Shell
- <4> 9/29/94 RA 1189812: Mods for 68K build.
- <3> 9/26/94 TÇ #1188679 Save A Copy As Stationery
- <2> 7/28/94 TÇ put ifdef ODDEBUG around DebugStr.
- #1155844
- <1> 6/30/94 TÇ first checked in
- <0> 6/29/94 SV SOMverted
- <4> 3/31/94 eeh bug# 1151750: more scripting support for
- operations on draft
- <3> 3/25/94 eeh bug# 1151750: more scripting support for
- operations on draft.
- <2> 3/24/94 eeh bug# 1151750: scripting support for
- operations on draft
- <4> 2/8/94 TÇ Throw -> THROW & some code clean up
- <3> 2/7/94 TÇ more fixes to compile with PPC Headers
- <2> 1/11/94 eeh nuked FrameEventHandler class; mods to
- others
- <1> 11/19/93 eeh first checked in
-
-
- To Do:
- In Progress:
-
- */
-
-
- #ifndef _PLFMDEF_
- #include "PlfmDef.h"
- #endif
-
-
- #ifndef _ODUTILS_
- #include <ODUtils.h>
- #endif
-
- #ifndef _SHLEVTHD_
- #include "ShlEvtHd.h"
- #endif
-
- #ifndef _SHPRPACC_
- #include "ShPrpAcc.h"
- #endif
-
- #ifndef _SEUTILS_
- #include "SEUtils.h"
- #endif
-
- #ifndef _DOCUTILS_
- #include "DocUtils.h"
- #endif
-
- #ifndef _ODREGISTRY_
- #include "ODRgstry.xh"
- #endif
-
- #ifndef _RLSHELL_
- #include <RlShell.h>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _PLFMFILE_
- #include <PlfmFile.h>
- #endif
-
- #ifndef SOM_ODDocument_xh
- #include <Document.xh>
- #endif
-
- #ifndef _ODDEBUG_
- #include "ODDebug.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include "TempObj.h"
- #endif
-
- #pragma segment ShPrpAcc
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- //==============================================================================
- // Scalar Types
- //==============================================================================
-
- //==============================================================================
- // Local Classes
- //==============================================================================
-
- //==============================================================================
- // Global Variables
- //==============================================================================
-
- //==============================================================================
- // Function Prototype
- //==============================================================================
-
- //==============================================================================
- // HandlerObject
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // HandlerObject::HandlerObject
- //------------------------------------------------------------------------------
-
- HandlerObject::HandlerObject(DescType theClass, ODObject* theObject,
- ODSLong refCon)
- {
- fObjectClass = theClass;
- fTheObject = theObject;
- fRefcon = refCon;
- }
-
- //------------------------------------------------------------------------------
- // HandlerObject::GetClass
- //------------------------------------------------------------------------------
-
- DescType HandlerObject::GetClass()
- {
- return fObjectClass;
- }
-
- //------------------------------------------------------------------------------
- // HandlerObject::GetObject
- //------------------------------------------------------------------------------
-
- ODObject* HandlerObject::GetObject()
- {
- return fTheObject;
- }
-
- //==============================================================================
- // ShellEventHandler
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::ShellEventHandler
- //------------------------------------------------------------------------------
-
- ShellEventHandler::ShellEventHandler(DescType theClass, ODObject* theObject,
- ODSLong refCon) : HandlerObject(theClass, theObject, refCon)
- {
- }
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::Save
- //------------------------------------------------------------------------------
-
- void ShellEventHandler::Save(AEDesc* whereFileSpec)
- {
- RealShell* self = (RealShell*)fRefcon;
- Environment* ev = self->GetEV();
- ODSession* session = self->GetSession();
- ODVolatile(session);
-
- // Note: this event acts upon the ACTIVE document in the process if
- // it is a plain Save event.
- // If it is a "Save A Copy" event and specifies a destination, then
- // it will act upon the ACTIVE draft.
-
- // Most of the time there will be only one document & one draft,
- // so this is fine, but FYI. -TÇ
-
- if (whereFileSpec->dataHandle == NULL)
- {
- ODSaveDocument(ev, session, ODGetActiveDocument(ev, session));
- }
- else
- {
- ODFileSpec fss;
- ODBlockMove(*(whereFileSpec->dataHandle), &fss, sizeof(fss));
- TempPlatformFile file = new PlatformFile;
- file->Specify(&fss);
- ODSaveACopyOfDraft(ev, session, ODGetActiveDraft(ev, session), file);
- }
- }
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::Close
- // Closing the shell means closing the active window
- //------------------------------------------------------------------------------
-
- void ShellEventHandler::Close(AEDesc* whereFileSpec, DescType saveOptions)
- {
- RealShell* self = (RealShell*)fRefcon;
- Environment* ev = self->GetEV();
- ODSession* session = self->GetSession();
-
- ODUnused(whereFileSpec);
-
- WindowPtr platformWindow = kODNULL;
- {
- TempODWindow window = ODAcquireActiveWindow(ev, session);
- if (window)
- platformWindow = window->GetPlatformWindow(ev);
- }
- self->CloseWindow(platformWindow, saveOptions);
- }
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::CountElements
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- static ODSLong CountDraftsInDocument( ODDocument* doc )
- {
- Environment* ev = somGetGlobalEnvironment();
- ODSLong result = 0; // current draft doesn't count
- ODDraft* thisDraft = doc->AcquireBaseDraft(ev, kODDPReadOnly); // -- TÇ: $$$$$ Don't know if this is a true leak
- ODDraft* nextDraft = kODNULL;
- ODVolatile(result);
- TRY
- while ( true )
- {
- nextDraft = doc->AcquireDraft(ev, kODDPReadOnly, kODNULL, thisDraft, /* -- TÇ: $$$$$ Don't know if this is a true leak */
- kODPosLastAbove, kODTrue );
- thisDraft = nextDraft;
- ++result;
- }
- CATCH_ALL
- ;
- ENDTRY
-
- return result;
- }
- #endif /* TO_BE_DELETED */
-
- #ifdef TO_BE_DELETED
- void ShellEventHandler::CountElements(DescType elemClass, AEDesc* result)
- {
- ODSLong resultCount;
- OSErr err = noErr;
-
- switch(this->GetClass())
- {
- case typeNull :
- switch( elemClass )
- {
- case cDraft :
- resultCount = CountDraftsInDocument(
- ((RealShell*)this->GetObject())->GetDocument() );
- break;
- case cWindow :
- resultCount = 1;
- break;
- default :
- err = errAEEventNotHandled;
- }
- break;
-
- case cWindow :
- switch(elemClass)
- {
- case cPart :
- resultCount = 1; // only one root part (now)
- break;
- default :
- err = errAEEventNotHandled;
- }
- break;
-
- default :
- err = errAEEventNotHandled;
- }
-
- if (err != noErr)
- THROW(err);
- else
- THROW_IF_ERROR(AECreateDesc(typeLongInteger, (Ptr)&resultCount,
- sizeof(resultCount), result));
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::Clone
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellEventHandler::Clone( AEDesc* whereto, AEDesc* result )
- {
- ODUnused( whereto );
- result->descriptorType = 'null';
- result->dataHandle = NULL;
- }
- #endif /* TO_BE_DELETED */
-
- //------------------------------------------------------------------------------
- // ShellEventHandler::Delete
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- void ShellEventHandler::Delete()
- {
- Environment* ev = somGetGlobalEnvironment();
- switch(this->GetClass() )
- {
- case cDraft :
- {
- ODDraft* selectedDraft = (ODDraft*)this->GetObject();
- ODDocument* document = selectedDraft->GetDocument(ev);
-
- WASSERT( selectedDraft->GetRefCount(ev) <= 1 );
-
- ODDraft* fromDraft = document->AcquireDraft(ev, kODDPReadOnly, kODNULL, /* -- TÇ: $$$$$ Don't know if this is a true leak */
- selectedDraft, kODPosFirstAbove, kODFalse );
- WASSERT( selectedDraft->GetRefCount(ev) <= 1 );
- WASSERT( fromDraft->GetRefCount(ev) <= 1 );
- document->SaveToAPrevDraft(ev, fromDraft, selectedDraft );
- document->CollapseDrafts(ev, fromDraft, selectedDraft );
- ODReleaseObject(ev, selectedDraft );
- }
- break;
- default :
- THROW( errAEEventNotHandled );
- }
- }
- #endif /* TO_BE_DELETED */
-
- //==============================================================================
- // PartEventHandler
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // PartEventHandler::PartEventHandler
- //------------------------------------------------------------------------------
-
- #ifdef TO_BE_DELETED
- PartEventHandler::PartEventHandler(DescType theClass, ODFrame* frame,
- ODSLong refCon) : HandlerObject(theClass, (ODObject*)frame,
- refCon)
- {
- }
- #endif /* TO_BE_DELETED */
-
-