From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- svl/source/config/asiancfg.cxx | 172 +++++++++++++ svl/source/config/cjkoptions.cxx | 170 +++++++++++++ svl/source/config/ctloptions.cxx | 446 ++++++++++++++++++++++++++++++++++ svl/source/config/itemholder2.cxx | 117 +++++++++ svl/source/config/itemholder2.hxx | 58 +++++ svl/source/config/languageoptions.cxx | 137 +++++++++++ 6 files changed, 1100 insertions(+) create mode 100644 svl/source/config/asiancfg.cxx create mode 100644 svl/source/config/cjkoptions.cxx create mode 100644 svl/source/config/ctloptions.cxx create mode 100644 svl/source/config/itemholder2.cxx create mode 100644 svl/source/config/itemholder2.hxx create mode 100644 svl/source/config/languageoptions.cxx (limited to 'svl/source/config') diff --git a/svl/source/config/asiancfg.cxx b/svl/source/config/asiancfg.cxx new file mode 100644 index 0000000000..a8f4e08e51 --- /dev/null +++ b/svl/source/config/asiancfg.cxx @@ -0,0 +1,172 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +namespace { + +OUString toString(css::lang::Locale const & locale) { + SAL_WARN_IF( locale.Language.indexOf('-') != -1, "svl", + "Locale language \"" << locale.Language << "\" contains \"-\""); + SAL_WARN_IF( locale.Country.indexOf('-') != -1, "svl", + "Locale country \"" << locale.Country << "\" contains \"-\""); + return LanguageTag::convertToBcp47( locale, false); +} + +} + +struct SvxAsianConfig::Impl { + Impl(): + batch(comphelper::ConfigurationChanges::create()) + {} + + Impl(const Impl&) = delete; + Impl& operator=(const Impl&) = delete; + + std::shared_ptr< comphelper::ConfigurationChanges > batch; +}; + +SvxAsianConfig::SvxAsianConfig(): impl_(new Impl) {} + +SvxAsianConfig::~SvxAsianConfig() {} + +void SvxAsianConfig::Commit() { + impl_->batch->commit(); +} + +bool SvxAsianConfig::IsKerningWesternTextOnly() const { + return + officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::get(); +} + +void SvxAsianConfig::SetKerningWesternTextOnly(bool value) { + officecfg::Office::Common::AsianLayout::IsKerningWesternTextOnly::set( + value, impl_->batch); +} + +CharCompressType SvxAsianConfig::GetCharDistanceCompression() const { + return static_cast(officecfg::Office::Common::AsianLayout::CompressCharacterDistance::get()); +} + +void SvxAsianConfig::SetCharDistanceCompression(CharCompressType value) { + officecfg::Office::Common::AsianLayout::CompressCharacterDistance::set( + static_cast(value), impl_->batch); +} + +css::uno::Sequence< css::lang::Locale > SvxAsianConfig::GetStartEndCharLocales() + const +{ + const css::uno::Sequence< OUString > ns( + officecfg::Office::Common::AsianLayout::StartEndCharacters::get()-> + getElementNames()); + css::uno::Sequence< css::lang::Locale > ls(ns.getLength()); + std::transform(ns.begin(), ns.end(), ls.getArray(), + [](const OUString& rName) -> css::lang::Locale { + return LanguageTag::convertToLocale( rName, false); }); + return ls; +} + +bool SvxAsianConfig::GetStartEndChars( + css::lang::Locale const & locale, OUString & startChars, + OUString & endChars) const +{ + css::uno::Reference< css::container::XNameAccess > set( + officecfg::Office::Common::AsianLayout::StartEndCharacters::get()); + css::uno::Any v; + try { + v = set->getByName(toString(locale)); + } catch (css::container::NoSuchElementException &) { + return false; + } + css::uno::Reference< css::beans::XPropertySet > el( + v.get< css::uno::Reference< css::beans::XPropertySet > >(), + css::uno::UNO_SET_THROW); + startChars = el->getPropertyValue("StartCharacters").get< OUString >(); + endChars = el->getPropertyValue("EndCharacters").get< OUString >(); + return true; +} + +void SvxAsianConfig::SetStartEndChars( + css::lang::Locale const & locale, OUString const * startChars, + OUString const * endChars) +{ + assert((startChars == nullptr) == (endChars == nullptr)); + css::uno::Reference< css::container::XNameContainer > set( + officecfg::Office::Common::AsianLayout::StartEndCharacters::get( + impl_->batch)); + OUString name(toString(locale)); + if (startChars == nullptr) { + try { + set->removeByName(name); + } catch (css::container::NoSuchElementException &) {} + } else { + bool found; + css::uno::Any v; + try { + v = set->getByName(name); + found = true; + } catch (css::container::NoSuchElementException &) { + found = false; + } + if (found) { + css::uno::Reference< css::beans::XPropertySet > el( + v.get< css::uno::Reference< css::beans::XPropertySet > >(), + css::uno::UNO_SET_THROW); + el->setPropertyValue("StartCharacters", css::uno::Any(*startChars)); + el->setPropertyValue("EndCharacters", css::uno::Any(*endChars)); + } else { + css::uno::Reference< css::beans::XPropertySet > el( + (css::uno::Reference< css::lang::XSingleServiceFactory >( + set, css::uno::UNO_QUERY_THROW)-> + createInstance()), + css::uno::UNO_QUERY_THROW); + el->setPropertyValue("StartCharacters", css::uno::Any(*startChars)); + el->setPropertyValue("EndCharacters", css::uno::Any(*endChars)); + css::uno::Any v2(el); + try { + set->insertByName(name, v2); + } catch (css::container::ElementExistException &) { + SAL_INFO("svl", "Concurrent update race for \"" << name << '"'); + } + } + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/cjkoptions.cxx b/svl/source/config/cjkoptions.cxx new file mode 100644 index 0000000000..e43d379f7e --- /dev/null +++ b/svl/source/config/cjkoptions.cxx @@ -0,0 +1,170 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#include + +#include +#include +#include +#include +#include +#include + +using namespace ::com::sun::star::uno; + +static void SvtCJKOptions_Load(); + +namespace SvtCJKOptions +{ + +bool IsCJKFontEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::CJKFont::get(); +} + +bool IsVerticalTextEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::VerticalText::get(); +} + +bool IsAsianTypographyEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::AsianTypography::get(); +} + +bool IsJapaneseFindEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::JapaneseFind::get(); +} + +bool IsRubyEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::Ruby::get(); +} + +bool IsChangeCaseMapEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::ChangeCaseMap::get(); +} + +bool IsDoubleLinesEnabled() +{ + SvtCJKOptions_Load(); + return officecfg::Office::Common::I18N::CJK::DoubleLines::get(); +} + +void SetAll(bool bSet) +{ + 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; + + std::shared_ptr 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 IsAnyEnabled() +{ + SvtCJKOptions_Load(); + return IsCJKFontEnabled() || IsVerticalTextEnabled() || IsAsianTypographyEnabled() || IsJapaneseFindEnabled() || + IsRubyEnabled() || IsChangeCaseMapEnabled() || IsDoubleLinesEnabled() ; +} + +bool IsAnyReadOnly() +{ + SvtCJKOptions_Load(); + 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(); +} + +} // namespace SvtCJKOptions + + +static std::once_flag gLoadFlag; + +static void SvtCJKOptions_Load() +{ + std::call_once(gLoadFlag, + []() + { + if (officecfg::Office::Common::I18N::CJK::CJKFont::get()) + return; + + 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) + { + std::shared_ptr 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/ctloptions.cxx b/svl/source/config/ctloptions.cxx new file mode 100644 index 0000000000..07c9c67fd6 --- /dev/null +++ b/svl/source/config/ctloptions.cxx @@ -0,0 +1,446 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include + +#include +#include +#include +#include +#include +#include "itemholder2.hxx" +#include + +using namespace ::com::sun::star; +using namespace ::com::sun::star::uno; + +#define CFG_READONLY_DEFAULT false + +class SvtCTLOptions_Impl : public utl::ConfigItem +{ +private: + bool m_bIsLoaded; + bool m_bCTLFontEnabled; + bool m_bCTLSequenceChecking; + bool m_bCTLRestricted; + bool m_bCTLTypeAndReplace; + SvtCTLOptions::CursorMovement m_eCTLCursorMovement; + SvtCTLOptions::TextNumerals m_eCTLTextNumerals; + + bool m_bROCTLFontEnabled; + bool m_bROCTLSequenceChecking; + bool m_bROCTLRestricted; + bool m_bROCTLTypeAndReplace; + bool m_bROCTLCursorMovement; + bool m_bROCTLTextNumerals; + + virtual void ImplCommit() override; + +public: + SvtCTLOptions_Impl(); + virtual ~SvtCTLOptions_Impl() override; + + virtual void Notify( const Sequence< OUString >& _aPropertyNames ) override; + void Load(); + + bool IsLoaded() const { return m_bIsLoaded; } + void SetCTLFontEnabled( bool _bEnabled ); + + void SetCTLSequenceChecking( bool _bEnabled ); + + void SetCTLSequenceCheckingRestricted( bool _bEnable ); + + void SetCTLSequenceCheckingTypeAndReplace( bool _bEnable ); + + void SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ); + + void SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ); + + bool IsReadOnly(SvtCTLOptions::EOption eOption) const; +}; +namespace +{ + Sequence & PropertyNames() + { + static Sequence SINGLETON; + return SINGLETON; + } +} +bool SvtCTLOptions_Impl::IsReadOnly(SvtCTLOptions::EOption eOption) const +{ + bool bReadOnly = CFG_READONLY_DEFAULT; + switch(eOption) + { + case SvtCTLOptions::E_CTLFONT : bReadOnly = m_bROCTLFontEnabled ; break; + case SvtCTLOptions::E_CTLSEQUENCECHECKING : bReadOnly = m_bROCTLSequenceChecking ; break; + case SvtCTLOptions::E_CTLCURSORMOVEMENT : bReadOnly = m_bROCTLCursorMovement ; break; + case SvtCTLOptions::E_CTLTEXTNUMERALS : bReadOnly = m_bROCTLTextNumerals ; break; + case SvtCTLOptions::E_CTLSEQUENCECHECKINGRESTRICTED: bReadOnly = m_bROCTLRestricted ; break; + case SvtCTLOptions::E_CTLSEQUENCECHECKINGTYPEANDREPLACE: bReadOnly = m_bROCTLTypeAndReplace; break; + default: assert(false); + } + return bReadOnly; +} +SvtCTLOptions_Impl::SvtCTLOptions_Impl() : + + utl::ConfigItem("Office.Common/I18N/CTL"), + + m_bIsLoaded ( false ), + m_bCTLFontEnabled ( true ), + m_bCTLSequenceChecking ( false ), + m_bCTLRestricted ( false ), + m_bCTLTypeAndReplace ( false ), + m_eCTLCursorMovement ( SvtCTLOptions::MOVEMENT_LOGICAL ), + m_eCTLTextNumerals ( SvtCTLOptions::NUMERALS_ARABIC ), + + m_bROCTLFontEnabled ( CFG_READONLY_DEFAULT ), + m_bROCTLSequenceChecking( CFG_READONLY_DEFAULT ), + m_bROCTLRestricted ( CFG_READONLY_DEFAULT ), + m_bROCTLTypeAndReplace ( CFG_READONLY_DEFAULT ), + m_bROCTLCursorMovement ( CFG_READONLY_DEFAULT ), + m_bROCTLTextNumerals ( CFG_READONLY_DEFAULT ) +{ +} +SvtCTLOptions_Impl::~SvtCTLOptions_Impl() +{ + assert(!IsModified()); // should have been committed +} + +void SvtCTLOptions_Impl::Notify( const Sequence< OUString >& ) +{ + Load(); + NotifyListeners(ConfigurationHints::CtlSettingsChanged); +} + +void SvtCTLOptions_Impl::ImplCommit() +{ + Sequence< OUString > &rPropertyNames = PropertyNames(); + 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 (!m_bROCTLFontEnabled) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= m_bCTLFontEnabled; + ++nRealCount; + } + } + break; + + case 1: + { + if (!m_bROCTLSequenceChecking) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= m_bCTLSequenceChecking; + ++nRealCount; + } + } + break; + + case 2: + { + if (!m_bROCTLCursorMovement) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= static_cast(m_eCTLCursorMovement); + ++nRealCount; + } + } + break; + + case 3: + { + if (!m_bROCTLTextNumerals) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= static_cast(m_eCTLTextNumerals); + ++nRealCount; + } + } + break; + + case 4: + { + if (!m_bROCTLRestricted) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= m_bCTLRestricted; + ++nRealCount; + } + } + break; + case 5: + { + if(!m_bROCTLTypeAndReplace) + { + pNames[nRealCount] = pOrgNames[nProp]; + pValues[nRealCount] <<= m_bCTLTypeAndReplace; + ++nRealCount; + } + } + break; + } + } + aNames.realloc(nRealCount); + aValues.realloc(nRealCount); + PutProperties( aNames, aValues ); + //broadcast changes + NotifyListeners(ConfigurationHints::CtlSettingsChanged); +} + +void SvtCTLOptions_Impl::Load() +{ + Sequence< OUString >& rPropertyNames = PropertyNames(); + if ( !rPropertyNames.hasElements() ) + { + rPropertyNames = { + "CTLFont", + "CTLSequenceChecking", + "CTLCursorMovement", + "CTLTextNumerals", + "CTLSequenceCheckingRestricted", + "CTLSequenceCheckingTypeAndReplace" }; + 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() ) + { + bool bValue = false; + sal_Int32 nValue = 0; + + for ( int nProp = 0; nProp < rPropertyNames.getLength(); nProp++ ) + { + if ( pValues[nProp].hasValue() ) + { + if ( pValues[nProp] >>= bValue ) + { + switch ( nProp ) + { + case 0: { m_bCTLFontEnabled = bValue; m_bROCTLFontEnabled = pROStates[nProp]; } break; + case 1: { m_bCTLSequenceChecking = bValue; m_bROCTLSequenceChecking = pROStates[nProp]; } break; + case 4: { m_bCTLRestricted = bValue; m_bROCTLRestricted = pROStates[nProp]; } break; + case 5: { m_bCTLTypeAndReplace = bValue; m_bROCTLTypeAndReplace = pROStates[nProp]; } break; + } + } + else if ( pValues[nProp] >>= nValue ) + { + switch ( nProp ) + { + case 2: { m_eCTLCursorMovement = static_cast(nValue); m_bROCTLCursorMovement = pROStates[nProp]; } break; + case 3: { m_eCTLTextNumerals = static_cast(nValue); m_bROCTLTextNumerals = pROStates[nProp]; } break; + } + } + } + } + } + + m_bIsLoaded = true; +} +void SvtCTLOptions_Impl::SetCTLFontEnabled( bool _bEnabled ) +{ + if(!m_bROCTLFontEnabled && m_bCTLFontEnabled != _bEnabled) + { + m_bCTLFontEnabled = _bEnabled; + SetModified(); + NotifyListeners(ConfigurationHints::NONE); + } +} +void SvtCTLOptions_Impl::SetCTLSequenceChecking( bool _bEnabled ) +{ + if(!m_bROCTLSequenceChecking && m_bCTLSequenceChecking != _bEnabled) + { + SetModified(); + m_bCTLSequenceChecking = _bEnabled; + NotifyListeners(ConfigurationHints::NONE); + } +} +void SvtCTLOptions_Impl::SetCTLSequenceCheckingRestricted( bool _bEnabled ) +{ + if(!m_bROCTLRestricted && m_bCTLRestricted != _bEnabled) + { + SetModified(); + m_bCTLRestricted = _bEnabled; + NotifyListeners(ConfigurationHints::NONE); + } +} +void SvtCTLOptions_Impl::SetCTLSequenceCheckingTypeAndReplace( bool _bEnabled ) +{ + if(!m_bROCTLTypeAndReplace && m_bCTLTypeAndReplace != _bEnabled) + { + SetModified(); + m_bCTLTypeAndReplace = _bEnabled; + NotifyListeners(ConfigurationHints::NONE); + } +} +void SvtCTLOptions_Impl::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ) +{ + if (!m_bROCTLCursorMovement && m_eCTLCursorMovement != _eMovement ) + { + SetModified(); + m_eCTLCursorMovement = _eMovement; + NotifyListeners(ConfigurationHints::NONE); + } +} +void SvtCTLOptions_Impl::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ) +{ + if (!m_bROCTLTextNumerals && m_eCTLTextNumerals != _eNumerals ) + { + SetModified(); + m_eCTLTextNumerals = _eNumerals; + NotifyListeners(ConfigurationHints::NONE); + } +} + +namespace { + + // global + std::weak_ptr g_pCTLOptions; + + osl::Mutex& CTLMutex() + { + static osl::Mutex aMutex; + return aMutex; + } +} + +SvtCTLOptions::SvtCTLOptions( bool bDontLoad ) +{ + // Global access, must be guarded (multithreading) + ::osl::MutexGuard aGuard( CTLMutex() ); + + m_pImpl = g_pCTLOptions.lock(); + if ( !m_pImpl ) + { + m_pImpl = std::make_shared(); + g_pCTLOptions = m_pImpl; + ItemHolder2::holdConfigItem(EItem::CTLOptions); + } + + if( !bDontLoad && !m_pImpl->IsLoaded() ) + m_pImpl->Load(); + + m_pImpl->AddListener(this); +} + + +SvtCTLOptions::~SvtCTLOptions() +{ + // Global access, must be guarded (multithreading) + ::osl::MutexGuard aGuard( CTLMutex() ); + + m_pImpl->RemoveListener(this); + m_pImpl.reset(); +} + +void SvtCTLOptions::SetCTLFontEnabled( bool _bEnabled ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLFontEnabled( _bEnabled ); +} + +bool SvtCTLOptions::IsCTLFontEnabled() +{ + return officecfg::Office::Common::I18N::CTL::CTLFont::get(); +} + +void SvtCTLOptions::SetCTLSequenceChecking( bool _bEnabled ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLSequenceChecking(_bEnabled); +} + +bool SvtCTLOptions::IsCTLSequenceChecking() +{ + return officecfg::Office::Common::I18N::CTL::CTLSequenceChecking::get(); +} + +void SvtCTLOptions::SetCTLSequenceCheckingRestricted( bool _bEnable ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLSequenceCheckingRestricted(_bEnable); +} + +bool SvtCTLOptions::IsCTLSequenceCheckingRestricted() +{ + return officecfg::Office::Common::I18N::CTL::CTLSequenceCheckingRestricted::get(); +} + +void SvtCTLOptions::SetCTLSequenceCheckingTypeAndReplace( bool _bEnable ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLSequenceCheckingTypeAndReplace(_bEnable); +} + +bool SvtCTLOptions::IsCTLSequenceCheckingTypeAndReplace() +{ + return officecfg::Office::Common::I18N::CTL::CTLSequenceCheckingTypeAndReplace::get(); +} + +void SvtCTLOptions::SetCTLCursorMovement( SvtCTLOptions::CursorMovement _eMovement ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLCursorMovement( _eMovement ); +} + +SvtCTLOptions::CursorMovement SvtCTLOptions::GetCTLCursorMovement() +{ + return static_cast(officecfg::Office::Common::I18N::CTL::CTLCursorMovement::get()); +} + +void SvtCTLOptions::SetCTLTextNumerals( SvtCTLOptions::TextNumerals _eNumerals ) +{ + assert(m_pImpl->IsLoaded()); + m_pImpl->SetCTLTextNumerals( _eNumerals ); +} + +SvtCTLOptions::TextNumerals SvtCTLOptions::GetCTLTextNumerals() +{ + if (utl::ConfigManager::IsFuzzing()) + return SvtCTLOptions::NUMERALS_ARABIC; + return static_cast(officecfg::Office::Common::I18N::CTL::CTLTextNumerals::get()); +} + +bool SvtCTLOptions::IsReadOnly(EOption eOption) const +{ + assert(m_pImpl->IsLoaded()); + return m_pImpl->IsReadOnly(eOption); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/itemholder2.cxx b/svl/source/config/itemholder2.cxx new file mode 100644 index 0000000000..4dc321cdce --- /dev/null +++ b/svl/source/config/itemholder2.cxx @@ -0,0 +1,117 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include "itemholder2.hxx" + +#include +#include +#include +#include +#include +#include +#include +#include + +ItemHolder2::ItemHolder2() +{ + try + { + css::uno::Reference< css::uno::XComponentContext > xContext = ::comphelper::getProcessComponentContext(); + css::uno::Reference< css::lang::XComponent > xCfg( css::configuration::theDefaultProvider::get(xContext), css::uno::UNO_QUERY_THROW ); + xCfg->addEventListener(static_cast< css::lang::XEventListener* >(this)); + } + catch(const css::uno::RuntimeException&) + { + throw; + } +#ifdef DBG_UTIL + catch(const css::uno::Exception&) + { + static bool bMessage = true; + if(bMessage) + { + bMessage = false; + TOOLS_WARN_EXCEPTION( "svl", "" ); + } + } +#else + catch(css::uno::Exception&){} +#endif +} + +ItemHolder2::~ItemHolder2() +{ + impl_releaseAllItems(); +} + +void ItemHolder2::holdConfigItem(EItem eItem) +{ + static rtl::Reference pHolder = new ItemHolder2(); + pHolder->impl_addItem(eItem); +} + +void SAL_CALL ItemHolder2::disposing(const css::lang::EventObject&) +{ + impl_releaseAllItems(); +} + +void ItemHolder2::impl_addItem(EItem eItem) +{ + std::scoped_lock aLock(m_aLock); + + for ( auto const & rInfo : m_lItems ) + { + if (rInfo.eItem == eItem) + return; + } + + TItemInfo aNewItem; + aNewItem.eItem = eItem; + impl_newItem(aNewItem); + if (aNewItem.pItem) + m_lItems.emplace_back(std::move(aNewItem)); +} + +void ItemHolder2::impl_releaseAllItems() +{ + std::vector< TItemInfo > items; + { + std::scoped_lock aLock(m_aLock); + items.swap(m_lItems); + } + + // items will be freed when the block exits +} + +void ItemHolder2::impl_newItem(TItemInfo& rItem) +{ + switch(rItem.eItem) + { + case EItem::CTLOptions : + rItem.pItem.reset( new SvtCTLOptions() ); + break; + + default: + OSL_ASSERT(false); + break; + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/itemholder2.hxx b/svl/source/config/itemholder2.hxx new file mode 100644 index 0000000000..cdb72581e7 --- /dev/null +++ b/svl/source/config/itemholder2.hxx @@ -0,0 +1,58 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ +#define INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ + +#include +#include +#include +#include + +class ItemHolder2 : public ::cppu::WeakImplHelper< css::lang::XEventListener > +{ + // member +private: + + std::mutex m_aLock; + std::vector m_lItems; + + // c++ interface + public: + + ItemHolder2(); + virtual ~ItemHolder2() override; + static void holdConfigItem(EItem eItem); + + // uno interface + public: + + virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override; + + // helper + private: + + void impl_addItem(EItem eItem); + void impl_releaseAllItems(); + static void impl_newItem(TItemInfo& rItem); +}; + +#endif // INCLUDED_SVTOOLS_ITEMHOLDER2_HXX_ + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/config/languageoptions.cxx b/svl/source/config/languageoptions.cxx new file mode 100644 index 0000000000..6391175c85 --- /dev/null +++ b/svl/source/config/languageoptions.cxx @@ -0,0 +1,137 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + + +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#if !defined WIN32_LEAN_AND_MEAN +# define WIN32_LEAN_AND_MEAN +#endif +#include +#endif + +using namespace ::com::sun::star; + + +namespace SvtLanguageOptions +{ + +// returns for a language the scripttype +SvtScriptType GetScriptTypeOfLanguage( LanguageType nLang ) +{ + if( LANGUAGE_DONTKNOW == nLang ) + nLang = LANGUAGE_ENGLISH_US; + else if (LANGUAGE_SYSTEM == nLang || LANGUAGE_PROCESS_OR_USER_DEFAULT == nLang) + nLang = SvtSysLocale().GetLanguageTag().getLanguageType(); + + sal_Int16 nScriptType = MsLangId::getScriptType( nLang ); + SvtScriptType nScript; + switch (nScriptType) + { + case css::i18n::ScriptType::ASIAN: + nScript = SvtScriptType::ASIAN; + break; + case css::i18n::ScriptType::COMPLEX: + nScript = SvtScriptType::COMPLEX; + break; + default: + nScript = SvtScriptType::LATIN; + } + return nScript; +} + +SvtScriptType FromI18NToSvtScriptType( sal_Int16 nI18NType ) +{ + switch ( nI18NType ) + { + case i18n::ScriptType::LATIN: return SvtScriptType::LATIN; + case i18n::ScriptType::ASIAN: return SvtScriptType::ASIAN; + case i18n::ScriptType::COMPLEX: return SvtScriptType::COMPLEX; + case i18n::ScriptType::WEAK: return SvtScriptType::NONE; // no mapping + default: assert(false && nI18NType && "Unknown i18n::ScriptType"); break; + } + return SvtScriptType::NONE; +} + +sal_Int16 FromSvtScriptTypeToI18N( SvtScriptType nItemType ) +{ + switch ( nItemType ) + { + case SvtScriptType::NONE: return 0; + case SvtScriptType::LATIN: return i18n::ScriptType::LATIN; + case SvtScriptType::ASIAN: return i18n::ScriptType::ASIAN; + case SvtScriptType::COMPLEX: return i18n::ScriptType::COMPLEX; + case SvtScriptType::UNKNOWN: return 0; // no mapping + default: assert(false && static_cast(nItemType) && "unknown SvtScriptType"); break; + } + return 0; +} + +sal_Int16 GetI18NScriptTypeOfLanguage( LanguageType nLang ) +{ + return FromSvtScriptTypeToI18N( GetScriptTypeOfLanguage( nLang ) ); +} + +} // namespace SvtLanguageOptions + +static bool isKeyboardLayoutTypeInstalled(sal_Int16 scriptType) +{ + bool isInstalled = false; +#ifdef _WIN32 + int nLayouts = GetKeyboardLayoutList(0, nullptr); + if (nLayouts > 0) + { + HKL *lpList = static_cast(LocalAlloc(LPTR, (nLayouts * sizeof(HKL)))); + if (lpList) + { + nLayouts = GetKeyboardLayoutList(nLayouts, lpList); + + for(int i = 0; i < nLayouts; ++i) + { + LCID lang = MAKELCID(LOWORD(lpList[i]), SORT_DEFAULT); + if (MsLangId::getScriptType(LanguageType(lang)) == scriptType) + { + isInstalled = true; + break; + } + } + + LocalFree(lpList); + } + } +#else + (void)scriptType; +#endif + return isInstalled; +} + +namespace SvtSystemLanguageOptions +{ + bool isCJKKeyboardLayoutInstalled() + { + return isKeyboardLayoutTypeInstalled(css::i18n::ScriptType::ASIAN); + } +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3