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