home *** CD-ROM | disk | FTP | other *** search
Wrap
Text File | 1994-08-04 | 14.3 KB | 446 lines | [ TEXT/PJMM]
unit TextServices; interface uses Components, AppleEvents, Menus; const gestaltTSMgrVersion = 'tsmv'; kTSMVersion = 1; { Version of the Text Services Manager } kTextService = 'tsvc'; { component type for the component description } kInputMethodService = 'inpm'; { component subtype for the component description } bTakeActiveEvent = 15; { bit set if the component takes active event } bScriptMask = $00007F00;{ bit 8 - 14 } bLanguageMask = $000000FF;{ bit 0 - 7 } bScriptLanguageMask = bScriptMask + bLanguageMask; { bit 0 - 14 } { •• ************************************** •• } { Hilite styles ... } type HiliteStyleType = (kHiliteStyleTypeNone, kCursorPosition, { specify cursor position } kRawText, { specify range of raw text } kSelectedRawText, { specify range of selected raw text } kConvertedText, { specify range of converted text } kSelectedConvertedText); { specify range of selected converted text } { •• ************************************** •• } { Apple Event constants ... } { Event class ... } const kTextServiceClass = kTextService; { event ID ... } kUpdateActiveInputArea = 'updt';{ update the active Inline area } kPos2Offset = 'p2st'; { converting global coordinates to char position } kOffset2Pos = 'st2p'; { converting char position to global coordinates } kShowHideInputWindow = 'shiw'; { show or hide the input window } { Event keywords ... } keyAETSMDocumentRefcon = 'refc'; { TSM document refcon, typeLongInteger <#45> } keyAEServerInstance = 'srvi'; { component instance } keyAETheData = 'kdat'; { typeText } keyAEScriptTag = 'sclg'; { script tag } keyAEFixLength = 'fixl'; { fix len ?? } keyAEHiliteRange = 'hrng'; { hilite range array } keyAEUpdateRange = 'udng'; { update range array } keyAEClauseOffsets = 'clau'; { Clause Offsets array } keyAECurrentPoint = 'cpos'; { current point } keyAEDragging = 'bool'; { dragging falg } keyAEOffset = 'ofst'; { offset } keyAERegionClass = 'rgnc'; { region class } keyAEPoint = 'gpos'; { current point } keyAEBufferSize = 'buff';{ buffer size to get the text } keyAERequestedType = 'rtyp'; { requested text type } keyAEMoveView = 'mvvw'; { move view flag } keyAELength = 'leng'; { length } keyAENextBody = 'nxbd'; { next or previous body } { optional keywords for Offset2Pos -- 28Mar92 <#38> } keyAETextFont = 'ktxf'; keyAETextPointSize = 'ktps'; keyAETextLineHeight = 'ktlh'; keyAETextLineAscent = 'ktas'; keyAEAngle = 'kang'; { optional keywords for Pos2Offset -- 20May92 <#44> } keyAELeftSide = 'klef'; { type Boolean } { optional keywords for kShowHideInputWindow -- <#48> } keyAEShowHideInputWindow = 'shiw'; { type Boolean } { for PinRange } keyAEPinRange = 'pnrg'; { <#49> } { Desc type ... } typeComponentInstance = 'cmpi'; { server instance } typeTextRangeArray = 'tray'; { text range array } typeOffsetArray = 'ofay'; { offset array } typeIntlWritingCode = 'intl'; { script code } typeQDPoint = 'QDpt'; { QuickDraw Point } typeAEText = 'tTXT'; { Apple Event text } typeText = 'TEXT'; { Plain text } typeTextRange = 'txrn'; { <#49> } { error codes } const tsmComponentNoErr = 0; { component result = no error } tsmUnsupScriptLanguageErr = -2500; tsmInputMethodNotFoundErr = -2501; tsmNotAnAppErr = -2502; { not an application error} tsmAlreadyRegisteredErr = -2503; { want to register again error} tsmNeverRegisteredErr = -2504; { app never registered error (not TSM aware)} tsmInvalidDocIDErr = -2505; { invalid TSM documentation id} tsmTSMDocBusyErr = -2506; { document is still active} tsmDocNotActiveErr = -2507; { document is NOT active} tsmNoOpenTSErr = -2508; { no open text service} tsmCantOpenComponentErr = -2509; { can't open the component} tsmTextServiceNotFoundErr = -2510; { no text service found} tsmDocumentOpenErr = -2511; { there are open documents} tsmUseInputWindowErr = -2512; { not TSM aware because we are using input window} tsmTSHasNoMenuErr = -2513; { the text service has no menu} tsmTSNotOpenErr = -2514; { text service is not open} tsmComponentAlreadyOpenErr = -2515; { text service already opened for the document} tsmInputMethodIsOldErr = -2516; { returned by GetDefaultInputMethod} tsmScriptHasNoIMErr = -2517; { script has no imput method or is using old IM.} tsmUnsupportedTypeErr = -2518; { unSupported interface type error} tsmUnknownErr = -2519; { any other errors} { Desc type constants } type AERegionClassType = (kAERegionClassTypeNone, kTSMOutsideOfBody, kTSMInsideOfBody, kTSMInsideOfActiveInputArea); AENextBodyType = (kAENextBodyTypeNone, kNextBody, kPreviousBody); { Apple Event error definitions } type AppleEventErrorType = integer; { longint???? } const errOffsetInvalid = -1800; errOffsetIsOutsideOfView = -1801; errTopOfDocument = -1810; errTopOfBody = -1811; errEndOfDocument = -1812; errEndOfBody = -1813; { •• ************************************** •• } type TextRange = record { typeTextRange 'txrn' } fStart: longInt; fEnd: longInt; fHiliteStyle: integer; end; TextRangePtr = ^TextRange; TextRangeHandle = ^TextRangePtr; TextRangeArray = record { typeTextRangeArray 'txra' } fNumOfRanges: integer; { specify the size of the fRange array } fRange: array[0..0] of TextRange; { when fNumOfRanges > 1, the size of this array has to be calculated } end; TextRangeArrayPtr = ^TextRangeArray; TextRangeArrayHandle = ^TextRangeArrayPtr; OffsetArray = record { typeOffsetArray 'offa' } fNumOfOffsets: integer; { specify the size of the fOffset array } fOffset: array[0..0] of longInt; { when fNumOfOffsets > 1, the size of this array has to be calculated } end; OffsetArrayPtr = ^OffsetArray; OffsetArrayHandle = ^OffsetArrayPtr; { •• ************************************** •• } { extract Script/Language code from Component flag ... } {#define mGetScriptCode(cdRec) ((ScriptCode) ((cdRec.componentFlags & bScriptMask) >> 8))} {#define mGetLanguageCode(cdRec) ((LangCode) cdRec.componentFlags & bLanguageMask)} type TSMDocumentID = ptr; { opaque } { •• ************************************** •• } { * Text Service Info List } type TextServiceInfo = record fComponent: Component; fItemName: Str255; end; TextServiceInfoPtr = ^TextServiceInfo; TextServiceList = record fTextServiceCount: integer; { number of entries in the 'fServices' array } fServices: array[0..0] of TextServiceInfo;{ Note: array of 'TextServiceInfo' records follows } end; TextServiceListPtr = ^TextServiceList; TextServiceListHandle = ^TextServiceListPtr; ScriptLanguageRecord = record fScript: ScriptCode; fLanguage: LangCode; end; ScriptLanguageSupport = record fScriptLanguageCount: integer; { number of entries in the 'fScriptLanguageArray' array } fScriptLanguageArray: array[0..0] of ScriptLanguageRecord; { Note: array of 'ScriptLanguageRecord' records follows } end; ScriptLanguageSupportPtr = ^ScriptLanguageSupport; ScriptLanguageSupportHandle = ^ScriptLanguageSupportPtr; { •• ************************************** •• } const TSMTrapNum = $AA54; { •• Text Services Manager function selectors ... } { •• High level routines ... } kNewTSMDocument = 0;{ create new TSM aware document} kDeleteTSMDocument = 1; { delete TSM aware document} kActivateTSMDocument = 2; { activate TSM aware document} kDeactivateTSMDocument = 3; { deactivate TSM aware document} kTSMEvent = 4; { pass all events to TSM} kTSMMenuSelect = 5; { pass menu selection to TSM} kSetTSMCursor = 6; { set the cursor} kFixTSMDocument = 7; { terminate text services} kGetServiceList = 8; { get all text service components} kOpenTextService = 9; { open the text service} kCloseTextService = 10; { close the text service} kSendAEFromTSMComponent = 11; { send Apple Event to client} { •• Utilities ... } kSetDefaultInputMethod = 12; kGetDefaultInputMethod = 13; { 0x0D } kSetTextServiceLanguage = 14; { Called by Script Mgr } kGetTextServiceLanguage = 15; kUseInputWindow = 16; kNewServiceWindow = 17; kCloseServiceWindow = 18; kGetFrontServiceWindow = 19; kInitTSMAwareApplication = 20; { claim TSM aware application } kCloseTSMAwareApplication = 21; { application deregisters itself as TSM aware } kFindServiceWindow = 23; { •• ************************************** •• } type OSTypeArray = array[0..0] of OSType; { High level TSM routines .. } function NewTSMDocument (numOfInterface: integer; supportedInterfaceTypes: OSTypeArray; var idocID: TSMDocumentID; refcon: longInt): OSErr; inline $303C, $0000, $AA54; function DeleteTSMDocument (idocID: TSMDocumentID): OSErr; inline $303C, $0001, $AA54; function ActivateTSMDocument (idocID: TSMDocumentID): OSErr; inline $303C, $0002, $AA54; function DeactivateTSMDocument (idocID: TSMDocumentID): OSErr; inline $303C, $0003, $AA54; function TSMEvent (var event: EventRecord): Boolean; { pass all events to TSM (removed TSMDocumentID #35)} inline $303C, $0004, $AA54; function TSMMenuSelect (menuResult: longInt): Boolean; { pass menu selection to TSM (removed TSMDocumentID #35)} inline $303C, $0005, $AA54; function SetTSMCursor (mousePos: Point): Boolean; { set the cursor (removed TSMDocumentID #35)} inline $303C, $0006, $AA54; function FixTSMDocument (idocID: TSMDocumentID): OSErr; { terminate text services} inline $303C, $0007, $AA54; function GetServiceList (numOfInterface: integer; supportedInterfaceTypes: OSTypeArray; var serviceInfo: TextServiceListHandle; var seedValue: longInt): OSErr; { get all text services} inline $303C, $0008, $AA54; function OpenTextService (idocID: TSMDocumentID; aComponent: Component; var aComponentInstance: ComponentInstance): OSErr; inline $303C, $0009, $AA54; { open the text service (return instance)} function CloseTextService (idocID: TSMDocumentID; aComponent: Component): OSErr; inline $303C, $000A, $AA54; { close the text service (return instance)} { Sending callback AppleEvents ... } function SendAEFromTSMComponent (var event: AppleEvent; { should be a pointer } var reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority; timeOutInTicks: longint; idleProc: IdleProcPtr; filterProc: EventFilterProcPtr): OSErr; inline $303C, $000B, $AA54; function InitTSMAwareApplication: OSErr; { app registers itself as TSM aware} inline $303C, $0014, $AA54; function CloseTSMAwareApplication: OSErr; { app deregisters itself when quit} inline $303C, $0015, $AA54; { •• Utilities ... } function SetDefaultInputMethod (ts: Component; var slRecordPtr: ScriptLanguageRecord): OSErr; inline $303C, $000C, $AA54; function GetDefaultInputMethod (var ts: Component; var slRecordPtr: ScriptLanguageRecord): OSErr; inline $303C, $000D, $AA54; function SetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr; inline $303C, $000E, $AA54; function GetTextServiceLanguage (var slRecordPtr: ScriptLanguageRecord): OSErr; inline $303C, $000F, $AA54; function UseInputWindow (idocID: TSMDocumentID; useWindow: Boolean): OSErr; inline $303C, $0010, $AA54; function NewServiceWindow (wStorage: ptr; boundsRect: rect; title: str255; visible: Boolean; theProc: integer; behind: WindowPtr; goAwayFlag: Boolean; ts: ComponentInstance; var window: WindowPtr): OSErr; inline $303C, $0011, $AA54; function CloseServiceWindow (window: WindowPtr): OSErr; inline $303C, $0012, $AA54; function GetFrontServiceWindow (var window: WindowPtr): OSErr; inline $303C, $0013, $AA54; function FindServiceWindow (thePoint: Point; var window: WindowPtr): integer; inline $303C, $0017, $AA54; { •• Low level routines which are dispatched directly to the Component Manager ... } const kCMGetScriptLangSupport = $0001; { Component Manager call selector 1} kCMInitiateTextService = $0002; { Component Manager call selector 2} kCMTerminateTextService = $0003; { Component Manager call selector 3} kCMActivateTextService = $0004; { Component Manager call selector 4} kCMDeactivateTextService = $0005; { Component Manager call selector 5} kCMTextServiceEvent = $0006; { Component Manager call selector 6} kCMGetTextServiceMenu = $0007; { Component Manager call selector 7} kCMTextServiceMenuSelect = $0008; { Component Manager call selector 8} kCMFixTextService = $0009; { Component Manager call selector 9} kCMSetTextServiceCursor = $000A;{ Component Manager call selector 10} kCMHidePaletteWindows = $000B; { Component Manager call selector 11 } { •• Low level TSM routines ... } function GetScriptLanguageSupport (ts: ComponentInstance; var scriptHdl: ScriptLanguageSupportHandle): ComponentResult; inline $2F3C, $0004, $0001, $7000, $A82A; { selector = 1 } function InitiateTextService (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $0002, $7000, $A82A; { selector = 2 } function TerminateTextService (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $0003, $7000, $A82A; { selector = 3 } function ActivateTextService (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $0004, $7000, $A82A; { selector = 4 } function DeactivateTextService (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $0005, $7000, $A82A; { selector = 5 } function TextServiceEvent (ts: ComponentInstance; numOfEvents: integer; var event: EventRecord): ComponentResult; inline $2F3C, $0006, $0006, $7000, $A82A; { selector = 6 } function GetTextServiceMenu (ts: ComponentInstance; var serviceMenu: MenuHandle): ComponentResult; inline $2F3C, $0004, $0007, $7000, $A82A; { selector = 7 } function TextServiceMenuSelect (ts: ComponentInstance; serviceMenu: MenuHandle; item: integer): ComponentResult; inline $2F3C, $0006, $0008, $7000, $A82A; { selector = 8 } function FixTextService (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $0009, $7000, $A82A; { selector = 9 } function SetTextServiceCursor (ts: ComponentInstance; mousePos: Point): ComponentResult; inline $2F3C, $0004, $000A, $7000, $A82A; { selector = 10 } function HidePaletteWindows (ts: ComponentInstance): ComponentResult; inline $2F3C, $0000, $000B, $7000, $A82A; { selector = 11 <#37> } implementation end.