1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_framework.hxx" 30*cdf0e10cSrcweir #include <uiconfiguration/uiconfigurationmanager.hxx> 31*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 32*cdf0e10cSrcweir #include <services.h> 33*cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx> 34*cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx> 35*cdf0e10cSrcweir #include <uielement/uielementtypenames.hxx> 36*cdf0e10cSrcweir #include <framework/menuconfiguration.hxx> 37*cdf0e10cSrcweir #include <framework/toolboxconfiguration.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #ifndef __FRAMEWORK_XML_STATUSBARCONFIGURATION_HXX_ 40*cdf0e10cSrcweir #include <framework/statusbarconfiguration.hxx> 41*cdf0e10cSrcweir #endif 42*cdf0e10cSrcweir 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir // interface includes 45*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 46*cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ui/ConfigurationEvent.hpp> 48*cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 49*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 50*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 51*cdf0e10cSrcweir #include <com/sun/star/embed/ElementModes.hpp> 52*cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp> 53*cdf0e10cSrcweir #include <com/sun/star/io/XStream.hpp> 54*cdf0e10cSrcweir #include <com/sun/star/embed/XTransactedObject.hpp> 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 57*cdf0e10cSrcweir // other includes 58*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir #include <vcl/svapp.hxx> 61*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx> 62*cdf0e10cSrcweir 63*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 64*cdf0e10cSrcweir // namespaces 65*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir using namespace com::sun::star::uno; 68*cdf0e10cSrcweir using namespace com::sun::star::io; 69*cdf0e10cSrcweir using namespace com::sun::star::embed; 70*cdf0e10cSrcweir using namespace com::sun::star::lang; 71*cdf0e10cSrcweir using namespace com::sun::star::container; 72*cdf0e10cSrcweir using namespace com::sun::star::beans; 73*cdf0e10cSrcweir using namespace ::com::sun::star::ui; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir namespace framework 76*cdf0e10cSrcweir { 77*cdf0e10cSrcweir 78*cdf0e10cSrcweir //***************************************************************************************************************** 79*cdf0e10cSrcweir // XInterface, XTypeProvider, XServiceInfo 80*cdf0e10cSrcweir //***************************************************************************************************************** 81*cdf0e10cSrcweir DEFINE_XINTERFACE_7 ( UIConfigurationManager , 82*cdf0e10cSrcweir OWeakObject , 83*cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XTypeProvider ), 84*cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XServiceInfo ), 85*cdf0e10cSrcweir DIRECT_INTERFACE( css::lang::XComponent ), 86*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfiguration ), 87*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationManager ), 88*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationPersistence ), 89*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationStorage ) 90*cdf0e10cSrcweir ) 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_7 ( UIConfigurationManager , 93*cdf0e10cSrcweir css::lang::XTypeProvider , 94*cdf0e10cSrcweir css::lang::XServiceInfo , 95*cdf0e10cSrcweir css::lang::XComponent , 96*cdf0e10cSrcweir ::com::sun::star::ui::XUIConfiguration , 97*cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationManager , 98*cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationPersistence , 99*cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationStorage 100*cdf0e10cSrcweir ) 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir DEFINE_XSERVICEINFO_MULTISERVICE ( UIConfigurationManager , 103*cdf0e10cSrcweir ::cppu::OWeakObject , 104*cdf0e10cSrcweir SERVICENAME_UICONFIGURATIONMANAGER , 105*cdf0e10cSrcweir IMPLEMENTATIONNAME_UICONFIGURATIONMANAGER 106*cdf0e10cSrcweir ) 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir DEFINE_INIT_SERVICE ( UIConfigurationManager, {} ) 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // important: The order and position of the elements must match the constant 112*cdf0e10cSrcweir // definition of "::com::sun::star::ui::UIElementType" 113*cdf0e10cSrcweir static const char* UIELEMENTTYPENAMES[] = 114*cdf0e10cSrcweir { 115*cdf0e10cSrcweir "", // Dummy value for unknown! 116*cdf0e10cSrcweir UIELEMENTTYPE_MENUBAR_NAME, 117*cdf0e10cSrcweir UIELEMENTTYPE_POPUPMENU_NAME, 118*cdf0e10cSrcweir UIELEMENTTYPE_TOOLBAR_NAME, 119*cdf0e10cSrcweir UIELEMENTTYPE_STATUSBAR_NAME, 120*cdf0e10cSrcweir UIELEMENTTYPE_FLOATINGWINDOW_NAME, 121*cdf0e10cSrcweir UIELEMENTTYPE_PROGRESSBAR_NAME, 122*cdf0e10cSrcweir UIELEMENTTYPE_TOOLPANEL_NAME 123*cdf0e10cSrcweir }; 124*cdf0e10cSrcweir 125*cdf0e10cSrcweir static const char RESOURCEURL_PREFIX[] = "private:resource/"; 126*cdf0e10cSrcweir static const sal_Int32 RESOURCEURL_PREFIX_SIZE = 17; 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir static sal_Int16 RetrieveTypeFromResourceURL( const rtl::OUString& aResourceURL ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir if (( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) && 132*cdf0e10cSrcweir ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir rtl::OUString aTmpStr = aResourceURL.copy( RESOURCEURL_PREFIX_SIZE ); 135*cdf0e10cSrcweir sal_Int32 nIndex = aTmpStr.indexOf( '/' ); 136*cdf0e10cSrcweir if (( nIndex > 0 ) && ( aTmpStr.getLength() > nIndex )) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir rtl::OUString aTypeStr( aTmpStr.copy( 0, nIndex )); 139*cdf0e10cSrcweir for ( int i = 0; i < UIElementType::COUNT; i++ ) 140*cdf0e10cSrcweir { 141*cdf0e10cSrcweir if ( aTypeStr.equalsAscii( UIELEMENTTYPENAMES[i] )) 142*cdf0e10cSrcweir return sal_Int16( i ); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir } 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir return UIElementType::UNKNOWN; 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir static rtl::OUString RetrieveNameFromResourceURL( const rtl::OUString& aResourceURL ) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir if (( aResourceURL.indexOf( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( RESOURCEURL_PREFIX ))) == 0 ) && 153*cdf0e10cSrcweir ( aResourceURL.getLength() > RESOURCEURL_PREFIX_SIZE )) 154*cdf0e10cSrcweir { 155*cdf0e10cSrcweir sal_Int32 nIndex = aResourceURL.lastIndexOf( '/' ); 156*cdf0e10cSrcweir if (( nIndex > 0 ) && (( nIndex+1 ) < aResourceURL.getLength())) 157*cdf0e10cSrcweir return aResourceURL.copy( nIndex+1 ); 158*cdf0e10cSrcweir } 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir return rtl::OUString(); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void UIConfigurationManager::impl_fillSequenceWithElementTypeInfo( UIElementInfoHashMap& aUIElementInfoCollection, sal_Int16 nElementType ) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // preload list of element types on demand 166*cdf0e10cSrcweir impl_preloadUIElementTypeList( nElementType ); 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir UIElementDataHashMap& rUserElements = m_aUIElements[nElementType].aElementsHashMap; 169*cdf0e10cSrcweir UIElementDataHashMap::const_iterator pUserIter = rUserElements.begin(); 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir while ( pUserIter != rUserElements.end() ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( pUserIter->second.aResourceURL, nElementType ); 174*cdf0e10cSrcweir if ( pDataSettings && !pDataSettings->bDefault ) 175*cdf0e10cSrcweir { 176*cdf0e10cSrcweir // Retrieve user interface name from XPropertySet interface 177*cdf0e10cSrcweir rtl::OUString aUIName; 178*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( pDataSettings->xSettings, UNO_QUERY ); 179*cdf0e10cSrcweir if ( xPropSet.is() ) 180*cdf0e10cSrcweir { 181*cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( m_aPropUIName ); 182*cdf0e10cSrcweir a >>= aUIName; 183*cdf0e10cSrcweir } 184*cdf0e10cSrcweir 185*cdf0e10cSrcweir UIElementInfo aInfo( pUserIter->second.aResourceURL, aUIName ); 186*cdf0e10cSrcweir aUIElementInfoCollection.insert( UIElementInfoHashMap::value_type( pUserIter->second.aResourceURL, aInfo )); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir ++pUserIter; 189*cdf0e10cSrcweir } 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir 192*cdf0e10cSrcweir void UIConfigurationManager::impl_preloadUIElementTypeList( sal_Int16 nElementType ) 193*cdf0e10cSrcweir { 194*cdf0e10cSrcweir UIElementType& rElementTypeData = m_aUIElements[nElementType]; 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir if ( !rElementTypeData.bLoaded ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage; 199*cdf0e10cSrcweir if ( xElementTypeStorage.is() ) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir rtl::OUStringBuffer aBuf( RESOURCEURL_PREFIX_SIZE ); 202*cdf0e10cSrcweir aBuf.appendAscii( RESOURCEURL_PREFIX ); 203*cdf0e10cSrcweir aBuf.appendAscii( UIELEMENTTYPENAMES[ nElementType ] ); 204*cdf0e10cSrcweir aBuf.appendAscii( "/" ); 205*cdf0e10cSrcweir rtl::OUString aResURLPrefix( aBuf.makeStringAndClear() ); 206*cdf0e10cSrcweir 207*cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rElementTypeData.aElementsHashMap; 208*cdf0e10cSrcweir Reference< XNameAccess > xNameAccess( xElementTypeStorage, UNO_QUERY ); 209*cdf0e10cSrcweir Sequence< rtl::OUString > aUIElementNames = xNameAccess->getElementNames(); 210*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aUIElementNames.getLength(); n++ ) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir UIElementData aUIElementData; 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir // Resource name must be without ".xml" 215*cdf0e10cSrcweir sal_Int32 nIndex = aUIElementNames[n].lastIndexOf( '.' ); 216*cdf0e10cSrcweir if (( nIndex > 0 ) && ( nIndex < aUIElementNames[n].getLength() )) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir rtl::OUString aExtension( aUIElementNames[n].copy( nIndex+1 )); 219*cdf0e10cSrcweir rtl::OUString aUIElementName( aUIElementNames[n].copy( 0, nIndex )); 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir if (( aUIElementName.getLength() > 0 ) && 222*cdf0e10cSrcweir ( aExtension.equalsIgnoreAsciiCaseAsciiL( "xml", 3 ))) 223*cdf0e10cSrcweir { 224*cdf0e10cSrcweir aUIElementData.aResourceURL = aResURLPrefix + aUIElementName; 225*cdf0e10cSrcweir aUIElementData.aName = aUIElementNames[n]; 226*cdf0e10cSrcweir aUIElementData.bModified = false; 227*cdf0e10cSrcweir aUIElementData.bDefault = false; 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir // Create hash_map entries for all user interface elements inside the storage. We don't load the 230*cdf0e10cSrcweir // settings to speed up the process. 231*cdf0e10cSrcweir rHashMap.insert( UIElementDataHashMap::value_type( aUIElementData.aResourceURL, aUIElementData )); 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir } 234*cdf0e10cSrcweir } 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir rElementTypeData.bLoaded = true; 239*cdf0e10cSrcweir } 240*cdf0e10cSrcweir 241*cdf0e10cSrcweir void UIConfigurationManager::impl_requestUIElementData( sal_Int16 nElementType, UIElementData& aUIElementData ) 242*cdf0e10cSrcweir { 243*cdf0e10cSrcweir UIElementType& rElementTypeData = m_aUIElements[nElementType]; 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage = rElementTypeData.xStorage; 246*cdf0e10cSrcweir if ( xElementTypeStorage.is() && aUIElementData.aName.getLength() ) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir try 249*cdf0e10cSrcweir { 250*cdf0e10cSrcweir Reference< XStream > xStream = xElementTypeStorage->openStreamElement( aUIElementData.aName, ElementModes::READ ); 251*cdf0e10cSrcweir Reference< XInputStream > xInputStream = xStream->getInputStream(); 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir if ( xInputStream.is() ) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir switch ( nElementType ) 256*cdf0e10cSrcweir { 257*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::UNKNOWN: 258*cdf0e10cSrcweir break; 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::MENUBAR: 261*cdf0e10cSrcweir { 262*cdf0e10cSrcweir try 263*cdf0e10cSrcweir { 264*cdf0e10cSrcweir MenuConfiguration aMenuCfg( m_xServiceManager ); 265*cdf0e10cSrcweir Reference< XIndexAccess > xContainer( aMenuCfg.CreateMenuBarConfigurationFromXML( xInputStream )); 266*cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xContainer ); 267*cdf0e10cSrcweir if ( pRootItemContainer ) 268*cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 269*cdf0e10cSrcweir else 270*cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( xContainer, sal_True ) ), UNO_QUERY ); 271*cdf0e10cSrcweir return; 272*cdf0e10cSrcweir } 273*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 274*cdf0e10cSrcweir { 275*cdf0e10cSrcweir } 276*cdf0e10cSrcweir } 277*cdf0e10cSrcweir break; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::POPUPMENU: 280*cdf0e10cSrcweir { 281*cdf0e10cSrcweir break; 282*cdf0e10cSrcweir } 283*cdf0e10cSrcweir 284*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::TOOLBAR: 285*cdf0e10cSrcweir { 286*cdf0e10cSrcweir try 287*cdf0e10cSrcweir { 288*cdf0e10cSrcweir Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY ); 289*cdf0e10cSrcweir ToolBoxConfiguration::LoadToolBox( m_xServiceManager, xInputStream, xIndexContainer ); 290*cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer ); 291*cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 292*cdf0e10cSrcweir return; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 295*cdf0e10cSrcweir { 296*cdf0e10cSrcweir } 297*cdf0e10cSrcweir 298*cdf0e10cSrcweir break; 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::STATUSBAR: 302*cdf0e10cSrcweir { 303*cdf0e10cSrcweir try 304*cdf0e10cSrcweir { 305*cdf0e10cSrcweir Reference< XIndexContainer > xIndexContainer( static_cast< OWeakObject * >( new RootItemContainer() ), UNO_QUERY ); 306*cdf0e10cSrcweir StatusBarConfiguration::LoadStatusBar( m_xServiceManager, xInputStream, xIndexContainer ); 307*cdf0e10cSrcweir RootItemContainer* pRootItemContainer = RootItemContainer::GetImplementation( xIndexContainer ); 308*cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( pRootItemContainer, sal_True ) ), UNO_QUERY ); 309*cdf0e10cSrcweir return; 310*cdf0e10cSrcweir } 311*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 312*cdf0e10cSrcweir { 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir break; 316*cdf0e10cSrcweir } 317*cdf0e10cSrcweir 318*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::FLOATINGWINDOW: 319*cdf0e10cSrcweir { 320*cdf0e10cSrcweir break; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir } 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir } 331*cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir } 334*cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 335*cdf0e10cSrcweir { 336*cdf0e10cSrcweir } 337*cdf0e10cSrcweir } 338*cdf0e10cSrcweir 339*cdf0e10cSrcweir // At least we provide an empty settings container! 340*cdf0e10cSrcweir aUIElementData.xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer()), UNO_QUERY ); 341*cdf0e10cSrcweir } 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir UIConfigurationManager::UIElementData* UIConfigurationManager::impl_findUIElementData( const rtl::OUString& aResourceURL, sal_Int16 nElementType, bool bLoad ) 344*cdf0e10cSrcweir { 345*cdf0e10cSrcweir // preload list of element types on demand 346*cdf0e10cSrcweir impl_preloadUIElementTypeList( nElementType ); 347*cdf0e10cSrcweir 348*cdf0e10cSrcweir // try to look into our document vector/hash_map combination 349*cdf0e10cSrcweir UIElementDataHashMap& rUserHashMap = m_aUIElements[nElementType].aElementsHashMap; 350*cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rUserHashMap.find( aResourceURL ); 351*cdf0e10cSrcweir if ( pIter != rUserHashMap.end() ) 352*cdf0e10cSrcweir { 353*cdf0e10cSrcweir // Default data settings data means removed! 354*cdf0e10cSrcweir if ( pIter->second.bDefault ) 355*cdf0e10cSrcweir return &(pIter->second); 356*cdf0e10cSrcweir else 357*cdf0e10cSrcweir { 358*cdf0e10cSrcweir if ( !pIter->second.xSettings.is() && bLoad ) 359*cdf0e10cSrcweir impl_requestUIElementData( nElementType, pIter->second ); 360*cdf0e10cSrcweir return &(pIter->second); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir } 363*cdf0e10cSrcweir 364*cdf0e10cSrcweir // Nothing has been found! 365*cdf0e10cSrcweir return NULL; 366*cdf0e10cSrcweir } 367*cdf0e10cSrcweir 368*cdf0e10cSrcweir void UIConfigurationManager::impl_storeElementTypeData( Reference< XStorage >& xStorage, UIElementType& rElementType, bool bResetModifyState ) 369*cdf0e10cSrcweir { 370*cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rElementType.aElementsHashMap; 371*cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 372*cdf0e10cSrcweir 373*cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 374*cdf0e10cSrcweir { 375*cdf0e10cSrcweir UIElementData& rElement = pIter->second; 376*cdf0e10cSrcweir if ( rElement.bModified ) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir if ( rElement.bDefault ) 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir xStorage->removeElement( rElement.aName ); 381*cdf0e10cSrcweir rElement.bModified = sal_False; // mark as not modified 382*cdf0e10cSrcweir } 383*cdf0e10cSrcweir else 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir Reference< XStream > xStream( xStorage->openStreamElement( rElement.aName, ElementModes::WRITE|ElementModes::TRUNCATE ), UNO_QUERY ); 386*cdf0e10cSrcweir Reference< XOutputStream > xOutputStream( xStream->getOutputStream() ); 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir if ( xOutputStream.is() ) 389*cdf0e10cSrcweir { 390*cdf0e10cSrcweir switch( rElementType.nElementType ) 391*cdf0e10cSrcweir { 392*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::MENUBAR: 393*cdf0e10cSrcweir { 394*cdf0e10cSrcweir try 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir MenuConfiguration aMenuCfg( m_xServiceManager ); 397*cdf0e10cSrcweir aMenuCfg.StoreMenuBarConfigurationToXML( rElement.xSettings, xOutputStream ); 398*cdf0e10cSrcweir } 399*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir } 402*cdf0e10cSrcweir } 403*cdf0e10cSrcweir break; 404*cdf0e10cSrcweir 405*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::TOOLBAR: 406*cdf0e10cSrcweir { 407*cdf0e10cSrcweir try 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir ToolBoxConfiguration::StoreToolBox( m_xServiceManager, xOutputStream, rElement.xSettings ); 410*cdf0e10cSrcweir } 411*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 412*cdf0e10cSrcweir { 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir } 415*cdf0e10cSrcweir break; 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir case ::com::sun::star::ui::UIElementType::STATUSBAR: 418*cdf0e10cSrcweir { 419*cdf0e10cSrcweir try 420*cdf0e10cSrcweir { 421*cdf0e10cSrcweir StatusBarConfiguration::StoreStatusBar( m_xServiceManager, xOutputStream, rElement.xSettings ); 422*cdf0e10cSrcweir } 423*cdf0e10cSrcweir catch ( ::com::sun::star::lang::WrappedTargetException& ) 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir } 427*cdf0e10cSrcweir break; 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir default: 430*cdf0e10cSrcweir break; 431*cdf0e10cSrcweir } 432*cdf0e10cSrcweir } 433*cdf0e10cSrcweir 434*cdf0e10cSrcweir // mark as not modified if we store to our own storage 435*cdf0e10cSrcweir if ( bResetModifyState ) 436*cdf0e10cSrcweir rElement.bModified = sal_False; 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir } 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir ++pIter; 441*cdf0e10cSrcweir } 442*cdf0e10cSrcweir 443*cdf0e10cSrcweir // commit element type storage 444*cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( xStorage, UNO_QUERY ); 445*cdf0e10cSrcweir if ( xTransactedObject.is() ) 446*cdf0e10cSrcweir xTransactedObject->commit(); 447*cdf0e10cSrcweir 448*cdf0e10cSrcweir // mark UIElementType as not modified if we store to our own storage 449*cdf0e10cSrcweir if ( bResetModifyState ) 450*cdf0e10cSrcweir rElementType.bModified = sal_False; 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir void UIConfigurationManager::impl_resetElementTypeData( 454*cdf0e10cSrcweir UIElementType& rDocElementType, 455*cdf0e10cSrcweir ConfigEventNotifyContainer& rRemoveNotifyContainer ) 456*cdf0e10cSrcweir { 457*cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rDocElementType.aElementsHashMap; 458*cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 459*cdf0e10cSrcweir 460*cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 461*cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 462*cdf0e10cSrcweir 463*cdf0e10cSrcweir // Make copies of the event structures to be thread-safe. We have to unlock our mutex before calling 464*cdf0e10cSrcweir // our listeners! 465*cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 466*cdf0e10cSrcweir { 467*cdf0e10cSrcweir UIElementData& rElement = pIter->second; 468*cdf0e10cSrcweir if ( !rElement.bDefault ) 469*cdf0e10cSrcweir { 470*cdf0e10cSrcweir // Remove user-defined settings from document 471*cdf0e10cSrcweir ConfigurationEvent aEvent; 472*cdf0e10cSrcweir aEvent.ResourceURL = rElement.aResourceURL; 473*cdf0e10cSrcweir aEvent.Accessor <<= xThis; 474*cdf0e10cSrcweir aEvent.Source = xIfac; 475*cdf0e10cSrcweir aEvent.Element <<= rElement.xSettings; 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir rRemoveNotifyContainer.push_back( aEvent ); 478*cdf0e10cSrcweir 479*cdf0e10cSrcweir // Mark element as default. 480*cdf0e10cSrcweir rElement.bModified = false; 481*cdf0e10cSrcweir rElement.bDefault = true; 482*cdf0e10cSrcweir } 483*cdf0e10cSrcweir else 484*cdf0e10cSrcweir rElement.bModified = false; 485*cdf0e10cSrcweir 486*cdf0e10cSrcweir ++pIter; 487*cdf0e10cSrcweir } 488*cdf0e10cSrcweir 489*cdf0e10cSrcweir // Remove all settings from our user interface elements 490*cdf0e10cSrcweir rHashMap.clear(); 491*cdf0e10cSrcweir } 492*cdf0e10cSrcweir 493*cdf0e10cSrcweir void UIConfigurationManager::impl_reloadElementTypeData( 494*cdf0e10cSrcweir UIElementType& rDocElementType, 495*cdf0e10cSrcweir ConfigEventNotifyContainer& rRemoveNotifyContainer, 496*cdf0e10cSrcweir ConfigEventNotifyContainer& rReplaceNotifyContainer ) 497*cdf0e10cSrcweir { 498*cdf0e10cSrcweir UIElementDataHashMap& rHashMap = rDocElementType.aElementsHashMap; 499*cdf0e10cSrcweir UIElementDataHashMap::iterator pIter = rHashMap.begin(); 500*cdf0e10cSrcweir Reference< XStorage > xElementStorage( rDocElementType.xStorage ); 501*cdf0e10cSrcweir Reference< XNameAccess > xElementNameAccess( xElementStorage, UNO_QUERY ); 502*cdf0e10cSrcweir 503*cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 504*cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 505*cdf0e10cSrcweir sal_Int16 nType = rDocElementType.nElementType; 506*cdf0e10cSrcweir 507*cdf0e10cSrcweir while ( pIter != rHashMap.end() ) 508*cdf0e10cSrcweir { 509*cdf0e10cSrcweir UIElementData& rElement = pIter->second; 510*cdf0e10cSrcweir if ( rElement.bModified ) 511*cdf0e10cSrcweir { 512*cdf0e10cSrcweir if ( xElementNameAccess->hasByName( rElement.aName )) 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir // Replace settings with data from user layer 515*cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings( rElement.xSettings ); 516*cdf0e10cSrcweir 517*cdf0e10cSrcweir impl_requestUIElementData( nType, rElement ); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir ConfigurationEvent aReplaceEvent; 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir aReplaceEvent.ResourceURL = rElement.aResourceURL; 522*cdf0e10cSrcweir aReplaceEvent.Accessor <<= xThis; 523*cdf0e10cSrcweir aReplaceEvent.Source = xIfac; 524*cdf0e10cSrcweir aReplaceEvent.ReplacedElement <<= xOldSettings; 525*cdf0e10cSrcweir aReplaceEvent.Element <<= rElement.xSettings; 526*cdf0e10cSrcweir rReplaceNotifyContainer.push_back( aReplaceEvent ); 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir rElement.bModified = false; 529*cdf0e10cSrcweir } 530*cdf0e10cSrcweir else 531*cdf0e10cSrcweir { 532*cdf0e10cSrcweir // Element settings are not in any storage => remove 533*cdf0e10cSrcweir ConfigurationEvent aRemoveEvent; 534*cdf0e10cSrcweir 535*cdf0e10cSrcweir aRemoveEvent.ResourceURL = rElement.aResourceURL; 536*cdf0e10cSrcweir aRemoveEvent.Accessor <<= xThis; 537*cdf0e10cSrcweir aRemoveEvent.Source = xIfac; 538*cdf0e10cSrcweir aRemoveEvent.Element <<= rElement.xSettings; 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir rRemoveNotifyContainer.push_back( aRemoveEvent ); 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // Mark element as default and not modified. That means "not active" in the document anymore 543*cdf0e10cSrcweir rElement.bModified = false; 544*cdf0e10cSrcweir rElement.bDefault = true; 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir } 547*cdf0e10cSrcweir ++pIter; 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir rDocElementType.bModified = sal_False; 551*cdf0e10cSrcweir } 552*cdf0e10cSrcweir 553*cdf0e10cSrcweir void UIConfigurationManager::impl_Initialize() 554*cdf0e10cSrcweir { 555*cdf0e10cSrcweir // Initialize the top-level structures with the storage data 556*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() ) 557*cdf0e10cSrcweir { 558*cdf0e10cSrcweir long nModes = m_bReadOnly ? ElementModes::READ : ElementModes::READWRITE; 559*cdf0e10cSrcweir 560*cdf0e10cSrcweir // Try to access our module sub folder 561*cdf0e10cSrcweir for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; 562*cdf0e10cSrcweir i++ ) 563*cdf0e10cSrcweir { 564*cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage; 565*cdf0e10cSrcweir try 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir xElementTypeStorage = m_xDocConfigStorage->openStorageElement( rtl::OUString::createFromAscii( UIELEMENTTYPENAMES[i] ), nModes ); 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir catch ( com::sun::star::container::NoSuchElementException& ) 570*cdf0e10cSrcweir { 571*cdf0e10cSrcweir } 572*cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 573*cdf0e10cSrcweir { 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 576*cdf0e10cSrcweir { 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir catch ( ::com::sun::star::io::IOException& ) 579*cdf0e10cSrcweir { 580*cdf0e10cSrcweir } 581*cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 582*cdf0e10cSrcweir { 583*cdf0e10cSrcweir } 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir m_aUIElements[i].nElementType = i; 586*cdf0e10cSrcweir m_aUIElements[i].bModified = false; 587*cdf0e10cSrcweir m_aUIElements[i].xStorage = xElementTypeStorage; 588*cdf0e10cSrcweir m_aUIElements[i].bDefaultLayer = false; 589*cdf0e10cSrcweir } 590*cdf0e10cSrcweir } 591*cdf0e10cSrcweir else 592*cdf0e10cSrcweir { 593*cdf0e10cSrcweir // We have no storage, just initialize ui element types with empty storage! 594*cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 595*cdf0e10cSrcweir m_aUIElements[i].xStorage = m_xDocConfigStorage; 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir UIConfigurationManager::UIConfigurationManager( com::sun::star::uno::Reference< com::sun::star::lang::XMultiServiceFactory > xServiceManager ) : 600*cdf0e10cSrcweir ThreadHelpBase( &Application::GetSolarMutex() ) 601*cdf0e10cSrcweir , m_xDocConfigStorage( 0 ) 602*cdf0e10cSrcweir , m_bReadOnly( true ) 603*cdf0e10cSrcweir , m_bInitialized( false ) 604*cdf0e10cSrcweir , m_bModified( false ) 605*cdf0e10cSrcweir , m_bConfigRead( false ) 606*cdf0e10cSrcweir , m_bDisposed( false ) 607*cdf0e10cSrcweir , m_aXMLPostfix( RTL_CONSTASCII_USTRINGPARAM( ".xml" )) 608*cdf0e10cSrcweir , m_aPropUIName( RTL_CONSTASCII_USTRINGPARAM( "UIName" )) 609*cdf0e10cSrcweir , m_aPropResourceURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )) 610*cdf0e10cSrcweir , m_xServiceManager( xServiceManager ) 611*cdf0e10cSrcweir , m_aListenerContainer( m_aLock.getShareableOslMutex() ) 612*cdf0e10cSrcweir { 613*cdf0e10cSrcweir // Make sure we have a default initialized entry for every layer and user interface element type! 614*cdf0e10cSrcweir // The following code depends on this! 615*cdf0e10cSrcweir m_aUIElements.resize( ::com::sun::star::ui::UIElementType::COUNT ); 616*cdf0e10cSrcweir } 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir UIConfigurationManager::~UIConfigurationManager() 619*cdf0e10cSrcweir { 620*cdf0e10cSrcweir } 621*cdf0e10cSrcweir 622*cdf0e10cSrcweir // XComponent 623*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::dispose() throw (::com::sun::star::uno::RuntimeException) 624*cdf0e10cSrcweir { 625*cdf0e10cSrcweir Reference< XComponent > xThis( static_cast< OWeakObject* >(this), UNO_QUERY ); 626*cdf0e10cSrcweir 627*cdf0e10cSrcweir css::lang::EventObject aEvent( xThis ); 628*cdf0e10cSrcweir m_aListenerContainer.disposeAndClear( aEvent ); 629*cdf0e10cSrcweir 630*cdf0e10cSrcweir { 631*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 632*cdf0e10cSrcweir try 633*cdf0e10cSrcweir { 634*cdf0e10cSrcweir if ( m_xImageManager.is() ) 635*cdf0e10cSrcweir m_xImageManager->dispose(); 636*cdf0e10cSrcweir } 637*cdf0e10cSrcweir catch ( Exception& ) 638*cdf0e10cSrcweir { 639*cdf0e10cSrcweir } 640*cdf0e10cSrcweir 641*cdf0e10cSrcweir m_xImageManager.clear(); 642*cdf0e10cSrcweir m_aUIElements.clear(); 643*cdf0e10cSrcweir m_xDocConfigStorage.clear(); 644*cdf0e10cSrcweir m_bConfigRead = false; 645*cdf0e10cSrcweir m_bModified = false; 646*cdf0e10cSrcweir m_bDisposed = true; 647*cdf0e10cSrcweir } 648*cdf0e10cSrcweir } 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::addEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 651*cdf0e10cSrcweir { 652*cdf0e10cSrcweir { 653*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 656*cdf0e10cSrcweir if ( m_bDisposed ) 657*cdf0e10cSrcweir throw DisposedException(); 658*cdf0e10cSrcweir } 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 661*cdf0e10cSrcweir } 662*cdf0e10cSrcweir 663*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::removeEventListener( const Reference< XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 664*cdf0e10cSrcweir { 665*cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 666*cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XEventListener >* ) NULL ), xListener ); 667*cdf0e10cSrcweir } 668*cdf0e10cSrcweir 669*cdf0e10cSrcweir // XUIConfigurationManager 670*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::addConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 671*cdf0e10cSrcweir { 672*cdf0e10cSrcweir { 673*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 674*cdf0e10cSrcweir 675*cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 676*cdf0e10cSrcweir if ( m_bDisposed ) 677*cdf0e10cSrcweir throw DisposedException(); 678*cdf0e10cSrcweir } 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener ); 681*cdf0e10cSrcweir } 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::removeConfigurationListener( const Reference< ::com::sun::star::ui::XUIConfigurationListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 684*cdf0e10cSrcweir { 685*cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 686*cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const Reference< XUIConfigurationListener >* ) NULL ), xListener ); 687*cdf0e10cSrcweir } 688*cdf0e10cSrcweir 689*cdf0e10cSrcweir 690*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::reset() throw (::com::sun::star::uno::RuntimeException) 691*cdf0e10cSrcweir { 692*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir /* SAFE AREA ----------------------------------------------------------------------------------------------- */ 695*cdf0e10cSrcweir if ( m_bDisposed ) 696*cdf0e10cSrcweir throw DisposedException(); 697*cdf0e10cSrcweir 698*cdf0e10cSrcweir if ( isReadOnly() ) 699*cdf0e10cSrcweir return; 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir bool bResetStorage( false ); 702*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() ) 703*cdf0e10cSrcweir { 704*cdf0e10cSrcweir try 705*cdf0e10cSrcweir { 706*cdf0e10cSrcweir // Remove all elements from our user-defined storage! 707*cdf0e10cSrcweir bool bCommit( false ); 708*cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 709*cdf0e10cSrcweir { 710*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[i]; 711*cdf0e10cSrcweir Reference< XStorage > xSubStorage( rElementType.xStorage, UNO_QUERY ); 712*cdf0e10cSrcweir 713*cdf0e10cSrcweir if ( xSubStorage.is() ) 714*cdf0e10cSrcweir { 715*cdf0e10cSrcweir bool bCommitSubStorage( false ); 716*cdf0e10cSrcweir Reference< XNameAccess > xSubStorageNameAccess( xSubStorage, UNO_QUERY ); 717*cdf0e10cSrcweir Sequence< rtl::OUString > aUIElementStreamNames = xSubStorageNameAccess->getElementNames(); 718*cdf0e10cSrcweir for ( sal_Int32 j = 0; j < aUIElementStreamNames.getLength(); j++ ) 719*cdf0e10cSrcweir { 720*cdf0e10cSrcweir xSubStorage->removeElement( aUIElementStreamNames[j] ); 721*cdf0e10cSrcweir bCommitSubStorage = true; 722*cdf0e10cSrcweir bCommit = true; 723*cdf0e10cSrcweir } 724*cdf0e10cSrcweir 725*cdf0e10cSrcweir if ( bCommitSubStorage ) 726*cdf0e10cSrcweir { 727*cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( xSubStorage, UNO_QUERY ); 728*cdf0e10cSrcweir if ( xTransactedObject.is() ) 729*cdf0e10cSrcweir xTransactedObject->commit(); 730*cdf0e10cSrcweir } 731*cdf0e10cSrcweir } 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir // Commit changes 735*cdf0e10cSrcweir if ( bCommit ) 736*cdf0e10cSrcweir { 737*cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( m_xDocConfigStorage, UNO_QUERY ); 738*cdf0e10cSrcweir if ( xTransactedObject.is() ) 739*cdf0e10cSrcweir xTransactedObject->commit(); 740*cdf0e10cSrcweir } 741*cdf0e10cSrcweir bResetStorage = true; 742*cdf0e10cSrcweir 743*cdf0e10cSrcweir // remove settings from user defined layer and notify listener about removed settings data! 744*cdf0e10cSrcweir // Try to access our module sub folder 745*cdf0e10cSrcweir ConfigEventNotifyContainer aRemoveEventNotifyContainer; 746*cdf0e10cSrcweir for ( sal_Int16 j = 1; j < ::com::sun::star::ui::UIElementType::COUNT; j++ ) 747*cdf0e10cSrcweir { 748*cdf0e10cSrcweir UIElementType& rDocElementType = m_aUIElements[j]; 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir impl_resetElementTypeData( rDocElementType, aRemoveEventNotifyContainer ); 751*cdf0e10cSrcweir rDocElementType.bModified = sal_False; 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir 754*cdf0e10cSrcweir m_bModified = sal_False; 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir // Unlock mutex before notify our listeners 757*cdf0e10cSrcweir aGuard.unlock(); 758*cdf0e10cSrcweir 759*cdf0e10cSrcweir // Notify our listeners 760*cdf0e10cSrcweir for ( sal_uInt32 k = 0; k < aRemoveEventNotifyContainer.size(); k++ ) 761*cdf0e10cSrcweir implts_notifyContainerListener( aRemoveEventNotifyContainer[k], NotifyOp_Remove ); 762*cdf0e10cSrcweir } 763*cdf0e10cSrcweir catch ( ::com::sun::star::lang::IllegalArgumentException& ) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir } 766*cdf0e10cSrcweir catch ( ::com::sun::star::container::NoSuchElementException& ) 767*cdf0e10cSrcweir { 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir catch ( ::com::sun::star::embed::InvalidStorageException& ) 770*cdf0e10cSrcweir { 771*cdf0e10cSrcweir } 772*cdf0e10cSrcweir catch ( ::com::sun::star::embed::StorageWrappedTargetException& ) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir } 775*cdf0e10cSrcweir } 776*cdf0e10cSrcweir } 777*cdf0e10cSrcweir 778*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > SAL_CALL UIConfigurationManager::getUIElementsInfo( sal_Int16 ElementType ) 779*cdf0e10cSrcweir throw ( IllegalArgumentException, RuntimeException ) 780*cdf0e10cSrcweir { 781*cdf0e10cSrcweir if (( ElementType < 0 ) || ( ElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 782*cdf0e10cSrcweir throw IllegalArgumentException(); 783*cdf0e10cSrcweir 784*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 785*cdf0e10cSrcweir if ( m_bDisposed ) 786*cdf0e10cSrcweir throw DisposedException(); 787*cdf0e10cSrcweir 788*cdf0e10cSrcweir Sequence< Sequence< PropertyValue > > aElementInfoSeq; 789*cdf0e10cSrcweir UIElementInfoHashMap aUIElementInfoCollection; 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir if ( ElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) 792*cdf0e10cSrcweir { 793*cdf0e10cSrcweir for ( sal_Int16 i = 0; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 794*cdf0e10cSrcweir impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, sal_Int16( i ) ); 795*cdf0e10cSrcweir } 796*cdf0e10cSrcweir else 797*cdf0e10cSrcweir impl_fillSequenceWithElementTypeInfo( aUIElementInfoCollection, ElementType ); 798*cdf0e10cSrcweir 799*cdf0e10cSrcweir Sequence< PropertyValue > aUIElementInfo( 2 ); 800*cdf0e10cSrcweir aUIElementInfo[0].Name = m_aPropResourceURL; 801*cdf0e10cSrcweir aUIElementInfo[1].Name = m_aPropUIName; 802*cdf0e10cSrcweir 803*cdf0e10cSrcweir aElementInfoSeq.realloc( aUIElementInfoCollection.size() ); 804*cdf0e10cSrcweir UIElementInfoHashMap::const_iterator pIter = aUIElementInfoCollection.begin(); 805*cdf0e10cSrcweir 806*cdf0e10cSrcweir sal_Int32 n = 0; 807*cdf0e10cSrcweir while ( pIter != aUIElementInfoCollection.end() ) 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir aUIElementInfo[0].Value <<= pIter->second.aResourceURL; 810*cdf0e10cSrcweir aUIElementInfo[1].Value <<= pIter->second.aUIName; 811*cdf0e10cSrcweir aElementInfoSeq[n++] = aUIElementInfo; 812*cdf0e10cSrcweir ++pIter; 813*cdf0e10cSrcweir } 814*cdf0e10cSrcweir 815*cdf0e10cSrcweir return aElementInfoSeq; 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir 818*cdf0e10cSrcweir Reference< XIndexContainer > SAL_CALL UIConfigurationManager::createSettings() throw (::com::sun::star::uno::RuntimeException) 819*cdf0e10cSrcweir { 820*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 821*cdf0e10cSrcweir 822*cdf0e10cSrcweir if ( m_bDisposed ) 823*cdf0e10cSrcweir throw DisposedException(); 824*cdf0e10cSrcweir 825*cdf0e10cSrcweir // Creates an empty item container which can be filled from outside 826*cdf0e10cSrcweir return Reference< XIndexContainer >( static_cast< OWeakObject * >( new RootItemContainer()), UNO_QUERY ); 827*cdf0e10cSrcweir } 828*cdf0e10cSrcweir 829*cdf0e10cSrcweir sal_Bool SAL_CALL UIConfigurationManager::hasSettings( const ::rtl::OUString& ResourceURL ) 830*cdf0e10cSrcweir throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 831*cdf0e10cSrcweir { 832*cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 835*cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 836*cdf0e10cSrcweir throw IllegalArgumentException(); 837*cdf0e10cSrcweir else 838*cdf0e10cSrcweir { 839*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType, false ); 840*cdf0e10cSrcweir if ( pDataSettings && !pDataSettings->bDefault ) 841*cdf0e10cSrcweir return sal_True; 842*cdf0e10cSrcweir } 843*cdf0e10cSrcweir 844*cdf0e10cSrcweir return sal_False; 845*cdf0e10cSrcweir } 846*cdf0e10cSrcweir 847*cdf0e10cSrcweir Reference< XIndexAccess > SAL_CALL UIConfigurationManager::getSettings( const ::rtl::OUString& ResourceURL, sal_Bool bWriteable ) 848*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException) 849*cdf0e10cSrcweir { 850*cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 853*cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 854*cdf0e10cSrcweir throw IllegalArgumentException(); 855*cdf0e10cSrcweir else 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 858*cdf0e10cSrcweir 859*cdf0e10cSrcweir if ( m_bDisposed ) 860*cdf0e10cSrcweir throw DisposedException(); 861*cdf0e10cSrcweir 862*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 863*cdf0e10cSrcweir if ( pDataSettings && !pDataSettings->bDefault ) 864*cdf0e10cSrcweir { 865*cdf0e10cSrcweir // Create a copy of our data if someone wants to change the data. 866*cdf0e10cSrcweir if ( bWriteable ) 867*cdf0e10cSrcweir return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( pDataSettings->xSettings ) ), UNO_QUERY ); 868*cdf0e10cSrcweir else 869*cdf0e10cSrcweir return pDataSettings->xSettings; 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir } 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir throw NoSuchElementException(); 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::replaceSettings( const ::rtl::OUString& ResourceURL, const Reference< ::com::sun::star::container::XIndexAccess >& aNewData ) 877*cdf0e10cSrcweir throw (::com::sun::star::container::NoSuchElementException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::IllegalAccessException, ::com::sun::star::uno::RuntimeException) 878*cdf0e10cSrcweir { 879*cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 880*cdf0e10cSrcweir 881*cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 882*cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 883*cdf0e10cSrcweir throw IllegalArgumentException(); 884*cdf0e10cSrcweir else if ( m_bReadOnly ) 885*cdf0e10cSrcweir throw IllegalAccessException(); 886*cdf0e10cSrcweir else 887*cdf0e10cSrcweir { 888*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 889*cdf0e10cSrcweir 890*cdf0e10cSrcweir if ( m_bDisposed ) 891*cdf0e10cSrcweir throw DisposedException(); 892*cdf0e10cSrcweir 893*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 894*cdf0e10cSrcweir if ( pDataSettings && !pDataSettings->bDefault ) 895*cdf0e10cSrcweir { 896*cdf0e10cSrcweir // we have a settings entry in our user-defined layer - replace 897*cdf0e10cSrcweir Reference< XIndexAccess > xOldSettings = pDataSettings->xSettings; 898*cdf0e10cSrcweir 899*cdf0e10cSrcweir // Create a copy of the data if the container is not const 900*cdf0e10cSrcweir Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY ); 901*cdf0e10cSrcweir if ( xReplace.is() ) 902*cdf0e10cSrcweir pDataSettings->xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY ); 903*cdf0e10cSrcweir else 904*cdf0e10cSrcweir pDataSettings->xSettings = aNewData; 905*cdf0e10cSrcweir 906*cdf0e10cSrcweir pDataSettings->bDefault = false; 907*cdf0e10cSrcweir pDataSettings->bModified = true; 908*cdf0e10cSrcweir m_bModified = true; 909*cdf0e10cSrcweir 910*cdf0e10cSrcweir // Modify type container 911*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[nElementType]; 912*cdf0e10cSrcweir rElementType.bModified = true; 913*cdf0e10cSrcweir 914*cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 915*cdf0e10cSrcweir 916*cdf0e10cSrcweir // Create event to notify listener about replaced element settings 917*cdf0e10cSrcweir ConfigurationEvent aEvent; 918*cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 921*cdf0e10cSrcweir aEvent.Accessor <<= xThis; 922*cdf0e10cSrcweir aEvent.Source = xIfac; 923*cdf0e10cSrcweir aEvent.ReplacedElement <<= xOldSettings; 924*cdf0e10cSrcweir aEvent.Element <<= pDataSettings->xSettings; 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir aGuard.unlock(); 927*cdf0e10cSrcweir 928*cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Replace ); 929*cdf0e10cSrcweir } 930*cdf0e10cSrcweir else 931*cdf0e10cSrcweir throw NoSuchElementException(); 932*cdf0e10cSrcweir } 933*cdf0e10cSrcweir } 934*cdf0e10cSrcweir 935*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::removeSettings( const ::rtl::OUString& ResourceURL ) 936*cdf0e10cSrcweir throw ( NoSuchElementException, IllegalArgumentException, IllegalAccessException, RuntimeException) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( ResourceURL ); 939*cdf0e10cSrcweir 940*cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 941*cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 942*cdf0e10cSrcweir throw IllegalArgumentException(); 943*cdf0e10cSrcweir else if ( m_bReadOnly ) 944*cdf0e10cSrcweir throw IllegalAccessException(); 945*cdf0e10cSrcweir else 946*cdf0e10cSrcweir { 947*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 948*cdf0e10cSrcweir 949*cdf0e10cSrcweir if ( m_bDisposed ) 950*cdf0e10cSrcweir throw DisposedException(); 951*cdf0e10cSrcweir 952*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( ResourceURL, nElementType ); 953*cdf0e10cSrcweir if ( pDataSettings ) 954*cdf0e10cSrcweir { 955*cdf0e10cSrcweir // If element settings are default, we don't need to change anything! 956*cdf0e10cSrcweir if ( pDataSettings->bDefault ) 957*cdf0e10cSrcweir return; 958*cdf0e10cSrcweir else 959*cdf0e10cSrcweir { 960*cdf0e10cSrcweir Reference< XIndexAccess > xRemovedSettings = pDataSettings->xSettings; 961*cdf0e10cSrcweir pDataSettings->bDefault = true; 962*cdf0e10cSrcweir 963*cdf0e10cSrcweir // check if this is a default layer node 964*cdf0e10cSrcweir pDataSettings->bModified = true; // we have to remove this node from the user layer! 965*cdf0e10cSrcweir pDataSettings->xSettings.clear(); 966*cdf0e10cSrcweir m_bModified = true; // user layer must be written 967*cdf0e10cSrcweir 968*cdf0e10cSrcweir // Modify type container 969*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[nElementType]; 970*cdf0e10cSrcweir rElementType.bModified = true; 971*cdf0e10cSrcweir 972*cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 973*cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 974*cdf0e10cSrcweir 975*cdf0e10cSrcweir // Create event to notify listener about removed element settings 976*cdf0e10cSrcweir ConfigurationEvent aEvent; 977*cdf0e10cSrcweir 978*cdf0e10cSrcweir aEvent.ResourceURL = ResourceURL; 979*cdf0e10cSrcweir aEvent.Accessor <<= xThis; 980*cdf0e10cSrcweir aEvent.Source = xIfac; 981*cdf0e10cSrcweir aEvent.Element <<= xRemovedSettings; 982*cdf0e10cSrcweir 983*cdf0e10cSrcweir aGuard.unlock(); 984*cdf0e10cSrcweir 985*cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Remove ); 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir } 988*cdf0e10cSrcweir else 989*cdf0e10cSrcweir throw NoSuchElementException(); 990*cdf0e10cSrcweir } 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir 993*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::insertSettings( const ::rtl::OUString& NewResourceURL, const Reference< XIndexAccess >& aNewData ) 994*cdf0e10cSrcweir throw ( ElementExistException, IllegalArgumentException, IllegalAccessException, RuntimeException ) 995*cdf0e10cSrcweir { 996*cdf0e10cSrcweir sal_Int16 nElementType = RetrieveTypeFromResourceURL( NewResourceURL ); 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir if (( nElementType == ::com::sun::star::ui::UIElementType::UNKNOWN ) || 999*cdf0e10cSrcweir ( nElementType >= ::com::sun::star::ui::UIElementType::COUNT )) 1000*cdf0e10cSrcweir throw IllegalArgumentException(); 1001*cdf0e10cSrcweir else if ( m_bReadOnly ) 1002*cdf0e10cSrcweir throw IllegalAccessException(); 1003*cdf0e10cSrcweir else 1004*cdf0e10cSrcweir { 1005*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1006*cdf0e10cSrcweir 1007*cdf0e10cSrcweir if ( m_bDisposed ) 1008*cdf0e10cSrcweir throw DisposedException(); 1009*cdf0e10cSrcweir 1010*cdf0e10cSrcweir bool bInsertData( false ); 1011*cdf0e10cSrcweir UIElementData aUIElementData; 1012*cdf0e10cSrcweir UIElementData* pDataSettings = impl_findUIElementData( NewResourceURL, nElementType ); 1013*cdf0e10cSrcweir 1014*cdf0e10cSrcweir if ( pDataSettings && !pDataSettings->bDefault ) 1015*cdf0e10cSrcweir throw ElementExistException(); 1016*cdf0e10cSrcweir 1017*cdf0e10cSrcweir if ( !pDataSettings ) 1018*cdf0e10cSrcweir { 1019*cdf0e10cSrcweir pDataSettings = &aUIElementData; 1020*cdf0e10cSrcweir bInsertData = true; 1021*cdf0e10cSrcweir } 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir { 1024*cdf0e10cSrcweir pDataSettings->bDefault = false; 1025*cdf0e10cSrcweir pDataSettings->bModified = true; 1026*cdf0e10cSrcweir 1027*cdf0e10cSrcweir // Create a copy of the data if the container is not const 1028*cdf0e10cSrcweir Reference< XIndexReplace > xReplace( aNewData, UNO_QUERY ); 1029*cdf0e10cSrcweir if ( xReplace.is() ) 1030*cdf0e10cSrcweir pDataSettings->xSettings = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( aNewData ) ), UNO_QUERY ); 1031*cdf0e10cSrcweir else 1032*cdf0e10cSrcweir pDataSettings->xSettings = aNewData; 1033*cdf0e10cSrcweir 1034*cdf0e10cSrcweir m_bModified = true; 1035*cdf0e10cSrcweir 1036*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[nElementType]; 1037*cdf0e10cSrcweir rElementType.bModified = true; 1038*cdf0e10cSrcweir 1039*cdf0e10cSrcweir if ( bInsertData ) 1040*cdf0e10cSrcweir { 1041*cdf0e10cSrcweir pDataSettings->aName = RetrieveNameFromResourceURL( NewResourceURL ) + m_aXMLPostfix; 1042*cdf0e10cSrcweir pDataSettings->aResourceURL = NewResourceURL; 1043*cdf0e10cSrcweir 1044*cdf0e10cSrcweir UIElementDataHashMap& rElements = rElementType.aElementsHashMap; 1045*cdf0e10cSrcweir rElements.insert( UIElementDataHashMap::value_type( NewResourceURL, *pDataSettings )); 1046*cdf0e10cSrcweir } 1047*cdf0e10cSrcweir 1048*cdf0e10cSrcweir Reference< XIndexAccess > xInsertSettings( aUIElementData.xSettings ); 1049*cdf0e10cSrcweir Reference< XUIConfigurationManager > xThis( static_cast< OWeakObject* >( this ), UNO_QUERY ); 1050*cdf0e10cSrcweir Reference< XInterface > xIfac( xThis, UNO_QUERY ); 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir // Create event to notify listener about removed element settings 1053*cdf0e10cSrcweir ConfigurationEvent aEvent; 1054*cdf0e10cSrcweir 1055*cdf0e10cSrcweir aEvent.ResourceURL = NewResourceURL; 1056*cdf0e10cSrcweir aEvent.Accessor <<= xThis; 1057*cdf0e10cSrcweir aEvent.Source = xIfac; 1058*cdf0e10cSrcweir aEvent.Element <<= xInsertSettings; 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir aGuard.unlock(); 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir implts_notifyContainerListener( aEvent, NotifyOp_Insert ); 1063*cdf0e10cSrcweir } 1064*cdf0e10cSrcweir } 1065*cdf0e10cSrcweir } 1066*cdf0e10cSrcweir 1067*cdf0e10cSrcweir Reference< XInterface > SAL_CALL UIConfigurationManager::getImageManager() throw (::com::sun::star::uno::RuntimeException) 1068*cdf0e10cSrcweir { 1069*cdf0e10cSrcweir if ( m_bDisposed ) 1070*cdf0e10cSrcweir throw DisposedException(); 1071*cdf0e10cSrcweir 1072*cdf0e10cSrcweir if ( !m_xImageManager.is() ) 1073*cdf0e10cSrcweir { 1074*cdf0e10cSrcweir m_xImageManager = Reference< XComponent >( static_cast< cppu::OWeakObject *>( new ImageManager( m_xServiceManager )), 1075*cdf0e10cSrcweir UNO_QUERY ); 1076*cdf0e10cSrcweir Reference< XInitialization > xInit( m_xImageManager, UNO_QUERY ); 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir Sequence< Any > aPropSeq( 2 ); 1079*cdf0e10cSrcweir PropertyValue aPropValue; 1080*cdf0e10cSrcweir aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UserConfigStorage" )); 1081*cdf0e10cSrcweir aPropValue.Value = makeAny( m_xDocConfigStorage ); 1082*cdf0e10cSrcweir aPropSeq[0] = makeAny( aPropValue ); 1083*cdf0e10cSrcweir aPropValue.Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "ModuleIdentifier" )); 1084*cdf0e10cSrcweir aPropValue.Value = makeAny( m_aModuleIdentifier ); 1085*cdf0e10cSrcweir aPropSeq[1] = makeAny( aPropValue ); 1086*cdf0e10cSrcweir 1087*cdf0e10cSrcweir xInit->initialize( aPropSeq ); 1088*cdf0e10cSrcweir } 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir return Reference< XInterface >( m_xImageManager, UNO_QUERY ); 1091*cdf0e10cSrcweir } 1092*cdf0e10cSrcweir 1093*cdf0e10cSrcweir Reference< XInterface > SAL_CALL UIConfigurationManager::getShortCutManager() throw (::com::sun::star::uno::RuntimeException) 1094*cdf0e10cSrcweir { 1095*cdf0e10cSrcweir // SAFE -> 1096*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir if (m_xAccConfig.is()) 1099*cdf0e10cSrcweir return m_xAccConfig; 1100*cdf0e10cSrcweir 1101*cdf0e10cSrcweir Reference< XMultiServiceFactory > xSMGR = m_xServiceManager; 1102*cdf0e10cSrcweir Reference< XStorage > xDocumentRoot = m_xDocConfigStorage; 1103*cdf0e10cSrcweir 1104*cdf0e10cSrcweir aGuard.unlock(); 1105*cdf0e10cSrcweir // <- SAFE 1106*cdf0e10cSrcweir 1107*cdf0e10cSrcweir Reference< XInterface > xAccConfig = xSMGR->createInstance(SERVICENAME_DOCUMENTACCELERATORCONFIGURATION); 1108*cdf0e10cSrcweir Reference< XInitialization > xInit (xAccConfig, UNO_QUERY_THROW); 1109*cdf0e10cSrcweir 1110*cdf0e10cSrcweir PropertyValue aProp; 1111*cdf0e10cSrcweir aProp.Name = ::rtl::OUString::createFromAscii("DocumentRoot"); 1112*cdf0e10cSrcweir aProp.Value <<= xDocumentRoot; 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir Sequence< Any > lArgs(1); 1115*cdf0e10cSrcweir lArgs[0] <<= aProp; 1116*cdf0e10cSrcweir 1117*cdf0e10cSrcweir xInit->initialize(lArgs); 1118*cdf0e10cSrcweir 1119*cdf0e10cSrcweir // SAFE -> 1120*cdf0e10cSrcweir aGuard.lock(); 1121*cdf0e10cSrcweir m_xAccConfig = xAccConfig; 1122*cdf0e10cSrcweir aGuard.unlock(); 1123*cdf0e10cSrcweir // <- SAFE 1124*cdf0e10cSrcweir 1125*cdf0e10cSrcweir return xAccConfig; 1126*cdf0e10cSrcweir } 1127*cdf0e10cSrcweir 1128*cdf0e10cSrcweir Reference< XInterface > SAL_CALL UIConfigurationManager::getEventsManager() throw (::com::sun::star::uno::RuntimeException) 1129*cdf0e10cSrcweir { 1130*cdf0e10cSrcweir return Reference< XInterface >(); 1131*cdf0e10cSrcweir } 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir // XUIConfigurationStorage 1134*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::setStorage( const Reference< XStorage >& Storage ) throw (::com::sun::star::uno::RuntimeException) 1135*cdf0e10cSrcweir { 1136*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1137*cdf0e10cSrcweir 1138*cdf0e10cSrcweir if ( m_bDisposed ) 1139*cdf0e10cSrcweir throw DisposedException(); 1140*cdf0e10cSrcweir 1141*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() ) 1142*cdf0e10cSrcweir { 1143*cdf0e10cSrcweir try 1144*cdf0e10cSrcweir { 1145*cdf0e10cSrcweir // Dispose old storage to be sure that it will be closed 1146*cdf0e10cSrcweir Reference< XComponent > xComponent( m_xDocConfigStorage, UNO_QUERY ); 1147*cdf0e10cSrcweir if ( xComponent.is() ) 1148*cdf0e10cSrcweir xComponent->dispose(); 1149*cdf0e10cSrcweir } 1150*cdf0e10cSrcweir catch ( Exception& ) 1151*cdf0e10cSrcweir { 1152*cdf0e10cSrcweir } 1153*cdf0e10cSrcweir } 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir // We store the new storage. Be careful it could be an empty reference! 1156*cdf0e10cSrcweir m_xDocConfigStorage = Storage; 1157*cdf0e10cSrcweir m_bReadOnly = sal_True; 1158*cdf0e10cSrcweir 1159*cdf0e10cSrcweir Reference< XUIConfigurationStorage > xAccUpdate(m_xAccConfig, UNO_QUERY); 1160*cdf0e10cSrcweir if ( xAccUpdate.is() ) 1161*cdf0e10cSrcweir xAccUpdate->setStorage( m_xDocConfigStorage ); 1162*cdf0e10cSrcweir 1163*cdf0e10cSrcweir if ( m_xImageManager.is() ) 1164*cdf0e10cSrcweir { 1165*cdf0e10cSrcweir ImageManager* pImageManager = (ImageManager*)m_xImageManager.get(); 1166*cdf0e10cSrcweir if ( pImageManager ) 1167*cdf0e10cSrcweir pImageManager->setStorage( m_xDocConfigStorage ); 1168*cdf0e10cSrcweir } 1169*cdf0e10cSrcweir 1170*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() ) 1171*cdf0e10cSrcweir { 1172*cdf0e10cSrcweir Reference< XPropertySet > xPropSet( m_xDocConfigStorage, UNO_QUERY ); 1173*cdf0e10cSrcweir if ( xPropSet.is() ) 1174*cdf0e10cSrcweir { 1175*cdf0e10cSrcweir try 1176*cdf0e10cSrcweir { 1177*cdf0e10cSrcweir long nOpenMode = 0; 1178*cdf0e10cSrcweir Any a = xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "OpenMode" ))); 1179*cdf0e10cSrcweir if ( a >>= nOpenMode ) 1180*cdf0e10cSrcweir m_bReadOnly = !( nOpenMode & ElementModes::WRITE ); 1181*cdf0e10cSrcweir } 1182*cdf0e10cSrcweir catch ( com::sun::star::beans::UnknownPropertyException& ) 1183*cdf0e10cSrcweir { 1184*cdf0e10cSrcweir } 1185*cdf0e10cSrcweir catch ( com::sun::star::lang::WrappedTargetException& ) 1186*cdf0e10cSrcweir { 1187*cdf0e10cSrcweir } 1188*cdf0e10cSrcweir } 1189*cdf0e10cSrcweir } 1190*cdf0e10cSrcweir 1191*cdf0e10cSrcweir impl_Initialize(); 1192*cdf0e10cSrcweir } 1193*cdf0e10cSrcweir 1194*cdf0e10cSrcweir sal_Bool SAL_CALL UIConfigurationManager::hasStorage() throw (::com::sun::star::uno::RuntimeException) 1195*cdf0e10cSrcweir { 1196*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1197*cdf0e10cSrcweir 1198*cdf0e10cSrcweir if ( m_bDisposed ) 1199*cdf0e10cSrcweir throw DisposedException(); 1200*cdf0e10cSrcweir 1201*cdf0e10cSrcweir return ( m_xDocConfigStorage.is() ); 1202*cdf0e10cSrcweir } 1203*cdf0e10cSrcweir 1204*cdf0e10cSrcweir // XUIConfigurationPersistence 1205*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::reload() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1206*cdf0e10cSrcweir { 1207*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1208*cdf0e10cSrcweir 1209*cdf0e10cSrcweir if ( m_bDisposed ) 1210*cdf0e10cSrcweir throw DisposedException(); 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() && m_bModified && !m_bReadOnly ) 1213*cdf0e10cSrcweir { 1214*cdf0e10cSrcweir // Try to access our module sub folder 1215*cdf0e10cSrcweir ConfigEventNotifyContainer aRemoveNotifyContainer; 1216*cdf0e10cSrcweir ConfigEventNotifyContainer aReplaceNotifyContainer; 1217*cdf0e10cSrcweir for ( sal_Int16 i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1218*cdf0e10cSrcweir { 1219*cdf0e10cSrcweir try 1220*cdf0e10cSrcweir { 1221*cdf0e10cSrcweir UIElementType& rDocElementType = m_aUIElements[i]; 1222*cdf0e10cSrcweir if ( rDocElementType.bModified ) 1223*cdf0e10cSrcweir impl_reloadElementTypeData( rDocElementType, aRemoveNotifyContainer, aReplaceNotifyContainer ); 1224*cdf0e10cSrcweir } 1225*cdf0e10cSrcweir catch ( Exception& ) 1226*cdf0e10cSrcweir { 1227*cdf0e10cSrcweir throw IOException(); 1228*cdf0e10cSrcweir } 1229*cdf0e10cSrcweir } 1230*cdf0e10cSrcweir 1231*cdf0e10cSrcweir m_bModified = sal_False; 1232*cdf0e10cSrcweir 1233*cdf0e10cSrcweir // Unlock mutex before notify our listeners 1234*cdf0e10cSrcweir aGuard.unlock(); 1235*cdf0e10cSrcweir 1236*cdf0e10cSrcweir // Notify our listeners 1237*cdf0e10cSrcweir for ( sal_uInt32 j = 0; j < aRemoveNotifyContainer.size(); j++ ) 1238*cdf0e10cSrcweir implts_notifyContainerListener( aRemoveNotifyContainer[j], NotifyOp_Remove ); 1239*cdf0e10cSrcweir for ( sal_uInt32 k = 0; k < aReplaceNotifyContainer.size(); k++ ) 1240*cdf0e10cSrcweir implts_notifyContainerListener( aReplaceNotifyContainer[k], NotifyOp_Replace ); 1241*cdf0e10cSrcweir } 1242*cdf0e10cSrcweir } 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::store() throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1245*cdf0e10cSrcweir { 1246*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1247*cdf0e10cSrcweir 1248*cdf0e10cSrcweir if ( m_bDisposed ) 1249*cdf0e10cSrcweir throw DisposedException(); 1250*cdf0e10cSrcweir 1251*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() && m_bModified && !m_bReadOnly ) 1252*cdf0e10cSrcweir { 1253*cdf0e10cSrcweir // Try to access our module sub folder 1254*cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1255*cdf0e10cSrcweir { 1256*cdf0e10cSrcweir try 1257*cdf0e10cSrcweir { 1258*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[i]; 1259*cdf0e10cSrcweir Reference< XStorage > xStorage( rElementType.xStorage, UNO_QUERY ); 1260*cdf0e10cSrcweir 1261*cdf0e10cSrcweir if ( rElementType.bModified && xStorage.is() ) 1262*cdf0e10cSrcweir impl_storeElementTypeData( xStorage, rElementType ); 1263*cdf0e10cSrcweir } 1264*cdf0e10cSrcweir catch ( Exception& ) 1265*cdf0e10cSrcweir { 1266*cdf0e10cSrcweir throw IOException(); 1267*cdf0e10cSrcweir } 1268*cdf0e10cSrcweir } 1269*cdf0e10cSrcweir 1270*cdf0e10cSrcweir m_bModified = false; 1271*cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( m_xDocConfigStorage, UNO_QUERY ); 1272*cdf0e10cSrcweir if ( xTransactedObject.is() ) 1273*cdf0e10cSrcweir xTransactedObject->commit(); 1274*cdf0e10cSrcweir } 1275*cdf0e10cSrcweir } 1276*cdf0e10cSrcweir 1277*cdf0e10cSrcweir void SAL_CALL UIConfigurationManager::storeToStorage( const Reference< XStorage >& Storage ) throw (::com::sun::star::uno::Exception, ::com::sun::star::uno::RuntimeException) 1278*cdf0e10cSrcweir { 1279*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1280*cdf0e10cSrcweir 1281*cdf0e10cSrcweir if ( m_bDisposed ) 1282*cdf0e10cSrcweir throw DisposedException(); 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir if ( m_xDocConfigStorage.is() && m_bModified && !m_bReadOnly ) 1285*cdf0e10cSrcweir { 1286*cdf0e10cSrcweir // Try to access our module sub folder 1287*cdf0e10cSrcweir for ( int i = 1; i < ::com::sun::star::ui::UIElementType::COUNT; i++ ) 1288*cdf0e10cSrcweir { 1289*cdf0e10cSrcweir try 1290*cdf0e10cSrcweir { 1291*cdf0e10cSrcweir Reference< XStorage > xElementTypeStorage( Storage->openStorageElement( 1292*cdf0e10cSrcweir rtl::OUString::createFromAscii( UIELEMENTTYPENAMES[i] ), ElementModes::READWRITE )); 1293*cdf0e10cSrcweir UIElementType& rElementType = m_aUIElements[i]; 1294*cdf0e10cSrcweir 1295*cdf0e10cSrcweir if ( rElementType.bModified && xElementTypeStorage.is() ) 1296*cdf0e10cSrcweir impl_storeElementTypeData( xElementTypeStorage, rElementType, false ); // store data to storage, but don't reset modify flag! 1297*cdf0e10cSrcweir } 1298*cdf0e10cSrcweir catch ( Exception& ) 1299*cdf0e10cSrcweir { 1300*cdf0e10cSrcweir throw IOException(); 1301*cdf0e10cSrcweir } 1302*cdf0e10cSrcweir } 1303*cdf0e10cSrcweir 1304*cdf0e10cSrcweir Reference< XTransactedObject > xTransactedObject( Storage, UNO_QUERY ); 1305*cdf0e10cSrcweir if ( xTransactedObject.is() ) 1306*cdf0e10cSrcweir xTransactedObject->commit(); 1307*cdf0e10cSrcweir } 1308*cdf0e10cSrcweir } 1309*cdf0e10cSrcweir 1310*cdf0e10cSrcweir sal_Bool SAL_CALL UIConfigurationManager::isModified() throw (::com::sun::star::uno::RuntimeException) 1311*cdf0e10cSrcweir { 1312*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1313*cdf0e10cSrcweir 1314*cdf0e10cSrcweir return m_bModified; 1315*cdf0e10cSrcweir } 1316*cdf0e10cSrcweir 1317*cdf0e10cSrcweir sal_Bool SAL_CALL UIConfigurationManager::isReadOnly() throw (::com::sun::star::uno::RuntimeException) 1318*cdf0e10cSrcweir { 1319*cdf0e10cSrcweir ResetableGuard aGuard( m_aLock ); 1320*cdf0e10cSrcweir 1321*cdf0e10cSrcweir return m_bReadOnly; 1322*cdf0e10cSrcweir } 1323*cdf0e10cSrcweir 1324*cdf0e10cSrcweir void UIConfigurationManager::implts_notifyContainerListener( const ConfigurationEvent& aEvent, NotifyOp eOp ) 1325*cdf0e10cSrcweir { 1326*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pContainer = m_aListenerContainer.getContainer( ::getCppuType( ( const css::uno::Reference< ::com::sun::star::ui::XUIConfigurationListener >*) NULL ) ); 1327*cdf0e10cSrcweir if ( pContainer != NULL ) 1328*cdf0e10cSrcweir { 1329*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper pIterator( *pContainer ); 1330*cdf0e10cSrcweir while ( pIterator.hasMoreElements() ) 1331*cdf0e10cSrcweir { 1332*cdf0e10cSrcweir try 1333*cdf0e10cSrcweir { 1334*cdf0e10cSrcweir switch ( eOp ) 1335*cdf0e10cSrcweir { 1336*cdf0e10cSrcweir case NotifyOp_Replace: 1337*cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementReplaced( aEvent ); 1338*cdf0e10cSrcweir break; 1339*cdf0e10cSrcweir case NotifyOp_Insert: 1340*cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementInserted( aEvent ); 1341*cdf0e10cSrcweir break; 1342*cdf0e10cSrcweir case NotifyOp_Remove: 1343*cdf0e10cSrcweir ((::com::sun::star::ui::XUIConfigurationListener*)pIterator.next())->elementRemoved( aEvent ); 1344*cdf0e10cSrcweir break; 1345*cdf0e10cSrcweir } 1346*cdf0e10cSrcweir } 1347*cdf0e10cSrcweir catch( css::uno::RuntimeException& ) 1348*cdf0e10cSrcweir { 1349*cdf0e10cSrcweir pIterator.remove(); 1350*cdf0e10cSrcweir } 1351*cdf0e10cSrcweir } 1352*cdf0e10cSrcweir } 1353*cdf0e10cSrcweir } 1354*cdf0e10cSrcweir 1355*cdf0e10cSrcweir } // namespace framework 1356