home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Pascal / Snippets / PNL Libraries / MyAEGetData.p < prev    next >
Encoding:
Text File  |  1996-05-31  |  3.0 KB  |  100 lines  |  [TEXT/CWIE]

  1. unit MyAEGetData;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Types, AppleEvents;
  7.  
  8.     type
  9.         GetSelectionProcType = function ( var reply:AppleEvent ): OSErr;
  10.         
  11.     procedure StartupAEGetData;
  12.     procedure ConfigureAEGetData (GetSelectionProc: GetSelectionProcType);
  13.  
  14. implementation
  15.  
  16.     uses
  17.         AERegistry, AEObjects, MyStartup;
  18.  
  19.     const
  20.         MaxPropLevel = 2; { or whatever number of levels you want to support }
  21.  
  22.     type
  23.         propArray = array[1..MaxPropLevel] of DescType;
  24.  
  25.     var
  26.         getdata: GetSelectionProcType;
  27.  
  28.     function PropertyOf (theSpec: AERecord; var propLevel: integer; var properties: propArray): boolean;
  29.         var
  30.             objSpec: AERecord;
  31.             typ, t, prop: DescType;
  32.             size: longint;
  33.             key: AEKeyword;
  34.             err: OSErr;
  35.     begin
  36.         PropertyOf := false; { we don't know this is a property yet }
  37.         if propLevel = 0 then begin { 0 means the Apple Event }
  38.             key := keyDirectObject;
  39.         end else begin
  40.             key := keyAEContainer;
  41.         end;
  42.         if AEGetParamDesc(theSpec, key, typeAERecord, objSpec) = noErr then begin
  43.             if (AEGetParamPtr(objSpec, keyAEDesiredClass, typeType, typ, @t, 4, size) = noErr) & (t = cProperty) then begin
  44.                 if (AEGetParamPtr(objSpec, keyAEKeyForm, typeEnumerated, typ, @t, 4, size) = noErr) & (t = formPropertyID) then begin { this is redundunt, won't hurt to make sure }
  45.                     if AEGetParamPtr(objSpec, keyAEKeyData, typeType, typ, @prop, 4, size) = noErr then begin { which of property? }
  46.                         propLevel := propLevel + 1;
  47.                         properties[propLevel] := prop;
  48.                         if AESizeOfParam(objSpec, keyAEContainer, typ, size) = noErr then begin { property of what }
  49.                             if typ = typeNull then begin { prop of application, we are done }
  50.                                 PropertyOf := true;
  51.                             end else if typ = typeObjectSpecifier then begin { from another object specifer }
  52.                                 if propLevel < MaxPropLevel then { only do it if we have not reach max level }
  53.                                     PropertyOf := PropertyOf(objSpec, propLevel, properties); { go down 1 level }
  54.                             end; { else it is an error }
  55.                         end;
  56.                     end;
  57.                 end;
  58.             end;
  59.             err := AEDisposeDesc(objSpec);
  60.         end;
  61.     end;
  62.  
  63.     function MyGetDataHandler (var event, reply: AppleEvent; theRefcon: longint): OSErr;
  64.         var
  65.             err: OSErr;
  66.             propLevel: integer;
  67.             properties: propArray;
  68.     begin
  69. {$unused(theRefcon)}
  70.         err := errAENoSuchObject;
  71.         propLevel := 0; { 0 means we are passing in an Apple Event }
  72.         if PropertyOf(event, propLevel, properties) & (propLevel = 2) then begin
  73.             if (properties[1] = pContents) & (properties[2] = pSelection) then begin { it is content of selection }
  74.                 err := getdata( reply );
  75.             end;
  76.         end;
  77.         MyGetDataHandler := err;
  78.     end;
  79.  
  80.     function InitAEGetData ( var msg: integer ): OSStatus;
  81.         var
  82.             junk: OSErr;
  83.     begin
  84. {$unused(msg)}
  85.         junk := AEInstallEventHandler(kAECoreSuite, kAEGetData, NewAEEventHandlerProc(MyGetDataHandler), 0, false);
  86.         InitAEGetData := noErr;
  87.     end;
  88.  
  89.     procedure ConfigureAEGetData (GetSelectionProc: GetSelectionProcType);
  90.     begin
  91.         getdata := GetSelectionProc;
  92.         StartupAEGetData;
  93.     end;
  94.     
  95.     procedure StartupAEGetData;
  96.     begin
  97.         SetStartup( InitAEGetData, nil, 0, nil );
  98.     end;
  99.  
  100. end.