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/uielementwrapperbase.hxx> 35*cdf0e10cSrcweir #include <general.h> 36*cdf0e10cSrcweir #include <properties.h> 37*cdf0e10cSrcweir #include <threadhelp/resetableguard.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 40*cdf0e10cSrcweir // interface includes 41*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 42*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 44*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 47*cdf0e10cSrcweir // includes of other projects 48*cdf0e10cSrcweir //_________________________________________________________________________________________________________________ 49*cdf0e10cSrcweir #include <vcl/svapp.hxx> 50*cdf0e10cSrcweir #include <rtl/logfile.hxx> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_RESOURCEURL = 1; 53*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_TYPE = 2; 54*cdf0e10cSrcweir const int UIELEMENT_PROPHANDLE_FRAME = 3; 55*cdf0e10cSrcweir const int UIELEMENT_PROPCOUNT = 3; 56*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_RESOURCEURL( RTL_CONSTASCII_USTRINGPARAM( "ResourceURL" )); 57*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_TYPE( RTL_CONSTASCII_USTRINGPARAM( "Type" )); 58*cdf0e10cSrcweir const rtl::OUString UIELEMENT_PROPNAME_FRAME( RTL_CONSTASCII_USTRINGPARAM( "Frame" )); 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir //using namespace rtl; 61*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 62*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 63*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir namespace framework 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir //***************************************************************************************************************** 69*cdf0e10cSrcweir // XInterface, XTypeProvider 70*cdf0e10cSrcweir //***************************************************************************************************************** 71*cdf0e10cSrcweir DEFINE_XINTERFACE_8 ( UIElementWrapperBase , 72*cdf0e10cSrcweir OWeakObject , 73*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ), 74*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::ui::XUIElement ), 75*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ), 76*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ), 77*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ), 78*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XInitialization ), 79*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::util::XUpdatable ), 80*cdf0e10cSrcweir DIRECT_INTERFACE( ::com::sun::star::lang::XComponent ) 81*cdf0e10cSrcweir ) 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir DEFINE_XTYPEPROVIDER_8 ( UIElementWrapperBase , 84*cdf0e10cSrcweir ::com::sun::star::lang::XTypeProvider , 85*cdf0e10cSrcweir ::com::sun::star::ui::XUIElement , 86*cdf0e10cSrcweir ::com::sun::star::beans::XMultiPropertySet , 87*cdf0e10cSrcweir ::com::sun::star::beans::XFastPropertySet , 88*cdf0e10cSrcweir ::com::sun::star::beans::XPropertySet , 89*cdf0e10cSrcweir ::com::sun::star::lang::XInitialization , 90*cdf0e10cSrcweir ::com::sun::star::util::XUpdatable , 91*cdf0e10cSrcweir ::com::sun::star::lang::XComponent 92*cdf0e10cSrcweir ) 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir UIElementWrapperBase::UIElementWrapperBase( sal_Int16 nType ) 95*cdf0e10cSrcweir : ThreadHelpBase ( &Application::GetSolarMutex() ) 96*cdf0e10cSrcweir , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() ) 97*cdf0e10cSrcweir , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) ) 98*cdf0e10cSrcweir , ::cppu::OWeakObject ( ) 99*cdf0e10cSrcweir , m_aListenerContainer ( m_aLock.getShareableOslMutex() ) 100*cdf0e10cSrcweir , m_nType ( nType ) 101*cdf0e10cSrcweir , m_bInitialized ( sal_False ) 102*cdf0e10cSrcweir , m_bDisposed ( sal_False ) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir UIElementWrapperBase::~UIElementWrapperBase() 107*cdf0e10cSrcweir { 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::dispose() throw (::com::sun::star::uno::RuntimeException) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir // must be implemented by derived class 113*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 114*cdf0e10cSrcweir m_bDisposed = sal_True; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 118*cdf0e10cSrcweir { 119*cdf0e10cSrcweir m_aListenerContainer.addInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener ); 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir 122*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference< ::com::sun::star::lang::XEventListener >& xListener ) throw (::com::sun::star::uno::RuntimeException) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir m_aListenerContainer.removeInterface( ::getCppuType( ( const css::uno::Reference< css::lang::XEventListener >* ) NULL ), xListener ); 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::initialize( const Sequence< Any >& aArguments ) 128*cdf0e10cSrcweir throw ( Exception, RuntimeException ) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir ResetableGuard aLock( m_aLock ); 131*cdf0e10cSrcweir 132*cdf0e10cSrcweir if ( !m_bInitialized ) 133*cdf0e10cSrcweir { 134*cdf0e10cSrcweir for ( sal_Int32 n = 0; n < aArguments.getLength(); n++ ) 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir PropertyValue aPropValue; 137*cdf0e10cSrcweir if ( aArguments[n] >>= aPropValue ) 138*cdf0e10cSrcweir { 139*cdf0e10cSrcweir if ( aPropValue.Name.equalsAscii( "ResourceURL" )) 140*cdf0e10cSrcweir aPropValue.Value >>= m_aResourceURL; 141*cdf0e10cSrcweir else if ( aPropValue.Name.equalsAscii( "Frame" )) 142*cdf0e10cSrcweir { 143*cdf0e10cSrcweir Reference< XFrame > xFrame; 144*cdf0e10cSrcweir aPropValue.Value >>= xFrame; 145*cdf0e10cSrcweir m_xWeakFrame = xFrame; 146*cdf0e10cSrcweir } 147*cdf0e10cSrcweir } 148*cdf0e10cSrcweir } 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir m_bInitialized = sal_True; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir // XUIElement 155*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > SAL_CALL UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException) 156*cdf0e10cSrcweir { 157*cdf0e10cSrcweir ::com::sun::star::uno::Reference< ::com::sun::star::frame::XFrame > xFrame( m_xWeakFrame ); 158*cdf0e10cSrcweir return xFrame; 159*cdf0e10cSrcweir } 160*cdf0e10cSrcweir 161*cdf0e10cSrcweir ::rtl::OUString SAL_CALL UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException) 162*cdf0e10cSrcweir { 163*cdf0e10cSrcweir return m_aResourceURL; 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir ::sal_Int16 SAL_CALL UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException) 167*cdf0e10cSrcweir { 168*cdf0e10cSrcweir return m_nType; 169*cdf0e10cSrcweir } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir // XUpdatable 172*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir // can be implemented by derived class 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir // XPropertySet helper 178*cdf0e10cSrcweir sal_Bool SAL_CALL UIElementWrapperBase::convertFastPropertyValue( Any& /*aConvertedValue*/ , 179*cdf0e10cSrcweir Any& /*aOldValue*/ , 180*cdf0e10cSrcweir sal_Int32 /*nHandle*/ , 181*cdf0e10cSrcweir const Any& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException ) 182*cdf0e10cSrcweir { 183*cdf0e10cSrcweir // Initialize state with sal_False !!! 184*cdf0e10cSrcweir // (Handle can be invalid) 185*cdf0e10cSrcweir return sal_False ; 186*cdf0e10cSrcweir } 187*cdf0e10cSrcweir 188*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32 /*nHandle*/ , 189*cdf0e10cSrcweir const com::sun::star::uno::Any& /*aValue*/ ) throw( com::sun::star::uno::Exception ) 190*cdf0e10cSrcweir { 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir void SAL_CALL UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any& aValue , 194*cdf0e10cSrcweir sal_Int32 nHandle ) const 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir switch( nHandle ) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_RESOURCEURL: 199*cdf0e10cSrcweir aValue <<= m_aResourceURL; 200*cdf0e10cSrcweir break; 201*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_TYPE: 202*cdf0e10cSrcweir aValue <<= m_nType; 203*cdf0e10cSrcweir break; 204*cdf0e10cSrcweir case UIELEMENT_PROPHANDLE_FRAME: 205*cdf0e10cSrcweir Reference< XFrame > xFrame( m_xWeakFrame ); 206*cdf0e10cSrcweir aValue <<= xFrame; 207*cdf0e10cSrcweir break; 208*cdf0e10cSrcweir } 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir ::cppu::IPropertyArrayHelper& SAL_CALL UIElementWrapperBase::getInfoHelper() 212*cdf0e10cSrcweir { 213*cdf0e10cSrcweir // Optimize this method ! 214*cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 215*cdf0e10cSrcweir // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL! 216*cdf0e10cSrcweir static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL; 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir if( pInfoHelper == NULL ) 219*cdf0e10cSrcweir { 220*cdf0e10cSrcweir // Ready for multithreading 221*cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 224*cdf0e10cSrcweir if( pInfoHelper == NULL ) 225*cdf0e10cSrcweir { 226*cdf0e10cSrcweir // Define static member to give structure of properties to baseclass "OPropertySetHelper". 227*cdf0e10cSrcweir // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable. 228*cdf0e10cSrcweir // "sal_True" say: Table is sorted by name. 229*cdf0e10cSrcweir static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True ); 230*cdf0e10cSrcweir pInfoHelper = &aInfoHelper; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir } 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir return(*pInfoHelper); 235*cdf0e10cSrcweir } 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException) 238*cdf0e10cSrcweir { 239*cdf0e10cSrcweir // Optimize this method ! 240*cdf0e10cSrcweir // We initialize a static variable only one time. And we don't must use a mutex at every call! 241*cdf0e10cSrcweir // For the first call; pInfo is NULL - for the second call pInfo is different from NULL! 242*cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL; 243*cdf0e10cSrcweir 244*cdf0e10cSrcweir if( pInfo == NULL ) 245*cdf0e10cSrcweir { 246*cdf0e10cSrcweir // Ready for multithreading 247*cdf0e10cSrcweir osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ; 248*cdf0e10cSrcweir // Control this pointer again, another instance can be faster then these! 249*cdf0e10cSrcweir if( pInfo == NULL ) 250*cdf0e10cSrcweir { 251*cdf0e10cSrcweir // Create structure of propertysetinfo for baseclass "OPropertySetHelper". 252*cdf0e10cSrcweir // (Use method "getInfoHelper()".) 253*cdf0e10cSrcweir static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) ); 254*cdf0e10cSrcweir pInfo = &xInfo; 255*cdf0e10cSrcweir } 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir return (*pInfo); 259*cdf0e10cSrcweir } 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir const com::sun::star::uno::Sequence< com::sun::star::beans::Property > UIElementWrapperBase::impl_getStaticPropertyDescriptor() 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir // Create a new static property array to initialize sequence! 264*cdf0e10cSrcweir // Table of all predefined properties of this class. Its used from OPropertySetHelper-class! 265*cdf0e10cSrcweir // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!! 266*cdf0e10cSrcweir // It's necessary for methods of OPropertySetHelper. 267*cdf0e10cSrcweir // ATTENTION: 268*cdf0e10cSrcweir // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!! 269*cdf0e10cSrcweir 270*cdf0e10cSrcweir static const com::sun::star::beans::Property pProperties[] = 271*cdf0e10cSrcweir { 272*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_FRAME , UIELEMENT_PROPHANDLE_FRAME , ::getCppuType((Reference< XFrame >*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ), 273*cdf0e10cSrcweir com::sun::star::beans::Property( UIELEMENT_PROPNAME_RESOURCEURL , UIELEMENT_PROPHANDLE_RESOURCEURL , ::getCppuType((sal_Int16*)NULL), com::sun::star::beans::PropertyAttribute::TRANSIENT | com::sun::star::beans::PropertyAttribute::READONLY ), 274*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 ) 275*cdf0e10cSrcweir }; 276*cdf0e10cSrcweir // Use it to initialize sequence! 277*cdf0e10cSrcweir static const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, UIELEMENT_PROPCOUNT ); 278*cdf0e10cSrcweir // Return static "PropertyDescriptor" 279*cdf0e10cSrcweir return lPropertyDescriptor; 280*cdf0e10cSrcweir } 281*cdf0e10cSrcweir 282*cdf0e10cSrcweir } 283