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 27 #include "WrappedAxisAndGridExistenceProperties.hxx" 28 #include "AxisHelper.hxx" 29 #include "ChartModelHelper.hxx" 30 #include "TitleHelper.hxx" 31 #include "macros.hxx" 32 33 using namespace ::com::sun::star; 34 using ::com::sun::star::uno::Any; 35 using ::com::sun::star::uno::Reference; 36 using ::com::sun::star::uno::Sequence; 37 using ::rtl::OUString; 38 39 //............................................................................. 40 namespace chart 41 { 42 namespace wrapper 43 { 44 45 class WrappedAxisAndGridExistenceProperty : public WrappedProperty 46 { 47 public: 48 WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex 49 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 50 virtual ~WrappedAxisAndGridExistenceProperty(); 51 52 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 53 54 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 55 56 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const; 57 58 private: //member 59 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 60 bool m_bAxis; 61 bool m_bMain; 62 sal_Int32 m_nDimensionIndex; 63 }; 64 65 void WrappedAxisAndGridExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 66 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 67 { 68 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 0, spChart2ModelContact ) );//x axis 69 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 0, spChart2ModelContact ) );//x secondary axis 70 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 0, spChart2ModelContact ) );//x grid 71 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 0, spChart2ModelContact ) );//x help grid 72 73 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 1, spChart2ModelContact ) );//y axis 74 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, false, 1, spChart2ModelContact ) );//y secondary axis 75 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 1, spChart2ModelContact ) );//y grid 76 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 1, spChart2ModelContact ) );//y help grid 77 78 rList.push_back( new WrappedAxisAndGridExistenceProperty( true, true, 2, spChart2ModelContact ) );//z axis 79 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, true, 2, spChart2ModelContact ) );//z grid 80 rList.push_back( new WrappedAxisAndGridExistenceProperty( false, false, 2, spChart2ModelContact ) );//z help grid 81 } 82 83 WrappedAxisAndGridExistenceProperty::WrappedAxisAndGridExistenceProperty( bool bAxis, bool bMain, sal_Int32 nDimensionIndex 84 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 85 : WrappedProperty(OUString(),OUString()) 86 , m_spChart2ModelContact( spChart2ModelContact ) 87 , m_bAxis( bAxis ) 88 , m_bMain( bMain ) 89 , m_nDimensionIndex( nDimensionIndex ) 90 { 91 switch( m_nDimensionIndex ) 92 { 93 case 0: 94 { 95 if( m_bAxis ) 96 { 97 if( m_bMain ) 98 m_aOuterName = C2U( "HasXAxis" ); 99 else 100 m_aOuterName = C2U( "HasSecondaryXAxis" ); 101 } 102 else 103 { 104 if( m_bMain ) 105 m_aOuterName = C2U( "HasXAxisGrid" ); 106 else 107 m_aOuterName = C2U( "HasXAxisHelpGrid" ); 108 } 109 } 110 break; 111 case 2: 112 { 113 if( m_bAxis ) 114 { 115 OSL_ENSURE(m_bMain == true,"there is no secondary z axis at the old api"); 116 m_bMain = true; 117 m_aOuterName = C2U( "HasZAxis" ); 118 } 119 else 120 { 121 if( m_bMain ) 122 m_aOuterName = C2U( "HasZAxisGrid" ); 123 else 124 m_aOuterName = C2U( "HasZAxisHelpGrid" ); 125 } 126 } 127 break; 128 default: 129 { 130 if( m_bAxis ) 131 { 132 if( m_bMain ) 133 m_aOuterName = C2U( "HasYAxis" ); 134 else 135 m_aOuterName = C2U( "HasSecondaryYAxis" ); 136 } 137 else 138 { 139 if( m_bMain ) 140 m_aOuterName = C2U( "HasYAxisGrid" ); 141 else 142 m_aOuterName = C2U( "HasYAxisHelpGrid" ); 143 } 144 } 145 break; 146 } 147 } 148 149 WrappedAxisAndGridExistenceProperty::~WrappedAxisAndGridExistenceProperty() 150 { 151 } 152 153 void WrappedAxisAndGridExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 154 { 155 sal_Bool bNewValue = false; 156 if( ! (rOuterValue >>= bNewValue) ) 157 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 158 159 sal_Bool bOldValue = sal_False; 160 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 161 162 if( bOldValue == bNewValue ) 163 return; 164 165 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 166 if( bNewValue ) 167 { 168 if( m_bAxis ) 169 AxisHelper::showAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ); 170 else 171 AxisHelper::showGrid( m_nDimensionIndex, 0, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ); 172 } 173 else 174 { 175 if( m_bAxis ) 176 AxisHelper::hideAxis( m_nDimensionIndex, m_bMain, xDiagram ); 177 else 178 AxisHelper::hideGrid( m_nDimensionIndex, 0, m_bMain, xDiagram ); 179 } 180 } 181 182 Any WrappedAxisAndGridExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /* xInnerPropertySet */ ) const 183 { 184 Any aRet; 185 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 186 if(m_bAxis) 187 { 188 sal_Bool bShown = AxisHelper::isAxisShown( m_nDimensionIndex, m_bMain, xDiagram ); 189 aRet <<= bShown; 190 } 191 else 192 { 193 sal_Bool bShown = AxisHelper::isGridShown( m_nDimensionIndex, 0, m_bMain, xDiagram ); 194 aRet <<= bShown; 195 } 196 return aRet; 197 } 198 199 Any WrappedAxisAndGridExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 200 { 201 Any aRet; 202 aRet <<= false; 203 return aRet; 204 } 205 206 //--------------------------------------------------------------------------------------------------------------- 207 //--------------------------------------------------------------------------------------------------------------- 208 //--------------------------------------------------------------------------------------------------------------- 209 210 class WrappedAxisTitleExistenceProperty : public WrappedProperty 211 { 212 public: 213 WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex 214 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 215 virtual ~WrappedAxisTitleExistenceProperty(); 216 217 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 218 219 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 220 221 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const; 222 223 private: //member 224 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 225 TitleHelper::eTitleType m_eTitleType; 226 }; 227 228 void WrappedAxisTitleExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 229 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 230 { 231 rList.push_back( new WrappedAxisTitleExistenceProperty( 0, spChart2ModelContact ) );//x axis title 232 rList.push_back( new WrappedAxisTitleExistenceProperty( 1, spChart2ModelContact ) );//y axis title 233 rList.push_back( new WrappedAxisTitleExistenceProperty( 2, spChart2ModelContact ) );//z axis title 234 rList.push_back( new WrappedAxisTitleExistenceProperty( 3, spChart2ModelContact ) );//secondary x axis title 235 rList.push_back( new WrappedAxisTitleExistenceProperty( 4, spChart2ModelContact ) );//secondary y axis title 236 } 237 238 WrappedAxisTitleExistenceProperty::WrappedAxisTitleExistenceProperty( sal_Int32 nTitleIndex 239 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 240 : WrappedProperty(OUString(),OUString()) 241 , m_spChart2ModelContact( spChart2ModelContact ) 242 , m_eTitleType( TitleHelper::Y_AXIS_TITLE ) 243 { 244 switch( nTitleIndex ) 245 { 246 case 0: 247 m_aOuterName = C2U( "HasXAxisTitle" ); 248 m_eTitleType = TitleHelper::X_AXIS_TITLE; 249 break; 250 case 2: 251 m_aOuterName = C2U( "HasZAxisTitle" ); 252 m_eTitleType = TitleHelper::Z_AXIS_TITLE; 253 break; 254 case 3: 255 m_aOuterName = C2U( "HasSecondaryXAxisTitle" ); 256 m_eTitleType = TitleHelper::SECONDARY_X_AXIS_TITLE; 257 break; 258 case 4: 259 m_aOuterName = C2U( "HasSecondaryYAxisTitle" ); 260 m_eTitleType = TitleHelper::SECONDARY_Y_AXIS_TITLE; 261 break; 262 default: 263 m_aOuterName = C2U( "HasYAxisTitle" ); 264 m_eTitleType = TitleHelper::Y_AXIS_TITLE; 265 break; 266 } 267 } 268 269 WrappedAxisTitleExistenceProperty::~WrappedAxisTitleExistenceProperty() 270 { 271 } 272 273 void WrappedAxisTitleExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 274 { 275 sal_Bool bNewValue = false; 276 if( ! (rOuterValue >>= bNewValue) ) 277 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 278 279 sal_Bool bOldValue = sal_False; 280 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 281 282 if( bOldValue == bNewValue ) 283 return; 284 285 if( bNewValue ) 286 { 287 rtl::OUString aTitleText; 288 TitleHelper::createTitle( m_eTitleType, aTitleText 289 , m_spChart2ModelContact->getChartModel(), m_spChart2ModelContact->m_xContext ); 290 } 291 else 292 { 293 TitleHelper::removeTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ); 294 } 295 } 296 297 Any WrappedAxisTitleExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const 298 { 299 sal_Bool bHasTitle = sal_False; 300 301 Reference< chart2::XTitle > xTitle( TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getChartModel() ) ); 302 if( xTitle.is() && (TitleHelper::getCompleteString( xTitle ).isEmpty() == false) ) 303 bHasTitle = sal_True; 304 305 Any aRet; 306 aRet <<= bHasTitle; 307 return aRet; 308 309 } 310 311 Any WrappedAxisTitleExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 312 { 313 Any aRet; 314 aRet <<= sal_Bool( sal_False ); 315 return aRet; 316 } 317 318 //--------------------------------------------------------------------------------------------------------------- 319 //--------------------------------------------------------------------------------------------------------------- 320 //--------------------------------------------------------------------------------------------------------------- 321 322 class WrappedAxisLabelExistenceProperty : public WrappedProperty 323 { 324 public: 325 WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex 326 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ); 327 virtual ~WrappedAxisLabelExistenceProperty(); 328 329 virtual void setPropertyValue( const ::com::sun::star::uno::Any& rOuterValue, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 330 331 virtual ::com::sun::star::uno::Any getPropertyValue( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet >& xInnerPropertySet ) const; 332 333 virtual ::com::sun::star::uno::Any getPropertyDefault( const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyState >& xInnerPropertyState ) const; 334 335 private: //member 336 ::boost::shared_ptr< Chart2ModelContact > m_spChart2ModelContact; 337 bool m_bMain; 338 sal_Int32 m_nDimensionIndex; 339 }; 340 341 void WrappedAxisLabelExistenceProperties::addWrappedProperties( std::vector< WrappedProperty* >& rList 342 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 343 { 344 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 0, spChart2ModelContact ) );//x axis 345 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 1, spChart2ModelContact ) );//y axis 346 rList.push_back( new WrappedAxisLabelExistenceProperty( true, 2, spChart2ModelContact ) );//z axis 347 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 0, spChart2ModelContact ) );//secondary x axis 348 rList.push_back( new WrappedAxisLabelExistenceProperty( false, 1, spChart2ModelContact ) );//secondary y axis 349 } 350 351 WrappedAxisLabelExistenceProperty::WrappedAxisLabelExistenceProperty( bool bMain, sal_Int32 nDimensionIndex 352 , ::boost::shared_ptr< Chart2ModelContact > spChart2ModelContact ) 353 : WrappedProperty(OUString(),OUString()) 354 , m_spChart2ModelContact( spChart2ModelContact ) 355 , m_bMain( bMain ) 356 , m_nDimensionIndex( nDimensionIndex ) 357 { 358 switch( m_nDimensionIndex ) 359 { 360 case 0: 361 m_aOuterName = m_bMain ? C2U( "HasXAxisDescription" ) : C2U( "HasSecondaryXAxisDescription" ); 362 break; 363 case 2: 364 OSL_ENSURE(m_bMain,"there is no description available for a secondary z axis"); 365 m_aOuterName = C2U( "HasZAxisDescription" ); 366 break; 367 default: 368 m_aOuterName = m_bMain ? C2U( "HasYAxisDescription" ) : C2U( "HasSecondaryYAxisDescription" ); 369 break; 370 } 371 } 372 373 WrappedAxisLabelExistenceProperty::~WrappedAxisLabelExistenceProperty() 374 { 375 } 376 377 void WrappedAxisLabelExistenceProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const 378 { 379 sal_Bool bNewValue = false; 380 if( ! (rOuterValue >>= bNewValue) ) 381 throw lang::IllegalArgumentException( C2U("Has axis or grid properties require boolean values"), 0, 0 ); 382 383 sal_Bool bOldValue = sal_False; 384 getPropertyValue( xInnerPropertySet ) >>= bOldValue; 385 386 if( bOldValue == bNewValue ) 387 return; 388 389 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 390 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY ); 391 if( !xProp.is() && bNewValue ) 392 { 393 //create axis if needed 394 xProp.set( AxisHelper::createAxis( m_nDimensionIndex, m_bMain, xDiagram, m_spChart2ModelContact->m_xContext ), uno::UNO_QUERY ); 395 if( xProp.is() ) 396 xProp->setPropertyValue( C2U( "Show" ), uno::makeAny( sal_False ) ); 397 } 398 if( xProp.is() ) 399 xProp->setPropertyValue( C2U( "DisplayLabels" ), rOuterValue ); 400 } 401 402 Any WrappedAxisLabelExistenceProperty::getPropertyValue( const Reference< beans::XPropertySet >& /*xInnerPropertySet*/ ) const 403 { 404 Any aRet; 405 Reference< chart2::XDiagram > xDiagram( m_spChart2ModelContact->getChart2Diagram() ); 406 Reference< beans::XPropertySet > xProp( AxisHelper::getAxis( m_nDimensionIndex, m_bMain, xDiagram ), uno::UNO_QUERY ); 407 if( xProp.is() ) 408 aRet = xProp->getPropertyValue( C2U( "DisplayLabels" )); 409 else 410 aRet <<= sal_False; 411 return aRet; 412 } 413 414 Any WrappedAxisLabelExistenceProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const 415 { 416 Any aRet; 417 aRet <<= sal_Bool( sal_True ); 418 return aRet; 419 } 420 421 } //namespace wrapper 422 } //namespace chart 423 //............................................................................. 424