home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / Peter Lewis / PNL Libraries / TextServices.p < prev    next >
Encoding:
Text File  |  1994-08-04  |  14.3 KB  |  446 lines  |  [TEXT/PJMM]

  1. unit TextServices;
  2.  
  3. interface
  4.  
  5.     uses
  6.         Components, AppleEvents, Menus;
  7.  
  8.     const
  9.         gestaltTSMgrVersion = 'tsmv';
  10.  
  11.         kTSMVersion = 1;            { Version of the Text Services Manager }
  12.         kTextService = 'tsvc';    { component type for the component description }
  13.         kInputMethodService = 'inpm';    { component subtype for the component description }
  14.  
  15.         bTakeActiveEvent = 15;            { bit set if the component takes active event }
  16.         bScriptMask = $00007F00;{ bit 8 - 14 }
  17.         bLanguageMask = $000000FF;{ bit 0 - 7  }
  18.         bScriptLanguageMask = bScriptMask + bLanguageMask;    { bit 0 - 14  }
  19. {    •• ************************************** ••  }
  20.  
  21.  
  22. { Hilite styles ... }
  23.     type
  24.         HiliteStyleType = (kHiliteStyleTypeNone, kCursorPosition,                    { specify cursor position }
  25.             kRawText,                    { specify range of raw text }
  26.             kSelectedRawText,                    { specify range of selected raw text }
  27.             kConvertedText,                    { specify range of converted text }
  28.             kSelectedConvertedText);            { specify range of selected converted text }
  29.  
  30. {    •• ************************************** ••  }
  31.  
  32.  
  33. { Apple Event constants ... }
  34.  
  35. { Event class ... }
  36.     const
  37.         kTextServiceClass = kTextService;
  38.  
  39. { event ID ... }
  40.  
  41.         kUpdateActiveInputArea = 'updt';{ update the active Inline area }
  42.         kPos2Offset = 'p2st';        { converting global coordinates to char position }
  43.         kOffset2Pos = 'st2p';    { converting char position to global coordinates }
  44.         kShowHideInputWindow = 'shiw';    { show or hide the input window }
  45.  
  46. { Event keywords ... }
  47.  
  48.         keyAETSMDocumentRefcon = 'refc';    { TSM document refcon, typeLongInteger        <#45> }
  49.  
  50.  
  51.         keyAEServerInstance = 'srvi';    { component instance }
  52.         keyAETheData = 'kdat';        { typeText }
  53.         keyAEScriptTag = 'sclg';    { script tag }
  54.         keyAEFixLength = 'fixl';    { fix len ?? }
  55.         keyAEHiliteRange = 'hrng';    { hilite range array }
  56.         keyAEUpdateRange = 'udng';    { update range array }
  57.         keyAEClauseOffsets = 'clau';    { Clause Offsets array }
  58.  
  59.         keyAECurrentPoint = 'cpos';    { current point }
  60.         keyAEDragging = 'bool';    { dragging falg }
  61.         keyAEOffset = 'ofst';    { offset }
  62.         keyAERegionClass = 'rgnc';        { region class }
  63.         keyAEPoint = 'gpos';        { current point }
  64.         keyAEBufferSize = 'buff';{ buffer size to get the text }
  65.         keyAERequestedType = 'rtyp';    { requested text type }
  66.         keyAEMoveView = 'mvvw';    { move view flag }
  67.         keyAELength = 'leng';    { length }
  68.         keyAENextBody = 'nxbd';    { next or previous body }
  69.  
  70.  
  71. { optional keywords for Offset2Pos                    -- 28Mar92 <#38> }
  72.         keyAETextFont = 'ktxf';
  73.         keyAETextPointSize = 'ktps';
  74.         keyAETextLineHeight = 'ktlh';
  75.         keyAETextLineAscent = 'ktas';
  76.         keyAEAngle = 'kang';
  77.  
  78.  
  79. { optional keywords for Pos2Offset                    -- 20May92 <#44> }
  80.         keyAELeftSide = 'klef';    { type Boolean }
  81.  
  82. { optional keywords for kShowHideInputWindow    -- <#48> }
  83.         keyAEShowHideInputWindow = 'shiw';    { type Boolean }
  84.  
  85. { for PinRange  }
  86.         keyAEPinRange = 'pnrg';    { <#49> }
  87.  
  88. { Desc type ... }
  89.  
  90.         typeComponentInstance = 'cmpi';    { server instance }
  91.         typeTextRangeArray = 'tray';    { text range array }
  92.         typeOffsetArray = 'ofay';    { offset array }
  93.         typeIntlWritingCode = 'intl';    { script code }
  94.         typeQDPoint = 'QDpt';        { QuickDraw Point }
  95.         typeAEText = 'tTXT';    { Apple Event text }
  96.         typeText = 'TEXT';    { Plain text }
  97.  
  98.         typeTextRange = 'txrn';    { <#49> }
  99.  
  100.  
  101.  
  102. { error codes }
  103.     const
  104.         tsmComponentNoErr = 0;            { component result = no error }
  105.  
  106.  
  107.         tsmUnsupScriptLanguageErr = -2500;
  108.         tsmInputMethodNotFoundErr = -2501;
  109.         tsmNotAnAppErr = -2502;        { not an application error}
  110.         tsmAlreadyRegisteredErr = -2503;    { want to register again error}
  111.         tsmNeverRegisteredErr = -2504;    { app never registered error (not TSM aware)}
  112.         tsmInvalidDocIDErr = -2505;    { invalid TSM documentation id}
  113.         tsmTSMDocBusyErr = -2506;        { document is still active}
  114.         tsmDocNotActiveErr = -2507;    { document is NOT active}
  115.         tsmNoOpenTSErr = -2508;        { no open text service}
  116.         tsmCantOpenComponentErr = -2509;    { can't open the component}
  117.         tsmTextServiceNotFoundErr = -2510;    { no text service found}
  118.         tsmDocumentOpenErr = -2511;    { there are open documents}
  119.         tsmUseInputWindowErr = -2512;        { not TSM aware because we are using input window}
  120.         tsmTSHasNoMenuErr = -2513;        { the text service has no menu}
  121.         tsmTSNotOpenErr = -2514;    { text service is not open}
  122.         tsmComponentAlreadyOpenErr = -2515;    { text service already opened for the document}
  123.  
  124.         tsmInputMethodIsOldErr = -2516;    { returned by GetDefaultInputMethod}
  125.         tsmScriptHasNoIMErr = -2517;    { script has no imput method or is using old IM.}
  126.         tsmUnsupportedTypeErr = -2518;    { unSupported interface type error}
  127.         tsmUnknownErr = -2519;        { any other errors}
  128.  
  129.  
  130.  
  131.  
  132. { Desc type constants }
  133.  
  134.     type
  135.         AERegionClassType = (kAERegionClassTypeNone, kTSMOutsideOfBody, kTSMInsideOfBody, kTSMInsideOfActiveInputArea);
  136.  
  137.         AENextBodyType = (kAENextBodyTypeNone, kNextBody, kPreviousBody);
  138.  
  139.  
  140. { Apple Event error definitions }
  141.  
  142.     type
  143.         AppleEventErrorType = integer; { longint???? }
  144.     const
  145.         errOffsetInvalid = -1800;
  146.         errOffsetIsOutsideOfView = -1801;
  147.         errTopOfDocument = -1810;
  148.         errTopOfBody = -1811;
  149.         errEndOfDocument = -1812;
  150.         errEndOfBody = -1813;
  151.  
  152. {    •• ************************************** ••  }
  153.  
  154.  
  155.     type
  156.         TextRange = record                    { typeTextRange         'txrn' }
  157.                 fStart: longInt;
  158.                 fEnd: longInt;
  159.                 fHiliteStyle: integer;
  160.             end;
  161.  
  162.         TextRangePtr = ^TextRange;
  163.         TextRangeHandle = ^TextRangePtr;
  164.  
  165.  
  166.         TextRangeArray = record                { typeTextRangeArray    'txra' }
  167.                 fNumOfRanges: integer;            { specify the size of the fRange array }
  168.                 fRange: array[0..0] of TextRange;            { when fNumOfRanges > 1, the size of this array has to be calculated }
  169.             end;
  170.  
  171.         TextRangeArrayPtr = ^TextRangeArray;
  172.         TextRangeArrayHandle = ^TextRangeArrayPtr;
  173.  
  174.  
  175.  
  176.         OffsetArray = record                    { typeOffsetArray        'offa' }
  177.                 fNumOfOffsets: integer;                { specify the size of the fOffset array }
  178.                 fOffset: array[0..0] of longInt;                    { when fNumOfOffsets > 1, the size of this array has to be calculated }
  179.             end;
  180.         OffsetArrayPtr = ^OffsetArray;
  181.         OffsetArrayHandle = ^OffsetArrayPtr;
  182.  
  183. {    •• ************************************** ••  }
  184.  
  185.  
  186. { extract Script/Language code from Component flag ... }
  187. {#define        mGetScriptCode(cdRec)        ((ScriptCode)    ((cdRec.componentFlags & bScriptMask) >> 8))}
  188. {#define        mGetLanguageCode(cdRec)        ((LangCode)        cdRec.componentFlags & bLanguageMask)}
  189.  
  190.  
  191.     type
  192.         TSMDocumentID = ptr; { opaque }
  193.  
  194. {    •• ************************************** ••  }
  195.  
  196.  
  197. { *    Text Service Info List }
  198.     type
  199.         TextServiceInfo = record
  200.                 fComponent: Component;
  201.                 fItemName: Str255;
  202.             end;
  203.         TextServiceInfoPtr = ^TextServiceInfo;
  204.  
  205.         TextServiceList = record
  206.                 fTextServiceCount: integer;                { number of entries in the 'fServices' array }
  207.                 fServices: array[0..0] of TextServiceInfo;{ Note: array of 'TextServiceInfo' records follows }
  208.             end;
  209.         TextServiceListPtr = ^TextServiceList;
  210.         TextServiceListHandle = ^TextServiceListPtr;
  211.  
  212.         ScriptLanguageRecord = record
  213.                 fScript: ScriptCode;
  214.                 fLanguage: LangCode;
  215.             end;
  216.  
  217.         ScriptLanguageSupport = record
  218.                 fScriptLanguageCount: integer;        { number of entries in the 'fScriptLanguageArray' array }
  219.                 fScriptLanguageArray: array[0..0] of ScriptLanguageRecord;    { Note: array of 'ScriptLanguageRecord' records follows }
  220.             end;
  221.         ScriptLanguageSupportPtr = ^ScriptLanguageSupport;
  222.         ScriptLanguageSupportHandle = ^ScriptLanguageSupportPtr;
  223.  
  224. {    •• ************************************** ••  }
  225.  
  226.  
  227.     const
  228.         TSMTrapNum = $AA54;
  229.  
  230. { ••    Text Services Manager function selectors ... }
  231.  
  232. { ••    High level routines ... }
  233.         kNewTSMDocument = 0;{ create new TSM aware document}
  234.         kDeleteTSMDocument = 1;    { delete TSM aware document}
  235.         kActivateTSMDocument = 2;        { activate TSM aware document}
  236.         kDeactivateTSMDocument = 3;    { deactivate TSM aware document}
  237.         kTSMEvent = 4;        { pass all events to TSM}
  238.         kTSMMenuSelect = 5;        { pass menu selection to TSM}
  239.         kSetTSMCursor = 6;        { set the cursor}
  240.         kFixTSMDocument = 7;    { terminate text services}
  241.         kGetServiceList = 8;    { get all text service components}
  242.         kOpenTextService = 9;        { open  the text service}
  243.         kCloseTextService = 10;        { close the text service}
  244.         kSendAEFromTSMComponent = 11;    { send Apple Event to client}
  245.  
  246.  
  247. { ••    Utilities ... }
  248.  
  249.         kSetDefaultInputMethod = 12;
  250.         kGetDefaultInputMethod = 13;    { 0x0D }
  251.         kSetTextServiceLanguage = 14;    { Called by Script Mgr }
  252.         kGetTextServiceLanguage = 15;
  253.         kUseInputWindow = 16;
  254.         kNewServiceWindow = 17;
  255.         kCloseServiceWindow = 18;
  256.         kGetFrontServiceWindow = 19;
  257.  
  258.  
  259.         kInitTSMAwareApplication = 20;    { claim TSM aware application }
  260.         kCloseTSMAwareApplication = 21;    { application deregisters itself as TSM aware }
  261.  
  262.         kFindServiceWindow = 23;
  263.  
  264.  
  265. {    •• ************************************** ••  }
  266.  
  267.     type
  268.         OSTypeArray = array[0..0] of OSType;
  269.  
  270. { High level TSM routines .. }
  271.  
  272.     function NewTSMDocument (numOfInterface: integer; supportedInterfaceTypes: OSTypeArray; var idocID: TSMDocumentID; refcon: longInt): OSErr;
  273.     inline
  274.         $303C, $0000, $AA54;
  275.  
  276.     function DeleteTSMDocument (idocID: TSMDocumentID): OSErr;
  277.     inline
  278.         $303C, $0001, $AA54;
  279.  
  280.     function ActivateTSMDocument (idocID: TSMDocumentID): OSErr;
  281.     inline
  282.         $303C, $0002, $AA54;
  283.  
  284.     function DeactivateTSMDocument (idocID: TSMDocumentID): OSErr;
  285.     inline
  286.         $303C, $0003, $AA54;
  287.  
  288.     function TSMEvent (var event: EventRecord): Boolean;                                    { pass all events to TSM (removed TSMDocumentID #35)}
  289.     inline
  290.         $303C, $0004, $AA54;
  291.  
  292.     function TSMMenuSelect (menuResult: longInt): Boolean;                                { pass menu selection to TSM (removed TSMDocumentID #35)}
  293.     inline
  294.         $303C, $0005, $AA54;
  295.  
  296.     function SetTSMCursor (mousePos: Point): Boolean;                                    { set the cursor (removed TSMDocumentID #35)}
  297.     inline
  298.         $303C, $0006, $AA54;
  299.  
  300.     function FixTSMDocument (idocID: TSMDocumentID): OSErr;                            { terminate text services}
  301.     inline
  302.         $303C, $0007, $AA54;
  303.  
  304.     function GetServiceList (numOfInterface: integer; supportedInterfaceTypes: OSTypeArray; var serviceInfo: TextServiceListHandle; var seedValue: longInt): OSErr;                    { get all text services}
  305.     inline
  306.         $303C, $0008, $AA54;
  307.  
  308.     function OpenTextService (idocID: TSMDocumentID; aComponent: Component; var aComponentInstance: ComponentInstance): OSErr;
  309.     inline
  310.         $303C, $0009, $AA54;                                    { open the text service (return instance)}
  311.  
  312.     function CloseTextService (idocID: TSMDocumentID; aComponent: Component): OSErr;
  313.     inline
  314.         $303C, $000A, $AA54;                                     { close the text service (return instance)}
  315.  
  316.  
  317.  
  318. { Sending callback AppleEvents ... }
  319.     function SendAEFromTSMComponent (var event: AppleEvent;    { should be a pointer }
  320.                                     var reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority; timeOutInTicks: longint; idleProc: IdleProcPtr; filterProc: EventFilterProcPtr): OSErr;
  321.     inline
  322.         $303C, $000B, $AA54;
  323.  
  324.     function InitTSMAwareApplication: OSErr;                                    { app registers itself as TSM aware}
  325.     inline
  326.         $303C, $0014, $AA54;
  327.  
  328.  
  329.     function CloseTSMAwareApplication: OSErr;                                    { app deregisters itself when quit}
  330.     inline
  331.         $303C, $0015, $AA54;
  332.  
  333.  
  334. { ••  Utilities ... }
  335.     function SetDefaultInputMethod (ts: Component; var slRecordPtr: ScriptLanguageRecord): OSErr;
  336.     inline
  337.         $303C, $000C, $AA54;
  338.  
  339.     function GetDefaultInputMethod (var ts: Component; var slRecordPtr: ScriptLanguageRecord): OSErr;
  340.     inline
  341.         $303C, $000D, $AA54;
  342.  
  343.     function SetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr;
  344.     inline
  345.         $303C, $000E, $AA54;
  346.  
  347.     function GetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr;
  348.     inline
  349.         $303C, $000F, $AA54;
  350.  
  351.     function UseInputWindow (idocID: TSMDocumentID; useWindow: Boolean): OSErr;
  352.     inline
  353.         $303C, $0010, $AA54;
  354.  
  355.     function NewServiceWindow (wStorage: ptr; boundsRect: rect; title: str255; visible: Boolean; theProc: integer; behind: WindowPtr; goAwayFlag: Boolean; ts: ComponentInstance; var window: WindowPtr): OSErr;
  356.     inline
  357.         $303C, $0011, $AA54;
  358.  
  359.     function CloseServiceWindow (window: WindowPtr): OSErr;
  360.     inline
  361.         $303C, $0012, $AA54;
  362.  
  363.     function GetFrontServiceWindow (var window: WindowPtr): OSErr;
  364.     inline
  365.         $303C, $0013, $AA54;
  366.  
  367.     function FindServiceWindow (thePoint: Point; var window: WindowPtr): integer;
  368.     inline
  369.         $303C, $0017, $AA54;
  370.  
  371.  
  372.  
  373. { ••    Low level routines which are dispatched directly to the Component Manager ... }
  374.     const
  375.         kCMGetScriptLangSupport = $0001;    { Component Manager call selector 1}
  376.         kCMInitiateTextService = $0002;    { Component Manager call selector 2}
  377.         kCMTerminateTextService = $0003;    { Component Manager call selector 3}
  378.         kCMActivateTextService = $0004;    { Component Manager call selector 4}
  379.         kCMDeactivateTextService = $0005;    { Component Manager call selector 5}
  380.         kCMTextServiceEvent = $0006;    { Component Manager call selector 6}
  381.         kCMGetTextServiceMenu = $0007;    { Component Manager call selector 7}
  382.         kCMTextServiceMenuSelect = $0008;    { Component Manager call selector 8}
  383.         kCMFixTextService = $0009;        { Component Manager call selector 9}
  384.         kCMSetTextServiceCursor = $000A;{ Component Manager call selector 10}
  385.         kCMHidePaletteWindows = $000B;    { Component Manager call selector 11    }
  386.  
  387.  
  388. { ••  Low level TSM routines ... }
  389.  
  390.     function GetScriptLanguageSupport (ts: ComponentInstance; var scriptHdl: ScriptLanguageSupportHandle): ComponentResult;
  391.     inline
  392.         $2F3C, $0004, $0001, $7000, $A82A;            { selector = 1 }
  393.  
  394.  
  395.     function InitiateTextService (ts: ComponentInstance): ComponentResult;
  396.     inline
  397.         $2F3C, $0000, $0002, $7000, $A82A;            { selector = 2 }
  398.  
  399.  
  400.     function TerminateTextService (ts: ComponentInstance): ComponentResult;
  401.     inline
  402.         $2F3C, $0000, $0003, $7000, $A82A;            { selector = 3 }
  403.  
  404.  
  405.     function ActivateTextService (ts: ComponentInstance): ComponentResult;
  406.     inline
  407.         $2F3C, $0000, $0004, $7000, $A82A;            { selector = 4 }
  408.  
  409.  
  410.     function DeactivateTextService (ts: ComponentInstance): ComponentResult;
  411.     inline
  412.         $2F3C, $0000, $0005, $7000, $A82A;            { selector = 5 }
  413.  
  414.  
  415.     function TextServiceEvent (ts: ComponentInstance; numOfEvents: integer; var event: EventRecord): ComponentResult;
  416.     inline
  417.         $2F3C, $0006, $0006, $7000, $A82A;                { selector = 6 }
  418.  
  419.  
  420.     function GetTextServiceMenu (ts: ComponentInstance; var serviceMenu: MenuHandle): ComponentResult;
  421.     inline
  422.         $2F3C, $0004, $0007, $7000, $A82A;                { selector = 7 }
  423.  
  424.  
  425.     function TextServiceMenuSelect (ts: ComponentInstance; serviceMenu: MenuHandle; item: integer): ComponentResult;
  426.     inline
  427.         $2F3C, $0006, $0008, $7000, $A82A;            { selector = 8 }
  428.  
  429.  
  430.     function FixTextService (ts: ComponentInstance): ComponentResult;
  431.     inline
  432.         $2F3C, $0000, $0009, $7000, $A82A;                    { selector = 9 }
  433.  
  434.  
  435.     function SetTextServiceCursor (ts: ComponentInstance; mousePos: Point): ComponentResult;
  436.     inline
  437.         $2F3C, $0004, $000A, $7000, $A82A;            { selector = 10 }
  438.  
  439.  
  440.     function HidePaletteWindows (ts: ComponentInstance): ComponentResult;
  441.     inline
  442.         $2F3C, $0000, $000B, $7000, $A82A;                { selector = 11                    <#37> }
  443.  
  444. implementation
  445.  
  446. end.