merge the formfield patch from ooo-build
[ooovba.git] / chart2 / source / model / main / FormattedString.cxx
blobad034ea7627f1b05673c12e29787853743cf0815
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: FormattedString.cxx,v $
10 * $Revision: 1.9.44.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
33 #include "FormattedString.hxx"
34 #include "ContainerHelper.hxx"
36 #include "CharacterProperties.hxx"
37 #include "PropertyHelper.hxx"
38 #include "macros.hxx"
39 #include <com/sun/star/beans/PropertyAttribute.hpp>
41 using namespace ::com::sun::star;
43 using ::rtl::OUString;
44 using ::com::sun::star::beans::Property;
45 using ::com::sun::star::uno::Sequence;
46 using ::com::sun::star::uno::Reference;
47 using ::com::sun::star::uno::Any;
48 using ::osl::MutexGuard;
50 namespace
53 const Sequence< Property > & lcl_GetPropertySequence()
55 static Sequence< Property > aPropSeq;
57 // /--
58 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
59 if( 0 == aPropSeq.getLength() )
61 // get properties
62 ::std::vector< ::com::sun::star::beans::Property > aProperties;
63 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
65 // and sort them for access via bsearch
66 ::std::sort( aProperties.begin(), aProperties.end(),
67 ::chart::PropertyNameLess() );
69 // transfer result to static Sequence
70 aPropSeq = ::chart::ContainerHelper::ContainerToSequence( aProperties );
73 return aPropSeq;
76 ::cppu::IPropertyArrayHelper & lcl_getInfoHelper()
78 static ::cppu::OPropertyArrayHelper aArrayHelper(
79 lcl_GetPropertySequence(),
80 /* bSorted = */ sal_True );
82 return aArrayHelper;
85 } // anonymous namespace
87 namespace chart
90 FormattedString::FormattedString(
91 uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
92 ::property::OPropertySet( m_aMutex ),
93 m_aString(),
94 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
97 FormattedString::FormattedString( const FormattedString & rOther ) :
98 MutexContainer(),
99 impl::FormattedString_Base(),
100 ::property::OPropertySet( rOther, m_aMutex ),
101 m_aString( rOther.m_aString ),
102 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
105 FormattedString::~FormattedString()
108 // ____ XCloneable ____
109 uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
110 throw (uno::RuntimeException)
112 return uno::Reference< util::XCloneable >( new FormattedString( *this ));
115 // ____ XFormattedString ____
116 ::rtl::OUString SAL_CALL FormattedString::getString()
117 throw (uno::RuntimeException)
119 // /--
120 MutexGuard aGuard( GetMutex());
121 return m_aString;
122 // \--
125 void SAL_CALL FormattedString::setString( const ::rtl::OUString& String )
126 throw (uno::RuntimeException)
128 // /--
129 MutexGuard aGuard( GetMutex());
130 m_aString = String;
131 fireModifyEvent();
132 // \--
135 // ____ XModifyBroadcaster ____
136 void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
137 throw (uno::RuntimeException)
141 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
142 xBroadcaster->addModifyListener( aListener );
144 catch( const uno::Exception & ex )
146 ASSERT_EXCEPTION( ex );
150 void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
151 throw (uno::RuntimeException)
155 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
156 xBroadcaster->removeModifyListener( aListener );
158 catch( const uno::Exception & ex )
160 ASSERT_EXCEPTION( ex );
164 // ____ XModifyListener ____
165 void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
166 throw (uno::RuntimeException)
168 m_xModifyEventForwarder->modified( aEvent );
171 // ____ XEventListener (base of XModifyListener) ____
172 void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
173 throw (uno::RuntimeException)
175 // nothing
178 // ____ OPropertySet ____
179 void FormattedString::firePropertyChangeEvent()
181 fireModifyEvent();
184 void FormattedString::fireModifyEvent()
186 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
190 // ----------------------------------------
192 Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
194 Sequence< OUString > aServices( 2 );
196 aServices[ 0 ] = C2U( "com.sun.star.chart2.FormattedString" );
197 aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
198 return aServices;
201 // ____ OPropertySet ____
202 uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
203 throw(beans::UnknownPropertyException)
205 static tPropertyValueMap aStaticDefaults;
207 // /--
208 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
209 if( 0 == aStaticDefaults.size() )
211 // initialize defaults
212 CharacterProperties::AddDefaultsToMap( aStaticDefaults );
215 tPropertyValueMap::const_iterator aFound(
216 aStaticDefaults.find( nHandle ));
218 if( aFound == aStaticDefaults.end())
219 throw beans::UnknownPropertyException();
221 return (*aFound).second;
222 // \--
225 // ____ OPropertySet ____
226 ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
228 return lcl_getInfoHelper();
232 // ____ XPropertySet ____
233 uno::Reference< beans::XPropertySetInfo > SAL_CALL
234 FormattedString::getPropertySetInfo()
235 throw (uno::RuntimeException)
237 static uno::Reference< beans::XPropertySetInfo > xInfo;
239 // /--
240 ::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
241 if( !xInfo.is())
243 xInfo = ::cppu::OPropertySetHelper::createPropertySetInfo(
244 getInfoHelper());
247 return xInfo;
248 // \--
251 // ================================================================================
253 using impl::FormattedString_Base;
255 IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
256 IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
258 // do this in derived classes!
260 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
261 APPHELPER_XSERVICEINFO_IMPL( FormattedString,
262 C2U( "com.sun.star.comp.chart.FormattedString" ));
264 } // namespace chart