Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "toolkit/controls/geometrycontrolmodel.hxx"
21 : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 : #include <com/sun/star/beans/PropertyAttribute.hpp>
23 : #include <osl/diagnose.h>
24 : #include <rtl/instance.hxx>
25 : #include <comphelper/property.hxx>
26 : #include <comphelper/sequence.hxx>
27 : #include <toolkit/controls/eventcontainer.hxx>
28 : #include <toolkit/helper/property.hxx>
29 : #include <algorithm>
30 : #include <functional>
31 :
32 :
33 : #define GCM_PROPERTY_ID_POS_X 1
34 : #define GCM_PROPERTY_ID_POS_Y 2
35 : #define GCM_PROPERTY_ID_WIDTH 3
36 : #define GCM_PROPERTY_ID_HEIGHT 4
37 : #define GCM_PROPERTY_ID_NAME 5
38 : #define GCM_PROPERTY_ID_TABINDEX 6
39 : #define GCM_PROPERTY_ID_STEP 7
40 : #define GCM_PROPERTY_ID_TAG 8
41 : #define GCM_PROPERTY_ID_RESOURCERESOLVER 9
42 :
43 : #define GCM_PROPERTY_POS_X OUString("PositionX")
44 : #define GCM_PROPERTY_POS_Y OUString("PositionY")
45 : #define GCM_PROPERTY_WIDTH OUString("Width")
46 : #define GCM_PROPERTY_HEIGHT OUString("Height")
47 : #define GCM_PROPERTY_NAME OUString("Name")
48 : #define GCM_PROPERTY_TABINDEX OUString("TabIndex")
49 : #define GCM_PROPERTY_STEP OUString("Step")
50 : #define GCM_PROPERTY_TAG OUString("Tag")
51 : #define GCM_PROPERTY_RESOURCERESOLVER OUString("ResourceResolver")
52 :
53 : #define DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT
54 :
55 :
56 : // namespace toolkit
57 : // {
58 :
59 :
60 : using namespace ::com::sun::star;
61 : using namespace ::com::sun::star::uno;
62 : using namespace ::com::sun::star::lang;
63 : using namespace ::com::sun::star::beans;
64 : using namespace ::com::sun::star::util;
65 : using namespace ::com::sun::star::container;
66 : using namespace ::comphelper;
67 :
68 :
69 : //= OGeometryControlModel_Base
70 :
71 :
72 104 : OGeometryControlModel_Base::OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance)
73 : :OPropertySetAggregationHelper( m_aBHelper )
74 : ,OPropertyContainer( m_aBHelper )
75 : ,OGCM_Base( m_aMutex )
76 : ,m_nPosX(0)
77 : ,m_nPosY(0)
78 : ,m_nWidth(0)
79 : ,m_nHeight(0)
80 : ,m_nTabIndex(-1)
81 : ,m_nStep(0)
82 104 : ,m_bCloneable(false)
83 : {
84 : OSL_ENSURE(NULL != _pAggregateInstance, "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid aggregate!");
85 :
86 104 : increment(m_refCount);
87 : {
88 104 : m_xAggregate = _pAggregateInstance;
89 :
90 : { // check if the aggregate is cloneable
91 104 : Reference< XCloneable > xCloneAccess(m_xAggregate, UNO_QUERY);
92 104 : m_bCloneable = xCloneAccess.is();
93 : }
94 :
95 104 : setAggregation(m_xAggregate);
96 104 : m_xAggregate->setDelegator(static_cast< XWeak* >(this));
97 : }
98 104 : decrement(m_refCount);
99 :
100 104 : registerProperties();
101 104 : }
102 :
103 :
104 38 : OGeometryControlModel_Base::OGeometryControlModel_Base(Reference< XCloneable >& _rxAggregateInstance)
105 : :OPropertySetAggregationHelper( m_aBHelper )
106 : ,OPropertyContainer( m_aBHelper )
107 : ,OGCM_Base( m_aMutex )
108 : ,m_nPosX(0)
109 : ,m_nPosY(0)
110 : ,m_nWidth(0)
111 : ,m_nHeight(0)
112 : ,m_nTabIndex(-1)
113 : ,m_nStep(0)
114 38 : ,m_bCloneable(_rxAggregateInstance.is())
115 : {
116 38 : increment(m_refCount);
117 : {
118 : {
119 : // ensure that the temporary gets destructed NOW
120 38 : m_xAggregate = Reference< XAggregation >(_rxAggregateInstance, UNO_QUERY);
121 : }
122 : OSL_ENSURE(m_xAggregate.is(), "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid object given!");
123 :
124 : // now the aggregate has a ref count of 2, but before setting the delegator it must be 1
125 38 : _rxAggregateInstance.clear();
126 : // now it should be the 1 we need here ...
127 :
128 38 : setAggregation(m_xAggregate);
129 38 : m_xAggregate->setDelegator(static_cast< XWeak* >(this));
130 : }
131 38 : decrement(m_refCount);
132 :
133 38 : registerProperties();
134 38 : }
135 :
136 :
137 308 : Sequence< Type > SAL_CALL OGeometryControlModel_Base::getTypes( ) throw (RuntimeException, std::exception)
138 : {
139 : // our own types
140 : Sequence< Type > aTypes = ::comphelper::concatSequences(
141 : OPropertySetAggregationHelper::getTypes(),
142 : getBaseTypes(),
143 : OGCM_Base::getTypes()
144 308 : );
145 :
146 308 : if ( m_xAggregate.is() )
147 : {
148 : // retrieve the types of the aggregate
149 308 : Reference< XTypeProvider > xAggregateTypeProv;
150 308 : m_xAggregate->queryAggregation( ::getCppuType( &xAggregateTypeProv ) ) >>= xAggregateTypeProv;
151 : OSL_ENSURE( xAggregateTypeProv.is(), "OGeometryControlModel_Base::getTypes: aggregate should be a type provider!" );
152 616 : Sequence< Type > aAggTypes;
153 308 : if ( xAggregateTypeProv.is() )
154 308 : aAggTypes = xAggregateTypeProv->getTypes();
155 :
156 : // concat the sequences
157 308 : sal_Int32 nOldSize = aTypes.getLength();
158 308 : aTypes.realloc( nOldSize + aAggTypes.getLength() );
159 : ::std::copy(
160 : aAggTypes.getConstArray(),
161 308 : aAggTypes.getConstArray() + aAggTypes.getLength(),
162 308 : aTypes.getArray() + nOldSize
163 924 : );
164 : }
165 :
166 308 : return aTypes;
167 : }
168 :
169 :
170 142 : void OGeometryControlModel_Base::registerProperties()
171 : {
172 : // register our members for the property handling of the OPropertyContainer
173 142 : registerProperty(GCM_PROPERTY_POS_X, GCM_PROPERTY_ID_POS_X, DEFAULT_ATTRIBS(), &m_nPosX, ::getCppuType(&m_nPosX));
174 142 : registerProperty(GCM_PROPERTY_POS_Y, GCM_PROPERTY_ID_POS_Y, DEFAULT_ATTRIBS(), &m_nPosY, ::getCppuType(&m_nPosY));
175 142 : registerProperty(GCM_PROPERTY_WIDTH, GCM_PROPERTY_ID_WIDTH, DEFAULT_ATTRIBS(), &m_nWidth, ::getCppuType(&m_nWidth));
176 142 : registerProperty(GCM_PROPERTY_HEIGHT, GCM_PROPERTY_ID_HEIGHT, DEFAULT_ATTRIBS(), &m_nHeight, ::getCppuType(&m_nHeight));
177 142 : registerProperty(GCM_PROPERTY_NAME, GCM_PROPERTY_ID_NAME, DEFAULT_ATTRIBS(), &m_aName, ::getCppuType(&m_aName));
178 142 : registerProperty(GCM_PROPERTY_TABINDEX, GCM_PROPERTY_ID_TABINDEX, DEFAULT_ATTRIBS(), &m_nTabIndex, ::getCppuType(&m_nTabIndex));
179 142 : registerProperty(GCM_PROPERTY_STEP, GCM_PROPERTY_ID_STEP, DEFAULT_ATTRIBS(), &m_nStep, ::getCppuType(&m_nStep));
180 142 : registerProperty(GCM_PROPERTY_TAG, GCM_PROPERTY_ID_TAG, DEFAULT_ATTRIBS(), &m_aTag, ::getCppuType(&m_aTag));
181 142 : registerProperty(GCM_PROPERTY_RESOURCERESOLVER, GCM_PROPERTY_ID_RESOURCERESOLVER, DEFAULT_ATTRIBS(), &m_xStrResolver, ::getCppuType(&m_xStrResolver));
182 142 : }
183 :
184 :
185 84 : ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetDefaultValueByHandle(sal_Int32 nHandle) const
186 : {
187 84 : ::com::sun::star::uno::Any aDefault;
188 :
189 84 : switch ( nHandle )
190 : {
191 0 : case GCM_PROPERTY_ID_POS_X: aDefault <<= (sal_Int32) 0; break;
192 0 : case GCM_PROPERTY_ID_POS_Y: aDefault <<= (sal_Int32) 0; break;
193 0 : case GCM_PROPERTY_ID_WIDTH: aDefault <<= (sal_Int32) 0; break;
194 0 : case GCM_PROPERTY_ID_HEIGHT: aDefault <<= (sal_Int32) 0; break;
195 0 : case GCM_PROPERTY_ID_NAME: aDefault <<= OUString(); break;
196 28 : case GCM_PROPERTY_ID_TABINDEX: aDefault <<= (sal_Int16) -1; break;
197 28 : case GCM_PROPERTY_ID_STEP: aDefault <<= (sal_Int32) 0; break;
198 28 : case GCM_PROPERTY_ID_TAG: aDefault <<= OUString(); break;
199 0 : case GCM_PROPERTY_ID_RESOURCERESOLVER: aDefault <<= Reference< resource::XStringResourceResolver >(); break;
200 : default: OSL_FAIL( "ImplGetDefaultValueByHandle - unknown Property" );
201 : }
202 :
203 84 : return aDefault;
204 : }
205 :
206 :
207 84 : ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetPropertyValueByHandle(sal_Int32 nHandle) const
208 : {
209 84 : ::com::sun::star::uno::Any aValue;
210 :
211 84 : switch ( nHandle )
212 : {
213 0 : case GCM_PROPERTY_ID_POS_X: aValue <<= m_nPosX; break;
214 0 : case GCM_PROPERTY_ID_POS_Y: aValue <<= m_nPosY; break;
215 0 : case GCM_PROPERTY_ID_WIDTH: aValue <<= m_nWidth; break;
216 0 : case GCM_PROPERTY_ID_HEIGHT: aValue <<= m_nHeight; break;
217 0 : case GCM_PROPERTY_ID_NAME: aValue <<= m_aName; break;
218 28 : case GCM_PROPERTY_ID_TABINDEX: aValue <<= m_nTabIndex; break;
219 28 : case GCM_PROPERTY_ID_STEP: aValue <<= m_nStep; break;
220 28 : case GCM_PROPERTY_ID_TAG: aValue <<= m_aTag; break;
221 0 : case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue <<= m_xStrResolver; break;
222 : default: OSL_FAIL( "ImplGetPropertyValueByHandle - unknown Property" );
223 : }
224 :
225 84 : return aValue;
226 : }
227 :
228 :
229 0 : void OGeometryControlModel_Base::ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue)
230 : {
231 0 : switch ( nHandle )
232 : {
233 0 : case GCM_PROPERTY_ID_POS_X: aValue >>= m_nPosX; break;
234 0 : case GCM_PROPERTY_ID_POS_Y: aValue >>= m_nPosY; break;
235 0 : case GCM_PROPERTY_ID_WIDTH: aValue >>= m_nWidth; break;
236 0 : case GCM_PROPERTY_ID_HEIGHT: aValue >>= m_nHeight; break;
237 0 : case GCM_PROPERTY_ID_NAME: aValue >>= m_aName; break;
238 0 : case GCM_PROPERTY_ID_TABINDEX: aValue >>= m_nTabIndex; break;
239 0 : case GCM_PROPERTY_ID_STEP: aValue >>= m_nStep; break;
240 0 : case GCM_PROPERTY_ID_TAG: aValue >>= m_aTag; break;
241 0 : case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue >>= m_xStrResolver; break;
242 : default: OSL_FAIL( "ImplSetPropertyValueByHandle - unknown Property" );
243 : }
244 0 : }
245 :
246 :
247 8106 : Any SAL_CALL OGeometryControlModel_Base::queryAggregation( const Type& _rType ) throw(RuntimeException, std::exception)
248 : {
249 8106 : Any aReturn;
250 8106 : if (_rType.equals(cppu::UnoType<XCloneable>::get()) && !m_bCloneable)
251 : // somebody is asking for the XCloneable interface, but our aggregate does not support it
252 : // -> outta here
253 : // (need this extra check, cause OGCM_Base::queryAggregation would return this interface
254 : // in every case)
255 0 : return aReturn;
256 :
257 8106 : aReturn = OGCM_Base::queryAggregation(_rType);
258 : // the basic interfaces (XInterface, XAggregation etc)
259 :
260 8106 : if (!aReturn.hasValue())
261 5516 : aReturn = OPropertySetAggregationHelper::queryInterface(_rType);
262 : // the property set related interfaces
263 :
264 8106 : if (!aReturn.hasValue() && m_xAggregate.is())
265 3716 : aReturn = m_xAggregate->queryAggregation(_rType);
266 : // the interfaces our aggregate can provide
267 :
268 8106 : return aReturn;
269 : }
270 :
271 :
272 8106 : Any SAL_CALL OGeometryControlModel_Base::queryInterface( const Type& _rType ) throw(RuntimeException, std::exception)
273 : {
274 8106 : return OGCM_Base::queryInterface(_rType);
275 : }
276 :
277 :
278 206536 : void SAL_CALL OGeometryControlModel_Base::acquire( ) throw()
279 : {
280 206536 : OGCM_Base::acquire();
281 206536 : }
282 :
283 :
284 206218 : void SAL_CALL OGeometryControlModel_Base::release( ) throw()
285 : {
286 206218 : OGCM_Base::release();
287 206218 : }
288 :
289 :
290 68 : void OGeometryControlModel_Base::releaseAggregation()
291 : {
292 : // release the aggregate (_before_ clearing m_xAggregate)
293 68 : if (m_xAggregate.is())
294 68 : m_xAggregate->setDelegator(NULL);
295 68 : setAggregation(NULL);
296 68 : }
297 :
298 :
299 136 : OGeometryControlModel_Base::~OGeometryControlModel_Base()
300 : {
301 68 : releaseAggregation();
302 68 : }
303 :
304 :
305 1388 : sal_Bool SAL_CALL OGeometryControlModel_Base::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
306 : sal_Int32 _nHandle, const Any& _rValue) throw (IllegalArgumentException)
307 : {
308 1388 : return OPropertyContainer::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
309 : }
310 :
311 :
312 476 : void SAL_CALL OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception, std::exception)
313 : {
314 476 : OPropertyContainer::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
315 476 : }
316 :
317 :
318 7156 : void SAL_CALL OGeometryControlModel_Base::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
319 : {
320 7156 : OPropertyArrayAggregationHelper& rPH = static_cast<OPropertyArrayAggregationHelper&>(const_cast<OGeometryControlModel_Base*>(this)->getInfoHelper());
321 7156 : OUString sPropName;
322 7156 : sal_Int32 nOriginalHandle = -1;
323 :
324 7156 : if (rPH.fillAggregatePropertyInfoByHandle(&sPropName, &nOriginalHandle, _nHandle))
325 5030 : OPropertySetAggregationHelper::getFastPropertyValue(_rValue, _nHandle);
326 : else
327 2126 : OPropertyContainer::getFastPropertyValue(_rValue, _nHandle);
328 7156 : }
329 :
330 :
331 84 : ::com::sun::star::beans::PropertyState OGeometryControlModel_Base::getPropertyStateByHandle(sal_Int32 nHandle)
332 : {
333 84 : ::com::sun::star::uno::Any aValue = ImplGetPropertyValueByHandle( nHandle );
334 168 : ::com::sun::star::uno::Any aDefault = ImplGetDefaultValueByHandle( nHandle );
335 :
336 168 : return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
337 : }
338 :
339 :
340 0 : void OGeometryControlModel_Base::setPropertyToDefaultByHandle(sal_Int32 nHandle)
341 : {
342 0 : ImplSetPropertyValueByHandle( nHandle , ImplGetDefaultValueByHandle( nHandle ) );
343 0 : }
344 :
345 :
346 0 : ::com::sun::star::uno::Any OGeometryControlModel_Base::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
347 : {
348 0 : return ImplGetDefaultValueByHandle( nHandle );
349 : }
350 :
351 :
352 758 : Reference< XPropertySetInfo> SAL_CALL OGeometryControlModel_Base::getPropertySetInfo() throw(RuntimeException, std::exception)
353 : {
354 758 : return OPropertySetAggregationHelper::createPropertySetInfo(getInfoHelper());
355 : }
356 :
357 :
358 6 : Reference< XCloneable > SAL_CALL OGeometryControlModel_Base::createClone( ) throw(RuntimeException, std::exception)
359 : {
360 : OSL_ENSURE(m_bCloneable, "OGeometryControlModel_Base::createClone: invalid call!");
361 6 : if (!m_bCloneable)
362 0 : return Reference< XCloneable >();
363 :
364 : // let the aggregate create it's own clone
365 : // the interface
366 6 : Reference< XCloneable > xCloneAccess;
367 6 : m_xAggregate->queryAggregation(::getCppuType(&xCloneAccess)) >>= xCloneAccess;
368 : OSL_ENSURE(xCloneAccess.is(), "OGeometryControlModel_Base::createClone: suspicious aggregate!");
369 6 : if (!xCloneAccess.is())
370 0 : return Reference< XCloneable >();
371 : // the aggregate's clone
372 12 : Reference< XCloneable > xAggregateClone = xCloneAccess->createClone();
373 : OSL_ENSURE(xAggregateClone.is(), "OGeometryControlModel_Base::createClone: suspicious return of the aggregate!");
374 :
375 : // create a new wrapper aggregating this return value
376 6 : OGeometryControlModel_Base* pOwnClone = createClone_Impl(xAggregateClone);
377 : OSL_ENSURE(pOwnClone, "OGeometryControlModel_Base::createClone: invalid derivee behaviour!");
378 : OSL_ENSURE(!xAggregateClone.is(), "OGeometryControlModel_Base::createClone: invalid ctor behaviour!");
379 : // should have been reset
380 :
381 : // set properties
382 6 : pOwnClone->m_nPosX = m_nPosX;
383 6 : pOwnClone->m_nPosY = m_nPosY;
384 6 : pOwnClone->m_nWidth = m_nWidth;
385 6 : pOwnClone->m_nHeight = m_nHeight;
386 6 : pOwnClone->m_aName = m_aName;
387 6 : pOwnClone->m_nTabIndex = m_nTabIndex;
388 6 : pOwnClone->m_nStep = m_nStep;
389 6 : pOwnClone->m_aTag = m_aTag;
390 :
391 :
392 : // Clone event container
393 : Reference< ::com::sun::star::script::XScriptEventsSupplier > xEventsSupplier =
394 12 : static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( this );
395 : Reference< ::com::sun::star::script::XScriptEventsSupplier > xCloneEventsSupplier =
396 12 : static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( pOwnClone );
397 :
398 6 : if( xEventsSupplier.is() && xCloneEventsSupplier.is() )
399 : {
400 6 : Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
401 12 : Reference< XNameContainer > xCloneEventCont = xCloneEventsSupplier->getEvents();
402 :
403 : ::com::sun::star::uno::Sequence< OUString > aNames =
404 12 : xEventCont->getElementNames();
405 6 : const OUString* pNames = aNames.getConstArray();
406 6 : sal_Int32 i, nNameCount = aNames.getLength();
407 :
408 6 : for( i = 0 ; i < nNameCount ; i++ )
409 : {
410 0 : OUString aName = pNames[ i ];
411 0 : ::com::sun::star::uno::Any aElement = xEventCont->getByName( aName );
412 0 : xCloneEventCont->insertByName( aName, aElement );
413 6 : }
414 : }
415 :
416 12 : return pOwnClone;
417 : }
418 :
419 :
420 88 : Reference< XNameContainer > SAL_CALL OGeometryControlModel_Base::getEvents() throw(RuntimeException, std::exception)
421 : {
422 88 : if( !mxEventContainer.is() )
423 60 : mxEventContainer = (XNameContainer*)new toolkit::ScriptEventContainer();
424 88 : return mxEventContainer;
425 : }
426 :
427 :
428 68 : void SAL_CALL OGeometryControlModel_Base::disposing()
429 : {
430 68 : OGCM_Base::disposing();
431 68 : OPropertySetAggregationHelper::disposing();
432 :
433 68 : Reference<XComponent> xComp;
434 68 : if ( query_aggregation( m_xAggregate, xComp ) )
435 68 : xComp->dispose();
436 68 : }
437 :
438 :
439 : //= OCommonGeometryControlModel
440 :
441 :
442 :
443 : typedef ::boost::unordered_map< OUString, sal_Int32, OUStringHash > HashMapString2Int;
444 : typedef ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > > PropSeqArray;
445 : typedef ::std::vector< ::std::vector< sal_Int32 > > IntArrayArray;
446 :
447 : // for creating class-unique PropertySetInfo's, we need some info:
448 : namespace { struct ServiceSpecifierMap : public rtl::Static< HashMapString2Int, ServiceSpecifierMap > {}; }
449 : // this one maps from a String, which is the service specifier for our
450 : // aggregate, to a unique id
451 :
452 : namespace { struct AggregateProperties : public rtl::Static< PropSeqArray, AggregateProperties > {}; }
453 : // this one contains the properties which belong to all the unique ids
454 : // in ServiceSpecifierMap
455 :
456 : namespace { struct AmbiguousPropertyIds : public rtl::Static< IntArrayArray, AmbiguousPropertyIds > {}; }
457 : // the ids of the properties which we as well as our aggregate supply
458 : // For such props, we let our base class handle them, and whenever such
459 : // a prop is set, we forward this to our aggregate.
460 :
461 : // With this, we can ensure that two instances of this class share the
462 : // same PropertySetInfo if and only if both aggregates have the same
463 : // service specifier.
464 :
465 :
466 :
467 34 : OCommonGeometryControlModel::OCommonGeometryControlModel( Reference< XCloneable >& _rxAgg, const OUString& _rServiceSpecifier )
468 : :OGeometryControlModel_Base( _rxAgg )
469 : ,m_sServiceSpecifier( _rServiceSpecifier )
470 34 : ,m_nPropertyMapId( 0 )
471 : {
472 34 : Reference< XPropertySetInfo > xPI;
473 34 : if ( m_xAggregateSet.is() )
474 34 : xPI = m_xAggregateSet->getPropertySetInfo();
475 34 : if ( !xPI.is() )
476 : {
477 0 : releaseAggregation();
478 0 : throw IllegalArgumentException();
479 : }
480 :
481 34 : HashMapString2Int &rMap = ServiceSpecifierMap::get();
482 34 : HashMapString2Int::iterator aPropMapIdPos = rMap.find( m_sServiceSpecifier );
483 34 : if ( rMap.end() == aPropMapIdPos )
484 : {
485 14 : PropSeqArray &rAggProperties = AggregateProperties::get();
486 14 : m_nPropertyMapId = rAggProperties.size();
487 14 : rAggProperties.push_back( xPI->getProperties() );
488 14 : AmbiguousPropertyIds::get().push_back( IntArrayArray::value_type() );
489 :
490 14 : rMap[ m_sServiceSpecifier ] = m_nPropertyMapId;
491 : }
492 : else
493 20 : m_nPropertyMapId = aPropMapIdPos->second;
494 34 : }
495 :
496 :
497 : struct PropertyNameLess : public ::std::binary_function< Property, Property, bool >
498 : {
499 3922 : bool operator()( const Property& _rLHS, const Property& _rRHS )
500 : {
501 3922 : return _rLHS.Name < _rRHS.Name;
502 : }
503 : };
504 :
505 :
506 : struct PropertyNameEqual : public ::std::unary_function< Property, bool >
507 : {
508 : const OUString& m_rCompare;
509 126 : PropertyNameEqual( const OUString& _rCompare ) : m_rCompare( _rCompare ) { }
510 :
511 6866 : bool operator()( const Property& _rLHS )
512 : {
513 6866 : return _rLHS.Name == m_rCompare;
514 : }
515 : };
516 :
517 :
518 14 : ::cppu::IPropertyArrayHelper* OCommonGeometryControlModel::createArrayHelper( sal_Int32 _nId ) const
519 : {
520 : OSL_ENSURE( _nId == m_nPropertyMapId, "OCommonGeometryControlModel::createArrayHelper: invalid argument!" );
521 : OSL_ENSURE( _nId < (sal_Int32)AggregateProperties::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (1)!" );
522 : OSL_ENSURE( _nId < (sal_Int32)AmbiguousPropertyIds::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (2)!" );
523 :
524 : // our own properties
525 14 : Sequence< Property > aProps;
526 14 : OPropertyContainer::describeProperties( aProps );
527 :
528 : // the aggregate properties
529 28 : Sequence< Property > aAggregateProps;
530 14 : aAggregateProps = AggregateProperties::get()[ _nId ];
531 :
532 : // look for duplicates, and remember them
533 14 : IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ _nId ];
534 : // for this, sort the aggregate properties
535 : ::std::sort(
536 : aAggregateProps.getArray(),
537 14 : aAggregateProps.getArray() + aAggregateProps.getLength(),
538 : PropertyNameLess()
539 14 : );
540 14 : const Property* pAggProps = aAggregateProps.getConstArray();
541 14 : const Property* pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength();
542 :
543 : // now loop through our own props
544 14 : const Property* pProp = aProps.getConstArray();
545 14 : const Property* pPropEnd = aProps.getConstArray() + aProps.getLength();
546 154 : while ( pProp < pPropEnd )
547 : {
548 : // look for the current property in the properties of our aggregate
549 126 : const Property* pAggPropPos = ::std::find_if( pAggProps, pAggPropsEnd, PropertyNameEqual( pProp->Name ) );
550 126 : if ( pAggPropPos != pAggPropsEnd )
551 : { // found a duplicate
552 : // -> remove from the aggregate property sequence
553 36 : ::comphelper::removeElementAt( aAggregateProps, pAggPropPos - pAggProps );
554 : // which means we have to adjust the pointers
555 : pAggProps = aAggregateProps.getConstArray(),
556 36 : pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength(),
557 :
558 : // and additionally, remember the id of this property
559 72 : rDuplicateIds.push_back( pProp->Handle );
560 : }
561 :
562 126 : ++pProp;
563 : }
564 :
565 : // now, finally, sort the duplicates
566 14 : ::std::sort( rDuplicateIds.begin(), rDuplicateIds.end(), ::std::less< sal_Int32 >() );
567 :
568 28 : return new OPropertyArrayAggregationHelper(aProps, aAggregateProps);
569 : }
570 :
571 :
572 2924 : ::cppu::IPropertyArrayHelper& SAL_CALL OCommonGeometryControlModel::getInfoHelper()
573 : {
574 2924 : return *getArrayHelper( m_nPropertyMapId );
575 : }
576 :
577 :
578 2 : OGeometryControlModel_Base* OCommonGeometryControlModel::createClone_Impl( Reference< XCloneable >& _rxAggregateInstance )
579 : {
580 2 : return new OCommonGeometryControlModel( _rxAggregateInstance, m_sServiceSpecifier );
581 : }
582 :
583 0 : Sequence< sal_Int8 > SAL_CALL OCommonGeometryControlModel::getImplementationId( ) throw (RuntimeException, std::exception)
584 : {
585 0 : return css::uno::Sequence<sal_Int8>();
586 : }
587 :
588 :
589 : struct Int32Equal : public ::std::unary_function< sal_Int32, bool >
590 : {
591 : sal_Int32 m_nCompare;
592 108 : Int32Equal( sal_Int32 _nCompare ) : m_nCompare( _nCompare ) { }
593 :
594 180 : bool operator()( sal_Int32 _nLHS )
595 : {
596 180 : return _nLHS == m_nCompare;
597 : }
598 : };
599 :
600 :
601 108 : void SAL_CALL OCommonGeometryControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
602 : {
603 108 : OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
604 :
605 : // look if this id is one we recognized as duplicate
606 108 : IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ m_nPropertyMapId ];
607 :
608 : IntArrayArray::value_type::const_iterator aPos = ::std::find_if(
609 : rDuplicateIds.begin(),
610 : rDuplicateIds.end(),
611 : Int32Equal( _nHandle )
612 108 : );
613 :
614 108 : if ( rDuplicateIds.end() != aPos )
615 : {
616 : // yes, it is such a property
617 24 : OUString sPropName;
618 24 : sal_Int16 nAttributes(0);
619 24 : static_cast< OPropertyArrayAggregationHelper* >( getArrayHelper( m_nPropertyMapId ) )->fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );
620 :
621 24 : if ( m_xAggregateSet.is() && !sPropName.isEmpty() )
622 24 : m_xAggregateSet->setPropertyValue( sPropName, _rValue );
623 : }
624 108 : }
625 :
626 :
627 : // } // namespace toolkit
628 :
629 :
630 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|