1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_chartcontroller.hxx" 26 #include "TitleWrapper.hxx" 27 #include "macros.hxx" 28 #include "ContainerHelper.hxx" 29 #include "ControllerLockGuard.hxx" 30 31 #include <comphelper/InlineContainer.hxx> 32 #include <com/sun/star/beans/PropertyAttribute.hpp> 33 #include <com/sun/star/chart2/RelativePosition.hpp> 34 35 #include "CharacterProperties.hxx" 36 #include "LineProperties.hxx" 37 #include "FillProperties.hxx" 38 #include "UserDefinedProperties.hxx" 39 #include "WrappedCharacterHeightProperty.hxx" 40 #include "WrappedTextRotationProperty.hxx" 41 #include "WrappedAutomaticPositionProperties.hxx" 42 #include "WrappedScaleTextProperties.hxx" 43 44 #include <algorithm> 45 #include <rtl/ustrbuf.hxx> 46 47 using namespace ::com::sun::star; 48 using ::com::sun::star::beans::Property; 49 using ::osl::MutexGuard; 50 using ::rtl::OUString; 51 using ::com::sun::star::uno::Any; 52 using ::com::sun::star::uno::Reference; 53 using ::com::sun::star::uno::Sequence; 54 55 56 namespace chart 57 { 58 class WrappedTitleStringProperty : public WrappedProperty 59 { 60 public: 61 WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext ); 62 virtual ~WrappedTitleStringProperty(); 63 64 virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const; 65 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const; 66 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const; 67 68 protected: 69 Reference< uno::XComponentContext > m_xContext; 70 }; 71 72 WrappedTitleStringProperty::WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext ) 73 : ::chart::WrappedProperty( C2U( "String" ), OUString() ) 74 , m_xContext( xContext ) 75 { 76 } 77 WrappedTitleStringProperty::~WrappedTitleStringProperty() 78 { 79 } 80 81 void WrappedTitleStringProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 82 { 83 Reference< chart2::XTitle > xTitle(xInnerPropertySet,uno::UNO_QUERY); 84 if(xTitle.is()) 85 { 86 OUString aString; 87 rOuterValue >>= aString; 88 TitleHelper::setCompleteString( aString, xTitle, m_xContext ); 89 } 90 } 91 Any WrappedTitleStringProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const 92 { 93 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) ); 94 Reference< chart2::XTitle > xTitle(xInnerPropertySet,uno::UNO_QUERY); 95 if(xTitle.is()) 96 { 97 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText()); 98 99 ::rtl::OUStringBuffer aBuf; 100 for( sal_Int32 i = 0; i < aStrings.getLength(); ++i ) 101 { 102 aBuf.append( aStrings[ i ]->getString()); 103 } 104 aRet <<= aBuf.makeStringAndClear(); 105 } 106 return aRet; 107 } 108 Any WrappedTitleStringProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 109 { 110 return uno::makeAny( rtl::OUString() );//default title is a empty String 111 } 112 113 //----------------------------------------------------------------------------- 114 //----------------------------------------------------------------------------- 115 116 class WrappedStackedTextProperty : public WrappedProperty 117 { 118 public: 119 WrappedStackedTextProperty(); 120 virtual ~WrappedStackedTextProperty(); 121 }; 122 123 WrappedStackedTextProperty::WrappedStackedTextProperty() 124 : ::chart::WrappedProperty( C2U( "StackedText" ), C2U( "StackCharacters" ) ) 125 { 126 } 127 WrappedStackedTextProperty::~WrappedStackedTextProperty() 128 { 129 } 130 131 }// end namespace chart 132 133 134 //----------------------------------------------------------------------------- 135 //----------------------------------------------------------------------------- 136 //----------------------------------------------------------------------------- 137 //----------------------------------------------------------------------------- 138 139 namespace 140 { 141 static const OUString lcl_aServiceName( 142 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart.Title" )); 143 144 enum 145 { 146 PROP_TITLE_STRING, 147 PROP_TITLE_TEXT_ROTATION, 148 PROP_TITLE_TEXT_STACKED 149 }; 150 151 void lcl_AddPropertiesToVector( 152 ::std::vector< Property > & rOutProperties ) 153 { 154 rOutProperties.push_back( 155 Property( C2U( "String" ), 156 PROP_TITLE_STRING, 157 ::getCppuType( reinterpret_cast< const ::rtl::OUString * >(0)), 158 beans::PropertyAttribute::BOUND 159 | beans::PropertyAttribute::MAYBEVOID )); 160 161 rOutProperties.push_back( 162 Property( C2U( "TextRotation" ), 163 PROP_TITLE_TEXT_ROTATION, 164 ::getCppuType( reinterpret_cast< const sal_Int32 * >(0)), 165 beans::PropertyAttribute::BOUND 166 | beans::PropertyAttribute::MAYBEDEFAULT )); 167 rOutProperties.push_back( 168 Property( C2U( "StackedText" ), 169 PROP_TITLE_TEXT_STACKED, 170 ::getBooleanCppuType(), 171 beans::PropertyAttribute::BOUND 172 | beans::PropertyAttribute::MAYBEDEFAULT )); 173 } 174 175 struct StaticTitleWrapperPropertyArray_Initializer 176 { 177 Sequence< Property >* operator()() 178 { 179 static Sequence< Property > aPropSeq( lcl_GetPropertySequence() ); 180 return &aPropSeq; 181 } 182 183 private: 184 Sequence< Property > lcl_GetPropertySequence() 185 { 186 ::std::vector< beans::Property > aProperties; 187 lcl_AddPropertiesToVector( aProperties ); 188 ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); 189 ::chart::LineProperties::AddPropertiesToVector( aProperties ); 190 ::chart::FillProperties::AddPropertiesToVector( aProperties ); 191 //::chart::NamedProperties::AddPropertiesToVector( aProperties ); 192 ::chart::UserDefinedProperties::AddPropertiesToVector( aProperties ); 193 ::chart::wrapper::WrappedAutomaticPositionProperties::addProperties( aProperties ); 194 ::chart::wrapper::WrappedScaleTextProperties::addProperties( aProperties ); 195 196 ::std::sort( aProperties.begin(), aProperties.end(), 197 ::chart::PropertyNameLess() ); 198 199 return ::chart::ContainerHelper::ContainerToSequence( aProperties ); 200 } 201 }; 202 203 struct StaticTitleWrapperPropertyArray : public rtl::StaticAggregate< Sequence< Property >, StaticTitleWrapperPropertyArray_Initializer > 204 { 205 }; 206 207 } // anonymous namespace 208 209 // -------------------------------------------------------------------------------- 210 211 namespace chart 212 { 213 namespace wrapper 214 { 215 216 TitleWrapper::TitleWrapper( ::chart::TitleHelper::eTitleType eTitleType, 217 ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) : 218 m_spChart2ModelContact( spChart2ModelContact ), 219 m_aEventListenerContainer( m_aMutex ), 220 m_eTitleType(eTitleType) 221 { 222 ControllerLockGuard aCtrlLockGuard( Reference< frame::XModel >( m_spChart2ModelContact->getChart2Document(), uno::UNO_QUERY )); 223 if( !getTitleObject().is() ) //#i83831# create an empty title at the model, thus references to properties can be mapped mapped correctly 224 TitleHelper::createTitle( m_eTitleType, OUString(), m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext ); 225 } 226 227 TitleWrapper::~TitleWrapper() 228 { 229 } 230 231 // ____ XShape ____ 232 awt::Point SAL_CALL TitleWrapper::getPosition() 233 { 234 return m_spChart2ModelContact->GetTitlePosition( this->getTitleObject() ); 235 } 236 237 void SAL_CALL TitleWrapper::setPosition( const awt::Point& aPosition ) 238 { 239 Reference< beans::XPropertySet > xPropertySet( this->getInnerPropertySet() ); 240 if(xPropertySet.is()) 241 { 242 awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() ); 243 244 chart2::RelativePosition aRelativePosition; 245 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT; 246 aRelativePosition.Primary = double(aPosition.X)/double(aPageSize.Width); 247 aRelativePosition.Secondary = double(aPosition.Y)/double(aPageSize.Height); 248 xPropertySet->setPropertyValue( C2U( "RelativePosition" ), uno::makeAny(aRelativePosition) ); 249 } 250 } 251 252 awt::Size SAL_CALL TitleWrapper::getSize() 253 { 254 return m_spChart2ModelContact->GetTitleSize( this->getTitleObject() ); 255 } 256 257 void SAL_CALL TitleWrapper::setSize( const awt::Size& /*aSize*/ ) 258 { 259 OSL_ENSURE( false, "trying to set size of title" ); 260 } 261 262 // ____ XShapeDescriptor (base of XShape) ____ 263 OUString SAL_CALL TitleWrapper::getShapeType() 264 { 265 return C2U( "com.sun.star.chart.ChartTitle" ); 266 } 267 268 // ____ XComponent ____ 269 void SAL_CALL TitleWrapper::dispose() 270 { 271 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) ); 272 m_aEventListenerContainer.disposeAndClear( lang::EventObject( xSource ) ); 273 274 // /-- 275 MutexGuard aGuard( GetMutex()); 276 clearWrappedPropertySet(); 277 // \-- 278 } 279 280 void SAL_CALL TitleWrapper::addEventListener( 281 const Reference< lang::XEventListener >& xListener ) 282 { 283 m_aEventListenerContainer.addInterface( xListener ); 284 } 285 286 void SAL_CALL TitleWrapper::removeEventListener( 287 const Reference< lang::XEventListener >& aListener ) 288 { 289 m_aEventListenerContainer.removeInterface( aListener ); 290 } 291 292 // ================================================================================ 293 294 Reference< beans::XPropertySet > TitleWrapper::getFirstCharacterPropertySet() 295 { 296 Reference< beans::XPropertySet > xProp; 297 298 Reference< chart2::XTitle > xTitle( this->getTitleObject() ); 299 if( xTitle.is()) 300 { 301 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText()); 302 if( aStrings.getLength() > 0 ) 303 xProp.set( aStrings[0], uno::UNO_QUERY ); 304 } 305 306 return xProp; 307 } 308 309 void TitleWrapper::getFastCharacterPropertyValue( sal_Int32 nHandle, Any& rValue ) 310 { 311 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP <= nHandle && 312 nHandle < CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP ); 313 314 Reference< beans::XPropertySet > xProp( getFirstCharacterPropertySet(), uno::UNO_QUERY ); 315 Reference< beans::XFastPropertySet > xFastProp( xProp, uno::UNO_QUERY ); 316 if(xProp.is()) 317 { 318 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle ); 319 if( pWrappedProperty ) 320 { 321 rValue = pWrappedProperty->getPropertyValue( xProp ); 322 } 323 else if( xFastProp.is() ) 324 { 325 rValue = xFastProp->getFastPropertyValue( nHandle ); 326 } 327 } 328 329 } 330 331 void TitleWrapper::setFastCharacterPropertyValue( 332 sal_Int32 nHandle, const Any& rValue ) 333 { 334 OSL_ASSERT( FAST_PROPERTY_ID_START_CHAR_PROP <= nHandle && 335 nHandle < CharacterProperties::FAST_PROPERTY_ID_END_CHAR_PROP ); 336 337 Reference< chart2::XTitle > xTitle( this->getTitleObject() ); 338 if( xTitle.is()) 339 { 340 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText()); 341 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle ); 342 343 for( sal_Int32 i = 0; i < aStrings.getLength(); ++i ) 344 { 345 Reference< beans::XFastPropertySet > xFastPropertySet( aStrings[ i ], uno::UNO_QUERY ); 346 Reference< beans::XPropertySet > xPropSet( xFastPropertySet, uno::UNO_QUERY ); 347 348 if( pWrappedProperty ) 349 pWrappedProperty->setPropertyValue( rValue, xPropSet ); 350 else if( xFastPropertySet.is() ) 351 xFastPropertySet->setFastPropertyValue( nHandle, rValue ); 352 } 353 } 354 } 355 356 // ================================================================================ 357 // WrappedPropertySet 358 359 void SAL_CALL TitleWrapper::setPropertyValue( const OUString& rPropertyName, const Any& rValue ) 360 { 361 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 362 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 363 { 364 setFastCharacterPropertyValue( nHandle, rValue ); 365 } 366 else 367 WrappedPropertySet::setPropertyValue( rPropertyName, rValue ); 368 } 369 370 Any SAL_CALL TitleWrapper::getPropertyValue( const OUString& rPropertyName ) 371 { 372 Any aRet; 373 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 374 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 375 getFastCharacterPropertyValue( nHandle, aRet ); 376 else 377 aRet = WrappedPropertySet::getPropertyValue( rPropertyName ); 378 return aRet; 379 } 380 381 beans::PropertyState SAL_CALL TitleWrapper::getPropertyState( const OUString& rPropertyName ) 382 { 383 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE ); 384 385 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 386 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 387 { 388 Reference< beans::XPropertyState > xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY ); 389 if( xPropState.is() ) 390 { 391 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 392 if( pWrappedProperty ) 393 aState = pWrappedProperty->getPropertyState( xPropState ); 394 else 395 aState = xPropState->getPropertyState( rPropertyName ); 396 } 397 } 398 else 399 aState = WrappedPropertySet::getPropertyState( rPropertyName ); 400 401 return aState; 402 } 403 void SAL_CALL TitleWrapper::setPropertyToDefault( const OUString& rPropertyName ) 404 { 405 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 406 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 407 { 408 Any aDefault = getPropertyDefault( rPropertyName ); 409 setFastCharacterPropertyValue( nHandle, aDefault ); 410 } 411 else 412 WrappedPropertySet::setPropertyToDefault( rPropertyName ); 413 } 414 Any SAL_CALL TitleWrapper::getPropertyDefault( const OUString& rPropertyName ) 415 { 416 Any aRet; 417 418 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 419 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 420 { 421 Reference< beans::XPropertyState > xPropState( getFirstCharacterPropertySet(), uno::UNO_QUERY ); 422 if( xPropState.is() ) 423 { 424 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName ); 425 if( pWrappedProperty ) 426 aRet = pWrappedProperty->getPropertyDefault(xPropState); 427 else 428 aRet = xPropState->getPropertyDefault( rPropertyName ); 429 } 430 } 431 else 432 aRet = WrappedPropertySet::getPropertyDefault( rPropertyName ); 433 434 return aRet; 435 } 436 437 void SAL_CALL TitleWrapper::addPropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener ) 438 { 439 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 440 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 441 { 442 Reference< beans::XPropertySet > xPropSet( getFirstCharacterPropertySet(), uno::UNO_QUERY ); 443 if( xPropSet.is() ) 444 xPropSet->addPropertyChangeListener( rPropertyName, xListener ); 445 } 446 else 447 WrappedPropertySet::addPropertyChangeListener( rPropertyName, xListener ); 448 } 449 void SAL_CALL TitleWrapper::removePropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener ) 450 { 451 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName ); 452 if( CharacterProperties::IsCharacterPropertyHandle( nHandle ) ) 453 { 454 Reference< beans::XPropertySet > xPropSet( getFirstCharacterPropertySet(), uno::UNO_QUERY ); 455 if( xPropSet.is() ) 456 xPropSet->removePropertyChangeListener( rPropertyName, xListener ); 457 } 458 else 459 WrappedPropertySet::removePropertyChangeListener( rPropertyName, xListener ); 460 } 461 462 // ================================================================================ 463 464 //ReferenceSizePropertyProvider 465 void TitleWrapper::updateReferenceSize() 466 { 467 Reference< beans::XPropertySet > xProp( this->getTitleObject(), uno::UNO_QUERY ); 468 if( xProp.is() ) 469 { 470 if( xProp->getPropertyValue( C2U("ReferencePageSize") ).hasValue() ) 471 xProp->setPropertyValue( C2U("ReferencePageSize"), uno::makeAny( 472 m_spChart2ModelContact->GetPageSize() )); 473 } 474 } 475 Any TitleWrapper::getReferenceSize() 476 { 477 Any aRet; 478 Reference< beans::XPropertySet > xProp( this->getTitleObject(), uno::UNO_QUERY ); 479 if( xProp.is() ) 480 aRet = xProp->getPropertyValue( C2U("ReferencePageSize") ); 481 482 return aRet; 483 } 484 awt::Size TitleWrapper::getCurrentSizeForReference() 485 { 486 return m_spChart2ModelContact->GetPageSize(); 487 } 488 489 // ================================================================================ 490 491 Reference< chart2::XTitle > TitleWrapper::getTitleObject() 492 { 493 return TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ); 494 } 495 496 // WrappedPropertySet 497 498 Reference< beans::XPropertySet > TitleWrapper::getInnerPropertySet() 499 { 500 return Reference< beans::XPropertySet >( this->getTitleObject(), uno::UNO_QUERY ); 501 } 502 503 const Sequence< beans::Property >& TitleWrapper::getPropertySequence() 504 { 505 return *StaticTitleWrapperPropertyArray::get(); 506 } 507 508 const std::vector< WrappedProperty* > TitleWrapper::createWrappedProperties() 509 { 510 ::std::vector< ::chart::WrappedProperty* > aWrappedProperties; 511 512 aWrappedProperties.push_back( new WrappedTitleStringProperty( m_spChart2ModelContact->m_xContext ) ); 513 aWrappedProperties.push_back( new WrappedTextRotationProperty( m_eTitleType==TitleHelper::Y_AXIS_TITLE || m_eTitleType==TitleHelper::X_AXIS_TITLE ) ); 514 aWrappedProperties.push_back( new WrappedStackedTextProperty() ); 515 WrappedCharacterHeightProperty::addWrappedProperties( aWrappedProperties, this ); 516 WrappedAutomaticPositionProperties::addWrappedProperties( aWrappedProperties ); 517 WrappedScaleTextProperties::addWrappedProperties( aWrappedProperties, m_spChart2ModelContact ); 518 519 return aWrappedProperties; 520 } 521 522 // ================================================================================ 523 524 Sequence< OUString > TitleWrapper::getSupportedServiceNames_Static() 525 { 526 Sequence< OUString > aServices( 4 ); 527 aServices[ 0 ] = C2U( "com.sun.star.chart.ChartTitle" ); 528 aServices[ 1 ] = C2U( "com.sun.star.drawing.Shape" ); 529 aServices[ 2 ] = C2U( "com.sun.star.xml.UserDefinedAttributeSupplier" ); 530 aServices[ 3 ] = C2U( "com.sun.star.style.CharacterProperties" ); 531 // aServices[ 4 ] = C2U( "com.sun.star.beans.PropertySet" ); 532 // aServices[ 5 ] = C2U( "com.sun.star.drawing.FillProperties" ); 533 // aServices[ 6 ] = C2U( "com.sun.star.drawing.LineProperties" ); 534 535 return aServices; 536 } 537 538 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static 539 APPHELPER_XSERVICEINFO_IMPL( TitleWrapper, lcl_aServiceName ); 540 541 } // namespace wrapper 542 } // namespace chart 543