28#include <com/sun/star/beans/XPropertySet.hpp>
29#include <com/sun/star/container/ElementExistException.hpp>
30#include <com/sun/star/container/XIndexContainer.hpp>
31#include <com/sun/star/embed/ElementModes.hpp>
32#include <com/sun/star/embed/InvalidStorageException.hpp>
33#include <com/sun/star/embed/StorageWrappedTargetException.hpp>
34#include <com/sun/star/embed/XTransactedObject.hpp>
35#include <com/sun/star/lang/IllegalAccessException.hpp>
36#include <com/sun/star/lang/DisposedException.hpp>
37#include <com/sun/star/io/IOException.hpp>
38#include <com/sun/star/io/XStream.hpp>
39#include <com/sun/star/ui/UIElementType.hpp>
40#include <com/sun/star/ui/ConfigurationEvent.hpp>
41#include <com/sun/star/ui/DocumentAcceleratorConfiguration.hpp>
42#include <com/sun/star/ui/XAcceleratorConfiguration.hpp>
43#include <com/sun/star/ui/XUIConfigurationManager2.hpp>
44#include <com/sun/star/lang/XComponent.hpp>
45#include <com/sun/star/lang/XServiceInfo.hpp>
61#include <unordered_map>
74class UIConfigurationManager :
public ::cppu::WeakImplHelper<
75 css::lang::XServiceInfo ,
76 css::ui::XUIConfigurationManager2 >
81 return "com.sun.star.comp.framework.UIConfigurationManager";
91 return {
"com.sun.star.ui.UIConfigurationManager"};
94 explicit UIConfigurationManager( css::uno::Reference< css::uno::XComponentContext > xContext );
97 virtual void SAL_CALL
dispose()
override;
98 virtual void SAL_CALL addEventListener(
const css::uno::Reference< css::lang::XEventListener >& xListener )
override;
99 virtual void SAL_CALL removeEventListener(
const css::uno::Reference< css::lang::XEventListener >& aListener )
override;
102 virtual void SAL_CALL addConfigurationListener(
const css::uno::Reference< css::ui::XUIConfigurationListener >& Listener )
override;
103 virtual void SAL_CALL removeConfigurationListener(
const css::uno::Reference< css::ui::XUIConfigurationListener >& Listener )
override;
106 virtual void SAL_CALL reset()
override;
107 virtual css::uno::Sequence< css::uno::Sequence< css::beans::PropertyValue > > SAL_CALL getUIElementsInfo( sal_Int16
ElementType )
override;
108 virtual css::uno::Reference< css::container::XIndexContainer > SAL_CALL createSettings( )
override;
109 virtual sal_Bool SAL_CALL hasSettings(
const OUString& ResourceURL )
override;
110 virtual css::uno::Reference< css::container::XIndexAccess > SAL_CALL getSettings(
const OUString& ResourceURL,
sal_Bool bWriteable )
override;
111 virtual void SAL_CALL replaceSettings(
const OUString& ResourceURL,
const css::uno::Reference< css::container::XIndexAccess >& aNewData )
override;
112 virtual void SAL_CALL removeSettings(
const OUString& ResourceURL )
override;
113 virtual void SAL_CALL insertSettings(
const OUString& NewResourceURL,
const css::uno::Reference< css::container::XIndexAccess >& aNewData )
override;
114 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getImageManager()
override;
115 virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL getShortCutManager()
override;
116 virtual css::uno::Reference< css::ui::XAcceleratorConfiguration > SAL_CALL createShortCutManager()
override;
117 virtual css::uno::Reference< css::uno::XInterface > SAL_CALL getEventsManager()
override;
120 virtual void SAL_CALL reload()
override;
121 virtual void SAL_CALL
store()
override;
122 virtual void SAL_CALL storeToStorage(
const css::uno::Reference< css::embed::XStorage >& Storage )
override;
123 virtual sal_Bool SAL_CALL isModified()
override;
124 virtual sal_Bool SAL_CALL isReadOnly()
override;
127 virtual void SAL_CALL setStorage(
const css::uno::Reference< css::embed::XStorage >& Storage )
override;
128 virtual sal_Bool SAL_CALL hasStorage()
override;
141 UIElementInfo( OUString _aResourceURL, OUString _aUIName ) :
142 aResourceURL(
std::move( _aResourceURL)),
aUIName(
std::move( _aUIName )) {}
143 OUString aResourceURL;
149 UIElementData() : bModified( false ), bDefault( true ) {};
151 OUString aResourceURL;
155 css::uno::Reference< css::container::XIndexAccess > xSettings;
158 struct UIElementType;
159 friend struct UIElementType;
160 typedef std::unordered_map< OUString, UIElementData > UIElementDataHashMap;
164 UIElementType() : bModified( false ),
166 nElementType( css::ui::UIElementType::
UNKNOWN ) {}
170 sal_Int16 nElementType;
171 UIElementDataHashMap aElementsHashMap;
172 css::uno::Reference< css::embed::XStorage > xStorage;
175 typedef std::vector< UIElementType > UIElementTypesVector;
176 typedef std::vector< css::ui::ConfigurationEvent > ConfigEventNotifyContainer;
177 typedef std::unordered_map< OUString, UIElementInfo > UIElementInfoHashMap;
179 void impl_Initialize();
180 void implts_notifyContainerListener(
const css::ui::ConfigurationEvent& aEvent, NotifyOp eOp );
181 void impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType );
182 void impl_preloadUIElementTypeList( sal_Int16 nElementType );
183 UIElementData* impl_findUIElementData(
const OUString& aResourceURL, sal_Int16 nElementType,
bool bLoad =
true );
184 void impl_requestUIElementData( sal_Int16 nElementType, UIElementData& aUIElementData );
185 void impl_storeElementTypeData( css::uno::Reference< css::embed::XStorage >
const & xStorage, UIElementType& rElementType,
bool bResetModifyState =
true );
186 void impl_resetElementTypeData( UIElementType& rDocElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer );
187 void impl_reloadElementTypeData( UIElementType& rDocElementType, ConfigEventNotifyContainer& rRemoveNotifyContainer, ConfigEventNotifyContainer& rReplaceNotifyContainer );
189 UIElementTypesVector m_aUIElements;
190 css::uno::Reference< css::embed::XStorage > m_xDocConfigStorage;
194 OUString m_aPropUIName;
195 css::uno::Reference< css::uno::XComponentContext >
m_xContext;
200 css::uno::Reference< css::ui::XAcceleratorConfiguration > m_xAccConfig;
205std::u16string_view UIELEMENTTYPENAMES[] =
217constexpr std::u16string_view RESOURCEURL_PREFIX =
u"private:resource/";
219sal_Int16 RetrieveTypeFromResourceURL( std::u16string_view aResourceURL )
223 ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
225 std::u16string_view aTmpStr = aResourceURL.substr( RESOURCEURL_PREFIX.size() );
226 size_t nIndex = aTmpStr.find(
'/' );
227 if (( nIndex > 0 ) && ( aTmpStr.size() > nIndex ))
229 std::u16string_view aTypeStr( aTmpStr.substr( 0, nIndex ));
230 for (
int i = 0;
i < UIElementType::COUNT;
i++ )
232 if ( aTypeStr == UIELEMENTTYPENAMES[i] )
233 return sal_Int16( i );
238 return UIElementType::UNKNOWN;
241OUString RetrieveNameFromResourceURL( std::u16string_view aResourceURL )
244 ( aResourceURL.size() > RESOURCEURL_PREFIX.size() ))
246 size_t nIndex = aResourceURL.rfind(
'/' );
247 if ( (nIndex > 0) && (nIndex != std::u16string_view::npos) && (( nIndex+1 ) < aResourceURL.size()) )
248 return OUString(aResourceURL.substr( nIndex+1 ));
254void UIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType )
257 impl_preloadUIElementTypeList( nElementType );
259 UIElementDataHashMap& rUserElements = m_aUIElements[nElementType].aElementsHashMap;
261 for (
auto const& elem : rUserElements)
263 UIElementData* pDataSettings = impl_findUIElementData( elem.second.aResourceURL, nElementType );
264 if ( pDataSettings && !pDataSettings->bDefault )
271 Any a = xPropSet->getPropertyValue( m_aPropUIName );
275 UIElementInfo aInfo( elem.second.aResourceURL,
aUIName );
276 aUIElementInfoCollection.emplace( elem.second.aResourceURL, aInfo );
281void UIConfigurationManager::impl_preloadUIElementTypeList( sal_Int16 nElementType )
283 UIElementType& rElementTypeData = m_aUIElements[nElementType];
285 if ( !rElementTypeData.bLoaded )
288 if ( xElementTypeStorage.is() )
290 OUString aResURLPrefix =
291 OUString::Concat(RESOURCEURL_PREFIX) +
292 UIELEMENTTYPENAMES[ nElementType ] +
295 UIElementDataHashMap& rHashMap = rElementTypeData.aElementsHashMap;
297 for ( OUString
const & rElementName : aUIElementNames )
299 UIElementData aUIElementData;
302 sal_Int32
nIndex = rElementName.lastIndexOf(
'.' );
303 if (( nIndex > 0 ) && ( nIndex < rElementName.getLength() ))
305 std::u16string_view aExtension( rElementName.subView( nIndex+1 ));
306 std::u16string_view aUIElementName( rElementName.subView( 0, nIndex ));
308 if (!aUIElementName.empty() &&
311 aUIElementData.aResourceURL = aResURLPrefix + aUIElementName;
312 aUIElementData.aName = rElementName;
313 aUIElementData.bModified =
false;
314 aUIElementData.bDefault =
false;
318 rHashMap.emplace( aUIElementData.aResourceURL, aUIElementData );
325 rElementTypeData.bLoaded =
true;
328void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType, UIElementData& aUIElementData )
330 UIElementType& rElementTypeData = m_aUIElements[nElementType];
333 if ( xElementTypeStorage.is() && !aUIElementData.aName.isEmpty() )
340 if ( xInputStream.is() )
342 switch ( nElementType )
344 case css::ui::UIElementType::UNKNOWN:
347 case css::ui::UIElementType::MENUBAR:
348 case css::ui::UIElementType::POPUPMENU:
355 if ( pRootItemContainer )
361 catch (
const css::lang::WrappedTargetException& )
367 case css::ui::UIElementType::TOOLBAR:
372 ToolBoxConfiguration::LoadToolBox(
m_xContext, xInputStream, xIndexContainer );
373 auto pRootItemContainer =
dynamic_cast<RootItemContainer*
>( xIndexContainer.get() );
377 catch (
const css::lang::WrappedTargetException& )
384 case css::ui::UIElementType::STATUSBAR:
389 StatusBarConfiguration::LoadStatusBar(
m_xContext, xInputStream, xIndexContainer );
390 auto pRootItemContainer =
dynamic_cast<RootItemContainer*
>( xIndexContainer.get() );
394 catch (
const css::lang::WrappedTargetException& )
401 case css::ui::UIElementType::FLOATINGWINDOW:
408 catch (
const css::embed::InvalidStorageException& )
411 catch (
const css::lang::IllegalArgumentException& )
414 catch (
const css::io::IOException& )
417 catch (
const css::embed::StorageWrappedTargetException& )
426UIConfigurationManager::UIElementData* UIConfigurationManager::impl_findUIElementData(
const OUString& aResourceURL, sal_Int16 nElementType,
bool bLoad )
429 impl_preloadUIElementTypeList( nElementType );
432 UIElementDataHashMap& rUserHashMap = m_aUIElements[nElementType].aElementsHashMap;
433 UIElementDataHashMap::iterator pIter = rUserHashMap.find( aResourceURL );
434 if ( pIter != rUserHashMap.end() )
437 if ( pIter->second.bDefault )
438 return &(pIter->second);
441 if ( !pIter->second.xSettings.is() && bLoad )
442 impl_requestUIElementData( nElementType, pIter->second );
443 return &(pIter->second);
451void UIConfigurationManager::impl_storeElementTypeData(
Reference< XStorage > const & xStorage, UIElementType& rElementType,
bool bResetModifyState )
453 UIElementDataHashMap& rHashMap = rElementType.aElementsHashMap;
455 for (
auto & elem : rHashMap)
457 UIElementData& rElement = elem.second;
458 if ( rElement.bModified )
460 if ( rElement.bDefault )
462 xStorage->removeElement( rElement.aName );
463 rElement.bModified =
false;
470 if ( xOutputStream.is() )
472 switch( rElementType.nElementType )
474 case css::ui::UIElementType::MENUBAR:
475 case css::ui::UIElementType::POPUPMENU:
480 aMenuCfg.StoreMenuBarConfigurationToXML(
481 rElement.xSettings, xOutputStream, rElementType.nElementType == css::ui::UIElementType::MENUBAR );
483 catch (
const css::lang::WrappedTargetException& )
489 case css::ui::UIElementType::TOOLBAR:
493 ToolBoxConfiguration::StoreToolBox(
m_xContext, xOutputStream, rElement.xSettings );
495 catch (
const css::lang::WrappedTargetException& )
501 case css::ui::UIElementType::STATUSBAR:
505 StatusBarConfiguration::StoreStatusBar(
m_xContext, xOutputStream, rElement.xSettings );
507 catch (
const css::lang::WrappedTargetException& )
519 if ( bResetModifyState )
520 rElement.bModified =
false;
527 if ( xTransactedObject.is() )
528 xTransactedObject->commit();
531 if ( bResetModifyState )
532 rElementType.bModified =
false;
535void UIConfigurationManager::impl_resetElementTypeData(
536 UIElementType& rDocElementType,
537 ConfigEventNotifyContainer& rRemoveNotifyContainer )
539 UIElementDataHashMap& rHashMap = rDocElementType.aElementsHashMap;
546 for (
auto & elem : rHashMap)
548 UIElementData& rElement = elem.second;
549 if ( !rElement.bDefault )
552 ConfigurationEvent
aEvent;
553 aEvent.ResourceURL = rElement.aResourceURL;
554 aEvent.Accessor <<= xThis;
556 aEvent.Element <<= rElement.xSettings;
558 rRemoveNotifyContainer.push_back( aEvent );
561 rElement.bModified =
false;
562 rElement.bDefault =
true;
565 rElement.bModified =
false;
572void UIConfigurationManager::impl_reloadElementTypeData(
573 UIElementType& rDocElementType,
574 ConfigEventNotifyContainer& rRemoveNotifyContainer,
575 ConfigEventNotifyContainer& rReplaceNotifyContainer )
577 UIElementDataHashMap& rHashMap = rDocElementType.aElementsHashMap;
582 sal_Int16
nType = rDocElementType.nElementType;
584 for (
auto & elem : rHashMap)
586 UIElementData& rElement = elem.second;
587 if ( rElement.bModified )
589 if ( xElementStorage->hasByName( rElement.aName ))
594 impl_requestUIElementData( nType, rElement );
596 ConfigurationEvent aReplaceEvent;
598 aReplaceEvent.ResourceURL = rElement.aResourceURL;
599 aReplaceEvent.Accessor <<= xThis;
600 aReplaceEvent.Source = xIfac;
601 aReplaceEvent.ReplacedElement <<= xOldSettings;
602 aReplaceEvent.Element <<= rElement.xSettings;
603 rReplaceNotifyContainer.push_back( aReplaceEvent );
605 rElement.bModified =
false;
610 ConfigurationEvent aRemoveEvent;
612 aRemoveEvent.ResourceURL = rElement.aResourceURL;
613 aRemoveEvent.Accessor <<= xThis;
614 aRemoveEvent.Source = xIfac;
615 aRemoveEvent.Element <<= rElement.xSettings;
617 rRemoveNotifyContainer.push_back( aRemoveEvent );
620 rElement.bModified =
false;
621 rElement.bDefault =
true;
626 rDocElementType.bModified =
false;
629void UIConfigurationManager::impl_Initialize()
632 if ( m_xDocConfigStorage.is() )
637 for ( sal_Int16 i = 1;
i < css::ui::UIElementType::COUNT;
643 xElementTypeStorage = m_xDocConfigStorage->openStorageElement( OUString(UIELEMENTTYPENAMES[i]), nModes );
645 catch (
const css::container::NoSuchElementException& )
648 catch (
const css::embed::InvalidStorageException& )
651 catch (
const css::lang::IllegalArgumentException& )
654 catch (
const css::io::IOException& )
657 catch (
const css::embed::StorageWrappedTargetException& )
661 m_aUIElements[
i].nElementType =
i;
662 m_aUIElements[
i].bModified =
false;
663 m_aUIElements[
i].xStorage = xElementTypeStorage;
669 for (
int i = 1;
i < css::ui::UIElementType::COUNT;
i++ )
670 m_aUIElements[i].xStorage = m_xDocConfigStorage;
674UIConfigurationManager::UIConfigurationManager( css::uno::Reference< css::uno::XComponentContext > xContext ) :
676 , m_bModified( false )
678 , m_aPropUIName(
"UIName" )
683 m_aUIElements.resize( css::ui::UIElementType::COUNT );
687void SAL_CALL UIConfigurationManager::dispose()
691 css::lang::EventObject
aEvent( xThis );
693 std::unique_lock aGuard(
m_mutex);
694 m_aEventListeners.disposeAndClear( aGuard, aEvent );
697 std::unique_lock aGuard(
m_mutex);
698 m_aConfigListeners.disposeAndClear( aGuard, aEvent );
705 if ( m_xImageManager.is() )
706 m_xImageManager->dispose();
708 catch (
const Exception& )
712 m_xImageManager.clear();
713 m_aUIElements.clear();
714 m_xDocConfigStorage.clear();
727 throw DisposedException();
730 std::unique_lock aGuard(
m_mutex);
731 m_aEventListeners.addInterface( aGuard, xListener );
737 std::unique_lock aGuard(
m_mutex);
738 m_aEventListeners.removeInterface( aGuard, xListener );
749 throw DisposedException();
752 std::unique_lock aGuard(
m_mutex);
753 m_aConfigListeners.addInterface( aGuard, xListener );
759 std::unique_lock aGuard(
m_mutex);
760 m_aConfigListeners.removeInterface( aGuard, xListener );
763void SAL_CALL UIConfigurationManager::reset()
769 throw DisposedException();
774 if ( !m_xDocConfigStorage.is() )
780 bool bCommit(
false );
781 for (
int i = 1;
i < css::ui::UIElementType::COUNT;
i++ )
783 UIElementType& rElementType = m_aUIElements[
i];
785 if ( rElementType.xStorage.is() )
787 bool bCommitSubStorage(
false );
789 for ( OUString
const & rStreamName : aUIElementStreamNames )
791 rElementType.xStorage->removeElement( rStreamName );
792 bCommitSubStorage =
true;
796 if ( bCommitSubStorage )
799 if ( xTransactedObject.is() )
800 xTransactedObject->commit();
809 if ( xTransactedObject.is() )
810 xTransactedObject->commit();
815 ConfigEventNotifyContainer aRemoveEventNotifyContainer;
816 for ( sal_Int16 j = 1; j < css::ui::UIElementType::COUNT; j++ )
818 UIElementType& rDocElementType = m_aUIElements[j];
820 impl_resetElementTypeData( rDocElementType, aRemoveEventNotifyContainer );
821 rDocElementType.bModified =
false;
830 for (
const ConfigurationEvent & k : aRemoveEventNotifyContainer)
831 implts_notifyContainerListener( k, NotifyOp_Remove );
833 catch (
const css::lang::IllegalArgumentException& )
836 catch (
const css::container::NoSuchElementException& )
839 catch (
const css::embed::InvalidStorageException& )
842 catch (
const css::embed::StorageWrappedTargetException& )
850 throw IllegalArgumentException();
854 throw DisposedException();
856 std::vector< Sequence< PropertyValue > > aElementInfoSeq;
857 UIElementInfoHashMap aUIElementInfoCollection;
859 if (
ElementType == css::ui::UIElementType::UNKNOWN )
861 for ( sal_Int16 i = 0;
i < css::ui::UIElementType::COUNT;
i++ )
862 impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, i );
865 impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection,
ElementType );
867 aElementInfoSeq.resize( aUIElementInfoCollection.size() );
869 for (
auto const& elem : aUIElementInfoCollection)
875 aElementInfoSeq[
n++] = aUIElementInfo;
886 throw DisposedException();
892sal_Bool SAL_CALL UIConfigurationManager::hasSettings(
const OUString& ResourceURL )
894 sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
896 if (( nElementType == css::ui::UIElementType::UNKNOWN ) ||
897 ( nElementType >= css::ui::UIElementType::COUNT ))
898 throw IllegalArgumentException();
899 UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType,
false );
900 if ( pDataSettings && !pDataSettings->bDefault )
908 sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
910 if (( nElementType == css::ui::UIElementType::UNKNOWN ) ||
911 ( nElementType >= css::ui::UIElementType::COUNT ))
912 throw IllegalArgumentException();
917 throw DisposedException();
919 UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
920 if ( pDataSettings && !pDataSettings->bDefault )
926 return pDataSettings->xSettings;
929 throw NoSuchElementException();
934 sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
936 if (( nElementType == css::ui::UIElementType::UNKNOWN ) ||
937 ( nElementType >= css::ui::UIElementType::COUNT ))
938 throw IllegalArgumentException();
939 else if ( m_bReadOnly )
940 throw IllegalAccessException();
946 throw DisposedException();
948 UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
949 if ( !pDataSettings || pDataSettings->bDefault )
950 throw NoSuchElementException();
959 pDataSettings->xSettings = aNewData;
961 pDataSettings->bDefault =
false;
962 pDataSettings->bModified =
true;
966 UIElementType& rElementType = m_aUIElements[nElementType];
967 rElementType.bModified =
true;
973 ConfigurationEvent
aEvent;
975 aEvent.ResourceURL = ResourceURL;
976 aEvent.Accessor <<= xThis;
978 aEvent.ReplacedElement <<= xOldSettings;
979 aEvent.Element <<= pDataSettings->xSettings;
983 implts_notifyContainerListener( aEvent, NotifyOp_Replace );
987void SAL_CALL UIConfigurationManager::removeSettings(
const OUString& ResourceURL )
989 sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL );
991 if (( nElementType == css::ui::UIElementType::UNKNOWN ) ||
992 ( nElementType >= css::ui::UIElementType::COUNT ))
993 throw IllegalArgumentException(
"The ResourceURL is not valid or "
994 "describes an unknown type. "
995 "ResourceURL: " + ResourceURL,
nullptr, 0 );
996 else if ( m_bReadOnly )
997 throw IllegalAccessException(
"The configuration manager is read-only. "
998 "ResourceURL: " + ResourceURL,
nullptr );
1004 throw DisposedException(
"The configuration manager has been disposed, "
1005 "and can't uphold its method specification anymore. "
1006 "ResourceURL: " + ResourceURL,
nullptr );
1008 UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType );
1009 if ( !pDataSettings )
1010 throw NoSuchElementException(
"The settings data cannot be found. "
1011 "ResourceURL: " + ResourceURL,
nullptr);
1013 if ( pDataSettings->bDefault )
1018 pDataSettings->bDefault =
true;
1021 pDataSettings->bModified =
true;
1022 pDataSettings->xSettings.clear();
1026 UIElementType& rElementType = m_aUIElements[nElementType];
1027 rElementType.bModified =
true;
1033 ConfigurationEvent
aEvent;
1035 aEvent.ResourceURL = ResourceURL;
1036 aEvent.Accessor <<= xThis;
1038 aEvent.Element <<= xRemovedSettings;
1042 implts_notifyContainerListener( aEvent, NotifyOp_Remove );
1047void SAL_CALL UIConfigurationManager::insertSettings(
const OUString& NewResourceURL,
const Reference< XIndexAccess >& aNewData )
1049 sal_Int16 nElementType = RetrieveTypeFromResourceURL( NewResourceURL );
1051 if (( nElementType == css::ui::UIElementType::UNKNOWN ) ||
1052 ( nElementType >= css::ui::UIElementType::COUNT ))
1053 throw IllegalArgumentException();
1054 else if ( m_bReadOnly )
1055 throw IllegalAccessException();
1061 throw DisposedException();
1063 bool bInsertData(
false );
1064 UIElementData aUIElementData;
1065 UIElementData* pDataSettings = impl_findUIElementData( NewResourceURL, nElementType );
1067 if ( pDataSettings && !pDataSettings->bDefault )
1068 throw ElementExistException();
1070 if ( !pDataSettings )
1072 pDataSettings = &aUIElementData;
1077 pDataSettings->bDefault =
false;
1078 pDataSettings->bModified =
true;
1082 if ( xReplace.is() )
1085 pDataSettings->xSettings = aNewData;
1089 UIElementType& rElementType = m_aUIElements[nElementType];
1090 rElementType.bModified =
true;
1094 pDataSettings->aName = RetrieveNameFromResourceURL( NewResourceURL ) +
".xml";
1095 pDataSettings->aResourceURL = NewResourceURL;
1097 UIElementDataHashMap& rElements = rElementType.aElementsHashMap;
1098 rElements.emplace( NewResourceURL, *pDataSettings );
1106 ConfigurationEvent
aEvent;
1108 aEvent.ResourceURL = NewResourceURL;
1109 aEvent.Accessor <<= xThis;
1111 aEvent.Element <<= xInsertSettings;
1115 implts_notifyContainerListener( aEvent, NotifyOp_Insert );
1123 throw DisposedException();
1125 if ( !m_xImageManager.is() )
1131 {
"UserConfigStorage",
Any(m_xDocConfigStorage)},
1132 {
"ModuleIdentifier",
Any(OUString())},
1135 m_xImageManager->initialize( aPropSeq );
1143 return DocumentAcceleratorConfiguration::createWithDocumentRoot(
m_xContext, m_xDocConfigStorage);
1151 if (!m_xAccConfig.is())
try
1153 m_xAccConfig = DocumentAcceleratorConfiguration::
1154 createWithDocumentRoot(
m_xContext, m_xDocConfigStorage);
1156 catch (
const css::uno::DeploymentException& )
1158 SAL_WARN(
"fwk.uiconfiguration",
"DocumentAcceleratorConfiguration"
1159 " not available. This should happen only on mobile platforms.");
1162 return m_xAccConfig;
1176 throw DisposedException();
1178 if ( m_xDocConfigStorage.is() )
1183 m_xDocConfigStorage->dispose();
1185 catch (
const Exception& )
1191 m_xDocConfigStorage =
Storage;
1194 if ( m_xAccConfig.is() )
1195 m_xAccConfig->setStorage( m_xDocConfigStorage );
1197 if ( m_xImageManager )
1198 m_xImageManager->setStorage( m_xDocConfigStorage );
1200 if ( m_xDocConfigStorage.is() )
1203 if ( xPropSet.is() )
1208 Any a = xPropSet->getPropertyValue(
"OpenMode");
1209 if ( a >>= nOpenMode )
1210 m_bReadOnly = !( nOpenMode & ElementModes::WRITE );
1212 catch (
const css::beans::UnknownPropertyException& )
1215 catch (
const css::lang::WrappedTargetException& )
1224sal_Bool SAL_CALL UIConfigurationManager::hasStorage()
1229 throw DisposedException();
1231 return m_xDocConfigStorage.is();
1235void SAL_CALL UIConfigurationManager::reload()
1240 throw DisposedException();
1242 if ( !m_xDocConfigStorage.is() || !m_bModified || m_bReadOnly )
1246 ConfigEventNotifyContainer aRemoveNotifyContainer;
1247 ConfigEventNotifyContainer aReplaceNotifyContainer;
1248 for ( sal_Int16 i = 1;
i < css::ui::UIElementType::COUNT;
i++ )
1252 UIElementType& rDocElementType = m_aUIElements[
i];
1253 if ( rDocElementType.bModified )
1254 impl_reloadElementTypeData( rDocElementType, aRemoveNotifyContainer, aReplaceNotifyContainer );
1256 catch (
const Exception& )
1262 m_bModified =
false;
1268 for (
const ConfigurationEvent & j : aRemoveNotifyContainer)
1269 implts_notifyContainerListener( j, NotifyOp_Remove );
1270 for (
const ConfigurationEvent & k : aReplaceNotifyContainer)
1271 implts_notifyContainerListener( k, NotifyOp_Replace );
1274void SAL_CALL UIConfigurationManager::store()
1279 throw DisposedException();
1281 if ( !m_xDocConfigStorage.is() || !m_bModified || m_bReadOnly )
1285 for (
int i = 1;
i < css::ui::UIElementType::COUNT;
i++ )
1289 UIElementType& rElementType = m_aUIElements[
i];
1291 if ( rElementType.bModified && rElementType.xStorage.is() )
1292 impl_storeElementTypeData( rElementType.xStorage, rElementType );
1294 catch (
const Exception& )
1300 m_bModified =
false;
1302 if ( xTransactedObject.is() )
1303 xTransactedObject->commit();
1311 throw DisposedException();
1313 if ( !m_xDocConfigStorage.is() || !m_bModified || m_bReadOnly )
1317 for (
int i = 1;
i < css::ui::UIElementType::COUNT;
i++ )
1322 OUString(UIELEMENTTYPENAMES[i]), ElementModes::READWRITE ));
1323 UIElementType& rElementType = m_aUIElements[
i];
1325 if ( rElementType.bModified && xElementTypeStorage.is() )
1326 impl_storeElementTypeData( xElementTypeStorage, rElementType,
false );
1328 catch (
const Exception& )
1335 if ( xTransactedObject.is() )
1336 xTransactedObject->commit();
1339sal_Bool SAL_CALL UIConfigurationManager::isModified()
1346sal_Bool SAL_CALL UIConfigurationManager::isReadOnly()
1353void UIConfigurationManager::implts_notifyContainerListener(
const ConfigurationEvent& aEvent, NotifyOp eOp )
1355 std::unique_lock aGuard(
m_mutex);
1356 m_aConfigListeners.forEach(aGuard, [&eOp, &aEvent](
const css::uno::Reference<XUIConfigurationListener>& l) {
1359 case NotifyOp_Replace:
1360 l->elementReplaced( aEvent );
1362 case NotifyOp_Insert:
1363 l->elementInserted( aEvent );
1365 case NotifyOp_Remove:
1366 l->elementRemoved( aEvent );
1374extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
1376 css::uno::XComponentContext *context,
1377 css::uno::Sequence<css::uno::Any>
const &)
1379 return cppu::acquire(
new UIConfigurationManager(context));
css::uno::Reference< css::uno::XComponentContext > m_xContext
#define SAL_WARN(area, stream)
css::uno::Sequence< css::uno::Any > InitAnyPropertySequence(::std::initializer_list< ::std::pair< OUString, css::uno::Any > > vInit)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
css::uno::Sequence< OUString > getSupportedServiceNames()
OUString getImplementationName()
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
bool equalsIgnoreAsciiCase(std::u16string_view s1, std::u16string_view s2)
constexpr bool starts_with(std::basic_string_view< charT, traits > sv, std::basic_string_view< charT, traits > x) noexcept
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_framework_UIConfigurationManager_get_implementation(css::uno::XComponentContext *context, css::uno::Sequence< css::uno::Any > const &)
#define UIELEMENTTYPE_POPUPMENU_NAME
#define UIELEMENTTYPE_PROGRESSBAR_NAME
#define UIELEMENTTYPE_TOOLBAR_NAME
#define UIELEMENTTYPE_STATUSBAR_NAME
#define UIELEMENTTYPE_MENUBAR_NAME
#define UIELEMENTTYPE_TOOLPANEL_NAME
#define UIELEMENTTYPE_FLOATINGWINDOW_NAME