summaryrefslogtreecommitdiff
path: root/svl
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2021-07-26 14:45:46 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-07-28 08:38:52 +0200
commitd8fec570c21c5e45ba593ee96cc1ba5d45d77fc8 (patch)
treeda5f5eed2c066325c409e64366b4569a54fb1791 /svl
parent3808418e38fe9540a286ad48f1c3eaed2706f78c (diff)
use officecfg for SvtCJKOptions
and remove some unused options Change-Id: I487a233de4f7414012e5405f2c2e1f9c8b8fb4f2 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119554 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svl')
-rw-r--r--svl/source/config/cjkoptions.cxx506
-rw-r--r--svl/source/config/itemholder2.cxx4
2 files changed, 111 insertions, 399 deletions
diff --git a/svl/source/config/cjkoptions.cxx b/svl/source/config/cjkoptions.cxx
index 84c972875f3a..572794926a04 100644
--- a/svl/source/config/cjkoptions.cxx
+++ b/svl/source/config/cjkoptions.cxx
@@ -19,453 +19,169 @@
#include <svl/cjkoptions.hxx>
-#include <o3tl/any.hxx>
#include <svl/languageoptions.hxx>
#include <i18nlangtag/lang.h>
#include <i18nlangtag/languagetag.hxx>
#include <unotools/configitem.hxx>
#include <com/sun/star/uno/Any.h>
#include <com/sun/star/uno/Sequence.hxx>
-#include <osl/mutex.hxx>
-#include <rtl/instance.hxx>
#include <officecfg/System.hxx>
-
-#include "itemholder2.hxx"
+#include <officecfg/Office/Common.hxx>
+#include <mutex>
using namespace ::com::sun::star::uno;
-#define CFG_READONLY_DEFAULT false
+static void SvtCJKOptions_Load();
-class SvtCJKOptions_Impl : public utl::ConfigItem
+namespace SvtCJKOptions
{
- bool bIsLoaded;
- bool bCJKFont;
- bool bVerticalText;
- bool bAsianTypography;
- bool bJapaneseFind;
- bool bRuby;
- bool bChangeCaseMap;
- bool bDoubleLines;
- bool bEmphasisMarks;
- bool bVerticalCallOut;
-
- bool bROCJKFont;
- bool bROVerticalText;
- bool bROAsianTypography;
- bool bROJapaneseFind;
- bool bRORuby;
- bool bROChangeCaseMap;
- bool bRODoubleLines;
- bool bROEmphasisMarks;
- bool bROVerticalCallOut;
-
- virtual void ImplCommit() override;
-
-public:
- SvtCJKOptions_Impl();
-
- virtual void Notify( const css::uno::Sequence< OUString >& rPropertyNames ) override;
- void Load();
-
- bool IsLoaded() const { return bIsLoaded; }
-
- bool IsCJKFontEnabled() const { return bCJKFont; }
- bool IsVerticalTextEnabled() const { return bVerticalText; }
- bool IsAsianTypographyEnabled() const { return bAsianTypography; }
- bool IsJapaneseFindEnabled() const { return bJapaneseFind; }
- bool IsRubyEnabled() const { return bRuby; }
- bool IsChangeCaseMapEnabled() const { return bChangeCaseMap; }
- bool IsDoubleLinesEnabled() const { return bDoubleLines; }
- bool IsAnyEnabled() const {
- return bCJKFont||bVerticalText||bAsianTypography||bJapaneseFind||
- bRuby||bChangeCaseMap||bDoubleLines||bEmphasisMarks||bVerticalCallOut; }
- void SetAll(bool bSet);
- bool IsReadOnly(SvtCJKOptions::EOption eOption) const;
-};
-
-namespace
+bool IsCJKFontEnabled()
{
- struct PropertyNames
- : public rtl::Static< Sequence<OUString>, PropertyNames > {};
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::CJKFont::get();
}
-SvtCJKOptions_Impl::SvtCJKOptions_Impl() :
- utl::ConfigItem("Office.Common/I18N/CJK"),
- bIsLoaded(false),
- bCJKFont(true),
- bVerticalText(true),
- bAsianTypography(true),
- bJapaneseFind(true),
- bRuby(true),
- bChangeCaseMap(true),
- bDoubleLines(true),
- bEmphasisMarks(true),
- bVerticalCallOut(true),
- bROCJKFont(CFG_READONLY_DEFAULT),
- bROVerticalText(CFG_READONLY_DEFAULT),
- bROAsianTypography(CFG_READONLY_DEFAULT),
- bROJapaneseFind(CFG_READONLY_DEFAULT),
- bRORuby(CFG_READONLY_DEFAULT),
- bROChangeCaseMap(CFG_READONLY_DEFAULT),
- bRODoubleLines(CFG_READONLY_DEFAULT),
- bROEmphasisMarks(CFG_READONLY_DEFAULT),
- bROVerticalCallOut(CFG_READONLY_DEFAULT)
+bool IsVerticalTextEnabled()
{
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::VerticalText::get();
}
-void SvtCJKOptions_Impl::SetAll(bool bSet)
+bool IsAsianTypographyEnabled()
{
- if (
- bROCJKFont ||
- bROVerticalText ||
- bROAsianTypography ||
- bROJapaneseFind ||
- bRORuby ||
- bROChangeCaseMap ||
- bRODoubleLines ||
- bROEmphasisMarks ||
- bROVerticalCallOut
- )
- return;
-
- bCJKFont=bSet;
- bVerticalText=bSet;
- bAsianTypography=bSet;
- bJapaneseFind=bSet;
- bRuby=bSet;
- bChangeCaseMap=bSet;
- bDoubleLines=bSet;
- bEmphasisMarks=bSet;
- bVerticalCallOut=bSet;
-
- SetModified();
- Commit();
- NotifyListeners(ConfigurationHints::NONE);
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::AsianTypography::get();
}
-void SvtCJKOptions_Impl::Load()
+bool IsJapaneseFindEnabled()
{
- Sequence<OUString> &rPropertyNames = PropertyNames::get();
- if(!rPropertyNames.hasElements())
- {
- rPropertyNames.realloc(9);
- OUString* pNames = rPropertyNames.getArray();
-
- pNames[0] = "CJKFont";
- pNames[1] = "VerticalText";
- pNames[2] = "AsianTypography";
- pNames[3] = "JapaneseFind";
- pNames[4] = "Ruby";
- pNames[5] = "ChangeCaseMap";
- pNames[6] = "DoubleLines";
- pNames[7] = "EmphasisMarks";
- pNames[8] = "VerticalCallOut";
-
- EnableNotification( rPropertyNames );
- }
- Sequence< Any > aValues = GetProperties(rPropertyNames);
- Sequence< sal_Bool > aROStates = GetReadOnlyStates(rPropertyNames);
- const Any* pValues = aValues.getConstArray();
- const sal_Bool* pROStates = aROStates.getConstArray();
- assert(aValues.getLength() == rPropertyNames.getLength() && "GetProperties failed");
- assert(aROStates.getLength() == rPropertyNames.getLength() && "GetReadOnlyStates failed");
- if ( aValues.getLength() == rPropertyNames.getLength() && aROStates.getLength() == rPropertyNames.getLength() )
- {
- for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ )
- {
- if( pValues[nProp].hasValue() )
- {
- bool bValue = *o3tl::doAccess<bool>(pValues[nProp]);
- switch ( nProp )
- {
- case 0: { bCJKFont = bValue; bROCJKFont = pROStates[nProp]; } break;
- case 1: { bVerticalText = bValue; bROVerticalText = pROStates[nProp]; } break;
- case 2: { bAsianTypography = bValue; bROAsianTypography = pROStates[nProp]; } break;
- case 3: { bJapaneseFind = bValue; bROJapaneseFind = pROStates[nProp]; } break;
- case 4: { bRuby = bValue; bRORuby = pROStates[nProp]; } break;
- case 5: { bChangeCaseMap = bValue; bROChangeCaseMap = pROStates[nProp]; } break;
- case 6: { bDoubleLines = bValue; bRODoubleLines = pROStates[nProp]; } break;
- case 7: { bEmphasisMarks = bValue; bROEmphasisMarks = pROStates[nProp]; } break;
- case 8: { bVerticalCallOut = bValue; bROVerticalCallOut = pROStates[nProp]; } break;
- }
- }
- }
- }
-
- if (!bCJKFont)
- {
- SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
- //system locale is CJK
- bool bAutoEnableCJK = bool(nScriptType & SvtScriptType::ASIAN);
-
- if (!bAutoEnableCJK)
- {
- //windows secondary system locale is CJK
- OUString sWin16SystemLocale = officecfg::System::L10N::SystemLocale::get();
- LanguageType eSystemLanguage = LANGUAGE_NONE;
- if( !sWin16SystemLocale.isEmpty() )
- eSystemLanguage = LanguageTag::convertToLanguageTypeWithFallback( sWin16SystemLocale );
- if (eSystemLanguage != LANGUAGE_SYSTEM)
- {
- SvtScriptType nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
- bAutoEnableCJK = bool(nWinScript & SvtScriptType::ASIAN);
- }
-
- //CJK keyboard is installed
- if (!bAutoEnableCJK)
- bAutoEnableCJK = SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled();
- }
-
- if (bAutoEnableCJK)
- {
- SetAll(true);
- }
- }
- bIsLoaded = true;
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::JapaneseFind::get();
}
-void SvtCJKOptions_Impl::Notify( const Sequence< OUString >& )
+bool IsRubyEnabled()
{
- Load();
- NotifyListeners(ConfigurationHints::NONE);
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::Ruby::get();
}
-void SvtCJKOptions_Impl::ImplCommit()
+bool IsChangeCaseMapEnabled()
{
- Sequence<OUString> &rPropertyNames = PropertyNames::get();
- OUString* pOrgNames = rPropertyNames.getArray();
- sal_Int32 nOrgCount = rPropertyNames.getLength();
-
- Sequence< OUString > aNames(nOrgCount);
- Sequence< Any > aValues(nOrgCount);
-
- OUString* pNames = aNames.getArray();
- Any* pValues = aValues.getArray();
- sal_Int32 nRealCount = 0;
-
- for(int nProp = 0; nProp < nOrgCount; nProp++)
- {
- switch(nProp)
- {
- case 0:
- {
- if (!bROCJKFont)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bCJKFont;
- ++nRealCount;
- }
- }
- break;
-
- case 1:
- {
- if (!bROVerticalText)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bVerticalText;
- ++nRealCount;
- }
- }
- break;
-
- case 2:
- {
- if (!bROAsianTypography)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bAsianTypography;
- ++nRealCount;
- }
- }
- break;
-
- case 3:
- {
- if (!bROJapaneseFind)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bJapaneseFind;
- ++nRealCount;
- }
- }
- break;
-
- case 4:
- {
- if (!bRORuby)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bRuby;
- ++nRealCount;
- }
- }
- break;
-
- case 5:
- {
- if (!bROChangeCaseMap)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bChangeCaseMap;
- ++nRealCount;
- }
- }
- break;
-
- case 6:
- {
- if (!bRODoubleLines)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bDoubleLines;
- ++nRealCount;
- }
- }
- break;
-
- case 7:
- {
- if (!bROEmphasisMarks)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bEmphasisMarks;
- ++nRealCount;
- }
- }
- break;
-
- case 8:
- {
- if (!bROVerticalCallOut)
- {
- pNames[nRealCount] = pOrgNames[nProp];
- pValues[nRealCount] <<= bVerticalCallOut;
- ++nRealCount;
- }
- }
- break;
- }
- }
- aNames.realloc(nRealCount);
- aValues.realloc(nRealCount);
- PutProperties(aNames, aValues);
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::ChangeCaseMap::get();
}
-bool SvtCJKOptions_Impl::IsReadOnly(SvtCJKOptions::EOption eOption) const
+bool IsDoubleLinesEnabled()
{
- bool bReadOnly = CFG_READONLY_DEFAULT;
- switch(eOption)
- {
- case SvtCJKOptions::E_CJKFONT : bReadOnly = bROCJKFont; break;
- case SvtCJKOptions::E_VERTICALTEXT : bReadOnly = bROVerticalText; break;
- case SvtCJKOptions::E_ASIANTYPOGRAPHY : bReadOnly = bROAsianTypography; break;
- case SvtCJKOptions::E_JAPANESEFIND : bReadOnly = bROJapaneseFind; break;
- case SvtCJKOptions::E_RUBY : bReadOnly = bRORuby; break;
- case SvtCJKOptions::E_CHANGECASEMAP : bReadOnly = bROChangeCaseMap; break;
- case SvtCJKOptions::E_DOUBLELINES : bReadOnly = bRODoubleLines; break;
- case SvtCJKOptions::E_EMPHASISMARKS : bReadOnly = bROEmphasisMarks; break;
- case SvtCJKOptions::E_VERTICALCALLOUT : bReadOnly = bROVerticalCallOut; break;
- case SvtCJKOptions::E_ALL : if (bROCJKFont || bROVerticalText || bROAsianTypography || bROJapaneseFind || bRORuby || bROChangeCaseMap || bRODoubleLines || bROEmphasisMarks || bROVerticalCallOut)
- bReadOnly = true;
- break;
- }
- return bReadOnly;
+ SvtCJKOptions_Load();
+ return officecfg::Office::Common::I18N::CJK::DoubleLines::get();
}
-namespace {
-
- // global
- std::weak_ptr<SvtCJKOptions_Impl> g_pCJKOptions;
-
- struct theCJKOptionsMutex : public rtl::Static< ::osl::Mutex , theCJKOptionsMutex >{};
-}
-
-SvtCJKOptions::SvtCJKOptions(bool bDontLoad)
-{
- // Global access, must be guarded (multithreading)
- ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() );
- pImpl = g_pCJKOptions.lock();
- if ( !pImpl )
- {
- pImpl = std::make_shared<SvtCJKOptions_Impl>();
- g_pCJKOptions = pImpl;
- ItemHolder2::holdConfigItem(EItem::CJKOptions);
- }
-
- if( !bDontLoad && !pImpl->IsLoaded())
- pImpl->Load();
-}
-
-
-SvtCJKOptions::~SvtCJKOptions()
+void SetAll(bool bSet)
{
- // Global access, must be guarded (multithreading)
- ::osl::MutexGuard aGuard( theCJKOptionsMutex::get() );
+ SvtCJKOptions_Load();
+ if ( officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly() )
+ return;
- // pImpl needs to be cleared before the mutex is dropped
- pImpl.reset();
+ std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::I18N::CJK::CJKFont::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::VerticalText::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::AsianTypography::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::JapaneseFind::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::Ruby::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::ChangeCaseMap::set(bSet, xChanges);
+ officecfg::Office::Common::I18N::CJK::DoubleLines::set(bSet, xChanges);
+ xChanges->commit();
}
-bool SvtCJKOptions::IsCJKFontEnabled() const
+bool IsAnyEnabled()
{
- assert(pImpl->IsLoaded());
- return pImpl->IsCJKFontEnabled();
+ SvtCJKOptions_Load();
+ return IsCJKFontEnabled() || IsVerticalTextEnabled() || IsAsianTypographyEnabled() || IsJapaneseFindEnabled() ||
+ IsRubyEnabled() || IsChangeCaseMapEnabled() || IsDoubleLinesEnabled() ;
}
-bool SvtCJKOptions::IsVerticalTextEnabled() const
+bool IsReadOnly(EOption eOption)
{
- assert(pImpl->IsLoaded());
- return pImpl->IsVerticalTextEnabled();
+ SvtCJKOptions_Load();
+ switch (eOption)
+ {
+ case E_CJKFONT: return officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly();
+ case E_VERTICALTEXT: return officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly();
+ case E_ASIANTYPOGRAPHY: return officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly();
+ case E_JAPANESEFIND: return officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly();
+ case E_RUBY: return officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly();
+ case E_CHANGECASEMAP: return officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly();
+ case E_DOUBLELINES: return officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly();
+ case E_ALL:
+ return officecfg::Office::Common::I18N::CJK::CJKFont::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::VerticalText::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::AsianTypography::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::JapaneseFind::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::Ruby::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::ChangeCaseMap::isReadOnly()
+ || officecfg::Office::Common::I18N::CJK::DoubleLines::isReadOnly();
+ default:
+ assert(false);
+ }
+ return false;
}
-bool SvtCJKOptions::IsAsianTypographyEnabled() const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsAsianTypographyEnabled();
-}
+} // namespace SvtCJKOptions
-bool SvtCJKOptions::IsJapaneseFindEnabled() const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsJapaneseFindEnabled();
-}
-bool SvtCJKOptions::IsRubyEnabled() const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsRubyEnabled();
-}
+static std::once_flag gLoadFlag;
-bool SvtCJKOptions::IsChangeCaseMapEnabled() const
+static void SvtCJKOptions_Load()
{
- assert(pImpl->IsLoaded());
- return pImpl->IsChangeCaseMapEnabled();
-}
+ std::call_once(gLoadFlag,
+ []()
+ {
+ if (officecfg::Office::Common::I18N::CJK::CJKFont::get())
+ return;
-bool SvtCJKOptions::IsDoubleLinesEnabled() const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsDoubleLinesEnabled();
-}
+ SvtScriptType nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(LANGUAGE_SYSTEM);
+ //system locale is CJK
+ bool bAutoEnableCJK = bool(nScriptType & SvtScriptType::ASIAN);
-void SvtCJKOptions::SetAll(bool bSet)
-{
- assert(pImpl->IsLoaded());
- pImpl->SetAll(bSet);
-}
+ if (!bAutoEnableCJK)
+ {
+ //windows secondary system locale is CJK
+ OUString sWin16SystemLocale = officecfg::System::L10N::SystemLocale::get();
+ LanguageType eSystemLanguage = LANGUAGE_NONE;
+ if( !sWin16SystemLocale.isEmpty() )
+ eSystemLanguage = LanguageTag::convertToLanguageTypeWithFallback( sWin16SystemLocale );
+ if (eSystemLanguage != LANGUAGE_SYSTEM)
+ {
+ SvtScriptType nWinScript = SvtLanguageOptions::GetScriptTypeOfLanguage( eSystemLanguage );
+ bAutoEnableCJK = bool(nWinScript & SvtScriptType::ASIAN);
+ }
-bool SvtCJKOptions::IsAnyEnabled() const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsAnyEnabled();
-}
+ //CJK keyboard is installed
+ if (!bAutoEnableCJK)
+ bAutoEnableCJK = SvtSystemLanguageOptions::isCJKKeyboardLayoutInstalled();
+ }
-bool SvtCJKOptions::IsReadOnly(EOption eOption) const
-{
- assert(pImpl->IsLoaded());
- return pImpl->IsReadOnly(eOption);
+ if (bAutoEnableCJK)
+ {
+ std::shared_ptr<comphelper::ConfigurationChanges> xChanges(comphelper::ConfigurationChanges::create());
+ officecfg::Office::Common::I18N::CJK::CJKFont::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::VerticalText::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::AsianTypography::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::JapaneseFind::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::Ruby::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::ChangeCaseMap::set(true, xChanges);
+ officecfg::Office::Common::I18N::CJK::DoubleLines::set(true, xChanges);
+ xChanges->commit();
+ }
+ });
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/svl/source/config/itemholder2.cxx b/svl/source/config/itemholder2.cxx
index 35e9e3da2550..6227ce390b45 100644
--- a/svl/source/config/itemholder2.cxx
+++ b/svl/source/config/itemholder2.cxx
@@ -106,10 +106,6 @@ void ItemHolder2::impl_newItem(TItemInfo& rItem)
{
switch(rItem.eItem)
{
- case EItem::CJKOptions :
- rItem.pItem.reset( new SvtCJKOptions() );
- break;
-
case EItem::CTLOptions :
rItem.pItem.reset( new SvtCTLOptions() );
break;