diff options
Diffstat (limited to 'framework/source/uiconfiguration/windowstateconfiguration.cxx')
-rw-r--r-- | framework/source/uiconfiguration/windowstateconfiguration.cxx | 119 |
1 files changed, 57 insertions, 62 deletions
diff --git a/framework/source/uiconfiguration/windowstateconfiguration.cxx b/framework/source/uiconfiguration/windowstateconfiguration.cxx index 31b08076e953..504ef4c97808 100644 --- a/framework/source/uiconfiguration/windowstateconfiguration.cxx +++ b/framework/source/uiconfiguration/windowstateconfiguration.cxx @@ -36,14 +36,16 @@ #include <com/sun/star/util/XChangesBatch.hpp> #include <com/sun/star/uno/XComponentContext.hpp> -#include <cppuhelper/basemutex.hxx> -#include <cppuhelper/compbase.hxx> +#include <comphelper/compbase.hxx> +#include <comphelper/string.hxx> #include <cppuhelper/implbase.hxx> #include <cppuhelper/supportsservice.hxx> #include <comphelper/propertysequence.hxx> #include <comphelper/sequence.hxx> #include <sal/log.hxx> +#include <o3tl/string_view.hxx> +#include <mutex> #include <string_view> #include <unordered_map> #include <vector> @@ -79,7 +81,7 @@ const sal_Int16 PROPERTY_DOCKPOS = 14; const sal_Int16 PROPERTY_DOCKSIZE = 15; // Order must be the same as WindowStateMask!! -const char* CONFIGURATION_PROPERTIES[] = +constexpr OUString CONFIGURATION_PROPERTIES[] { WINDOWSTATE_PROPERTY_LOCKED, WINDOWSTATE_PROPERTY_DOCKED, @@ -96,8 +98,7 @@ const char* CONFIGURATION_PROPERTIES[] = WINDOWSTATE_PROPERTY_INTERNALSTATE, WINDOWSTATE_PROPERTY_STYLE, WINDOWSTATE_PROPERTY_DOCKPOS, - WINDOWSTATE_PROPERTY_DOCKSIZE, - nullptr + WINDOWSTATE_PROPERTY_DOCKSIZE }; // Configuration access class for WindowState supplier implementation @@ -203,7 +204,7 @@ class ConfigurationAccess_WindowState : public ::cppu::WeakImplHelper< XNameCon typedef std::unordered_map< OUString, WindowStateInfo > ResourceURLToInfoCache; - osl::Mutex m_aMutex; + std::mutex m_aMutex; OUString m_aConfigWindowAccess; Reference< XMultiServiceFactory > m_xConfigProvider; Reference< XNameAccess > m_xConfigAccess; @@ -223,18 +224,14 @@ ConfigurationAccess_WindowState::ConfigurationAccess_WindowState( std::u16string m_bModified( false ) { // Initialize access array with property names. - sal_Int32 n = 0; - while ( CONFIGURATION_PROPERTIES[n] ) - { - m_aPropArray.push_back( OUString::createFromAscii( CONFIGURATION_PROPERTIES[n] )); - ++n; - } + for (const OUString & s : CONFIGURATION_PROPERTIES ) + m_aPropArray.push_back(s); } ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState() { // SAFE - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); Reference< XContainer > xContainer( m_xConfigAccess, UNO_QUERY ); if ( xContainer.is() ) xContainer->removeContainerListener(m_xConfigListener); @@ -244,7 +241,7 @@ ConfigurationAccess_WindowState::~ConfigurationAccess_WindowState() Any SAL_CALL ConfigurationAccess_WindowState::getByName( const OUString& rResourceURL ) { // SAFE - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL ); if ( pIter != m_aResourceURLToInfoCache.end() ) @@ -261,7 +258,7 @@ Any SAL_CALL ConfigurationAccess_WindowState::getByName( const OUString& rResour Sequence< OUString > SAL_CALL ConfigurationAccess_WindowState::getElementNames() { // SAFE - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); if ( !m_bConfigAccessInitialized ) { @@ -278,7 +275,7 @@ Sequence< OUString > SAL_CALL ConfigurationAccess_WindowState::getElementNames() sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasByName( const OUString& rResourceURL ) { // SAFE - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); ResourceURLToInfoCache::const_iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL ); if ( pIter != m_aResourceURLToInfoCache.end() ) @@ -302,7 +299,7 @@ Type SAL_CALL ConfigurationAccess_WindowState::getElementType() sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasElements() { // SAFE - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); if ( !m_bConfigAccessInitialized ) { @@ -320,7 +317,7 @@ sal_Bool SAL_CALL ConfigurationAccess_WindowState::hasElements() void SAL_CALL ConfigurationAccess_WindowState::removeByName( const OUString& rResourceURL ) { // SAFE - osl::ClearableMutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); ResourceURLToInfoCache::iterator pIter = m_aResourceURLToInfoCache.find( rResourceURL ); if ( pIter != m_aResourceURLToInfoCache.end() ) @@ -338,7 +335,7 @@ void SAL_CALL ConfigurationAccess_WindowState::removeByName( const OUString& rRe Reference< XNameContainer > xNameContainer( m_xConfigAccess, UNO_QUERY ); if ( xNameContainer.is() ) { - g.clear(); + g.unlock(); xNameContainer->removeByName( rResourceURL ); Reference< XChangesBatch > xFlush( m_xConfigAccess, UNO_QUERY ); @@ -354,7 +351,7 @@ void SAL_CALL ConfigurationAccess_WindowState::removeByName( const OUString& rRe void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rResourceURL, const css::uno::Any& aPropertySet ) { // SAFE - osl::ClearableMutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); Sequence< PropertyValue > aPropSet; if ( !(aPropertySet >>= aPropSet) ) @@ -387,7 +384,7 @@ void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rRe return; Reference< XSingleServiceFactory > xFactory( m_xConfigAccess, UNO_QUERY ); - g.clear(); + g.unlock(); try { @@ -412,7 +409,7 @@ void SAL_CALL ConfigurationAccess_WindowState::insertByName( const OUString& rRe void SAL_CALL ConfigurationAccess_WindowState::replaceByName( const OUString& rResourceURL, const css::uno::Any& aPropertySet ) { // SAFE - osl::ClearableMutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); Sequence< PropertyValue > aPropSet; if ( !(aPropertySet >>= aPropSet) ) @@ -457,7 +454,7 @@ void SAL_CALL ConfigurationAccess_WindowState::replaceByName( const OUString& rR WindowStateInfo aWinStateInfo( pIter->second ); OUString aResourceURL( pIter->first ); m_bModified = false; - g.clear(); + g.unlock(); try { @@ -496,7 +493,7 @@ void SAL_CALL ConfigurationAccess_WindowState::disposing( const EventObject& aEv { // SAFE // remove our reference to the config access - osl::MutexGuard g(m_aMutex); + std::unique_lock g(m_aMutex); Reference< XInterface > xIfac1( aEvent.Source, UNO_QUERY ); Reference< XInterface > xIfac2( m_xConfigAccess, UNO_QUERY ); @@ -560,7 +557,7 @@ Any ConfigurationAccess_WindowState::impl_getSequenceFromStruct( const WindowSta } } - return makeAny( comphelper::containerToSequence(aPropVec) ); + return Any( comphelper::containerToSequence(aPropVec) ); } Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OUString& rResourceURL, Reference< XNameAccess > const & xNameAccess ) @@ -641,12 +638,12 @@ Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OU if ( a >>= aString ) { sal_Int32 nToken( 0 ); - OUString aXStr = aString.getToken( 0, ',', nToken ); + std::u16string_view aXStr = o3tl::getToken(aString, 0, ',', nToken ); if ( nToken > 0 ) { css::awt::Point aPos; - aPos.X = aXStr.toInt32(); - aPos.Y = aString.getToken( 0, ',', nToken ).toInt32(); + aPos.X = o3tl::toInt32(aXStr); + aPos.Y = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken )); if ( i == PROPERTY_POS ) { @@ -673,12 +670,12 @@ Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OU if ( a >>= aString ) { sal_Int32 nToken( 0 ); - OUString aStr = aString.getToken( 0, ',', nToken ); + std::u16string_view aStr = o3tl::getToken(aString, 0, ',', nToken ); if ( nToken > 0 ) { css::awt::Size aSize; - aSize.Width = aStr.toInt32(); - aSize.Height = aString.getToken( 0, ',', nToken ).toInt32(); + aSize.Width = o3tl::toInt32(aStr); + aSize.Height = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken )); if ( i == PROPERTY_SIZE ) { aWindowStateInfo.aSize = aSize; @@ -756,7 +753,7 @@ Any ConfigurationAccess_WindowState::impl_insertCacheAndReturnSequence( const OU aWindowStateInfo.nMask = nMask; m_aResourceURLToInfoCache.emplace( rResourceURL, aWindowStateInfo ); - return makeAny( comphelper::containerToSequence(aPropVec) ); + return Any( comphelper::containerToSequence(aPropVec) ); } ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowState::impl_insertCacheAndReturnWinState( const OUString& rResourceURL, Reference< XNameAccess > const & rNameAccess ) @@ -834,12 +831,12 @@ ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowStat if ( a >>= aString ) { sal_Int32 nToken( 0 ); - OUString aXStr = aString.getToken( 0, ',', nToken ); + std::u16string_view aXStr = o3tl::getToken(aString, 0, ',', nToken ); if ( nToken > 0 ) { css::awt::Point aPos; - aPos.X = aXStr.toInt32(); - aPos.Y = aString.getToken( 0, ',', nToken ).toInt32(); + aPos.X = o3tl::toInt32(aXStr); + aPos.Y = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken )); if ( i == PROPERTY_POS ) { @@ -863,12 +860,12 @@ ConfigurationAccess_WindowState::WindowStateInfo& ConfigurationAccess_WindowStat if ( a >>= aString ) { sal_Int32 nToken( 0 ); - OUString aStr = aString.getToken( 0, ',', nToken ); + std::u16string_view aStr = o3tl::getToken(aString, 0, ',', nToken ); if ( nToken > 0 ) { css::awt::Size aSize; - aSize.Width = aStr.toInt32(); - aSize.Height = aString.getToken( 0, ',', nToken ).toInt32(); + aSize.Width = o3tl::toInt32(aStr); + aSize.Height = o3tl::toInt32(o3tl::getToken(aString, 0, ',', nToken )); if ( i == PROPERTY_SIZE ) { aWindowStateInfo.aSize = aSize; @@ -1132,23 +1129,23 @@ void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const Window switch ( i ) { case PROPERTY_LOCKED: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bLocked ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bLocked ) ); break; case PROPERTY_DOCKED: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bDocked ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bDocked ) ); break; case PROPERTY_VISIBLE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bVisible ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bVisible ) ); break; case PROPERTY_CONTEXT: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bContext ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bContext ) ); break; case PROPERTY_HIDEFROMMENU: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bHideFromMenu ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bHideFromMenu ) ); break; case PROPERTY_NOCLOSE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bNoClose ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bNoClose ) ); break; case PROPERTY_SOFTCLOSE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bSoftClose ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bSoftClose ) ); break; case PROPERTY_CONTEXTACTIVE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.bContextActive ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.bContextActive ) ); break; case PROPERTY_DOCKINGAREA: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int16( rWinStateInfo.aDockingArea ) ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int16( rWinStateInfo.aDockingArea ) ) ); break; case PROPERTY_POS: case PROPERTY_DOCKPOS: { @@ -1162,7 +1159,7 @@ void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const Window aPosStr += OUString::number( rWinStateInfo.aPos.Y ); else aPosStr += OUString::number( rWinStateInfo.aDockPos.Y ); - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aPosStr ) ); + xPropSet->setPropertyValue( m_aPropArray[i], Any( aPosStr ) ); break; } case PROPERTY_SIZE: @@ -1178,15 +1175,15 @@ void ConfigurationAccess_WindowState::impl_putPropertiesFromStruct( const Window aSizeStr += OUString::number( rWinStateInfo.aSize.Height ); else aSizeStr += OUString::number( rWinStateInfo.aDockSize.Height ); - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( aSizeStr ) ); + xPropSet->setPropertyValue( m_aPropArray[i], Any( aSizeStr ) ); break; } case PROPERTY_UINAME: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( rWinStateInfo.aUIName ) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( rWinStateInfo.aUIName ) ); break; case PROPERTY_INTERNALSTATE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nInternalState )) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int32( rWinStateInfo.nInternalState )) ); break; case PROPERTY_STYLE: - xPropSet->setPropertyValue( m_aPropArray[i], makeAny( sal_Int32( rWinStateInfo.nStyle )) ); break; + xPropSet->setPropertyValue( m_aPropArray[i], Any( sal_Int32( rWinStateInfo.nStyle )) ); break; default: assert( false && "Wrong value for ConfigurationAccess_WindowState. Who has forgotten to add this new property!" ); } @@ -1227,11 +1224,10 @@ void ConfigurationAccess_WindowState::impl_initializeConfigAccess() } } -typedef ::cppu::WeakComponentImplHelper< css::container::XNameAccess, +typedef comphelper::WeakComponentImplHelper< css::container::XNameAccess, css::lang::XServiceInfo> WindowStateConfiguration_BASE; -class WindowStateConfiguration : private cppu::BaseMutex, - public WindowStateConfiguration_BASE +class WindowStateConfiguration : public WindowStateConfiguration_BASE { public: explicit WindowStateConfiguration( const css::uno::Reference< css::uno::XComponentContext >& rxContext ); @@ -1276,7 +1272,6 @@ private: }; WindowStateConfiguration::WindowStateConfiguration( const Reference< XComponentContext >& rxContext ) : - WindowStateConfiguration_BASE(m_aMutex), m_xContext( rxContext ) { css::uno::Reference< css::frame::XModuleManager2 > xModuleManager = @@ -1292,12 +1287,12 @@ WindowStateConfiguration::WindowStateConfiguration( const Reference< XComponentC } Sequence< PropertyValue > aSeq; - for ( OUString const & aModuleIdentifier : std::as_const(aElementNames) ) + for (OUString const& aModuleIdentifier : aElementNames) { if ( xModuleManager->getByName( aModuleIdentifier ) >>= aSeq ) { OUString aWindowStateFileStr; - for ( PropertyValue const & rProp : std::as_const(aSeq) ) + for (PropertyValue const& rProp : aSeq) { if ( rProp.Name == "ooSetupFactoryWindowStateConfigRef" ) { @@ -1322,14 +1317,14 @@ WindowStateConfiguration::WindowStateConfiguration( const Reference< XComponentC WindowStateConfiguration::~WindowStateConfiguration() { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); + std::unique_lock g(m_aMutex); m_aModuleToFileHashMap.clear(); m_aModuleToWindowStateHashMap.clear(); } Any SAL_CALL WindowStateConfiguration::getByName( const OUString& aModuleIdentifier ) { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); + std::unique_lock g(m_aMutex); ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aModuleIdentifier ); if ( pIter != m_aModuleToFileHashMap.end() ) @@ -1358,14 +1353,14 @@ Any SAL_CALL WindowStateConfiguration::getByName( const OUString& aModuleIdentif Sequence< OUString > SAL_CALL WindowStateConfiguration::getElementNames() { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); + std::unique_lock g(m_aMutex); return comphelper::mapKeysToSequence( m_aModuleToFileHashMap ); } sal_Bool SAL_CALL WindowStateConfiguration::hasByName( const OUString& aName ) { - osl::MutexGuard g(cppu::WeakComponentImplHelperBase::rBHelper.rMutex); + std::unique_lock g(m_aMutex); ModuleToWindowStateFileMap::const_iterator pIter = m_aModuleToFileHashMap.find( aName ); return ( pIter != m_aModuleToFileHashMap.end() ); |