Accessing Dictionaries
Although the Dictionary Services programming interface provides only a few functions, these functions provide two valuable services. You can:
Search for and obtain definitions from active dictionaries
Display a Dictionary window that shows results of a dictionary search.
Getting a Definition
There are two steps you need to perform to get a definition:
Call the function
DCSGetTermRangeInStringto obtain the range in a dictionary that contains the definition for a word or phrase.Pass that range to the function
DCSCopyTextDefinitionto get the definition associated with the text range and word or phrase. Dictionary Services returns the definition as aCFStringobject, which is plain text.
An alternative to getting the definition returned to you is to let Dictionary Services obtain and display the search results for you. In this case, instead of calling DCSCopyTextDefinition, you would pass the text range to the HIDictionaryWindowShow function.
Supporting Contextual Lookup
You may want to use the HIDictionaryWindowShow function to support contextual look-up in any application that provides text editing. For example, you could set up your application to respond as follows when the user control-clicks a text selection:
Get the text selection and supply that as the
textStringparameter. If you use aCFStringobject for this text, you also need to specify a Core Text font to use to display the text. Otherwise, Dictionary Services uses the attributes provided.Determine the range of the selected text and provide that as the
selectionRangeparameter.Determine the origin of the typographic baseline of the selected text and provide that as the
textOriginparameter.
For More Information
Dictionary Services Reference describes functions and their parameters in detail.
Copyright © 2007 Apple Inc. All Rights Reserved. Terms of Use | Privacy Policy | Updated: 2007-05-30