merged tag ooo/OOO330_m14
[LibreOffice.git] / chart2 / source / model / main / FormattedString.cxx
blob9d38fafd3cf72bf64e30aab5b51299ef48bcc5b1
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
30 #include "FormattedString.hxx"
31 #include "ContainerHelper.hxx"
33 #include "CharacterProperties.hxx"
34 #include "PropertyHelper.hxx"
35 #include "macros.hxx"
36 #include <com/sun/star/beans/PropertyAttribute.hpp>
38 using namespace ::com::sun::star;
40 using ::rtl::OUString;
41 using ::com::sun::star::beans::Property;
42 using ::com::sun::star::uno::Sequence;
43 using ::com::sun::star::uno::Reference;
44 using ::com::sun::star::uno::Any;
45 using ::osl::MutexGuard;
47 namespace
50 const Sequence< Property > & lcl_GetPropertySequence()
52 static Sequence< Property > aPropSeq;
54 // /--
55 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
56 if( 0 == aPropSeq.getLength() )
58 // get properties
59 ::std::vector< ::com::sun::star::beans::Property > aProperties;
60 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
62 // and sort them for access via bsearch
63 ::std::sort( aProperties.begin(), aProperties.end(),
64 ::chart::PropertyNameLess() );
66 // transfer result to static Sequence
67 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
70 return aPropSeq;
73 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
75 static ::cppu::OPropertyArrayHelper aArrayHelper(
76 lcl_GetPropertySequence(),
77 /* bSorted = */ sal_True );
79 return aArrayHelper;
82 } // anonymous namespace
84 namespace chart
87 FormattedString::FormattedString(
88 uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
89 ::property::OPropertySet( m_aMutex ),
90 m_aString(),
91 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
94 FormattedString::FormattedString( const FormattedString & rOther ) :
95 MutexContainer(),
96 impl::FormattedString_Base(),
97 ::property::OPropertySet( rOther, m_aMutex ),
98 m_aString( rOther.m_aString ),
99 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
102 FormattedString::~FormattedString()
105 // ____ XCloneable ____
106 uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
107 throw (uno::RuntimeException)
109 return uno::Reference< util::XCloneable >( new FormattedString( *this ));
112 // ____ XFormattedString ____
113 ::rtl::OUString SAL_CALL FormattedString::getString()
114 throw (uno::RuntimeException)
116 // /--
117 MutexGuard aGuard( GetMutex());
118 return m_aString;
119 // \--
122 void SAL_CALL FormattedString::setString( const ::rtl::OUString& String )
123 throw (uno::RuntimeException)
126 MutexGuard aGuard( GetMutex());
127 m_aString = String;
129 //don't keep the mutex locked while calling out
130 fireModifyEvent();
134 // ____ XModifyBroadcaster ____
135 void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
136 throw (uno::RuntimeException)
140 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
141 xBroadcaster->addModifyListener( aListener );
143 catch( const uno::Exception & ex )
145 ASSERT_EXCEPTION( ex );
149 void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
150 throw (uno::RuntimeException)
154 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
155 xBroadcaster->removeModifyListener( aListener );
157 catch( const uno::Exception & ex )
159 ASSERT_EXCEPTION( ex );
163 // ____ XModifyListener ____
164 void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
165 throw (uno::RuntimeException)
167 m_xModifyEventForwarder->modified( aEvent );
170 // ____ XEventListener (base of XModifyListener) ____
171 void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
172 throw (uno::RuntimeException)
174 // nothing
177 // ____ OPropertySet ____
178 void FormattedString::firePropertyChangeEvent()
180 fireModifyEvent();
183 void FormattedString::fireModifyEvent()
185 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
189 // ----------------------------------------
191 Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
193 Sequence< OUString > aServices( 2 );
195 aServices[ 0 ] = C2U( "com.sun.star.chart2.FormattedString" );
196 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
197 return aServices;
200 // ____ OPropertySet ____
201 uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
202 throw(beans::UnknownPropertyException)
204 static tPropertyValueMap aStaticDefaults;
206 // /--
207 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
208 if( 0 == aStaticDefaults.size() )
210 // initialize defaults
211 CharacterProperties::AddDefaultsToMap( aStaticDefaults );
214 tPropertyValueMap::const_iterator aFound(
215 aStaticDefaults.find( nHandle ));
217 if( aFound == aStaticDefaults.end())
218 throw beans::UnknownPropertyException();
220 return (*aFound).second;
221 // \--
224 // ____ OPropertySet ____
225 ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
227 return lcl_getInfoHelper();
231 // ____ XPropertySet ____
232 uno::Reference< beans::XPropertySetInfo > SAL_CALL
233 FormattedString::getPropertySetInfo()
234 throw (uno::RuntimeException)
236 static uno::Reference< beans::XPropertySetInfo > xInfo;
238 // /--
239 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
240 if( !xInfo.is())
242 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
243 getInfoHelper());
246 return xInfo;
247 // \--
250 // ================================================================================
252 using impl::FormattedString_Base;
254 IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
255 IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
257 // do this in derived classes!
259 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
260 APPHELPER_XSERVICEINFO_IMPL( FormattedString,
261 C2U( "com.sun.star.comp.chart.FormattedString" ));
263 } // namespace chart