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