On 28/04/08 1:55 AM, "Ying Bian" <[EMAIL PROTECTED]> wrote:
> I am thinking of developing my own dictionary tool which can detects the word > under the cursor and automatically (or when a modifier key is pressed) popup > a translation window. > > After researching for a while, I find it more tricky than I estimated. > If you search the Cocoa Dev and Carbon Dev archives for "dictionary panel", "dictionary popup" or "dictionary service", you should find some useful information. And you are correct, implementing something like it is (to understate) a non-trivial task. > The accessibility APIs may of help, but for text in a text view, the returned > information is not enough to reproduce the layout and let me detect the > "exact" word over which the mouse hovers. > > There is a similar functionality in Lepoard (I am not sure if it exists prior > to 10.5): > It does, definitely in Tiger, not sure about Panther. The required APIs first appeared in 10.3. > in any cocoa-based applications, if you press Apple + Ctrl + D, the current > word under cursor is automatically selected and translated in a popup window. > It seems to me not implemented with accessibility APIs as it does not require > to enable access for assistive devices in the Universal Access System > Preference panel. > This works in many Carbon apps as well. Strictly speaking, it has nothing to do with Carbon vs. Cocoa. It depends entirely on the capabilities of the text view/area/engine. It works just fine in BBEdit, for example. > Then, how is this implemented? I want to get some hints from this. The Dictionary panel is a special type of input method component: /System/Library/Components/DictionaryService.component It uses Text Service Manager (both "regular" TSM and TSM Document Access) and Accessibility APIs to determine the text (and its attributes) under the mouse. It will use various combinations of TSM/AX APIs to get the best representation available from the underlying document. If you look closely, the results are often slightly different with Universal Access on vs. off. It does not use any Cocoa APIs (as suggested in some other replies) for this purpose. Reading up on TSM and input method components is the proper starting point for what you want to do. Hope that helps, Evan Gross -- Evan Gross, President, Rainmaker Research Inc. Developers of Macintosh and Windows Software Spell Catcher for Mac OS and Windows http://www.rainmakerinc.com/ _______________________________________________ Cocoa-dev mailing list (Cocoa-dev@lists.apple.com) Please do not post admin requests or moderator comments to the list. Contact the moderators at cocoa-dev-admins(at)lists.apple.com Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com This email sent to [EMAIL PROTECTED]