LibreOffice Module chart2 (master) 1
UpDownBarWrapper.cxx
Go to the documentation of this file.
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 "UpDownBarWrapper.hxx"
22#include <ChartType.hxx>
23#include <DiagramHelper.hxx>
28
30#include <FillProperties.hxx>
32#include <utility>
34
35using namespace ::com::sun::star;
36using namespace ::com::sun::star::chart2;
37
38using ::com::sun::star::beans::Property;
39using ::com::sun::star::uno::Reference;
40using ::com::sun::star::uno::Sequence;
41using ::com::sun::star::uno::Any;
42
43namespace
44{
45
46const Sequence< Property > & StaticUpDownBarWrapperPropertyArray()
47{
48 static Sequence< Property > aPropSeq = []()
49 {
50 std::vector< css::beans::Property > aProperties;
51
55
56 std::sort( aProperties.begin(), aProperties.end(),
58
59 return comphelper::containerToSequence( aProperties );
60 }();
61 return aPropSeq;
62};
63
64::cppu::OPropertyArrayHelper& StaticUpDownBarWrapperInfoHelper()
65{
66 static ::cppu::OPropertyArrayHelper aPropHelper( StaticUpDownBarWrapperPropertyArray() );
67 return aPropHelper;
68};
69
70} // anonymous namespace
71
72namespace chart::wrapper
73{
74
76 bool bUp, std::shared_ptr<Chart2ModelContact> spChart2ModelContact)
77 : m_spChart2ModelContact(std::move( spChart2ModelContact ))
78 , m_aPropertySetName( bUp ? OUString( "WhiteDay" ) : OUString( "BlackDay" ))
79{
80}
81
83{
84}
85
86// ____ XComponent ____
88{
89 std::unique_lock g(m_aMutex);
90 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
91 m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
92}
93
95 const Reference< lang::XEventListener >& xListener )
96{
97 std::unique_lock g(m_aMutex);
99}
100
102 const Reference< lang::XEventListener >& aListener )
103{
104 std::unique_lock g(m_aMutex);
106}
107
108//XPropertySet
110{
111 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
112 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticUpDownBarWrapperInfoHelper() ) );
113 return xPropertySetInfo;
114}
115
116void SAL_CALL UpDownBarWrapper::setPropertyValue( const OUString& rPropertyName, const uno::Any& rValue )
117{
119
120 const std::vector< rtl::Reference< ChartType > > aTypes =
121 m_spChart2ModelContact->getDiagram()->getChartTypes();
122 for( rtl::Reference< ChartType > const & xType : aTypes )
123 {
124 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
125 {
126 xType->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
127 }
128 }
129 if(xPropSet.is())
130 xPropSet->setPropertyValue( rPropertyName, rValue );
131}
132uno::Any SAL_CALL UpDownBarWrapper::getPropertyValue( const OUString& rPropertyName )
133{
134 Any aRet;
135
137
138 const std::vector< rtl::Reference< ChartType > > aTypes =
139 m_spChart2ModelContact->getDiagram()->getChartTypes();
140 for( rtl::Reference<ChartType > const & xType : aTypes )
141 {
142 if( xType->getChartType() == CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK )
143 {
144 xType->getPropertyValue( m_aPropertySetName ) >>= xPropSet;
145 }
146 }
147 if(xPropSet.is())
148 aRet = xPropSet->getPropertyValue( rPropertyName );
149 return aRet;
150}
151
152void SAL_CALL UpDownBarWrapper::addPropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*xListener*/ )
153{
154 OSL_FAIL("not implemented");
155}
156void SAL_CALL UpDownBarWrapper::removePropertyChangeListener( const OUString& /*aPropertyName*/, const uno::Reference< beans::XPropertyChangeListener >& /*aListener*/ )
157{
158 OSL_FAIL("not implemented");
159}
160void SAL_CALL UpDownBarWrapper::addVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
161{
162 OSL_FAIL("not implemented");
163}
164void SAL_CALL UpDownBarWrapper::removeVetoableChangeListener( const OUString& /*PropertyName*/, const uno::Reference< beans::XVetoableChangeListener >& /*aListener*/ )
165{
166 OSL_FAIL("not implemented");
167}
168
169//XMultiPropertySet
170//getPropertySetInfo() already declared in XPropertySet
172{
173 sal_Int32 nMinCount = std::min( rValueSeq.getLength(), rNameSeq.getLength() );
174 for(sal_Int32 nN=0; nN<nMinCount; nN++)
175 {
176 OUString aPropertyName( rNameSeq[nN] );
177 try
178 {
179 setPropertyValue( aPropertyName, rValueSeq[nN] );
180 }
181 catch( const beans::UnknownPropertyException& )
182 {
183 DBG_UNHANDLED_EXCEPTION("chart2");
184 }
185 }
186 //todo: store unknown properties elsewhere
187}
189{
190 Sequence< Any > aRetSeq;
191 if( rNameSeq.hasElements() )
192 {
193 aRetSeq.realloc( rNameSeq.getLength() );
194 auto pRetSeq = aRetSeq.getArray();
195 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
196 {
197 OUString aPropertyName( rNameSeq[nN] );
198 pRetSeq[nN] = getPropertyValue( aPropertyName );
199 }
200 }
201 return aRetSeq;
202}
204{
205 OSL_FAIL("not implemented");
206}
208{
209 OSL_FAIL("not implemented");
210}
212{
213 OSL_FAIL("not implemented");
214}
215
216//XPropertyState
217beans::PropertyState SAL_CALL UpDownBarWrapper::getPropertyState( const OUString& rPropertyName )
218{
219 uno::Any aDefault( getPropertyDefault( rPropertyName ) );
220 uno::Any aValue( getPropertyValue( rPropertyName ) );
221
222 if( aDefault == aValue )
223 return beans::PropertyState_DEFAULT_VALUE;
224
225 return beans::PropertyState_DIRECT_VALUE;
226}
228{
230 if( rNameSeq.hasElements() )
231 {
232 aRetSeq.realloc( rNameSeq.getLength() );
233 auto pRetSeq = aRetSeq.getArray();
234 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
235 {
236 OUString aPropertyName( rNameSeq[nN] );
237 pRetSeq[nN] = getPropertyState( aPropertyName );
238 }
239 }
240 return aRetSeq;
241}
242void SAL_CALL UpDownBarWrapper::setPropertyToDefault( const OUString& rPropertyName )
243{
244 setPropertyValue( rPropertyName, getPropertyDefault(rPropertyName) );
245}
246
247uno::Any SAL_CALL UpDownBarWrapper::getPropertyDefault( const OUString& rPropertyName )
248{
249 static const ::chart::tPropertyValueMap aStaticDefaults = []()
250 {
254 return aTmp;
255 }();
256 tPropertyValueMap::const_iterator aFound( aStaticDefaults.find( StaticUpDownBarWrapperInfoHelper().getHandleByName( rPropertyName ) ) );
257 if( aFound == aStaticDefaults.end() )
258 return uno::Any();
259 return (*aFound).second;
260}
261
262//XMultiPropertyStates
263//getPropertyStates() already declared in XPropertyState
265{
266 const Sequence< beans::Property >& rPropSeq = StaticUpDownBarWrapperPropertyArray();
267 for(beans::Property const & prop : rPropSeq)
268 {
269 setPropertyToDefault( prop.Name );
270 }
271}
273{
274 for(OUString const & s : rNameSeq)
275 {
277 }
278}
280{
281 Sequence< Any > aRetSeq;
282 if( rNameSeq.hasElements() )
283 {
284 aRetSeq.realloc( rNameSeq.getLength() );
285 auto pRetSeq = aRetSeq.getArray();
286 for(sal_Int32 nN=0; nN<rNameSeq.getLength(); nN++)
287 {
288 OUString aPropertyName( rNameSeq[nN] );
289 pRetSeq[nN] = getPropertyDefault( aPropertyName );
290 }
291 }
292 return aRetSeq;
293}
294
296{
297 return "com.sun.star.comp.chart.ChartArea";
298}
299
300sal_Bool SAL_CALL UpDownBarWrapper::supportsService( const OUString& rServiceName )
301{
302 return cppu::supportsService(this, rServiceName);
303}
304
305css::uno::Sequence< OUString > SAL_CALL UpDownBarWrapper::getSupportedServiceNames()
306{
307 return {
308 "com.sun.star.chart.ChartArea",
309 "com.sun.star.drawing.LineProperties",
310 "com.sun.star.drawing.FillProperties",
311 "com.sun.star.xml.UserDefinedAttributesSupplier"
312 };
313}
314
315} // namespace chart::wrapper
316
317/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
PropertiesInfo aProperties
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::uno::Sequence< css::beans::PropertyState > SAL_CALL getPropertyStates(const css::uno::Sequence< OUString > &aPropertyName) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL addPropertiesChangeListener(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual void SAL_CALL dispose() override
virtual void SAL_CALL firePropertiesChangeEvent(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aEventListenerContainer
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
virtual void SAL_CALL setPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames, const css::uno::Sequence< css::uno::Any > &aValues) override
virtual void SAL_CALL setAllPropertiesToDefault() override
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
UpDownBarWrapper(bool bUp, std::shared_ptr< Chart2ModelContact > spChart2ModelContact)
virtual void SAL_CALL removePropertiesChangeListener(const css::uno::Reference< css::beans::XPropertiesChangeListener > &xListener) override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyDefaults(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual css::uno::Sequence< css::uno::Any > SAL_CALL getPropertyValues(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
virtual void SAL_CALL setPropertiesToDefault(const css::uno::Sequence< OUString > &aPropertyNames) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
#define DBG_UNHANDLED_EXCEPTION(...)
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
constexpr OUStringLiteral CHART2_SERVICE_NAME_CHARTTYPE_CANDLESTICK
unsigned char sal_Bool
const SvXMLTokenMapEntry aTypes[]