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

Generated by: LCOV version 1.10