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/.
10 #include "GL3DBarChartTypeTemplate.hxx"
11 #include "GL3DBarChartType.hxx"
13 #include <servicenames_charttypes.hxx>
14 #include <PropertyHelper.hxx>
15 #include <DiagramHelper.hxx>
16 #include <unonames.hxx>
19 #include <com/sun/star/beans/Property.hpp>
20 #include <com/sun/star/beans/PropertyAttribute.hpp>
22 using namespace com::sun::star
;
30 PROP_GL3DCHARTTYPE_ROUNDED_EDGE
33 struct DefaultsInitializer
35 tPropertyValueMap
* operator()()
37 static tPropertyValueMap aStaticDefaults
;
39 if (aStaticDefaults
.empty())
40 addDefaults(aStaticDefaults
);
42 return &aStaticDefaults
;
46 static void addDefaults( tPropertyValueMap
& rOutMap
)
48 PropertyHelper::setPropertyValueDefault(rOutMap
, PROP_GL3DCHARTTYPE_ROUNDED_EDGE
, false);
52 struct Defaults
: public rtl::StaticAggregate
<tPropertyValueMap
, DefaultsInitializer
> {};
54 struct InfoHelperInitializer
56 cppu::OPropertyArrayHelper
* operator()()
58 static cppu::OPropertyArrayHelper
aHelper(getProperties());
62 static uno::Sequence
<beans::Property
> getProperties()
64 uno::Sequence
<beans::Property
> aRet(1);
66 aRet
[0] = beans::Property(
67 CHART_UNONAME_ROUNDED_EDGE
,
68 PROP_GL3DCHARTTYPE_ROUNDED_EDGE
,
69 cppu::UnoType
<bool>::get(),
70 beans::PropertyAttribute::BOUND
| beans::PropertyAttribute::MAYBEDEFAULT
);
76 struct InfoHelper
: public rtl::StaticAggregate
<cppu::OPropertyArrayHelper
, InfoHelperInitializer
> {};
78 struct ChartTypeInfoInitializer
80 uno::Reference
<beans::XPropertySetInfo
>* operator()()
82 static uno::Reference
<beans::XPropertySetInfo
> xPropertySetInfo
;
84 if (!xPropertySetInfo
.is())
85 xPropertySetInfo
= cppu::OPropertySetHelper::createPropertySetInfo(*InfoHelper::get());
87 return &xPropertySetInfo
;
91 struct ChartTypeInfo
: public rtl::StaticAggregate
<uno::Reference
<beans::XPropertySetInfo
>, ChartTypeInfoInitializer
> {};
95 GL3DBarChartTypeTemplate::GL3DBarChartTypeTemplate(
96 const uno::Reference
<uno::XComponentContext
>& xContext
, const OUString
& rServiceName
) :
97 property::OPropertySet(m_aMutex
),
98 ChartTypeTemplate(xContext
, rServiceName
) {}
100 GL3DBarChartTypeTemplate::~GL3DBarChartTypeTemplate() {}
102 uno::Reference
<chart2::XChartType
> GL3DBarChartTypeTemplate::getChartTypeForIndex( sal_Int32
/*nChartTypeIndex*/ )
104 uno::Reference
<chart2::XChartType
> xResult
;
108 uno::Reference
<lang::XMultiServiceFactory
> xFact(
109 GetComponentContext()->getServiceManager(), uno::UNO_QUERY_THROW
);
111 xResult
.set(xFact
->createInstance(CHART2_SERVICE_NAME_CHARTTYPE_GL3DBAR
), uno::UNO_QUERY_THROW
);
113 uno::Reference
<beans::XPropertySet
> xCTProp(xResult
, uno::UNO_QUERY
);
116 xCTProp
->setPropertyValue(
117 CHART_UNONAME_ROUNDED_EDGE
, getFastPropertyValue(PROP_GL3DCHARTTYPE_ROUNDED_EDGE
));
120 catch (const uno::Exception
& ex
)
122 ASSERT_EXCEPTION( ex
);
128 sal_Bool SAL_CALL
GL3DBarChartTypeTemplate::matchesTemplate(
129 const css::uno::Reference
<css::chart2::XDiagram
>& xDiagram
,
130 sal_Bool bAdaptProperties
)
131 throw (css::uno::RuntimeException
, std::exception
)
133 bool bResult
= ChartTypeTemplate::matchesTemplate(xDiagram
, bAdaptProperties
);
135 if (bResult
&& bAdaptProperties
)
137 uno::Reference
<chart2::XChartType
> xChartType
= DiagramHelper::getChartTypeByIndex(xDiagram
, 0);
138 uno::Reference
<beans::XPropertySet
> xPS(xChartType
, uno::UNO_QUERY
);
141 setFastPropertyValue_NoBroadcast(
142 PROP_GL3DCHARTTYPE_ROUNDED_EDGE
, xPS
->getPropertyValue(CHART_UNONAME_ROUNDED_EDGE
));
149 uno::Reference
<chart2::XChartType
>
150 GL3DBarChartTypeTemplate::getChartTypeForNewSeries( const uno::Sequence
<uno::Reference
<chart2::XChartType
> >& /*xOldChartTypes*/ )
151 throw (css::uno::RuntimeException
, ::std::exception
)
153 uno::Reference
<chart2::XChartType
> xResult
;
157 rtl::Reference
<GL3DBarChartType
> chart(
158 new GL3DBarChartType(GetComponentContext()));
160 getFastPropertyValue(PROP_GL3DCHARTTYPE_ROUNDED_EDGE
) >>= bVal
;
161 chart
->setPropertyValue(CHART_UNONAME_ROUNDED_EDGE
, uno::makeAny(bVal
));
162 xResult
= chart
.get();
164 catch (const uno::Exception
& ex
)
166 ASSERT_EXCEPTION( ex
);
172 sal_Bool
GL3DBarChartTypeTemplate::supportsCategories()
173 throw (css::uno::RuntimeException
, ::std::exception
)
178 css::uno::Any
GL3DBarChartTypeTemplate::GetDefaultValue( sal_Int32 nHandle
) const
179 throw (css::beans::UnknownPropertyException
)
181 const tPropertyValueMap
& rDefaults
= *Defaults::get();
182 tPropertyValueMap::const_iterator it
= rDefaults
.find(nHandle
);
183 return it
== rDefaults
.end() ? uno::Any() : it
->second
;
186 cppu::IPropertyArrayHelper
& GL3DBarChartTypeTemplate::getInfoHelper()
188 return *InfoHelper::get();
191 css::uno::Reference
<css::beans::XPropertySetInfo
> GL3DBarChartTypeTemplate::getPropertySetInfo()
192 throw (css::uno::RuntimeException
, std::exception
)
194 return *ChartTypeInfo::get();
197 IMPLEMENT_FORWARD_XINTERFACE2(GL3DBarChartTypeTemplate
, ChartTypeTemplate
, OPropertySet
)
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */