nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / model / main / FormattedString.cxx
blob0d6e733a2c31bd339a445e94121ffec156741d8e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
26 #include <tools/diagnose_ex.h>
28 namespace com::sun::star::uno { class XComponentContext; }
30 using namespace ::com::sun::star;
32 using ::com::sun::star::beans::Property;
33 using ::com::sun::star::uno::Sequence;
34 using ::osl::MutexGuard;
36 namespace
39 struct StaticFormattedStringDefaults_Initializer
41 ::chart::tPropertyValueMap* operator()()
43 static ::chart::tPropertyValueMap aStaticDefaults;
44 ::chart::CharacterProperties::AddDefaultsToMap( aStaticDefaults );
45 return &aStaticDefaults;
49 struct StaticFormattedStringDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticFormattedStringDefaults_Initializer >
53 struct StaticFormattedStringInfoHelper_Initializer
55 ::cppu::OPropertyArrayHelper* operator()()
57 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
58 return &aPropHelper;
61 private:
62 static Sequence< Property > lcl_GetPropertySequence()
64 std::vector< css::beans::Property > aProperties;
65 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
67 std::sort( aProperties.begin(), aProperties.end(),
68 ::chart::PropertyNameLess() );
70 return comphelper::containerToSequence( aProperties );
75 struct StaticFormattedStringInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticFormattedStringInfoHelper_Initializer >
79 struct StaticFormattedStringInfo_Initializer
81 uno::Reference< beans::XPropertySetInfo >* operator()()
83 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
84 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticFormattedStringInfoHelper::get() ) );
85 return &xPropertySetInfo;
89 struct StaticFormattedStringInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticFormattedStringInfo_Initializer >
93 } // anonymous namespace
95 namespace chart
98 FormattedString::FormattedString() :
99 ::property::OPropertySet( m_aMutex ),
100 m_aString(),
101 m_aType(chart2::DataPointCustomLabelFieldType::DataPointCustomLabelFieldType_TEXT),
102 m_aGuid(),
103 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
106 FormattedString::FormattedString( const FormattedString & rOther ) :
107 impl::FormattedString_Base(rOther),
108 ::property::OPropertySet( rOther, m_aMutex ),
109 m_aString( rOther.m_aString ),
110 m_aType(rOther.m_aType),
111 m_aGuid(rOther.m_aGuid),
112 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
115 FormattedString::~FormattedString()
118 // ____ XCloneable ____
119 uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
121 return uno::Reference< util::XCloneable >( new FormattedString( *this ));
124 // ____ XFormattedString ____
125 OUString SAL_CALL FormattedString::getString()
127 MutexGuard aGuard( m_aMutex);
128 return m_aString;
131 void SAL_CALL FormattedString::setString( const OUString& String )
134 MutexGuard aGuard( m_aMutex);
135 m_aString = String;
137 //don't keep the mutex locked while calling out
138 fireModifyEvent();
142 // ____ XDataPointCustomLabelField ____
143 css::chart2::DataPointCustomLabelFieldType SAL_CALL FormattedString::getFieldType()
145 MutexGuard aGuard(m_aMutex);
146 return m_aType;
149 void SAL_CALL
150 FormattedString::setFieldType(const css::chart2::DataPointCustomLabelFieldType Type)
153 MutexGuard aGuard(m_aMutex);
154 m_aType = Type;
156 //don't keep the mutex locked while calling out
157 fireModifyEvent();
160 OUString SAL_CALL FormattedString::getGuid()
162 MutexGuard aGuard( m_aMutex);
163 return m_aGuid;
166 void SAL_CALL FormattedString::setGuid( const OUString& guid )
169 MutexGuard aGuard( m_aMutex);
170 m_aGuid= guid;
172 //don't keep the mutex locked while calling out
173 fireModifyEvent();
177 // ____ XModifyBroadcaster ____
178 void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
182 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
183 xBroadcaster->addModifyListener( aListener );
185 catch( const uno::Exception & )
187 DBG_UNHANDLED_EXCEPTION("chart2");
191 void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
195 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
196 xBroadcaster->removeModifyListener( aListener );
198 catch( const uno::Exception & )
200 DBG_UNHANDLED_EXCEPTION("chart2");
204 // ____ XModifyListener ____
205 void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
207 m_xModifyEventForwarder->modified( aEvent );
210 // ____ XEventListener (base of XModifyListener) ____
211 void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
213 // nothing
216 // ____ OPropertySet ____
217 void FormattedString::firePropertyChangeEvent()
219 fireModifyEvent();
222 void FormattedString::fireModifyEvent()
224 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
227 // ____ OPropertySet ____
228 uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
230 const tPropertyValueMap& rStaticDefaults = *StaticFormattedStringDefaults::get();
231 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
232 if( aFound == rStaticDefaults.end() )
233 return uno::Any();
234 return (*aFound).second;
237 // ____ OPropertySet ____
238 ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
240 return *StaticFormattedStringInfoHelper::get();
243 // ____ XPropertySet ____
244 uno::Reference< beans::XPropertySetInfo > SAL_CALL FormattedString::getPropertySetInfo()
246 return *StaticFormattedStringInfo::get();
249 using impl::FormattedString_Base;
251 IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
252 IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
254 // do this in derived classes!
256 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
257 OUString SAL_CALL FormattedString::getImplementationName()
259 return "com.sun.star.comp.chart.FormattedString";
262 sal_Bool SAL_CALL FormattedString::supportsService( const OUString& rServiceName )
264 return cppu::supportsService(this, rServiceName);
267 css::uno::Sequence< OUString > SAL_CALL FormattedString::getSupportedServiceNames()
269 return {
270 "com.sun.star.chart2.DataPointCustomLabelField",
271 "com.sun.star.chart2.FormattedString",
272 "com.sun.star.beans.PropertySet" };
275 } // namespace chart
277 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
278 com_sun_star_comp_chart_FormattedString_get_implementation(css::uno::XComponentContext *,
279 css::uno::Sequence<css::uno::Any> const &)
281 return cppu::acquire(new ::chart::FormattedString);
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */