summaryrefslogtreecommitdiff
path: root/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2019-03-25 14:23:38 +0200
committerTor Lillqvist <tml@collabora.com>2019-03-25 15:01:03 +0200
commit2e28b198007b525ee66b9864677acdd8ff0d85c7 (patch)
tree20a2d5feab8ac1946fd9dd0ee871282f78d833ee /lingucomponent/source/spellcheck/macosxspell/macspellimp.mm
parent7afb8ab90f29068c63f2920a52c4df172631b59d (diff)
tdf#124172: Use the MacOSXSpell library on iOS, too
The code needed just a small amount of ifdefs to use UITextChecker on iOS instead of NSSpellChecker. Change-Id: I19edfffd3cc317a79beacc0b94668a6fd5ea3b32
Diffstat (limited to 'lingucomponent/source/spellcheck/macosxspell/macspellimp.mm')
-rw-r--r--lingucomponent/source/spellcheck/macosxspell/macspellimp.mm22
1 files changed, 17 insertions, 5 deletions
diff --git a/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm b/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm
index 9eb7e65244d6..d66e7149ea70 100644
--- a/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm
+++ b/lingucomponent/source/spellcheck/macosxspell/macspellimp.mm
@@ -54,10 +54,14 @@ MacSpellChecker::MacSpellChecker() :
bDisposing = false;
pPropHelper = nullptr;
numdict = 0;
+#ifndef IOS
NSApplicationLoad();
NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
macTag = [NSSpellChecker uniqueSpellDocumentTag];
[pool release];
+#else
+ pChecker = [[UITextChecker alloc] init];
+#endif
}
@@ -109,7 +113,11 @@ Sequence< Locale > SAL_CALL MacSpellChecker::getLocales()
// TODO How on macOS?
// invoke a second dictionary manager to get the shared dictionary list
+#ifdef MACOSX
NSArray *aSpellCheckLanguages = [[NSSpellChecker sharedSpellChecker] availableLanguages];
+#else
+ NSArray *aSpellCheckLanguages = [UITextChecker availableLanguages];
+#endif
for (NSUInteger i = 0; i < [aSpellCheckLanguages count]; i++)
{
@@ -332,8 +340,12 @@ sal_Int16 MacSpellChecker::GetSpellFailure( const OUString &rWord, const Locale
aLang = [aLang stringByAppendingString:aTaggedCountry];
}
+#ifdef MACOSX
NSInteger aCount;
NSRange range = [[NSSpellChecker sharedSpellChecker] checkSpellingOfString:aNSStr startingAt:0 language:aLang wrap:false inSpellDocumentWithTag:macTag wordCount:&aCount];
+#else
+ NSRange range = [pChecker rangeOfMisspelledWordInString:aNSStr range:NSMakeRange(0, [aNSStr length]) startingAt:0 wrap:NO language:aLang];
+#endif
int rVal = 0;
if(range.length>0)
{
@@ -394,10 +406,8 @@ sal_Bool SAL_CALL
return (nFailure == -1);
}
-namespace {
-
Reference< XSpellAlternatives >
- GetProposals( const OUString &rWord, const Locale &rLocale )
+ MacSpellChecker::GetProposals( const OUString &rWord, const Locale &rLocale )
{
// Retrieves the return values for the 'spell' function call in case
// of a misspelled word.
@@ -432,8 +442,12 @@ Reference< XSpellAlternatives >
NSString* aTaggedCountry = [@"_" stringByAppendingString:aCountry];
aLang = [aLang stringByAppendingString:aTaggedCountry];
}
+#ifdef MACOSX
[[NSSpellChecker sharedSpellChecker] setLanguage:aLang];
NSArray *guesses = [[NSSpellChecker sharedSpellChecker] guessesForWordRange:NSMakeRange(0, [aNSStr length]) inString:aNSStr language:aLang inSpellDocumentWithTag:0];
+#else
+ NSArray *guesses = [pChecker guessesForWordRange:NSMakeRange(0, [aNSStr length]) inString:aNSStr language:aLang];
+#endif
count = [guesses count];
if (count)
{
@@ -460,8 +474,6 @@ Reference< XSpellAlternatives >
}
-}
-
Reference< XSpellAlternatives > SAL_CALL
MacSpellChecker::spell( const OUString& rWord, const Locale& rLocale,
const css::uno::Sequence<PropertyValue>& rProperties )