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

Generated by: LCOV version 1.10