1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_chart2.hxx" 30 31 #include "WrappedAxisAndGridExistenceProperties.hxx" 32 #include "AxisHelper.hxx" 33 #include "ChartModelHelper.hxx" 34 #include "TitleHelper.hxx" 35 #include "macros.hxx" 36 37 using namespace ::com::sun::star; 38 using ::com::sun::star::uno::Any; 39 using ::com::sun::star::uno::Reference; 40 using ::com::sun::star::uno::Sequence; 41 using ::rtl::OUString; 42 43 //............................................................................. 44 namespace chart 45 { 46 namespace wrapper 47 { 48 49 class WrappedAxisAndGridExistenceProperty : public WrappedProperty 50 { 51 public: 52 WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex 53 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 54 virtual ~WrappedAxisAndGridExistenceProperty(); 55 56 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 57 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 58 59 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 60 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 61 62 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const 63 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 64 65 private: //member 66 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 67 bool m_bAxis; 68 bool m_bMain; 69 sal_Int32 m_nDimensionIndex; 70 }; 71 72 void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 73 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 74 { 75 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis 76 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis 77 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid 78 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid 79 80 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis 81 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis 82 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid 83 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid 84 85 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis 86 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid 87 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid 88 } 89 90 WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex 91 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 92 : WrappedProperty(OUString(),OUString()) 93 , m_spChart2ModelContact( spChart2ModelContact ) 94 , m_bAxis( bAxis ) 95 , m_bMain( bMain ) 96 , m_nDimensionIndex( nDimensionIndex ) 97 { 98 switch( m_nDimensionIndex ) 99 { 100 case 0: 101 { 102 if( m_bAxis ) 103 { 104 if( m_bMain ) 105 m_aOuterName = C2U( "HasXAxis" ); 106 else 107 m_aOuterName = C2U( "HasSecondaryXAxis" ); 108 } 109 else 110 { 111 if( m_bMain ) 112 m_aOuterName = C2U( "HasXAxisGrid" ); 113 else 114 m_aOuterName = C2U( "HasXAxisHelpGrid" ); 115 } 116 } 117 break; 118 case 2: 119 { 120 if( m_bAxis ) 121 { 122 OSL_ENSURE(m_bMain == true,"there is no secondary z axis at the old api"); 123 m_bMain = true; 124 m_aOuterName = C2U( "HasZAxis" ); 125 } 126 else 127 { 128 if( m_bMain ) 129 m_aOuterName = C2U( "HasZAxisGrid" ); 130 else 131 m_aOuterName = C2U( "HasZAxisHelpGrid" ); 132 } 133 } 134 break; 135 default: 136 { 137 if( m_bAxis ) 138 { 139 if( m_bMain ) 140 m_aOuterName = C2U( "HasYAxis" ); 141 else 142 m_aOuterName = C2U( "HasSecondaryYAxis" ); 143 } 144 else 145 { 146 if( m_bMain ) 147 m_aOuterName = C2U( "HasYAxisGrid" ); 148 else 149 m_aOuterName = C2U( "HasYAxisHelpGrid" ); 150 } 151 } 152 break; 153 } 154 } 155 156 WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty() 157 { 158 } 159 160 void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 161 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 162 { 163 sal_Bool bNewValue = false; 164 if( ! (rOuterValue >>= bNewValue) ) 165 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 166 167 sal_Bool bOldValue = sal_False; 168 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 169 170 if( bOldValue == bNewValue ) 171 return; 172 173 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 174 if( bNewValue ) 175 { 176 if( m_bAxis ) 177 AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ); 178 else 179 AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ); 180 } 181 else 182 { 183 if( m_bAxis ) 184 AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram ); 185 else 186 AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram ); 187 } 188 } 189 190 Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const 191 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 192 { 193 Any aRet; 194 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 195 if(m_bAxis) 196 { 197 sal_Bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram ); 198 aRet <<= bShown; 199 } 200 else 201 { 202 sal_Bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram ); 203 aRet <<= bShown; 204 } 205 return aRet; 206 } 207 208 Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 209 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 210 { 211 Any aRet; 212 aRet <<= false; 213 return aRet; 214 } 215 216 //--------------------------------------------------------------------------------------------------------------- 217 //--------------------------------------------------------------------------------------------------------------- 218 //--------------------------------------------------------------------------------------------------------------- 219 220 class WrappedAxisTitleExistenceProperty : public WrappedProperty 221 { 222 public: 223 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex 224 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 225 virtual ~WrappedAxisTitleExistenceProperty(); 226 227 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 228 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 229 230 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 231 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 232 233 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const 234 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 235 236 private: //member 237 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 238 TitleHelper::eTitleType m_eTitleType; 239 }; 240 241 void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 242 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 243 { 244 rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title 245 rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title 246 rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title 247 rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title 248 rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title 249 } 250 251 WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex 252 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 253 : WrappedProperty(OUString(),OUString()) 254 , m_spChart2ModelContact( spChart2ModelContact ) 255 , m_eTitleType( TitleHelper::Y_AXIS_TITLE ) 256 { 257 switch( nTitleIndex ) 258 { 259 case 0: 260 m_aOuterName = C2U( "HasXAxisTitle" ); 261 m_eTitleType = TitleHelper::X_AXIS_TITLE; 262 break; 263 case 2: 264 m_aOuterName = C2U( "HasZAxisTitle" ); 265 m_eTitleType = TitleHelper::Z_AXIS_TITLE; 266 break; 267 case 3: 268 m_aOuterName = C2U( "HasSecondaryXAxisTitle" ); 269 m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE; 270 break; 271 case 4: 272 m_aOuterName = C2U( "HasSecondaryYAxisTitle" ); 273 m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE; 274 break; 275 default: 276 m_aOuterName = C2U( "HasYAxisTitle" ); 277 m_eTitleType = TitleHelper::Y_AXIS_TITLE; 278 break; 279 } 280 } 281 282 WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty() 283 { 284 } 285 286 void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 287 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 288 { 289 sal_Bool bNewValue = false; 290 if( ! (rOuterValue >>= bNewValue) ) 291 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 292 293 sal_Bool bOldValue = sal_False; 294 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 295 296 if( bOldValue == bNewValue ) 297 return; 298 299 if( bNewValue ) 300 { 301 rtl::OUString aTitleText; 302 TitleHelper::createTitle( m_eTitleType, aTitleText 303 , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext ); 304 } 305 else 306 { 307 TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ); 308 } 309 } 310 311 Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const 312 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 313 { 314 sal_Bool bHasTitle = sal_False; 315 316 Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) ); 317 if( xTitle.is() && (TitleHelper::getCompleteString( xTitle ).getLength() != 0) ) 318 bHasTitle = sal_True; 319 320 Any aRet; 321 aRet <<= bHasTitle; 322 return aRet; 323 324 } 325 326 Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 327 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 328 { 329 Any aRet; 330 aRet <<= sal_Bool( sal_False ); 331 return aRet; 332 } 333 334 //--------------------------------------------------------------------------------------------------------------- 335 //--------------------------------------------------------------------------------------------------------------- 336 //--------------------------------------------------------------------------------------------------------------- 337 338 class WrappedAxisLabelExistenceProperty : public WrappedProperty 339 { 340 public: 341 WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex 342 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 343 virtual ~WrappedAxisLabelExistenceProperty(); 344 345 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 346 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 347 348 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const 349 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 350 351 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const 352 throw (::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException); 353 354 private: //member 355 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 356 bool m_bMain; 357 sal_Int32 m_nDimensionIndex; 358 }; 359 360 void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 361 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 362 { 363 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis 364 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis 365 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis 366 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis 367 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis 368 } 369 370 WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex 371 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 372 : WrappedProperty(OUString(),OUString()) 373 , m_spChart2ModelContact( spChart2ModelContact ) 374 , m_bMain( bMain ) 375 , m_nDimensionIndex( nDimensionIndex ) 376 { 377 switch( m_nDimensionIndex ) 378 { 379 case 0: 380 m_aOuterName = m_bMain ? C2U( "HasXAxisDescription" ) : C2U( "HasSecondaryXAxisDescription" ); 381 break; 382 case 2: 383 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis"); 384 m_aOuterName = C2U( "HasZAxisDescription" ); 385 break; 386 default: 387 m_aOuterName = m_bMain ? C2U( "HasYAxisDescription" ) : C2U( "HasSecondaryYAxisDescription" ); 388 break; 389 } 390 } 391 392 WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty() 393 { 394 } 395 396 void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 397 throw (beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException, lang::WrappedTargetException, uno::RuntimeException) 398 { 399 sal_Bool bNewValue = false; 400 if( ! (rOuterValue >>= bNewValue) ) 401 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 402 403 sal_Bool bOldValue = sal_False; 404 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 405 406 if( bOldValue == bNewValue ) 407 return; 408 409 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 410 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY ); 411 if( !xProp.is() && bNewValue ) 412 { 413 //create axis if needed 414 xProp.set( AxisHelper::createAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ), uno::UNO_QUERY ); 415 if( xProp.is() ) 416 xProp->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) ); 417 } 418 if( xProp.is() ) 419 xProp->setPropertyValue( C2U( "DisplayLabels" ), rOuterValue ); 420 } 421 422 Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const 423 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 424 { 425 Any aRet; 426 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 427 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY ); 428 if( xProp.is() ) 429 aRet = xProp->getPropertyValue( C2U( "DisplayLabels" )); 430 else 431 aRet <<= sal_False; 432 return aRet; 433 } 434 435 Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 436 throw (beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException) 437 { 438 Any aRet; 439 aRet <<= sal_Bool( sal_True ); 440 return aRet; 441 } 442 443 } //namespace wrapper 444 } //namespace chart 445 //............................................................................. 446