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 31*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 32*cdf0e10cSrcweir // my own includes 33*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 34*cdf0e10cSrcweir #include <helper/uiconfigelementwrapperbase.hxx> 35*cdf0e10cSrcweir #include <general.h> 36*cdf0e10cSrcweir #include <properties.h> 37*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 38*cdf0e10cSrcweir #include <uielement/constitemcontainer.hxx> 39*cdf0e10cSrcweir #include <uielement/rootitemcontainer.hxx> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir // interface includes 43*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 44*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 45*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 46*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/ui/XUIConfiguration.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 50*cdf0e10cSrcweir // includes of other projects 51*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 52*cdf0e10cSrcweir #include <vcl/svapp.hxx> 53*cdf0e10cSrcweir #include <rtl/logfile.hxx> 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_CONFIGSOURCE = 1; 56*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_FRAME = 2; 57*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_PERSISTENT = 3; 58*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_RESOURCEURL = 4; 59*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_TYPE = 5; 60*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_XMENUBAR = 6; 61*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_CONFIGLISTENER = 7; 62*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_NOCLOSE = 8; 63*cdf0e10cSrcweir const int UIELEMENT_PROPCOUNT = 8; 64*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_CONFIGLISTENER( RTL_CONSTASCII_USTRINGPARAM( "ConfigListener" )); 65*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_CONFIGSOURCE( RTL_CONSTASCII_USTRINGPARAM( "ConfigurationSource" )); 66*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_FRAME( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 67*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_PERSISTENT( RTL_CONSTASCII_USTRINGPARAM( "Persistent" )); 68*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_RESOURCEURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )); 69*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_TYPE( RTL_CONSTASCII_USTRINGPARAM( "Type" )); 70*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_XMENUBAR( RTL_CONSTASCII_USTRINGPARAM( "XMenuBar" )); 71*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_NOCLOSE( RTL_CONSTASCII_USTRINGPARAM( "NoClose" )); 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir //using namespace rtl; 74*cdf0e10cSrcweir using namespace com::sun::star::beans; 75*cdf0e10cSrcweir using namespace com::sun::star::uno; 76*cdf0e10cSrcweir using namespace com::sun::star::frame; 77*cdf0e10cSrcweir using namespace com::sun::star::lang; 78*cdf0e10cSrcweir using namespace com::sun::star::container; 79*cdf0e10cSrcweir using namespace ::com::sun::star::ui; 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir namespace framework 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir //***************************************************************************************************************** 85*cdf0e10cSrcweir // XInterface, XTypeProvider 86*cdf0e10cSrcweir //***************************************************************************************************************** 87*cdf0e10cSrcweir DEFINE_XINTERFACE_10 ( UIConfigElementWrapperBase , 88*cdf0e10cSrcweir OWeakObject , 89*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ), 90*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ), 91*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIElementSettings ), 92*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ), 93*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ), 94*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ), 95*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ), 96*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XComponent ), 97*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ), 98*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIConfigurationListener ) 99*cdf0e10cSrcweir ) 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_10 ( UIConfigElementWrapperBase , 102*cdf0e10cSrcweir ::com::sun::star::lang::XTypeProvider , 103*cdf0e10cSrcweir ::com::sun::star::ui::XUIElement , 104*cdf0e10cSrcweir ::com::sun::star::ui::XUIElementSettings , 105*cdf0e10cSrcweir ::com::sun::star::beans::XMultiPropertySet , 106*cdf0e10cSrcweir ::com::sun::star::beans::XFastPropertySet , 107*cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet , 108*cdf0e10cSrcweir ::com::sun::star::lang::XInitialization , 109*cdf0e10cSrcweir ::com::sun::star::lang::XComponent , 110*cdf0e10cSrcweir ::com::sun::star::util::XUpdatable , 111*cdf0e10cSrcweir ::com::sun::star::ui::XUIConfigurationListener 112*cdf0e10cSrcweir ) 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir UIConfigElementWrapperBase::UIConfigElementWrapperBase( sal_Int16 nType,const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XMultiServiceFactory >& _xServiceFactory ) 115*cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 116*cdf0e10cSrcweir , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() ) 117*cdf0e10cSrcweir , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) ) 118*cdf0e10cSrcweir , ::cppu::OWeakObject ( ) 119*cdf0e10cSrcweir , m_nType ( nType ) 120*cdf0e10cSrcweir , m_bPersistent ( sal_True ) 121*cdf0e10cSrcweir , m_bInitialized ( sal_False ) 122*cdf0e10cSrcweir , m_bConfigListener ( sal_False ) 123*cdf0e10cSrcweir , m_bConfigListening ( sal_False ) 124*cdf0e10cSrcweir , m_bDisposed ( sal_False ) 125*cdf0e10cSrcweir , m_bNoClose ( sal_False ) 126*cdf0e10cSrcweir , m_xServiceFactory ( _xServiceFactory ) 127*cdf0e10cSrcweir , m_aListenerContainer ( m_aLock.getShareableOslMutex() ) 128*cdf0e10cSrcweir { 129*cdf0e10cSrcweir } 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir UIConfigElementWrapperBase::~UIConfigElementWrapperBase() 132*cdf0e10cSrcweir { 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir // XComponent 136*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::dispose() throw (::com::sun::star::uno::RuntimeException) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir // must be implemented by derived class 139*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 140*cdf0e10cSrcweir m_bDisposed = sal_True; 141*cdf0e10cSrcweir } 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 144*cdf0e10cSrcweir { 145*cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener ); 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& aListener ) throw (::com::sun::star::uno::RuntimeException) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), aListener ); 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir 153*cdf0e10cSrcweir // XEventListener 154*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::disposing( const EventObject& ) 155*cdf0e10cSrcweir throw( RuntimeException ) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 158*cdf0e10cSrcweir m_xConfigSource.clear(); 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::initialize( const Sequence< Any >& aArguments ) 162*cdf0e10cSrcweir throw ( Exception, RuntimeException ) 163*cdf0e10cSrcweir { 164*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir if ( !m_bInitialized ) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ ) 169*cdf0e10cSrcweir { 170*cdf0e10cSrcweir PropertyValue aPropValue; 171*cdf0e10cSrcweir if ( aArguments[n] >>= aPropValue ) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_CONFIGSOURCE )) 174*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_CONFIGSOURCE, aPropValue.Value ); 175*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_FRAME )) 176*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_FRAME, aPropValue.Value ); 177*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_PERSISTENT )) 178*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_PERSISTENT, aPropValue.Value ); 179*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_RESOURCEURL )) 180*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_RESOURCEURL, aPropValue.Value ); 181*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_TYPE )) 182*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_TYPE, aPropValue.Value ); 183*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_CONFIGLISTENER )) 184*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_CONFIGLISTENER, aPropValue.Value ); 185*cdf0e10cSrcweir else if ( aPropValue.Name.equals( UIELEMENT_PROPNAME_NOCLOSE )) 186*cdf0e10cSrcweir setFastPropertyValue_NoBroadcast( UIELEMENT_PROPHANDLE_NOCLOSE, aPropValue.Value ); 187*cdf0e10cSrcweir } 188*cdf0e10cSrcweir } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir m_bInitialized = sal_True; 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir } 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir // XUpdatable 195*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException) 196*cdf0e10cSrcweir { 197*cdf0e10cSrcweir // can be implemented by derived class 198*cdf0e10cSrcweir } 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::elementInserted( const ::com::sun::star::ui::ConfigurationEvent& ) throw (::com::sun::star::uno::RuntimeException) 201*cdf0e10cSrcweir { 202*cdf0e10cSrcweir // can be implemented by derived class 203*cdf0e10cSrcweir } 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::elementRemoved( const ::com::sun::star::ui::ConfigurationEvent& ) throw (::com::sun::star::uno::RuntimeException) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir // can be implemented by derived class 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::elementReplaced( const ::com::sun::star::ui::ConfigurationEvent& ) throw (::com::sun::star::uno::RuntimeException) 211*cdf0e10cSrcweir { 212*cdf0e10cSrcweir // can be implemented by derived class 213*cdf0e10cSrcweir } 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir // XPropertySet helper 216*cdf0e10cSrcweir sal_Bool SAL_CALL UIConfigElementWrapperBase::convertFastPropertyValue( Any& aConvertedValue , 217*cdf0e10cSrcweir Any& aOldValue , 218*cdf0e10cSrcweir sal_Int32 nHandle , 219*cdf0e10cSrcweir const Any& aValue ) throw( com::sun::star::lang::IllegalArgumentException ) 220*cdf0e10cSrcweir { 221*cdf0e10cSrcweir // Initialize state with sal_False !!! 222*cdf0e10cSrcweir // (Handle can be invalid) 223*cdf0e10cSrcweir sal_Bool bReturn = sal_False; 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir switch( nHandle ) 226*cdf0e10cSrcweir { 227*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGLISTENER: 228*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 229*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_bConfigListener), 230*cdf0e10cSrcweir aValue, 231*cdf0e10cSrcweir aOldValue, 232*cdf0e10cSrcweir aConvertedValue); 233*cdf0e10cSrcweir break; 234*cdf0e10cSrcweir 235*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGSOURCE: 236*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 237*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_xConfigSource), 238*cdf0e10cSrcweir aValue, 239*cdf0e10cSrcweir aOldValue, 240*cdf0e10cSrcweir aConvertedValue); 241*cdf0e10cSrcweir break; 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_FRAME: 244*cdf0e10cSrcweir { 245*cdf0e10cSrcweir Reference< XFrame > xFrame( m_xWeakFrame ); 246*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 247*cdf0e10cSrcweir com::sun::star::uno::makeAny(xFrame), 248*cdf0e10cSrcweir aValue, 249*cdf0e10cSrcweir aOldValue, 250*cdf0e10cSrcweir aConvertedValue); 251*cdf0e10cSrcweir } 252*cdf0e10cSrcweir break; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_PERSISTENT: 255*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 256*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_bPersistent), 257*cdf0e10cSrcweir aValue, 258*cdf0e10cSrcweir aOldValue, 259*cdf0e10cSrcweir aConvertedValue); 260*cdf0e10cSrcweir break; 261*cdf0e10cSrcweir 262*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_RESOURCEURL: 263*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 264*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_aResourceURL), 265*cdf0e10cSrcweir aValue, 266*cdf0e10cSrcweir aOldValue, 267*cdf0e10cSrcweir aConvertedValue); 268*cdf0e10cSrcweir break; 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_TYPE : 271*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 272*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_nType), 273*cdf0e10cSrcweir aValue, 274*cdf0e10cSrcweir aOldValue, 275*cdf0e10cSrcweir aConvertedValue); 276*cdf0e10cSrcweir break; 277*cdf0e10cSrcweir 278*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_XMENUBAR : 279*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 280*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_xMenuBar), 281*cdf0e10cSrcweir aValue, 282*cdf0e10cSrcweir aOldValue, 283*cdf0e10cSrcweir aConvertedValue); 284*cdf0e10cSrcweir break; 285*cdf0e10cSrcweir 286*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_NOCLOSE: 287*cdf0e10cSrcweir bReturn = PropHelper::willPropertyBeChanged( 288*cdf0e10cSrcweir com::sun::star::uno::makeAny(m_bNoClose), 289*cdf0e10cSrcweir aValue, 290*cdf0e10cSrcweir aOldValue, 291*cdf0e10cSrcweir aConvertedValue); 292*cdf0e10cSrcweir break; 293*cdf0e10cSrcweir } 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir // Return state of operation. 296*cdf0e10cSrcweir return bReturn ; 297*cdf0e10cSrcweir } 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle , 300*cdf0e10cSrcweir const com::sun::star::uno::Any& aValue ) throw( com::sun::star::uno::Exception ) 301*cdf0e10cSrcweir { 302*cdf0e10cSrcweir switch( nHandle ) 303*cdf0e10cSrcweir { 304*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGLISTENER: 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir bool bBool( m_bConfigListener ); 307*cdf0e10cSrcweir aValue >>= bBool; 308*cdf0e10cSrcweir if ( m_bConfigListener != bBool ) 309*cdf0e10cSrcweir { 310*cdf0e10cSrcweir if ( m_bConfigListening ) 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir if ( m_xConfigSource.is() && !bBool ) 313*cdf0e10cSrcweir { 314*cdf0e10cSrcweir try 315*cdf0e10cSrcweir { 316*cdf0e10cSrcweir Reference< XUIConfiguration > xUIConfig( m_xConfigSource, UNO_QUERY ); 317*cdf0e10cSrcweir if ( xUIConfig.is() ) 318*cdf0e10cSrcweir { 319*cdf0e10cSrcweir xUIConfig->removeConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY )); 320*cdf0e10cSrcweir m_bConfigListening = sal_False; 321*cdf0e10cSrcweir } 322*cdf0e10cSrcweir } 323*cdf0e10cSrcweir catch ( Exception& ) 324*cdf0e10cSrcweir { 325*cdf0e10cSrcweir } 326*cdf0e10cSrcweir } 327*cdf0e10cSrcweir } 328*cdf0e10cSrcweir else 329*cdf0e10cSrcweir { 330*cdf0e10cSrcweir if ( m_xConfigSource.is() && bBool ) 331*cdf0e10cSrcweir { 332*cdf0e10cSrcweir try 333*cdf0e10cSrcweir { 334*cdf0e10cSrcweir Reference< XUIConfiguration > xUIConfig( m_xConfigSource, UNO_QUERY ); 335*cdf0e10cSrcweir if ( xUIConfig.is() ) 336*cdf0e10cSrcweir { 337*cdf0e10cSrcweir xUIConfig->addConfigurationListener( Reference< XUIConfigurationListener >( static_cast< OWeakObject* >( this ), UNO_QUERY )); 338*cdf0e10cSrcweir m_bConfigListening = sal_True; 339*cdf0e10cSrcweir } 340*cdf0e10cSrcweir } 341*cdf0e10cSrcweir catch ( Exception& ) 342*cdf0e10cSrcweir { 343*cdf0e10cSrcweir } 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir 347*cdf0e10cSrcweir m_bConfigListener = bBool; 348*cdf0e10cSrcweir } 349*cdf0e10cSrcweir } 350*cdf0e10cSrcweir break; 351*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGSOURCE: 352*cdf0e10cSrcweir aValue >>= m_xConfigSource; 353*cdf0e10cSrcweir break; 354*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_FRAME: 355*cdf0e10cSrcweir { 356*cdf0e10cSrcweir Reference< XFrame > xFrame; 357*cdf0e10cSrcweir 358*cdf0e10cSrcweir aValue >>= xFrame; 359*cdf0e10cSrcweir m_xWeakFrame = xFrame; 360*cdf0e10cSrcweir break; 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_PERSISTENT: 363*cdf0e10cSrcweir { 364*cdf0e10cSrcweir sal_Bool bBool( m_bPersistent ); 365*cdf0e10cSrcweir aValue >>= bBool; 366*cdf0e10cSrcweir m_bPersistent = bBool; 367*cdf0e10cSrcweir break; 368*cdf0e10cSrcweir } 369*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_RESOURCEURL: 370*cdf0e10cSrcweir aValue >>= m_aResourceURL; 371*cdf0e10cSrcweir break; 372*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_TYPE: 373*cdf0e10cSrcweir aValue >>= m_nType; 374*cdf0e10cSrcweir break; 375*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_XMENUBAR: 376*cdf0e10cSrcweir aValue >>= m_xMenuBar; 377*cdf0e10cSrcweir break; 378*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_NOCLOSE: 379*cdf0e10cSrcweir { 380*cdf0e10cSrcweir sal_Bool bBool( m_bNoClose ); 381*cdf0e10cSrcweir aValue >>= bBool; 382*cdf0e10cSrcweir m_bNoClose = bBool; 383*cdf0e10cSrcweir break; 384*cdf0e10cSrcweir } 385*cdf0e10cSrcweir } 386*cdf0e10cSrcweir } 387*cdf0e10cSrcweir 388*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue , 389*cdf0e10cSrcweir sal_Int32 nHandle ) const 390*cdf0e10cSrcweir { 391*cdf0e10cSrcweir switch( nHandle ) 392*cdf0e10cSrcweir { 393*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGLISTENER: 394*cdf0e10cSrcweir aValue <<= m_bConfigListener; 395*cdf0e10cSrcweir break; 396*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_CONFIGSOURCE: 397*cdf0e10cSrcweir aValue <<= m_xConfigSource; 398*cdf0e10cSrcweir break; 399*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_FRAME: 400*cdf0e10cSrcweir { 401*cdf0e10cSrcweir Reference< XFrame > xFrame( m_xWeakFrame ); 402*cdf0e10cSrcweir aValue <<= xFrame; 403*cdf0e10cSrcweir break; 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_PERSISTENT: 406*cdf0e10cSrcweir aValue <<= m_bPersistent; 407*cdf0e10cSrcweir break; 408*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_RESOURCEURL: 409*cdf0e10cSrcweir aValue <<= m_aResourceURL; 410*cdf0e10cSrcweir break; 411*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_TYPE: 412*cdf0e10cSrcweir aValue <<= m_nType; 413*cdf0e10cSrcweir break; 414*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_XMENUBAR: 415*cdf0e10cSrcweir aValue <<= m_xMenuBar; 416*cdf0e10cSrcweir break; 417*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_NOCLOSE: 418*cdf0e10cSrcweir aValue <<= m_bNoClose; 419*cdf0e10cSrcweir break; 420*cdf0e10cSrcweir } 421*cdf0e10cSrcweir } 422*cdf0e10cSrcweir 423*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL UIConfigElementWrapperBase::getInfoHelper() 424*cdf0e10cSrcweir { 425*cdf0e10cSrcweir // Optimize this method ! 426*cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 427*cdf0e10cSrcweir // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL! 428*cdf0e10cSrcweir static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL; 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir if( pInfoHelper == NULL ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // Ready for multithreading 433*cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 434*cdf0e10cSrcweir 435*cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 436*cdf0e10cSrcweir if( pInfoHelper == NULL ) 437*cdf0e10cSrcweir { 438*cdf0e10cSrcweir // Define static member to give structure of properties to baseclass "OPropertySetHelper". 439*cdf0e10cSrcweir // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable. 440*cdf0e10cSrcweir // "sal_True" say: Table is sorted by name. 441*cdf0e10cSrcweir static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True ); 442*cdf0e10cSrcweir pInfoHelper = &aInfoHelper; 443*cdf0e10cSrcweir } 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir 446*cdf0e10cSrcweir return(*pInfoHelper); 447*cdf0e10cSrcweir } 448*cdf0e10cSrcweir 449*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIConfigElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException) 450*cdf0e10cSrcweir { 451*cdf0e10cSrcweir // Optimize this method ! 452*cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 453*cdf0e10cSrcweir // For the first call; pInfo is NULL - for the second call pInfo is different from NULL! 454*cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL; 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir if( pInfo == NULL ) 457*cdf0e10cSrcweir { 458*cdf0e10cSrcweir // Ready for multithreading 459*cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 460*cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 461*cdf0e10cSrcweir if( pInfo == NULL ) 462*cdf0e10cSrcweir { 463*cdf0e10cSrcweir // Create structure of propertysetinfo for baseclass "OPropertySetHelper". 464*cdf0e10cSrcweir // (Use method "getInfoHelper()".) 465*cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 466*cdf0e10cSrcweir pInfo = &xInfo; 467*cdf0e10cSrcweir } 468*cdf0e10cSrcweir } 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir return (*pInfo); 471*cdf0e10cSrcweir } 472*cdf0e10cSrcweir 473*cdf0e10cSrcweir const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIConfigElementWrapperBase::impl_getStaticPropertyDescriptor() 474*cdf0e10cSrcweir { 475*cdf0e10cSrcweir // Create a new static property array to initialize sequence! 476*cdf0e10cSrcweir // Table of all predefined properties of this class. Its used from OPropertySetHelper-class! 477*cdf0e10cSrcweir // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!! 478*cdf0e10cSrcweir // It's necessary for methods of OPropertySetHelper. 479*cdf0e10cSrcweir // ATTENTION: 480*cdf0e10cSrcweir // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!! 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir static const com::sun::star::beans::Property pProperties[] = 483*cdf0e10cSrcweir { 484*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_CONFIGLISTENER, UIELEMENT_PROPHANDLE_CONFIGLISTENER , ::getCppuType((const sal_Bool*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT ), 485*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_CONFIGSOURCE , UIELEMENT_PROPHANDLE_CONFIGSOURCE , ::getCppuType((const Reference< ::com::sun::star::ui::XUIConfigurationManager >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT ), 486*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_FRAME , UIELEMENT_PROPHANDLE_FRAME , ::getCppuType((const Reference< com::sun::star::frame::XFrame >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ), 487*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_NOCLOSE , UIELEMENT_PROPHANDLE_NOCLOSE , ::getCppuType((const sal_Bool*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT ), 488*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_PERSISTENT , UIELEMENT_PROPHANDLE_PERSISTENT , ::getCppuType((const sal_Bool*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT ), 489*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL , UIELEMENT_PROPHANDLE_RESOURCEURL , ::getCppuType((const ::rtl::OUString*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ), 490*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_TYPE , UIELEMENT_PROPHANDLE_TYPE , ::getCppuType((const ::rtl::OUString*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ), 491*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_XMENUBAR , UIELEMENT_PROPHANDLE_XMENUBAR , ::getCppuType((const Reference< com::sun::star::awt::XMenuBar >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ) 492*cdf0e10cSrcweir }; 493*cdf0e10cSrcweir // Use it to initialize sequence! 494*cdf0e10cSrcweir static const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT ); 495*cdf0e10cSrcweir // Return static "PropertyDescriptor" 496*cdf0e10cSrcweir return lPropertyDescriptor; 497*cdf0e10cSrcweir } 498*cdf0e10cSrcweir void SAL_CALL UIConfigElementWrapperBase::setSettings( const Reference< XIndexAccess >& xSettings ) throw ( RuntimeException ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 501*cdf0e10cSrcweir 502*cdf0e10cSrcweir //if ( m_bDisposed ) 503*cdf0e10cSrcweir // throw DisposedException(); 504*cdf0e10cSrcweir 505*cdf0e10cSrcweir if ( xSettings.is() ) 506*cdf0e10cSrcweir { 507*cdf0e10cSrcweir // Create a copy of the data if the container is not const 508*cdf0e10cSrcweir Reference< XIndexReplace > xReplace( xSettings, UNO_QUERY ); 509*cdf0e10cSrcweir if ( xReplace.is() ) 510*cdf0e10cSrcweir m_xConfigData = Reference< XIndexAccess >( static_cast< OWeakObject * >( new ConstItemContainer( xSettings ) ), UNO_QUERY ); 511*cdf0e10cSrcweir else 512*cdf0e10cSrcweir m_xConfigData = xSettings; 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir if ( m_xConfigSource.is() && m_bPersistent ) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir ::rtl::OUString aResourceURL( m_aResourceURL ); 517*cdf0e10cSrcweir Reference< XUIConfigurationManager > xUICfgMgr( m_xConfigSource ); 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir aLock.unlock(); 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir try 522*cdf0e10cSrcweir { 523*cdf0e10cSrcweir xUICfgMgr->replaceSettings( aResourceURL, m_xConfigData ); 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir catch( NoSuchElementException& ) 526*cdf0e10cSrcweir { 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir } 529*cdf0e10cSrcweir else if ( !m_bPersistent ) 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir // Transient menubar => Fill menubar with new data 532*cdf0e10cSrcweir impl_fillNewData(); 533*cdf0e10cSrcweir } 534*cdf0e10cSrcweir } 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir void UIConfigElementWrapperBase::impl_fillNewData() 537*cdf0e10cSrcweir { 538*cdf0e10cSrcweir } 539*cdf0e10cSrcweir Reference< XIndexAccess > SAL_CALL UIConfigElementWrapperBase::getSettings( sal_Bool bWriteable ) throw ( RuntimeException ) 540*cdf0e10cSrcweir { 541*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 542*cdf0e10cSrcweir 543*cdf0e10cSrcweir //if ( m_bDisposed ) 544*cdf0e10cSrcweir // throw DisposedException(); 545*cdf0e10cSrcweir 546*cdf0e10cSrcweir if ( bWriteable ) 547*cdf0e10cSrcweir return Reference< XIndexAccess >( static_cast< OWeakObject * >( new RootItemContainer( m_xConfigData ) ), UNO_QUERY ); 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir return m_xConfigData; 550*cdf0e10cSrcweir } 551*cdf0e10cSrcweir 552*cdf0e10cSrcweir Reference< XFrame > SAL_CALL UIConfigElementWrapperBase::getFrame() throw (RuntimeException) 553*cdf0e10cSrcweir { 554*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 555*cdf0e10cSrcweir Reference< XFrame > xFrame( m_xWeakFrame ); 556*cdf0e10cSrcweir return xFrame; 557*cdf0e10cSrcweir } 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir ::rtl::OUString SAL_CALL UIConfigElementWrapperBase::getResourceURL() throw (RuntimeException) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 562*cdf0e10cSrcweir return m_aResourceURL; 563*cdf0e10cSrcweir } 564*cdf0e10cSrcweir 565*cdf0e10cSrcweir ::sal_Int16 SAL_CALL UIConfigElementWrapperBase::getType() throw (RuntimeException) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 568*cdf0e10cSrcweir return m_nType; 569*cdf0e10cSrcweir } 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir } 572