From 2e28b198007b525ee66b9864677acdd8ff0d85c7 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Mon, 25 Mar 2019 14:23:38 +0200 Subject: 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 --- Repository.mk | 2 ++ lingucomponent/Module_lingucomponent.mk | 2 +- .../source/spellcheck/macosxspell/macspellimp.hxx | 12 +++++++++--- .../source/spellcheck/macosxspell/macspellimp.mm | 22 +++++++++++++++++----- postprocess/Rdb_services.mk | 4 +++- solenv/bin/native-code.py | 3 ++- 6 files changed, 34 insertions(+), 11 deletions(-) diff --git a/Repository.mk b/Repository.mk index 6508d6866807..20ba9b0697c1 100644 --- a/Repository.mk +++ b/Repository.mk @@ -484,6 +484,8 @@ $(eval $(call gb_Helper_register_libraries_for_install,OOOLIBS,ooo, \ ) \ fps_aqua \ vclplug_osx \ + ) \ + $(if $(filter iOS MACOSX,$(OS)), \ MacOSXSpell \ ) \ )) diff --git a/lingucomponent/Module_lingucomponent.mk b/lingucomponent/Module_lingucomponent.mk index 4f3d2424f992..2bde5d5391e5 100644 --- a/lingucomponent/Module_lingucomponent.mk +++ b/lingucomponent/Module_lingucomponent.mk @@ -14,7 +14,7 @@ $(eval $(call gb_Module_add_targets,lingucomponent,\ Library_guesslang \ Library_hyphen \ Library_lnth \ - $(if $(filter MACOSX,$(OS)),Library_MacOSXSpell) \ + $(if $(filter iOS MACOSX,$(OS)),Library_MacOSXSpell) \ Library_spell \ StaticLibrary_ulingu \ Library_numbertext \ diff --git a/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx b/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx index 084b08c23d0f..fea3ba77c742 100644 --- a/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx +++ b/lingucomponent/source/spellcheck/macosxspell/macspellimp.hxx @@ -22,12 +22,14 @@ #include -#ifdef MACOSX #include +#ifdef MACOSX #include #import -#include +#else +#include #endif +#include #include #include #include @@ -62,8 +64,11 @@ class MacSpellChecker : Locale * aDLocs; OUString * aDNames; sal_Int32 numdict; +#ifdef MACOSX int macTag; // unique tag for this doc - +#else + UITextChecker * pChecker; +#endif ::comphelper::OInterfaceContainerHelper2 aEvtListeners; Reference< XPropertyChangeListener > xPropHelper; linguistic::PropertyHelper_Spell * pPropHelper; @@ -79,6 +84,7 @@ class MacSpellChecker : } sal_Int16 GetSpellFailure( const OUString &rWord, const Locale &rLocale ); + Reference< XSpellAlternatives > GetProposals( const OUString &rWord, const Locale &rLocale ); public: MacSpellChecker(); 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& rProperties ) diff --git a/postprocess/Rdb_services.mk b/postprocess/Rdb_services.mk index 342f19bb0f09..6f6c8d3620c4 100644 --- a/postprocess/Rdb_services.mk +++ b/postprocess/Rdb_services.mk @@ -128,11 +128,13 @@ $(eval $(call gb_Rdb_add_components,services,\ writerperfect/source/calc/wpftcalc \ $(if $(filter MACOSX,$(OS)), \ $(call gb_Helper_optional,AVMEDIA,avmedia/source/macavf/avmediaMacAVF) \ - lingucomponent/source/spellcheck/macosxspell/MacOSXSpell \ fpicker/source/aqua/fps_aqua \ shell/source/backends/macbe/macbe1 \ vcl/vcl.macosx \ ) \ + $(if $(filter iOS MACOSX,$(OS)), \ + lingucomponent/source/spellcheck/macosxspell/MacOSXSpell \ + ) \ $(if $(filter WNT,$(OS)), \ avmedia/source/win/avmediawin \ dtrans/source/generic/dtrans \ diff --git a/solenv/bin/native-code.py b/solenv/bin/native-code.py index 0a47b8c38061..1848e68dcbdb 100755 --- a/solenv/bin/native-code.py +++ b/solenv/bin/native-code.py @@ -62,7 +62,8 @@ core_factory_list = [ ("libpdffilterlo.a", "pdffilter_component_getFactory"), ("libsvgiolo.a", "svgio_component_getFactory"), ("libsvtlo.a", "svt_component_getFactory"), - ("libctllo.a", "ctl_component_getFactory") + ("libctllo.a", "ctl_component_getFactory"), + ("libMacOSXSpelllo.a", "MacOSXSpell_component_getFactory", "#ifdef IOS"), ] core_constructor_list = [ -- cgit