home *** CD-ROM | disk | FTP | other *** search
- /*********************************************************************************
- µCinema Converter 1.0
- module: apple events.c
- December 1992 - April 1994
- by John A. Schlack
-
- Description:
- This file contains routines for handling required apple events.
-
- *********************************************************************************/
-
-
- #include "constants.h"
-
- #include "apple events.h"
- #include "PICS to QuickTime.h"
- #include "µCinema.h"
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- enum AEventStatus { AE_NONE, AE_ODOC, AE_OTHER, AE_ERROR };
- static enum AEventStatus aestatus;
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- /* PRIVATE FUNCTION PROTOTYPES */
-
- static pascal OSErr handle_ODOC( AppleEvent * aevent, AppleEvent * reply, long refcon );
- static pascal OSErr handle_QUIT( AppleEvent * aevent, AppleEvent * reply, long refcon );
- static pascal OSErr handle_OAPP( AppleEvent * aevent, AppleEvent * reply, long refcon );
- static pascal OSErr handle_PDOC( AppleEvent * aevent, AppleEvent * reply, long refcon );
- static OSErr RequiredCheck( AppleEvent * aevent );
- static void DoAEInstall( void );
- static void high_level_process_events( void );
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static pascal OSErr handle_ODOC( AppleEvent * aevent, AppleEvent * reply, long refcon )
- {
- OSErr err;
- AEDescList docList;
- FSSpec spec;
- long items, i, num_errors;
- AEKeyword keyword;
- DescType typeCode;
- Size actualSize;
-
- err = AEGetParamDesc( aevent, keyDirectObject, typeAEList, &docList );
- if (err) goto handle_ODOC_err;
-
- err = RequiredCheck( aevent );
- if (err) goto handle_ODOC_err;
-
- err = AECountItems( &docList, &items );
- if (err) goto handle_ODOC_err;
-
- for (i=1L; i<=items; i++)
- {
- err = AEGetNthPtr( &docList, i, typeFSS, &keyword, &typeCode, (Ptr) &spec,
- sizeof( FSSpec ), &actualSize );
- if (err) goto handle_ODOC_err;
- picsToMovieBatch( &spec );
- }
-
- aestatus = AE_ODOC;
- return noErr;
-
-
- handle_ODOC_err:
- aestatus = AE_ERROR;
- return err;
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static pascal OSErr handle_QUIT( AppleEvent * aevent, AppleEvent * reply, long refcon )
- {
- OSErr err;
-
- err = RequiredCheck( aevent );
- if (err)
- {
- aestatus = AE_ERROR;
- return err;
- }
-
- installProgramStatus( PS_APP_DONE );
- return noErr;
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static pascal OSErr handle_OAPP( AppleEvent * aevent, AppleEvent * reply, long refcon )
- {
- OSErr err;
-
- err = RequiredCheck( aevent );
- if (err)
- {
- aestatus = AE_ERROR;
- return err;
- }
-
- aestatus = AE_OTHER;
- return noErr;
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static pascal OSErr handle_PDOC( AppleEvent * aevent, AppleEvent * reply, long refcon )
- {
- aestatus = AE_ERROR;
- return errAEEventNotHandled;
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static OSErr RequiredCheck( AppleEvent * aevent )
- {
- OSErr err;
- DescType typeCode;
- Size siz;
-
- err = AEGetAttributePtr( aevent, keyMissedKeywordAttr, typeWildCard, &typeCode,
- 0L, 0, &siz );
- if (err == errAEDescNotFound) return noErr;
- if (err == noErr) return errAEEventNotHandled;
- return err;
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- static void DoAEInstall( void )
- {
- AEInstallEventHandler( kCoreEventClass, kAEOpenDocuments,
- (EventHandlerProcPtr) handle_ODOC, 0, false );
-
- AEInstallEventHandler( kCoreEventClass, kAEQuitApplication,
- (EventHandlerProcPtr) handle_QUIT, 0, false );
-
- AEInstallEventHandler( kCoreEventClass, kAEOpenApplication,
- (EventHandlerProcPtr) handle_OAPP, 0, false );
-
- AEInstallEventHandler( kCoreEventClass, kAEPrintDocuments,
- (EventHandlerProcPtr) handle_PDOC, 0, false );
- }
-
-
- /* -------------------------------------------------------------------------------- */
-
-
- Boolean loadDragAndDrop( void )
- {
- #define MAX_HIGH_EVT_WAIT 60 // 1.0 seconds
-
- long end_tick, count;
- CursHandle waitCursorH;
-
- aestatus = AE_NONE;
- DoAEInstall();
-
- // dump all events until we get to the high level events
- FlushEvents( everyEvent, highLevelEventMask );
-
- end_tick = TickCount() + MAX_HIGH_EVT_WAIT;
- count = 0L;
- do
- {
- if (aestatus != AE_NONE) break;
- if (count++ == 1L)
- {
- waitCursorH = GetCursor( watchCursor );
- SetCursor( *waitCursorH );
- }
- high_level_process_events();
- } while (TickCount() < end_tick);
-
- SetCursor( &arrow );
- if (aestatus == AE_ERROR)
- errorHandler( ERR_APPLE_EVENT );
- return ((aestatus == AE_ODOC) ? true : false);
- }
-
-
- /* --------------------------------------------------------------------------------- */
-
-
- static void high_level_process_events( void )
- {
- EventRecord event;
- Boolean event_present;
-
- event_present = WaitNextEvent( highLevelEventMask, &event, 20L, 0L );
-
- if (event_present)
- {
- if ( event.what == kHighLevelEvent )
- AEProcessAppleEvent( &event );
- }
- }
-