1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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"
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
;
53 const Sequence
< Property
> & lcl_GetPropertySequence()
55 static Sequence
< Property
> aPropSeq
;
58 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
59 if( 0 == aPropSeq
.getLength() )
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
);
76 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
78 static ::cppu::OPropertyArrayHelper
aArrayHelper(
79 lcl_GetPropertySequence(),
80 /* bSorted = */ sal_True
);
85 } // anonymous namespace
90 FormattedString::FormattedString(
91 uno::Reference
< uno::XComponentContext
> const & /* xContext */ ) :
92 ::property::OPropertySet( m_aMutex
),
94 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
97 FormattedString::FormattedString( const FormattedString
& rOther
) :
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
)
120 MutexGuard
aGuard( GetMutex());
125 void SAL_CALL
FormattedString::setString( const ::rtl::OUString
& String
)
126 throw (uno::RuntimeException
)
129 MutexGuard
aGuard( GetMutex());
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
)
178 // ____ OPropertySet ____
179 void FormattedString::firePropertyChangeEvent()
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" );
201 // ____ OPropertySet ____
202 uno::Any
FormattedString::GetDefaultValue( sal_Int32 nHandle
) const
203 throw(beans::UnknownPropertyException
)
205 static tPropertyValueMap aStaticDefaults
;
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
;
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
;
240 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
243 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
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" ));