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