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 <DiagramHelper.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>
33 using namespace ::com::sun::star
;
34 using ::com::sun::star::uno::Any
;
35 using ::com::sun::star::uno::Sequence
;
36 using ::com::sun::star::beans::Property
;
43 //PROPERTYTYPE is the type of the outer property
45 template< typename PROPERTYTYPE
>
46 class WrappedSplineProperty
: public WrappedProperty
49 explicit WrappedSplineProperty( const OUString
& rOuterName
, const OUString
& rInnerName
50 , const css::uno::Any
& rDefaulValue
51 , const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
52 : WrappedProperty(rOuterName
,OUString())
53 , m_spChart2ModelContact(spChart2ModelContact
)
54 , m_aOuterValue(rDefaulValue
)
55 , m_aDefaultValue(rDefaulValue
)
56 , m_aOwnInnerName(rInnerName
)
60 bool detectInnerValue( PROPERTYTYPE
& rValue
, bool& rHasAmbiguousValue
) const
62 bool bHasDetectableInnerValue
= false;
63 rHasAmbiguousValue
= false;
64 Sequence
< css::uno::Reference
< css::chart2::XChartType
> > aChartTypes(
65 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
66 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
70 uno::Reference
<beans::XPropertySet
> xChartTypePropertySet(aChartTypes
[nN
], uno::UNO_QUERY
);
71 if (!xChartTypePropertySet
.is())
74 Any aSingleValue
= convertInnerToOuterValue( xChartTypePropertySet
->getPropertyValue(m_aOwnInnerName
) );
75 PROPERTYTYPE aCurValue
= PROPERTYTYPE();
76 aSingleValue
>>= aCurValue
;
77 if( !bHasDetectableInnerValue
)
81 if( rValue
!= aCurValue
)
83 rHasAmbiguousValue
= true;
89 bHasDetectableInnerValue
= true;
91 catch( uno::Exception
& ex
)
93 //spline properties are not supported by all charttypes
94 //in that cases this exception is ok
95 ex
.Context
.is();//to have debug information without compilation warnings
98 return bHasDetectableInnerValue
;
100 void setPropertyValue( const css::uno::Any
& rOuterValue
, const css::uno::Reference
< css::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const override
102 PROPERTYTYPE aNewValue
;
103 if( ! (rOuterValue
>>= aNewValue
) )
104 throw css::lang::IllegalArgumentException( "spline property requires different type", nullptr, 0 );
106 m_aOuterValue
= rOuterValue
;
108 bool bHasAmbiguousValue
= false;
109 PROPERTYTYPE aOldValue
= PROPERTYTYPE();
110 if( detectInnerValue( aOldValue
, bHasAmbiguousValue
) )
112 if( bHasAmbiguousValue
|| aNewValue
!= aOldValue
)
114 Sequence
< css::uno::Reference
< css::chart2::XChartType
> > aChartTypes(
115 ::chart::DiagramHelper::getChartTypesFromDiagram( m_spChart2ModelContact
->getChart2Diagram() ) );
116 for( sal_Int32 nN
= aChartTypes
.getLength(); nN
--; )
120 css::uno::Reference
< css::beans::XPropertySet
> xChartTypePropertySet( aChartTypes
[nN
], css::uno::UNO_QUERY
);
121 if( xChartTypePropertySet
.is() )
123 xChartTypePropertySet
->setPropertyValue(m_aOwnInnerName
,convertOuterToInnerValue(uno::Any(aNewValue
)));
126 catch( uno::Exception
& ex
)
128 //spline properties are not supported by all charttypes
129 //in that cases this exception is ok
130 ex
.Context
.is();//to have debug information without compilation warnings
137 css::uno::Any
getPropertyValue( const css::uno::Reference
< css::beans::XPropertySet
>& /*xInnerPropertySet*/ ) const override
139 bool bHasAmbiguousValue
= false;
141 if( detectInnerValue( aValue
, bHasAmbiguousValue
) )
143 m_aOuterValue
<<= aValue
;
145 return m_aOuterValue
;
148 css::uno::Any
getPropertyDefault( const css::uno::Reference
< css::beans::XPropertyState
>& /*xInnerPropertyState*/ ) const override
150 return m_aDefaultValue
;
154 std::shared_ptr
< Chart2ModelContact
> m_spChart2ModelContact
;
155 mutable css::uno::Any m_aOuterValue
;
156 css::uno::Any m_aDefaultValue
;
157 // this inner name is not set as inner name at the base class
158 const OUString m_aOwnInnerName
;
161 class WrappedSplineTypeProperty
: public WrappedSplineProperty
< sal_Int32
>
164 explicit WrappedSplineTypeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
);
166 virtual css::uno::Any
convertInnerToOuterValue( const css::uno::Any
& rInnerValue
) const override
;
167 virtual css::uno::Any
convertOuterToInnerValue( const css::uno::Any
& rOuterValue
) const override
;
175 PROP_CHART_SPLINE_TYPE
= FAST_PROPERTY_ID_START_CHART_SPLINE_PROP
176 , PROP_CHART_SPLINE_ORDER
177 , PROP_CHART_SPLINE_RESOLUTION
180 }//anonymous namespace
182 void WrappedSplineProperties::addProperties( std::vector
< Property
> & rOutProperties
)
184 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_TYPE
,
185 PROP_CHART_SPLINE_TYPE
,
186 cppu::UnoType
<sal_Int32
>::get(),
187 beans::PropertyAttribute::BOUND
188 | beans::PropertyAttribute::MAYBEDEFAULT
189 | beans::PropertyAttribute::MAYBEVOID
);
190 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_ORDER
,
191 PROP_CHART_SPLINE_ORDER
,
192 cppu::UnoType
<sal_Int32
>::get(),
193 beans::PropertyAttribute::BOUND
194 | beans::PropertyAttribute::MAYBEDEFAULT
195 | beans::PropertyAttribute::MAYBEVOID
);
196 rOutProperties
.emplace_back( CHART_UNONAME_SPLINE_RESOLUTION
,
197 PROP_CHART_SPLINE_RESOLUTION
,
198 cppu::UnoType
<sal_Int32
>::get(),
199 beans::PropertyAttribute::BOUND
200 | beans::PropertyAttribute::MAYBEDEFAULT
201 | beans::PropertyAttribute::MAYBEVOID
);
204 void WrappedSplineProperties::addWrappedProperties( std::vector
< std::unique_ptr
<WrappedProperty
> >& rList
205 , const std::shared_ptr
< Chart2ModelContact
>& spChart2ModelContact
)
207 rList
.emplace_back( new WrappedSplineTypeProperty( spChart2ModelContact
) );
209 new WrappedSplineProperty
<sal_Int32
>(
210 CHART_UNONAME_SPLINE_ORDER
, CHART_UNONAME_SPLINE_ORDER
,
211 uno::Any(sal_Int32(3)), spChart2ModelContact
));
213 new WrappedSplineProperty
<sal_Int32
>(
214 CHART_UNONAME_SPLINE_RESOLUTION
, CHART_UNONAME_CURVE_RESOLUTION
,
215 uno::Any(sal_Int32(20)), spChart2ModelContact
));
218 WrappedSplineTypeProperty::WrappedSplineTypeProperty(const std::shared_ptr
<Chart2ModelContact
>& spChart2ModelContact
)
219 : WrappedSplineProperty
<sal_Int32
>(CHART_UNONAME_SPLINE_TYPE
, CHART_UNONAME_CURVE_STYLE
, uno::Any(sal_Int32(0)), spChart2ModelContact
)
223 Any
WrappedSplineTypeProperty::convertInnerToOuterValue( const Any
& rInnerValue
) const
225 chart2::CurveStyle aInnerValue
= chart2::CurveStyle_LINES
;
226 rInnerValue
>>= aInnerValue
;
228 sal_Int32 nOuterValue
;
231 case chart2::CurveStyle_CUBIC_SPLINES
:
234 case chart2::CurveStyle_B_SPLINES
:
237 case chart2::CurveStyle_STEP_START
:
240 case chart2::CurveStyle_STEP_END
:
243 case chart2::CurveStyle_STEP_CENTER_X
:
246 case chart2::CurveStyle_STEP_CENTER_Y
:
253 return uno::Any(nOuterValue
);
255 Any
WrappedSplineTypeProperty::convertOuterToInnerValue( const Any
& rOuterValue
) const
257 sal_Int32 nOuterValue
=0;
258 rOuterValue
>>= nOuterValue
;
260 chart2::CurveStyle aInnerValue
;
265 aInnerValue
= chart2::CurveStyle_CUBIC_SPLINES
;
268 aInnerValue
= chart2::CurveStyle_B_SPLINES
;
271 aInnerValue
= chart2::CurveStyle_STEP_START
;
274 aInnerValue
= chart2::CurveStyle_STEP_END
;
277 aInnerValue
= chart2::CurveStyle_STEP_CENTER_X
;
280 aInnerValue
= chart2::CurveStyle_STEP_CENTER_Y
;
283 SAL_WARN_IF(nOuterValue
!= 0, "chart2", "Unknown line style");
284 aInnerValue
= chart2::CurveStyle_LINES
;
287 return uno::Any(aInnerValue
);
290 } //namespace wrapper
293 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */