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