]> git.lyx.org Git - lyx.git/blobdiff - src/support/AppleSpeller.m
Set correctly the spacing between atoms in MathData
[lyx.git] / src / support / AppleSpeller.m
index feba78c1a1b4b55cfee4509d20e24390b9c47153..08e3f5972214e38218ec72e1a37ec5529aba1e4d 100644 (file)
@@ -8,7 +8,6 @@
  * Full author contact details are available in file CREDITS.
  */
 
-#import <Carbon/Carbon.h>
 #import <Cocoa/Cocoa.h>
 
 #import <AvailabilityMacros.h>
@@ -69,7 +68,7 @@ static NSString * toLanguage(AppleSpeller speller, const char * lang)
                NSArray * languages = [speller->checker availableLanguages];
                
                for (NSString *element in languages) {
-                       if ([element isEqualToString:lang_]) {
+                       if (0 == [element caseInsensitiveCompare:lang_]) {
                                result = element;
                                break;
                        } else if ([lang_ hasPrefix:element]) {
@@ -94,16 +93,17 @@ SpellCheckResult AppleSpeller_check(AppleSpeller speller, const char * word, con
        NSString * lang_ = toString(lang);
        SpellCheckResult result = SPELL_CHECK_FAILED;
        int start = 0;
-
+       int length = [word_ length];
+       
        [speller->misspelled release];
        speller->misspelled = nil;
 
-       while (result == SPELL_CHECK_FAILED) {
+       while (result == SPELL_CHECK_FAILED && start < length) {
                NSRange match = [speller->checker
                        checkSpellingOfString:word_
                        startingAt:start
                        language:lang_
-                       wrap:NO
+                       wrap:(BOOL)NO
                        inSpellDocumentWithTag:speller->doctag
                        wordCount:NULL];
 
@@ -114,7 +114,11 @@ SpellCheckResult AppleSpeller_check(AppleSpeller speller, const char * word, con
                                        result = SPELL_CHECK_LEARNED;
                        }
                } else {
+#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
+                       NSUInteger capacity = [speller->misspelled count] + 1;
+#else
                        int capacity = [speller->misspelled count] + 1;
+#endif
                        NSMutableArray * misspelled = [NSMutableArray arrayWithCapacity:capacity];
                        [misspelled addObjectsFromArray:speller->misspelled];
                        [misspelled addObject:[NSValue valueWithRange:match]];
@@ -158,16 +162,11 @@ size_t AppleSpeller_makeSuggestion(AppleSpeller speller, const char * word, cons
        // Mac OS X 10.6 only
        NSInteger slen = [word_ length];
        NSRange range = { 0, slen };
-       
-       if ([NSSpellChecker instancesRespondToSelector:@selector(guessesForWordRange:)]) {
-               result = [speller->checker guessesForWordRange:range
-                       inString:word_
-                       language:lang_
-                       inSpellDocumentWithTag:speller->doctag];
-       } else {
-               [speller->checker setLanguage:lang_];
-               result = [speller->checker guessesForWord:word_];
-       }
+
+       result = [speller->checker guessesForWordRange:range
+               inString:word_
+               language:lang_
+               inSpellDocumentWithTag:speller->doctag];
 #else
        [speller->checker setLanguage:lang_];
        result = [speller->checker guessesForWord:word_];
@@ -232,7 +231,11 @@ int AppleSpeller_numMisspelledWords(AppleSpeller speller)
 
 void AppleSpeller_misspelledWord(AppleSpeller speller, int index, int * start, int * length)
 {
+#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
+       NSRange range = [[speller->misspelled objectAtIndex:(NSUInteger)index] rangeValue];
+#else
        NSRange range = [[speller->misspelled objectAtIndex:index] rangeValue];
+#endif
        *start = range.location;
        *length = range.length;
 }
@@ -240,5 +243,9 @@ void AppleSpeller_misspelledWord(AppleSpeller speller, int index, int * start, i
 
 int AppleSpeller_hasLanguage(AppleSpeller speller, const char * lang)
 {
+#if defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && (__MAC_OS_X_VERSION_MAX_ALLOWED >= 1050)
        return toLanguage(speller, lang) != nil;
+#else
+       return true;
+#endif
 }