This is NSSpellServer.rtf in view mode; [Download] [Up]
paperh18648 margl-907 margr0 margt0 margb0 fi0 ri0 ql sb0 f1 fs24 Copyright f3 'e3f1 1994 by NeXT Computer, Inc. All Rights Reserved. s4 li100 fi0 ri1007 ql f0 b fs36 fs100 fs36 NSSpellServer pard s11 li2872 fi-2771 ri1007 ql tx2872 f1 b0 fs28 fs48 fs28 f0 b fs24 Inherits From:tab b0 fs28 f1 NSObject fs20 fs28 s6 f0 b fs24 Conforms To:tab b0 fs28 f1 NSObject (NSObject) fs20 fs28 s7 f0 b fs24 Declared In:tab b0 fs28 f1 AppKit/NSSpellServer.h fs20 fs28 pard s16 li100 fi0 ri1007 ql f0 b fs28 fs20 fs28 Class Description fs14 fs28 pard s1 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs2 fs28 The NSSpellServer class gives you a way to make your particular spelling checker a service that'27s available to any application. A i servicei0 is an application that declares its availability in a standard way, so that any other applications that wish to use it can do so. If you build a spelling checker that makes use of the NSSpellServer class and list it as an available service, then users of any application that makes use of NSSpellChecker or includes a Services menu will see your spelling checker as one of the available dictionaries. fs16 fs28 To make use of NSSpellServer, you write a small program that creates an NSSpellServer instance and a delegate that responds to messages asking it to find a misspelled word and to suggest guesses for a misspelled word. Send the NSSpellServer b registerLanguage:byVendor:b0 messages to tell it the languages your delegate can handle. fs16 fs28 The program that runs your spelling checker should not be built as an Application Kit application, but as a simple program. Suppose you supply spelling checkers under the vendor name 'aaAcme.'ba Suppose the file containing the code for your delegate is called AcmeEnglishSpellChecker. Then the following might be your program'27s b mainb0 : fs16 fs28 pard s5 li1231 fi0 ri1007 ql f2 fs20 void main() { NSSpellServer *aServer = [[NSSpellServer alloc] init]; if ([aServer registerLanguage:"English" byVendor:"Acme"]) { [aServer setDelegate:[AcmeEnglishSpellChecker alloc] init]]; [aServer run]; fprintf(stderr, "Unexpected death of Acme SpellChecker!\n"); } else { fprintf(stderr, "Unable to check in Acme SpellChecker.\n"); } } pard s1 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 fs16 fs28 Your delegate is an instance of a custom subclass. (It'27s simplest to make it a subclass of NSObject, but that'27s not a requirement.) Given an NSString, your delegate must be able to find a misspelled word by implementing the methodb spellServer:findMisspelledWordInString:language:wordCount:countOnly:b0 . Usually, this method also reports the number of words it has scanned, but that isn'27t mandatory. fs16 fs28 Optionally, the delegate may also suggest corrections for misspelled words. It does so by implementing the method b spellServer:suggestGuessesForWord:inLanguage: fs16 fs28 pard s15 li477 fi0 ri1007 ql f0 fs24 fs4 fs24 Service Availability Notice pard s1 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs28 fs16 fs28 When there'27s more than one spelling checker available, the user selects the one desired. The application that requests a spelling check uses an NSSpellChecker object, and it provides a Spelling panel; in the panel there'27s a pop-up list of available spelling checkers. Your spelling checker appears in that list if it has a i service descriptori0 . fs16 fs28 A service descriptor is an entry in a text file called b servicesb0 . Usually it'27s located within the bundle that also contains your spelling checker'27s executable file. The bundle (or directory) that contains the services file must have a name ending in 'aa.service'ba or 'aa.app'ba. The system looks for service bundles in a standard set of directories. fs16 fs28 A spell checker service availability notice has a standard format, illustrated in the following example for the Acme spelling checker: fs16 fs28 pard s5 li1231 fi0 ri1007 ql f2 fs20 Spell Checker: Acme Language: French Language: English Executable: franglais.daemon pard s1 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 fs28 fs16 fs28 The first line identifies the type of service; for a spelling checker, it must say 'aaSpell Checker:'ba followed by your vendor name. The next line contains the English name of a language your spelling checker is prepared to check. (The language must be one your system recognizes.) If your program can check more than one language, use an additional line for each additional language. The last line of a descriptor gives the name of the service'27s executable file. (It requires a complete path if it'27s in a different directory.) fs16 fs28 If there'27s a service descriptor for your Acme spelling checker and also a service descriptor for the English checker provided by a vendor named Consolidated, a user looking at the Spelling panel'27s pop-up list would see: fs16 fs28 pard s5 li1231 fi0 ri1007 ql f2 fs20 English (Acme) fi0 English (Consolidated) fi0 French (Acme) s15 li477 fi0 f0 b fs24 fs20 fs24 Illustrative Sequence of Messages to an NSSpellServer pard s1 li477 fi0 ri1007 ql tx2494 tx2872 tx3250 f1 b0 fs28 fs16 fs28 The act of checking spelling usually involves the interplay of objects in two classes: the user application'27s NSSpellChecker (which responds to interactions with the user) and your spelling checker'27s NSSpellServer (which provides the application interface for your spelling checker). You can see the interaction between the two in the following list of steps involved in finding a misspelled word. fs16 fs28 pard s3 li1231 fi-376 ri1007 ql tx1231 tx2872 tx3250 'b7tab The user of an application selects a menu item to request a spelling check. The application sends a message to its NSSpellChecker object. The NSSpellChecker in turn sends a corresponding message to the appropriate NSSpellServer. fs16 fs28 'b7tab The NSSpellServer receives the message asking it to check the spelling of an NSString. It forwards the message to its delegate. fs16 fs28 'b7tab The delegate searches for a misspelled word. If it finds one, it returns an NSRange identifying the word'27s location in the string. fs16 fs28 'b7tab The NSSpellServer receives a message asking it to suggest guesses for the correct spelling of a misspelled word, and forwards the message to its delegate. fs16 fs28 'b7tab The delegate returns a list of possible corrections, which the NSSpellServer in turn returns to the NSSpellChecker that initiated the request. fs16 fs28 'b7tab The NSSpellServer doesn'27t know what the user does with the errors its delegate has found or with the guesses its delegate has proposed. (Perhaps the user corrects the document, perhaps by selecting a correction from the NSSpellChecker'27s display of guesses; but that'27s not the NSSpellServer'27s responsibility.) However, if the user presses the Learn or Forget buttons (thereby causing the NSSpellChecker to revise the user'27s word list), the NSSpellServer receives a notification of the word thus learned or forgotten. It'27s up to you whether your spell checker acts on this information. If the user presses the Ignore button, the delegate is not notified (but the next time that word occurs in the text, the method b isWordInUserDictionaries:caseSensitive: b0 will report YES rather than NO). fs16 fs28 'b7tab Once the NSSpellServer delegate has reported a misspelled word, it has completed its search. Of course, it'27s likely that the user'27s application will then send a new message, this time asking the NSSpellServer to check a string containing the part of the text it didn'27t get to earlier. fs16 fs28 pard s16 li100 fi0 ri1007 ql f0 b fs24 fs28 Checking in Your Service fs14 fs28 pard s8 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (BOOL)b registerLanguage:b0 (NSString *)i languagei0 tab Registers a spelling server for i languagei0 by i vendori0 . s9 li7030 fi-6553 fi-5796 b byVendor:b0 (NSString *)i vendori0 tab pard s16 li100 fi0 ri1007 ql f0 b fs48 fs28 Assigning a Delegate fs14 fs28 pard s8 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (id)b delegateb0 tab Returns the NSSpellServer'27s delegate. fi-6552 fs16 fs28 fi-6552 {f3 -} (void)b setDelegate:b0 (id)i anObjecti0 tab Sets the delegate of the NSSpellServer. pard s16 li100 fi0 ri1007 ql f0 b fs48 fs28 Running the Service fs14 fs28 pard s8 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (void)b runb0 tab Makes the NSSpellServer start listening for spell-checking requests. This method should not return. pard s16 li100 fi0 ri1007 ql f0 b fs48 fs28 Checking User Dictionaries fs14 fs28 pard s8 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (BOOL)b isWordInUserDictionaries:b0 (NSString *)i word s9 li7030 fi-6553 fi-5796 i0 b caseSensitive:b0 (BOOL)i flagi0 tab Returns whether i wordi0 is in any open user dictionary; the search is case-sensitive if i flagi0 is YES. pard s16 li100 fi0 ri1007 ql f0 b fs48 fs28 Methods Implemented by the Delegate fs14 fs28 pard s8 li7029 fi-6552 ri1007 ql tx6652 tx7030 f1 b0 fs2 fs28 fi-6552 {f3 -} (NSRange)b spellServer:b0 (NSSpellServer *)i senderi0 tab Search for a misspelled word in i stringToChecki0 , using s9 li7030 fi-6553 fi-5796 b findMisspelledWordInString:tab tab b0 i languagei0 , and marking the firstb b0 misspelled word found (NSString *)i stringToCheck i0 tab tab by returning its range within the string object. In b language:b0 (NSString *)i languagei0 tab tab i wordCounti0 return by reference the number of words b wordCount:b0 (int *)i wordCounti0 tab tab from the beginning of the string object until the b countOnly:b0 (BOOL)i countOnlyi0 tab tab misspelled word (or the end-of-string). If i countOnlyi0 is YES, just count the words in the string object; do not spell-check. Send b isWordInUserDictionaries:caseSensitive:b0 to the spelling server to determine if i wordi0 exists in the user'27s language dictionaries. s8 li7029 fi-5794 fi-6552 fs16 fs28 fi-6552 {f3 -} (NSArray *)b spellServer:b0 (NSSpellServer *)i senderi0 tab Search for alternatives to the misspelled i wordi0 in s9 li7030 fi-6553 fi-5796 b suggestGuessesForWord:b0 (NSString *)i wordi0 tab tab i languagei0 . Return guesses as an array of string objects. b inLanguage:b0 (NSString *)i language s8 li7029 fi-5794 fi-6552 i0 fs16 fs28 fi-6552 {f3 -} (void)b spellServer:b0 (NSSpellServer *)i senderi0 tab Notifies the delegate of a i wordi0 added to the user'27s hidden s9 li7030 fi-6553 fi-5796 b didLearnWord:b0 (NSString *)i wordi0 tab tab word list. b inLanguage:b0 (NSString *)i language s8 li7029 fi-5794 fi-6552 i0 fs16 fs28 fi-6552 {f3 -} (void)b spellServer:b0 (NSSpellServer *)i senderi0 tab Notifies the delegate of a i wordi0 removed from the user'27s s9 li7030 fi-6553 fi-5796 b didForgetWord:b0 (NSString *)i wordi0 tab tab hidden word list. b inLanguage:b0 (NSString *)i language i0 }
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.