diff options
Diffstat (limited to 'framework/source/accelerators')
8 files changed, 143 insertions, 159 deletions
diff --git a/framework/source/accelerators/acceleratorcache.cxx b/framework/source/accelerators/acceleratorcache.cxx index 98596a895036..c0b819a2a9e8 100644 --- a/framework/source/accelerators/acceleratorcache.cxx +++ b/framework/source/accelerators/acceleratorcache.cxx @@ -27,19 +27,16 @@ namespace framework { bool AcceleratorCache::hasKey(const css::awt::KeyEvent& aKey) const { - SolarMutexGuard g; return (m_lKey2Commands.find(aKey) != m_lKey2Commands.end()); } bool AcceleratorCache::hasCommand(const OUString& sCommand) const { - SolarMutexGuard g; return (m_lCommand2Keys.find(sCommand) != m_lCommand2Keys.end()); } AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const { - SolarMutexGuard g; TKeyList lKeys; lKeys.reserve(m_lKey2Commands.size()); @@ -53,8 +50,6 @@ AcceleratorCache::TKeyList AcceleratorCache::getAllKeys() const void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey, const OUString& sCommand) { - SolarMutexGuard g; - // register command for the specified key m_lKey2Commands[aKey] = sCommand; @@ -65,7 +60,6 @@ void AcceleratorCache::setKeyCommandPair(const css::awt::KeyEvent& aKey, const O AcceleratorCache::TKeyList AcceleratorCache::getKeysByCommand(const OUString& sCommand) const { - SolarMutexGuard g; TCommand2Keys::const_iterator pCommand = m_lCommand2Keys.find(sCommand); if (pCommand == m_lCommand2Keys.end()) throw css::container::NoSuchElementException(); @@ -74,7 +68,6 @@ AcceleratorCache::TKeyList AcceleratorCache::getKeysByCommand(const OUString& sC OUString AcceleratorCache::getCommandByKey(const css::awt::KeyEvent& aKey) const { - SolarMutexGuard g; TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey); if (pKey == m_lKey2Commands.end()) throw css::container::NoSuchElementException(); @@ -83,8 +76,6 @@ OUString AcceleratorCache::getCommandByKey(const css::awt::KeyEvent& aKey) const void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey) { - SolarMutexGuard g; - // check if key exists TKey2Commands::const_iterator pKey = m_lKey2Commands.find(aKey); if (pKey == m_lKey2Commands.end()) @@ -99,20 +90,32 @@ void AcceleratorCache::removeKey(const css::awt::KeyEvent& aKey) // remove key from primary list m_lKey2Commands.erase(aKey); - // remove key from optimized command list - m_lCommand2Keys.erase(sCommand); + // get keylist for that command + TCommand2Keys::iterator pCommand = m_lCommand2Keys.find(sCommand); + if (pCommand == m_lCommand2Keys.end()) + return; + TKeyList& lKeys = pCommand->second; + + // one or more keys assign + if (lKeys.size() == 1) + // remove key from optimized command list + m_lCommand2Keys.erase(sCommand); + else // only remove this key from the keylist + { + auto pKeys = ::std::find(lKeys.begin(), lKeys.end(), aKey); + + if (pKeys != lKeys.end()) + lKeys.erase(pKeys); + } } void AcceleratorCache::removeCommand(const OUString& sCommand) { - SolarMutexGuard g; - const TKeyList& lKeys = getKeysByCommand(sCommand); for (auto const& lKey : lKeys) { removeKey(lKey); } - m_lCommand2Keys.erase(sCommand); } } // namespace framework diff --git a/framework/source/accelerators/acceleratorconfiguration.cxx b/framework/source/accelerators/acceleratorconfiguration.cxx index 85edc3833025..4f34dfc0141b 100644 --- a/framework/source/accelerators/acceleratorconfiguration.cxx +++ b/framework/source/accelerators/acceleratorconfiguration.cxx @@ -51,19 +51,23 @@ #include <svtools/acceleratorexecute.hxx> #include <sal/log.hxx> #include <rtl/ustrbuf.hxx> +#include <o3tl/string_view.hxx> -#define PRESET_DEFAULT u"default" -#define TARGET_CURRENT "current" +constexpr OUString PRESET_DEFAULT = u"default"_ustr; +constexpr OUString TARGET_CURRENT = u"current"_ustr; namespace framework { - constexpr OUStringLiteral CFG_ENTRY_SECONDARY = u"SecondaryKeys"; - constexpr OUStringLiteral CFG_PROP_COMMAND = u"Command"; + constexpr OUString CFG_ENTRY_SECONDARY = u"SecondaryKeys"_ustr; + constexpr OUString CFG_PROP_COMMAND = u"Command"_ustr; static OUString lcl_getKeyString(const css::awt::KeyEvent& aKeyEvent) { const sal_Int32 nBeginIndex = 4; // "KEY_" is the prefix of an identifier... - OUStringBuffer sKeyBuffer((KeyMapping::get().mapCodeToIdentifier(aKeyEvent.KeyCode)).copy(nBeginIndex)); + OUString sKey(KeyMapping::get().mapCodeToIdentifier(aKeyEvent.KeyCode)); + if (sKey.getLength() < nBeginIndex) // dead key + return OUString(); + OUStringBuffer sKeyBuffer(sKey.subView(nBeginIndex)); if ( (aKeyEvent.Modifiers & css::awt::KeyModifier::SHIFT) == css::awt::KeyModifier::SHIFT ) sKeyBuffer.append("_SHIFT"); @@ -171,6 +175,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XMLBasedAcceleratorConfiguration::g css::uno::Sequence< css::uno::Any > lPreferredOnes (c); // don't pack list! AcceleratorCache& rCache = impl_getCFG(); + auto lPreferredOnesRange = asNonConstRange(lPreferredOnes); for (i=0; i<c; ++i) { const OUString& rCommand = lCommandList[i]; @@ -187,7 +192,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XMLBasedAcceleratorConfiguration::g if ( lKeys.empty() ) continue; - css::uno::Any& rAny = lPreferredOnes[i]; + css::uno::Any& rAny = lPreferredOnesRange[i]; rAny <<= *(lKeys.begin()); } @@ -217,7 +222,7 @@ void SAL_CALL XMLBasedAcceleratorConfiguration::reload() css::uno::Reference< css::io::XStream > xStreamNoLang; { SolarMutexGuard g; - xStream = m_aPresetHandler.openTarget(u"" TARGET_CURRENT, + xStream = m_aPresetHandler.openTarget(TARGET_CURRENT, css::embed::ElementModes::READ); try { @@ -257,7 +262,7 @@ void SAL_CALL XMLBasedAcceleratorConfiguration::store() css::uno::Reference< css::io::XStream > xStream; { SolarMutexGuard g; - xStream = m_aPresetHandler.openTarget(u"" TARGET_CURRENT, + xStream = m_aPresetHandler.openTarget(TARGET_CURRENT, css::embed::ElementModes::READWRITE); // open or create! } @@ -308,7 +313,7 @@ sal_Bool SAL_CALL XMLBasedAcceleratorConfiguration::isReadOnly() css::uno::Reference< css::io::XStream > xStream; { SolarMutexGuard g; - xStream = m_aPresetHandler.openTarget(u"" TARGET_CURRENT, + xStream = m_aPresetHandler.openTarget(TARGET_CURRENT, css::embed::ElementModes::READWRITE); // open or create! } @@ -343,7 +348,7 @@ void SAL_CALL XMLBasedAcceleratorConfiguration::reset() { { SolarMutexGuard g; - m_aPresetHandler.copyPresetToTarget(PRESET_DEFAULT, u"" TARGET_CURRENT); + m_aPresetHandler.copyPresetToTarget(PRESET_DEFAULT, TARGET_CURRENT); } reload(); @@ -384,14 +389,12 @@ void XMLBasedAcceleratorConfiguration::impl_ts_load(const css::uno::Reference< c // Note: Use special filter object between parser and reader // to get filtered xml with right namespaces ... // Use further a temp cache for reading! - AcceleratorConfigurationReader* pReader = new AcceleratorConfigurationReader(m_aReadCache); - css::uno::Reference< css::xml::sax::XDocumentHandler > xReader (static_cast< ::cppu::OWeakObject* >(pReader), css::uno::UNO_QUERY_THROW); - SaxNamespaceFilter* pFilter = new SaxNamespaceFilter(xReader); - css::uno::Reference< css::xml::sax::XDocumentHandler > xFilter (static_cast< ::cppu::OWeakObject* >(pFilter), css::uno::UNO_QUERY_THROW); + rtl::Reference<AcceleratorConfigurationReader> pReader = new AcceleratorConfigurationReader(m_aReadCache); + rtl::Reference<SaxNamespaceFilter> pFilter = new SaxNamespaceFilter(pReader); // connect parser, filter and stream css::uno::Reference< css::xml::sax::XParser > xParser = css::xml::sax::Parser::create(xContext); - xParser->setDocumentHandler(xFilter); + xParser->setDocumentHandler(pFilter); css::xml::sax::InputSource aSource; aSource.aInputStream = xStream; @@ -461,7 +464,8 @@ AcceleratorCache& XMLBasedAcceleratorConfiguration::impl_getCFG(bool bWriteAcces return m_aReadCache; } -OUString XMLBasedAcceleratorConfiguration::impl_ts_getLocale() const +// static +OUString XMLBasedAcceleratorConfiguration::impl_ts_getLocale() { OUString sISOLocale = officecfg::Setup::L10N::ooLocale::get(); @@ -476,8 +480,8 @@ OUString XMLBasedAcceleratorConfiguration::impl_ts_getLocale() const * *******************************************************************************/ -XCUBasedAcceleratorConfiguration::XCUBasedAcceleratorConfiguration(const css::uno::Reference< css::uno::XComponentContext >& xContext) - : m_xContext (xContext ) +XCUBasedAcceleratorConfiguration::XCUBasedAcceleratorConfiguration(css::uno::Reference< css::uno::XComponentContext > xContext) + : m_xContext (std::move(xContext )) { m_xCfg.set( ::comphelper::ConfigurationHelper::openConfig( m_xContext, "org.openoffice.Office.Accelerators", ::comphelper::EConfigurationModes::AllLocales ), @@ -614,10 +618,9 @@ void SAL_CALL XCUBasedAcceleratorConfiguration::removeKeyEvent(const css::awt::K if (rPrimaryCache.hasKey(aKeyEvent)) { - OUString sDelCommand = rPrimaryCache.getCommandByKey(aKeyEvent); - if (!sDelCommand.isEmpty()) + OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); + if (!sOriginalCommand.isEmpty()) { - OUString sOriginalCommand = rPrimaryCache.getCommandByKey(aKeyEvent); if (rSecondaryCache.hasCommand(sOriginalCommand)) { AcceleratorCache::TKeyList lSecondaryKeys = rSecondaryCache.getKeysByCommand(sOriginalCommand); @@ -679,6 +682,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XCUBasedAcceleratorConfiguration::g css::uno::Sequence< css::uno::Any > lPreferredOnes (c); // don't pack list! AcceleratorCache& rCache = impl_getCFG(true); + auto lPreferredOnesRange = asNonConstRange(lPreferredOnes); for (i=0; i<c; ++i) { const OUString& rCommand = lCommandList[i]; @@ -698,7 +702,7 @@ css::uno::Sequence< css::uno::Any > SAL_CALL XCUBasedAcceleratorConfiguration::g AcceleratorCache::TKeyList::const_iterator pPreferredKey = lcl_getPreferredKey(lKeys); if (pPreferredKey != lKeys.end ()) { - css::uno::Any& rAny = lPreferredOnes[i]; + css::uno::Any& rAny = lPreferredOnesRange[i]; rAny <<= *pPreferredKey; } } @@ -959,7 +963,7 @@ void XCUBasedAcceleratorConfiguration::impl_ts_load( bool bPreferred, const css: } const OUString sIsoLang = impl_ts_getLocale(); - const OUString sDefaultLocale("en-US"); + static constexpr OUStringLiteral sDefaultLocale(u"en-US"); css::uno::Reference< css::container::XNameAccess > xKey; css::uno::Reference< css::container::XNameAccess > xCommand; @@ -973,12 +977,8 @@ void XCUBasedAcceleratorConfiguration::impl_ts_load( bool bPreferred, const css: xAccess->getByName(sKey) >>= xKey; xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; - css::uno::Sequence< OUString > lLocales = xCommand->getElementNames(); - sal_Int32 nLocales = lLocales.getLength(); - ::std::vector< OUString > aLocales; - aLocales.reserve(nLocales); - for (sal_Int32 j = 0; j < nLocales; ++j) - aLocales.push_back(lLocales[j]); + const css::uno::Sequence< OUString > lLocales = xCommand->getElementNames(); + ::std::vector< OUString > aLocales { lLocales.begin(), lLocales.end() }; OUString sLocale; for (auto const& locale : aLocales) @@ -1013,32 +1013,31 @@ void XCUBasedAcceleratorConfiguration::impl_ts_load( bool bPreferred, const css: css::awt::KeyEvent aKeyEvent; sal_Int32 nIndex = 0; - OUString sKeyCommand = sKey.getToken(0, '_', nIndex); - aKeyEvent.KeyCode = KeyMapping::get().mapIdentifierToCode("KEY_" + sKeyCommand); + std::u16string_view sKeyCommand = o3tl::getToken(sKey, 0, '_', nIndex); + aKeyEvent.KeyCode = KeyMapping::get().mapIdentifierToCode(OUString::Concat("KEY_") + sKeyCommand); - css::uno::Sequence< OUString > sToken(4); const sal_Int32 nToken = 4; bool bValid = true; sal_Int32 k; - for (k=0; k<nToken; ++k) + for (k = 0; k < nToken; ++k) { if (nIndex < 0) break; - sToken[k] = sKey.getToken(0, '_', nIndex); - if (sToken[k].isEmpty()) + std::u16string_view sToken = o3tl::getToken(sKey, 0, '_', nIndex); + if (sToken.empty()) { bValid = false; break; } - if ( sToken[k] == "SHIFT" ) + if ( sToken == u"SHIFT" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; - else if ( sToken[k] == "MOD1" ) + else if ( sToken == u"MOD1" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; - else if ( sToken[k] == "MOD2" ) + else if ( sToken == u"MOD2" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; - else if ( sToken[k] == "MOD3" ) + else if ( sToken == u"MOD3" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; else { @@ -1157,7 +1156,7 @@ void XCUBasedAcceleratorConfiguration::insertKeyToConfiguration( const css::awt: { xFac.set(xModules, css::uno::UNO_QUERY); xInst = xFac->createInstance(); - xModules->insertByName(m_sModuleCFG, css::uno::makeAny(xInst)); + xModules->insertByName(m_sModuleCFG, css::uno::Any(xInst)); } xModules->getByName(m_sModuleCFG) >>= xContainer; } @@ -1169,16 +1168,16 @@ void XCUBasedAcceleratorConfiguration::insertKeyToConfiguration( const css::awt: { xFac.set(xContainer, css::uno::UNO_QUERY); xInst = xFac->createInstance(); - xContainer->insertByName(sKey, css::uno::makeAny(xInst)); + xContainer->insertByName(sKey, css::uno::Any(xInst)); } xContainer->getByName(sKey) >>= xKey; xKey->getByName(CFG_PROP_COMMAND) >>= xCommand; OUString sLocale = impl_ts_getLocale(); if ( !xCommand->hasByName(sLocale) ) - xCommand->insertByName(sLocale, css::uno::makeAny(sCommand)); + xCommand->insertByName(sLocale, css::uno::Any(sCommand)); else - xCommand->replaceByName(sLocale, css::uno::makeAny(sCommand)); + xCommand->replaceByName(sLocale, css::uno::Any(sCommand)); } void XCUBasedAcceleratorConfiguration::removeKeyFromConfiguration( const css::awt::KeyEvent& aKeyEvent, const bool bPreferred ) @@ -1224,27 +1223,25 @@ void XCUBasedAcceleratorConfiguration::reloadChanged( const OUString& sPrimarySe } css::awt::KeyEvent aKeyEvent; - OUString sKeyIdentifier; sal_Int32 nIndex = 0; - sKeyIdentifier = sKey.getToken(0, '_', nIndex); - aKeyEvent.KeyCode = KeyMapping::get().mapIdentifierToCode("KEY_"+sKeyIdentifier); + std::u16string_view sKeyIdentifier = o3tl::getToken(sKey, 0, '_', nIndex); + aKeyEvent.KeyCode = KeyMapping::get().mapIdentifierToCode(OUString::Concat("KEY_") + sKeyIdentifier); - css::uno::Sequence< OUString > sToken(3); - const sal_Int32 nToken = 3; - for (sal_Int32 i=0; i<nToken; ++i) + const int nToken = 4; + for (sal_Int32 i = 0; i < nToken; ++i) { if ( nIndex < 0 ) break; - sToken[i] = sKey.getToken(0, '_', nIndex); - if ( sToken[i] == "SHIFT" ) + std::u16string_view sToken = o3tl::getToken(sKey, 0, '_', nIndex); + if ( sToken == u"SHIFT" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::SHIFT; - else if ( sToken[i] == "MOD1" ) + else if ( sToken == u"MOD1" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD1; - else if ( sToken[i] == "MOD2" ) + else if ( sToken == u"MOD2" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD2; - else if ( sToken[i] == "MOD3" ) + else if ( sToken == u"MOD3" ) aKeyEvent.Modifiers |= css::awt::KeyModifier::MOD3; } @@ -1315,7 +1312,8 @@ AcceleratorCache& XCUBasedAcceleratorConfiguration::impl_getCFG(bool bPreferred, } } -OUString XCUBasedAcceleratorConfiguration::impl_ts_getLocale() const +// static +OUString XCUBasedAcceleratorConfiguration::impl_ts_getLocale() { OUString sISOLocale = officecfg::Setup::L10N::ooLocale::get(); diff --git a/framework/source/accelerators/documentacceleratorconfiguration.cxx b/framework/source/accelerators/documentacceleratorconfiguration.cxx index 33f4e877a534..c86895f0de32 100644 --- a/framework/source/accelerators/documentacceleratorconfiguration.cxx +++ b/framework/source/accelerators/documentacceleratorconfiguration.cxx @@ -30,7 +30,7 @@ using namespace framework; -#define RESOURCETYPE_ACCELERATOR "accelerator" +constexpr OUStringLiteral RESOURCETYPE_ACCELERATOR = u"accelerator"; namespace { @@ -167,7 +167,7 @@ void DocumentAcceleratorConfiguration::fillCache() m_aPresetHandler.connectToResource( PresetHandler::E_DOCUMENT, RESOURCETYPE_ACCELERATOR, - OUString(), + u"", xDocumentRoot, aLanguageTag); @@ -185,8 +185,8 @@ com_sun_star_comp_framework_DocumentAcceleratorConfiguration_get_implementation( css::uno::XComponentContext *context, css::uno::Sequence<css::uno::Any> const &arguments) { - DocumentAcceleratorConfiguration *inst = new DocumentAcceleratorConfiguration(context, arguments); - css::uno::XInterface *acquired_inst = cppu::acquire(inst); + rtl::Reference<DocumentAcceleratorConfiguration> inst = new DocumentAcceleratorConfiguration(context, arguments); + css::uno::XInterface *acquired_inst = cppu::acquire(inst.get()); inst->fillCache(); diff --git a/framework/source/accelerators/globalacceleratorconfiguration.cxx b/framework/source/accelerators/globalacceleratorconfiguration.cxx index 359fbcd5be42..e54a05a03be3 100644 --- a/framework/source/accelerators/globalacceleratorconfiguration.cxx +++ b/framework/source/accelerators/globalacceleratorconfiguration.cxx @@ -109,22 +109,6 @@ void GlobalAcceleratorConfiguration::fillCache() {} } -struct Instance -{ - explicit Instance(css::uno::Reference<css::uno::XComponentContext> const & context) - : instance(new GlobalAcceleratorConfiguration(context)) - { - instance->fillCache(); - } - - rtl::Reference<GlobalAcceleratorConfiguration> instance; -}; - -struct Singleton: - public rtl::StaticWithArg< - Instance, css::uno::Reference<css::uno::XComponentContext>, Singleton> -{}; - } extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * @@ -132,7 +116,9 @@ com_sun_star_comp_framework_GlobalAcceleratorConfiguration_get_implementation( css::uno::XComponentContext *context, css::uno::Sequence<css::uno::Any> const &) { - return cppu::acquire(static_cast<cppu::OWeakObject*>(Singleton::get(context).instance.get())); + rtl::Reference<GlobalAcceleratorConfiguration> xGAC = new GlobalAcceleratorConfiguration(context); + xGAC->fillCache(); + return cppu::acquire(xGAC.get()); } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/framework/source/accelerators/keymapping.cxx b/framework/source/accelerators/keymapping.cxx index 5f78d6dd65b0..be0c4c27f291 100644 --- a/framework/source/accelerators/keymapping.cxx +++ b/framework/source/accelerators/keymapping.cxx @@ -21,7 +21,7 @@ #include <com/sun/star/awt/Key.hpp> #include <com/sun/star/lang/IllegalArgumentException.hpp> -#include <rtl/instance.hxx> +#include <o3tl/string_view.hxx> namespace framework { @@ -136,6 +136,9 @@ KeyMapping::KeyIdentifierInfo const KeyMapping::KeyIdentifierMap[] = {css::awt::Key::BRACKETRIGHT , "KEY_BRACKETRIGHT" }, {css::awt::Key::SEMICOLON , "KEY_SEMICOLON" }, {css::awt::Key::QUOTERIGHT , "KEY_QUOTERIGHT" }, + {css::awt::Key::RIGHTCURLYBRACKET, "KEY_RIGHTCURLYBRACKET" }, + {css::awt::Key::NUMBERSIGN, "KEY_NUMBERSIGN" }, + {css::awt::Key::COLON , "KEY_COLON" }, {0 , "" } // mark the end of this array! }; @@ -154,14 +157,9 @@ KeyMapping::KeyMapping() } } -namespace { - -struct Instance: public rtl::Static<KeyMapping, Instance> {}; - -} - KeyMapping & KeyMapping::get() { - return Instance::get(); + static KeyMapping KEYS; + return KEYS; } sal_uInt16 KeyMapping::mapIdentifierToCode(const OUString& sIdentifier) @@ -192,10 +190,10 @@ OUString KeyMapping::mapCodeToIdentifier(sal_uInt16 nCode) return OUString::number(nCode); } -bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const OUString& sIdentifier, +bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(std::u16string_view sIdentifier, sal_uInt16& rCode ) { - sal_Int32 nCode = sIdentifier.toInt32(); + sal_Int32 nCode = o3tl::toInt32(sIdentifier); if (nCode > 0) { rCode = static_cast<sal_uInt16>(nCode); @@ -205,7 +203,7 @@ bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const OUString& sIdent // 0 is normally an error of the called method toInt32() ... // But we must be aware, that the identifier is "0"! rCode = 0; - return sIdentifier == "0"; + return sIdentifier == u"0"; } } // namespace framework diff --git a/framework/source/accelerators/moduleacceleratorconfiguration.cxx b/framework/source/accelerators/moduleacceleratorconfiguration.cxx index 71f33bc5b0ab..c8ce39fec495 100644 --- a/framework/source/accelerators/moduleacceleratorconfiguration.cxx +++ b/framework/source/accelerators/moduleacceleratorconfiguration.cxx @@ -146,8 +146,8 @@ com_sun_star_comp_framework_ModuleAcceleratorConfiguration_get_implementation( css::uno::XComponentContext *context, css::uno::Sequence<css::uno::Any> const &arguments) { - ModuleAcceleratorConfiguration *inst = new ModuleAcceleratorConfiguration(context, arguments); - css::uno::XInterface *acquired_inst = cppu::acquire(inst); + rtl::Reference<ModuleAcceleratorConfiguration> inst = new ModuleAcceleratorConfiguration(context, arguments); + css::uno::XInterface *acquired_inst = cppu::acquire(inst.get()); inst->fillCache(); diff --git a/framework/source/accelerators/presethandler.cxx b/framework/source/accelerators/presethandler.cxx index bce2e3861499..f1879af97f70 100644 --- a/framework/source/accelerators/presethandler.cxx +++ b/framework/source/accelerators/presethandler.cxx @@ -30,6 +30,7 @@ #include <com/sun/star/lang/XSingleServiceFactory.hpp> #include <com/sun/star/util/thePathSettings.hpp> +#include <utility> #include <vcl/svapp.hxx> #include <cppuhelper/exc_hlp.hxx> #include <rtl/ustrbuf.hxx> @@ -57,8 +58,6 @@ struct TSharedStorages final StorageHolder m_lStoragesUser; TSharedStorages() - : m_lStoragesShare() - , m_lStoragesUser () {}; }; @@ -66,14 +65,17 @@ struct TSharedStorages final a) shared root storages b) shared "inbetween" storages of the share and user layer. */ -struct SharedStorages: public rtl::Static<TSharedStorages, SharedStorages> {}; +TSharedStorages& SharedStorages() +{ + static TSharedStorages theStorages; + return theStorages; +} } -PresetHandler::PresetHandler(const css::uno::Reference< css::uno::XComponentContext >& xContext) - : m_xContext(xContext) +PresetHandler::PresetHandler(css::uno::Reference< css::uno::XComponentContext > xContext) + : m_xContext(std::move(xContext)) , m_eConfigType(E_GLOBAL) - , m_lDocumentStorages() { } @@ -105,7 +107,7 @@ PresetHandler::~PresetHandler() Otherwise we will disconnect all other open configuration access objects which base on these storages. */ - auto & sharedStorages = SharedStorages::get(); + auto & sharedStorages = SharedStorages(); sharedStorages.m_lStoragesShare.closePath(m_sRelPathShare); sharedStorages.m_lStoragesUser.closePath (m_sRelPathUser ); @@ -171,7 +173,7 @@ void lcl_throwCorruptedUIConfigurationException( css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageShare() { - auto & sharedStorages = SharedStorages::get(); + auto & sharedStorages = SharedStorages(); css::uno::Reference< css::embed::XStorage > xRoot = sharedStorages.m_lStoragesShare.getRootStorage(); if (xRoot.is()) return xRoot; @@ -204,9 +206,10 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorag // based of a system directory. This must be used so, till the storage implementation // can work on directories too. */ - css::uno::Sequence< css::uno::Any > lArgs(2); - lArgs[0] <<= sShareLayer; - lArgs[1] <<= css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE; + css::uno::Sequence< css::uno::Any > lArgs{ + css::uno::Any(sShareLayer), + css::uno::Any(css::embed::ElementModes::READ | css::embed::ElementModes::NOCREATE) + }; css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory = css::embed::FileSystemStorageFactory::create( xContext ); css::uno::Reference< css::embed::XStorage > xStorage; @@ -229,7 +232,7 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorag css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorageUser() { - auto & sharedStorages = SharedStorages::get(); + auto & sharedStorages = SharedStorages(); css::uno::Reference< css::embed::XStorage > xRoot = sharedStorages.m_lStoragesUser.getRootStorage(); if (xRoot.is()) return xRoot; @@ -252,9 +255,8 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::getOrCreateRootStorag sUserLayer += "soffice.cfg"; // storage file - css::uno::Sequence< css::uno::Any > lArgs(2); - lArgs[0] <<= sUserLayer; - lArgs[1] <<= css::embed::ElementModes::READWRITE; + css::uno::Sequence< css::uno::Any > lArgs{ css::uno::Any(sUserLayer), + css::uno::Any(css::embed::ElementModes::READWRITE) }; css::uno::Reference< css::lang::XSingleServiceFactory > xStorageFactory = css::embed::FileSystemStorageFactory::create( xContext ); css::uno::Reference< css::embed::XStorage > xStorage; @@ -289,7 +291,7 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageShare xWorking = m_xWorkingStorageShare; } - return SharedStorages::get().m_lStoragesShare.getParentStorage(xWorking); + return SharedStorages().m_lStoragesShare.getParentStorage(xWorking); } css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageUser() @@ -300,12 +302,12 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::getParentStorageUser( xWorking = m_xWorkingStorageUser; } - return SharedStorages::get().m_lStoragesUser.getParentStorage(xWorking); + return SharedStorages().m_lStoragesUser.getParentStorage(xWorking); } void PresetHandler::connectToResource( PresetHandler::EConfigType eConfigType , - const OUString& sResource , - const OUString& sModule , + std::u16string_view sResource , + std::u16string_view sModule , const css::uno::Reference< css::embed::XStorage >& xDocumentRoot, const LanguageTag& rLanguageTag ) { @@ -355,10 +357,7 @@ void PresetHandler::connectToResource( PresetHandler::EConfigType { case E_GLOBAL : { - sRelPathBuf.append("global"); - sRelPathBuf.append("/"); - sRelPathBuf.append(sResource); - sRelPathShare = sRelPathBuf.makeStringAndClear(); + sRelPathShare = OUString::Concat("global/") + sResource; sRelPathUser = sRelPathShare; xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, true ); @@ -368,12 +367,7 @@ void PresetHandler::connectToResource( PresetHandler::EConfigType case E_MODULES : { - sRelPathBuf.append("modules"); - sRelPathBuf.append("/"); - sRelPathBuf.append(sModule); - sRelPathBuf.append("/"); - sRelPathBuf.append(sResource); - sRelPathShare = sRelPathBuf.makeStringAndClear(); + sRelPathShare = OUString::Concat("modules/") + sModule + "/" + sResource; sRelPathUser = sRelPathShare; xShare = impl_openPathIgnoringErrors(sRelPathShare, eShareMode, true ); @@ -548,7 +542,7 @@ void PresetHandler::commitUserChanges() case E_GLOBAL : case E_MODULES : { - auto & sharedStorages = SharedStorages::get(); + auto & sharedStorages = SharedStorages(); sPath = sharedStorages.m_lStoragesUser.getPathOfStorage(xWorking); sharedStorages.m_lStoragesUser.commitPath(sPath); sharedStorages.m_lStoragesUser.notifyPath(sPath); @@ -583,7 +577,7 @@ void PresetHandler::addStorageListener(XMLBasedAcceleratorConfiguration* pListen case E_GLOBAL : case E_MODULES : { - SharedStorages::get().m_lStoragesUser.addStorageListener(pListener, sRelPath); + SharedStorages().m_lStoragesUser.addStorageListener(pListener, sRelPath); } break; @@ -613,7 +607,7 @@ void PresetHandler::removeStorageListener(XMLBasedAcceleratorConfiguration* pLis case E_GLOBAL : case E_MODULES : { - SharedStorages::get().m_lStoragesUser.removeStorageListener(pListener, sRelPath); + SharedStorages().m_lStoragesUser.removeStorageListener(pListener, sRelPath); } break; @@ -625,6 +619,7 @@ void PresetHandler::removeStorageListener(XMLBasedAcceleratorConfiguration* pLis } } +// static css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoringErrors(const OUString& sPath , sal_Int32 eMode , bool bShare) @@ -633,9 +628,9 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoring try { if (bShare) - xPath = SharedStorages::get().m_lStoragesShare.openPath(sPath, eMode); + xPath = SharedStorages().m_lStoragesShare.openPath(sPath, eMode); else - xPath = SharedStorages::get().m_lStoragesUser.openPath(sPath, eMode); + xPath = SharedStorages().m_lStoragesUser.openPath(sPath, eMode); } catch(const css::uno::RuntimeException&) { throw; } @@ -644,6 +639,7 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoring return xPath; } +// static ::std::vector< OUString >::const_iterator PresetHandler::impl_findMatchingLocalizedValue( const ::std::vector< OUString >& lLocalizedValues, OUString& rLanguageTag, @@ -668,6 +664,7 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openPathIgnoring return pFound; } +// static css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openLocalizedPathIgnoringErrors( OUString& sPath , sal_Int32 eMode , @@ -705,6 +702,7 @@ css::uno::Reference< css::embed::XStorage > PresetHandler::impl_openLocalizedPat return xLocalePath; } +// static ::std::vector< OUString > PresetHandler::impl_getSubFolderNames(const css::uno::Reference< css::embed::XStorage >& xFolder) { if (!xFolder.is()) diff --git a/framework/source/accelerators/storageholder.cxx b/framework/source/accelerators/storageholder.cxx index 4c7702e579ca..6cef699bfb14 100644 --- a/framework/source/accelerators/storageholder.cxx +++ b/framework/source/accelerators/storageholder.cxx @@ -26,10 +26,11 @@ #include <com/sun/star/embed/XTransactedObject.hpp> #include <rtl/ustrbuf.hxx> +#include <o3tl/string_view.hxx> #include <algorithm> -#define PATH_SEPARATOR "/" +constexpr OUString PATH_SEPARATOR = u"/"_ustr; #define PATH_SEPARATOR_UNICODE u'/' namespace framework @@ -47,7 +48,7 @@ StorageHolder::~StorageHolder() void StorageHolder::forgetCachedStorages() { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); for (auto & lStorage : m_lStorages) { TStorageInfo& rInfo = lStorage.second; @@ -59,13 +60,13 @@ void StorageHolder::forgetCachedStorages() void StorageHolder::setRootStorage(const css::uno::Reference< css::embed::XStorage >& xRoot) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); m_xRoot = xRoot; } css::uno::Reference< css::embed::XStorage > StorageHolder::getRootStorage() const { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); return m_xRoot; } @@ -76,9 +77,9 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri std::vector<OUString> lFolders = StorageHolder::impl_st_parsePath(sNormedPath); // SAFE -> ---------------------------------- - osl::ResettableMutexGuard aReadLock(m_mutex); + std::unique_lock aReadLock(m_mutex); css::uno::Reference< css::embed::XStorage > xParent = m_xRoot; - aReadLock.clear(); + aReadLock.unlock(); // <- SAFE ---------------------------------- css::uno::Reference< css::embed::XStorage > xChild; @@ -89,7 +90,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri OUString sCheckPath (sRelPath + lFolder + PATH_SEPARATOR); // SAFE -> ------------------------------ - aReadLock.reset(); + aReadLock.lock(); // If we found an already open storage ... we must increase // its use count. Otherwise it will may be closed too early :-) @@ -101,12 +102,12 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri ++(pInfo->UseCount); xChild = pInfo->Storage; - aReadLock.clear(); + aReadLock.unlock(); // <- SAFE ------------------------------ } else { - aReadLock.clear(); + aReadLock.unlock(); // <- SAFE ------------------------------ try @@ -130,7 +131,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::openPath(const OUStri throw; } - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); pInfo = &(m_lStorages[sCheckPath]); pInfo->Storage = xChild; pInfo->UseCount = 1; @@ -154,7 +155,7 @@ StorageHolder::TStorageList StorageHolder::getAllPathStorages(const OUString& sP StorageHolder::TStorageList lStoragesOfPath; OUString sRelPath; - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); for (auto const& lFolder : lFolders) { @@ -196,7 +197,7 @@ void StorageHolder::commitPath(const OUString& sPath) // SAFE -> ------------------------------ { - osl::MutexGuard aReadLock(m_mutex); + std::unique_lock aReadLock(m_mutex); xCommit.set(m_xRoot, css::uno::UNO_QUERY); } // <- SAFE ------------------------------ @@ -223,7 +224,7 @@ void StorageHolder::closePath(const OUString& rPath) sParentPath = sCurrentRelPath; } - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); std::vector<OUString>::reverse_iterator pIt2; for ( pIt2 = lFolders.rbegin(); @@ -249,7 +250,7 @@ void StorageHolder::notifyPath(const OUString& sPath) { OUString sNormedPath = StorageHolder::impl_st_normPath(sPath); - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath); if (pIt1 == m_lStorages.end()) @@ -268,7 +269,7 @@ void StorageHolder::addStorageListener( XMLBasedAcceleratorConfiguration* p { OUString sNormedPath = StorageHolder::impl_st_normPath(sPath); - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath); if (pIt1 == m_lStorages.end()) @@ -285,7 +286,7 @@ void StorageHolder::removeStorageListener( XMLBasedAcceleratorConfiguration { OUString sNormedPath = StorageHolder::impl_st_normPath(sPath); - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); TPath2StorageInfo::iterator pIt1 = m_lStorages.find(sNormedPath); if (pIt1 == m_lStorages.end()) @@ -299,7 +300,7 @@ void StorageHolder::removeStorageListener( XMLBasedAcceleratorConfiguration OUString StorageHolder::getPathOfStorage(const css::uno::Reference< css::embed::XStorage >& xStorage) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); for (auto const& lStorage : m_lStorages) { @@ -334,7 +335,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons // SAFE -> ---------------------------------- { - osl::MutexGuard aReadLock(m_mutex); + std::unique_lock aReadLock(m_mutex); // b) if (c < 2) @@ -345,7 +346,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons sal_Int32 i = 0; for (i = 0; i < c - 1; ++i) { - sParentPath.append(lFolders[i]).append(PATH_SEPARATOR); + sParentPath.append(lFolders[i] + PATH_SEPARATOR); } auto pParent = m_lStorages.find(sParentPath.makeStringAndClear()); @@ -361,7 +362,7 @@ css::uno::Reference< css::embed::XStorage > StorageHolder::getParentStorage(cons StorageHolder& StorageHolder::operator=(const StorageHolder& rCopy) { - osl::MutexGuard g(m_mutex); + std::unique_lock g(m_mutex); m_xRoot = rCopy.m_xRoot; m_lStorages = rCopy.m_lStorages; return *this; @@ -427,13 +428,13 @@ OUString StorageHolder::impl_st_normPath(const OUString& sPath) return sNormedPath; } -std::vector<OUString> StorageHolder::impl_st_parsePath(const OUString& sPath) +std::vector<OUString> StorageHolder::impl_st_parsePath(std::u16string_view sPath) { std::vector<OUString> lToken; sal_Int32 i = 0; while (true) { - OUString sToken = sPath.getToken(0, PATH_SEPARATOR_UNICODE, i); + OUString sToken( o3tl::getToken(sPath, 0, PATH_SEPARATOR_UNICODE, i) ); if (i < 0) break; lToken.push_back(sToken); |