bump product version to 4.1.6.2
[LibreOffice.git] / chart2 / source / model / main / Title.cxx
blob346a967058afae2adc752841a8206706430c4ae3
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "Title.hxx"
21 #include "macros.hxx"
22 #include "FormattedString.hxx"
23 #include "LinePropertiesHelper.hxx"
24 #include "FillProperties.hxx"
25 #include "ContainerHelper.hxx"
26 #include "CloneHelper.hxx"
27 #include "PropertyHelper.hxx"
28 #include <com/sun/star/beans/PropertyAttribute.hpp>
29 #include <com/sun/star/style/ParagraphAdjust.hpp>
30 #include <com/sun/star/drawing/FillStyle.hpp>
31 #include <com/sun/star/drawing/LineStyle.hpp>
32 #include <com/sun/star/chart2/RelativePosition.hpp>
33 #include <com/sun/star/awt/Size.hpp>
34 #include <rtl/uuid.h>
35 #include <cppuhelper/queryinterface.hxx>
37 #include <vector>
38 #include <algorithm>
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::beans::PropertyAttribute;
43 using ::com::sun::star::beans::Property;
44 using ::osl::MutexGuard;
46 namespace
49 static const OUString lcl_aServiceName( "com.sun.star.comp.chart2.Title" );
51 enum
53 PROP_TITLE_PARA_ADJUST,
54 PROP_TITLE_PARA_LAST_LINE_ADJUST,
55 PROP_TITLE_PARA_LEFT_MARGIN,
56 PROP_TITLE_PARA_RIGHT_MARGIN,
57 PROP_TITLE_PARA_TOP_MARGIN,
58 PROP_TITLE_PARA_BOTTOM_MARGIN,
59 PROP_TITLE_PARA_IS_HYPHENATION,
61 PROP_TITLE_TEXT_ROTATION,
62 PROP_TITLE_TEXT_STACKED,
63 PROP_TITLE_REL_POS,
65 PROP_TITLE_REF_PAGE_SIZE
68 void lcl_AddPropertiesToVector(
69 ::std::vector< Property > & rOutProperties )
71 rOutProperties.push_back(
72 Property( "ParaAdjust",
73 PROP_TITLE_PARA_ADJUST,
74 ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust * >(0)),
75 beans::PropertyAttribute::BOUND
76 | beans::PropertyAttribute::MAYBEDEFAULT ));
78 rOutProperties.push_back(
79 Property( "ParaLastLineAdjust",
80 PROP_TITLE_PARA_LAST_LINE_ADJUST,
81 ::getCppuType( reinterpret_cast< sal_Int16 * >(0)),
82 beans::PropertyAttribute::BOUND
83 | beans::PropertyAttribute::MAYBEDEFAULT ));
85 rOutProperties.push_back(
86 Property( "ParaLeftMargin",
87 PROP_TITLE_PARA_LEFT_MARGIN,
88 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEDEFAULT ));
92 rOutProperties.push_back(
93 Property( "ParaRightMargin",
94 PROP_TITLE_PARA_RIGHT_MARGIN,
95 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEDEFAULT ));
99 rOutProperties.push_back(
100 Property( "ParaTopMargin",
101 PROP_TITLE_PARA_TOP_MARGIN,
102 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT ));
106 rOutProperties.push_back(
107 Property( "ParaBottomMargin",
108 PROP_TITLE_PARA_BOTTOM_MARGIN,
109 ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEDEFAULT ));
113 rOutProperties.push_back(
114 Property( "ParaIsHyphenation",
115 PROP_TITLE_PARA_IS_HYPHENATION,
116 ::getBooleanCppuType(),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::MAYBEDEFAULT ));
120 rOutProperties.push_back(
121 Property( "TextRotation",
122 PROP_TITLE_TEXT_ROTATION,
123 ::getCppuType( reinterpret_cast< const double * >(0)),
124 beans::PropertyAttribute::BOUND
125 | beans::PropertyAttribute::MAYBEDEFAULT ));
126 rOutProperties.push_back(
127 Property( "StackCharacters",
128 PROP_TITLE_TEXT_STACKED,
129 ::getBooleanCppuType(),
130 beans::PropertyAttribute::BOUND
131 | beans::PropertyAttribute::MAYBEDEFAULT ));
133 rOutProperties.push_back(
134 Property( "RelativePosition",
135 PROP_TITLE_REL_POS,
136 ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
137 beans::PropertyAttribute::BOUND
138 | beans::PropertyAttribute::MAYBEVOID ));
140 rOutProperties.push_back(
141 Property( "ReferencePageSize",
142 PROP_TITLE_REF_PAGE_SIZE,
143 ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
144 beans::PropertyAttribute::BOUND
145 | beans::PropertyAttribute::MAYBEVOID ));
148 struct StaticTitleDefaults_Initializer
150 ::chart::tPropertyValueMap* operator()()
152 static ::chart::tPropertyValueMap aStaticDefaults;
153 lcl_AddDefaultsToMap( aStaticDefaults );
154 return &aStaticDefaults;
156 private:
157 void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
159 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
160 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
162 // ParagraphProperties
163 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST,
164 ::com::sun::star::style::ParagraphAdjust_CENTER );
165 // PROP_TITLE_PARA_LAST_LINE_ADJUST
167 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
168 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
169 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 );
170 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
171 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true );
173 // own properties
174 ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 );
175 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false );
177 // override other defaults
178 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
179 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
183 struct StaticTitleDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticTitleDefaults_Initializer >
187 struct StaticTitleInfoHelper_Initializer
189 ::cppu::OPropertyArrayHelper* operator()()
191 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
192 return &aPropHelper;
195 private:
196 uno::Sequence< Property > lcl_GetPropertySequence()
198 ::std::vector< ::com::sun::star::beans::Property > aProperties;
199 lcl_AddPropertiesToVector( aProperties );
200 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
201 ::chart::FillProperties::AddPropertiesToVector( aProperties );
203 ::std::sort( aProperties.begin(), aProperties.end(),
204 ::chart::PropertyNameLess() );
206 return ::chart::ContainerHelper::ContainerToSequence( aProperties );
212 struct StaticTitleInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticTitleInfoHelper_Initializer >
216 struct StaticTitleInfo_Initializer
218 uno::Reference< beans::XPropertySetInfo >* operator()()
220 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
221 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticTitleInfoHelper::get() ) );
222 return &xPropertySetInfo;
226 struct StaticTitleInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticTitleInfo_Initializer >
230 } // anonymous namespace
232 // ================================================================================
234 namespace chart
237 Title::Title( uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
238 ::property::OPropertySet( m_aMutex ),
239 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
242 Title::Title( const Title & rOther ) :
243 MutexContainer(),
244 impl::Title_Base(),
245 ::property::OPropertySet( rOther, m_aMutex ),
246 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
248 CloneHelper::CloneRefSequence< uno::Reference< chart2::XFormattedString > >(
249 rOther.m_aStrings, m_aStrings );
250 ModifyListenerHelper::addListenerToAllElements(
251 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
254 Title::~Title()
256 ModifyListenerHelper::removeListenerFromAllElements(
257 ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
260 // ____ XCloneable ____
261 uno::Reference< util::XCloneable > SAL_CALL Title::createClone()
262 throw (uno::RuntimeException)
264 return uno::Reference< util::XCloneable >( new Title( *this ));
267 // --------------------------------------------------------------------------------
269 // ____ XTitle ____
270 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
271 throw (uno::RuntimeException)
273 MutexGuard aGuard( GetMutex() );
274 return m_aStrings;
277 void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
278 throw (uno::RuntimeException)
280 uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
282 MutexGuard aGuard( GetMutex() );
283 std::swap( m_aStrings, aOldStrings );
284 m_aStrings = rNewStrings;
286 //don't keep the mutex locked while calling out
287 ModifyListenerHelper::removeListenerFromAllElements(
288 ContainerHelper::SequenceToVector( aOldStrings ), m_xModifyEventForwarder );
289 ModifyListenerHelper::addListenerToAllElements(
290 ContainerHelper::SequenceToVector( rNewStrings ), m_xModifyEventForwarder );
291 fireModifyEvent();
294 // ================================================================================
296 // ____ OPropertySet ____
297 uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const
298 throw(beans::UnknownPropertyException)
300 const tPropertyValueMap& rStaticDefaults = *StaticTitleDefaults::get();
301 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
302 if( aFound == rStaticDefaults.end() )
303 return uno::Any();
304 return (*aFound).second;
307 ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
309 return *StaticTitleInfoHelper::get();
312 // ____ XPropertySet ____
313 uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo()
314 throw (uno::RuntimeException)
316 return *StaticTitleInfo::get();
319 // ____ XModifyBroadcaster ____
320 void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
321 throw (uno::RuntimeException)
325 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
326 xBroadcaster->addModifyListener( aListener );
328 catch( const uno::Exception & ex )
330 ASSERT_EXCEPTION( ex );
334 void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
335 throw (uno::RuntimeException)
339 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
340 xBroadcaster->removeModifyListener( aListener );
342 catch( const uno::Exception & ex )
344 ASSERT_EXCEPTION( ex );
348 // ____ XModifyListener ____
349 void SAL_CALL Title::modified( const lang::EventObject& aEvent )
350 throw (uno::RuntimeException)
352 m_xModifyEventForwarder->modified( aEvent );
355 // ____ XEventListener (base of XModifyListener) ____
356 void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
357 throw (uno::RuntimeException)
359 // nothing
362 // ____ OPropertySet ____
363 void Title::firePropertyChangeEvent()
365 fireModifyEvent();
368 void Title::fireModifyEvent()
370 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
374 // ================================================================================
376 uno::Sequence< OUString > Title::getSupportedServiceNames_Static()
378 uno::Sequence< OUString > aServices( 4 );
379 aServices[ 0 ] = "com.sun.star.chart2.Title";
380 aServices[ 1 ] = "com.sun.star.style.ParagraphProperties";
381 aServices[ 2 ] = "com.sun.star.beans.PropertySet";
382 aServices[ 3 ] = "com.sun.star.layout.LayoutElement";
383 return aServices;
386 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
387 APPHELPER_XSERVICEINFO_IMPL( Title, lcl_aServiceName );
389 // needed by MSC compiler
390 using impl::Title_Base;
392 IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
393 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
395 } // namespace chart
397 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */