1*cde9e8dcSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*cde9e8dcSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*cde9e8dcSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*cde9e8dcSAndrew Rist  * distributed with this work for additional information
6*cde9e8dcSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*cde9e8dcSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*cde9e8dcSAndrew Rist  * "License"); you may not use this file except in compliance
9*cde9e8dcSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*cde9e8dcSAndrew Rist  *
11*cde9e8dcSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*cde9e8dcSAndrew Rist  *
13*cde9e8dcSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*cde9e8dcSAndrew Rist  * software distributed under the License is distributed on an
15*cde9e8dcSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*cde9e8dcSAndrew Rist  * KIND, either express or implied.  See the License for the
17*cde9e8dcSAndrew Rist  * specific language governing permissions and limitations
18*cde9e8dcSAndrew Rist  * under the License.
19*cde9e8dcSAndrew Rist  *
20*cde9e8dcSAndrew Rist  *************************************************************/
21*cde9e8dcSAndrew Rist 
22*cde9e8dcSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_chart2.hxx"
26cdf0e10cSrcweir #include "FormattedString.hxx"
27cdf0e10cSrcweir #include "ContainerHelper.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "CharacterProperties.hxx"
30cdf0e10cSrcweir #include "PropertyHelper.hxx"
31cdf0e10cSrcweir #include "macros.hxx"
32cdf0e10cSrcweir #include <com/sun/star/beans/PropertyAttribute.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir using ::rtl::OUString;
37cdf0e10cSrcweir using ::com::sun::star::beans::Property;
38cdf0e10cSrcweir using ::com::sun::star::uno::Sequence;
39cdf0e10cSrcweir using ::com::sun::star::uno::Reference;
40cdf0e10cSrcweir using ::com::sun::star::uno::Any;
41cdf0e10cSrcweir using ::osl::MutexGuard;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir namespace
44cdf0e10cSrcweir {
45cdf0e10cSrcweir 
46cdf0e10cSrcweir struct StaticFormattedStringDefaults_Initializer
47cdf0e10cSrcweir {
operator ()__anon17c9719c0111::StaticFormattedStringDefaults_Initializer48cdf0e10cSrcweir     ::chart::tPropertyValueMap* operator()()
49cdf0e10cSrcweir     {
50cdf0e10cSrcweir         static ::chart::tPropertyValueMap aStaticDefaults;
51cdf0e10cSrcweir         lcl_AddDefaultsToMap( aStaticDefaults );
52cdf0e10cSrcweir         return &aStaticDefaults;
53cdf0e10cSrcweir     }
54cdf0e10cSrcweir private:
lcl_AddDefaultsToMap__anon17c9719c0111::StaticFormattedStringDefaults_Initializer55cdf0e10cSrcweir     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
56cdf0e10cSrcweir     {
57cdf0e10cSrcweir         ::chart::CharacterProperties::AddDefaultsToMap( rOutMap );
58cdf0e10cSrcweir     }
59cdf0e10cSrcweir };
60cdf0e10cSrcweir 
61cdf0e10cSrcweir struct StaticFormattedStringDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticFormattedStringDefaults_Initializer >
62cdf0e10cSrcweir {
63cdf0e10cSrcweir };
64cdf0e10cSrcweir 
65cdf0e10cSrcweir struct StaticFormattedStringInfoHelper_Initializer
66cdf0e10cSrcweir {
operator ()__anon17c9719c0111::StaticFormattedStringInfoHelper_Initializer67cdf0e10cSrcweir     ::cppu::OPropertyArrayHelper* operator()()
68cdf0e10cSrcweir     {
69cdf0e10cSrcweir         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
70cdf0e10cSrcweir         return &aPropHelper;
71cdf0e10cSrcweir     }
72cdf0e10cSrcweir 
73cdf0e10cSrcweir private:
lcl_GetPropertySequence__anon17c9719c0111::StaticFormattedStringInfoHelper_Initializer74cdf0e10cSrcweir     Sequence< Property > lcl_GetPropertySequence()
75cdf0e10cSrcweir     {
76cdf0e10cSrcweir         ::std::vector< ::com::sun::star::beans::Property > aProperties;
77cdf0e10cSrcweir         ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
78cdf0e10cSrcweir 
79cdf0e10cSrcweir         ::std::sort( aProperties.begin(), aProperties.end(),
80cdf0e10cSrcweir                      ::chart::PropertyNameLess() );
81cdf0e10cSrcweir 
82cdf0e10cSrcweir         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir };
86cdf0e10cSrcweir 
87cdf0e10cSrcweir struct StaticFormattedStringInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticFormattedStringInfoHelper_Initializer >
88cdf0e10cSrcweir {
89cdf0e10cSrcweir };
90cdf0e10cSrcweir 
91cdf0e10cSrcweir struct StaticFormattedStringInfo_Initializer
92cdf0e10cSrcweir {
operator ()__anon17c9719c0111::StaticFormattedStringInfo_Initializer93cdf0e10cSrcweir     uno::Reference< beans::XPropertySetInfo >* operator()()
94cdf0e10cSrcweir     {
95cdf0e10cSrcweir         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
96cdf0e10cSrcweir             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticFormattedStringInfoHelper::get() ) );
97cdf0e10cSrcweir         return &xPropertySetInfo;
98cdf0e10cSrcweir     }
99cdf0e10cSrcweir };
100cdf0e10cSrcweir 
101cdf0e10cSrcweir struct StaticFormattedStringInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticFormattedStringInfo_Initializer >
102cdf0e10cSrcweir {
103cdf0e10cSrcweir };
104cdf0e10cSrcweir 
105cdf0e10cSrcweir } // anonymous namespace
106cdf0e10cSrcweir 
107cdf0e10cSrcweir namespace chart
108cdf0e10cSrcweir {
109cdf0e10cSrcweir 
FormattedString(uno::Reference<uno::XComponentContext> const &)110cdf0e10cSrcweir FormattedString::FormattedString(
111cdf0e10cSrcweir         uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
112cdf0e10cSrcweir         ::property::OPropertySet( m_aMutex ),
113cdf0e10cSrcweir     m_aString(),
114cdf0e10cSrcweir     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
115cdf0e10cSrcweir {}
116cdf0e10cSrcweir 
FormattedString(const FormattedString & rOther)117cdf0e10cSrcweir FormattedString::FormattedString( const FormattedString & rOther ) :
118cdf0e10cSrcweir         MutexContainer(),
119cdf0e10cSrcweir         impl::FormattedString_Base(),
120cdf0e10cSrcweir         ::property::OPropertySet( rOther, m_aMutex ),
121cdf0e10cSrcweir     m_aString( rOther.m_aString ),
122cdf0e10cSrcweir     m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
123cdf0e10cSrcweir {}
124cdf0e10cSrcweir 
~FormattedString()125cdf0e10cSrcweir FormattedString::~FormattedString()
126cdf0e10cSrcweir {}
127cdf0e10cSrcweir 
128cdf0e10cSrcweir // ____ XCloneable ____
createClone()129cdf0e10cSrcweir uno::Reference< util::XCloneable > SAL_CALL FormattedString::createClone()
130cdf0e10cSrcweir     throw (uno::RuntimeException)
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     return uno::Reference< util::XCloneable >( new FormattedString( *this ));
133cdf0e10cSrcweir }
134cdf0e10cSrcweir 
135cdf0e10cSrcweir // ____ XFormattedString ____
getString()136cdf0e10cSrcweir ::rtl::OUString SAL_CALL FormattedString::getString()
137cdf0e10cSrcweir     throw (uno::RuntimeException)
138cdf0e10cSrcweir {
139cdf0e10cSrcweir     // /--
140cdf0e10cSrcweir     MutexGuard aGuard( GetMutex());
141cdf0e10cSrcweir     return m_aString;
142cdf0e10cSrcweir     // \--
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
setString(const::rtl::OUString & String)145cdf0e10cSrcweir void SAL_CALL FormattedString::setString( const ::rtl::OUString& String )
146cdf0e10cSrcweir     throw (uno::RuntimeException)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir     {
149cdf0e10cSrcweir         MutexGuard aGuard( GetMutex());
150cdf0e10cSrcweir         m_aString = String;
151cdf0e10cSrcweir     }
152cdf0e10cSrcweir     //don't keep the mutex locked while calling out
153cdf0e10cSrcweir     fireModifyEvent();
154cdf0e10cSrcweir 
155cdf0e10cSrcweir }
156cdf0e10cSrcweir 
157cdf0e10cSrcweir // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)158cdf0e10cSrcweir void SAL_CALL FormattedString::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
159cdf0e10cSrcweir     throw (uno::RuntimeException)
160cdf0e10cSrcweir {
161cdf0e10cSrcweir     try
162cdf0e10cSrcweir     {
163cdf0e10cSrcweir         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
164cdf0e10cSrcweir         xBroadcaster->addModifyListener( aListener );
165cdf0e10cSrcweir     }
166cdf0e10cSrcweir     catch( const uno::Exception & ex )
167cdf0e10cSrcweir     {
168cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
169cdf0e10cSrcweir     }
170cdf0e10cSrcweir }
171cdf0e10cSrcweir 
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)172cdf0e10cSrcweir void SAL_CALL FormattedString::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
173cdf0e10cSrcweir     throw (uno::RuntimeException)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir     try
176cdf0e10cSrcweir     {
177cdf0e10cSrcweir         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
178cdf0e10cSrcweir         xBroadcaster->removeModifyListener( aListener );
179cdf0e10cSrcweir     }
180cdf0e10cSrcweir     catch( const uno::Exception & ex )
181cdf0e10cSrcweir     {
182cdf0e10cSrcweir         ASSERT_EXCEPTION( ex );
183cdf0e10cSrcweir     }
184cdf0e10cSrcweir }
185cdf0e10cSrcweir 
186cdf0e10cSrcweir // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)187cdf0e10cSrcweir void SAL_CALL FormattedString::modified( const lang::EventObject& aEvent )
188cdf0e10cSrcweir     throw (uno::RuntimeException)
189cdf0e10cSrcweir {
190cdf0e10cSrcweir     m_xModifyEventForwarder->modified( aEvent );
191cdf0e10cSrcweir }
192cdf0e10cSrcweir 
193cdf0e10cSrcweir // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)194cdf0e10cSrcweir void SAL_CALL FormattedString::disposing( const lang::EventObject& /* Source */ )
195cdf0e10cSrcweir     throw (uno::RuntimeException)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     // nothing
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir // ____ OPropertySet ____
firePropertyChangeEvent()201cdf0e10cSrcweir void FormattedString::firePropertyChangeEvent()
202cdf0e10cSrcweir {
203cdf0e10cSrcweir     fireModifyEvent();
204cdf0e10cSrcweir }
205cdf0e10cSrcweir 
fireModifyEvent()206cdf0e10cSrcweir void FormattedString::fireModifyEvent()
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
211cdf0e10cSrcweir 
212cdf0e10cSrcweir // ----------------------------------------
213cdf0e10cSrcweir 
getSupportedServiceNames_Static()214cdf0e10cSrcweir Sequence< OUString > FormattedString::getSupportedServiceNames_Static()
215cdf0e10cSrcweir {
216cdf0e10cSrcweir     Sequence< OUString > aServices( 2 );
217cdf0e10cSrcweir 
218cdf0e10cSrcweir     aServices[ 0 ] = C2U( "com.sun.star.chart2.FormattedString" );
219cdf0e10cSrcweir     aServices[ 1 ] = C2U( "com.sun.star.beans.PropertySet" );
220cdf0e10cSrcweir     return aServices;
221cdf0e10cSrcweir }
222cdf0e10cSrcweir 
223cdf0e10cSrcweir // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const224cdf0e10cSrcweir uno::Any FormattedString::GetDefaultValue( sal_Int32 nHandle ) const
225cdf0e10cSrcweir     throw(beans::UnknownPropertyException)
226cdf0e10cSrcweir {
227cdf0e10cSrcweir     const tPropertyValueMap& rStaticDefaults = *StaticFormattedStringDefaults::get();
228cdf0e10cSrcweir     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
229cdf0e10cSrcweir     if( aFound == rStaticDefaults.end() )
230cdf0e10cSrcweir         return uno::Any();
231cdf0e10cSrcweir     return (*aFound).second;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir // ____ OPropertySet ____
getInfoHelper()235cdf0e10cSrcweir ::cppu::IPropertyArrayHelper & SAL_CALL FormattedString::getInfoHelper()
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     return *StaticFormattedStringInfoHelper::get();
238cdf0e10cSrcweir }
239cdf0e10cSrcweir 
240cdf0e10cSrcweir 
241cdf0e10cSrcweir // ____ XPropertySet ____
getPropertySetInfo()242cdf0e10cSrcweir uno::Reference< beans::XPropertySetInfo > SAL_CALL FormattedString::getPropertySetInfo()
243cdf0e10cSrcweir     throw (uno::RuntimeException)
244cdf0e10cSrcweir {
245cdf0e10cSrcweir     return *StaticFormattedStringInfo::get();
246cdf0e10cSrcweir }
247cdf0e10cSrcweir 
248cdf0e10cSrcweir // ================================================================================
249cdf0e10cSrcweir 
250cdf0e10cSrcweir using impl::FormattedString_Base;
251cdf0e10cSrcweir 
252cdf0e10cSrcweir IMPLEMENT_FORWARD_XINTERFACE2( FormattedString, FormattedString_Base, ::property::OPropertySet )
253cdf0e10cSrcweir IMPLEMENT_FORWARD_XTYPEPROVIDER2( FormattedString, FormattedString_Base, ::property::OPropertySet )
254cdf0e10cSrcweir 
255cdf0e10cSrcweir // do this in derived classes!
256cdf0e10cSrcweir 
257cdf0e10cSrcweir // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
258cdf0e10cSrcweir APPHELPER_XSERVICEINFO_IMPL( FormattedString,
259cdf0e10cSrcweir                              C2U( "com.sun.star.comp.chart.FormattedString" ));
260cdf0e10cSrcweir 
261cdf0e10cSrcweir } //  namespace chart
262