1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
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.
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).
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.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_framework.hxx"
31 //_________________________________________________________________________________________________________________
33 //_________________________________________________________________________________________________________________
34 #include <helper/uielementwrapperbase.hxx>
36 #include <properties.h>
37 #include <threadhelp/resetableguard.hxx>
39 //_________________________________________________________________________________________________________________
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>
46 //_________________________________________________________________________________________________________________
47 // includes of other projects
48 //_________________________________________________________________________________________________________________
49 #include <vcl/svapp.hxx>
50 #include <rtl/logfile.hxx>
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" ));
61 using namespace ::com::sun::star::uno
;
62 using namespace ::com::sun::star::beans
;
63 using namespace ::com::sun::star::frame
;
68 //*****************************************************************************************************************
69 // XInterface, XTypeProvider
70 //*****************************************************************************************************************
71 DEFINE_XINTERFACE_8 ( UIElementWrapperBase
,
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
)
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
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() )
101 , m_bInitialized ( sal_False
)
102 , m_bDisposed ( sal_False
)
106 UIElementWrapperBase::~UIElementWrapperBase()
110 void SAL_CALL
UIElementWrapperBase::dispose() throw (::com::sun::star::uno::RuntimeException
)
112 // must be implemented by derived class
113 ResetableGuard
aLock( m_aLock
);
114 m_bDisposed
= sal_True
;
117 void SAL_CALL
UIElementWrapperBase::addEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
)
119 m_aListenerContainer
.addInterface( ::getCppuType( ( const css::uno::Reference
< css::lang::XEventListener
>* ) NULL
), xListener
);
122 void SAL_CALL
UIElementWrapperBase::removeEventListener( const ::com::sun::star::uno::Reference
< ::com::sun::star::lang::XEventListener
>& xListener
) throw (::com::sun::star::uno::RuntimeException
)
124 m_aListenerContainer
.removeInterface( ::getCppuType( ( const css::uno::Reference
< css::lang::XEventListener
>* ) NULL
), xListener
);
127 void SAL_CALL
UIElementWrapperBase::initialize( const Sequence
< Any
>& aArguments
)
128 throw ( Exception
, RuntimeException
)
130 ResetableGuard
aLock( m_aLock
);
132 if ( !m_bInitialized
)
134 for ( sal_Int32 n
= 0; n
< aArguments
.getLength(); n
++ )
136 PropertyValue aPropValue
;
137 if ( aArguments
[n
] >>= aPropValue
)
139 if ( aPropValue
.Name
.equalsAscii( "ResourceURL" ))
140 aPropValue
.Value
>>= m_aResourceURL
;
141 else if ( aPropValue
.Name
.equalsAscii( "Frame" ))
143 Reference
< XFrame
> xFrame
;
144 aPropValue
.Value
>>= xFrame
;
145 m_xWeakFrame
= xFrame
;
150 m_bInitialized
= sal_True
;
155 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> SAL_CALL
UIElementWrapperBase::getFrame() throw (::com::sun::star::uno::RuntimeException
)
157 ::com::sun::star::uno::Reference
< ::com::sun::star::frame::XFrame
> xFrame( m_xWeakFrame
);
161 ::rtl::OUString SAL_CALL
UIElementWrapperBase::getResourceURL() throw (::com::sun::star::uno::RuntimeException
)
163 return m_aResourceURL
;
166 ::sal_Int16 SAL_CALL
UIElementWrapperBase::getType() throw (::com::sun::star::uno::RuntimeException
)
172 void SAL_CALL
UIElementWrapperBase::update() throw (::com::sun::star::uno::RuntimeException
)
174 // can be implemented by derived class
177 // XPropertySet helper
178 sal_Bool SAL_CALL
UIElementWrapperBase::convertFastPropertyValue( Any
& /*aConvertedValue*/ ,
180 sal_Int32
/*nHandle*/ ,
181 const Any
& /*aValue*/ ) throw( com::sun::star::lang::IllegalArgumentException
)
183 // Initialize state with FALSE !!!
184 // (Handle can be invalid)
188 void SAL_CALL
UIElementWrapperBase::setFastPropertyValue_NoBroadcast( sal_Int32
/*nHandle*/ ,
189 const com::sun::star::uno::Any
& /*aValue*/ ) throw( com::sun::star::uno::Exception
)
193 void SAL_CALL
UIElementWrapperBase::getFastPropertyValue( com::sun::star::uno::Any
& aValue
,
194 sal_Int32 nHandle
) const
198 case UIELEMENT_PROPHANDLE_RESOURCEURL
:
199 aValue
<<= m_aResourceURL
;
201 case UIELEMENT_PROPHANDLE_TYPE
:
204 case UIELEMENT_PROPHANDLE_FRAME
:
205 Reference
< XFrame
> xFrame( m_xWeakFrame
);
211 ::cppu::IPropertyArrayHelper
& SAL_CALL
UIElementWrapperBase::getInfoHelper()
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
;
218 if( pInfoHelper
== NULL
)
220 // Ready for multithreading
221 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
223 // Control this pointer again, another instance can be faster then these!
224 if( pInfoHelper
== NULL
)
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
;
234 return(*pInfoHelper
);
237 com::sun::star::uno::Reference
< com::sun::star::beans::XPropertySetInfo
> SAL_CALL
UIElementWrapperBase::getPropertySetInfo() throw (::com::sun::star::uno::RuntimeException
)
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
;
246 // Ready for multithreading
247 osl::MutexGuard
aGuard( osl::Mutex::getGlobalMutex() ) ;
248 // Control this pointer again, another instance can be faster then these!
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() ) );
261 const com::sun::star::uno::Sequence
< com::sun::star::beans::Property
> UIElementWrapperBase::impl_getStaticPropertyDescriptor()
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.
268 // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
270 static const com::sun::star::beans::Property pProperties
[] =
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
)
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
;