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