Legacy Documentclose button

Important: The information in this document is obsolete and should not be used for new development.

Previous Book Contents Book Index Next

Inside Macintosh: Text /
Chapter 7 - Text Services Manager / Text Services Manager Reference
Apple Event Handlers Supplied by Client Applications


Converting Global Coordinates to Text Offsets

The Position To Offset Apple event requests a client application to convert specified global coordinates to byte offsets in text. The text service component uses this Apple event for mouse tracking, in order to draw the caret, highlight text, or adjust the cursor appearance.
Position To Offset--Converting Global Coordinates to Text Offset (Continued)
Event classkTextServiceClass  
Event IDkPos2Offset  
Requested actionConvert global coordinates specified in the keyAECurrentPoint parameter to a byte offset. If the click is within the limits of the active input area, the offset is relative to the start of the active input area. Otherwise, the offset is relative to the start of the application's body text. The client application specifies the classification of the location of the offset in the keyAERegionClass return parameter.
   
Required parameters  
Keyword:keyAETSMDocumentRefcon 
Descriptor type:typeLongInteger  
Data:A TSM document specifier (reference constant) supplied by the application in a prior call to the NewTSMDocument function
(see page 7-50). This value is associated with the TSM document affected by this event.
Required parameters
Keyword:keyAEServerInstance  
Descriptor type:typeComponentInstance  
Data:A component instance value created by a prior call to the Component Manager OpenComponent function. This value identifies the text service component.
Keyword:keyAECurrentPoint  
Descriptor type:typePoint  
Data:A point that contains the global coordinates that describe the current mouse position.
Optional parameter  
Keyword:keyAEdragging  
Descriptor type:typeBoolean  
Data:A Boolean value that indicates whether the input method is currently tracking the mouse--that is, whether the user is dragging the current selection. If it is TRUE, the application should pin the cursor to the limits of the active input area (to avoid highlighting beyond the limits of the active input area).
Return parameters   
Keyword:keyAEOffset  
Descriptor type:typeLongInteger  
Data:A byte offset that specifies the character corresponding to the current mouse position (keyAECurrentPoint). If the click is within the limits of the active input area, the offset is relative to the start of the active input area. Otherwise, the offset is relative to the start of the application's body text.
Keyword:keyAERegionClass  
Descriptor type:typeShortInteger  
Data:The classification of the position specified in the keyAEOffset parameter. Three constants define the classification:
 ConstantValue 
 kTSMOutsideOfBody1 
 kTSMInsideOfBody2 
 kTSMInsideOfActiveInputArea3 
 A value of kTSMOutsideOfBody means that the offset is
outside the application's body text. A value of kTSMInsideOfBody means that the offset is inside the body text. kTSMInsideOfActiveInputArea means that the offset is inside the active input area.
    
Return parameters   
Keyword:keyErrorNumber  
Descriptor type:typeShortInteger  
Data:Any errors that the application needs to return to the text service component. The application must pass Memory Manager, TextEdit, or other errors that it receives through to the component; otherwise, it should pass 0 (noErr).
Optional return parameter  
Keyword:keyAELeadingEdge  
Descriptor type:typeBoolean  
Data:A Boolean value that is equivalent to the leadingEdge parameter
of the QuickDraw PixelToChar function. It is TRUE if the specified point corresponds to the leading edge of the character whose offset is returned; it is FALSE if the specified point corresponds to the trailing edge of the character.

For sample code that handles the Position To Offset Apple event, see Listing 7-8 on page 7-30.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
6 JUL 1996