home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Pascal / Utilities / pLayer 1.0d5 / pLayer Source / TextServices.p < prev   
Encoding:
Text File  |  1993-06-08  |  10.9 KB  |  312 lines  |  [TEXT/MPS ]

  1. {
  2.     File:        TextServices.p
  3.  
  4.     Copyright:    © 1983-1993 by Apple Computer, Inc.
  5.                 All rights reserved.
  6.  
  7.     Version:    System 7.1 for ETO #11
  8.     Created:    Tuesday, March 30, 1993 18:00
  9.  
  10. }
  11.  
  12. {$IFC UNDEFINED UsingIncludes}
  13. {$SETC UsingIncludes := 0}
  14. {$ENDC}
  15.  
  16. {$IFC NOT UsingIncludes}
  17.  UNIT TextServices;
  18.  INTERFACE
  19. {$ENDC}
  20.  
  21. {$IFC UNDEFINED UsingTextServices}
  22. {$SETC UsingTextServices := 1}
  23.  
  24. {$I+}
  25. {$SETC UsingTextServices := UsingIncludes}
  26. {$SETC UsingIncludes := 1}
  27. {$IFC UNDEFINED UsingTypes}
  28. {$I $$Shell(PInterfaces)Types.p}
  29. {$ENDC}
  30. {$IFC UNDEFINED UsingEvents}
  31. {$I $$Shell(PInterfaces)Events.p}
  32. {$ENDC}
  33. {$IFC UNDEFINED UsingMenus}
  34. {$I $$Shell(PInterfaces)Menus.p}
  35. {$ENDC}
  36. {$IFC UNDEFINED UsingAppleEvents}
  37. {$I $$Shell(PInterfaces)AppleEvents.p}
  38. {$ENDC}
  39. {$IFC UNDEFINED UsingErrors}
  40. {$I $$Shell(PInterfaces)Errors.p}
  41. {$ENDC}
  42. {$IFC UNDEFINED UsingComponents}
  43. {$I $$Shell(PInterfaces)Components.p}
  44. {$ENDC}
  45. {$SETC UsingIncludes := UsingTextServices}
  46.  
  47. CONST
  48.  
  49.     gestaltTSMgrVersion = 'tsmv';            { Text Services Mgr version, if present }
  50.  
  51.     kTSMVersion            =    1;                        { Version of Text Services Manager }
  52.     kTextService        =    'tsvc';                    { Component type for component description }
  53.     kInputMethodService    =    'inpm';                    { Component subtype for component description }
  54.     
  55.     bTakeActiveEvent    =    15;                        { Bit set if the component takes activate events }
  56.     bScriptMask            =    $00007F00;                { Bits 8 - 14 }
  57.     bLanguageMask        =    $000000FF;                { Bits 0 - 7 }
  58.     bScriptLanguageMask    =    bScriptMask + bLanguageMask;    {Bits 0 - 14 }
  59.  
  60. { Hilite styles ... }
  61.     kCursorPosition                =    1;                { specify cursor position }
  62.     kRawText                    =    2;                { specify range of raw text }
  63.     kSelectedRawText            =    3;                { specify range of selected raw text }
  64.     kConvertedText                =    4;                { specify range of converted text }
  65.     kSelectedConvertedText        =    5;                { specify range of selected converted text }
  66.     
  67. {
  68.     Apple Event constants
  69. }
  70.  
  71.     kTextServiceClass        =    kTextService;        { Event class }
  72.     kUpdateActiveInputArea    =    'updt';                { Update the active inline area }
  73.     kPos2Offset                =    'p2st';                { Convert global coordinates to character position }
  74.     kOffset2Pos                =    'st2p';                { Convert character position to global coordinate }
  75.     kShowHideInputWindow    =    'shiw';                { show or hide the input window }
  76.     
  77.  
  78.     { Event keywords ... }
  79.  
  80.     keyAETSMDocumentRefcon    =    'refc';                { TSM document refcon }
  81.  
  82.     keyAEServerInstance    =    'srvi';                    { Server instance }
  83.     keyAETheData        =    'kdat';                    { typeText }
  84.     keyAEFixLength        =    'fixl';
  85.     keyAEHiliteRange    =    'hrng';                    { Hilite range array }
  86.     keyAEUpdateRange    =    'udng';                    { Update range array }
  87.     keyAEClauseOffsets    =    'clau';                    { Clause offsets array }
  88.     keyAECurrentPoint    =    'cpos';                    { Current point }
  89.     keyAEDragging        =    'bool';                    { Dragging flag }
  90.     keyAEOffset            =    'ofst';                    { Offset }
  91.     keyAERegionClass    =    'rgnc';                    { Region class }
  92.     keyAEPoint            =    'gpos';                    { Current point }
  93.     keyAEBufferSize        =    'buff';                    { Buffer size to get the text }
  94.     keyAEMoveView        =    'mvvw';                    { Move view flag }
  95.     keyAELength            =    'leng';                    { Length }
  96.     keyAENextBody        =    'nxbd';                    { Next or previous body }
  97.  
  98. { optional keywords for Offset2Pos        -- 28Mar92 }
  99.  
  100.     keyAETextLineHeight    =    'ktlh';
  101.     keyAETextLineAscent    =    'ktas';
  102.     
  103. { optional keyword for Pos2Offset        }
  104.  
  105.     keyAELeftSide        =    'klef';                    { type Boolean }
  106.  
  107.  
  108. { optional keyword for kShowHideInputWindow    }
  109.  
  110.     keyAEShowHideInputWindow    =    'shiw';            { type Boolean }
  111.  
  112. { keyword for PinRange  }
  113.  
  114.     keyAEPinRange                =    'pnrg';            { <#6> }
  115.  
  116.  
  117. { Desc type ... }
  118.  
  119.     typeComponentInstance    =    'cmpi';                { Component instance }
  120.     typeTextRangeArray        =    'tray';                { Text range array }
  121.     typeOffsetArray            =    'ofay';                { Offset array }
  122.     typeText                =    'TEXT';                { Plain text }
  123.     
  124.     typeTextRange            =    'txrn';                { <#6> }
  125.  
  126.  
  127. {
  128.     Error codes
  129. }
  130.  
  131.     tsmComponentNoErr    =    0;                        { Component result = no error }
  132.     
  133.     tsmUnsupScriptLanguageErr    =    -2500;
  134.     tsmInputMethodNotFoundErr    =    -2501;
  135.     tsmNotAnAppErr                =    -2502;            { Not an application error }
  136.     tsmAlreadyRegisteredErr        =    -2503;            { Attemp to register again }
  137.     tsmNeverRegisteredErr        =    -2504;            { App never registered.  (Not TSM Aware) }
  138.     tsmInvalidDocIDErr            =    -2505;            { Invalid TSM documentation ID }
  139.     tsmTSMDocBusyErr            =    -2506;            { Document is still active }
  140.     tsmDocNotActiveErr            =    -2507;            { Document is not active }
  141.     tsmNoOpenTSErr                =    -2508;            { No open text service }
  142.     tsmCantOpenComponentErr        =    -2509;            { Can’t open the component }
  143.     tsmTextServiceNotFoundErr    =    -2510;            { No text service found }
  144.     tsmDocumentOpenErr            =    -2511;            { There are open documents }
  145.     tsmUseInputWindowErr        =    -2512;            { Not TSM aware because an input window is being used }
  146.     tsmTSHasNoMenuErr            =    -2513;            { The Text Service has no menu }
  147.     tsmTSNotOpenErr                =    -2514;            { Text service is not open }
  148.     tsmComponentAlreadyOpenErr    =    -2515;            { Text service already open for document }
  149.  
  150.     tsmInputMethodIsOldErr        =    -2516;            { Returned by GetDefaultInputMethod }
  151.     tsmScriptHasNoIMErr            =    -2517;            { Script has no input method or is using old input method }
  152.     tsmUnsupportedTypeErr        =    -2518;            { unSupported interface type error }
  153.     tsmUnknownErr                =    -2519;            { Any other errors }
  154.  
  155.     kTSMOutsideOfBody            =    1;
  156.     kTSMInsideOfBody            =    2;
  157.     kTSMInsideOfActiveInputArea    =    3;
  158.     
  159.     kNextBody                    =    1;
  160.     kPreviousBody                =    2;
  161.     
  162.     errOffsetInvalid            =    -1800;
  163.     errOffsetIsOutsideOfView    =    -1801;
  164.     errTopOfDocument            =    -1810;
  165.     errTopOfBody                =    -1811;
  166.     errEndOfDocument            =    -1812;
  167.     errEndOfBody                =    -1813;
  168.     
  169. TYPE
  170.     TextRangeHandle    =    ^TextRangePtr;
  171.     TextRangePtr    =    ^TextRange;
  172.     TextRange        =    Record                            { typeTextRange }
  173.                             fStart:            Longint;
  174.                             fEnd:            Longint;
  175.                             fHiliteStyle:    Integer;
  176.                         End;
  177.                         
  178.     TextRangeArrayHandle    =    ^TextRangeArrayPtr;
  179.     TextRangeArrayPtr        =    ^TextRangeArray;
  180.     TextRangeArray            =    Record                    { typeTextRangeArray }
  181.                                     fNumOfRanges:    Integer;
  182.                                     fRange:            Array [0..0] of TextRange;
  183.                                 End;
  184.                                 
  185.     OffsetArrayHandle    =    ^OffsetArrayPtr;
  186.     OffsetArrayPtr        =    ^OffsetArray;
  187.     OffsetArray            =    Record                        { typeOffsetArray }
  188.                                 fNumOfOffsets:    Integer;
  189.                                 fOffset:        Array [0..0] of Longint;
  190.                             End;
  191.  
  192.  
  193.     TextServicesInfoPtr    =    ^TextServiceInfo;
  194.     TextServiceInfo        =    Record
  195.                                 fComponent:        Component;
  196.                                 fItemName:        Str255;
  197.                             End;
  198.                             
  199.     TextServiceListHandle    =    ^TextServiceListPtr;
  200.     TextServiceListPtr        =    ^TextServiceList;
  201.     TextServiceList            =    Record
  202.                                     fTextServiceCount:    Integer;
  203.                                     fServices:             Array [0..0] of TextServiceInfo;
  204.                                 End;
  205.                             
  206.     ScriptLanguageRecord    =    Record
  207.                                     fScript:    ScriptCode;
  208.                                     fLanguage:    LangCode;
  209.                                 End;
  210.                                 
  211.     ScriptLanguageSupportHandle    =    ^ScriptLanguageSupportPtr;
  212.     ScriptLanguageSupportPtr    =    ^ScriptLanguageSupport;
  213.     ScriptLanguageSupport        =    Record
  214.                                         fScriptLanguageCount:    Integer;
  215.                                         fScriptLanguageArray:    Array [0..0] of ScriptLanguageRecord;
  216.                                     End;
  217.  
  218.     InterfaceTypeList    =    Array [0..0] of OSType;
  219.     
  220.     TSMDocumentID        =    Ptr;
  221.     
  222. {
  223.     Text Services Routines
  224. }
  225.  
  226. Function NewTSMDocument(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR idocID: TSMDocumentID; refCon: Longint): OSErr;
  227.     INLINE $303C, $0000, $AA54;
  228. Function DeleteTSMDocument(idocID: TSMDocumentID): OSErr;
  229.     INLINE $303C, $0001, $AA54;
  230. Function ActivateTSMDocument(idocID: TSMDocumentID): OSErr;
  231.     INLINE $303C, $0002, $AA54;
  232. Function DeactivateTSMDocument(idocID: TSMDocumentID): OSErr;
  233.     INLINE $303C, $0003, $AA54;
  234. Function TSMEvent(VAR event: EventRecord): Boolean;
  235.     INLINE $303C, $0004, $AA54;
  236. Function TSMMenuSelect(menuResult: Longint): Boolean;
  237.     INLINE $303C, $0005, $AA54;
  238. Function SetTSMCursor(mousePos: Point): Boolean;
  239.     INLINE $303C, $0006, $AA54;
  240. Function FixTSMDocument(idocID: TSMDocumentID): OSErr;
  241.     INLINE $303C, $0007, $AA54;
  242. Function GetServiceList(numOfInterface: Integer; supportedInterfaceTypes: InterfaceTypeList; VAR serviceInfo: TextServiceListHandle; VAR seedValue: Longint): OSErr;
  243.     INLINE $303C, $0008, $AA54;
  244. Function OpenTextService(idocID: TSMDocumentID; aComponent: Component; VAR aComponentInstance: ComponentInstance): OSErr;
  245.     INLINE $303C, $0009, $AA54;
  246. Function CloseTextService(idocID: TSMDocumentID; aComponentInstance: ComponentInstance): OSErr;
  247.     INLINE $303C, $000A, $AA54;
  248.  
  249. Function SendAEFromTSMComponent(VAR theAppleEvent: AppleEvent; VAR reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority; timeOutInTicks: Longint; idleProc: IdleProcPtr; filterProc: EventFilterProcPtr): OSErr;
  250.     INLINE $303C, $000B, $AA54;
  251. Function InitTSMAwareApplication: OSErr;
  252.     INLINE $303C, $0014, $AA54;
  253. Function CloseTSMAwareApplication: OSErr;
  254.     INLINE $303C, $0015, $AA54;
  255.  
  256.  
  257. Function SetDefaultInputMethod(ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  258.     INLINE $303C, $000C, $AA54;
  259. Function GetDefaultInputMethod(VAR ts: Component; VAR slRecord: ScriptLanguageRecord): OSErr;
  260.     INLINE $303C, $000D, $AA54;
  261. Function SetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  262.     INLINE $303C, $000E, $AA54;
  263. Function GetTextServiceLanguage(VAR slRecord: ScriptLanguageRecord): OSErr;
  264.     INLINE $303C, $000F, $AA54;
  265. Function UseInputWindow(idocID: TSMDocumentID; useWindow: Boolean): OSErr;
  266.     INLINE $303C, $0010, $AA54;
  267. Function NewServiceWindow(wStorage: Ptr; boundsRect: Rect; title: Str255; 
  268.     visible: Boolean; theProc: Integer; behind: WindowPtr; goAwayFlag: BOOLEAN;
  269.     ts: ComponentInstance; VAR window: WindowPtr): OSErr;
  270.     INLINE $303C, $0011, $AA54;
  271. Function CloseServiceWindow(window: WindowPtr): OSErr;
  272.     INLINE $303C, $0012, $AA54;
  273. Function GetFrontServiceWindow(VAR window: WindowPtr): OSErr;
  274.     INLINE $303C, $0013, $AA54;
  275. Function FindServiceWindow(thePoint: Point; VAR theWindow: WindowPtr): Integer;
  276.     INLINE $303C, $0017, $AA54;
  277.  
  278. {
  279.     Low level Text Services routines
  280. }
  281.  
  282. Function GetScriptLanguageSupport(ts: ComponentInstance; VAR scriptHandle: ScriptLanguageSupportHandle): ComponentResult;
  283.     INLINE $2F3C, $0400, $0001, $7000, $A82A;
  284. Function InitiateTextService(ts: ComponentInstance): ComponentResult;
  285.     INLINE $2F3C, $0000, $0002, $7000, $A82A;
  286. Function TerminateTextService(ts: ComponentInstance): ComponentResult;
  287.     INLINE $2F3C, $0000, $0003, $7000, $A82A;
  288. Function ActivateTextService(ts: ComponentInstance): ComponentResult;
  289.     INLINE $2F3C, $0000, $0004, $7000, $A82A;
  290. Function DeactivateTextService(ts: ComponentInstance): ComponentResult;
  291.     INLINE $2F3C, $0000, $0005, $7000, $A82A;
  292. Function TextServiceEvent(ts: ComponentInstance; numOfEvents: Integer; VAR event: EventRecord): ComponentResult;
  293.     INLINE $2F3C, $0000, $0006, $7000, $A82A;
  294. Function GetTextServiceMenu(ts: ComponentInstance; VAR serviceMenu: MenuHandle): ComponentResult;
  295.     INLINE $2F3C, $0000, $0007, $7000, $A82A;
  296. Function TextServiceMenuSelect(ts: ComponentInstance; serviceMenu: MenuHandle; item: Integer): ComponentResult;
  297.     INLINE $2F3C, $0000, $0008, $7000, $A82A;
  298. Function FixTextService(ts: ComponentInstance): ComponentResult;
  299.     INLINE $2F3C, $0000, $0009, $7000, $A82A;
  300. Function SetTextServiceCursor(ts: ComponentInstance; mousePos: Point): ComponentResult;
  301.     INLINE $2F3C, $0000, $000A, $7000, $A82A;
  302. Function HidePaletteWindows(ts: ComponentInstance): ComponentResult;
  303.     INLINE $2F3C, $0000, $000B, $7000, $A82A;
  304.  
  305.  
  306. {$ENDC} { UsingTextServices }
  307.  
  308. {$IFC NOT UsingIncludes}
  309.  END.
  310. {$ENDC}
  311.  
  312.