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