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