home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Libraries / WASTE 1.1a4 / Interfaces 2 / AEObjects.p next >
Encoding:
Text File  |  1993-07-14  |  8.5 KB  |  220 lines  |  [TEXT/PJMM]

  1. unit AEObjects;
  2.  
  3. { Copyright © Apple Computer Inc. 1990, 1991 }
  4. { All Rights Reserved }
  5.  
  6. { Adapted for use with THINK Pascal by Merzwaren (MP 7/14/93) }
  7.  
  8. interface
  9.     uses
  10.         EPPC, AppleEvents;
  11.  
  12.     const
  13.  
  14. { Logical operators: look for them in descriptors of type typeLogicalDescriptor}
  15. {  with keyword keyAELogicalOperator}
  16.         kAEAND = 'AND ';
  17.         kAEOR = 'OR  ';
  18.         kAENOT = 'NOT ';
  19.  
  20. { Absolute ordinals: look for them in descriptors of type typeAbsoluteOrdinal.}
  21. {  Possible use is as keyAEKeyData in an object specifier whose keyAEKeyForm}
  22. {  field is formAbsolutePosition.}
  23.         kAEFirst = 'firs';
  24.         kAELast = 'last';
  25.         kAEMiddle = 'midd';
  26.         kAEAny = 'any ';
  27.         kAEAll = 'all ';
  28.  
  29. {  Relative ordinals: look for them in descriptors of type formRelativePosition. }
  30.         kAENext = 'next';
  31.         kAEPrevious = 'prev';
  32.  
  33. {********* Keywords for getting fields out of Object specifier records *********}
  34.         keyAEDesiredClass = 'want';
  35.         keyAEContainer = 'from';
  36.         keyAEKeyForm = 'form';
  37.         keyAEKeyData = 'seld';
  38.  
  39.  
  40. {********* Keywords for getting fields out of Range specifier records *********}
  41.         keyAERangeStart = 'star';        { These are the only two fields in the range desc }
  42.         keyAERangeStop = 'stop';
  43.  
  44. {********* Possible values for the keyAEKeyForm field of an object specifier *********}
  45. { Remember that this set is an open-ended one.  The OSL makes assumptions about some of them,}
  46. {  but nothing in the grammar says you can't define your own}
  47.         formAbsolutePosition = 'indx';    { e.g., 1st, -2nd (= 2nd from end) }
  48.         formRelativePosition = 'rele';    { next, previous }
  49.         formTest = 'test';    { A logical or a comparison }
  50.         formRange = 'rang';    { Two arbitrary objects and everything in between }
  51.         formPropertyID = 'prop';    { Key data is a 4-char property name }
  52.         formName = 'name';    { Key data may be of type 'TEXT' }
  53.  
  54. {************* Various relevant types ***************}
  55. { Some of these tend to be paired with certain of the forms above.  Where this}
  56. {  is the case comments indicating the form(s) follow.}
  57.         typeObjectSpecifier = 'obj ';        { keyAEContainer will often be one of these }
  58.         typeObjectBeingExamined = 'exmn';        { Another possible value for keyAEContainer }
  59.         typeCurrentContainer = 'ccnt';        { Another possible value for keyAEContainer }
  60.         typeToken = 'toke';        { Substituted for 'ccnt' before accessor called }
  61.  
  62.         typeRelativeDescriptor = 'rel ';        { formRelativePosition }
  63.         typeAbsoluteOrdinal = 'abso';        { formAbsolutePosition }
  64.         typeIndexDescriptor = 'inde';        { formAbsolutePosition }
  65.         typeRangeDescriptor = 'rang';        { formRange }
  66.         typeLogicalDescriptor = 'logi';        { formTest is this or typeCompDescriptor }
  67.         typeCompDescriptor = 'cmpd';        { formTest is this or typeLogicalDescriptor }
  68.  
  69. {************* various relevant keywords ***************}
  70.         keyAECompOperator = 'relo';        { Relates two terms: '=', '<=', etc. }
  71.         keyAELogicalTerms = 'term';        { An AEList of terms to be related by 'logc' below }
  72.         keyAELogicalOperator = 'logc';        { kAEAND,  kAEOR or kAENOT }
  73.         keyAEObject1 = 'obj1';        { One of two objects in a term; must be object specifier }
  74.         keyAEObject2 = 'obj2';        { The other object; may be a simple descriptor or obj. spec. }
  75.  
  76.  
  77. {*********** Special Handler selectors for OSL Callbacks **************}
  78. { You don't need to use these unless you are not using AESetObjectCallbacks. }
  79.         keyDisposeTokenProc = 'xtok';
  80.         keyAECompareProc = 'cmpr';
  81.         keyAECountProc = 'cont';
  82.         keyAEMarkTokenProc = 'mkid';
  83.         keyAEMarkProc = 'mark';
  84.         keyAEAdjustMarksProc = 'adjm';
  85.         keyAEGetErrDescProc = 'indc';
  86.  
  87. {*********** Error codes **************}
  88. { OSL error codes: AEM proper uses up to -1719}
  89.         errAEImpossibleRange = -1720;        { A range like 3rd to 2nd, or 1st to all. }
  90.         errAEWrongNumberArgs = -1721;        { Logical op kAENOT used with other than 1 term }
  91.  
  92.         errAEAccessorNotFound = -1723;        { Accessor proc matching wantClass and containerType}
  93. {                                            ...or wildcards not found}
  94.         errAENoSuchLogical = -1725;     { Something other than AND, OR, or NOT }
  95.         errAEBadTestKey = -1726;        { Test is neither typeLogicalDescriptor}
  96. {                                            ...nor typeCompDescriptor}
  97.         errAENotAnObjSpec = -1727;     { Param to AEResolve not of type 'obj ' }
  98.         errAENoSuchObject = -1728;     { e.g.,: specifier asked for the 3rd, but there are only 2.}
  99. {                                            ...Basically, this indicates a run-time resolution error.}
  100.         errAENegativeCount = -1729;        { CountProc returned negative value }
  101.         errAEEmptyListContainer = -1730;        { Attempt to pass empty list as container to accessor }
  102.  
  103. { Possible values for flags parameter to AEResolve.  They're additive }
  104.         kAEIDoMinimum = $0000;
  105.         kAEIDoWhose = $0001;
  106.         kAEIDoMarking = $0004;
  107.  
  108.  
  109. { You only care about the constants that follow if you're doing your own whose}
  110. {  clause resolution}
  111.         typeWhoseDescriptor = 'whos';
  112.         formWhose = 'whos';
  113.         typeWhoseRange = 'wrng';
  114.         keyAEWhoseRangeStart = 'wstr';
  115.         keyAEWhoseRangeStop = 'wstp';
  116.         keyAEIndex = 'kidx';
  117.         keyAETest = 'ktst';
  118.  
  119.  
  120.     type
  121.         ccntTokenRecord = record        { Used for rewriting tokens in place of 'ccnt' descriptors.        }
  122.                 tokenClass: DescType;        { This record is only of interest to those who, when they...    }
  123.                 token: AEDesc;        { ...get ranges as key data in their accessor procs, choose...    }
  124.             end;                        { ...resolve them manually rather than call AEResolve again.    }
  125.         ccntTokenRecPtr = ^ccntTokenRecord;
  126.         ccntTokenRecHandle = ^ccntTokenRecPtr;
  127.  
  128.         DescPtr = ^AEDesc;
  129.         DescHandle = ^DescPtr;
  130.  
  131.         AccessorProcPtr = ProcPtr;
  132.  
  133. {——————————————————————————————— PUBLIC PROCEDURES —————————————————————————————————}
  134.  
  135. { Not done by inline, but by direct linking into code.  It sets up the pack}
  136. {  such that further calls can be via inline}
  137.     function AEObjectInit: OSErr;
  138.  
  139.  
  140.     function AESetObjectCallbacks (myCompareProc, myCountProc, myDisposeTokenProc, myGetMarkTokenProc,                    { called when mark (below) is true }
  141.                                     myMarkProc,                            { called when mark (below) is true }
  142.                                     myAdjustMarksProc,                    { called when mark (below) is true }
  143.                                     myGetErrDescProc: ProcPtr): OSErr;{ called to report an error descriptor }
  144.     inline
  145.         $303C, $0E35, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  146.  
  147.  
  148.  
  149.  
  150.     function AEResolve (objectSpecifier: AEDesc;
  151.                                     callbackFlags: INTEGER;        { see above for possible values }
  152.                                     var theToken: AEDesc): OSErr;
  153.     inline
  154.         $303C, $0536, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  155.  
  156.  
  157.     function AEInstallObjectAccessor (desiredClass: DescType;
  158.                                     containerType: DescType;
  159.                                     theAccessor: AccessorProcPtr;
  160.                                     accessorRefcon: LONGINT;
  161.                                     isSysHandler: BOOLEAN): OSErr;
  162.     inline
  163.         $303C, $0937, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  164.  
  165.     function AERemoveObjectAccessor (desiredClass: DescType;
  166.                                     containerType: DescType;
  167.                                     theAccessor: AccessorProcPtr;
  168.                                     isSysHandler: BOOLEAN): OSErr;
  169.     inline
  170.         $303C, $0738, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  171.  
  172.     function AEGetObjectAccessor (desiredClass: DescType;
  173.                                     containerType: DescType;
  174.                                     var theAccessor: AccessorProcPtr;
  175.                                     var accessorRefcon: LONGINT;
  176.                                     isSysHandler: BOOLEAN): OSErr;
  177.     inline
  178.         $303C, $0939, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  179.  
  180.     function AEDisposeToken (var theToken: AEDesc): OSErr;
  181.     inline
  182.         $303C, $023A, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  183.  
  184.     function AECallObjectAccessor (desiredClass: DescType;
  185.                                     containerToken: AEDesc;
  186.                                     containerClass: DescType;
  187.                                     keyForm: DescType;
  188.                                     keyData: AEDesc;
  189.                                     var theToken: AEDesc): OSErr;
  190.     inline
  191.         $303C, $0C3B, $A816;        { = move.w    #$E35,d0 \n _Pack8 }
  192.  
  193. {}
  194. {Here are the interfaces your callback procs must be written to:}
  195. {}
  196. {FUNCTION MyCompareProc( comparisonOperator: DescType; theObject: AEDesc; descOrObj:AEDesc;}
  197. {        VAR result: BOOLEAN ): OSErr;}
  198. {FUNCTION MyCountProc( desiredType: DescType; containerClass: DescType; theContainer: AEDesc;}
  199. {        VAR result: LongInt ): OSErr;}
  200. {FUNCTION MyGetMarkToken( containerToken: AEDesc; containerClass: DescType; VAR result: AEDesc ): OSErr;}
  201. {FUNCTION MyMark( theToken: AEDesc; markToken: AEDesc; markCount: LONGINT ): OSErr;}
  202. {FUNCTION MyAdjustMarks( newStart,newStop: LongInt; markToken: AEDesc ): OSErr;}
  203. {FUNCTION MyDisposeToken( VAR unneededToken: AEDesc ) : OSErr ;}
  204. {FUNCTION MyGetErrDescProc( VAR errDescPtr: DescPtr ) : OSErr ;}
  205. {}
  206. {FUNCTION MyObjectAccessor( desiredClass: DescType; containerToken: AEDesc;}
  207. {        containerClass: DescType; keyForm: DescType;}
  208. {        keyData: AEDesc; VAR theToken: AEDesc; theRefcon: LongInt; ): OSErr;}
  209. {}
  210. {You'll probably want to have a number of these last ones.}
  211. {A proc that finds a line within a document should be installed with 'line' and 'docu'}
  212. {as the desiredClass and containerClass fields in the call to AEInstallObjectHandler().}
  213. {}
  214.  
  215.     { UsingAEObjects }
  216.  
  217.  
  218. implementation
  219. end.
  220.