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"
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
;
50 const Sequence
< Property
> & lcl_GetPropertySequence()
52 static Sequence
< Property
> aPropSeq
;
55 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
56 if( 0 == aPropSeq
.getLength() )
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
);
73 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
75 static ::cppu::OPropertyArrayHelper
aArrayHelper(
76 lcl_GetPropertySequence(),
77 /* bSorted = */ sal_True
);
82 } // anonymous namespace
87 FormattedString::FormattedString(
88 uno::Reference
< uno::XComponentContext
> const & /* xContext */ ) :
89 ::property::OPropertySet( m_aMutex
),
91 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
94 FormattedString::FormattedString( const FormattedString
& rOther
) :
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
)
117 MutexGuard
aGuard( GetMutex());
122 void SAL_CALL
FormattedString::setString( const ::rtl::OUString
& String
)
123 throw (uno::RuntimeException
)
126 MutexGuard
aGuard( GetMutex());
129 //don't keep the mutex locked while calling out
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
)
177 // ____ OPropertySet ____
178 void FormattedString::firePropertyChangeEvent()
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" );
200 // ____ OPropertySet ____
201 uno::Any
FormattedString::GetDefaultValue( sal_Int32 nHandle
) const
202 throw(beans::UnknownPropertyException
)
204 static tPropertyValueMap aStaticDefaults
;
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
;
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
;
239 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
242 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
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" ));