summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2017-03-14 00:03:16 +0100
committerEike Rathke <erack@redhat.com>2017-03-14 12:48:22 +0100
commitbf63e5a3a6ae458ffe10061c1bcf969a534760c5 (patch)
treee07b1edcdb23da1ea4db20b374757243eda26869
parent104d72b00c2c328f63591b26b9e65dd7355649b4 (diff)
tdf#100462 inject language tags provided by spell-checkers to language list
... so they are available already at the first instanciation without having to be added manually, depending on which listing is requested. Change-Id: Idcb8f7fcbc82c757a2b06b8f04b81e88197a0a5b
-rw-r--r--include/svx/langbox.hxx2
-rw-r--r--svx/source/dialog/langbox.cxx82
2 files changed, 65 insertions, 19 deletions
diff --git a/include/svx/langbox.hxx b/include/svx/langbox.hxx
index 4a309e2ee17b..9292ab5f11a7 100644
--- a/include/svx/langbox.hxx
+++ b/include/svx/langbox.hxx
@@ -68,6 +68,8 @@ public:
bool bHasLangNone, bool bLangNoneIsLangAll = false,
bool bCheckSpellAvail = false );
+ void AddLanguages( const css::uno::Sequence< sal_Int16 >& rLanguageTypes, SvxLanguageListFlags nLangList );
+
sal_Int32 InsertLanguage( const LanguageType eLangType );
void InsertDefaultLanguage( sal_Int16 nType );
void InsertSystemLanguage();
diff --git a/svx/source/dialog/langbox.cxx b/svx/source/dialog/langbox.cxx
index 60e5278c8277..8839c45b552d 100644
--- a/svx/source/dialog/langbox.cxx
+++ b/svx/source/dialog/langbox.cxx
@@ -174,6 +174,50 @@ SvxLanguageBoxBase::~SvxLanguageBoxBase()
}
+bool lcl_isPrerequisite( LanguageType nLangType, SvxLanguageListFlags nLangList )
+{
+ return
+ nLangType != LANGUAGE_DONTKNOW &&
+ nLangType != LANGUAGE_SYSTEM &&
+ nLangType != LANGUAGE_NONE &&
+ !MsLangId::isLegacy( nLangType) &&
+ (MsLangId::getSubLanguage( nLangType) ||
+ bool(nLangList & SvxLanguageListFlags::ALSO_PRIMARY_ONLY));
+}
+
+bool lcl_isScriptTypeRequested( LanguageType nLangType, SvxLanguageListFlags nLangList )
+{
+ return
+ bool(nLangList & SvxLanguageListFlags::ALL) ||
+ (bool(nLangList & SvxLanguageListFlags::WESTERN) &&
+ (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) == SvtScriptType::LATIN)) ||
+ (bool(nLangList & SvxLanguageListFlags::CTL) &&
+ (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) == SvtScriptType::COMPLEX)) ||
+ (bool(nLangList & SvxLanguageListFlags::CJK) &&
+ (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) == SvtScriptType::ASIAN));
+}
+
+void SvxLanguageBoxBase::AddLanguages( const css::uno::Sequence< sal_Int16 >& rLanguageTypes,
+ SvxLanguageListFlags nLangList )
+{
+ sal_Int16 const * pLang = rLanguageTypes.getConstArray();
+ sal_Int16 const * const pStop = pLang + rLanguageTypes.getLength();
+ for ( ; pLang < pStop; ++pLang )
+ {
+ LanguageType nLangType = static_cast<LanguageType>(*pLang);
+ if (lcl_isPrerequisite( nLangType, nLangList))
+ {
+ LanguageType nLang = MsLangId::getReplacementForObsoleteLanguage( nLangType );
+ if (lcl_isScriptTypeRequested( nLang, nLangList))
+ {
+ sal_Int32 nAt = ImplTypeToPos( nLang );
+ if (nAt == LISTBOX_ENTRY_NOTFOUND)
+ InsertLanguage( nLang );
+ }
+ }
+ }
+}
+
void SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags nLangList,
bool bHasLangNone, bool bLangNoneIsLangAll, bool bCheckSpellAvail )
{
@@ -186,6 +230,11 @@ void SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags nLangList,
if ( SvxLanguageListFlags::EMPTY != nLangList )
{
+ bool bAddAvailable = (!(nLangList & SvxLanguageListFlags::ONLY_KNOWN) &&
+ ((nLangList & SvxLanguageListFlags::ALL) ||
+ (nLangList & SvxLanguageListFlags::WESTERN) ||
+ (nLangList & SvxLanguageListFlags::CTL) ||
+ (nLangList & SvxLanguageListFlags::CJK)));
Sequence< sal_Int16 > aSpellAvailLang;
Sequence< sal_Int16 > aHyphAvailLang;
Sequence< sal_Int16 > aThesAvailLang;
@@ -197,17 +246,17 @@ void SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags nLangList,
{
Sequence< css::lang::Locale > aTmp;
- if (SvxLanguageListFlags::SPELL_AVAIL & nLangList)
+ if (bAddAvailable || (SvxLanguageListFlags::SPELL_AVAIL & nLangList))
{
aTmp = xAvail->getAvailableLocales( SN_SPELLCHECKER );
aSpellAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
}
- if (SvxLanguageListFlags::HYPH_AVAIL & nLangList)
+ if (bAddAvailable || (SvxLanguageListFlags::HYPH_AVAIL & nLangList))
{
aTmp = xAvail->getAvailableLocales( SN_HYPHENATOR );
aHyphAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
}
- if (SvxLanguageListFlags::THES_AVAIL & nLangList)
+ if (bAddAvailable || (SvxLanguageListFlags::THES_AVAIL & nLangList))
{
aTmp = xAvail->getAvailableLocales( SN_THESAURUS );
aThesAvailLang = lcl_LocaleSeqToLangSeq( aTmp );
@@ -257,22 +306,8 @@ void SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags nLangList,
nLangType = pKnown[i];
else
nLangType = SvtLanguageTable::GetLanguageTypeAtIndex( i );
- if ( nLangType != LANGUAGE_DONTKNOW &&
- nLangType != LANGUAGE_SYSTEM &&
- nLangType != LANGUAGE_NONE &&
- !MsLangId::isLegacy( nLangType) &&
- (MsLangId::getSubLanguage( nLangType) ||
- bool(nLangList & SvxLanguageListFlags::ALSO_PRIMARY_ONLY)) &&
- (bool(nLangList & SvxLanguageListFlags::ALL) ||
- (bool(nLangList & SvxLanguageListFlags::WESTERN) &&
- (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
- SvtScriptType::LATIN)) ||
- (bool(nLangList & SvxLanguageListFlags::CTL) &&
- (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
- SvtScriptType::COMPLEX)) ||
- (bool(nLangList & SvxLanguageListFlags::CJK) &&
- (SvtLanguageOptions::GetScriptTypeOfLanguage(nLangType) ==
- SvtScriptType::ASIAN)) ||
+ if ( lcl_isPrerequisite( nLangType, nLangList) &&
+ (lcl_isScriptTypeRequested( nLangType, nLangList) ||
(bool(nLangList & SvxLanguageListFlags::FBD_CHARS) &&
MsLangId::hasForbiddenCharacters(nLangType)) ||
(bool(nLangList & SvxLanguageListFlags::SPELL_AVAIL) &&
@@ -290,6 +325,15 @@ void SvxLanguageBoxBase::SetLanguageList( SvxLanguageListFlags nLangList,
InsertLanguage( nLangType );
}
+ if (bAddAvailable)
+ {
+ // Spell checkers, hyphenators and thesauri may add language tags
+ // unknown so far.
+ AddLanguages( aSpellAvailLang, nLangList);
+ AddLanguages( aHyphAvailLang, nLangList);
+ AddLanguages( aThesAvailLang, nLangList);
+ }
+
if (bHasLangNone)
InsertLanguage( LANGUAGE_NONE );
}