1*6d739b60SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*6d739b60SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*6d739b60SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*6d739b60SAndrew Rist * distributed with this work for additional information 6*6d739b60SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*6d739b60SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*6d739b60SAndrew Rist * "License"); you may not use this file except in compliance 9*6d739b60SAndrew Rist * with the License. You may obtain a copy of the License at 10cdf0e10cSrcweir * 11*6d739b60SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12cdf0e10cSrcweir * 13*6d739b60SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*6d739b60SAndrew Rist * software distributed under the License is distributed on an 15*6d739b60SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*6d739b60SAndrew Rist * KIND, either express or implied. See the License for the 17*6d739b60SAndrew Rist * specific language governing permissions and limitations 18*6d739b60SAndrew Rist * under the License. 19cdf0e10cSrcweir * 20*6d739b60SAndrew Rist *************************************************************/ 21*6d739b60SAndrew Rist 22*6d739b60SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_framework.hxx" 26cdf0e10cSrcweir #include <uiconfiguration/moduleuiconfigurationmanager.hxx> 27cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 28cdf0e10cSrcweir #include <services.h> 29cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx> 30cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx> 31cdf0e10cSrcweir #include <uielement/uielementtypenames.hxx> 32cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 33cdf0e10cSrcweir #include <framework/toolboxconfiguration.hxx> 34cdf0e10cSrcweir 35cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_STATUSBARCONFIGURATION_HXX_ 36cdf0e10cSrcweir #include <framework/statusbarconfiguration.hxx> 37cdf0e10cSrcweir #endif 38cdf0e10cSrcweir 39cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40cdf0e10cSrcweir // interface includes 41cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 43cdf0e10cSrcweir #include <com/sun/star/ui/ConfigurationEvent.hpp> 44cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 45cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 46cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 47cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 48cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 49cdf0e10cSrcweir 50cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 51cdf0e10cSrcweir // other includes 52cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 53cdf0e10cSrcweir 54cdf0e10cSrcweir #include <vcl/svapp.hxx> 55cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 56cdf0e10cSrcweir #include <comphelper/sequenceashashmap.hxx> 57cdf0e10cSrcweir 58cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59cdf0e10cSrcweir // namespaces 60cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 61cdf0e10cSrcweir 62cdf0e10cSrcweir using rtl::OUString; 63cdf0e10cSrcweir using namespace com::sun::star::uno; 64cdf0e10cSrcweir using namespace com::sun::star::io; 65cdf0e10cSrcweir using namespace com::sun::star::embed; 66cdf0e10cSrcweir using namespace com::sun::star::lang; 67cdf0e10cSrcweir using namespace com::sun::star::container; 68cdf0e10cSrcweir using namespace com::sun::star::beans; 69cdf0e10cSrcweir using namespace ::com::sun::star::ui; 70cdf0e10cSrcweir 71cdf0e10cSrcweir namespace framework 72cdf0e10cSrcweir { 73cdf0e10cSrcweir 74cdf0e10cSrcweir //***************************************************************************************************************** 75cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 76cdf0e10cSrcweir //***************************************************************************************************************** 77cdf0e10cSrcweir DEFINE_XINTERFACE_8 ( ModuleUIConfigurationManager , 78cdf0e10cSrcweir OWeakObject , 79cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XTypeProvider ), 80cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XServiceInfo ), 81cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XComponent ), 82cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XInitialization ), 83cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfiguration ), 84cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationManager ), 85cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XModuleUIConfigurationManager ), 86cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationPersistence ) 87cdf0e10cSrcweir ) 88cdf0e10cSrcweir 89cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_8 ( ModuleUIConfigurationManager , 90cdf0e10cSrcweir css::lang::XTypeProvider , 91cdf0e10cSrcweir css::lang::XServiceInfo , 92cdf0e10cSrcweir css::lang::XComponent , 93cdf0e10cSrcweir css::lang::XInitialization , 94cdf0e10cSrcweir ::com::sun::star::ui::XUIConfiguration , 95cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationManager , 96cdf0e10cSrcweir ::com::sun::star::ui::XModuleUIConfigurationManager , 97cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationPersistence 98cdf0e10cSrcweir ) 99cdf0e10cSrcweir 100cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( ModuleUIConfigurationManager , 101cdf0e10cSrcweir ::cppu::OWeakObject , 102cdf0e10cSrcweir SERVICENAME_MODULEUICONFIGURATIONMANAGER , 103cdf0e10cSrcweir IMPLEMENTATIONNAME_MODULEUICONFIGURATIONMANAGER 104cdf0e10cSrcweir ) 105cdf0e10cSrcweir 106cdf0e10cSrcweir DEFINE_INIT_SERVICE ( ModuleUIConfigurationManager, {} ) 107cdf0e10cSrcweir 108cdf0e10cSrcweir 109cdf0e10cSrcweir // important: The order and position of the elements must match the constant 110cdf0e10cSrcweir // definition of "::com::sun::star::ui::UIElementType" 111cdf0e10cSrcweir static const char* UIELEMENTTYPENAMES[] = 112cdf0e10cSrcweir { 113cdf0e10cSrcweir "", // Dummy value for unknown! 114cdf0e10cSrcweir UIELEMENTTYPE_MENUBAR_NAME, 115cdf0e10cSrcweir UIELEMENTTYPE_POPUPMENU_NAME, 116cdf0e10cSrcweir UIELEMENTTYPE_TOOLBAR_NAME, 117cdf0e10cSrcweir UIELEMENTTYPE_STATUSBAR_NAME, 118cdf0e10cSrcweir UIELEMENTTYPE_FLOATINGWINDOW_NAME, 119cdf0e10cSrcweir UIELEMENTTYPE_PROGRESSBAR_NAME, 120cdf0e10cSrcweir UIELEMENTTYPE_TOOLPANEL_NAME 121cdf0e10cSrcweir }; 122cdf0e10cSrcweir 123cdf0e10cSrcweir static const char RESOURCEURL_PREFIX[] = "private:resource/"; 124cdf0e10cSrcweir static const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17; 125cdf0e10cSrcweir static const char RESOURCEURL_CUSTOM_ELEMENT[] = "custom_"; 126cdf0e10cSrcweir 127cdf0e10cSrcweir static sal_Int16 RetrieveTypeFromResourceURL( const rtl::OUString& aResourceURL ) 128cdf0e10cSrcweir { 129cdf0e10cSrcweir 130cdf0e10cSrcweir if (( aResourceURL.indexOf( OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) && 131cdf0e10cSrcweir ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir OUString aTmpStr = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ); 134cdf0e10cSrcweir sal_Int32 nIndex = aTmpStr.indexOf( '/' ); 135cdf0e10cSrcweir if (( nIndex > 0 ) && ( aTmpStr.getLength() > nIndex )) 136cdf0e10cSrcweir { 137cdf0e10cSrcweir OUString aTypeStr( aTmpStr.copy( 0, nIndex )); 138cdf0e10cSrcweir for ( int i = 0; i < UIElementType::COUNT; i++ ) 139cdf0e10cSrcweir { 140cdf0e10cSrcweir if ( aTypeStr.equalsAscii( UIELEMENTTYPENAMES[i] )) 141cdf0e10cSrcweir return sal_Int16( i ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir } 144cdf0e10cSrcweir } 145cdf0e10cSrcweir 146cdf0e10cSrcweir return UIElementType::UNKNOWN; 147cdf0e10cSrcweir } 148cdf0e10cSrcweir 149cdf0e10cSrcweir static OUString RetrieveNameFromResourceURL( const rtl::OUString& aResourceURL ) 150cdf0e10cSrcweir { 151cdf0e10cSrcweir if (( aResourceURL.indexOf( OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) && 152cdf0e10cSrcweir ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) 153cdf0e10cSrcweir { 154cdf0e10cSrcweir sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' ); 155cdf0e10cSrcweir if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength())) 156cdf0e10cSrcweir return aResourceURL.copy( nIndex+1 ); 157cdf0e10cSrcweir } 158cdf0e10cSrcweir 159cdf0e10cSrcweir return OUString(); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType ) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir // preload list of element types on demand 165cdf0e10cSrcweir impl_preloadUIElementTypeList( LAYER_USERDEFINED, nElementType ); 166cdf0e10cSrcweir impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); 167cdf0e10cSrcweir 168cdf0e10cSrcweir UIElementDataHashMap& rUserElements = m_aUIElements[LAYER_USERDEFINED][nElementType].aElementsHashMap; 169cdf0e10cSrcweir UIElementDataHashMap::const_iterator pUserIter = rUserElements.begin(); 170cdf0e10cSrcweir 171cdf0e10cSrcweir OUString aCustomUrlPrefix( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_CUSTOM_ELEMENT )); 172cdf0e10cSrcweir while ( pUserIter != rUserElements.end() ) 173cdf0e10cSrcweir { 174cdf0e10cSrcweir sal_Int32 nIndex = pUserIter->second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE ); 175cdf0e10cSrcweir if ( nIndex > RESOURCEURL_PREFIX_SIZE ) 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // Performance: Retrieve user interface name only for custom user interface elements. 178cdf0e10cSrcweir // It's only used by them! 179cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( pUserIter->second.aResourceURL, nElementType ); 180cdf0e10cSrcweir if ( pDataSettings ) 181cdf0e10cSrcweir { 182cdf0e10cSrcweir // Retrieve user interface name from XPropertySet interface 183cdf0e10cSrcweir rtl::OUString aUIName; 184cdf0e10cSrcweir Reference< XPropertySet > xPropSet( pDataSettings->xSettings, UNO_QUERY ); 185cdf0e10cSrcweir if ( xPropSet.is() ) 186cdf0e10cSrcweir { 187cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( m_aPropUIName ); 188cdf0e10cSrcweir a >>= aUIName; 189cdf0e10cSrcweir } 190cdf0e10cSrcweir 191cdf0e10cSrcweir UIElementInfo aInfo( pUserIter->second.aResourceURL, aUIName ); 192cdf0e10cSrcweir aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pUserIter->second.aResourceURL, aInfo )); 193cdf0e10cSrcweir } 194cdf0e10cSrcweir } 195cdf0e10cSrcweir else 196cdf0e10cSrcweir { 197cdf0e10cSrcweir // The user interface name for standard user interface elements is stored in the WindowState.xcu file 198cdf0e10cSrcweir UIElementInfo aInfo( pUserIter->second.aResourceURL, OUString() ); 199cdf0e10cSrcweir aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pUserIter->second.aResourceURL, aInfo )); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir ++pUserIter; 202cdf0e10cSrcweir } 203cdf0e10cSrcweir 204cdf0e10cSrcweir UIElementDataHashMap& rDefaultElements = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; 205cdf0e10cSrcweir UIElementDataHashMap::const_iterator pDefIter = rDefaultElements.begin(); 206cdf0e10cSrcweir 207cdf0e10cSrcweir while ( pDefIter != rDefaultElements.end() ) 208cdf0e10cSrcweir { 209cdf0e10cSrcweir UIElementInfoHashMap::const_iterator pIterInfo = aUIElementInfoCollection.find( pDefIter->second.aResourceURL ); 210cdf0e10cSrcweir if ( pIterInfo == aUIElementInfoCollection.end() ) 211cdf0e10cSrcweir { 212cdf0e10cSrcweir sal_Int32 nIndex = pDefIter->second.aResourceURL.indexOf( aCustomUrlPrefix, RESOURCEURL_PREFIX_SIZE ); 213cdf0e10cSrcweir if ( nIndex > RESOURCEURL_PREFIX_SIZE ) 214cdf0e10cSrcweir { 215cdf0e10cSrcweir // Performance: Retrieve user interface name only for custom user interface elements. 216cdf0e10cSrcweir // It's only used by them! 217cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( pDefIter->second.aResourceURL, nElementType ); 218cdf0e10cSrcweir if ( pDataSettings ) 219cdf0e10cSrcweir { 220cdf0e10cSrcweir // Retrieve user interface name from XPropertySet interface 221cdf0e10cSrcweir rtl::OUString aUIName; 222cdf0e10cSrcweir Reference< XPropertySet > xPropSet( pDataSettings->xSettings, UNO_QUERY ); 223cdf0e10cSrcweir if ( xPropSet.is() ) 224cdf0e10cSrcweir { 225cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( m_aPropUIName ); 226cdf0e10cSrcweir a >>= aUIName; 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir UIElementInfo aInfo( pDefIter->second.aResourceURL, aUIName ); 230cdf0e10cSrcweir aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pDefIter->second.aResourceURL, aInfo )); 231cdf0e10cSrcweir } 232cdf0e10cSrcweir } 233cdf0e10cSrcweir else 234cdf0e10cSrcweir { 235cdf0e10cSrcweir // The user interface name for standard user interface elements is stored in the WindowState.xcu file 236cdf0e10cSrcweir UIElementInfo aInfo( pDefIter->second.aResourceURL, OUString() ); 237cdf0e10cSrcweir aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pDefIter->second.aResourceURL, aInfo )); 238cdf0e10cSrcweir } 239cdf0e10cSrcweir } 240cdf0e10cSrcweir 241cdf0e10cSrcweir ++pDefIter; 242cdf0e10cSrcweir } 243cdf0e10cSrcweir } 244cdf0e10cSrcweir 245cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_preloadUIElementTypeList( Layer eLayer, sal_Int16 nElementType ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir UIElementType& rElementTypeData = m_aUIElements[eLayer][nElementType]; 248cdf0e10cSrcweir 249cdf0e10cSrcweir if ( !rElementTypeData.bLoaded ) 250cdf0e10cSrcweir { 251cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage; 252cdf0e10cSrcweir if ( xElementTypeStorage.is() ) 253cdf0e10cSrcweir { 254cdf0e10cSrcweir rtl::OUStringBuffer aBuf( RESOURCEURL_PREFIX_SIZE ); 255cdf0e10cSrcweir aBuf.appendAscii( RESOURCEURL_PREFIX ); 256cdf0e10cSrcweir aBuf.appendAscii( UIELEMENTTYPENAMES[ nElementType ] ); 257cdf0e10cSrcweir aBuf.appendAscii( "/" ); 258cdf0e10cSrcweir OUString aResURLPrefix( aBuf.makeStringAndClear() ); 259cdf0e10cSrcweir 260cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rElementTypeData.aElementsHashMap; 261cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( xElementTypeStorage, UNO_QUERY ); 262cdf0e10cSrcweir Sequence< OUString > aUIElementNames = xNameAccess->getElementNames(); 263cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aUIElementNames.getLength(); n++ ) 264cdf0e10cSrcweir { 265cdf0e10cSrcweir UIElementData aUIElementData; 266cdf0e10cSrcweir 267cdf0e10cSrcweir // Resource name must be without ".xml" 268cdf0e10cSrcweir sal_Int32 nIndex = aUIElementNames[n].lastIndexOf( '.' ); 269cdf0e10cSrcweir if (( nIndex > 0 ) && ( nIndex < aUIElementNames[n].getLength() )) 270cdf0e10cSrcweir { 271cdf0e10cSrcweir OUString aExtension( aUIElementNames[n].copy( nIndex+1 )); 272cdf0e10cSrcweir OUString aUIElementName( aUIElementNames[n].copy( 0, nIndex )); 273cdf0e10cSrcweir 274cdf0e10cSrcweir if (( aUIElementName.getLength() > 0 ) && 275cdf0e10cSrcweir ( aExtension.equalsIgnoreAsciiCaseAsciiL( "xml", 3 ))) 276cdf0e10cSrcweir { 277cdf0e10cSrcweir aUIElementData.aResourceURL = aResURLPrefix + aUIElementName; 278cdf0e10cSrcweir aUIElementData.aName = aUIElementNames[n]; 279cdf0e10cSrcweir 280cdf0e10cSrcweir if ( eLayer == LAYER_USERDEFINED ) 281cdf0e10cSrcweir { 282cdf0e10cSrcweir aUIElementData.bModified = false; 283cdf0e10cSrcweir aUIElementData.bDefault = false; 284cdf0e10cSrcweir aUIElementData.bDefaultNode = false; 285cdf0e10cSrcweir } 286cdf0e10cSrcweir 287cdf0e10cSrcweir // Create hash_map entries for all user interface elements inside the storage. We don't load the 288cdf0e10cSrcweir // settings to speed up the process. 289cdf0e10cSrcweir rHashMap.insert( UIElementDataHashMap::value_type( aUIElementData.aResourceURL, aUIElementData )); 290cdf0e10cSrcweir } 291cdf0e10cSrcweir } 292cdf0e10cSrcweir rElementTypeData.bLoaded = true; 293cdf0e10cSrcweir } 294cdf0e10cSrcweir } 295cdf0e10cSrcweir } 296cdf0e10cSrcweir 297cdf0e10cSrcweir //rElementTypeData.bLoaded = true; 298cdf0e10cSrcweir } 299cdf0e10cSrcweir 300cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType, Layer eLayer, UIElementData& aUIElementData ) 301cdf0e10cSrcweir { 302cdf0e10cSrcweir UIElementType& rElementTypeData = m_aUIElements[eLayer][nElementType]; 303cdf0e10cSrcweir 304cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage; 305cdf0e10cSrcweir if ( xElementTypeStorage.is() && aUIElementData.aName.getLength() ) 306cdf0e10cSrcweir { 307cdf0e10cSrcweir try 308cdf0e10cSrcweir { 309cdf0e10cSrcweir Reference< XStream > xStream = xElementTypeStorage->openStreamElement( aUIElementData.aName, ElementModes::READ ); 310cdf0e10cSrcweir Reference< XInputStream > xInputStream = xStream->getInputStream(); 311cdf0e10cSrcweir 312cdf0e10cSrcweir if ( xInputStream.is() ) 313cdf0e10cSrcweir { 314cdf0e10cSrcweir switch ( nElementType ) 315cdf0e10cSrcweir { 316cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::UNKNOWN: 317cdf0e10cSrcweir break; 318cdf0e10cSrcweir 319cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::MENUBAR: 320cdf0e10cSrcweir { 321cdf0e10cSrcweir try 322cdf0e10cSrcweir { 323cdf0e10cSrcweir MenuConfiguration aMenuCfg( m_xServiceManager ); 324cdf0e10cSrcweir Reference< XIndexAccess > xContainer( aMenuCfg.CreateMenuBarConfigurationFromXML( xInputStream )); 325cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xContainer ); 326cdf0e10cSrcweir if ( pRootItemContainer ) 327cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 328cdf0e10cSrcweir else 329cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( xContainer, sal_True ) ), UNO_QUERY ); 330cdf0e10cSrcweir return; 331cdf0e10cSrcweir } 332cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 333cdf0e10cSrcweir { 334cdf0e10cSrcweir } 335cdf0e10cSrcweir } 336cdf0e10cSrcweir break; 337cdf0e10cSrcweir 338cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::POPUPMENU: 339cdf0e10cSrcweir { 340cdf0e10cSrcweir break; 341cdf0e10cSrcweir } 342cdf0e10cSrcweir 343cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::TOOLBAR: 344cdf0e10cSrcweir { 345cdf0e10cSrcweir try 346cdf0e10cSrcweir { 347cdf0e10cSrcweir Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY ); 348cdf0e10cSrcweir ToolBoxConfiguration::LoadToolBox( m_xServiceManager, xInputStream, xIndexContainer ); 349cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer ); 350cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 351cdf0e10cSrcweir return; 352cdf0e10cSrcweir } 353cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 354cdf0e10cSrcweir { 355cdf0e10cSrcweir } 356cdf0e10cSrcweir 357cdf0e10cSrcweir break; 358cdf0e10cSrcweir } 359cdf0e10cSrcweir 360cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::STATUSBAR: 361cdf0e10cSrcweir { 362cdf0e10cSrcweir try 363cdf0e10cSrcweir { 364cdf0e10cSrcweir Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY ); 365cdf0e10cSrcweir StatusBarConfiguration::LoadStatusBar( m_xServiceManager, xInputStream, xIndexContainer ); 366cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer ); 367cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 368cdf0e10cSrcweir return; 369cdf0e10cSrcweir } 370cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 371cdf0e10cSrcweir { 372cdf0e10cSrcweir } 373cdf0e10cSrcweir 374cdf0e10cSrcweir break; 375cdf0e10cSrcweir } 376cdf0e10cSrcweir 377cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::FLOATINGWINDOW: 378cdf0e10cSrcweir { 379cdf0e10cSrcweir break; 380cdf0e10cSrcweir } 381cdf0e10cSrcweir } 382cdf0e10cSrcweir } 383cdf0e10cSrcweir } 384cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 385cdf0e10cSrcweir { 386cdf0e10cSrcweir } 387cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 388cdf0e10cSrcweir { 389cdf0e10cSrcweir } 390cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& ) 391cdf0e10cSrcweir { 392cdf0e10cSrcweir } 393cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir } 396cdf0e10cSrcweir } 397cdf0e10cSrcweir 398cdf0e10cSrcweir // At least we provide an empty settings container! 399cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer() ), UNO_QUERY ); 400cdf0e10cSrcweir } 401cdf0e10cSrcweir 402cdf0e10cSrcweir ModuleUIConfigurationManager::UIElementData* ModuleUIConfigurationManager::impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad ) 403cdf0e10cSrcweir { 404cdf0e10cSrcweir // preload list of element types on demand 405cdf0e10cSrcweir impl_preloadUIElementTypeList( LAYER_USERDEFINED, nElementType ); 406cdf0e10cSrcweir impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); 407cdf0e10cSrcweir 408cdf0e10cSrcweir // first try to look into our user-defined vector/hash_map combination 409cdf0e10cSrcweir UIElementDataHashMap& rUserHashMap = m_aUIElements[LAYER_USERDEFINED][nElementType].aElementsHashMap; 410cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rUserHashMap.find( aResourceURL ); 411cdf0e10cSrcweir if ( pIter != rUserHashMap.end() ) 412cdf0e10cSrcweir { 413cdf0e10cSrcweir // Default data settings data must be retrieved from the default layer! 414cdf0e10cSrcweir if ( !pIter->second.bDefault ) 415cdf0e10cSrcweir { 416cdf0e10cSrcweir if ( !pIter->second.xSettings.is() && bLoad ) 417cdf0e10cSrcweir impl_requestUIElementData( nElementType, LAYER_USERDEFINED, pIter->second ); 418cdf0e10cSrcweir return &(pIter->second); 419cdf0e10cSrcweir } 420cdf0e10cSrcweir } 421cdf0e10cSrcweir 422cdf0e10cSrcweir // Not successfull, we have to look into our default vector/hash_map combination 423cdf0e10cSrcweir UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; 424cdf0e10cSrcweir pIter = rDefaultHashMap.find( aResourceURL ); 425cdf0e10cSrcweir if ( pIter != rDefaultHashMap.end() ) 426cdf0e10cSrcweir { 427cdf0e10cSrcweir if ( !pIter->second.xSettings.is() && bLoad ) 428cdf0e10cSrcweir impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); 429cdf0e10cSrcweir return &(pIter->second); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir 432cdf0e10cSrcweir // Nothing has been found! 433cdf0e10cSrcweir return NULL; 434cdf0e10cSrcweir } 435cdf0e10cSrcweir 436cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_storeElementTypeData( Reference< XStorage > xStorage, UIElementType& rElementType, bool bResetModifyState ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rElementType.aElementsHashMap; 439cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 440cdf0e10cSrcweir 441cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 442cdf0e10cSrcweir { 443cdf0e10cSrcweir UIElementData& rElement = pIter->second; 444cdf0e10cSrcweir if ( rElement.bModified ) 445cdf0e10cSrcweir { 446cdf0e10cSrcweir if ( rElement.bDefault ) 447cdf0e10cSrcweir { 448cdf0e10cSrcweir xStorage->removeElement( rElement.aName ); 449cdf0e10cSrcweir rElement.bModified = sal_False; // mark as not modified 450cdf0e10cSrcweir } 451cdf0e10cSrcweir else 452cdf0e10cSrcweir { 453cdf0e10cSrcweir Reference< XStream > xStream( xStorage->openStreamElement( rElement.aName, ElementModes::WRITE|ElementModes::TRUNCATE ), UNO_QUERY ); 454cdf0e10cSrcweir Reference< XOutputStream > xOutputStream( xStream->getOutputStream() ); 455cdf0e10cSrcweir 456cdf0e10cSrcweir if ( xOutputStream.is() ) 457cdf0e10cSrcweir { 458cdf0e10cSrcweir switch( rElementType.nElementType ) 459cdf0e10cSrcweir { 460cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::MENUBAR: 461cdf0e10cSrcweir { 462cdf0e10cSrcweir try 463cdf0e10cSrcweir { 464cdf0e10cSrcweir MenuConfiguration aMenuCfg( m_xServiceManager ); 465cdf0e10cSrcweir aMenuCfg.StoreMenuBarConfigurationToXML( rElement.xSettings, xOutputStream ); 466cdf0e10cSrcweir } 467cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 468cdf0e10cSrcweir { 469cdf0e10cSrcweir } 470cdf0e10cSrcweir } 471cdf0e10cSrcweir break; 472cdf0e10cSrcweir 473cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::TOOLBAR: 474cdf0e10cSrcweir { 475cdf0e10cSrcweir try 476cdf0e10cSrcweir { 477cdf0e10cSrcweir ToolBoxConfiguration::StoreToolBox( m_xServiceManager, xOutputStream, rElement.xSettings ); 478cdf0e10cSrcweir } 479cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 480cdf0e10cSrcweir { 481cdf0e10cSrcweir } 482cdf0e10cSrcweir } 483cdf0e10cSrcweir break; 484cdf0e10cSrcweir 485cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::STATUSBAR: 486cdf0e10cSrcweir { 487cdf0e10cSrcweir try 488cdf0e10cSrcweir { 489cdf0e10cSrcweir StatusBarConfiguration::StoreStatusBar( m_xServiceManager, xOutputStream, rElement.xSettings ); 490cdf0e10cSrcweir } 491cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 492cdf0e10cSrcweir { 493cdf0e10cSrcweir } 494cdf0e10cSrcweir } 495cdf0e10cSrcweir break; 496cdf0e10cSrcweir 497cdf0e10cSrcweir default: 498cdf0e10cSrcweir break; 499cdf0e10cSrcweir } 500cdf0e10cSrcweir } 501cdf0e10cSrcweir 502cdf0e10cSrcweir // mark as not modified if we store to our own storage 503cdf0e10cSrcweir if ( bResetModifyState ) 504cdf0e10cSrcweir rElement.bModified = sal_False; 505cdf0e10cSrcweir } 506cdf0e10cSrcweir } 507cdf0e10cSrcweir 508cdf0e10cSrcweir ++pIter; 509cdf0e10cSrcweir } 510cdf0e10cSrcweir 511cdf0e10cSrcweir // commit element type storage 512cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( xStorage, UNO_QUERY ); 513cdf0e10cSrcweir if ( xTransactedObject.is() ) 514cdf0e10cSrcweir xTransactedObject->commit(); 515cdf0e10cSrcweir 516cdf0e10cSrcweir // mark UIElementType as not modified if we store to our own storage 517cdf0e10cSrcweir if ( bResetModifyState ) 518cdf0e10cSrcweir rElementType.bModified = sal_False; 519cdf0e10cSrcweir } 520cdf0e10cSrcweir 521cdf0e10cSrcweir // This is only allowed to be called on the LAYER_USER_DEFINED! 522cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_resetElementTypeData( 523cdf0e10cSrcweir UIElementType& rUserElementType, 524cdf0e10cSrcweir UIElementType& rDefaultElementType, 525cdf0e10cSrcweir ConfigEventNotifyContainer& rRemoveNotifyContainer, 526cdf0e10cSrcweir ConfigEventNotifyContainer& rReplaceNotifyContainer ) 527cdf0e10cSrcweir { 528cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rUserElementType.aElementsHashMap; 529cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 530cdf0e10cSrcweir 531cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 532cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 533cdf0e10cSrcweir Reference< XNameAccess > xDefaultNameAccess( rDefaultElementType.xStorage, UNO_QUERY ); 534cdf0e10cSrcweir sal_Int16 nType = rUserElementType.nElementType; 535cdf0e10cSrcweir 536cdf0e10cSrcweir // Make copies of the event structures to be thread-safe. We have to unlock our mutex before calling 537cdf0e10cSrcweir // our listeners! 538cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 539cdf0e10cSrcweir { 540cdf0e10cSrcweir UIElementData& rElement = pIter->second; 541cdf0e10cSrcweir if ( !rElement.bDefault ) 542cdf0e10cSrcweir { 543cdf0e10cSrcweir if ( xDefaultNameAccess->hasByName( rElement.aName )) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir // Replace settings with data from default layer 546cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings( rElement.xSettings ); 547cdf0e10cSrcweir impl_requestUIElementData( nType, LAYER_DEFAULT, rElement ); 548cdf0e10cSrcweir 549cdf0e10cSrcweir ConfigurationEvent aReplaceEvent; 550cdf0e10cSrcweir aReplaceEvent.ResourceURL = rElement.aResourceURL; 551cdf0e10cSrcweir aReplaceEvent.Accessor <<= xThis; 552cdf0e10cSrcweir aReplaceEvent.Source = xIfac; 553cdf0e10cSrcweir aReplaceEvent.ReplacedElement <<= xOldSettings; 554cdf0e10cSrcweir aReplaceEvent.Element <<= rElement.xSettings; 555cdf0e10cSrcweir 556cdf0e10cSrcweir rReplaceNotifyContainer.push_back( aReplaceEvent ); 557cdf0e10cSrcweir 558cdf0e10cSrcweir // Mark element as default and not modified. That means "not active" 559cdf0e10cSrcweir // in the user layer anymore. 560cdf0e10cSrcweir rElement.bModified = false; 561cdf0e10cSrcweir rElement.bDefault = true; 562cdf0e10cSrcweir } 563cdf0e10cSrcweir else 564cdf0e10cSrcweir { 565cdf0e10cSrcweir // Remove user-defined settings from user layer 566cdf0e10cSrcweir ConfigurationEvent aEvent; 567cdf0e10cSrcweir aEvent.ResourceURL = rElement.aResourceURL; 568cdf0e10cSrcweir aEvent.Accessor <<= xThis; 569cdf0e10cSrcweir aEvent.Source = xIfac; 570cdf0e10cSrcweir aEvent.Element <<= rElement.xSettings; 571cdf0e10cSrcweir 572cdf0e10cSrcweir rRemoveNotifyContainer.push_back( aEvent ); 573cdf0e10cSrcweir 574cdf0e10cSrcweir // Mark element as default and not modified. That means "not active" 575cdf0e10cSrcweir // in the user layer anymore. 576cdf0e10cSrcweir rElement.bModified = false; 577cdf0e10cSrcweir rElement.bDefault = true; 578cdf0e10cSrcweir } 579cdf0e10cSrcweir } 580cdf0e10cSrcweir 581cdf0e10cSrcweir ++pIter; 582cdf0e10cSrcweir } 583cdf0e10cSrcweir 584cdf0e10cSrcweir // Remove all settings from our user interface elements 585cdf0e10cSrcweir rHashMap.clear(); 586cdf0e10cSrcweir } 587cdf0e10cSrcweir 588cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_reloadElementTypeData( 589cdf0e10cSrcweir UIElementType& rUserElementType, 590cdf0e10cSrcweir UIElementType& rDefaultElementType, 591cdf0e10cSrcweir ConfigEventNotifyContainer& rRemoveNotifyContainer, 592cdf0e10cSrcweir ConfigEventNotifyContainer& rReplaceNotifyContainer ) 593cdf0e10cSrcweir { 594cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rUserElementType.aElementsHashMap; 595cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 596cdf0e10cSrcweir Reference< XStorage > xUserStorage( rUserElementType.xStorage ); 597cdf0e10cSrcweir Reference< XStorage > xDefaultStorage( rDefaultElementType.xStorage ); 598cdf0e10cSrcweir Reference< XNameAccess > xUserNameAccess( rUserElementType.xStorage, UNO_QUERY ); 599cdf0e10cSrcweir Reference< XNameAccess > xDefaultNameAccess( rDefaultElementType.xStorage, UNO_QUERY ); 600cdf0e10cSrcweir 601cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 602cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 603cdf0e10cSrcweir sal_Int16 nType = rUserElementType.nElementType; 604cdf0e10cSrcweir 605cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 606cdf0e10cSrcweir { 607cdf0e10cSrcweir UIElementData& rElement = pIter->second; 608cdf0e10cSrcweir if ( rElement.bModified ) 609cdf0e10cSrcweir { 610cdf0e10cSrcweir if ( xUserNameAccess->hasByName( rElement.aName )) 611cdf0e10cSrcweir { 612cdf0e10cSrcweir // Replace settings with data from user layer 613cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings( rElement.xSettings ); 614cdf0e10cSrcweir 615cdf0e10cSrcweir impl_requestUIElementData( nType, LAYER_USERDEFINED, rElement ); 616cdf0e10cSrcweir 617cdf0e10cSrcweir ConfigurationEvent aReplaceEvent; 618cdf0e10cSrcweir 619cdf0e10cSrcweir aReplaceEvent.ResourceURL = rElement.aResourceURL; 620cdf0e10cSrcweir aReplaceEvent.Accessor <<= xThis; 621cdf0e10cSrcweir aReplaceEvent.Source = xIfac; 622cdf0e10cSrcweir aReplaceEvent.ReplacedElement <<= xOldSettings; 623cdf0e10cSrcweir aReplaceEvent.Element <<= rElement.xSettings; 624cdf0e10cSrcweir rReplaceNotifyContainer.push_back( aReplaceEvent ); 625cdf0e10cSrcweir 626cdf0e10cSrcweir rElement.bModified = false; 627cdf0e10cSrcweir } 628cdf0e10cSrcweir else if ( xDefaultNameAccess->hasByName( rElement.aName )) 629cdf0e10cSrcweir { 630cdf0e10cSrcweir // Replace settings with data from default layer 631cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings( rElement.xSettings ); 632cdf0e10cSrcweir 633cdf0e10cSrcweir impl_requestUIElementData( nType, LAYER_DEFAULT, rElement ); 634cdf0e10cSrcweir 635cdf0e10cSrcweir ConfigurationEvent aReplaceEvent; 636cdf0e10cSrcweir 637cdf0e10cSrcweir aReplaceEvent.ResourceURL = rElement.aResourceURL; 638cdf0e10cSrcweir aReplaceEvent.Accessor <<= xThis; 639cdf0e10cSrcweir aReplaceEvent.Source = xIfac; 640cdf0e10cSrcweir aReplaceEvent.ReplacedElement <<= xOldSettings; 641cdf0e10cSrcweir aReplaceEvent.Element <<= rElement.xSettings; 642cdf0e10cSrcweir rReplaceNotifyContainer.push_back( aReplaceEvent ); 643cdf0e10cSrcweir 644cdf0e10cSrcweir // Mark element as default and not modified. That means "not active" 645cdf0e10cSrcweir // in the user layer anymore. 646cdf0e10cSrcweir rElement.bModified = false; 647cdf0e10cSrcweir rElement.bDefault = true; 648cdf0e10cSrcweir } 649cdf0e10cSrcweir else 650cdf0e10cSrcweir { 651cdf0e10cSrcweir // Element settings are not in any storage => remove 652cdf0e10cSrcweir ConfigurationEvent aRemoveEvent; 653cdf0e10cSrcweir 654cdf0e10cSrcweir aRemoveEvent.ResourceURL = rElement.aResourceURL; 655cdf0e10cSrcweir aRemoveEvent.Accessor <<= xThis; 656cdf0e10cSrcweir aRemoveEvent.Source = xIfac; 657cdf0e10cSrcweir aRemoveEvent.Element <<= rElement.xSettings; 658cdf0e10cSrcweir 659cdf0e10cSrcweir rRemoveNotifyContainer.push_back( aRemoveEvent ); 660cdf0e10cSrcweir 661cdf0e10cSrcweir // Mark element as default and not modified. That means "not active" 662cdf0e10cSrcweir // in the user layer anymore. 663cdf0e10cSrcweir rElement.bModified = false; 664cdf0e10cSrcweir rElement.bDefault = true; 665cdf0e10cSrcweir } 666cdf0e10cSrcweir } 667cdf0e10cSrcweir ++pIter; 668cdf0e10cSrcweir } 669cdf0e10cSrcweir 670cdf0e10cSrcweir rUserElementType.bModified = sal_False; 671cdf0e10cSrcweir } 672cdf0e10cSrcweir 673cdf0e10cSrcweir void ModuleUIConfigurationManager::impl_Initialize() 674cdf0e10cSrcweir { 675cdf0e10cSrcweir // Initialize the top-level structures with the storage data 676cdf0e10cSrcweir if ( m_xUserConfigStorage.is() ) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir // Try to access our module sub folder 679cdf0e10cSrcweir for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; 680cdf0e10cSrcweir i++ ) 681cdf0e10cSrcweir { 682cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage; 683cdf0e10cSrcweir try 684cdf0e10cSrcweir { 685cdf0e10cSrcweir if ( m_pStorageHandler[i] ) 686cdf0e10cSrcweir xElementTypeStorage = m_pStorageHandler[i]->getWorkingStorageUser(); 687cdf0e10cSrcweir } 688cdf0e10cSrcweir catch ( com::sun::star::container::NoSuchElementException& ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir } 691cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 692cdf0e10cSrcweir { 693cdf0e10cSrcweir } 694cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 695cdf0e10cSrcweir { 696cdf0e10cSrcweir } 697cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& ) 698cdf0e10cSrcweir { 699cdf0e10cSrcweir } 700cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 701cdf0e10cSrcweir { 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED][i].nElementType = i; 705cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED][i].bModified = false; 706cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED][i].xStorage = xElementTypeStorage; 707cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED][i].bDefaultLayer = false; 708cdf0e10cSrcweir } 709cdf0e10cSrcweir } 710cdf0e10cSrcweir 711cdf0e10cSrcweir if ( m_xDefaultConfigStorage.is() ) 712cdf0e10cSrcweir { 713cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( m_xDefaultConfigStorage, UNO_QUERY_THROW ); 714cdf0e10cSrcweir 715cdf0e10cSrcweir // Try to access our module sub folder 716cdf0e10cSrcweir for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; 717cdf0e10cSrcweir i++ ) 718cdf0e10cSrcweir { 719cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage; 720cdf0e10cSrcweir try 721cdf0e10cSrcweir { 722cdf0e10cSrcweir const OUString sName( OUString::createFromAscii( UIELEMENTTYPENAMES[i] ) ); 723cdf0e10cSrcweir if( xNameAccess->hasByName( sName ) ) 724cdf0e10cSrcweir xNameAccess->getByName( sName ) >>= xElementTypeStorage; 725cdf0e10cSrcweir } 726cdf0e10cSrcweir catch ( com::sun::star::container::NoSuchElementException& ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir } 729cdf0e10cSrcweir 730cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT][i].nElementType = i; 731cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT][i].bModified = false; 732cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT][i].xStorage = xElementTypeStorage; 733cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT][i].bDefaultLayer = true; 734cdf0e10cSrcweir } 735cdf0e10cSrcweir } 736cdf0e10cSrcweir } 737cdf0e10cSrcweir 738cdf0e10cSrcweir ModuleUIConfigurationManager::ModuleUIConfigurationManager( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xServiceManager ) : 739cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ) 740cdf0e10cSrcweir , m_xDefaultConfigStorage( 0 ) 741cdf0e10cSrcweir , m_xUserConfigStorage( 0 ) 742cdf0e10cSrcweir , m_bReadOnly( true ) 743cdf0e10cSrcweir , m_bInitialized( false ) 744cdf0e10cSrcweir , m_bModified( false ) 745cdf0e10cSrcweir , m_bConfigRead( false ) 746cdf0e10cSrcweir , m_bDisposed( false ) 747cdf0e10cSrcweir , m_aXMLPostfix( RTL_CONSTASCII_USTRINGPARAM( ".xml" )) 748cdf0e10cSrcweir , m_aPropUIName( RTL_CONSTASCII_USTRINGPARAM( "UIName" )) 749cdf0e10cSrcweir , m_aPropResourceURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )) 750cdf0e10cSrcweir , m_xServiceManager( xServiceManager ) 751cdf0e10cSrcweir , m_aListenerContainer( m_aLock.getShareableOslMutex() ) 752cdf0e10cSrcweir { 753cdf0e10cSrcweir for ( int i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 754cdf0e10cSrcweir m_pStorageHandler[i] = 0; 755cdf0e10cSrcweir 756cdf0e10cSrcweir // Make sure we have a default initialized entry for every layer and user interface element type! 757cdf0e10cSrcweir // The following code depends on this! 758cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT].resize( ::com::sun::star::ui::UIElementType::COUNT ); 759cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED].resize( ::com::sun::star::ui::UIElementType::COUNT ); 760cdf0e10cSrcweir } 761cdf0e10cSrcweir 762cdf0e10cSrcweir ModuleUIConfigurationManager::~ModuleUIConfigurationManager() 763cdf0e10cSrcweir { 764cdf0e10cSrcweir for ( int i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 765cdf0e10cSrcweir delete m_pStorageHandler[i]; 766cdf0e10cSrcweir } 767cdf0e10cSrcweir 768cdf0e10cSrcweir // XComponent 769cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::dispose() throw (::com::sun::star::uno::RuntimeException) 770cdf0e10cSrcweir { 771cdf0e10cSrcweir Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); 772cdf0e10cSrcweir 773cdf0e10cSrcweir css::lang::EventObject aEvent( xThis ); 774cdf0e10cSrcweir m_aListenerContainer.disposeAndClear( aEvent ); 775cdf0e10cSrcweir 776cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 777cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 778cdf0e10cSrcweir Reference< XComponent > xModuleImageManager( m_xModuleImageManager ); 779cdf0e10cSrcweir m_xModuleImageManager.clear(); 780cdf0e10cSrcweir m_xModuleAcceleratorManager.clear(); 781cdf0e10cSrcweir m_aUIElements[LAYER_USERDEFINED].clear(); 782cdf0e10cSrcweir m_aUIElements[LAYER_DEFAULT].clear(); 783cdf0e10cSrcweir m_xDefaultConfigStorage.clear(); 784cdf0e10cSrcweir m_xUserConfigStorage.clear(); 785cdf0e10cSrcweir m_xUserRootCommit.clear(); 786cdf0e10cSrcweir m_bConfigRead = false; 787cdf0e10cSrcweir m_bModified = false; 788cdf0e10cSrcweir m_bDisposed = true; 789cdf0e10cSrcweir aGuard.unlock(); 790cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 791cdf0e10cSrcweir 792cdf0e10cSrcweir try 793cdf0e10cSrcweir { 794cdf0e10cSrcweir if ( xModuleImageManager.is() ) 795cdf0e10cSrcweir xModuleImageManager->dispose(); 796cdf0e10cSrcweir } 797cdf0e10cSrcweir catch ( Exception& ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir } 800cdf0e10cSrcweir } 801cdf0e10cSrcweir 802cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::addEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 803cdf0e10cSrcweir { 804cdf0e10cSrcweir { 805cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 806cdf0e10cSrcweir 807cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 808cdf0e10cSrcweir if ( m_bDisposed ) 809cdf0e10cSrcweir throw DisposedException(); 810cdf0e10cSrcweir } 811cdf0e10cSrcweir 812cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 813cdf0e10cSrcweir } 814cdf0e10cSrcweir 815cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::removeEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 818cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 819cdf0e10cSrcweir } 820cdf0e10cSrcweir 821cdf0e10cSrcweir // XInitialization 822cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::initialize( const Sequence< Any >& aArguments ) throw ( Exception, RuntimeException ) 823cdf0e10cSrcweir { 824cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 825cdf0e10cSrcweir 826cdf0e10cSrcweir if ( !m_bInitialized ) 827cdf0e10cSrcweir { 828cdf0e10cSrcweir ::comphelper::SequenceAsHashMap lArgs(aArguments); 829cdf0e10cSrcweir m_aModuleIdentifier = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleIdentifier"), ::rtl::OUString()); 830cdf0e10cSrcweir m_aModuleShortName = lArgs.getUnpackedValueOrDefault(::rtl::OUString::createFromAscii("ModuleShortName"), ::rtl::OUString()); 831cdf0e10cSrcweir 832cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 833cdf0e10cSrcweir { 834cdf0e10cSrcweir rtl::OUString aResourceType; 835cdf0e10cSrcweir if ( i == ::com::sun::star::ui::UIElementType::MENUBAR ) 836cdf0e10cSrcweir aResourceType = PresetHandler::RESOURCETYPE_MENUBAR(); 837cdf0e10cSrcweir else if ( i == ::com::sun::star::ui::UIElementType::TOOLBAR ) 838cdf0e10cSrcweir aResourceType = PresetHandler::RESOURCETYPE_TOOLBAR(); 839cdf0e10cSrcweir else if ( i == ::com::sun::star::ui::UIElementType::STATUSBAR ) 840cdf0e10cSrcweir aResourceType = PresetHandler::RESOURCETYPE_STATUSBAR(); 841cdf0e10cSrcweir 842cdf0e10cSrcweir if ( aResourceType.getLength() > 0 ) 843cdf0e10cSrcweir { 844cdf0e10cSrcweir m_pStorageHandler[i] = new PresetHandler( m_xServiceManager ); 845cdf0e10cSrcweir m_pStorageHandler[i]->connectToResource( PresetHandler::E_MODULES, 846cdf0e10cSrcweir aResourceType, // this path wont be used later ... seee next lines! 847cdf0e10cSrcweir m_aModuleShortName, 848cdf0e10cSrcweir css::uno::Reference< css::embed::XStorage >()); // no document root used here! 849cdf0e10cSrcweir } 850cdf0e10cSrcweir } 851cdf0e10cSrcweir 852cdf0e10cSrcweir // initialize root storages for all resource types 853cdf0e10cSrcweir m_xUserRootCommit = css::uno::Reference< css::embed::XTransactedObject >( 854cdf0e10cSrcweir m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getOrCreateRootStorageUser(), css::uno::UNO_QUERY); // can be empty 855cdf0e10cSrcweir m_xDefaultConfigStorage = m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getParentStorageShare( 856cdf0e10cSrcweir m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getWorkingStorageShare()); 857cdf0e10cSrcweir m_xUserConfigStorage = m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getParentStorageUser( 858cdf0e10cSrcweir m_pStorageHandler[::com::sun::star::ui::UIElementType::MENUBAR]->getWorkingStorageUser()); 859cdf0e10cSrcweir 860cdf0e10cSrcweir if ( m_xUserConfigStorage.is() ) 861cdf0e10cSrcweir { 862cdf0e10cSrcweir Reference< XPropertySet > xPropSet( m_xUserConfigStorage, UNO_QUERY ); 863cdf0e10cSrcweir if ( xPropSet.is() ) 864cdf0e10cSrcweir { 865cdf0e10cSrcweir long nOpenMode = 0; 866cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))); 867cdf0e10cSrcweir if ( a >>= nOpenMode ) 868cdf0e10cSrcweir m_bReadOnly = !( nOpenMode & ElementModes::WRITE ); 869cdf0e10cSrcweir } 870cdf0e10cSrcweir } 871cdf0e10cSrcweir 872cdf0e10cSrcweir impl_Initialize(); 873cdf0e10cSrcweir 874cdf0e10cSrcweir m_bInitialized = true; 875cdf0e10cSrcweir } 876cdf0e10cSrcweir } 877cdf0e10cSrcweir 878cdf0e10cSrcweir // XUIConfiguration 879cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::addConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 880cdf0e10cSrcweir { 881cdf0e10cSrcweir { 882cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 883cdf0e10cSrcweir 884cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 885cdf0e10cSrcweir if ( m_bDisposed ) 886cdf0e10cSrcweir throw DisposedException(); 887cdf0e10cSrcweir } 888cdf0e10cSrcweir 889cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener ); 890cdf0e10cSrcweir } 891cdf0e10cSrcweir 892cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::removeConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 895cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener ); 896cdf0e10cSrcweir } 897cdf0e10cSrcweir 898cdf0e10cSrcweir 899cdf0e10cSrcweir // XUIConfigurationManager 900cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::reset() throw (::com::sun::star::uno::RuntimeException) 901cdf0e10cSrcweir { 902cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 903cdf0e10cSrcweir 904cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 905cdf0e10cSrcweir if ( m_bDisposed ) 906cdf0e10cSrcweir throw DisposedException(); 907cdf0e10cSrcweir 908cdf0e10cSrcweir bool bResetStorage( false ); 909cdf0e10cSrcweir 910cdf0e10cSrcweir if ( !isReadOnly() ) 911cdf0e10cSrcweir { 912cdf0e10cSrcweir // Remove all elements from our user-defined storage! 913cdf0e10cSrcweir try 914cdf0e10cSrcweir { 915cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 916cdf0e10cSrcweir { 917cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][i]; 918cdf0e10cSrcweir Reference< XStorage > xSubStorage( rElementType.xStorage, UNO_QUERY ); 919cdf0e10cSrcweir 920cdf0e10cSrcweir if ( xSubStorage.is() ) 921cdf0e10cSrcweir { 922cdf0e10cSrcweir bool bCommitSubStorage( false ); 923cdf0e10cSrcweir Reference< XNameAccess > xSubStorageNameAccess( xSubStorage, UNO_QUERY ); 924cdf0e10cSrcweir Sequence< OUString > aUIElementStreamNames = xSubStorageNameAccess->getElementNames(); 925cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aUIElementStreamNames.getLength(); j++ ) 926cdf0e10cSrcweir { 927cdf0e10cSrcweir xSubStorage->removeElement( aUIElementStreamNames[j] ); 928cdf0e10cSrcweir bCommitSubStorage = true; 929cdf0e10cSrcweir } 930cdf0e10cSrcweir 931cdf0e10cSrcweir if ( bCommitSubStorage ) 932cdf0e10cSrcweir { 933cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( xSubStorage, UNO_QUERY ); 934cdf0e10cSrcweir if ( xTransactedObject.is() ) 935cdf0e10cSrcweir xTransactedObject->commit(); 936cdf0e10cSrcweir m_pStorageHandler[i]->commitUserChanges(); 937cdf0e10cSrcweir } 938cdf0e10cSrcweir } 939cdf0e10cSrcweir } 940cdf0e10cSrcweir 941cdf0e10cSrcweir bResetStorage = true; 942cdf0e10cSrcweir 943cdf0e10cSrcweir // remove settings from user defined layer and notify listener about removed settings data! 944cdf0e10cSrcweir ConfigEventNotifyContainer aRemoveEventNotifyContainer; 945cdf0e10cSrcweir ConfigEventNotifyContainer aReplaceEventNotifyContainer; 946cdf0e10cSrcweir for ( sal_Int16 j = 1; j < ::com::sun::star::ui::UIElementType::COUNT; j++ ) 947cdf0e10cSrcweir { 948cdf0e10cSrcweir try 949cdf0e10cSrcweir { 950cdf0e10cSrcweir UIElementType& rUserElementType = m_aUIElements[LAYER_USERDEFINED][j]; 951cdf0e10cSrcweir UIElementType& rDefaultElementType = m_aUIElements[LAYER_DEFAULT][j]; 952cdf0e10cSrcweir 953cdf0e10cSrcweir impl_resetElementTypeData( rUserElementType, rDefaultElementType, aRemoveEventNotifyContainer, aReplaceEventNotifyContainer ); 954cdf0e10cSrcweir rUserElementType.bModified = sal_False; 955cdf0e10cSrcweir } 956cdf0e10cSrcweir catch ( Exception& ) 957cdf0e10cSrcweir { 958cdf0e10cSrcweir throw IOException(); 959cdf0e10cSrcweir } 960cdf0e10cSrcweir } 961cdf0e10cSrcweir 962cdf0e10cSrcweir m_bModified = sal_False; 963cdf0e10cSrcweir 964cdf0e10cSrcweir // Unlock mutex before notify our listeners 965cdf0e10cSrcweir aGuard.unlock(); 966cdf0e10cSrcweir 967cdf0e10cSrcweir // Notify our listeners 968cdf0e10cSrcweir sal_uInt32 k = 0; 969cdf0e10cSrcweir for ( k = 0; k < aRemoveEventNotifyContainer.size(); k++ ) 970cdf0e10cSrcweir implts_notifyContainerListener( aRemoveEventNotifyContainer[k], NotifyOp_Remove ); 971cdf0e10cSrcweir for ( k = 0; k < aReplaceEventNotifyContainer.size(); k++ ) 972cdf0e10cSrcweir implts_notifyContainerListener( aReplaceEventNotifyContainer[k], NotifyOp_Replace ); 973cdf0e10cSrcweir } 974cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 975cdf0e10cSrcweir { 976cdf0e10cSrcweir } 977cdf0e10cSrcweir catch ( ::com::sun::star::container::NoSuchElementException& ) 978cdf0e10cSrcweir { 979cdf0e10cSrcweir } 980cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 981cdf0e10cSrcweir { 982cdf0e10cSrcweir } 983cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 984cdf0e10cSrcweir { 985cdf0e10cSrcweir } 986cdf0e10cSrcweir } 987cdf0e10cSrcweir } 988cdf0e10cSrcweir 989cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SAL_CALL ModuleUIConfigurationManager::getUIElementsInfo( sal_Int16 ElementType ) 990cdf0e10cSrcweir throw ( IllegalArgumentException, RuntimeException ) 991cdf0e10cSrcweir { 992cdf0e10cSrcweir if (( ElementType < 0 ) || ( ElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 993cdf0e10cSrcweir throw IllegalArgumentException(); 994cdf0e10cSrcweir 995cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 996cdf0e10cSrcweir if ( m_bDisposed ) 997cdf0e10cSrcweir throw DisposedException(); 998cdf0e10cSrcweir 999cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aElementInfoSeq; 1000cdf0e10cSrcweir UIElementInfoHashMap aUIElementInfoCollection; 1001cdf0e10cSrcweir 1002cdf0e10cSrcweir if ( ElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir for ( sal_Int16 i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1005cdf0e10cSrcweir impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, sal_Int16( i ) ); 1006cdf0e10cSrcweir } 1007cdf0e10cSrcweir else 1008cdf0e10cSrcweir impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, ElementType ); 1009cdf0e10cSrcweir 1010cdf0e10cSrcweir Sequence< PropertyValue > aUIElementInfo( 2 ); 1011cdf0e10cSrcweir aUIElementInfo[0].Name = m_aPropResourceURL; 1012cdf0e10cSrcweir aUIElementInfo[1].Name = m_aPropUIName; 1013cdf0e10cSrcweir 1014cdf0e10cSrcweir aElementInfoSeq.realloc( aUIElementInfoCollection.size() ); 1015cdf0e10cSrcweir UIElementInfoHashMap::const_iterator pIter = aUIElementInfoCollection.begin(); 1016cdf0e10cSrcweir 1017cdf0e10cSrcweir sal_Int32 n = 0; 1018cdf0e10cSrcweir while ( pIter != aUIElementInfoCollection.end() ) 1019cdf0e10cSrcweir { 1020cdf0e10cSrcweir aUIElementInfo[0].Value <<= pIter->second.aResourceURL; 1021cdf0e10cSrcweir aUIElementInfo[1].Value <<= pIter->second.aUIName; 1022cdf0e10cSrcweir aElementInfoSeq[n++] = aUIElementInfo; 1023cdf0e10cSrcweir ++pIter; 1024cdf0e10cSrcweir } 1025cdf0e10cSrcweir 1026cdf0e10cSrcweir return aElementInfoSeq; 1027cdf0e10cSrcweir } 1028cdf0e10cSrcweir 1029cdf0e10cSrcweir Reference< XIndexContainer > SAL_CALL ModuleUIConfigurationManager::createSettings() throw (::com::sun::star::uno::RuntimeException) 1030cdf0e10cSrcweir { 1031cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1032cdf0e10cSrcweir 1033cdf0e10cSrcweir if ( m_bDisposed ) 1034cdf0e10cSrcweir throw DisposedException(); 1035cdf0e10cSrcweir 1036cdf0e10cSrcweir // Creates an empty item container which can be filled from outside 1037cdf0e10cSrcweir return Reference< XIndexContainer >( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY ); 1038cdf0e10cSrcweir } 1039cdf0e10cSrcweir 1040cdf0e10cSrcweir sal_Bool SAL_CALL ModuleUIConfigurationManager::hasSettings( const ::rtl::OUString& ResourceURL ) 1041cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1042cdf0e10cSrcweir { 1043cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1044cdf0e10cSrcweir 1045cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1046cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1047cdf0e10cSrcweir throw IllegalArgumentException(); 1048cdf0e10cSrcweir else 1049cdf0e10cSrcweir { 1050cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1051cdf0e10cSrcweir 1052cdf0e10cSrcweir if ( m_bDisposed ) 1053cdf0e10cSrcweir throw DisposedException(); 1054cdf0e10cSrcweir 1055cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); 1056cdf0e10cSrcweir if ( pDataSettings ) 1057cdf0e10cSrcweir return sal_True; 1058cdf0e10cSrcweir } 1059cdf0e10cSrcweir 1060cdf0e10cSrcweir return sal_False; 1061cdf0e10cSrcweir } 1062cdf0e10cSrcweir 1063cdf0e10cSrcweir Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getSettings( const ::rtl::OUString& ResourceURL, sal_Bool bWriteable ) 1064cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1065cdf0e10cSrcweir { 1066cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1067cdf0e10cSrcweir 1068cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1069cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1070cdf0e10cSrcweir throw IllegalArgumentException(); 1071cdf0e10cSrcweir else 1072cdf0e10cSrcweir { 1073cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir if ( m_bDisposed ) 1076cdf0e10cSrcweir throw DisposedException(); 1077cdf0e10cSrcweir 1078cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 1079cdf0e10cSrcweir if ( pDataSettings ) 1080cdf0e10cSrcweir { 1081cdf0e10cSrcweir // Create a copy of our data if someone wants to change the data. 1082cdf0e10cSrcweir if ( bWriteable ) 1083cdf0e10cSrcweir return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); 1084cdf0e10cSrcweir else 1085cdf0e10cSrcweir return pDataSettings->xSettings; 1086cdf0e10cSrcweir } 1087cdf0e10cSrcweir } 1088cdf0e10cSrcweir 1089cdf0e10cSrcweir throw NoSuchElementException(); 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::replaceSettings( const ::rtl::OUString& ResourceURL, const Reference< ::com::sun::star::container::XIndexAccess >& aNewData ) 1093cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1098cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1099cdf0e10cSrcweir throw IllegalArgumentException(); 1100cdf0e10cSrcweir else if ( m_bReadOnly ) 1101cdf0e10cSrcweir throw IllegalAccessException(); 1102cdf0e10cSrcweir else 1103cdf0e10cSrcweir { 1104cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1105cdf0e10cSrcweir 1106cdf0e10cSrcweir if ( m_bDisposed ) 1107cdf0e10cSrcweir throw DisposedException(); 1108cdf0e10cSrcweir 1109cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 1110cdf0e10cSrcweir if ( pDataSettings ) 1111cdf0e10cSrcweir { 1112cdf0e10cSrcweir if ( !pDataSettings->bDefaultNode ) 1113cdf0e10cSrcweir { 1114cdf0e10cSrcweir // we have a settings entry in our user-defined layer - replace 1115cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings = pDataSettings->xSettings; 1116cdf0e10cSrcweir 1117cdf0e10cSrcweir // Create a copy of the data if the container is not const 1118cdf0e10cSrcweir Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY ); 1119cdf0e10cSrcweir if ( xReplace.is() ) 1120cdf0e10cSrcweir pDataSettings->xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY ); 1121cdf0e10cSrcweir else 1122cdf0e10cSrcweir pDataSettings->xSettings = aNewData; 1123cdf0e10cSrcweir pDataSettings->bDefault = false; 1124cdf0e10cSrcweir pDataSettings->bModified = true; 1125cdf0e10cSrcweir m_bModified = true; 1126cdf0e10cSrcweir 1127cdf0e10cSrcweir // Modify type container 1128cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType]; 1129cdf0e10cSrcweir rElementType.bModified = true; 1130cdf0e10cSrcweir 1131cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1132cdf0e10cSrcweir 1133cdf0e10cSrcweir // Create event to notify listener about replaced element settings 1134cdf0e10cSrcweir ConfigurationEvent aEvent; 1135cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 1136cdf0e10cSrcweir 1137cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 1138cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1139cdf0e10cSrcweir aEvent.Source = xIfac; 1140cdf0e10cSrcweir aEvent.ReplacedElement <<= xOldSettings; 1141cdf0e10cSrcweir aEvent.Element <<= pDataSettings->xSettings; 1142cdf0e10cSrcweir 1143cdf0e10cSrcweir aGuard.unlock(); 1144cdf0e10cSrcweir 1145cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Replace ); 1146cdf0e10cSrcweir } 1147cdf0e10cSrcweir else 1148cdf0e10cSrcweir { 1149cdf0e10cSrcweir // we have no settings in our user-defined layer - insert 1150cdf0e10cSrcweir UIElementData aUIElementData; 1151cdf0e10cSrcweir 1152cdf0e10cSrcweir aUIElementData.bDefault = false; 1153cdf0e10cSrcweir aUIElementData.bDefaultNode = false; 1154cdf0e10cSrcweir aUIElementData.bModified = true; 1155cdf0e10cSrcweir 1156cdf0e10cSrcweir // Create a copy of the data if the container is not const 1157cdf0e10cSrcweir Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY ); 1158cdf0e10cSrcweir if ( xReplace.is() ) 1159cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY ); 1160cdf0e10cSrcweir else 1161cdf0e10cSrcweir aUIElementData.xSettings = aNewData; 1162cdf0e10cSrcweir aUIElementData.aName = RetrieveNameFromResourceURL( ResourceURL ) + m_aXMLPostfix; 1163cdf0e10cSrcweir aUIElementData.aResourceURL = ResourceURL; 1164cdf0e10cSrcweir m_bModified = true; 1165cdf0e10cSrcweir 1166cdf0e10cSrcweir // Modify type container 1167cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType]; 1168cdf0e10cSrcweir rElementType.bModified = true; 1169cdf0e10cSrcweir 1170cdf0e10cSrcweir UIElementDataHashMap& rElements = rElementType.aElementsHashMap; 1171cdf0e10cSrcweir 1172cdf0e10cSrcweir // Check our user element settings hash map as it can already contain settings that have been set to default! 1173cdf0e10cSrcweir // If no node can be found, we have to insert it. 1174cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rElements.find( ResourceURL ); 1175cdf0e10cSrcweir if ( pIter != rElements.end() ) 1176cdf0e10cSrcweir pIter->second = aUIElementData; 1177cdf0e10cSrcweir else 1178cdf0e10cSrcweir rElements.insert( UIElementDataHashMap::value_type( ResourceURL, aUIElementData )); 1179cdf0e10cSrcweir 1180cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1181cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 1182cdf0e10cSrcweir 1183cdf0e10cSrcweir // Create event to notify listener about replaced element settings 1184cdf0e10cSrcweir ConfigurationEvent aEvent; 1185cdf0e10cSrcweir 1186cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 1187cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1188cdf0e10cSrcweir aEvent.Source = xIfac; 1189cdf0e10cSrcweir aEvent.ReplacedElement <<= pDataSettings->xSettings; 1190cdf0e10cSrcweir aEvent.Element <<= aUIElementData.xSettings; 1191cdf0e10cSrcweir 1192cdf0e10cSrcweir aGuard.unlock(); 1193cdf0e10cSrcweir 1194cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Replace ); 1195cdf0e10cSrcweir } 1196cdf0e10cSrcweir } 1197cdf0e10cSrcweir else 1198cdf0e10cSrcweir throw NoSuchElementException(); 1199cdf0e10cSrcweir } 1200cdf0e10cSrcweir } 1201cdf0e10cSrcweir 1202cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::removeSettings( const ::rtl::OUString& ResourceURL ) 1203cdf0e10cSrcweir throw ( NoSuchElementException, IllegalArgumentException, IllegalAccessException, RuntimeException) 1204cdf0e10cSrcweir { 1205cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1206cdf0e10cSrcweir 1207cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1208cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1209cdf0e10cSrcweir throw IllegalArgumentException(); 1210cdf0e10cSrcweir else if ( m_bReadOnly ) 1211cdf0e10cSrcweir throw IllegalAccessException(); 1212cdf0e10cSrcweir else 1213cdf0e10cSrcweir { 1214cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1215cdf0e10cSrcweir 1216cdf0e10cSrcweir if ( m_bDisposed ) 1217cdf0e10cSrcweir throw DisposedException(); 1218cdf0e10cSrcweir 1219cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 1220cdf0e10cSrcweir if ( pDataSettings ) 1221cdf0e10cSrcweir { 1222cdf0e10cSrcweir // If element settings are default, we don't need to change anything! 1223cdf0e10cSrcweir if ( pDataSettings->bDefault ) 1224cdf0e10cSrcweir return; 1225cdf0e10cSrcweir else 1226cdf0e10cSrcweir { 1227cdf0e10cSrcweir Reference< XIndexAccess > xRemovedSettings = pDataSettings->xSettings; 1228cdf0e10cSrcweir pDataSettings->bDefault = true; 1229cdf0e10cSrcweir 1230cdf0e10cSrcweir // check if this is a default layer node 1231cdf0e10cSrcweir if ( !pDataSettings->bDefaultNode ) 1232cdf0e10cSrcweir pDataSettings->bModified = true; // we have to remove this node from the user layer! 1233cdf0e10cSrcweir pDataSettings->xSettings.clear(); 1234cdf0e10cSrcweir m_bModified = true; // user layer must be written 1235cdf0e10cSrcweir 1236cdf0e10cSrcweir // Modify type container 1237cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType]; 1238cdf0e10cSrcweir rElementType.bModified = true; 1239cdf0e10cSrcweir 1240cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1241cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 1242cdf0e10cSrcweir 1243cdf0e10cSrcweir // Check if we have settings in the default layer which replaces the user-defined one! 1244cdf0e10cSrcweir UIElementData* pDefaultDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 1245cdf0e10cSrcweir if ( pDefaultDataSettings ) 1246cdf0e10cSrcweir { 1247cdf0e10cSrcweir // Create event to notify listener about replaced element settings 1248cdf0e10cSrcweir ConfigurationEvent aEvent; 1249cdf0e10cSrcweir 1250cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 1251cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1252cdf0e10cSrcweir aEvent.Source = xIfac; 1253cdf0e10cSrcweir aEvent.Element <<= xRemovedSettings; 1254cdf0e10cSrcweir aEvent.ReplacedElement <<= pDefaultDataSettings->xSettings; 1255cdf0e10cSrcweir 1256cdf0e10cSrcweir aGuard.unlock(); 1257cdf0e10cSrcweir 1258cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Replace ); 1259cdf0e10cSrcweir } 1260cdf0e10cSrcweir else 1261cdf0e10cSrcweir { 1262cdf0e10cSrcweir // Create event to notify listener about removed element settings 1263cdf0e10cSrcweir ConfigurationEvent aEvent; 1264cdf0e10cSrcweir 1265cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 1266cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1267cdf0e10cSrcweir aEvent.Source = xIfac; 1268cdf0e10cSrcweir aEvent.Element <<= xRemovedSettings; 1269cdf0e10cSrcweir 1270cdf0e10cSrcweir aGuard.unlock(); 1271cdf0e10cSrcweir 1272cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Remove ); 1273cdf0e10cSrcweir } 1274cdf0e10cSrcweir } 1275cdf0e10cSrcweir } 1276cdf0e10cSrcweir else 1277cdf0e10cSrcweir throw NoSuchElementException(); 1278cdf0e10cSrcweir } 1279cdf0e10cSrcweir } 1280cdf0e10cSrcweir 1281cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::insertSettings( const ::rtl::OUString& NewResourceURL, const Reference< XIndexAccess >& aNewData ) 1282cdf0e10cSrcweir throw ( ElementExistException, IllegalArgumentException, IllegalAccessException, RuntimeException ) 1283cdf0e10cSrcweir { 1284cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( NewResourceURL ); 1285cdf0e10cSrcweir 1286cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1287cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1288cdf0e10cSrcweir throw IllegalArgumentException(); 1289cdf0e10cSrcweir else if ( m_bReadOnly ) 1290cdf0e10cSrcweir throw IllegalAccessException(); 1291cdf0e10cSrcweir else 1292cdf0e10cSrcweir { 1293cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1294cdf0e10cSrcweir 1295cdf0e10cSrcweir if ( m_bDisposed ) 1296cdf0e10cSrcweir throw DisposedException(); 1297cdf0e10cSrcweir 1298cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( NewResourceURL, nElementType ); 1299cdf0e10cSrcweir if ( !pDataSettings ) 1300cdf0e10cSrcweir { 1301cdf0e10cSrcweir UIElementData aUIElementData; 1302cdf0e10cSrcweir 1303cdf0e10cSrcweir aUIElementData.bDefault = false; 1304cdf0e10cSrcweir aUIElementData.bDefaultNode = false; 1305cdf0e10cSrcweir aUIElementData.bModified = true; 1306cdf0e10cSrcweir 1307cdf0e10cSrcweir // Create a copy of the data if the container is not const 1308cdf0e10cSrcweir Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY ); 1309cdf0e10cSrcweir if ( xReplace.is() ) 1310cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY ); 1311cdf0e10cSrcweir else 1312cdf0e10cSrcweir aUIElementData.xSettings = aNewData; 1313cdf0e10cSrcweir aUIElementData.aName = RetrieveNameFromResourceURL( NewResourceURL ) + m_aXMLPostfix; 1314cdf0e10cSrcweir aUIElementData.aResourceURL = NewResourceURL; 1315cdf0e10cSrcweir m_bModified = true; 1316cdf0e10cSrcweir 1317cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][nElementType]; 1318cdf0e10cSrcweir rElementType.bModified = true; 1319cdf0e10cSrcweir 1320cdf0e10cSrcweir UIElementDataHashMap& rElements = rElementType.aElementsHashMap; 1321cdf0e10cSrcweir rElements.insert( UIElementDataHashMap::value_type( NewResourceURL, aUIElementData )); 1322cdf0e10cSrcweir 1323cdf0e10cSrcweir Reference< XIndexAccess > xInsertSettings( aUIElementData.xSettings ); 1324cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1325cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 1326cdf0e10cSrcweir 1327cdf0e10cSrcweir // Create event to notify listener about removed element settings 1328cdf0e10cSrcweir ConfigurationEvent aEvent; 1329cdf0e10cSrcweir 1330cdf0e10cSrcweir aEvent.ResourceURL = NewResourceURL; 1331cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1332cdf0e10cSrcweir aEvent.Source = xIfac; 1333cdf0e10cSrcweir aEvent.Element <<= xInsertSettings; 1334cdf0e10cSrcweir 1335cdf0e10cSrcweir aGuard.unlock(); 1336cdf0e10cSrcweir 1337cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Insert ); 1338cdf0e10cSrcweir } 1339cdf0e10cSrcweir else 1340cdf0e10cSrcweir throw ElementExistException(); 1341cdf0e10cSrcweir } 1342cdf0e10cSrcweir } 1343cdf0e10cSrcweir 1344cdf0e10cSrcweir Reference< XInterface > SAL_CALL ModuleUIConfigurationManager::getImageManager() throw (::com::sun::star::uno::RuntimeException) 1345cdf0e10cSrcweir { 1346cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1347cdf0e10cSrcweir 1348cdf0e10cSrcweir if ( m_bDisposed ) 1349cdf0e10cSrcweir throw DisposedException(); 1350cdf0e10cSrcweir 1351cdf0e10cSrcweir if ( !m_xModuleImageManager.is() ) 1352cdf0e10cSrcweir { 1353cdf0e10cSrcweir m_xModuleImageManager = Reference< XComponent >( static_cast< cppu::OWeakObject *>( new ModuleImageManager( m_xServiceManager )), 1354cdf0e10cSrcweir UNO_QUERY ); 1355cdf0e10cSrcweir Reference< XInitialization > xInit( m_xModuleImageManager, UNO_QUERY ); 1356cdf0e10cSrcweir 1357cdf0e10cSrcweir Sequence< Any > aPropSeq( 3 ); 1358cdf0e10cSrcweir PropertyValue aPropValue; 1359cdf0e10cSrcweir aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" )); 1360cdf0e10cSrcweir aPropValue.Value = makeAny( m_xUserConfigStorage ); 1361cdf0e10cSrcweir aPropSeq[0] = makeAny( aPropValue ); 1362cdf0e10cSrcweir aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" )); 1363cdf0e10cSrcweir aPropValue.Value = makeAny( m_aModuleIdentifier ); 1364cdf0e10cSrcweir aPropSeq[1] = makeAny( aPropValue ); 1365cdf0e10cSrcweir aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserRootCommit" )); 1366cdf0e10cSrcweir aPropValue.Value = makeAny( m_xUserRootCommit ); 1367cdf0e10cSrcweir aPropSeq[2] = makeAny( aPropValue ); 1368cdf0e10cSrcweir 1369cdf0e10cSrcweir xInit->initialize( aPropSeq ); 1370cdf0e10cSrcweir } 1371cdf0e10cSrcweir 1372cdf0e10cSrcweir return Reference< XInterface >( m_xModuleImageManager, UNO_QUERY ); 1373cdf0e10cSrcweir } 1374cdf0e10cSrcweir 1375cdf0e10cSrcweir Reference< XInterface > SAL_CALL ModuleUIConfigurationManager::getShortCutManager() throw (::com::sun::star::uno::RuntimeException) 1376cdf0e10cSrcweir { 1377cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1378cdf0e10cSrcweir 1379cdf0e10cSrcweir if ( m_bDisposed ) 1380cdf0e10cSrcweir throw DisposedException(); 1381cdf0e10cSrcweir 1382cdf0e10cSrcweir Reference< XMultiServiceFactory > xSMGR = m_xServiceManager; 1383cdf0e10cSrcweir ::rtl::OUString aModule = m_aModuleIdentifier; 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir if ( !m_xModuleAcceleratorManager.is() ) 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir Reference< XInterface > xManager = xSMGR->createInstance(SERVICENAME_MODULEACCELERATORCONFIGURATION); 1388cdf0e10cSrcweir Reference< XInitialization > xInit (xManager, UNO_QUERY_THROW); 1389cdf0e10cSrcweir 1390cdf0e10cSrcweir PropertyValue aProp; 1391cdf0e10cSrcweir aProp.Name = ::rtl::OUString::createFromAscii("ModuleIdentifier"); 1392cdf0e10cSrcweir aProp.Value <<= aModule; 1393cdf0e10cSrcweir 1394cdf0e10cSrcweir Sequence< Any > lArgs(1); 1395cdf0e10cSrcweir lArgs[0] <<= aProp; 1396cdf0e10cSrcweir 1397cdf0e10cSrcweir xInit->initialize(lArgs); 1398cdf0e10cSrcweir m_xModuleAcceleratorManager = Reference< XInterface >( xManager, UNO_QUERY ); 1399cdf0e10cSrcweir } 1400cdf0e10cSrcweir 1401cdf0e10cSrcweir return m_xModuleAcceleratorManager; 1402cdf0e10cSrcweir } 1403cdf0e10cSrcweir 1404cdf0e10cSrcweir Reference< XInterface > SAL_CALL ModuleUIConfigurationManager::getEventsManager() throw (::com::sun::star::uno::RuntimeException) 1405cdf0e10cSrcweir { 1406cdf0e10cSrcweir return Reference< XInterface >(); 1407cdf0e10cSrcweir } 1408cdf0e10cSrcweir 1409cdf0e10cSrcweir // XModuleUIConfigurationManager 1410cdf0e10cSrcweir sal_Bool SAL_CALL ModuleUIConfigurationManager::isDefaultSettings( const ::rtl::OUString& ResourceURL ) 1411cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1412cdf0e10cSrcweir { 1413cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1414cdf0e10cSrcweir 1415cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1416cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1417cdf0e10cSrcweir throw IllegalArgumentException(); 1418cdf0e10cSrcweir else 1419cdf0e10cSrcweir { 1420cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1421cdf0e10cSrcweir 1422cdf0e10cSrcweir if ( m_bDisposed ) 1423cdf0e10cSrcweir throw DisposedException(); 1424cdf0e10cSrcweir 1425cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); 1426cdf0e10cSrcweir if ( pDataSettings && pDataSettings->bDefaultNode ) 1427cdf0e10cSrcweir return sal_True; 1428cdf0e10cSrcweir } 1429cdf0e10cSrcweir 1430cdf0e10cSrcweir return sal_False; 1431cdf0e10cSrcweir } 1432cdf0e10cSrcweir 1433cdf0e10cSrcweir Reference< XIndexAccess > SAL_CALL ModuleUIConfigurationManager::getDefaultSettings( const ::rtl::OUString& ResourceURL ) 1434cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 1435cdf0e10cSrcweir { 1436cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 1437cdf0e10cSrcweir 1438cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 1439cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1440cdf0e10cSrcweir throw IllegalArgumentException(); 1441cdf0e10cSrcweir else 1442cdf0e10cSrcweir { 1443cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir if ( m_bDisposed ) 1446cdf0e10cSrcweir throw DisposedException(); 1447cdf0e10cSrcweir 1448cdf0e10cSrcweir // preload list of element types on demand 1449cdf0e10cSrcweir impl_preloadUIElementTypeList( LAYER_DEFAULT, nElementType ); 1450cdf0e10cSrcweir 1451cdf0e10cSrcweir // Look into our default vector/hash_map combination 1452cdf0e10cSrcweir UIElementDataHashMap& rDefaultHashMap = m_aUIElements[LAYER_DEFAULT][nElementType].aElementsHashMap; 1453cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rDefaultHashMap.find( ResourceURL ); 1454cdf0e10cSrcweir if ( pIter != rDefaultHashMap.end() ) 1455cdf0e10cSrcweir { 1456cdf0e10cSrcweir if ( !pIter->second.xSettings.is() ) 1457cdf0e10cSrcweir impl_requestUIElementData( nElementType, LAYER_DEFAULT, pIter->second ); 1458cdf0e10cSrcweir return pIter->second.xSettings; 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir } 1461cdf0e10cSrcweir 1462cdf0e10cSrcweir // Nothing has been found! 1463cdf0e10cSrcweir throw NoSuchElementException(); 1464cdf0e10cSrcweir } 1465cdf0e10cSrcweir 1466cdf0e10cSrcweir // XUIConfigurationPersistence 1467cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1468cdf0e10cSrcweir { 1469cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1470cdf0e10cSrcweir 1471cdf0e10cSrcweir if ( m_bDisposed ) 1472cdf0e10cSrcweir throw DisposedException(); 1473cdf0e10cSrcweir 1474cdf0e10cSrcweir if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly ) 1475cdf0e10cSrcweir { 1476cdf0e10cSrcweir // Try to access our module sub folder 1477cdf0e10cSrcweir ConfigEventNotifyContainer aRemoveNotifyContainer; 1478cdf0e10cSrcweir ConfigEventNotifyContainer aReplaceNotifyContainer; 1479cdf0e10cSrcweir for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1480cdf0e10cSrcweir { 1481cdf0e10cSrcweir try 1482cdf0e10cSrcweir { 1483cdf0e10cSrcweir UIElementType& rUserElementType = m_aUIElements[LAYER_USERDEFINED][i]; 1484cdf0e10cSrcweir UIElementType& rDefaultElementType = m_aUIElements[LAYER_DEFAULT][i]; 1485cdf0e10cSrcweir 1486cdf0e10cSrcweir if ( rUserElementType.bModified ) 1487cdf0e10cSrcweir impl_reloadElementTypeData( rUserElementType, rDefaultElementType, aRemoveNotifyContainer, aReplaceNotifyContainer ); 1488cdf0e10cSrcweir } 1489cdf0e10cSrcweir catch ( Exception& ) 1490cdf0e10cSrcweir { 1491cdf0e10cSrcweir throw IOException(); 1492cdf0e10cSrcweir } 1493cdf0e10cSrcweir } 1494cdf0e10cSrcweir 1495cdf0e10cSrcweir m_bModified = sal_False; 1496cdf0e10cSrcweir 1497cdf0e10cSrcweir // Unlock mutex before notify our listeners 1498cdf0e10cSrcweir aGuard.unlock(); 1499cdf0e10cSrcweir 1500cdf0e10cSrcweir // Notify our listeners 1501cdf0e10cSrcweir for ( sal_uInt32 j = 0; j < aRemoveNotifyContainer.size(); j++ ) 1502cdf0e10cSrcweir implts_notifyContainerListener( aRemoveNotifyContainer[j], NotifyOp_Remove ); 1503cdf0e10cSrcweir for ( sal_uInt32 k = 0; k < aReplaceNotifyContainer.size(); k++ ) 1504cdf0e10cSrcweir implts_notifyContainerListener( aReplaceNotifyContainer[k], NotifyOp_Replace ); 1505cdf0e10cSrcweir } 1506cdf0e10cSrcweir } 1507cdf0e10cSrcweir 1508cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1509cdf0e10cSrcweir { 1510cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1511cdf0e10cSrcweir 1512cdf0e10cSrcweir if ( m_bDisposed ) 1513cdf0e10cSrcweir throw DisposedException(); 1514cdf0e10cSrcweir 1515cdf0e10cSrcweir if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly ) 1516cdf0e10cSrcweir { 1517cdf0e10cSrcweir // Try to access our module sub folder 1518cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir try 1521cdf0e10cSrcweir { 1522cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][i]; 1523cdf0e10cSrcweir Reference< XStorage > xStorage( rElementType.xStorage, UNO_QUERY ); 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir if ( rElementType.bModified && xStorage.is() ) 1526cdf0e10cSrcweir { 1527cdf0e10cSrcweir impl_storeElementTypeData( xStorage, rElementType ); 1528cdf0e10cSrcweir m_pStorageHandler[i]->commitUserChanges(); 1529cdf0e10cSrcweir } 1530cdf0e10cSrcweir } 1531cdf0e10cSrcweir catch ( Exception& ) 1532cdf0e10cSrcweir { 1533cdf0e10cSrcweir throw IOException(); 1534cdf0e10cSrcweir } 1535cdf0e10cSrcweir } 1536cdf0e10cSrcweir 1537cdf0e10cSrcweir m_bModified = false; 1538cdf0e10cSrcweir } 1539cdf0e10cSrcweir } 1540cdf0e10cSrcweir 1541cdf0e10cSrcweir void SAL_CALL ModuleUIConfigurationManager::storeToStorage( const Reference< XStorage >& Storage ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1542cdf0e10cSrcweir { 1543cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir if ( m_bDisposed ) 1546cdf0e10cSrcweir throw DisposedException(); 1547cdf0e10cSrcweir 1548cdf0e10cSrcweir if ( m_xUserConfigStorage.is() && m_bModified && !m_bReadOnly ) 1549cdf0e10cSrcweir { 1550cdf0e10cSrcweir // Try to access our module sub folder 1551cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1552cdf0e10cSrcweir { 1553cdf0e10cSrcweir try 1554cdf0e10cSrcweir { 1555cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage( Storage->openStorageElement( 1556cdf0e10cSrcweir OUString::createFromAscii( UIELEMENTTYPENAMES[i] ), ElementModes::READWRITE )); 1557cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[LAYER_USERDEFINED][i]; 1558cdf0e10cSrcweir 1559cdf0e10cSrcweir if ( rElementType.bModified && xElementTypeStorage.is() ) 1560cdf0e10cSrcweir impl_storeElementTypeData( xElementTypeStorage, rElementType, false ); // store data to storage, but don't reset modify flag! 1561cdf0e10cSrcweir } 1562cdf0e10cSrcweir catch ( Exception& ) 1563cdf0e10cSrcweir { 1564cdf0e10cSrcweir throw IOException(); 1565cdf0e10cSrcweir } 1566cdf0e10cSrcweir } 1567cdf0e10cSrcweir 1568cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( Storage, UNO_QUERY ); 1569cdf0e10cSrcweir if ( xTransactedObject.is() ) 1570cdf0e10cSrcweir xTransactedObject->commit(); 1571cdf0e10cSrcweir } 1572cdf0e10cSrcweir } 1573cdf0e10cSrcweir 1574cdf0e10cSrcweir sal_Bool SAL_CALL ModuleUIConfigurationManager::isModified() throw (::com::sun::star::uno::RuntimeException) 1575cdf0e10cSrcweir { 1576cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1577cdf0e10cSrcweir 1578cdf0e10cSrcweir return m_bModified; 1579cdf0e10cSrcweir } 1580cdf0e10cSrcweir 1581cdf0e10cSrcweir sal_Bool SAL_CALL ModuleUIConfigurationManager::isReadOnly() throw (::com::sun::star::uno::RuntimeException) 1582cdf0e10cSrcweir { 1583cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1584cdf0e10cSrcweir 1585cdf0e10cSrcweir return m_bReadOnly; 1586cdf0e10cSrcweir } 1587cdf0e10cSrcweir 1588cdf0e10cSrcweir void ModuleUIConfigurationManager::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp ) 1589cdf0e10cSrcweir { 1590cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer( ::getCppuType( ( const css::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >*) NULL ) ); 1591cdf0e10cSrcweir if ( pContainer != NULL ) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); 1594cdf0e10cSrcweir while ( pIterator.hasMoreElements() ) 1595cdf0e10cSrcweir { 1596cdf0e10cSrcweir try 1597cdf0e10cSrcweir { 1598cdf0e10cSrcweir switch ( eOp ) 1599cdf0e10cSrcweir { 1600cdf0e10cSrcweir case NotifyOp_Replace: 1601cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementReplaced( aEvent ); 1602cdf0e10cSrcweir break; 1603cdf0e10cSrcweir case NotifyOp_Insert: 1604cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementInserted( aEvent ); 1605cdf0e10cSrcweir break; 1606cdf0e10cSrcweir case NotifyOp_Remove: 1607cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementRemoved( aEvent ); 1608cdf0e10cSrcweir break; 1609cdf0e10cSrcweir } 1610cdf0e10cSrcweir } 1611cdf0e10cSrcweir catch( css::uno::RuntimeException& ) 1612cdf0e10cSrcweir { 1613cdf0e10cSrcweir pIterator.remove(); 1614cdf0e10cSrcweir } 1615cdf0e10cSrcweir } 1616cdf0e10cSrcweir } 1617cdf0e10cSrcweir } 1618cdf0e10cSrcweir 1619cdf0e10cSrcweir } // namespace framework 1620