Support dictionary lookup
By gnach... on June 01, 2011 04:01 (imported from Google Code)
Activiated by hovering over a word and pressing cmd-ctrl-D.
Info from http://lists.apple.com/archives/carbon-dev/2005/Dec/msg00797.html
Subject: Re: Dictionary popup support using HITextView?
From: Evan Gross <email@hidden>
Date: Wed, 28 Dec 2005 23:44:25 -0500
Delivered-to: email@hidden
Delivered-to: email@hidden
Thread-index: AcYMMos0ydpvXnglEdqW1wANk3ZiGg==
Thread-topic: Dictionary popup support using HITextView?
User-agent: Microsoft-Entourage/11.2.1.051004
On 12/27/05 5:06 PM, "David Catmull" <email@hidden> wrote:
> On Dec 27, 2005, at 10:01 AM, Keisuke Hara <email@hidden> wrote:
>> Dictionary popup is based on some existing text events and should
>> naturally work with HITextView.
>
> Which events are those? It would be nice to be able to support it in
> third-party text editors.
While this isn't documented (it should be!), I think that you need to
support the following TSM Doc Access (kEventClassTSMDocumentAccess) events
(the Dictionary popup is a specific "class" of input method component):
kEventTSMDocumentAccessGetSelectedRange
kEventTSMDocumentAccessGetLength
kEventTSMDocumentAccessGetCharacters
to get the text itself - note that kEventClassTextInput /
kEventTextInputGetSelectedText isn't sufficient because the Dictionary popup
uses the text under the mouse in most cases.
kEventTSMDocumentAccessGetFont
- It appears that both the kTSMDocAccessFontSizeAttribute and
kTSMDocAccessEffectiveRangeAttribute must be supported.
to get the font and size "runs." A couple of notes:
- If this event isn't supported (it would be considered a bug if it wasn't
AND the kTSMDocumentSupportDocumentAccessPropertyTag was present!) then it
tries to get what it can from kEventClassTextInput /
kEventTextInputOffsetToPos (see below). Generally, you'll get more accurate
results from here since an ATSFontRef is returned.
- Not all text attributes can be described using just a font and size
(obviously), easy to see when hovering over a word with a sub/superscript'ed
character, or underlines, foreground color, etc.
It uses the following kEventClassTextInput events to figure out the word
that's under the mouse, and where to draw:
kEventTextInputOffsetToPos
- kEventParamTextInputReplyFMFont and kEventParamTextInputReplyPointSize
may not be needed by the Dictionary popup if
kEventTSMDocumentAccessGetFont is supported. But it's really best to support
all possible return parameters unless they make no sense in your particular
app. Just because one input method doesn't need a particular return
parameter, another one may well rely on it!
kEventTextInputPosToOffset
Your handlers for the above two events must be able to deal with the "no
active inline input area" situation. The correct behavior is described in
the headers. This means properly dealing with NEGATIVE offsets in the
kEventParamTextInputSendTextOffset parameter for kEventTextInputOffsetToPos!
Other Interesting Observations
The Dictionary popup prefers using Accessibility for certain things (not
totally sure if it can get everything it needs via AX, I suspect it can but
don't know if it does). Put some heavily formatted text into a TextEdit
document (subscript a letter in the middle of a word, vary the font size
within a word and line, set the font for a word to one that needs to be
synthesized (Helvetica or Courier Oblique), try with Universal access on and
off. Also note that when AX is on, it'll work with inactive documents (even
if the app's not active).
There's a long-standing, nasty bug in MLTE's kEventTextInputOffsetToPos
handling of negative offsets (filed eons ago). Easy to see with Apple's
MLTE_CustomScrolling sample:
<http://developer.apple.com/samplecode/MLTE_CustomScrolling/MLTE_CustomScrol
ling.html>
The Dictionary popup works for words after the insertion point, but not for
before (negative offset returns -1800). Not sure why it's totally broken
with HITextView, as it's based on MLTE AFIK. Doesn't seem to work at all in
the MLTEShowcase sample (Developer/Examples/Carbon) either, no idea why.
This may not be the entire story (and probably more than you wanted to
know), just relaying what I've been told by those that know at Apple, and
what I've found out from my own experimenting. Future versions of my input
method will rely heavily on TSM Doc Access to do some extremely cool
things...
Evan Gross
--
+------------------------------------------------------------------------+
| Evan Gross, President, Rainmaker Research Inc. |
| - Developers of Macintosh and Windows Software - |
| Spell Catcher for Mac OS and Windows |
| Visit <http://www.rainmakerinc.com> |
Do not post admin requests to the list. They will be ignored.
Carbon-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/carbon-dev/email@hidden
This email sent to email@hidden
References:
>Re: Dictionary popup support using HITextView? (From: David Catmull <email@hidden>)