Summary of the Text Services Manager
Pascal Summary
Constants
CONST
kTSMVersion = 1; {Version of Text Services Manager}
kTextService = 'tsvc'; {Component type for component description}
kInputMethodService = 'inpm'; {Component subtype for component desc.}
bTakeActiveEvent = 15; {Bit set if component takes activate events}
bScriptMask = $00007F00; {Bits 8 - 14}
bLanguageMask = $000000FF; {Bits 0 - 7}
bScriptLanguageMask = ScriptMask + bLanguageMask; {Bits 0 - 14}
{Hilite styles}
kCaretPosition = 1; {specify caret position}
kRawText = 2; {specify range of raw text}
kSelectedRawText = 3; {specify range of selected raw text}
kConvertedText = 4; {specify range of converted text}
kSelectedConvertedText = 5; {specify range of selected converted text}
{Apple Event constants}
kTextServiceClass = kTextService; {Event class}
kUpdateActiveInputArea = 'updt'; {Update active inline area}
kPos2Offset = 'p2st'; {Convert global coordinates to }
{ character position}
kOffset2Pos = 'st2p'; {Convert character position to }
{ global coordinate}
kShowHideInputWindow = 'shiw'; {show or hide the input window}
{Event keywords}
keyAETSMDocumentRefcon = 'refc'; {TSM document refcon}
keyAEServerInstance = 'srvi'; {Server instance}
keyAETheData = 'kdat'; {typeText}
keyAEScriptTag = 'sclg'; {Script tag}
keyAEFixLength = 'fixl';
keyAEHiliteRange = 'hrng'; {Hilite range array}
keyAEUpdateRange = 'udng'; {Update range array}
keyAEClauseOffsets = 'clau'; {Clause offsets array}
keyAECurrentPoint = 'cpos'; {Current point}
keyAEDragging = 'bool'; {Dragging flag}
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}
keyAETextFont = 'ktxf';
keyAETextPointSize = 'ktps';
keyAETextLineHeight = 'ktlh';
keyAETextLineAscent = 'ktas';
keyAEAngle = 'kang';
{optional keyword for Pos2Offset}
keyAELeftSide = 'klef'; {type Boolean}
{optional keyword for kShowHideInputWindow}
keyAEShowHideInputWindow = 'shiw'; {type Boolean}
{keyword for PinRange}
keyAEPinRange = 'pnrg';
{Desc type ...}
typeComponentInstance = 'cmpi'; {component instance}
typeTextRange = 'txrn'; {text range}
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}
{Apple event descriptor type constants}
kTSMOutsideOfBody = 1;
kTSMInsideOfBody = 2;
kTSMInsideOfActiveInputArea = 3;
kNextBody = 1;
kPreviousBody = 2;
{Apple event error constants}
errOffsetInvalid = -1800;
errOffsetIsOutsideOfView = -1801;
errTopOfDocument = -1810;
errTopOfBody = -1811;
errEndOfDocument = -1812;
errEndOfBody = -1813;
Data Types
TYPE TextRange =
RECORD
fStart: LongInt;
fEnd: LongInt;
fHiliteStyle: Integer;
END;
TextRangePtr = ^TextRange;
TextRangeHandle = ^TextRangePtr;
TextRangeArray =
RECORD
fNumOfRanges: Integer;
fRange: ARRAY [0..0] of TextRange;
END;
TextRangeArrayPtr = ^TextRangeArray;
TextRangeArrayHandle = ^TextRangeArrayPtr;
OffsetArray =
RECORD
fNumOfOffsets: Integer;
fOffset: ARRAY [0..0] of LongInt;
END;
OffsetArrayPtr = ^OffsetArray;
OffsetArrayHandle = ^OffsetArrayPtr;
TextServiceInfo =
RECORD
fComponent: Component;
fItemName: Str255;
END;
TextServicesInfoPtr = ^TextServiceInfo;
TextServiceList =
RECORD
fTextServiceCount: Integer;
fServices: ARRAY [0..0] of TextServiceInfo;
END;
TextServiceListPtr = ^TextServiceList;
TextServiceListHandle = ^TextServiceListPtr;
ScriptLanguageRecord =
RECORD
fScript: ScriptCode;
fLanguage: LangCode;
END;
ScriptLanguageSupport =
RECORD
fScriptLanguageCount: Integer;
fScriptLanguageArray: ARRAY [0..0] of ScriptLanguageRecord;
END;
ScriptLanguageSupportPtr = ^ScriptLanguageSupport;
ScriptLanguageSupportHandle = ^ScriptLanguageSupportPtr;
InterfaceTypeList = ARRAY [0..0] of OSType;
TSMDocumentID = Ptr;
Text Services Manager Routines for Client Applications
Initializing and Closing as a TSM-Aware Application
FUNCTION InitTSMAwareApplication : OSErr;
FUNCTION CloseTSMAwareApplication : OSErr;
Creating and Activating TSM Documents
FUNCTION NewTSMDocument (numOfInterface: Integer;
VAR supportedInterfaceTypes: InterfaceTypeList;
VAR idocID: TSMDocumentID;
refCon: LongInt): OSErr;
FUNCTION ActivateTSMDocument
(idocID: TSMDocumentID): OSErr;
FUNCTION DeactivateTSMDocument
(idocID: TSMDocumentID): OSErr;
FUNCTION DeleteTSMDocument (idocID: TSMDocumentID): OSErr;
Passing Events to Text Service Components
FUNCTION TSMEvent (VAR event: EventRecord): Boolean;
Passing Menu Selections and Cursor Setting
FUNCTION TSMMenuSelect (menuResult: LongInt): Boolean;
FUNCTION SetTSMCursor (mousePos: Point): Boolean;
Confirming Active Input in a TSM Document
FUNCTION FixTSMDocument (idocID: TSMDocumentID): OSErr;
Making Text Services Available to the User
FUNCTION GetServiceList (numOfInterfaceTypes: Integer;
supportedInterfaceTypes: InterfaceTypeList;
VAR serviceInfo: TextServiceListHandle;
VAR seedValue: LongInt): OSErr;
FUNCTION OpenTextService (idocID: TSMDocumentID; aComponent: Component;
VAR aComponentInstance: ComponentInstance):
OSErr;
FUNCTION CloseTextService (idocID: TSMDocumentID; aComponentInstance:
ComponentInstance): OSErr;
Requesting a Floating Input Window
FUNCTION UseInputWindow (idocID: TSMDocumentID; useWindow: Boolean):
OSErr;
Associating Scripts and Languages With Components
FUNCTION SetDefaultInputMethod
(ts: Component;
VAR slRecord: ScriptLanguageRecord): OSErr;
FUNCTION GetDefaultInputMethod
(VAR ts: Component;
VAR slRecord: ScriptLanguageRecord): OSErr;
FUNCTION SetTextServiceLanguage
(VAR slRecord: ScriptLanguageRecord): OSErr;
FUNCTION GetTextServiceLanguage
(VAR slRecord: ScriptLanguageRecord): OSErr;
Text Services Manager Routines for Components
Sending Apple Events to a Client Application
FUNCTION SendAEFromTSMComponent
(VAR theAppleEvent: AppleEvent;
VAR reply: AppleEvent; sendMode: AESendMode; sendPriority: AESendPriority;
timeOutInTicks: LongInt;
idleProc: IdleProcPtr;
filterProc: EventFilterProcPtr): OSErr;
Opening Floating Utility Windows
FUNCTION NewServiceWindow (wStorage: Ptr; boundsRect: Rect;
title: Str255; visible: Boolean;
theProc: Integer; behind: WindowPtr;
goAwayFlag: Boolean; ts: ComponentInstance;
VAR window: WindowPtr): OSErr;
FUNCTION CloseServiceWindow (window: WindowPtr): OSErr;
FUNCTION GetFrontServiceWindow
(VAR window: WindowPtr): OSErr;
FUNCTION FindServiceWindow (thePoint: Point; VAR theWindow: WindowPtr):
Integer;
Text Service Component Routines
Providing a Text Service
FUNCTION InitiateTextService
(ts: ComponentInstance): ComponentResult;
FUNCTION ActivateTextService
(ts: ComponentInstance): ComponentResult;
FUNCTION DeactivateTextService
(ts: ComponentInstance): ComponentResult;
FUNCTION HidePaletteWindows (ts: ComponentInstance): ComponentResult;
FUNCTION TerminateTextService
(ts: ComponentInstance): ComponentResult;
Responding to Events and Updating the Cursor and Menu
FUNCTION TextServiceEvent (ts: ComponentInstance; numOfEvents: Integer;
VAR event: EventRecord): ComponentResult;
FUNCTION TextServiceMenuSelect
(ts: ComponentInstance; serviceMenu: MenuHandle; item: Integer): ComponentResult;
FUNCTION SetTextServiceCursor
(ts: ComponentInstance; mousePos: Point): ComponentResult;
FUNCTION GetTextServiceMenu (ts: ComponentInstance;
VAR serviceMenu: MenuHandle): ComponentResult;
Confirming Active Input in a TSM Document
FUNCTION FixTextService (ts: ComponentInstance): ComponentResult;
Identifying the Supported Scripts and Languages
FUNCTION GetScriptLanguageSupport
(ts: ComponentInstance; VAR scriptHandle: ScriptLanguageSupportHandle): ComponentResult;
C Summary
Constants
#define kTSMVersion 1 /* Version of the
Text Services Manager */
#define kTextService 'tsvc' /* component type for
the component description */
#define kInputMethodService 'inpm' /* component subtype for
the component description */
#define bTakeActiveEvent 15 /* bit set if the component
takes active event */
#define bScriptMask 0x00007F00 /* bit 8 - 14 */
#define bLanguageMask 0x000000FF /* bit 0 - 7 */
#define bScriptLanguageMask bScriptMask+bLanguageMask /* bit 0 - 14 */
/* Hilite styles ... */
typedef enum {
kCaretPosition = 1, /* specify caret position */
kRawText = 2, /* specify range of raw text */
kSelectedRawText = 3, /* specify range of selected raw text */
kConvertedText = 4, /* specify range of converted text */
kSelectedConvertedText = 5 /* specify range of selected
converted text */
} HiliteStyleType;
/* Apple Event constants ... */
/* Event class ... */
#define kTextServiceClass kTextService
/* event ID ... */
#define kUpdateActiveInputArea 'updt' /* update active Inline area */
#define kPos2Offset 'p2st' /* converting global coordinates
to char position */
#define kOffset2Pos 'st2p' /* converting char position
to global coordinates */
#define kShowHideInputWindow 'shiw' /* show or hide bottomline
input window */
/* Event keywords ... */
#define keyTSMDocumentRefcon 'refc' /* TSM document refcon */
#define keyAEServerInstance 'srvi' /* component instance */
#define keyAETheData 'kdat' /* typeText */
#define keyAEScriptTag 'sclg' /* script tag */
#define keyAEFixLength 'fixl' /* fix len ?? */
#define keyAEHiliteRange 'hrng' /* hilite range array */
#define keyAEUpdateRange 'udng' /* update range array */
#define keyAEClauseOffsets 'clau' /* Clause Offsets array */
#define keyAECurrentPoint 'cpos' /* current point */
#define keyAEDragging 'bool' /* dragging flag */
#define keyAEOffset 'ofst' /* offset */
#define keyAERegionClass 'rgnc' /* region class */
#define keyAEPoint 'gpos' /* current point */
#define keyAEBufferSize 'buff' /* buffer size to get text */
#define keyAERequestedType 'rtyp' /* requested text type */
#define keyAEMoveView 'mvvw' /* move view flag */
#define keyAELength 'leng' /* length */
#define keyAENextBody 'nxbd' /* next or previous body */
/* optional keyword for UpdateActiveInputArea */
#define keyAEPinRange 'pnrg'
/* optional keywords for Offset2Pos */
#define keyAETextFont 'ktxf'
#define keyAETextPointSize 'ktps'
#define keyAETextLineHeight 'ktlh'
#define keyAETextLineAscent 'ktas'
#define keyAEAngle 'kang'
/* optional keywords for Pos2Offset */
#define keyAELeadingEdge 'klef'
/* Apple event descriptor type ... */
#define typeComponentInstance 'cmpi' /* server instance */
#define typeTextRange 'txrn' /* text range record */
#define typeTextRangeArray 'tray' /* text range array */
#define typeOffsetArray 'ofay' /* offset array */
#define typeIntlWritingCode 'intl' /* script code */
#define typeQDPoint 'QDpt' /* QuickDraw Point */
#define typeAEText 'tTXT' /* Apple Event text */
#define typeText 'TEXT' /* Plain text */
#define typeFixed 'fixd' /* Fixed number 16.16 */
/* Apple event descriptor type constants */
typedef enum {
kTSMOutsideOfBody = 1,
kTSMInsideOfBody = 2,
kTSMInsideOfActiveInputArea = 3
} AERegionClassType;
typedef enum {
kNextBody = 1,
kPreviousBody = 2
} AENextBodyType;
/* Apple Event error definitions */
typedef enum {
errOffsetInvalid = -1800,
errOffsetIsOutsideOfView = -1801,
errTopOfDocument = -1810,
errTopOfBody = -1811,
errEndOfDocument = -1812,
errEndOfBody = -1813
} AppleEventErrorType;
Data Types
struct TextRange { /* typeTextRange 'txrn' */
long fStart;
long fEnd;
short fHiliteStyle;
};
typedef struct TextRange TextRange;
typedef TextRange *TextRangePtr;
typedef TextRangePtr *TextRangeHandle;
struct TextRangeArray { /* typeTextRangeArray 'txra' */
short fNumOfRanges; /* specify the size of the fRange array */
TextRange fRange[1]; /* when fNumOfRanges > 1, the size of this
array has to be calculated */
};
typedef struct TextRangeArray TextRangeArray;
typedef TextRangeArray *TextRangeArrayPtr;
typedef TextRangeArrayPtr *TextRangeArrayHandle;
struct OffsetArray { /* typeOffsetArray'offa' */
short fNumOfOffsets; /* specify the size of the fOffset array */
long fOffset[1]; /* when fNumOfOffsets > 1, the size of
this array has to be calculated */
};
typedef struct OffsetArray OffsetArray;
typedef OffsetArray *OffsetArrayPtr;
typedef OffsetArrayPtr *OffsetArrayHandle;
/* extract Script/Language code from Component flag ... */
#define mGetScriptCode(cdRec) ((ScriptCode) (cdRec.componentFlags &
bScriptMask) >> 8)
#define mGetLanguageCode(cdRec) ((LangCode) cdRec.componentFlags &
bLanguageMask)
typedef void *TSMDocumentID;
/* text service component information list */
struct TextServiceInfo {
Component fComponent;
Str255 fItemName;
};
typedef struct TextServiceInfo TextServiceInfo;
typedef TextServiceInfo *TextServiceInfoPtr;
/*text service component list*/
struct TextServiceList {
short fTextServiceCount; /* number of entries in the
'fServices' array */
TextServiceInfo fServices[1]; /* Note: array of 'TextServiceInfo'
records follows */
};
typedef struct TextServiceList TextServiceList;
typedef TextServiceList *TextServiceListPtr;
typedef TextServiceListPtr *TextServiceListHandle;
/*script and language record*/
struct ScriptLanguageRecord {
ScriptCode fScript;
LangCode fLanguage;
};
typedef struct ScriptLanguageRecord ScriptLanguageRecord;
/*script and language support record*/
struct ScriptLanguageSupport {
short fScriptLanguageCount; /* number of entries in the
'fScriptLanguageArray'
array */
ScriptLanguageRecord fScriptLanguageArray[1]; /* Note: array of
'ScriptLanguageRecord'
records follows */
};
typedef struct ScriptLanguageSupport ScriptLanguageSupport;
typedef ScriptLanguageSupport *ScriptLanguageSupportPtr;
typedef ScriptLanguageSupportPtr *ScriptLanguageSupportHandle;
Text Services Manager Routines for Client Applications
Initializing and Closing as a TSM-Aware Application
pascal OSErr InitTSMAwareApplication ();
pascal OSErr CloseTSMAwareApplication ();
Creating and Activating TSM Documents
pascal OSErr NewTSMDocument (short numOfInterface,
OSType supportedInterfaceTypes[],
TSMDocumentID *idocID, long refCon);
pascal OSErr ActivateTSMDocument
(TSMDocumentID idocID);
pascal OSErr DeactivateTSMDocument
(TSMDocumentID idocID);
pascal OSErr DeleteTSMDocument
(TSMDocumentID idocID);
Passing Events to Text Service Components
pascal Boolean TSMEvent (EventRecord *event);
Passing Menu Selections and Cursor Setting
pascal Boolean TSMMenuSelect (long menuResult);
pascal Boolean SetTSMCursor (Point mousePos);
Confirming Active Input in a TSM Document
pascal OSErr FixTSMDocument (TSMDocumentID idocID);
Making Text Services Available to the User
pascal OSErr GetServiceList (short numOfInterfaceTypes,
OSType supportedInterfaceTypes[],
TextServiceListHandle *serviceInfo,
long *seedValue);
pascal OSErr OpenTextService
(TSMDocumentID idocID, Component aComponent,
ComponentInstance *aComponentInstance);
pascal OSErr CloseTextService
(TSMDocumentID idocID,
ComponentInstance aComponentInstance)
Requesting a Floating Input Window
pascal OSErr UseInputWindow (TSMDocumentID idocID, Boolean useWindow);
Associating Scripts and Languages With Components
pascal OSErr SetDefaultInputMethod
(Component ts,
ScriptLanguageRecord *slRecordPtr);
pascal OSErr GetDefaultInputMethod
(Component *ts,
ScriptLanguageRecord *slRecordPtr);
pascal OSErr SetTextServiceLanguage
(ScriptLanguageRecord *slRecordPtr);
pascal OSErr GetTextServiceLanguage
(ScriptLanguageRecord *slRecordPtr);
Text Services Manager Routines for Components
Sending Apple Events to a Client Application
pascal OSErr SendAEFromTSMComponent
(AppleEvent *theAppleEvent,
AppleEvent *reply, AESendMode sendMode,
AESendPriority sendPriority,
long timeOutInTicks, IdleProcPtr idleProc,
EventFilterProcPtr filterProc);
Opening Floating Utility Windows
pascal OSErr NewServiceWindow
(void *wStorage, const Rect *boundsRect,
ConstStr255Param title, Boolean visible,
short theProc, WindowPtr behind,
Boolean goAwayFlag, ComponentInstance ts,
WindowPtr *window);
pascal OSErr CloseServiceWindow
(WindowPtr window);
pascal OSErr GetFrontServiceWindow
(WindowPtr *window);
pascal short FindServiceWindow
(Point thePoint, WindowPtr *theWindow);
Text Service Component Routines
Providing a Text Service
pascal ComponentResult InitiateTextService
(ComponentInstance ts);
pascal ComponentResult ActivateTextService
(ComponentInstance ts);
pascal ComponentResult DeactivateTextService
(ComponentInstance ts);
pascal ComponentResult HidePaletteWindows
(ComponentInstance ts);
pascal ComponentResult TerminateTextService
(ComponentInstance ts);
Responding to Events and Updating the Cursor and Menu
pascal ComponentResult TextServiceEvent
(ComponentInstance ts,
short numOfEvents, EventRecord *event)
pascal ComponentResult TextServiceMenuSelect
(ComponentInstance ts,
MenuHandle serviceMenu, short item);
pascal ComponentResult SetTextServiceCursor
(ComponentInstance ts, Point mousePos);
pascal ComponentResult GetTextServiceMenu
(ComponentInstance ts, MenuHandle *serviceMenu);
Confirming Active Input in a TSM Document
pascal ComponentResult FixTextService
(ComponentInstance ts);
Identifying the Supported Scripts and Languages
pascal ComponentResult GetScriptLanguageSupport
(ComponentInstance ts,
ScriptLanguageSupportHandle *scriptHdl);
Assembly-Language Summary
Trap Macros
Trap Macro Names for Text Services Manager Routines
| Pascal name | Trap macro name |
| NewTSMDocument | _NewTSMDocument |
| DeleteTSMDocument | _DeleteTSMDocument |
| ActivateTSMDocument | _ActivateTSMDocument |
| DeactivateTSMDocument | _DeactivateTSMDocument |
| TSMEvent | _TSMEvent |
| TSMMenuSelect | _TSMMenuSelect |
| SetTSMCursor | _SetTSMCursor |
| FixTSMDocument | _FixTSMDocument |
| GetServiceList | _GetServiceList |
| OpenTextService | _OpenTextService |
| CloseTextService | _CloseTextService |
| SendAEFromTSMComponent | _SendAEFromTSMComponent |
| SetDefaultInputMethod | _SetDefaultInputMethod |
| GetDefaultInputMethod | _GetDefaultInputMethod |
| SetTextServiceLanguage | _SetTextServiceLanguage |
| GetTextServiceLanguage | _GetTextServiceLanguage |
| UseInputWindow | _UseInputWindow |
| NewServiceWindow | _NewServiceWindow |
| CloseServiceWindow | _CloseServiceWindow |
| GetFrontServiceWindow | _GetFrontServiceWindow |
| InitTSMAwareApplication | _InitTSMAwareApplication |
| CloseTSMAwareApplication | _CloseTSMAwareApplication |
| FindServiceWindow | _FindServiceWindow |
Trap Macro Names for Text Service Component Routines
| Pascal name | Trap macro name |
| GetScriptLanguageSupport | _GetScriptLanguageSupport |
| InitiateTextService | _InitiateTextService |
| TerminateTextService | _TerminateTextService |
| ActivateTextService | _ActivateTextService |
| DeactivateTextService | _DeactivateTextService |
| TextServiceEvent | _TextServiceEvent |
| GetTextServiceMenu | _GetTextServiceMenu |
| TextServiceMenuSelect | _TextServiceMenuSelect |
| FixTextService | _FixTextService |
| SetTextServiceCursor | _SetTextServiceCursor |
| HidePaletteWindows | _HidePaletteWindows |
Result Codes
| tsmComponentNoErr | 0 | Component result: no error |
| tsmUnsupScriptLanguageErr | -2500 | Specified script and language are not supported |
| tsmInputMethodNotFoundErr | -2501 | Specified input method cannot be found |
| tsmNotAnAppErr | -2502 | The caller was not an application |
| tsmAlreadyRegisteredErr | -2503 | The caller is already TSM-initialized |
| tsmNeverRegisteredErr | -2504 | The caller is not TSM-aware |
| tsmInvalidDocIDErr | -2505 | Invalid TSM document ID |
| tsmTSMDocBusyErr | -2506 | Document is still active |
| tsmDocNotActiveErr | -2507 | Document is not active |
| tsmNoOpenTSErr | -2508 | There is no open text service component |
| tsmCantOpenComponentErr | -2509 | Can't open the component |
| tsmTextServiceNotFoundErr | -2510 | No text service component found |
| tsmDocumentOpenErr | -2511 | There are open documents |
| tsmUseInputWindowErr | -2512 | An input window is being used |
| tsmTSHasNoMenuErr | -2513 | The text service component has no menu |
| tsmTSNotOpenErr | -2514 | Text service component is not open |
| tsmComponentAlreadyOpenErr | -2515 | Text service component already open for document |
| tsmInputMethodIsOldErr | -2516 | The default input method is old-style |
| tsmScriptHasNoIMErr | -2517 | Script has no (or old) input method |
| tsmUnsupportedTypeErr | -2518 | Unsupported interface type |
| tsmUnknownErr | -2519 | Any other error |