xref: /aoo4110/main/chart2/source/model/main/Title.cxx (revision b1cdbd2c)
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 "Title.hxx"
27 #include "macros.hxx"
28 #include "FormattedString.hxx"
29 #include "LineProperties.hxx"
30 #include "FillProperties.hxx"
31 #include "ContainerHelper.hxx"
32 #include "CloneHelper.hxx"
33 #include "PropertyHelper.hxx"
34 #include <com/sun/star/beans/PropertyAttribute.hpp>
35 #include <com/sun/star/style/ParagraphAdjust.hpp>
36 #include <com/sun/star/drawing/FillStyle.hpp>
37 #include <com/sun/star/drawing/LineStyle.hpp>
38 #include <com/sun/star/chart2/RelativePosition.hpp>
39 #include <com/sun/star/awt/Size.hpp>
40 #include <rtl/uuid.h>
41 #include <cppuhelper/queryinterface.hxx>
42 
43 #include <vector>
44 #include <algorithm>
45 
46 using namespace ::com::sun::star;
47 using namespace ::com::sun::star::beans::PropertyAttribute;
48 
49 using ::com::sun::star::beans::Property;
50 using ::osl::MutexGuard;
51 
52 namespace
53 {
54 
55 static const ::rtl::OUString lcl_aServiceName(
56     RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Title" ));
57 
58 enum
59 {
60     PROP_TITLE_PARA_ADJUST,
61     PROP_TITLE_PARA_LAST_LINE_ADJUST,
62     PROP_TITLE_PARA_LEFT_MARGIN,
63     PROP_TITLE_PARA_RIGHT_MARGIN,
64     PROP_TITLE_PARA_TOP_MARGIN,
65     PROP_TITLE_PARA_BOTTOM_MARGIN,
66     PROP_TITLE_PARA_IS_HYPHENATION,
67 
68     PROP_TITLE_TEXT_ROTATION,
69     PROP_TITLE_TEXT_STACKED,
70     PROP_TITLE_REL_POS,
71 
72     PROP_TITLE_REF_PAGE_SIZE
73 };
74 
lcl_AddPropertiesToVector(::std::vector<Property> & rOutProperties)75 void lcl_AddPropertiesToVector(
76     ::std::vector< Property > & rOutProperties )
77 {
78     rOutProperties.push_back(
79         Property( C2U( "ParaAdjust" ),
80                   PROP_TITLE_PARA_ADJUST,
81                   ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust * >(0)),
82                   beans::PropertyAttribute::BOUND
83                   | beans::PropertyAttribute::MAYBEDEFAULT ));
84 
85     rOutProperties.push_back(
86         Property( C2U( "ParaLastLineAdjust" ),
87                   PROP_TITLE_PARA_LAST_LINE_ADJUST,
88                   ::getCppuType( reinterpret_cast< sal_Int16 * >(0)),
89                   beans::PropertyAttribute::BOUND
90                   | beans::PropertyAttribute::MAYBEDEFAULT ));
91 
92     rOutProperties.push_back(
93         Property( C2U( "ParaLeftMargin" ),
94                   PROP_TITLE_PARA_LEFT_MARGIN,
95                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
96                   beans::PropertyAttribute::BOUND
97                   | beans::PropertyAttribute::MAYBEDEFAULT ));
98 
99     rOutProperties.push_back(
100         Property( C2U( "ParaRightMargin" ),
101                   PROP_TITLE_PARA_RIGHT_MARGIN,
102                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
103                   beans::PropertyAttribute::BOUND
104                   | beans::PropertyAttribute::MAYBEDEFAULT ));
105 
106     rOutProperties.push_back(
107         Property( C2U( "ParaTopMargin" ),
108                   PROP_TITLE_PARA_TOP_MARGIN,
109                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
110                   beans::PropertyAttribute::BOUND
111                   | beans::PropertyAttribute::MAYBEDEFAULT ));
112 
113     rOutProperties.push_back(
114         Property( C2U( "ParaBottomMargin" ),
115                   PROP_TITLE_PARA_BOTTOM_MARGIN,
116                   ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
117                   beans::PropertyAttribute::BOUND
118                   | beans::PropertyAttribute::MAYBEDEFAULT ));
119 
120     rOutProperties.push_back(
121         Property( C2U( "ParaIsHyphenation" ),
122                   PROP_TITLE_PARA_IS_HYPHENATION,
123                   ::getBooleanCppuType(),
124                   beans::PropertyAttribute::BOUND
125                   | beans::PropertyAttribute::MAYBEDEFAULT ));
126 
127     rOutProperties.push_back(
128         Property( C2U( "TextRotation" ),
129                   PROP_TITLE_TEXT_ROTATION,
130                   ::getCppuType( reinterpret_cast< const double * >(0)),
131                   beans::PropertyAttribute::BOUND
132                   | beans::PropertyAttribute::MAYBEDEFAULT ));
133     rOutProperties.push_back(
134         Property( C2U( "StackCharacters" ),
135                   PROP_TITLE_TEXT_STACKED,
136                   ::getBooleanCppuType(),
137                   beans::PropertyAttribute::BOUND
138                   | beans::PropertyAttribute::MAYBEDEFAULT ));
139 
140     rOutProperties.push_back(
141         Property( C2U( "RelativePosition" ),
142                   PROP_TITLE_REL_POS,
143                   ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
144                   beans::PropertyAttribute::BOUND
145                   | beans::PropertyAttribute::MAYBEVOID ));
146 
147     rOutProperties.push_back(
148         Property( C2U( "ReferencePageSize" ),
149                   PROP_TITLE_REF_PAGE_SIZE,
150                   ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
151                   beans::PropertyAttribute::BOUND
152                   | beans::PropertyAttribute::MAYBEVOID ));
153 }
154 
155 struct StaticTitleDefaults_Initializer
156 {
operator ()__anonbe7b14290111::StaticTitleDefaults_Initializer157     ::chart::tPropertyValueMap* operator()()
158     {
159         static ::chart::tPropertyValueMap aStaticDefaults;
160         lcl_AddDefaultsToMap( aStaticDefaults );
161         return &aStaticDefaults;
162     }
163 private:
lcl_AddDefaultsToMap__anonbe7b14290111::StaticTitleDefaults_Initializer164     void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
165     {
166         ::chart::LineProperties::AddDefaultsToMap( rOutMap );
167         ::chart::FillProperties::AddDefaultsToMap( rOutMap );
168 
169         // ParagraphProperties
170         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST,
171                                                           ::com::sun::star::style::ParagraphAdjust_CENTER );
172         // PROP_TITLE_PARA_LAST_LINE_ADJUST
173 
174         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
175         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
176         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 );
177         ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
178         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true );
179 
180         // own properties
181         ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 );
182         ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false );
183 
184         // override other defaults
185         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
186         ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
187     }
188 };
189 
190 struct StaticTitleDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticTitleDefaults_Initializer >
191 {
192 };
193 
194 struct StaticTitleInfoHelper_Initializer
195 {
operator ()__anonbe7b14290111::StaticTitleInfoHelper_Initializer196     ::cppu::OPropertyArrayHelper* operator()()
197     {
198         static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
199         return &aPropHelper;
200     }
201 
202 private:
lcl_GetPropertySequence__anonbe7b14290111::StaticTitleInfoHelper_Initializer203     uno::Sequence< Property > lcl_GetPropertySequence()
204     {
205         ::std::vector< ::com::sun::star::beans::Property > aProperties;
206         lcl_AddPropertiesToVector( aProperties );
207         ::chart::LineProperties::AddPropertiesToVector( aProperties );
208         ::chart::FillProperties::AddPropertiesToVector( aProperties );
209 
210         ::std::sort( aProperties.begin(), aProperties.end(),
211                      ::chart::PropertyNameLess() );
212 
213         return ::chart::ContainerHelper::ContainerToSequence( aProperties );
214     }
215 
216 
217 };
218 
219 struct StaticTitleInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticTitleInfoHelper_Initializer >
220 {
221 };
222 
223 struct StaticTitleInfo_Initializer
224 {
operator ()__anonbe7b14290111::StaticTitleInfo_Initializer225     uno::Reference< beans::XPropertySetInfo >* operator()()
226     {
227         static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
228             ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticTitleInfoHelper::get() ) );
229         return &xPropertySetInfo;
230     }
231 };
232 
233 struct StaticTitleInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticTitleInfo_Initializer >
234 {
235 };
236 
237 } // anonymous namespace
238 
239 // ================================================================================
240 
241 namespace chart
242 {
243 
Title(uno::Reference<uno::XComponentContext> const &)244 Title::Title( uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
245         ::property::OPropertySet( m_aMutex ),
246         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
247 {}
248 
Title(const Title & rOther)249 Title::Title( const Title & rOther ) :
250         MutexContainer(),
251         impl::Title_Base(),
252         ::property::OPropertySet( rOther, m_aMutex ),
253         m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
254 {
255     CloneHelper::CloneRefSequence< uno::Reference< chart2::XFormattedString > >(
256         rOther.m_aStrings, m_aStrings );
257     ModifyListenerHelper::addListenerToAllElements(
258         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
259 }
260 
~Title()261 Title::~Title()
262 {
263     ModifyListenerHelper::removeListenerFromAllElements(
264         ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
265 }
266 
267 // ____ XCloneable ____
createClone()268 uno::Reference< util::XCloneable > SAL_CALL Title::createClone()
269     throw (uno::RuntimeException)
270 {
271     return uno::Reference< util::XCloneable >( new Title( *this ));
272 }
273 
274 // --------------------------------------------------------------------------------
275 
276 // ____ XTitle ____
getText()277 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
278     throw (uno::RuntimeException)
279 {
280     MutexGuard aGuard( GetMutex() );
281     return m_aStrings;
282 }
283 
setText(const uno::Sequence<uno::Reference<chart2::XFormattedString>> & rNewStrings)284 void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
285     throw (uno::RuntimeException)
286 {
287     uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
288     {
289         MutexGuard aGuard( GetMutex() );
290         std::swap( m_aStrings, aOldStrings );
291         m_aStrings = rNewStrings;
292     }
293     //don't keep the mutex locked while calling out
294     ModifyListenerHelper::removeListenerFromAllElements(
295         ContainerHelper::SequenceToVector( aOldStrings ), m_xModifyEventForwarder );
296     ModifyListenerHelper::addListenerToAllElements(
297         ContainerHelper::SequenceToVector( rNewStrings ), m_xModifyEventForwarder );
298     fireModifyEvent();
299 }
300 
301 // ================================================================================
302 
303 // ____ OPropertySet ____
GetDefaultValue(sal_Int32 nHandle) const304 uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const
305     throw(beans::UnknownPropertyException)
306 {
307     const tPropertyValueMap& rStaticDefaults = *StaticTitleDefaults::get();
308     tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
309     if( aFound == rStaticDefaults.end() )
310         return uno::Any();
311     return (*aFound).second;
312 }
313 
getInfoHelper()314 ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
315 {
316     return *StaticTitleInfoHelper::get();
317 }
318 
319 // ____ XPropertySet ____
getPropertySetInfo()320 uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo()
321     throw (uno::RuntimeException)
322 {
323     return *StaticTitleInfo::get();
324 }
325 
326 // ____ XModifyBroadcaster ____
addModifyListener(const uno::Reference<util::XModifyListener> & aListener)327 void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
328     throw (uno::RuntimeException)
329 {
330     try
331     {
332         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
333         xBroadcaster->addModifyListener( aListener );
334     }
335     catch( const uno::Exception & ex )
336     {
337         ASSERT_EXCEPTION( ex );
338     }
339 }
340 
removeModifyListener(const uno::Reference<util::XModifyListener> & aListener)341 void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
342     throw (uno::RuntimeException)
343 {
344     try
345     {
346         uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
347         xBroadcaster->removeModifyListener( aListener );
348     }
349     catch( const uno::Exception & ex )
350     {
351         ASSERT_EXCEPTION( ex );
352     }
353 }
354 
355 // ____ XModifyListener ____
modified(const lang::EventObject & aEvent)356 void SAL_CALL Title::modified( const lang::EventObject& aEvent )
357     throw (uno::RuntimeException)
358 {
359     m_xModifyEventForwarder->modified( aEvent );
360 }
361 
362 // ____ XEventListener (base of XModifyListener) ____
disposing(const lang::EventObject &)363 void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
364     throw (uno::RuntimeException)
365 {
366     // nothing
367 }
368 
369 // ____ OPropertySet ____
firePropertyChangeEvent()370 void Title::firePropertyChangeEvent()
371 {
372     fireModifyEvent();
373 }
374 
fireModifyEvent()375 void Title::fireModifyEvent()
376 {
377     m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
378 }
379 
380 
381 // ================================================================================
382 
getSupportedServiceNames_Static()383 uno::Sequence< ::rtl::OUString > Title::getSupportedServiceNames_Static()
384 {
385     uno::Sequence< ::rtl::OUString > aServices( 4 );
386     aServices[ 0 ] = C2U( "com.sun.star.chart2.Title" );
387     aServices[ 1 ] = C2U( "com.sun.star.style.ParagraphProperties" );
388     aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
389     aServices[ 3 ] = C2U( "com.sun.star.layout.LayoutElement" );
390     return aServices;
391 }
392 
393 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
394 APPHELPER_XSERVICEINFO_IMPL( Title, lcl_aServiceName );
395 
396 // needed by MSC compiler
397 using impl::Title_Base;
398 
399 IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
400 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
401 
402 } //  namespace chart
403