fix baseline build (old cairo) - 'cairo_rectangle_int_t' does not name a type
[LibreOffice.git] / chart2 / source / model / main / FormattedString.cxx
blobf30eb31a4098e9413981214c5c450b8949daf01f
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"
21 #include "ContainerHelper.hxx"
23 #include "CharacterProperties.hxx"
24 #include "PropertyHelper.hxx"
25 #include "macros.hxx"
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <cppuhelper/supportsservice.hxx>
29 using namespace ::com::sun::star;
31 using ::com::sun::star::beans::Property;
32 using ::com::sun::star::uno::Sequence;
33 using ::com::sun::star::uno::Reference;
34 using ::com::sun::star::uno::Any;
35 using ::osl::MutexGuard;
37 namespace
40 struct StaticFormattedStringDefaults_Initializer
42 ::chart::tPropertyValueMap* operator()()
44 static ::chart::tPropertyValueMap aStaticDefaults;
45 lcl_AddDefaultsToMap( aStaticDefaults );
46 return &aStaticDefaults;
48 private:
49 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
51 ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
55 struct StaticFormattedStringDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticFormattedStringDefaults_Initializer >
59 struct StaticFormattedStringInfoHelper_Initializer
61 ::cppu::OPropertyArrayHelper* operator()()
63 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
64 return &aPropHelper;
67 private:
68 static Sequence< Property > lcl_GetPropertySequence()
70 ::std::vector< ::com::sun::star::beans::Property > aProperties;
71 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
73 ::std::sort( aProperties.begin(), aProperties.end(),
74 ::chart::PropertyNameLess() );
76 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
81 struct StaticFormattedStringInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticFormattedStringInfoHelper_Initializer >
85 struct StaticFormattedStringInfo_Initializer
87 uno::Reference< beans::XPropertySetInfo >* operator()()
89 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
90 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticFormattedStringInfoHelper::get() ) );
91 return &xPropertySetInfo;
95 struct StaticFormattedStringInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticFormattedStringInfo_Initializer >
99 } // anonymous namespace
101 namespace chart
104 FormattedString::FormattedString(
105 uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
106 ::property::OPropertySet( m_aMutex ),
107 m_aString(),
108 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
111 FormattedString::FormattedString( const FormattedString & rOther ) :
112 MutexContainer(),
113 impl::FormattedString_Base(),
114 ::property::OPropertySet( rOther, m_aMutex ),
115 m_aString( rOther.m_aString ),
116 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
119 FormattedString::~FormattedString()
122 // ____ XCloneable ____
123 uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
124 throw (uno::RuntimeException, std::exception)
126 return uno::Reference< util::XCloneable >( new FormattedString( *this ));
129 // ____ XFormattedString ____
130 OUString SAL_CALL FormattedString::getString()
131 throw (uno::RuntimeException, std::exception)
133 MutexGuard aGuard( GetMutex());
134 return m_aString;
137 void SAL_CALL FormattedString::setString( const OUString& String )
138 throw (uno::RuntimeException, std::exception)
141 MutexGuard aGuard( GetMutex());
142 m_aString = String;
144 //don't keep the mutex locked while calling out
145 fireModifyEvent();
149 // ____ XModifyBroadcaster ____
150 void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
151 throw (uno::RuntimeException, std::exception)
155 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
156 xBroadcaster->addModifyListener( aListener );
158 catch( const uno::Exception & ex )
160 ASSERT_EXCEPTION( ex );
164 void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
165 throw (uno::RuntimeException, std::exception)
169 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
170 xBroadcaster->removeModifyListener( aListener );
172 catch( const uno::Exception & ex )
174 ASSERT_EXCEPTION( ex );
178 // ____ XModifyListener ____
179 void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
180 throw (uno::RuntimeException, std::exception)
182 m_xModifyEventForwarder->modified( aEvent );
185 // ____ XEventListener (base of XModifyListener) ____
186 void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
187 throw (uno::RuntimeException, std::exception)
189 // nothing
192 // ____ OPropertySet ____
193 void FormattedString::firePropertyChangeEvent()
195 fireModifyEvent();
198 void FormattedString::fireModifyEvent()
200 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
203 Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
205 Sequence< OUString > aServices( 2 );
207 aServices[ 0 ] = "com.sun.star.chart2.FormattedString";
208 aServices[ 1 ] = "com.sun.star.beans.PropertySet";
209 return aServices;
212 // ____ OPropertySet ____
213 uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
214 throw (beans::UnknownPropertyException, uno::RuntimeException)
216 const tPropertyValueMap& rStaticDefaults = *StaticFormattedStringDefaults::get();
217 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
218 if( aFound == rStaticDefaults.end() )
219 return uno::Any();
220 return (*aFound).second;
223 // ____ OPropertySet ____
224 ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
226 return *StaticFormattedStringInfoHelper::get();
229 // ____ XPropertySet ____
230 uno::Reference< beans::XPropertySetInfo > SAL_CALL FormattedString::getPropertySetInfo()
231 throw (uno::RuntimeException, std::exception)
233 return *StaticFormattedStringInfo::get();
236 using impl::FormattedString_Base;
238 IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
239 IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
241 // do this in derived classes!
243 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
244 OUString SAL_CALL FormattedString::getImplementationName()
245 throw( css::uno::RuntimeException, std::exception )
247 return getImplementationName_Static();
250 OUString FormattedString::getImplementationName_Static()
252 return OUString("com.sun.star.comp.chart.FormattedString");
255 sal_Bool SAL_CALL FormattedString::supportsService( const OUString& rServiceName )
256 throw( css::uno::RuntimeException, std::exception )
258 return cppu::supportsService(this, rServiceName);
261 css::uno::Sequence< OUString > SAL_CALL FormattedString::getSupportedServiceNames()
262 throw( css::uno::RuntimeException, std::exception )
264 return getSupportedServiceNames_Static();
267 } // namespace chart
269 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * SAL_CALL
270 com_sun_star_comp_chart_FormattedString_get_implementation(css::uno::XComponentContext *context,
271 css::uno::Sequence<css::uno::Any> const &)
273 return cppu::acquire(new ::chart::FormattedString(context));
276 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */