1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
31 #include <comphelper/sequence.hxx>
34 #define GCM_PROPERTY_ID_POS_X 1
35 #define GCM_PROPERTY_ID_POS_Y 2
36 #define GCM_PROPERTY_ID_WIDTH 3
37 #define GCM_PROPERTY_ID_HEIGHT 4
38 #define GCM_PROPERTY_ID_NAME 5
39 #define GCM_PROPERTY_ID_TABINDEX 6
40 #define GCM_PROPERTY_ID_STEP 7
41 #define GCM_PROPERTY_ID_TAG 8
42 #define GCM_PROPERTY_ID_RESOURCERESOLVER 9
44 #define GCM_PROPERTY_POS_X ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionX"))
45 #define GCM_PROPERTY_POS_Y ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionY"))
46 #define GCM_PROPERTY_WIDTH ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Width"))
47 #define GCM_PROPERTY_HEIGHT ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Height"))
48 #define GCM_PROPERTY_NAME ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"))
49 #define GCM_PROPERTY_TABINDEX ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex"))
50 #define GCM_PROPERTY_STEP ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Step"))
51 #define GCM_PROPERTY_TAG ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag"))
52 #define GCM_PROPERTY_RESOURCERESOLVER ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver"))
54 #define DEFAULT_ATTRIBS() PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT
56 //........................................................................
59 //........................................................................
61 using namespace ::com::sun::star
;
62 using namespace ::com::sun::star::uno
;
63 using namespace ::com::sun::star::lang
;
64 using namespace ::com::sun::star::beans
;
65 using namespace ::com::sun::star::util
;
66 using namespace ::com::sun::star::container
;
67 using namespace ::comphelper
;
69 //====================================================================
70 //= OGeometryControlModel_Base
71 //====================================================================
72 //--------------------------------------------------------------------
73 OGeometryControlModel_Base::OGeometryControlModel_Base(::com::sun::star::uno::XAggregation
* _pAggregateInstance
)
74 :OPropertySetAggregationHelper( m_aBHelper
)
75 ,OPropertyContainer( m_aBHelper
)
76 ,OGCM_Base( m_aMutex
)
83 ,m_bCloneable(sal_False
)
85 OSL_ENSURE(NULL
!= _pAggregateInstance
, "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid aggregate!");
87 increment(m_refCount
);
89 m_xAggregate
= _pAggregateInstance
;
91 { // check if the aggregat is cloneable
92 Reference
< XCloneable
> xCloneAccess(m_xAggregate
, UNO_QUERY
);
93 m_bCloneable
= xCloneAccess
.is();
96 setAggregation(m_xAggregate
);
97 m_xAggregate
->setDelegator(static_cast< XWeak
* >(this));
99 decrement(m_refCount
);
101 registerProperties();
104 //--------------------------------------------------------------------
105 OGeometryControlModel_Base::OGeometryControlModel_Base(Reference
< XCloneable
>& _rxAggregateInstance
)
106 :OPropertySetAggregationHelper( m_aBHelper
)
107 ,OPropertyContainer( m_aBHelper
)
108 ,OGCM_Base( m_aMutex
)
115 ,m_bCloneable(_rxAggregateInstance
.is())
117 increment(m_refCount
);
120 // ensure that the temporary gets destructed NOW
121 m_xAggregate
= Reference
< XAggregation
>(_rxAggregateInstance
, UNO_QUERY
);
123 OSL_ENSURE(m_xAggregate
.is(), "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid object given!");
125 // now the aggregate has a ref count of 2, but before setting the delegator it must be 1
126 _rxAggregateInstance
.clear();
127 // now it should be the 1 we need here ...
129 setAggregation(m_xAggregate
);
130 m_xAggregate
->setDelegator(static_cast< XWeak
* >(this));
132 decrement(m_refCount
);
134 registerProperties();
137 //--------------------------------------------------------------------
138 Sequence
< Type
> SAL_CALL
OGeometryControlModel_Base::getTypes( ) throw (RuntimeException
)
141 Sequence
< Type
> aTypes
= ::comphelper::concatSequences(
142 OPropertySetAggregationHelper::getTypes(),
143 OPropertyContainer::getTypes(),
144 OGCM_Base::getTypes()
147 if ( m_xAggregate
.is() )
149 // retrieve the types of the aggregate
150 Reference
< XTypeProvider
> xAggregateTypeProv
;
151 m_xAggregate
->queryAggregation( ::getCppuType( &xAggregateTypeProv
) ) >>= xAggregateTypeProv
;
152 OSL_ENSURE( xAggregateTypeProv
.is(), "OGeometryControlModel_Base::getTypes: aggregate should be a type provider!" );
153 Sequence
< Type
> aAggTypes
;
154 if ( xAggregateTypeProv
.is() )
155 aAggTypes
= xAggregateTypeProv
->getTypes();
157 // concat the sequences
158 sal_Int32 nOldSize
= aTypes
.getLength();
159 aTypes
.realloc( nOldSize
+ aAggTypes
.getLength() );
161 aAggTypes
.getConstArray(),
162 aAggTypes
.getConstArray() + aAggTypes
.getLength(),
163 aTypes
.getArray() + nOldSize
170 //--------------------------------------------------------------------
171 void OGeometryControlModel_Base::registerProperties()
173 // register our members for the property handling of the OPropertyContainer
174 registerProperty(GCM_PROPERTY_POS_X
, GCM_PROPERTY_ID_POS_X
, DEFAULT_ATTRIBS(), &m_nPosX
, ::getCppuType(&m_nPosX
));
175 registerProperty(GCM_PROPERTY_POS_Y
, GCM_PROPERTY_ID_POS_Y
, DEFAULT_ATTRIBS(), &m_nPosY
, ::getCppuType(&m_nPosY
));
176 registerProperty(GCM_PROPERTY_WIDTH
, GCM_PROPERTY_ID_WIDTH
, DEFAULT_ATTRIBS(), &m_nWidth
, ::getCppuType(&m_nWidth
));
177 registerProperty(GCM_PROPERTY_HEIGHT
, GCM_PROPERTY_ID_HEIGHT
, DEFAULT_ATTRIBS(), &m_nHeight
, ::getCppuType(&m_nHeight
));
178 registerProperty(GCM_PROPERTY_NAME
, GCM_PROPERTY_ID_NAME
, DEFAULT_ATTRIBS(), &m_aName
, ::getCppuType(&m_aName
));
179 registerProperty(GCM_PROPERTY_TABINDEX
, GCM_PROPERTY_ID_TABINDEX
, DEFAULT_ATTRIBS(), &m_nTabIndex
, ::getCppuType(&m_nTabIndex
));
180 registerProperty(GCM_PROPERTY_STEP
, GCM_PROPERTY_ID_STEP
, DEFAULT_ATTRIBS(), &m_nStep
, ::getCppuType(&m_nStep
));
181 registerProperty(GCM_PROPERTY_TAG
, GCM_PROPERTY_ID_TAG
, DEFAULT_ATTRIBS(), &m_aTag
, ::getCppuType(&m_aTag
));
182 registerProperty(GCM_PROPERTY_RESOURCERESOLVER
, GCM_PROPERTY_ID_RESOURCERESOLVER
, DEFAULT_ATTRIBS(), &m_xStrResolver
, ::getCppuType(&m_xStrResolver
));
185 //--------------------------------------------------------------------
186 ::com::sun::star::uno::Any
OGeometryControlModel_Base::ImplGetDefaultValueByHandle(sal_Int32 nHandle
) const
188 ::com::sun::star::uno::Any aDefault
;
192 case GCM_PROPERTY_ID_POS_X
: aDefault
<<= (sal_Int32
) 0; break;
193 case GCM_PROPERTY_ID_POS_Y
: aDefault
<<= (sal_Int32
) 0; break;
194 case GCM_PROPERTY_ID_WIDTH
: aDefault
<<= (sal_Int32
) 0; break;
195 case GCM_PROPERTY_ID_HEIGHT
: aDefault
<<= (sal_Int32
) 0; break;
196 case GCM_PROPERTY_ID_NAME
: aDefault
<<= ::rtl::OUString(); break;
197 case GCM_PROPERTY_ID_TABINDEX
: aDefault
<<= (sal_Int16
) -1; break;
198 case GCM_PROPERTY_ID_STEP
: aDefault
<<= (sal_Int32
) 0; break;
199 case GCM_PROPERTY_ID_TAG
: aDefault
<<= ::rtl::OUString(); break;
200 case GCM_PROPERTY_ID_RESOURCERESOLVER
: aDefault
<<= Reference
< resource::XStringResourceResolver
>(); break;
201 default: OSL_FAIL( "ImplGetDefaultValueByHandle - unknown Property" );
207 //--------------------------------------------------------------------
208 ::com::sun::star::uno::Any
OGeometryControlModel_Base::ImplGetPropertyValueByHandle(sal_Int32 nHandle
) const
210 ::com::sun::star::uno::Any aValue
;
214 case GCM_PROPERTY_ID_POS_X
: aValue
<<= m_nPosX
; break;
215 case GCM_PROPERTY_ID_POS_Y
: aValue
<<= m_nPosY
; break;
216 case GCM_PROPERTY_ID_WIDTH
: aValue
<<= m_nWidth
; break;
217 case GCM_PROPERTY_ID_HEIGHT
: aValue
<<= m_nHeight
; break;
218 case GCM_PROPERTY_ID_NAME
: aValue
<<= m_aName
; break;
219 case GCM_PROPERTY_ID_TABINDEX
: aValue
<<= m_nTabIndex
; break;
220 case GCM_PROPERTY_ID_STEP
: aValue
<<= m_nStep
; break;
221 case GCM_PROPERTY_ID_TAG
: aValue
<<= m_aTag
; break;
222 case GCM_PROPERTY_ID_RESOURCERESOLVER
: aValue
<<= m_xStrResolver
; break;
223 default: OSL_FAIL( "ImplGetPropertyValueByHandle - unknown Property" );
229 //--------------------------------------------------------------------
230 void OGeometryControlModel_Base::ImplSetPropertyValueByHandle(sal_Int32 nHandle
, const :: com::sun::star::uno::Any
& aValue
)
234 case GCM_PROPERTY_ID_POS_X
: aValue
>>= m_nPosX
; break;
235 case GCM_PROPERTY_ID_POS_Y
: aValue
>>= m_nPosY
; break;
236 case GCM_PROPERTY_ID_WIDTH
: aValue
>>= m_nWidth
; break;
237 case GCM_PROPERTY_ID_HEIGHT
: aValue
>>= m_nHeight
; break;
238 case GCM_PROPERTY_ID_NAME
: aValue
>>= m_aName
; break;
239 case GCM_PROPERTY_ID_TABINDEX
: aValue
>>= m_nTabIndex
; break;
240 case GCM_PROPERTY_ID_STEP
: aValue
>>= m_nStep
; break;
241 case GCM_PROPERTY_ID_TAG
: aValue
>>= m_aTag
; break;
242 case GCM_PROPERTY_ID_RESOURCERESOLVER
: aValue
>>= m_xStrResolver
; break;
243 default: OSL_FAIL( "ImplSetPropertyValueByHandle - unknown Property" );
247 //--------------------------------------------------------------------
248 Any SAL_CALL
OGeometryControlModel_Base::queryAggregation( const Type
& _rType
) throw(RuntimeException
)
251 if (_rType
.equals(::getCppuType(static_cast< Reference
< XCloneable
>* >(NULL
))) && !m_bCloneable
)
252 // somebody is asking for the XCloneable interface, but our aggregate does not support it
254 // (need this extra check, cause OGCM_Base::queryAggregation would return this interface
258 aReturn
= OGCM_Base::queryAggregation(_rType
);
259 // the basic interfaces (XInterface, XAggregation etc)
261 if (!aReturn
.hasValue())
262 aReturn
= OPropertySetAggregationHelper::queryInterface(_rType
);
263 // the property set related interfaces
265 if (!aReturn
.hasValue() && m_xAggregate
.is())
266 aReturn
= m_xAggregate
->queryAggregation(_rType
);
267 // the interfaces our aggregate can provide
272 //--------------------------------------------------------------------
273 Any SAL_CALL
OGeometryControlModel_Base::queryInterface( const Type
& _rType
) throw(RuntimeException
)
275 return OGCM_Base::queryInterface(_rType
);
278 //--------------------------------------------------------------------
279 void SAL_CALL
OGeometryControlModel_Base::acquire( ) throw()
281 OGCM_Base::acquire();
284 //--------------------------------------------------------------------
285 void SAL_CALL
OGeometryControlModel_Base::release( ) throw()
287 OGCM_Base::release();
290 //--------------------------------------------------------------------
291 void OGeometryControlModel_Base::releaseAggregation()
293 // release the aggregate (_before_ clearing m_xAggregate)
294 if (m_xAggregate
.is())
295 m_xAggregate
->setDelegator(NULL
);
296 setAggregation(NULL
);
299 //--------------------------------------------------------------------
300 OGeometryControlModel_Base::~OGeometryControlModel_Base()
302 releaseAggregation();
305 //--------------------------------------------------------------------
306 sal_Bool SAL_CALL
OGeometryControlModel_Base::convertFastPropertyValue(Any
& _rConvertedValue
, Any
& _rOldValue
,
307 sal_Int32 _nHandle
, const Any
& _rValue
) throw (IllegalArgumentException
)
309 return OPropertyContainer::convertFastPropertyValue(_rConvertedValue
, _rOldValue
, _nHandle
, _rValue
);
312 //--------------------------------------------------------------------
313 void SAL_CALL
OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle
, const Any
& _rValue
) throw (Exception
)
315 OPropertyContainer::setFastPropertyValue_NoBroadcast(_nHandle
, _rValue
);
318 //--------------------------------------------------------------------
319 void SAL_CALL
OGeometryControlModel_Base::getFastPropertyValue(Any
& _rValue
, sal_Int32 _nHandle
) const
321 OPropertyArrayAggregationHelper
& rPH
= static_cast<OPropertyArrayAggregationHelper
&>(const_cast<OGeometryControlModel_Base
*>(this)->getInfoHelper());
322 ::rtl::OUString sPropName
;
323 sal_Int32 nOriginalHandle
= -1;
325 if (rPH
.fillAggregatePropertyInfoByHandle(&sPropName
, &nOriginalHandle
, _nHandle
))
326 OPropertySetAggregationHelper::getFastPropertyValue(_rValue
, _nHandle
);
328 OPropertyContainer::getFastPropertyValue(_rValue
, _nHandle
);
331 //--------------------------------------------------------------------
332 ::com::sun::star::beans::PropertyState
OGeometryControlModel_Base::getPropertyStateByHandle(sal_Int32 nHandle
)
334 ::com::sun::star::uno::Any aValue
= ImplGetPropertyValueByHandle( nHandle
);
335 ::com::sun::star::uno::Any aDefault
= ImplGetDefaultValueByHandle( nHandle
);
337 return CompareProperties( aValue
, aDefault
) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE
: ::com::sun::star::beans::PropertyState_DIRECT_VALUE
;
340 //--------------------------------------------------------------------
341 void OGeometryControlModel_Base::setPropertyToDefaultByHandle(sal_Int32 nHandle
)
343 ImplSetPropertyValueByHandle( nHandle
, ImplGetDefaultValueByHandle( nHandle
) );
346 //--------------------------------------------------------------------
347 ::com::sun::star::uno::Any
OGeometryControlModel_Base::getPropertyDefaultByHandle( sal_Int32 nHandle
) const
349 return ImplGetDefaultValueByHandle( nHandle
);
352 //--------------------------------------------------------------------
353 Reference
< XPropertySetInfo
> SAL_CALL
OGeometryControlModel_Base::getPropertySetInfo() throw(RuntimeException
)
355 return OPropertySetAggregationHelper::createPropertySetInfo(getInfoHelper());
358 //--------------------------------------------------------------------
359 Reference
< XCloneable
> SAL_CALL
OGeometryControlModel_Base::createClone( ) throw(RuntimeException
)
361 OSL_ENSURE(m_bCloneable
, "OGeometryControlModel_Base::createClone: invalid call!");
363 return Reference
< XCloneable
>();
365 // let the aggregate create it's own clone
367 Reference
< XCloneable
> xCloneAccess
;
368 m_xAggregate
->queryAggregation(::getCppuType(&xCloneAccess
)) >>= xCloneAccess
;
369 OSL_ENSURE(xCloneAccess
.is(), "OGeometryControlModel_Base::createClone: suspicious aggregate!");
370 if (!xCloneAccess
.is())
371 return Reference
< XCloneable
>();
372 // the aggregate's clone
373 Reference
< XCloneable
> xAggregateClone
= xCloneAccess
->createClone();
374 OSL_ENSURE(xAggregateClone
.is(), "OGeometryControlModel_Base::createClone: suspicious return of the aggregate!");
376 // create a new wrapper aggregating this return value
377 OGeometryControlModel_Base
* pOwnClone
= createClone_Impl(xAggregateClone
);
378 OSL_ENSURE(pOwnClone
, "OGeometryControlModel_Base::createClone: invalid derivee behaviour!");
379 OSL_ENSURE(!xAggregateClone
.is(), "OGeometryControlModel_Base::createClone: invalid ctor behaviour!");
380 // should have been reset
383 pOwnClone
->m_nPosX
= m_nPosX
;
384 pOwnClone
->m_nPosY
= m_nPosY
;
385 pOwnClone
->m_nWidth
= m_nWidth
;
386 pOwnClone
->m_nHeight
= m_nHeight
;
387 pOwnClone
->m_aName
= m_aName
;
388 pOwnClone
->m_nTabIndex
= m_nTabIndex
;
389 pOwnClone
->m_nStep
= m_nStep
;
390 pOwnClone
->m_aTag
= m_aTag
;
393 // Clone event container
394 Reference
< ::com::sun::star::script::XScriptEventsSupplier
> xEventsSupplier
=
395 static_cast< ::com::sun::star::script::XScriptEventsSupplier
* >( this );
396 Reference
< ::com::sun::star::script::XScriptEventsSupplier
> xCloneEventsSupplier
=
397 static_cast< ::com::sun::star::script::XScriptEventsSupplier
* >( pOwnClone
);
399 if( xEventsSupplier
.is() && xCloneEventsSupplier
.is() )
401 Reference
< XNameContainer
> xEventCont
= xEventsSupplier
->getEvents();
402 Reference
< XNameContainer
> xCloneEventCont
= xCloneEventsSupplier
->getEvents();
404 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> aNames
=
405 xEventCont
->getElementNames();
406 const ::rtl::OUString
* pNames
= aNames
.getConstArray();
407 sal_Int32 i
, nNameCount
= aNames
.getLength();
409 for( i
= 0 ; i
< nNameCount
; i
++ )
411 ::rtl::OUString aName
= pNames
[ i
];
412 ::com::sun::star::uno::Any aElement
= xEventCont
->getByName( aName
);
413 xCloneEventCont
->insertByName( aName
, aElement
);
420 //--------------------------------------------------------------------
421 Reference
< XNameContainer
> SAL_CALL
OGeometryControlModel_Base::getEvents() throw(RuntimeException
)
423 if( !mxEventContainer
.is() )
424 mxEventContainer
= (XNameContainer
*)new toolkit::ScriptEventContainer();
425 return mxEventContainer
;
428 //--------------------------------------------------------------------
429 void SAL_CALL
OGeometryControlModel_Base::disposing()
431 OGCM_Base::disposing();
432 OPropertySetAggregationHelper::disposing();
434 Reference
<XComponent
> xComp
;
435 if ( query_aggregation( m_xAggregate
, xComp
) )
439 //====================================================================
440 //= OCommonGeometryControlModel
441 //====================================================================
442 //--------------------------------------------------------------------
444 typedef ::boost::unordered_map
< ::rtl::OUString
, sal_Int32
, ::rtl::OUStringHash
> HashMapString2Int
;
445 typedef ::std::vector
< ::com::sun::star::uno::Sequence
< ::com::sun::star::beans::Property
> > PropSeqArray
;
446 typedef ::std::vector
< ::std::vector
< sal_Int32
> > IntArrayArray
;
448 // for creating class-unique PropertySetInfo's, we need some info:
449 namespace { struct ServiceSpecifierMap
: public rtl::Static
< HashMapString2Int
, ServiceSpecifierMap
> {}; }
450 // this one maps from a String, which is the service specifier for our
451 // aggregate, to a unique id
453 namespace { struct AggregateProperties
: public rtl::Static
< PropSeqArray
, AggregateProperties
> {}; }
454 // this one contains the properties which belong to all the unique ids
455 // in ServiceSpecifierMap
457 namespace { struct AmbiguousPropertyIds
: public rtl::Static
< IntArrayArray
, AmbiguousPropertyIds
> {}; }
458 // the ids of the properties which we as well as our aggregate supply
459 // For such props, we let our base class handle them, and whenever such
460 // a prop is set, we forward this to our aggregate.
462 // With this, we can ensure that two instances of this class share the
463 // same PropertySetInfo if and only if both aggregates have the same
464 // service specifier.
467 //--------------------------------------------------------------------
468 OCommonGeometryControlModel::OCommonGeometryControlModel( Reference
< XCloneable
>& _rxAgg
, const ::rtl::OUString
& _rServiceSpecifier
)
469 :OGeometryControlModel_Base( _rxAgg
)
470 ,m_sServiceSpecifier( _rServiceSpecifier
)
471 ,m_nPropertyMapId( 0 )
473 Reference
< XPropertySetInfo
> xPI
;
474 if ( m_xAggregateSet
.is() )
475 xPI
= m_xAggregateSet
->getPropertySetInfo();
478 releaseAggregation();
479 throw IllegalArgumentException();
482 HashMapString2Int
&rMap
= ServiceSpecifierMap::get();
483 HashMapString2Int::iterator aPropMapIdPos
= rMap
.find( m_sServiceSpecifier
);
484 if ( rMap
.end() == aPropMapIdPos
)
486 PropSeqArray
&rAggProperties
= AggregateProperties::get();
487 m_nPropertyMapId
= rAggProperties
.size();
488 rAggProperties
.push_back( xPI
->getProperties() );
489 AmbiguousPropertyIds::get().push_back( IntArrayArray::value_type() );
491 rMap
[ m_sServiceSpecifier
] = m_nPropertyMapId
;
494 m_nPropertyMapId
= aPropMapIdPos
->second
;
497 //--------------------------------------------------------------------
498 struct PropertyNameLess
: public ::std::binary_function
< Property
, Property
, bool >
500 bool operator()( const Property
& _rLHS
, const Property
& _rRHS
)
502 return _rLHS
.Name
< _rRHS
.Name
? true : false;
506 //--------------------------------------------------------------------
507 struct PropertyNameEqual
: public ::std::unary_function
< Property
, bool >
509 const ::rtl::OUString
& m_rCompare
;
510 PropertyNameEqual( const ::rtl::OUString
& _rCompare
) : m_rCompare( _rCompare
) { }
512 bool operator()( const Property
& _rLHS
)
514 return _rLHS
.Name
== m_rCompare
? true : false;
518 //--------------------------------------------------------------------
519 ::cppu::IPropertyArrayHelper
* OCommonGeometryControlModel::createArrayHelper( sal_Int32 _nId
) const
521 OSL_ENSURE( _nId
== m_nPropertyMapId
, "OCommonGeometryControlModel::createArrayHelper: invalid argument!" );
522 OSL_ENSURE( _nId
< (sal_Int32
)AggregateProperties::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (1)!" );
523 OSL_ENSURE( _nId
< (sal_Int32
)AmbiguousPropertyIds::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (2)!" );
525 // our own properties
526 Sequence
< Property
> aProps
;
527 OPropertyContainer::describeProperties( aProps
);
529 // the aggregate properties
530 Sequence
< Property
> aAggregateProps
;
531 aAggregateProps
= AggregateProperties::get()[ _nId
];
533 // look for duplicates, and remember them
534 IntArrayArray::value_type
& rDuplicateIds
= AmbiguousPropertyIds::get()[ _nId
];
535 // for this, sort the aggregate properties
537 aAggregateProps
.getArray(),
538 aAggregateProps
.getArray() + aAggregateProps
.getLength(),
541 const Property
* pAggProps
= aAggregateProps
.getConstArray();
542 const Property
* pAggPropsEnd
= aAggregateProps
.getConstArray() + aAggregateProps
.getLength();
544 // now loop through our own props
545 const Property
* pProp
= aProps
.getConstArray();
546 const Property
* pPropEnd
= aProps
.getConstArray() + aProps
.getLength();
547 while ( pProp
< pPropEnd
)
549 // look for the current property in the properties of our aggregate
550 const Property
* pAggPropPos
= ::std::find_if( pAggProps
, pAggPropsEnd
, PropertyNameEqual( pProp
->Name
) );
551 if ( pAggPropPos
!= pAggPropsEnd
)
552 { // found a duplicate
553 // -> remove from the aggregate property sequence
554 ::comphelper::removeElementAt( aAggregateProps
, pAggPropPos
- pAggProps
);
555 // which means we have to adjust the pointers
556 pAggProps
= aAggregateProps
.getConstArray(),
557 pAggPropsEnd
= aAggregateProps
.getConstArray() + aAggregateProps
.getLength(),
559 // and additionally, remember the id of this property
560 rDuplicateIds
.push_back( pProp
->Handle
);
566 // now, finally, sort the duplicates
567 ::std::sort( rDuplicateIds
.begin(), rDuplicateIds
.end(), ::std::less
< sal_Int32
>() );
569 return new OPropertyArrayAggregationHelper(aProps
, aAggregateProps
);
572 //--------------------------------------------------------------------
573 ::cppu::IPropertyArrayHelper
& SAL_CALL
OCommonGeometryControlModel::getInfoHelper()
575 return *getArrayHelper( m_nPropertyMapId
);
578 //--------------------------------------------------------------------
579 OGeometryControlModel_Base
* OCommonGeometryControlModel::createClone_Impl( Reference
< XCloneable
>& _rxAggregateInstance
)
581 return new OCommonGeometryControlModel( _rxAggregateInstance
, m_sServiceSpecifier
);
586 class theOCommonGeometryControlModelImplementationId
:
587 public rtl::Static
< ::cppu::OImplementationId
, theOCommonGeometryControlModelImplementationId
> {};
590 //--------------------------------------------------------------------
591 Sequence
< sal_Int8
> SAL_CALL
OCommonGeometryControlModel::getImplementationId( ) throw (RuntimeException
)
593 return theOCommonGeometryControlModelImplementationId::get().getImplementationId();
596 //--------------------------------------------------------------------
597 struct Int32Equal
: public ::std::unary_function
< sal_Int32
, bool >
599 sal_Int32 m_nCompare
;
600 Int32Equal( sal_Int32 _nCompare
) : m_nCompare( _nCompare
) { }
602 bool operator()( sal_Int32 _nLHS
)
604 return _nLHS
== m_nCompare
? true : false;
608 //--------------------------------------------------------------------
609 void SAL_CALL
OCommonGeometryControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle
, const Any
& _rValue
) throw ( Exception
)
611 OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast( _nHandle
, _rValue
);
613 // look if this id is one we recognized as duplicate
614 IntArrayArray::value_type
& rDuplicateIds
= AmbiguousPropertyIds::get()[ m_nPropertyMapId
];
616 IntArrayArray::value_type::const_iterator aPos
= ::std::find_if(
617 rDuplicateIds
.begin(),
619 Int32Equal( _nHandle
)
622 if ( rDuplicateIds
.end() != aPos
)
624 // yes, it is such a property
625 ::rtl::OUString sPropName
;
626 sal_Int16
nAttributes(0);
627 static_cast< OPropertyArrayAggregationHelper
* >( getArrayHelper( m_nPropertyMapId
) )->fillPropertyMembersByHandle( &sPropName
, &nAttributes
, _nHandle
);
629 if ( m_xAggregateSet
.is() && !sPropName
.isEmpty() )
630 m_xAggregateSet
->setPropertyValue( sPropName
, _rValue
);
634 //........................................................................
635 // } // namespace toolkit
636 //........................................................................
638 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */