summaryrefslogtreecommitdiffstats
path: root/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
diff options
context:
space:
mode:
Diffstat (limited to 'framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx')
-rw-r--r--framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx107
1 files changed, 52 insertions, 55 deletions
diff --git a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
index 65ff144913f9..4e3585c51341 100644
--- a/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
+++ b/framework/source/uiconfiguration/moduleuiconfigurationmanager.cxx
@@ -52,12 +52,14 @@
#include <cppuhelper/exc_hlp.hxx>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <utility>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
#include <comphelper/interfacecontainer4.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/sequenceashashmap.hxx>
#include <comphelper/servicehelper.hxx>
+#include <o3tl/string_view.hxx>
#include <memory>
#include <mutex>
#include <string_view>
@@ -123,6 +125,7 @@ public:
virtual void SAL_CALL insertSettings( const OUString& NewResourceURL, const css::uno::Reference< css::container::XIndexAccess >& aNewData ) override;
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getImageManager() override;
virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL getShortCutManager() override;
+ virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL createShortCutManager() override;
virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getEventsManager() override;
// XModuleUIConfigurationManager
@@ -154,8 +157,8 @@ private:
struct UIElementInfo
{
- UIElementInfo( const OUString& rResourceURL, const OUString& rUIName ) :
- aResourceURL( rResourceURL), aUIName( rUIName ) {}
+ UIElementInfo( OUString _aResourceURL, OUString _aUIName ) :
+ aResourceURL(std::move( _aResourceURL)), aUIName(std::move( _aUIName )) {}
OUString aResourceURL;
OUString aUIName;
};
@@ -234,20 +237,19 @@ std::u16string_view UIELEMENTTYPENAMES[] =
u"" UIELEMENTTYPE_TOOLPANEL_NAME
};
-const char RESOURCEURL_PREFIX[] = "private:resource/";
-const sal_Int32 RESOURCEURL_PREFIX_SIZE = strlen(RESOURCEURL_PREFIX);
+constexpr std::u16string_view RESOURCEURL_PREFIX = u"private:resource/";
-sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
+sal_Int16 RetrieveTypeFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- OUString aTmpStr = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE );
- sal_Int32 nIndex = aTmpStr.indexOf( '/' );
- if (( nIndex > 0 ) && ( aTmpStr.getLength() > nIndex ))
+ std::u16string_view aTmpStr = aResourceURL.substr( RESOURCEURL_PREFIX.size() );
+ size_t nIndex = aTmpStr.find( '/' );
+ if (( nIndex > 0 ) && ( aTmpStr.size() > nIndex ))
{
- OUString aTypeStr( aTmpStr.copy( 0, nIndex ));
+ std::u16string_view aTypeStr( aTmpStr.substr( 0, nIndex ));
for ( int i = 0; i < ui::UIElementType::COUNT; i++ )
{
if ( aTypeStr == UIELEMENTTYPENAMES[i] )
@@ -259,14 +261,15 @@ sal_Int16 RetrieveTypeFromResourceURL( const OUString& aResourceURL )
return ui::UIElementType::UNKNOWN;
}
-OUString RetrieveNameFromResourceURL( const OUString& aResourceURL )
+OUString RetrieveNameFromResourceURL( std::u16string_view aResourceURL )
{
- if (( aResourceURL.startsWith( RESOURCEURL_PREFIX ) ) &&
- ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE ))
+ if (( o3tl::starts_with(aResourceURL, RESOURCEURL_PREFIX ) ) &&
+ ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
{
- sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' );
- if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength()))
- return aResourceURL.copy( nIndex+1 );
+ size_t nIndex = aResourceURL.rfind( '/' );
+
+ if ( nIndex > 0 && nIndex != std::u16string_view::npos && (( nIndex+1 ) < aResourceURL.size()) )
+ return OUString(aResourceURL.substr( nIndex+1 ));
}
return OUString();
@@ -283,8 +286,8 @@ void ModuleUIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIEleme
OUString aCustomUrlPrefix( "custom_" );
for (auto const& userElement : rUserElements)
{
- sal_Int32 nIndex = userElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
- if ( nIndex > RESOURCEURL_PREFIX_SIZE )
+ sal_Int32 nIndex = userElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX.size() );
+ if ( nIndex > static_cast<sal_Int32>(RESOURCEURL_PREFIX.size()) )
{
// Performance: Retrieve user interface name only for custom user interface elements.
// It's only used by them!
@@ -319,8 +322,8 @@ void ModuleUIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIEleme
UIElementInfoHashMap::const_iterator pIterInfo = aUIElementInfoCollection.find( defaultElement.second.aResourceURL );
if ( pIterInfo == aUIElementInfoCollection.end() )
{
- sal_Int32 nIndex = defaultElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE );
- if ( nIndex > RESOURCEURL_PREFIX_SIZE )
+ sal_Int32 nIndex = defaultElement.second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX.size() );
+ if ( nIndex > static_cast<sal_Int32>(RESOURCEURL_PREFIX.size()) )
{
// Performance: Retrieve user interface name only for custom user interface elements.
// It's only used by them!
@@ -375,11 +378,11 @@ void ModuleUIConfigurationManager::impl_preloadUIElementTypeList( Layer eLayer,
sal_Int32 nIndex = rElementName.lastIndexOf( '.' );
if (( nIndex > 0 ) && ( nIndex < rElementName.getLength() ))
{
- OUString aExtension( rElementName.copy( nIndex+1 ));
- OUString aUIElementName( rElementName.copy( 0, nIndex ));
+ std::u16string_view aExtension( rElementName.subView( nIndex+1 ));
+ std::u16string_view aUIElementName( rElementName.subView( 0, nIndex ));
- if (!aUIElementName.isEmpty() &&
- ( aExtension.equalsIgnoreAsciiCase("xml")))
+ if (!aUIElementName.empty() &&
+ ( o3tl::equalsIgnoreAsciiCase(aExtension, u"xml")))
{
aUIElementData.aResourceURL = aResURLPrefix + aUIElementName;
aUIElementData.aName = rElementName;
@@ -427,7 +430,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
{
MenuConfiguration aMenuCfg( m_xContext );
Reference< XIndexAccess > xContainer( aMenuCfg.CreateMenuBarConfigurationFromXML( xInputStream ));
- auto pRootItemContainer = comphelper::getFromUnoTunnel<RootItemContainer>( xContainer );
+ auto pRootItemContainer = dynamic_cast<RootItemContainer*>( xContainer.get() );
if ( pRootItemContainer )
aUIElementData.xSettings = new ConstItemContainer( pRootItemContainer, true );
else
@@ -446,7 +449,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
{
Reference< XIndexContainer > xIndexContainer( new RootItemContainer() );
ToolBoxConfiguration::LoadToolBox( m_xContext, xInputStream, xIndexContainer );
- auto pRootItemContainer = comphelper::getFromUnoTunnel<RootItemContainer>( xIndexContainer );
+ auto pRootItemContainer = dynamic_cast<RootItemContainer*>( xIndexContainer.get() );
aUIElementData.xSettings = new ConstItemContainer( pRootItemContainer, true );
return;
}
@@ -463,7 +466,7 @@ void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElement
{
Reference< XIndexContainer > xIndexContainer( new RootItemContainer() );
StatusBarConfiguration::LoadStatusBar( m_xContext, xInputStream, xIndexContainer );
- auto pRootItemContainer = comphelper::getFromUnoTunnel<RootItemContainer>( xIndexContainer );
+ auto pRootItemContainer = dynamic_cast<RootItemContainer*>( xIndexContainer.get() );
aUIElementData.xSettings = new ConstItemContainer( pRootItemContainer, true );
return;
}
@@ -1086,11 +1089,10 @@ Sequence< Sequence< PropertyValue > > SAL_CALL ModuleUIConfigurationManager::get
sal_Int32 n = 0;
for (auto const& elem : aUIElementInfoCollection)
{
- Sequence< PropertyValue > aUIElementInfo{
+ aElementInfoSeq[n++] = Sequence<PropertyValue> {
comphelper::makePropertyValue("ResourceURL", elem.second.aResourceURL),
comphelper::makePropertyValue(m_aPropUIName, elem.second.aUIName)
};
- aElementInfoSeq[n++] = aUIElementInfo;
}
return comphelper::containerToSequence(aElementInfoSeq);
@@ -1192,13 +1194,12 @@ void SAL_CALL ModuleUIConfigurationManager::replaceSettings( const OUString& Res
rElementType.bModified = true;
Reference< XUIConfigurationManager > xThis(this);
- Reference< XInterface > xIfac( xThis, UNO_QUERY );
// Create event to notify listener about replaced element settings
ui::ConfigurationEvent aEvent;
aEvent.ResourceURL = ResourceURL;
aEvent.Accessor <<= xThis;
- aEvent.Source = xIfac;
+ aEvent.Source.set(xThis, UNO_QUERY);
aEvent.ReplacedElement <<= xOldSettings;
aEvent.Element <<= pDataSettings->xSettings;
@@ -1240,14 +1241,13 @@ void SAL_CALL ModuleUIConfigurationManager::replaceSettings( const OUString& Res
rElements.emplace( ResourceURL, aUIElementData );
Reference< XUIConfigurationManager > xThis(this);
- Reference< XInterface > xIfac( xThis, UNO_QUERY );
// Create event to notify listener about replaced element settings
ui::ConfigurationEvent aEvent;
aEvent.ResourceURL = ResourceURL;
aEvent.Accessor <<= xThis;
- aEvent.Source = xIfac;
+ aEvent.Source.set(xThis, UNO_QUERY);
aEvent.ReplacedElement <<= pDataSettings->xSettings;
aEvent.Element <<= aUIElementData.xSettings;
@@ -1420,6 +1420,11 @@ Reference< XInterface > SAL_CALL ModuleUIConfigurationManager::getImageManager()
return Reference< XInterface >( static_cast<cppu::OWeakObject*>(m_xModuleImageManager.get()), UNO_QUERY );
}
+Reference< ui::XAcceleratorConfiguration > SAL_CALL ModuleUIConfigurationManager::createShortCutManager()
+{
+ return ui::ModuleAcceleratorConfiguration::createWithModuleIdentifier(m_xContext, m_aModuleIdentifier);
+}
+
Reference< ui::XAcceleratorConfiguration > SAL_CALL ModuleUIConfigurationManager::getShortCutManager()
{
SolarMutexGuard g;
@@ -1623,29 +1628,21 @@ sal_Bool SAL_CALL ModuleUIConfigurationManager::isReadOnly()
void ModuleUIConfigurationManager::implts_notifyContainerListener( const ui::ConfigurationEvent& aEvent, NotifyOp eOp )
{
std::unique_lock aGuard(m_mutex);
- comphelper::OInterfaceIteratorHelper4 pIterator( aGuard, m_aConfigListeners );
- while ( pIterator.hasMoreElements() )
+ using ListenerMethodType = void (SAL_CALL css::ui::XUIConfigurationListener::*)(const ui::ConfigurationEvent&);
+ ListenerMethodType aListenerMethod {};
+ switch ( eOp )
{
- try
- {
- switch ( eOp )
- {
- case NotifyOp_Replace:
- pIterator.next()->elementReplaced( aEvent );
- break;
- case NotifyOp_Insert:
- pIterator.next()->elementInserted( aEvent );
- break;
- case NotifyOp_Remove:
- pIterator.next()->elementRemoved( aEvent );
- break;
- }
- }
- catch( const css::uno::RuntimeException& )
- {
- pIterator.remove(aGuard);
- }
+ case NotifyOp_Replace:
+ aListenerMethod = &css::ui::XUIConfigurationListener::elementReplaced;
+ break;
+ case NotifyOp_Insert:
+ aListenerMethod = &css::ui::XUIConfigurationListener::elementInserted;
+ break;
+ case NotifyOp_Remove:
+ aListenerMethod = &css::ui::XUIConfigurationListener::elementRemoved;
+ break;
}
+ m_aConfigListeners.notifyEach(aGuard, aListenerMethod, aEvent);
}
}