LCOV - code coverage report
Current view: top level - toolkit/source/controls - geometrycontrolmodel.cxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 201 240 83.8 %
Date: 2014-04-11 Functions: 30 35 85.7 %
Legend: Lines: hit not hit

          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          48 :     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          48 :         ,m_bCloneable(false)
      83             :     {
      84             :         OSL_ENSURE(NULL != _pAggregateInstance, "OGeometryControlModel_Base::OGeometryControlModel_Base: invalid aggregate!");
      85             : 
      86          48 :         increment(m_refCount);
      87             :         {
      88          48 :             m_xAggregate = _pAggregateInstance;
      89             : 
      90             :             {   // check if the aggregate is cloneable
      91          48 :                 Reference< XCloneable > xCloneAccess(m_xAggregate, UNO_QUERY);
      92          48 :                 m_bCloneable = xCloneAccess.is();
      93             :             }
      94             : 
      95          48 :             setAggregation(m_xAggregate);
      96          48 :             m_xAggregate->setDelegator(static_cast< XWeak* >(this));
      97             :         }
      98          48 :         decrement(m_refCount);
      99             : 
     100          48 :         registerProperties();
     101          48 :     }
     102             : 
     103             : 
     104          19 :     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          19 :         ,m_bCloneable(_rxAggregateInstance.is())
     115             :     {
     116          19 :         increment(m_refCount);
     117             :         {
     118             :             {
     119             :                 // ensure that the temporary gets destructed NOW
     120          19 :                 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          19 :             _rxAggregateInstance.clear();
     126             :             // now it should be the 1 we need here ...
     127             : 
     128          19 :             setAggregation(m_xAggregate);
     129          19 :             m_xAggregate->setDelegator(static_cast< XWeak* >(this));
     130             :         }
     131          19 :         decrement(m_refCount);
     132             : 
     133          19 :         registerProperties();
     134          19 :     }
     135             : 
     136             : 
     137         154 :     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         154 :         );
     145             : 
     146         154 :         if ( m_xAggregate.is() )
     147             :         {
     148             :             // retrieve the types of the aggregate
     149         154 :             Reference< XTypeProvider > xAggregateTypeProv;
     150         154 :             m_xAggregate->queryAggregation( ::getCppuType( &xAggregateTypeProv ) ) >>= xAggregateTypeProv;
     151             :             OSL_ENSURE( xAggregateTypeProv.is(), "OGeometryControlModel_Base::getTypes: aggregate should be a type provider!" );
     152         308 :             Sequence< Type > aAggTypes;
     153         154 :             if ( xAggregateTypeProv.is() )
     154         154 :                 aAggTypes = xAggregateTypeProv->getTypes();
     155             : 
     156             :             // concat the sequences
     157         154 :             sal_Int32 nOldSize = aTypes.getLength();
     158         154 :             aTypes.realloc( nOldSize + aAggTypes.getLength() );
     159             :             ::std::copy(
     160             :                 aAggTypes.getConstArray(),
     161         154 :                 aAggTypes.getConstArray() + aAggTypes.getLength(),
     162         154 :                 aTypes.getArray() + nOldSize
     163         462 :             );
     164             :         }
     165             : 
     166         154 :         return aTypes;
     167             :     }
     168             : 
     169             : 
     170          67 :     void OGeometryControlModel_Base::registerProperties()
     171             :     {
     172             :         // register our members for the property handling of the OPropertyContainer
     173          67 :         registerProperty(GCM_PROPERTY_POS_X,    GCM_PROPERTY_ID_POS_X,      DEFAULT_ATTRIBS(), &m_nPosX, ::getCppuType(&m_nPosX));
     174          67 :         registerProperty(GCM_PROPERTY_POS_Y,    GCM_PROPERTY_ID_POS_Y,      DEFAULT_ATTRIBS(), &m_nPosY, ::getCppuType(&m_nPosY));
     175          67 :         registerProperty(GCM_PROPERTY_WIDTH,    GCM_PROPERTY_ID_WIDTH,      DEFAULT_ATTRIBS(), &m_nWidth, ::getCppuType(&m_nWidth));
     176          67 :         registerProperty(GCM_PROPERTY_HEIGHT,   GCM_PROPERTY_ID_HEIGHT,     DEFAULT_ATTRIBS(), &m_nHeight, ::getCppuType(&m_nHeight));
     177          67 :         registerProperty(GCM_PROPERTY_NAME,     GCM_PROPERTY_ID_NAME,       DEFAULT_ATTRIBS(), &m_aName, ::getCppuType(&m_aName));
     178          67 :         registerProperty(GCM_PROPERTY_TABINDEX, GCM_PROPERTY_ID_TABINDEX,   DEFAULT_ATTRIBS(), &m_nTabIndex, ::getCppuType(&m_nTabIndex));
     179          67 :         registerProperty(GCM_PROPERTY_STEP,     GCM_PROPERTY_ID_STEP,       DEFAULT_ATTRIBS(), &m_nStep, ::getCppuType(&m_nStep));
     180          67 :         registerProperty(GCM_PROPERTY_TAG,      GCM_PROPERTY_ID_TAG,        DEFAULT_ATTRIBS(), &m_aTag, ::getCppuType(&m_aTag));
     181          67 :         registerProperty(GCM_PROPERTY_RESOURCERESOLVER, GCM_PROPERTY_ID_RESOURCERESOLVER, DEFAULT_ATTRIBS(), &m_xStrResolver, ::getCppuType(&m_xStrResolver));
     182          67 :     }
     183             : 
     184             : 
     185          30 :     ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetDefaultValueByHandle(sal_Int32 nHandle) const
     186             :     {
     187          30 :         ::com::sun::star::uno::Any aDefault;
     188             : 
     189          30 :         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          10 :             case GCM_PROPERTY_ID_TABINDEX:          aDefault <<= (sal_Int16) -1; break;
     197          10 :             case GCM_PROPERTY_ID_STEP:              aDefault <<= (sal_Int32) 0; break;
     198          10 :             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          30 :         return aDefault;
     204             :     }
     205             : 
     206             : 
     207          30 :     ::com::sun::star::uno::Any OGeometryControlModel_Base::ImplGetPropertyValueByHandle(sal_Int32 nHandle) const
     208             :     {
     209          30 :         ::com::sun::star::uno::Any aValue;
     210             : 
     211          30 :         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          10 :             case GCM_PROPERTY_ID_TABINDEX:      aValue <<= m_nTabIndex; break;
     219          10 :             case GCM_PROPERTY_ID_STEP:          aValue <<= m_nStep; break;
     220          10 :             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          30 :         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        3971 :     Any SAL_CALL OGeometryControlModel_Base::queryAggregation( const Type& _rType ) throw(RuntimeException, std::exception)
     248             :     {
     249        3971 :         Any aReturn;
     250        3971 :         if (_rType.equals(::getCppuType(static_cast< Reference< XCloneable>* >(NULL))) && !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        3971 :         aReturn = OGCM_Base::queryAggregation(_rType);
     258             :             // the basic interfaces (XInterface, XAggregation etc)
     259             : 
     260        3971 :         if (!aReturn.hasValue())
     261        2709 :             aReturn = OPropertySetAggregationHelper::queryInterface(_rType);
     262             :             // the property set related interfaces
     263             : 
     264        3971 :         if (!aReturn.hasValue() && m_xAggregate.is())
     265        1838 :             aReturn = m_xAggregate->queryAggregation(_rType);
     266             :             // the interfaces our aggregate can provide
     267             : 
     268        3971 :         return aReturn;
     269             :     }
     270             : 
     271             : 
     272        3971 :     Any SAL_CALL OGeometryControlModel_Base::queryInterface( const Type& _rType ) throw(RuntimeException, std::exception)
     273             :     {
     274        3971 :         return OGCM_Base::queryInterface(_rType);
     275             :     }
     276             : 
     277             : 
     278      102047 :     void SAL_CALL OGeometryControlModel_Base::acquire(  ) throw()
     279             :     {
     280      102047 :         OGCM_Base::acquire();
     281      102047 :     }
     282             : 
     283             : 
     284      101885 :     void SAL_CALL OGeometryControlModel_Base::release(  ) throw()
     285             :     {
     286      101885 :         OGCM_Base::release();
     287      101885 :     }
     288             : 
     289             : 
     290          34 :     void OGeometryControlModel_Base::releaseAggregation()
     291             :     {
     292             :         // release the aggregate (_before_ clearing m_xAggregate)
     293          34 :         if (m_xAggregate.is())
     294          34 :             m_xAggregate->setDelegator(NULL);
     295          34 :         setAggregation(NULL);
     296          34 :     }
     297             : 
     298             : 
     299          68 :     OGeometryControlModel_Base::~OGeometryControlModel_Base()
     300             :     {
     301          34 :         releaseAggregation();
     302          34 :     }
     303             : 
     304             : 
     305         670 :     sal_Bool SAL_CALL OGeometryControlModel_Base::convertFastPropertyValue(Any& _rConvertedValue, Any& _rOldValue,
     306             :             sal_Int32 _nHandle, const Any& _rValue) throw (IllegalArgumentException)
     307             :     {
     308         670 :         return OPropertyContainer::convertFastPropertyValue(_rConvertedValue, _rOldValue, _nHandle, _rValue);
     309             :     }
     310             : 
     311             : 
     312         218 :     void SAL_CALL OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast(sal_Int32 _nHandle, const Any& _rValue) throw (Exception, std::exception)
     313             :     {
     314         218 :         OPropertyContainer::setFastPropertyValue_NoBroadcast(_nHandle, _rValue);
     315         218 :     }
     316             : 
     317             : 
     318        3556 :     void SAL_CALL OGeometryControlModel_Base::getFastPropertyValue(Any& _rValue, sal_Int32 _nHandle) const
     319             :     {
     320        3556 :         OPropertyArrayAggregationHelper& rPH = static_cast<OPropertyArrayAggregationHelper&>(const_cast<OGeometryControlModel_Base*>(this)->getInfoHelper());
     321        3556 :         OUString sPropName;
     322        3556 :         sal_Int32   nOriginalHandle = -1;
     323             : 
     324        3556 :         if (rPH.fillAggregatePropertyInfoByHandle(&sPropName, &nOriginalHandle, _nHandle))
     325        2515 :             OPropertySetAggregationHelper::getFastPropertyValue(_rValue, _nHandle);
     326             :         else
     327        1041 :             OPropertyContainer::getFastPropertyValue(_rValue, _nHandle);
     328        3556 :     }
     329             : 
     330             : 
     331          30 :     ::com::sun::star::beans::PropertyState OGeometryControlModel_Base::getPropertyStateByHandle(sal_Int32 nHandle)
     332             :     {
     333          30 :         ::com::sun::star::uno::Any aValue = ImplGetPropertyValueByHandle( nHandle );
     334          60 :         ::com::sun::star::uno::Any aDefault = ImplGetDefaultValueByHandle( nHandle );
     335             : 
     336          60 :         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         376 :     Reference< XPropertySetInfo> SAL_CALL OGeometryControlModel_Base::getPropertySetInfo() throw(RuntimeException, std::exception)
     353             :     {
     354         376 :         return OPropertySetAggregationHelper::createPropertySetInfo(getInfoHelper());
     355             :     }
     356             : 
     357             : 
     358           3 :     Reference< XCloneable > SAL_CALL OGeometryControlModel_Base::createClone(  ) throw(RuntimeException, std::exception)
     359             :     {
     360             :         OSL_ENSURE(m_bCloneable, "OGeometryControlModel_Base::createClone: invalid call!");
     361           3 :         if (!m_bCloneable)
     362           0 :             return Reference< XCloneable >();
     363             : 
     364             :         // let the aggregate create it's own clone
     365             :         // the interface
     366           3 :         Reference< XCloneable > xCloneAccess;
     367           3 :         m_xAggregate->queryAggregation(::getCppuType(&xCloneAccess)) >>= xCloneAccess;
     368             :         OSL_ENSURE(xCloneAccess.is(), "OGeometryControlModel_Base::createClone: suspicious aggregate!");
     369           3 :         if (!xCloneAccess.is())
     370           0 :             return Reference< XCloneable >();
     371             :         // the aggregate's clone
     372           6 :         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           3 :         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           3 :         pOwnClone->m_nPosX      = m_nPosX;
     383           3 :         pOwnClone->m_nPosY      = m_nPosY;
     384           3 :         pOwnClone->m_nWidth     = m_nWidth;
     385           3 :         pOwnClone->m_nHeight    = m_nHeight;
     386           3 :         pOwnClone->m_aName      = m_aName;
     387           3 :         pOwnClone->m_nTabIndex  = m_nTabIndex;
     388           3 :         pOwnClone->m_nStep      = m_nStep;
     389           3 :         pOwnClone->m_aTag       = m_aTag;
     390             : 
     391             : 
     392             :         // Clone event container
     393             :         Reference< ::com::sun::star::script::XScriptEventsSupplier > xEventsSupplier =
     394           6 :             static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( this );
     395             :         Reference< ::com::sun::star::script::XScriptEventsSupplier > xCloneEventsSupplier =
     396           6 :             static_cast< ::com::sun::star::script::XScriptEventsSupplier* >( pOwnClone );
     397             : 
     398           3 :         if( xEventsSupplier.is() && xCloneEventsSupplier.is() )
     399             :         {
     400           3 :             Reference< XNameContainer > xEventCont = xEventsSupplier->getEvents();
     401           6 :             Reference< XNameContainer > xCloneEventCont = xCloneEventsSupplier->getEvents();
     402             : 
     403             :             ::com::sun::star::uno::Sequence< OUString > aNames =
     404           6 :                 xEventCont->getElementNames();
     405           3 :             const OUString* pNames = aNames.getConstArray();
     406           3 :             sal_Int32 i, nNameCount = aNames.getLength();
     407             : 
     408           3 :             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           3 :             }
     414             :         }
     415             : 
     416           6 :         return pOwnClone;
     417             :     }
     418             : 
     419             : 
     420          36 :     Reference< XNameContainer > SAL_CALL OGeometryControlModel_Base::getEvents() throw(RuntimeException, std::exception)
     421             :     {
     422          36 :         if( !mxEventContainer.is() )
     423          26 :             mxEventContainer = (XNameContainer*)new toolkit::ScriptEventContainer();
     424          36 :         return mxEventContainer;
     425             :     }
     426             : 
     427             : 
     428          34 :     void SAL_CALL OGeometryControlModel_Base::disposing()
     429             :     {
     430          34 :         OGCM_Base::disposing();
     431          34 :         OPropertySetAggregationHelper::disposing();
     432             : 
     433          34 :         Reference<XComponent>  xComp;
     434          34 :         if ( query_aggregation( m_xAggregate, xComp ) )
     435          34 :             xComp->dispose();
     436          34 :     }
     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          17 :     OCommonGeometryControlModel::OCommonGeometryControlModel( Reference< XCloneable >& _rxAgg, const OUString& _rServiceSpecifier )
     468             :         :OGeometryControlModel_Base( _rxAgg )
     469             :         ,m_sServiceSpecifier( _rServiceSpecifier )
     470          17 :         ,m_nPropertyMapId( 0 )
     471             :     {
     472          17 :         Reference< XPropertySetInfo > xPI;
     473          17 :         if ( m_xAggregateSet.is() )
     474          17 :             xPI = m_xAggregateSet->getPropertySetInfo();
     475          17 :         if ( !xPI.is() )
     476             :         {
     477           0 :             releaseAggregation();
     478           0 :             throw IllegalArgumentException();
     479             :         }
     480             : 
     481          17 :             HashMapString2Int &rMap = ServiceSpecifierMap::get();
     482          17 :         HashMapString2Int::iterator aPropMapIdPos = rMap.find( m_sServiceSpecifier );
     483          17 :         if ( rMap.end() == aPropMapIdPos )
     484             :         {
     485           7 :             PropSeqArray &rAggProperties = AggregateProperties::get();
     486           7 :             m_nPropertyMapId = rAggProperties.size();
     487           7 :             rAggProperties.push_back( xPI->getProperties() );
     488           7 :             AmbiguousPropertyIds::get().push_back( IntArrayArray::value_type() );
     489             : 
     490           7 :             rMap[ m_sServiceSpecifier ] = m_nPropertyMapId;
     491             :         }
     492             :         else
     493          10 :             m_nPropertyMapId = aPropMapIdPos->second;
     494          17 :     }
     495             : 
     496             : 
     497             :     struct PropertyNameLess : public ::std::binary_function< Property, Property, bool >
     498             :     {
     499        1961 :         bool operator()( const Property& _rLHS, const Property& _rRHS )
     500             :         {
     501        1961 :             return _rLHS.Name < _rRHS.Name ? true : false;
     502             :         }
     503             :     };
     504             : 
     505             : 
     506             :     struct PropertyNameEqual : public ::std::unary_function< Property, bool >
     507             :     {
     508             :         const OUString&  m_rCompare;
     509          63 :         PropertyNameEqual( const OUString& _rCompare ) : m_rCompare( _rCompare ) { }
     510             : 
     511        3433 :         bool operator()( const Property& _rLHS )
     512             :         {
     513        3433 :             return _rLHS.Name == m_rCompare ? true : false;
     514             :         }
     515             :     };
     516             : 
     517             : 
     518           7 :     ::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           7 :         Sequence< Property > aProps;
     526           7 :         OPropertyContainer::describeProperties( aProps );
     527             : 
     528             :         // the aggregate properties
     529          14 :         Sequence< Property > aAggregateProps;
     530           7 :         aAggregateProps = AggregateProperties::get()[ _nId ];
     531             : 
     532             :         // look for duplicates, and remember them
     533           7 :         IntArrayArray::value_type& rDuplicateIds = AmbiguousPropertyIds::get()[ _nId ];
     534             :         // for this, sort the aggregate properties
     535             :         ::std::sort(
     536             :             aAggregateProps.getArray(),
     537           7 :             aAggregateProps.getArray() + aAggregateProps.getLength(),
     538             :             PropertyNameLess()
     539           7 :         );
     540           7 :         const Property* pAggProps = aAggregateProps.getConstArray();
     541           7 :         const Property* pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength();
     542             : 
     543             :         // now loop through our own props
     544           7 :         const Property* pProp = aProps.getConstArray();
     545           7 :         const Property* pPropEnd = aProps.getConstArray() + aProps.getLength();
     546          77 :         while ( pProp < pPropEnd )
     547             :         {
     548             :             // look for the current property in the properties of our aggregate
     549          63 :             const Property* pAggPropPos = ::std::find_if( pAggProps, pAggPropsEnd, PropertyNameEqual( pProp->Name ) );
     550          63 :             if ( pAggPropPos != pAggPropsEnd )
     551             :             {   // found a duplicate
     552             :                 // -> remove from the aggregate property sequence
     553          18 :                 ::comphelper::removeElementAt( aAggregateProps, pAggPropPos - pAggProps );
     554             :                 // which means we have to adjust the pointers
     555             :                 pAggProps = aAggregateProps.getConstArray(),
     556          18 :                 pAggPropsEnd = aAggregateProps.getConstArray() + aAggregateProps.getLength(),
     557             : 
     558             :                 // and additionally, remember the id of this property
     559          36 :                 rDuplicateIds.push_back( pProp->Handle );
     560             :             }
     561             : 
     562          63 :             ++pProp;
     563             :         }
     564             : 
     565             :         // now, finally, sort the duplicates
     566           7 :         ::std::sort( rDuplicateIds.begin(), rDuplicateIds.end(), ::std::less< sal_Int32 >() );
     567             : 
     568          14 :         return new OPropertyArrayAggregationHelper(aProps, aAggregateProps);
     569             :     }
     570             : 
     571             : 
     572        1463 :     ::cppu::IPropertyArrayHelper& SAL_CALL OCommonGeometryControlModel::getInfoHelper()
     573             :     {
     574        1463 :         return *getArrayHelper( m_nPropertyMapId );
     575             :     }
     576             : 
     577             : 
     578           1 :     OGeometryControlModel_Base* OCommonGeometryControlModel::createClone_Impl( Reference< XCloneable >& _rxAggregateInstance )
     579             :     {
     580           1 :         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          54 :         Int32Equal( sal_Int32 _nCompare ) : m_nCompare( _nCompare ) { }
     593             : 
     594          90 :         bool operator()( sal_Int32 _nLHS )
     595             :         {
     596          90 :             return _nLHS == m_nCompare ? true  : false;
     597             :         }
     598             :     };
     599             : 
     600             : 
     601          54 :     void SAL_CALL OCommonGeometryControlModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw ( Exception, std::exception )
     602             :     {
     603          54 :         OGeometryControlModel_Base::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
     604             : 
     605             :         // look if this id is one we recognized as duplicate
     606          54 :         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          54 :         );
     613             : 
     614          54 :         if ( rDuplicateIds.end() != aPos )
     615             :         {
     616             :             // yes, it is such a property
     617          12 :             OUString sPropName;
     618          12 :             sal_Int16 nAttributes(0);
     619          12 :             static_cast< OPropertyArrayAggregationHelper* >( getArrayHelper( m_nPropertyMapId ) )->fillPropertyMembersByHandle( &sPropName, &nAttributes, _nHandle );
     620             : 
     621          12 :             if ( m_xAggregateSet.is() && !sPropName.isEmpty() )
     622          12 :                 m_xAggregateSet->setPropertyValue( sPropName, _rValue );
     623             :         }
     624          54 :     }
     625             : 
     626             : 
     627             : // }    // namespace toolkit
     628             : 
     629             : 
     630             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10