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 <FormattedString.hxx>
22 #include <CharacterProperties.hxx>
23 #include <PropertyHelper.hxx>
24 #include <ModifyListenerHelper.hxx>
25 #include <cppuhelper/supportsservice.hxx>
27 namespace com::sun::star::uno
{ class XComponentContext
; }
29 using namespace ::com::sun::star
;
31 using ::com::sun::star::beans::Property
;
32 using ::com::sun::star::uno::Sequence
;
33 using ::osl::MutexGuard
;
37 const ::chart::tPropertyValueMap
& StaticFormattedStringDefaults()
39 static ::chart::tPropertyValueMap aStaticDefaults
= []
41 ::chart::tPropertyValueMap aMap
;
42 ::chart::CharacterProperties::AddDefaultsToMap( aMap
);
45 return aStaticDefaults
;
52 ::cppu::OPropertyArrayHelper
& StaticFormattedStringInfoHelper()
54 static ::cppu::OPropertyArrayHelper aPropHelper
= []()
56 std::vector
< css::beans::Property
> aProperties
;
57 ::chart::CharacterProperties::AddPropertiesToVector( aProperties
);
59 std::sort( aProperties
.begin(), aProperties
.end(),
60 ::chart::PropertyNameLess() );
62 return comphelper::containerToSequence( aProperties
);
67 } // anonymous namespace
72 FormattedString::FormattedString() :
73 m_aType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT
),
74 m_bDataLabelsRange(false),
75 m_xModifyEventForwarder( new ModifyEventForwarder() )
78 FormattedString::FormattedString( const FormattedString
& rOther
) :
79 impl::FormattedString_Base(rOther
),
80 ::property::OPropertySet( rOther
),
81 m_aString( rOther
.m_aString
),
82 m_aType(rOther
.m_aType
),
83 m_aGuid(rOther
.m_aGuid
),
84 m_bDataLabelsRange(rOther
.m_bDataLabelsRange
),
85 m_xModifyEventForwarder( new ModifyEventForwarder() )
88 FormattedString::~FormattedString()
91 // ____ XCloneable ____
92 uno::Reference
< util::XCloneable
> SAL_CALL
FormattedString::createClone()
94 return uno::Reference
< util::XCloneable
>( new FormattedString( *this ));
97 // ____ XFormattedString ____
98 OUString SAL_CALL
FormattedString::getString()
100 MutexGuard
aGuard( m_aMutex
);
104 void SAL_CALL
FormattedString::setString( const OUString
& String
)
107 MutexGuard
aGuard( m_aMutex
);
110 //don't keep the mutex locked while calling out
115 // ____ XDataPointCustomLabelField ____
116 css::chart2::DataPointCustomLabelFieldType SAL_CALL
FormattedString::getFieldType()
118 MutexGuard
aGuard(m_aMutex
);
123 FormattedString::setFieldType(const css::chart2::DataPointCustomLabelFieldType Type
)
126 MutexGuard
aGuard(m_aMutex
);
129 //don't keep the mutex locked while calling out
133 OUString SAL_CALL
FormattedString::getGuid()
135 MutexGuard
aGuard( m_aMutex
);
139 void SAL_CALL
FormattedString::setGuid( const OUString
& guid
)
142 MutexGuard
aGuard( m_aMutex
);
145 //don't keep the mutex locked while calling out
150 sal_Bool SAL_CALL
FormattedString::getDataLabelsRange()
152 MutexGuard
aGuard( m_aMutex
);
153 return m_bDataLabelsRange
;
156 void SAL_CALL
FormattedString::setDataLabelsRange( sal_Bool dataLabelsRange
)
159 MutexGuard
aGuard( m_aMutex
);
160 m_bDataLabelsRange
= dataLabelsRange
;
162 //don't keep the mutex locked while calling out
166 OUString SAL_CALL
FormattedString::getCellRange()
168 MutexGuard
aGuard( m_aMutex
);
172 void SAL_CALL
FormattedString::setCellRange( const OUString
& cellRange
)
175 MutexGuard
aGuard( m_aMutex
);
176 m_aCellRange
= cellRange
;
178 //don't keep the mutex locked while calling out
182 // ____ XModifyBroadcaster ____
183 void SAL_CALL
FormattedString::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
185 m_xModifyEventForwarder
->addModifyListener( aListener
);
188 void SAL_CALL
FormattedString::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
190 m_xModifyEventForwarder
->removeModifyListener( aListener
);
193 // ____ XModifyListener ____
194 void SAL_CALL
FormattedString::modified( const lang::EventObject
& aEvent
)
196 m_xModifyEventForwarder
->modified( aEvent
);
199 // ____ XEventListener (base of XModifyListener) ____
200 void SAL_CALL
FormattedString::disposing( const lang::EventObject
& /* Source */ )
205 // ____ OPropertySet ____
206 void FormattedString::firePropertyChangeEvent()
211 void FormattedString::fireModifyEvent()
213 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
216 // ____ OPropertySet ____
217 void FormattedString::GetDefaultValue( sal_Int32 nHandle
, uno::Any
& rAny
) const
219 const tPropertyValueMap
& rStaticDefaults
= StaticFormattedStringDefaults();
220 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
221 if( aFound
== rStaticDefaults
.end() )
224 rAny
= (*aFound
).second
;
227 // ____ OPropertySet ____
228 ::cppu::IPropertyArrayHelper
& SAL_CALL
FormattedString::getInfoHelper()
230 return StaticFormattedStringInfoHelper();
233 // ____ XPropertySet ____
234 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
FormattedString::getPropertySetInfo()
236 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
237 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticFormattedStringInfoHelper() ) );
238 return xPropertySetInfo
;
241 using impl::FormattedString_Base
;
243 IMPLEMENT_FORWARD_XINTERFACE2( FormattedString
, FormattedString_Base
, ::property::OPropertySet
)
244 IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString
, FormattedString_Base
, ::property::OPropertySet
)
246 // do this in derived classes!
248 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
249 OUString SAL_CALL
FormattedString::getImplementationName()
251 return u
"com.sun.star.comp.chart.FormattedString"_ustr
;
254 sal_Bool SAL_CALL
FormattedString::supportsService( const OUString
& rServiceName
)
256 return cppu::supportsService(this, rServiceName
);
259 css::uno::Sequence
< OUString
> SAL_CALL
FormattedString::getSupportedServiceNames()
262 u
"com.sun.star.chart2.DataPointCustomLabelField"_ustr
,
263 u
"com.sun.star.chart2.FormattedString"_ustr
,
264 u
"com.sun.star.beans.PropertySet"_ustr
};
269 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
*
270 com_sun_star_comp_chart_FormattedString_get_implementation(css::uno::XComponentContext
*,
271 css::uno::Sequence
<css::uno::Any
> const &)
273 return cppu::acquire(new ::chart::FormattedString
);
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */