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