home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-12-20 | 5.0 KB | 161 lines | [TEXT/CWIE] |
- unit MyRequiredEventSupport;
-
- interface
-
- uses
- Types, Files, AppleEvents, MyTypes;
-
- var
- required_event_with_option: boolean;
- required_event_with_control: boolean;
-
- type
- DocProc = function (var fs:FSSpec): OSErr;
- NoDocProc = function: OSErr;
-
- procedure InitAppleEvents (DoOpenApplication:NoDocProc; DoOpenDocuments:DocProc; DoPrintDocuments: DocProc; DoQuitApplication: NoDocProc);
-
- implementation
-
- uses
- Processes, Events, Memory, EPPC,
- MyAEUtils, MyEvents, MyAssertions;
-
- var
- gDoOpenApplication: NoDocProc;
- gDoOpenDocuments: DocProc;
- gDoPrintDocuments: DocProc;
- gDoQuitApplication: NoDocProc;
-
- procedure GetModifiers(var event: AppleEvent);
- var
- err, junk: OSErr;
- psn: ProcessSerialNumber;
- pi: ProcessInfoRec;
- dummy: Boolean;
- er: EventRecord;
- keywd: AEKeyword;
- actualSize: Size;
- attrdesc:AEDesc;
- targrec: TargetID;
- begin
- { check if the event comes from the finder and honour the option/control keys }
- required_event_with_control := false;
- required_event_with_option := false;
- AECreate( attrdesc );
- err := AEGetAttributePtr(event, keyAddressAttr, keyProcessSerialNumber, keywd, @psn, SizeOf(psn), actualSize);
- if err <> noErr then begin
- err := AEGetAttributePtr(event, keyAddressAttr, typeTargetID, keywd, @targrec, SizeOf(targrec), actualSize);
- if err = noErr then begin
- err := GetProcessSerialNumberFromPortName( targrec.name, psn );
- end;
- end;
- if err = noErr then begin
- pi.processInfoLength := sizeof(ProcessInfoRec);
- pi.processName := nil;
- pi.processAppSpec := nil;
- err := GetProcessInformation(psn, pi);
- end;
- if (err = noErr) & (pi.processSignature = 'MACS') then begin
- dummy := OSEventAvail(everyEvent, er);
- required_event_with_option := EventHasOptionKey( er );
- required_event_with_control := EventHasControlKey( er );
- end;
- junk := GetBooleanFromAERecord(event, keyOdocOption, required_event_with_option);
- junk := GetBooleanFromAERecord(event, keyOdocControl, required_event_with_control);
- AEDestroy( attrdesc );
- end;
-
- function HandleNoDocs (var event, reply: AppleEvent; Doit:NoDocProc): OSErr;
- var
- err: OSErr;
- begin
- {$unused(reply)}
- GetModifiers(event);
- err := GotRequiredParams(event);
- if err = noErr then begin
- err := Doit;
- end;
- HandleNoDocs := err;
- end;
-
- function HandleDocs (var event, reply: AppleEvent; Doit:DocProc): OSErr;
- var
- myFSS: FSSpec;
- docList: AEDescList;
- index, itemsInList: longint;
- typeCode: DescType;
- err, oerr, junk: OSErr;
- keywd: AEKeyword;
- actualSize: Size;
- begin
- {$unused(reply)}
- GetModifiers(event);
- err := AEGetParamDesc(event, keyDirectObject, typeAEList, docList);
- if err = noErr then begin
- junk := GotRequiredParams(event);
- (* now get each alias from the list (as an FSSSpec) and open the associated file. *)
- err := AECountItems(docList, itemsInList);
- if err = noErr then begin
- for index := 1 to itemsInList do begin
- oerr := AEGetNthPtr(docList, index, typeFSS, keywd, typeCode, @myFSS, sizeof(myFSS), actualSize);
- (* coercion does alias->fsspec *)
- if oerr = noErr then begin
- Assert( Doit <> nil );
- oerr := Doit(myFSS);
- end;
- end;
- end;
- junk := AEDisposeDesc(docList);
- end;
- HandleDocs := err;
- end;
-
- function HandleOpenApplication(var event, reply: AppleEvent; ignored: longint): OSErr;
- begin
- {$unused(ignored)}
- HandleOpenApplication := HandleNoDocs(event, reply, gDoOpenApplication);
- end;
-
- function HandleOpenDocuments (var event, reply: AppleEvent; ignored: longint): OSErr;
- begin
- {$unused(ignored)}
- HandleOpenDocuments := HandleDocs(event, reply, gDoOpenDocuments);
- end;
-
- function HandlePrintDocuments(var event, reply: AppleEvent; ignored: longint): OSErr;
- begin
- {$unused(ignored)}
- HandlePrintDocuments := HandleDocs(event, reply, gDoPrintDocuments);
- end;
-
- function HandleQuitApplication(var event, reply: AppleEvent; ignored: longint): OSErr;
- begin
- {$unused(ignored)}
- HandleQuitApplication := HandleNoDocs(event, reply, gDoQuitApplication);
- end;
-
- procedure InitAppleEvents (DoOpenApplication:NoDocProc; DoOpenDocuments:DocProc; DoPrintDocuments: DocProc; DoQuitApplication: NoDocProc);
- var
- junk: OSErr;
- begin
- gDoOpenApplication := DoOpenApplication;
- gDoOpenDocuments := DoOpenDocuments;
- gDoPrintDocuments := DoPrintDocuments;
- gDoQuitApplication := DoQuitApplication;
- if (@gDoOpenApplication <> nil) then begin
- junk := AEInstallEventHandler(kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(HandleOpenApplication), 0, false);
- end;
- if (@gDoOpenDocuments <> nil) then begin
- junk := AEInstallEventHandler(kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(HandleOpenDocuments), 0, false);
- end;
- if (@gDoPrintDocuments <> nil) then begin
- junk := AEInstallEventHandler(kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(HandlePrintDocuments), 0, false);
- end;
- if (@gDoQuitApplication <> nil) then begin
- junk := AEInstallEventHandler(kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(HandleQuitApplication), 0, false);
- end;
- end;
-
- end.
-