| 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 "WrappedNumberFormatProperty.hxx" |
| 21 |
#include "Chart2ModelContact.hxx" |
| 22 |
#include <Axis.hxx> |
| 23 |
#include <DataSeries.hxx> |
| 24 |
#include <com/sun/star/chart2/XDataSeries.hpp> |
| 25 |
#include <unonames.hxx> |
| 26 |
#include <utility> |
| 27 |
#include <osl/diagnose.h> |
| 28 |
|
| 29 |
using namespace ::com::sun::star; |
| 30 |
using ::com::sun::star::uno::Reference; |
| 31 |
using ::com::sun::star::uno::Any; |
| 32 |
|
| 33 |
namespace chart::wrapper |
| 34 |
{ |
| 35 |
|
| 36 |
WrappedNumberFormatProperty::WrappedNumberFormatProperty(std::shared_ptr<Chart2ModelContact> spChart2ModelContact) |
| 37 |
: WrappedDirectStateProperty( CHART_UNONAME_NUMFMT, CHART_UNONAME_NUMFMT ) |
| 38 |
, m_spChart2ModelContact(std::move(spChart2ModelContact)) |
| 39 |
{ |
| 40 |
} |
| 41 |
|
| 42 |
WrappedNumberFormatProperty::~WrappedNumberFormatProperty() |
| 43 |
{ |
| 44 |
} |
| 45 |
|
| 46 |
void WrappedNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 47 |
{ |
| 48 |
sal_Int32 nFormat = 0; |
| 49 |
if( ! (rOuterValue >>= nFormat) ) |
| 50 |
throw lang::IllegalArgumentException( u"Property 'NumberFormat' requires value of type sal_Int32"_ustr, nullptr, 0 ); |
| 51 |
|
| 52 |
if(xInnerPropertySet.is()) |
| 53 |
xInnerPropertySet->setPropertyValue(getInnerName(), convertOuterToInnerValue(rOuterValue)); |
| 54 |
} |
| 55 |
|
| 56 |
Any WrappedNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 57 |
{ |
| 58 |
if( !xInnerPropertySet.is() ) |
| 59 |
{ |
| 60 |
OSL_FAIL("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue"); |
| 61 |
return Any(); |
| 62 |
} |
| 63 |
Any aRet( xInnerPropertySet->getPropertyValue(getInnerName())); |
| 64 |
if( !aRet.hasValue() ) |
| 65 |
{ |
| 66 |
sal_Int32 nKey = 0; |
| 67 |
Reference< chart2::XDataSeries > xSeries( xInnerPropertySet, uno::UNO_QUERY ); |
| 68 |
if( ::chart::DataSeries* pDataSeries = dynamic_cast<DataSeries*>(xSeries.get()) ) |
| 69 |
nKey = pDataSeries->getExplicitNumberFormatKeyForDataLabel(); |
| 70 |
else |
| 71 |
{ |
| 72 |
rtl::Reference< Axis > xAxis = dynamic_cast<Axis*>(xInnerPropertySet.get()); |
| 73 |
assert(xAxis || !xInnerPropertySet); |
| 74 |
nKey = m_spChart2ModelContact->getExplicitNumberFormatKeyForAxis( xAxis ); |
| 75 |
} |
| 76 |
aRet <<= nKey; |
| 77 |
} |
| 78 |
return aRet; |
| 79 |
} |
| 80 |
|
| 81 |
Any WrappedNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const |
| 82 |
{ |
| 83 |
return uno::Any( sal_Int32( 0 ) ); |
| 84 |
} |
| 85 |
|
| 86 |
WrappedLinkNumberFormatProperty::WrappedLinkNumberFormatProperty() : |
| 87 |
WrappedDirectStateProperty(CHART_UNONAME_LINK_TO_SRC_NUMFMT, CHART_UNONAME_LINK_TO_SRC_NUMFMT) |
| 88 |
{ |
| 89 |
} |
| 90 |
|
| 91 |
WrappedLinkNumberFormatProperty::~WrappedLinkNumberFormatProperty() |
| 92 |
{ |
| 93 |
} |
| 94 |
|
| 95 |
void WrappedLinkNumberFormatProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 96 |
{ |
| 97 |
if( !xInnerPropertySet.is() ) |
| 98 |
{ |
| 99 |
OSL_FAIL("missing xInnerPropertySet in WrappedNumberFormatProperty::setPropertyValue"); |
| 100 |
return; |
| 101 |
} |
| 102 |
|
| 103 |
xInnerPropertySet->setPropertyValue(getInnerName(), rOuterValue); |
| 104 |
} |
| 105 |
|
| 106 |
Any WrappedLinkNumberFormatProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const |
| 107 |
{ |
| 108 |
if( !xInnerPropertySet.is() ) |
| 109 |
{ |
| 110 |
OSL_FAIL("missing xInnerPropertySet in WrappedNumberFormatProperty::getPropertyValue"); |
| 111 |
return getPropertyDefault(nullptr); |
| 112 |
} |
| 113 |
|
| 114 |
return xInnerPropertySet->getPropertyValue(getInnerName()); |
| 115 |
} |
| 116 |
|
| 117 |
Any WrappedLinkNumberFormatProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const |
| 118 |
{ |
| 119 |
return uno::Any( true ); // bLink |
| 120 |
} |
| 121 |
|
| 122 |
} //namespace chart::wrapper |
| 123 |
|
| 124 |
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |