Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <comphelper/servicehelper.hxx>
30 : : #include <uielement/rootitemcontainer.hxx>
31 : : #include <uielement/itemcontainer.hxx>
32 : : #include <uielement/constitemcontainer.hxx>
33 : : #include <threadhelp/resetableguard.hxx>
34 : : #include <general.h>
35 : : #include <properties.h>
36 : :
37 : : #include <com/sun/star/beans/PropertyAttribute.hpp>
38 : :
39 : : using namespace cppu;
40 : : using namespace com::sun::star::uno;
41 : : using namespace com::sun::star::lang;
42 : : using namespace com::sun::star::beans;
43 : : using namespace com::sun::star::container;
44 : :
45 : : const char WRONG_TYPE_EXCEPTION[] = "Type must be com::sun::star::uno::Sequence< com::sun::star::beans::PropertyValue >";
46 : :
47 : : const int PROPHANDLE_UINAME = 1;
48 : : const int PROPCOUNT = 1;
49 : : const char PROPNAME_UINAME[] = "UIName";
50 : :
51 : : namespace framework
52 : : {
53 : :
54 : : //*****************************************************************************************************************
55 : : // XInterface, XTypeProvider
56 : : //*****************************************************************************************************************
57 [ + + ][ + - ]: 19578 : DEFINE_XINTERFACE_10 ( RootItemContainer ,
58 : : OWeakObject ,
59 : : DIRECT_INTERFACE( ::com::sun::star::lang::XTypeProvider ),
60 : : DIRECT_INTERFACE( ::com::sun::star::container::XIndexContainer ),
61 : : DIRECT_INTERFACE( ::com::sun::star::lang::XUnoTunnel ),
62 : : DIRECT_INTERFACE( ::com::sun::star::lang::XSingleComponentFactory ),
63 : : DIRECT_INTERFACE( ::com::sun::star::beans::XMultiPropertySet ),
64 : : DIRECT_INTERFACE( ::com::sun::star::beans::XFastPropertySet ),
65 : : DIRECT_INTERFACE( ::com::sun::star::beans::XPropertySet ),
66 : : DERIVED_INTERFACE( ::com::sun::star::container::XIndexReplace, com::sun::star::container::XIndexContainer ),
67 : : DERIVED_INTERFACE( ::com::sun::star::container::XIndexAccess, com::sun::star::container::XIndexReplace ),
68 : : DERIVED_INTERFACE( ::com::sun::star::container::XElementAccess, ::com::sun::star::container::XIndexAccess )
69 : : )
70 : :
71 [ + + ][ + - ]: 4 : DEFINE_XTYPEPROVIDER_10 ( RootItemContainer ,
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ + - ][ + - ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
72 : : ::com::sun::star::lang::XTypeProvider ,
73 : : ::com::sun::star::container::XIndexContainer ,
74 : : ::com::sun::star::container::XIndexReplace ,
75 : : ::com::sun::star::container::XIndexAccess ,
76 : : ::com::sun::star::container::XElementAccess ,
77 : : ::com::sun::star::beans::XMultiPropertySet ,
78 : : ::com::sun::star::beans::XFastPropertySet ,
79 : : ::com::sun::star::beans::XPropertySet ,
80 : : ::com::sun::star::lang::XUnoTunnel ,
81 : : ::com::sun::star::lang::XSingleComponentFactory
82 : : )
83 : :
84 : 414 : RootItemContainer::RootItemContainer()
85 : : : ThreadHelpBase ( )
86 [ + - ]: 414 : , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
87 : : , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
88 [ + - ][ + - ]: 828 : , ::cppu::OWeakObject()
[ + - ][ + - ]
[ + - ]
89 : : {
90 : 414 : }
91 : :
92 : 10 : RootItemContainer::RootItemContainer( const Reference< XIndexAccess >& rSourceContainer )
93 : : : ThreadHelpBase ( )
94 [ + - ]: 10 : , ::cppu::OBroadcastHelperVar< ::cppu::OMultiTypeInterfaceContainerHelper, ::cppu::OMultiTypeInterfaceContainerHelper::keyType >( m_aLock.getShareableOslMutex() )
95 : : , ::cppu::OPropertySetHelper ( *(static_cast< ::cppu::OBroadcastHelper* >(this)) )
96 [ + - ][ + - ]: 20 : , ::cppu::OWeakObject()
[ + - ][ + - ]
[ + - ]
97 : : {
98 : : // We also have to copy the UIName property
99 : : try
100 : : {
101 [ + - ]: 10 : Reference< XPropertySet > xPropSet( rSourceContainer, UNO_QUERY );
102 [ + - ]: 10 : if ( xPropSet.is() )
103 : : {
104 [ + - ][ + - ]: 10 : xPropSet->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UIName" ))) >>= m_aUIName;
[ + - ]
105 [ # # ]: 10 : }
106 : : }
107 [ # # ]: 0 : catch ( const Exception& )
108 : : {
109 : : }
110 : :
111 [ + - ]: 10 : if ( rSourceContainer.is() )
112 : : {
113 [ + - ][ + - ]: 10 : sal_Int32 nCount = rSourceContainer->getCount();
114 : : try
115 : : {
116 [ + + ]: 102 : for ( sal_Int32 i = 0; i < nCount; i++ )
117 : : {
118 [ + - ]: 92 : Sequence< PropertyValue > aPropSeq;
119 [ + - ][ + - ]: 92 : if ( rSourceContainer->getByIndex( i ) >>= aPropSeq )
[ + - ][ + - ]
120 : : {
121 : 92 : sal_Int32 nContainerIndex = -1;
122 : 92 : Reference< XIndexAccess > xIndexAccess;
123 [ + - ]: 278 : for ( sal_Int32 j = 0; j < aPropSeq.getLength(); j++ )
124 : : {
125 [ + - ][ + + ]: 278 : if ( aPropSeq[j].Name == "ItemDescriptorContainer" )
126 : : {
127 [ + - ][ + - ]: 92 : aPropSeq[j].Value >>= xIndexAccess;
128 : 92 : nContainerIndex = j;
129 : 92 : break;
130 : : }
131 : : }
132 : :
133 [ + - ][ + - ]: 92 : if ( xIndexAccess.is() && nContainerIndex >= 0 )
[ + - ]
134 [ + - ][ + - ]: 92 : aPropSeq[nContainerIndex].Value <<= deepCopyContainer( xIndexAccess );
[ + - ]
135 : :
136 [ + - ]: 92 : m_aItemVector.push_back( aPropSeq );
137 : : }
138 [ + - # # ]: 92 : }
139 : : }
140 [ # # ]: 0 : catch ( const IndexOutOfBoundsException& )
141 : : {
142 : : }
143 : : }
144 : 10 : }
145 : :
146 [ + - ][ + - ]: 424 : RootItemContainer::~RootItemContainer()
[ + - ][ + - ]
[ + - ]
147 : : {
148 [ - + ]: 848 : }
149 : :
150 : 92 : Reference< XIndexAccess > RootItemContainer::deepCopyContainer( const Reference< XIndexAccess >& rSubContainer )
151 : : {
152 : 92 : Reference< XIndexAccess > xReturn;
153 [ + - ]: 92 : if ( rSubContainer.is() )
154 : : {
155 : 92 : ConstItemContainer* pSource = ConstItemContainer::GetImplementation( rSubContainer );
156 : 92 : ItemContainer* pSubContainer( 0 );
157 [ + + ]: 92 : if ( pSource )
158 [ + - ]: 20 : pSubContainer = new ItemContainer( *pSource, m_aShareMutex );
159 : : else
160 [ + - ]: 72 : pSubContainer = new ItemContainer( rSubContainer, m_aShareMutex );
161 [ + - ][ + - ]: 92 : xReturn = Reference< XIndexAccess >( static_cast< OWeakObject* >( pSubContainer ), UNO_QUERY );
162 : : }
163 : :
164 : 92 : return xReturn;
165 : : }
166 : :
167 : : // XUnoTunnel
168 : 412 : sal_Int64 RootItemContainer::getSomething( const ::com::sun::star::uno::Sequence< sal_Int8 >& rIdentifier ) throw(::com::sun::star::uno::RuntimeException)
169 : : {
170 [ + - ][ + - ]: 412 : if( ( rIdentifier.getLength() == 16 ) && ( 0 == rtl_compareMemory( RootItemContainer::GetUnoTunnelId().getConstArray(), rIdentifier.getConstArray(), 16 ) ) )
[ + - ]
171 : 412 : return sal::static_int_cast< sal_Int64 >( reinterpret_cast< sal_IntPtr >( this ));
172 : 412 : return 0;
173 : : }
174 : :
175 : : namespace
176 : : {
177 : : class theRootItemContainerUnoTunnelId : public rtl::Static< UnoTunnelIdInit, theRootItemContainerUnoTunnelId > {};
178 : : }
179 : :
180 : 824 : const Sequence< sal_Int8 >& RootItemContainer::GetUnoTunnelId() throw()
181 : : {
182 : 824 : return theRootItemContainerUnoTunnelId::get().getSeq();
183 : : }
184 : :
185 : 412 : RootItemContainer* RootItemContainer::GetImplementation( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& rxIFace ) throw()
186 : : {
187 [ + - ]: 412 : ::com::sun::star::uno::Reference< ::com::sun::star::lang::XUnoTunnel > xUT( rxIFace, ::com::sun::star::uno::UNO_QUERY );
188 : 412 : return xUT.is() ? reinterpret_cast< RootItemContainer* >(sal::static_int_cast< sal_IntPtr >(
189 [ + - ][ + - ]: 412 : xUT->getSomething( RootItemContainer::GetUnoTunnelId() ))) : NULL;
[ + - ]
190 : : }
191 : :
192 : : // XElementAccess
193 : 0 : sal_Bool SAL_CALL RootItemContainer::hasElements()
194 : : throw ( RuntimeException )
195 : : {
196 [ # # ]: 0 : ShareGuard aLock( m_aShareMutex );
197 [ # # ]: 0 : return ( !m_aItemVector.empty() );
198 : : }
199 : :
200 : : // XIndexAccess
201 : 9766 : sal_Int32 SAL_CALL RootItemContainer::getCount()
202 : : throw ( RuntimeException )
203 : : {
204 [ + - ]: 9766 : ShareGuard aLock( m_aShareMutex );
205 [ + - ]: 9766 : return m_aItemVector.size();
206 : : }
207 : :
208 : 9394 : Any SAL_CALL RootItemContainer::getByIndex( sal_Int32 Index )
209 : : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
210 : : {
211 [ + - ]: 9394 : ShareGuard aLock( m_aShareMutex );
212 [ + - ]: 9394 : if ( sal_Int32( m_aItemVector.size()) > Index )
213 [ + - ]: 18788 : return makeAny( m_aItemVector[Index] );
214 : : else
215 [ # # ][ # # ]: 9394 : throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
[ + - ]
216 : : }
217 : :
218 : : // XIndexContainer
219 : 9280 : void SAL_CALL RootItemContainer::insertByIndex( sal_Int32 Index, const Any& aItem )
220 : : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
221 : : {
222 [ + - ]: 9280 : Sequence< PropertyValue > aSeq;
223 [ + - ][ + - ]: 9280 : if ( aItem >>= aSeq )
224 : : {
225 [ + - ]: 9280 : ShareGuard aLock( m_aShareMutex );
226 [ + - ]: 9280 : if ( sal_Int32( m_aItemVector.size()) == Index )
227 [ + - ]: 9280 : m_aItemVector.push_back( aSeq );
228 [ # # ]: 0 : else if ( sal_Int32( m_aItemVector.size()) >Index )
229 : : {
230 : 0 : std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
231 : 0 : aIter += Index;
232 [ # # ]: 0 : m_aItemVector.insert( aIter, aSeq );
233 : : }
234 : : else
235 [ # # ][ # # ]: 9280 : throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
[ + - ]
236 : : }
237 : : else
238 : : throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
239 [ + - ][ # # ]: 9280 : (OWeakObject *)this, 2 );
[ # # ][ # # ]
240 : 9280 : }
241 : :
242 : 0 : void SAL_CALL RootItemContainer::removeByIndex( sal_Int32 Index )
243 : : throw ( IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
244 : : {
245 [ # # ]: 0 : ShareGuard aLock( m_aShareMutex );
246 [ # # ]: 0 : if ( (sal_Int32)m_aItemVector.size() > Index )
247 : : {
248 : 0 : std::vector< Sequence< PropertyValue > >::iterator aIter = m_aItemVector.begin();
249 : 0 : aIter += Index;
250 [ # # ]: 0 : m_aItemVector.erase( aIter );
251 : : }
252 : : else
253 [ # # ][ # # ]: 0 : throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
[ # # ]
254 : 0 : }
255 : :
256 : 0 : void SAL_CALL RootItemContainer::replaceByIndex( sal_Int32 Index, const Any& aItem )
257 : : throw ( IllegalArgumentException, IndexOutOfBoundsException, WrappedTargetException, RuntimeException )
258 : : {
259 [ # # ]: 0 : Sequence< PropertyValue > aSeq;
260 [ # # ][ # # ]: 0 : if ( aItem >>= aSeq )
261 : : {
262 [ # # ]: 0 : ShareGuard aLock( m_aShareMutex );
263 [ # # ]: 0 : if ( sal_Int32( m_aItemVector.size()) > Index )
264 [ # # ]: 0 : m_aItemVector[Index] = aSeq;
265 : : else
266 [ # # ][ # # ]: 0 : throw IndexOutOfBoundsException( ::rtl::OUString(), (OWeakObject *)this );
[ # # ]
267 : : }
268 : : else
269 : : throw IllegalArgumentException( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( WRONG_TYPE_EXCEPTION )),
270 [ # # ][ # # ]: 0 : (OWeakObject *)this, 2 );
[ # # ][ # # ]
271 : 0 : }
272 : :
273 : 3284 : Reference< XInterface > SAL_CALL RootItemContainer::createInstanceWithContext( const Reference< XComponentContext >& )
274 : : throw ( Exception, RuntimeException)
275 : : {
276 [ + - ]: 3284 : return (OWeakObject *)(new ItemContainer( m_aShareMutex ));
277 : : }
278 : :
279 : 0 : Reference< XInterface > SAL_CALL RootItemContainer::createInstanceWithArgumentsAndContext( const Sequence< Any >&, const Reference< XComponentContext >& )
280 : : throw (Exception, RuntimeException)
281 : : {
282 [ # # ]: 0 : return (OWeakObject *)(new ItemContainer( m_aShareMutex ));
283 : : }
284 : :
285 : : // XPropertySet helper
286 : 0 : sal_Bool SAL_CALL RootItemContainer::convertFastPropertyValue( Any& aConvertedValue ,
287 : : Any& aOldValue ,
288 : : sal_Int32 nHandle ,
289 : : const Any& aValue )
290 : : throw( com::sun::star::lang::IllegalArgumentException )
291 : : {
292 : : // Initialize state with sal_False !!!
293 : : // (Handle can be invalid)
294 : 0 : sal_Bool bReturn = sal_False;
295 : :
296 [ # # ]: 0 : switch( nHandle )
297 : : {
298 : : case PROPHANDLE_UINAME:
299 : : bReturn = PropHelper::willPropertyBeChanged(
300 : : com::sun::star::uno::makeAny(m_aUIName),
301 : : aValue,
302 : : aOldValue,
303 : 0 : aConvertedValue);
304 : 0 : break;
305 : : }
306 : :
307 : : // Return state of operation.
308 : 0 : return bReturn ;
309 : : }
310 : :
311 : 0 : void SAL_CALL RootItemContainer::setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
312 : : const com::sun::star::uno::Any& aValue )
313 : : throw( com::sun::star::uno::Exception )
314 : : {
315 [ # # ]: 0 : switch( nHandle )
316 : : {
317 : : case PROPHANDLE_UINAME:
318 : 0 : aValue >>= m_aUIName;
319 : 0 : break;
320 : : }
321 : 0 : }
322 : :
323 : 420 : void SAL_CALL RootItemContainer::getFastPropertyValue( com::sun::star::uno::Any& aValue ,
324 : : sal_Int32 nHandle ) const
325 : : {
326 [ + - ]: 420 : switch( nHandle )
327 : : {
328 : : case PROPHANDLE_UINAME:
329 : 420 : aValue <<= m_aUIName;
330 : 420 : break;
331 : : }
332 : 420 : }
333 : :
334 : 840 : ::cppu::IPropertyArrayHelper& SAL_CALL RootItemContainer::getInfoHelper()
335 : : {
336 : : // Optimize this method !
337 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
338 : : // For the first call; pInfoHelper is NULL - for the second call pInfoHelper is different from NULL!
339 : : static ::cppu::OPropertyArrayHelper* pInfoHelper = NULL;
340 : :
341 [ + + ]: 840 : if( pInfoHelper == NULL )
342 : : {
343 : : // Ready for multithreading
344 [ + - ][ + - ]: 60 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
345 : :
346 : : // Control this pointer again, another instance can be faster then these!
347 [ + - ]: 60 : if( pInfoHelper == NULL )
348 : : {
349 : : // Define static member to give structure of properties to baseclass "OPropertySetHelper".
350 : : // "impl_getStaticPropertyDescriptor" is a non exported and static funtion, who will define a static propertytable.
351 : : // "sal_True" say: Table is sorted by name.
352 [ + - ][ + - ]: 60 : static ::cppu::OPropertyArrayHelper aInfoHelper( impl_getStaticPropertyDescriptor(), sal_True );
[ + - ][ + - ]
[ + - ][ # # ]
353 : 60 : pInfoHelper = &aInfoHelper;
354 [ + - ]: 60 : }
355 : : }
356 : :
357 : 840 : return(*pInfoHelper);
358 : : }
359 : :
360 : 0 : com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > SAL_CALL RootItemContainer::getPropertySetInfo()
361 : : throw (::com::sun::star::uno::RuntimeException)
362 : : {
363 : : // Optimize this method !
364 : : // We initialize a static variable only one time. And we don't must use a mutex at every call!
365 : : // For the first call; pInfo is NULL - for the second call pInfo is different from NULL!
366 : : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo >* pInfo = NULL;
367 : :
368 [ # # ]: 0 : if( pInfo == NULL )
369 : : {
370 : : // Ready for multithreading
371 [ # # ][ # # ]: 0 : osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
372 : : // Control this pointer again, another instance can be faster then these!
373 [ # # ]: 0 : if( pInfo == NULL )
374 : : {
375 : : // Create structure of propertysetinfo for baseclass "OPropertySetHelper".
376 : : // (Use method "getInfoHelper()".)
377 [ # # ][ # # ]: 0 : static com::sun::star::uno::Reference< com::sun::star::beans::XPropertySetInfo > xInfo( createPropertySetInfo( getInfoHelper() ) );
[ # # ][ # # ]
[ # # ]
378 : 0 : pInfo = &xInfo;
379 [ # # ]: 0 : }
380 : : }
381 : :
382 : 0 : return (*pInfo);
383 : : }
384 : :
385 : 60 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > RootItemContainer::impl_getStaticPropertyDescriptor()
386 : : {
387 : : // Create a property array to initialize sequence!
388 : : // Table of all predefined properties of this class. Its used from OPropertySetHelper-class!
389 : : // Don't forget to change the defines (see begin of this file), if you add, change or delete a property in this list!!!
390 : : // It's necessary for methods of OPropertySetHelper.
391 : : // ATTENTION:
392 : : // YOU MUST SORT FOLLOW TABLE BY NAME ALPHABETICAL !!!
393 : :
394 : : const com::sun::star::beans::Property pProperties[] =
395 : : {
396 : : com::sun::star::beans::Property( rtl::OUString(PROPNAME_UINAME), PROPHANDLE_UINAME ,
397 [ + - ]: 60 : ::getCppuType((const rtl::OUString*)NULL),
398 : : com::sun::star::beans::PropertyAttribute::TRANSIENT )
399 [ # # # # ]: 120 : };
400 : : // Use it to initialize sequence!
401 [ + - ]: 60 : const com::sun::star::uno::Sequence< com::sun::star::beans::Property > lPropertyDescriptor( pProperties, PROPCOUNT );
402 : : // Return "PropertyDescriptor"
403 [ + + ][ # # ]: 120 : return lPropertyDescriptor;
404 : : }
405 : :
406 : : } // namespace framework
407 : :
408 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|