1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include "WrappedSplineProperties.hxx"
21 #include "Chart2ModelContact.hxx"
22 #include <FastPropertyIdRanges.hxx>
23 #include <ChartType.hxx>
24 #include <WrappedProperty.hxx>
25 #include <unonames.hxx>
27 #include <sal/log.hxx>
29 #include <com/sun/star/chart2/CurveStyle.hpp>
30 #include <com/sun/star/beans/PropertyAttribute.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
34 using namespace ::com::sun::star
;
35 using ::com::sun::star::uno::Any
;
36 using ::com::sun::star::beans::Property
;
38 namespace chart::wrapper
44 //PROPERTYTYPE is the type of the outer property
46 template< typename PROPERTYTYPE
>
47 class WrappedSplineProperty
: public WrappedProperty
50 explicit WrappedSplineProperty( const OUString
& rOuterName
, OUString aInnerName
51 , const css::uno::Any
& rDefaulValue
52 , std::shared_ptr
<Chart2ModelContact
> spChart2ModelContact
)
53 : WrappedProperty(rOuterName
,OUString())
54 , m_spChart2ModelContact(std::move(spChart2ModelContact
))
55 , m_aOuterValue(rDefaulValue
)
56 , m_aDefaultValue(rDefaulValue
)
57 , m_aOwnInnerName(std::move(aInnerName
))
61 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
63 rHasAmbiguousValue
= false;
64 rtl::Reference
<Diagram
> xDiagram
= m_spChart2ModelContact
->getDiagram();
67 bool bHasDetectableInnerValue
= false;
68 std::vector
< rtl::Reference
< ChartType
> > aChartTypes
= xDiagram
->getChartTypes();
69 for( sal_Int32 nN
= aChartTypes
.size(); nN
--; )
73 Any aSingleValue
= convertInnerToOuterValue( aChartTypes
[nN
]->getPropertyValue(m_aOwnInnerName
) );
74 PROPERTYTYPE aCurValue
= PROPERTYTYPE();
75 aSingleValue
>>= aCurValue
;
76 if( !bHasDetectableInnerValue
)
80 if( rValue
!= aCurValue
)
82 rHasAmbiguousValue
= true;
88 bHasDetectableInnerValue
= true;
90 catch( uno::Exception
& ex
)
92 //spline properties are not supported by all charttypes
93 //in that cases this exception is ok
94 ex
.Context
.is();//to have debug information without compilation warnings
97 return bHasDetectableInnerValue
;
99 void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const override
101 PROPERTYTYPE aNewValue
;
102 if( ! (rOuterValue
>>= aNewValue
) )
103 throw css::lang::IllegalArgumentException( u
"spline property requires different type"_ustr
, nullptr, 0 );
105 m_aOuterValue
= rOuterValue
;
107 bool bHasAmbiguousValue
= false;
108 PROPERTYTYPE aOldValue
= PROPERTYTYPE();
109 if( !detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
112 if( !(bHasAmbiguousValue
|| aNewValue
!= aOldValue
) )
115 std::vector
< rtl::Reference
< ChartType
> > aChartTypes
=
116 m_spChart2ModelContact
->getDiagram()->getChartTypes();
117 for( sal_Int32 nN
= aChartTypes
.size(); nN
--; )
121 aChartTypes
[nN
]->setPropertyValue(m_aOwnInnerName
,convertOuterToInnerValue(uno::Any(aNewValue
)));
123 catch( uno::Exception
& ex
)
125 //spline properties are not supported by all charttypes
126 //in that cases this exception is ok
127 ex
.Context
.is();//to have debug information without compilation warnings
132 css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const override
134 bool bHasAmbiguousValue
= false;
136 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
138 m_aOuterValue
<<= aValue
;
140 return m_aOuterValue
;
143 css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& /*xInnerPropertyState*/ ) const override
145 return m_aDefaultValue
;
149 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
150 mutable css::uno::Any m_aOuterValue
;
151 css::uno::Any m_aDefaultValue
;
152 // this inner name is not set as inner name at the base class
153 const OUString m_aOwnInnerName
;
156 class WrappedSplineTypeProperty
: public WrappedSplineProperty
< sal_Int32
>
159 explicit WrappedSplineTypeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
);
161 virtual css::uno::Any
convertInnerToOuterValue( const css::uno::Any
& rInnerValue
) const override
;
162 virtual css::uno::Any
convertOuterToInnerValue( const css::uno::Any
& rOuterValue
) const override
;
168 PROP_CHART_SPLINE_TYPE
= FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
169 , PROP_CHART_SPLINE_ORDER
170 , PROP_CHART_SPLINE_RESOLUTION
173 }//anonymous namespace
175 void WrappedSplineProperties::addProperties( std::vector
< Property
> & rOutProperties
)
177 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_TYPE
,
178 PROP_CHART_SPLINE_TYPE
,
179 cppu::UnoType
<sal_Int32
>::get(),
180 beans::PropertyAttribute::BOUND
181 | beans::PropertyAttribute::MAYBEDEFAULT
182 | beans::PropertyAttribute::MAYBEVOID
);
183 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_ORDER
,
184 PROP_CHART_SPLINE_ORDER
,
185 cppu::UnoType
<sal_Int32
>::get(),
186 beans::PropertyAttribute::BOUND
187 | beans::PropertyAttribute::MAYBEDEFAULT
188 | beans::PropertyAttribute::MAYBEVOID
);
189 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_RESOLUTION
,
190 PROP_CHART_SPLINE_RESOLUTION
,
191 cppu::UnoType
<sal_Int32
>::get(),
192 beans::PropertyAttribute::BOUND
193 | beans::PropertyAttribute::MAYBEDEFAULT
194 | beans::PropertyAttribute::MAYBEVOID
);
197 void WrappedSplineProperties::addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
198 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
200 rList
.emplace_back( new WrappedSplineTypeProperty( spChart2ModelContact
) );
202 new WrappedSplineProperty
<sal_Int32
>(
203 CHART_UNONAME_SPLINE_ORDER
, CHART_UNONAME_SPLINE_ORDER
,
204 uno::Any(sal_Int32(3)), spChart2ModelContact
));
206 new WrappedSplineProperty
<sal_Int32
>(
207 CHART_UNONAME_SPLINE_RESOLUTION
, CHART_UNONAME_CURVE_RESOLUTION
,
208 uno::Any(sal_Int32(20)), spChart2ModelContact
));
211 WrappedSplineTypeProperty::WrappedSplineTypeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
212 : WrappedSplineProperty
<sal_Int32
>(CHART_UNONAME_SPLINE_TYPE
, CHART_UNONAME_CURVE_STYLE
, uno::Any(sal_Int32(0)), spChart2ModelContact
)
216 Any
WrappedSplineTypeProperty::convertInnerToOuterValue( const Any
& rInnerValue
) const
218 chart2::CurveStyle aInnerValue
= chart2::CurveStyle_LINES
;
219 rInnerValue
>>= aInnerValue
;
221 sal_Int32 nOuterValue
;
224 case chart2::CurveStyle_CUBIC_SPLINES
:
227 case chart2::CurveStyle_B_SPLINES
:
230 case chart2::CurveStyle_STEP_START
:
233 case chart2::CurveStyle_STEP_END
:
236 case chart2::CurveStyle_STEP_CENTER_X
:
239 case chart2::CurveStyle_STEP_CENTER_Y
:
246 return uno::Any(nOuterValue
);
248 Any
WrappedSplineTypeProperty::convertOuterToInnerValue( const Any
& rOuterValue
) const
250 sal_Int32 nOuterValue
=0;
251 rOuterValue
>>= nOuterValue
;
253 chart2::CurveStyle aInnerValue
;
258 aInnerValue
= chart2::CurveStyle_CUBIC_SPLINES
;
261 aInnerValue
= chart2::CurveStyle_B_SPLINES
;
264 aInnerValue
= chart2::CurveStyle_STEP_START
;
267 aInnerValue
= chart2::CurveStyle_STEP_END
;
270 aInnerValue
= chart2::CurveStyle_STEP_CENTER_X
;
273 aInnerValue
= chart2::CurveStyle_STEP_CENTER_Y
;
276 SAL_WARN_IF(nOuterValue
!= 0, "chart2", "Unknown line style");
277 aInnerValue
= chart2::CurveStyle_LINES
;
280 return uno::Any(aInnerValue
);
283 } //namespace chart::wrapper
285 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */