summaryrefslogtreecommitdiff
path: root/toolkit/source/controls/geometrycontrolmodel.cxx
blob: fa1c49ffcb91856d2c6d2963bd4434f421f1f898 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2000, 2010 Oracle and/or its affiliates.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_toolkit.hxx"
#include "toolkit/controls/geometrycontrolmodel.hxx"
#include <com/sun/star/lang/XMultiServiceFactory.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <osl/diagnose.h>
#include <rtl/instance.hxx>
#include <comphelper/property.hxx>
#include <comphelper/sequence.hxx>
#include <toolkit/controls/eventcontainer.hxx>
#include <toolkit/helper/property.hxx>
#include <tools/debug.hxx>
#include <algorithm>
#include <functional>
#include <comphelper/sequence.hxx>


#define GCM_PROPERTY_ID_POS_X               1
#define GCM_PROPERTY_ID_POS_Y               2
#define GCM_PROPERTY_ID_WIDTH               3
#define GCM_PROPERTY_ID_HEIGHT              4
#define GCM_PROPERTY_ID_NAME                5
#define GCM_PROPERTY_ID_TABINDEX            6
#define GCM_PROPERTY_ID_STEP                7
#define GCM_PROPERTY_ID_TAG                 8
#define GCM_PROPERTY_ID_RESOURCERESOLVER    9

#define GCM_PROPERTY_POS_X              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionX"))
#define GCM_PROPERTY_POS_Y              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PositionY"))
#define GCM_PROPERTY_WIDTH              ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Width"))
#define GCM_PROPERTY_HEIGHT             ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Height"))
#define GCM_PROPERTY_NAME               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Name"))
#define GCM_PROPERTY_TABINDEX           ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TabIndex"))
#define GCM_PROPERTY_STEP               ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Step"))
#define GCM_PROPERTY_TAG                ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Tag"))
#define GCM_PROPERTY_RESOURCERESOLVER   ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ResourceResolver"))

#define DEFAULT_ATTRIBS()       PropertyAttribute::BOUND | PropertyAttribute::TRANSIENT

//........................................................................
// namespace toolkit
// {
//........................................................................

    using namespace ::com::sun::star;
    using namespace ::com::sun::star::uno;
    using namespace ::com::sun::star::lang;
    using namespace ::com::sun::star::beans;
    using namespace ::com::sun::star::util;
    using namespace ::com::sun::star::container;
    using namespace ::comphelper;

    //====================================================================
    //= OGeometryControlModel_Base
    //====================================================================
    //--------------------------------------------------------------------
    OGeometryControlModel_Base::OGeometryControlModel_Base(::com::sun::star::uno::XAggregation* _pAggregateInstance)
        :OPropertySetAggregationHelper( m_aBHelper )
        ,OPropertyContainer( m_aBHelper )
        ,OGCM_Base( m_aMutex )
        ,m_nPosX(0)
        ,m_nPosY(0)
        ,m_nWidth(0)
        ,m_nHeight(0)
        ,m_nTabIndex(-1)
        ,m_nStep(0)
        ,m_bCloneable(sal_False)
    {
        OSL_ENSURE(NULL != _pAggregateInstance, "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid aggregate!");

        increment(m_refCount);
        {
            m_xAggregate = _pAggregateInstance;

            {   // check if the aggregat is cloneable
                Reference< XCloneable > xCloneAccess(m_xAggregate, UNO_QUERY);
                m_bCloneable = xCloneAccess.is();
            }

            setAggregation(m_xAggregate);
            m_xAggregate->setDelegator(static_cast< XWeak* >(this));
        }
        decrement(m_refCount);

        registerProperties();
    }

    //--------------------------------------------------------------------
    OGeometryControlModel_Base::OGeometryControlModel_Base(Reference< XCloneable >& _rxAggregateInstance)
        :OPropertySetAggregationHelper( m_aBHelper )
        ,OPropertyContainer( m_aBHelper )
        ,OGCM_Base( m_aMutex )
        ,m_nPosX(0)
        ,m_nPosY(0)
        ,m_nWidth(0)
        ,m_nHeight(0)
        ,m_nTabIndex(-1)
        ,m_nStep(0)
        ,m_bCloneable(_rxAggregateInstance.is())
    {
        increment(m_refCount);
        {
            {
                // ensure that the temporary gets destructed NOW
                m_xAggregate = Reference< XAggregation >(_rxAggregateInstance, UNO_QUERY);
            }
            OSL_ENSURE(m_xAggregate.is(), "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid object given!");

            // now the aggregate has a ref count of 2, but before setting the delegator it must be 1
            _rxAggregateInstance.clear();
            // now it should be the 1 we need here ...

            setAggregation(m_xAggregate);
            m_xAggregate->setDelegator(static_cast< XWeak* >(this));
        }
        decrement(m_refCount);

        registerProperties();
    }

    //--------------------------------------------------------------------
    Sequence< Type > SAL_CALL OGeometryControlModel_Base::getTypes(  ) throw (RuntimeException)
    {
        // our own types
        Sequence< Type > aTypes = ::comphelper::concatSequences(
            OPropertySetAggregationHelper::getTypes(),
            OPropertyContainer::getTypes(),
            OGCM_Base::getTypes()
        );

        if ( m_xAggregate.is() )
        {
            // retrieve the types of the aggregate
            Reference< XTypeProvider > xAggregateTypeProv;
            m_xAggregate->queryAggregation( ::getCppuType( &xAggregateTypeProv ) ) >>= xAggregateTypeProv;
            OSL_ENSURE( xAggregateTypeProv.is(), "OGeometryControlModel_Base::getTypes: aggregate should be a type provider!" );
            Sequence< Type > aAggTypes;
            if ( xAggregateTypeProv.is() )
                aAggTypes = xAggregateTypeProv->getTypes();

            // concat the sequences
            sal_Int32 nOldSize = aTypes.getLength();
            aTypes.realloc( nOldSize + aAggTypes.getLength() );
            ::std::copy(
                aAggTypes.getConstArray(),
                aAggTypes.getConstArray() + aAggTypes.getLength(),
                aTypes.getArray() + nOldSize
            );
        }

        return aTypes;
    }

    //--------------------------------------------------------------------
    void OGeometryControlModel_Base::registerProperties()
    {
        // register our members for the property handling of the OPropertyContainer
        registerProperty(GCM_PROPERTY_POS_X,    GCM_PROPERTY_ID_POS_X,      DEFAULT_ATTRIBS(), &m_nPosX, ::getCppuType(&m_nPosX));
        registerProperty(GCM_PROPERTY_POS_Y,    GCM_PROPERTY_ID_POS_Y,      DEFAULT_ATTRIBS(), &m_nPosY, ::getCppuType(&m_nPosY));
        registerProperty(GCM_PROPERTY_WIDTH,    GCM_PROPERTY_ID_WIDTH,      DEFAULT_ATTRIBS(), &m_nWidth, ::getCppuType(&m_nWidth));
        registerProperty(GCM_PROPERTY_HEIGHT,   GCM_PROPERTY_ID_HEIGHT,     DEFAULT_ATTRIBS(), &m_nHeight, ::getCppuType(&m_nHeight));
        registerProperty(GCM_PROPERTY_NAME,     GCM_PROPERTY_ID_NAME,       DEFAULT_ATTRIBS(), &m_aName, ::getCppuType(&m_aName));
        registerProperty(GCM_PROPERTY_TABINDEX, GCM_PROPERTY_ID_TABINDEX,   DEFAULT_ATTRIBS(), &m_nTabIndex, ::getCppuType(&m_nTabIndex));
        registerProperty(GCM_PROPERTY_STEP,     GCM_PROPERTY_ID_STEP,       DEFAULT_ATTRIBS(), &m_nStep, ::getCppuType(&m_nStep));
        registerProperty(GCM_PROPERTY_TAG,      GCM_PROPERTY_ID_TAG,        DEFAULT_ATTRIBS(), &m_aTag, ::getCppuType(&m_aTag));
        registerProperty(GCM_PROPERTY_RESOURCERESOLVER, GCM_PROPERTY_ID_RESOURCERESOLVER, DEFAULT_ATTRIBS(), &m_xStrResolver, ::getCppuType(&m_xStrResolver));
    }

    //--------------------------------------------------------------------
    ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetDefaultValueByHandle(sal_Int32 nHandle) const
    {
        ::com::sun::star::uno::Any aDefault;

        switch ( nHandle )
        {
            case GCM_PROPERTY_ID_POS_X:             aDefault <<= (sal_Int32) 0; break;
            case GCM_PROPERTY_ID_POS_Y:             aDefault <<= (sal_Int32) 0; break;
            case GCM_PROPERTY_ID_WIDTH:             aDefault <<= (sal_Int32) 0; break;
            case GCM_PROPERTY_ID_HEIGHT:            aDefault <<= (sal_Int32) 0; break;
            case GCM_PROPERTY_ID_NAME:              aDefault <<= ::rtl::OUString(); break;
            case GCM_PROPERTY_ID_TABINDEX:          aDefault <<= (sal_Int16) -1; break;
            case GCM_PROPERTY_ID_STEP:              aDefault <<= (sal_Int32) 0; break;
            case GCM_PROPERTY_ID_TAG:               aDefault <<= ::rtl::OUString(); break;
            case GCM_PROPERTY_ID_RESOURCERESOLVER:  aDefault <<= Reference< resource::XStringResourceResolver >(); break;
            default:                            DBG_ERROR( "ImplGetDefaultValueByHandle - unknown Property" );
        }

        return aDefault;
    }

    //--------------------------------------------------------------------
    ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetPropertyValueByHandle(sal_Int32 nHandle) const
    {
        ::com::sun::star::uno::Any aValue;

        switch ( nHandle )
        {
            case GCM_PROPERTY_ID_POS_X:         aValue <<= m_nPosX; break;
            case GCM_PROPERTY_ID_POS_Y:         aValue <<= m_nPosY; break;
            case GCM_PROPERTY_ID_WIDTH:         aValue <<= m_nWidth; break;
            case GCM_PROPERTY_ID_HEIGHT:        aValue <<= m_nHeight; break;
            case GCM_PROPERTY_ID_NAME:          aValue <<= m_aName; break;
            case GCM_PROPERTY_ID_TABINDEX:      aValue <<= m_nTabIndex; break;
            case GCM_PROPERTY_ID_STEP:          aValue <<= m_nStep; break;
            case GCM_PROPERTY_ID_TAG:           aValue <<= m_aTag; break;
            case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue <<= m_xStrResolver; break;
            default:                            DBG_ERROR( "ImplGetPropertyValueByHandle - unknown Property" );
        }

        return aValue;
    }

    //--------------------------------------------------------------------
    void OGeometryControlModel_Base::ImplSetPropertyValueByHandle(sal_Int32 nHandle, const :: com::sun::star::uno::Any& aValue)
    {
        switch ( nHandle )
        {
            case GCM_PROPERTY_ID_POS_X:         aValue >>= m_nPosX; break;
            case GCM_PROPERTY_ID_POS_Y:         aValue >>= m_nPosY; break;
            case GCM_PROPERTY_ID_WIDTH:         aValue >>= m_nWidth; break;
            case GCM_PROPERTY_ID_HEIGHT:        aValue >>= m_nHeight; break;
            case GCM_PROPERTY_ID_NAME:          aValue >>= m_aName; break;
            case GCM_PROPERTY_ID_TABINDEX:      aValue >>= m_nTabIndex; break;
            case GCM_PROPERTY_ID_STEP:          aValue >>= m_nStep; break;
            case GCM_PROPERTY_ID_TAG:           aValue >>= m_aTag; break;
            case GCM_PROPERTY_ID_RESOURCERESOLVER: aValue >>= m_xStrResolver; break;
            default:                            DBG_ERROR( "ImplSetPropertyValueByHandle - unknown Property" );
        }
    }

    //--------------------------------------------------------------------
    Any SAL_CALL OGeometryControlModel_Base::queryAggregation( const Type& _rType ) throw(RuntimeException)
    {
        Any aReturn;
        if (_rType.equals(::getCppuType(static_cast< Reference< XCloneable>* >(NULL))) && !m_bCloneable)
            // somebody is asking for the XCloneable interface, but our aggregate does not support it
            // -> outta here
            // (need this extra check, cause OGCM_Base::queryAggregation would return this interface
            // in every case)
            return aReturn;

        aReturn = OGCM_Base::queryAggregation(_rType);
            // the basic interfaces (XInterface, XAggregation etc)

        if (!aReturn.hasValue())
            aReturn = OPropertySetAggregationHelper::queryInterface(_rType);
            // the property set related interfaces

        if (!aReturn.hasValue() && m_xAggregate.is())
            aReturn = m_xAggregate->queryAggregation(_rType);
            // the interfaces our aggregate can provide

        return aReturn;
    }

    //--------------------------------------------------------------------
    Any SAL_CALL OGeometryControlModel_Base::queryInterface( const Type& _rType ) throw(RuntimeException)
    {
        return OGCM_Base::queryInterface(_rType);
    }

    //--------------------------------------------------------------------
    void SAL_CALL OGeometryControlModel_Base::acquire(  ) throw()
    {
        OGCM_Base::acquire();
    }

    //--------------------------------------------------------------------
    void SAL_CALL OGeometryControlModel_Base::release(  ) throw()
    {
        OGCM_Base::release();
    }

    //--------------------------------------------------------------------
    void OGeometryControlModel_Base::releaseAggregation()
    {
        // release the aggregate (_before_ clearing m_xAggregate)
        if (m_xAggregate.is())
            m_xAggregate->setDelegator(NULL);
        setAggregation(NULL);
    }

    //--------------------------------------------------------------------
    OGeometryControlModel_Base::~OGeometryControlModel_Base()
    {
        releaseAggregation();
    }

    //--------------------------------------------------------------------
    sal_Bool SAL_CALL OGeometryControlModel_Base::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
            sal_Int32 _nHandle, const Any& _rValue) throw (IllegalArgumentException)
    {
        return OPropertyContainer::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
    }

    //--------------------------------------------------------------------
    void SAL_CALL OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception)
    {
        OPropertyContainer::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
    }

    //--------------------------------------------------------------------
    void SAL_CALL OGeometryControlModel_Base::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
    {
        OPropertyArrayAggregationHelper& rPH = static_cast<OPropertyArrayAggregationHelper&>(const_cast<OGeometryControlModel_Base*>(this)->getInfoHelper());
        ::rtl::OUString sPropName;
        sal_Int32   nOriginalHandle = -1;

        if (rPH.fillAggregatePropertyInfoByHandle(&sPropName, &nOriginalHandle, _nHandle))
            OPropertySetAggregationHelper::getFastPropertyValue(_rValue, _nHandle);
        else
            OPropertyContainer::getFastPropertyValue(_rValue, _nHandle);
    }

    //--------------------------------------------------------------------
    ::com::sun::star::beans::PropertyState OGeometryControlModel_Base::getPropertyStateByHandle(sal_Int32 nHandle)
    {
        ::com::sun::star::uno::Any aValue = ImplGetPropertyValueByHandle( nHandle );
        ::com::sun::star::uno::Any aDefault = ImplGetDefaultValueByHandle( nHandle );

        return CompareProperties( aValue, aDefault ) ? ::com::sun::star::beans::PropertyState_DEFAULT_VALUE : ::com::sun::star::beans::PropertyState_DIRECT_VALUE;
    }

    //--------------------------------------------------------------------
    void OGeometryControlModel_Base::setPropertyToDefaultByHandle(sal_Int32 nHandle)
    {
        ImplSetPropertyValueByHandle( nHandle , ImplGetDefaultValueByHandle( nHandle ) );
    }

    //--------------------------------------------------------------------
    ::com::sun::star::uno::Any OGeometryControlModel_Base::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
    {
        return ImplGetDefaultValueByHandle( nHandle );
    }

    //--------------------------------------------------------------------
    Reference< XPropertySetInfo> SAL_CALL OGeometryControlModel_Base::getPropertySetInfo() throw(RuntimeException)
    {
        return OPropertySetAggregationHelper::createPropertySetInfo(getInfoHelper());
    }

    //--------------------------------------------------------------------
    Reference< XCloneable > SAL_CALL OGeometryControlModel_Base::createClone(  ) throw(RuntimeException)
    {
        OSL_ENSURE(m_bCloneable, "OGeometryControlModel_Base::createClone: invalid call!");
        if (!m_bCloneable)
            return Reference< XCloneable >();

        // let the aggregate create it's own clone
        // the interface
        Reference< XCloneable > xCloneAccess;
        m_xAggregate->queryAggregation(::getCppuType(&xCloneAccess)) >>= xCloneAccess;
        OSL_ENSURE(xCloneAccess.is(), "OGeometryControlModel_Base::createClone: suspicious aggregate!");
        if (!xCloneAccess.is())
            return Reference< XCloneable >();
        // the aggregate's clone
        Reference< XCloneable > xAggregateClone = xCloneAccess->createClone();
        OSL_ENSURE(xAggregateClone.is(), "OGeometryControlModel_Base::createClone: suspicious return of the aggregate!");

        // create a new wrapper aggregating this return value
        OGeometryControlModel_Base* pOwnClone = createClone_Impl(xAggregateClone);
        OSL_ENSURE(pOwnClone, "OGeometryControlModel_Base::createClone: invalid derivee behaviour!");
        OSL_ENSURE(!xAggregateClone.is(), "OGeometryControlModel_Base::createClone: invalid ctor behaviour!");
            // should have been reset

        // set properties
        pOwnClone->m_nPosX      = m_nPosX;
        pOwnClone->m_nPosY      = m_nPosY;
        pOwnClone->m_nWidth     = m_nWidth;
        pOwnClone->m_nHeight    = m_nHeight;
        pOwnClone->m_aName      = m_aName;
        pOwnClone->m_nTabIndex  = m_nTabIndex;
        pOwnClone->m_nStep      = m_nStep;
        pOwnClone->m_aTag       = m_aTag;


        // Clone event container
        Reference< ::com::sun::star::script::XScriptEventsSupplier > xEventsSupplier =
            static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( this );
        Reference< ::com::sun::star::script::XScriptEventsSupplier > xCloneEventsSupplier =
            static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( pOwnClone );

        if( xEventsSupplier.is() && xCloneEventsSupplier.is() )
        {
            Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
            Reference< XNameContainer > xCloneEventCont = xCloneEventsSupplier->getEvents();

            ::com::sun::star::uno::Sequence< ::rtl::OUString > aNames =
                xEventCont->getElementNames();
            const ::rtl::OUString* pNames = aNames.getConstArray();
            sal_Int32 i, nNameCount = aNames.getLength();

            for( i = 0 ; i < nNameCount ; i++ )
            {
                ::rtl::OUString aName = pNames[ i ];
                ::com::sun::star::uno::Any aElement = xEventCont->getByName( aName );
                xCloneEventCont->insertByName( aName, aElement );
            }
        }

        return pOwnClone;
    }

    //--------------------------------------------------------------------
    Reference< XNameContainer > SAL_CALL OGeometryControlModel_Base::getEvents() throw(RuntimeException)
    {
        if( !mxEventContainer.is() )
            mxEventContainer = (XNameContainer*)new toolkit::ScriptEventContainer();
        return mxEventContainer;
    }

    //--------------------------------------------------------------------
    void SAL_CALL OGeometryControlModel_Base::disposing()
    {
        OGCM_Base::disposing();
        OPropertySetAggregationHelper::disposing();

        Reference<XComponent>  xComp;
        if ( query_aggregation( m_xAggregate, xComp ) )
            xComp->dispose();
    }

    //====================================================================
    //= OCommonGeometryControlModel
    //====================================================================
    //--------------------------------------------------------------------

    typedef ::boost::unordered_map< ::rtl::OUString, sal_Int32, ::comphelper::UStringHash > HashMapString2Int;
    typedef ::std::vector< ::com::sun::star::uno::Sequence< ::com::sun::star::beans::Property > >   PropSeqArray;
    typedef ::std::vector< ::std::vector< sal_Int32 > > IntArrayArray;

    // for creating class-unique PropertySetInfo's, we need some info:
    namespace { struct ServiceSpecifierMap : public rtl::Static< HashMapString2Int, ServiceSpecifierMap > {}; }
    // this one maps from a String, which is the service specifier for our
    // aggregate, to a unique id

    namespace { struct AggregateProperties : public rtl::Static< PropSeqArray, AggregateProperties > {}; }
    // this one contains the properties which belong to all the unique ids
    // in ServiceSpecifierMap

    namespace { struct AmbiguousPropertyIds : public rtl::Static< IntArrayArray, AmbiguousPropertyIds > {}; }
    // the ids of the properties which we as well as our aggregate supply
    // For such props, we let our base class handle them, and whenever such
    // a prop is set, we forward this to our aggregate.

    // With this, we can ensure that two instances of this class share the
    // same PropertySetInfo if and only if both aggregates have the same
    // service specifier.


    //--------------------------------------------------------------------
    OCommonGeometryControlModel::OCommonGeometryControlModel( Reference< XCloneable >& _rxAgg, const ::rtl::OUString& _rServiceSpecifier )
        :OGeometryControlModel_Base( _rxAgg )
        ,m_sServiceSpecifier( _rServiceSpecifier )
        ,m_nPropertyMapId( 0 )
    {
        Reference< XPropertySetInfo > xPI;
        if ( m_xAggregateSet.is() )
            xPI = m_xAggregateSet->getPropertySetInfo();
        if ( !xPI.is() )
        {
            releaseAggregation();
            throw IllegalArgumentException();
        }

            HashMapString2Int &rMap = ServiceSpecifierMap::get();
        HashMapString2Int::iterator aPropMapIdPos = rMap.find( m_sServiceSpecifier );
        if ( rMap.end() == aPropMapIdPos )
        {
            PropSeqArray &rAggProperties = AggregateProperties::get();
            m_nPropertyMapId = rAggProperties.size();
            rAggProperties.push_back( xPI->getProperties() );
            AmbiguousPropertyIds::get().push_back( IntArrayArray::value_type() );

            rMap[ m_sServiceSpecifier ] = m_nPropertyMapId;
        }
        else
            m_nPropertyMapId = aPropMapIdPos->second;
    }

    //--------------------------------------------------------------------
    struct PropertyNameLess : public ::std::binary_function< Property, Property, bool >
    {
        bool operator()( const Property& _rLHS, const Property& _rRHS )
        {
            return _rLHS.Name < _rRHS.Name ? true : false;
        }
    };

    //--------------------------------------------------------------------
    struct PropertyNameEqual : public ::std::unary_function< Property, bool >
    {
        const ::rtl::OUString&  m_rCompare;
        PropertyNameEqual( const ::rtl::OUString& _rCompare ) : m_rCompare( _rCompare ) { }

        bool operator()( const Property& _rLHS )
        {
            return _rLHS.Name == m_rCompare ? true : false;
        }
    };

    //--------------------------------------------------------------------
    ::cppu::IPropertyArrayHelper* OCommonGeometryControlModel::createArrayHelper( sal_Int32 _nId ) const
    {
        OSL_ENSURE( _nId == m_nPropertyMapId, "OCommonGeometryControlModel::createArrayHelper: invalid argument!" );
        OSL_ENSURE( _nId < (sal_Int32)AggregateProperties::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (1)!" );
        OSL_ENSURE( _nId < (sal_Int32)AmbiguousPropertyIds::get().size(), "OCommonGeometryControlModel::createArrayHelper: invalid status info (2)!" );

        // our own properties
        Sequence< Property > aProps;
        OPropertyContainer::describeProperties( aProps );

        // the aggregate properties
        Sequence< Property > aAggregateProps;
        aAggregateProps = AggregateProperties::get()[ _nId ];

        // look for duplicates, and remember them
        IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ _nId ];
        // for this, sort the aggregate properties
        ::std::sort(
            aAggregateProps.getArray(),
            aAggregateProps.getArray() + aAggregateProps.getLength(),
            PropertyNameLess()
        );
        const Property* pAggProps = aAggregateProps.getConstArray();
        const Property* pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength();

        // now loop through our own props
        const Property* pProp = aProps.getConstArray();
        const Property* pPropEnd = aProps.getConstArray() + aProps.getLength();
        while ( pProp < pPropEnd )
        {
            // look for the current property in the properties of our aggregate
            const Property* pAggPropPos = ::std::find_if( pAggProps, pAggPropsEnd, PropertyNameEqual( pProp->Name ) );
            if ( pAggPropPos != pAggPropsEnd )
            {   // found a duplicate
                // -> remove from the aggregate property sequence
                ::comphelper::removeElementAt( aAggregateProps, pAggPropPos - pAggProps );
                // which means we have to adjust the pointers
                pAggProps = aAggregateProps.getConstArray(),
                pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength(),

                // and additionally, remember the id of this property
                rDuplicateIds.push_back( pProp->Handle );
            }

            ++pProp;
        }

        // now, finally, sort the duplicates
        ::std::sort( rDuplicateIds.begin(), rDuplicateIds.end(), ::std::less< sal_Int32 >() );

        return new OPropertyArrayAggregationHelper(aProps, aAggregateProps);
    }

    //--------------------------------------------------------------------
    ::cppu::IPropertyArrayHelper& SAL_CALL OCommonGeometryControlModel::getInfoHelper()
    {
        return *getArrayHelper( m_nPropertyMapId );
    }

    //--------------------------------------------------------------------
    OGeometryControlModel_Base* OCommonGeometryControlModel::createClone_Impl( Reference< XCloneable >& _rxAggregateInstance )
    {
        return new OCommonGeometryControlModel( _rxAggregateInstance, m_sServiceSpecifier );
    }

    //--------------------------------------------------------------------
    Sequence< sal_Int8 > SAL_CALL OCommonGeometryControlModel::getImplementationId(  ) throw (RuntimeException)
    {
        static ::cppu::OImplementationId * pId = NULL;
        if ( !pId )
        {
            ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
            if ( !pId )
            {
                static ::cppu::OImplementationId s_aId;
                pId = &s_aId;
            }
        }
        return pId->getImplementationId();
    }

    //--------------------------------------------------------------------
    struct Int32Equal : public ::std::unary_function< sal_Int32, bool >
    {
        sal_Int32   m_nCompare;
        Int32Equal( sal_Int32 _nCompare ) : m_nCompare( _nCompare ) { }

        bool operator()( sal_Int32 _nLHS )
        {
            return _nLHS == m_nCompare ? true  : false;
        }
    };

    //--------------------------------------------------------------------
    void SAL_CALL OCommonGeometryControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception )
    {
        OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );

        // look if this id is one we recognized as duplicate
        IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ m_nPropertyMapId ];

        IntArrayArray::value_type::const_iterator aPos = ::std::find_if(
            rDuplicateIds.begin(),
            rDuplicateIds.end(),
            Int32Equal( _nHandle )
        );

        if ( rDuplicateIds.end() != aPos )
        {
            // yes, it is such a property
            ::rtl::OUString sPropName;
            sal_Int16 nAttributes(0);
            static_cast< OPropertyArrayAggregationHelper* >( getArrayHelper( m_nPropertyMapId ) )->fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );

            if ( m_xAggregateSet.is() && sPropName.getLength() )
                m_xAggregateSet->setPropertyValue( sPropName, _rValue );
        }
    }

//........................................................................
// }    // namespace toolkit
//........................................................................

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */