nss: upgrade to release 3.73
[LibreOffice.git] / chart2 / source / model / main / Title.cxx
bloba42374ce5f51c2b9b3d060661896fa78289c598d
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 <LinePropertiesHelper.hxx>
22 #include <FillProperties.hxx>
23 #include <CloneHelper.hxx>
24 #include <PropertyHelper.hxx>
25 #include <ModifyListenerHelper.hxx>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/style/ParagraphAdjust.hpp>
28 #include <com/sun/star/drawing/FillStyle.hpp>
29 #include <com/sun/star/drawing/LineStyle.hpp>
30 #include <com/sun/star/chart2/RelativePosition.hpp>
31 #include <com/sun/star/awt/Size.hpp>
32 #include <cppuhelper/supportsservice.hxx>
33 #include <tools/diagnose_ex.h>
35 #include <vector>
36 #include <algorithm>
38 namespace com::sun::star::uno { class XComponentContext; }
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 enum
51 PROP_TITLE_PARA_ADJUST,
52 PROP_TITLE_PARA_LAST_LINE_ADJUST,
53 PROP_TITLE_PARA_LEFT_MARGIN,
54 PROP_TITLE_PARA_RIGHT_MARGIN,
55 PROP_TITLE_PARA_TOP_MARGIN,
56 PROP_TITLE_PARA_BOTTOM_MARGIN,
57 PROP_TITLE_PARA_IS_HYPHENATION,
58 PROP_TITLE_VISIBLE,
60 PROP_TITLE_TEXT_ROTATION,
61 PROP_TITLE_TEXT_STACKED,
62 PROP_TITLE_REL_POS,
64 PROP_TITLE_REF_PAGE_SIZE
67 void lcl_AddPropertiesToVector(
68 std::vector< Property > & rOutProperties )
70 rOutProperties.emplace_back( "ParaAdjust",
71 PROP_TITLE_PARA_ADJUST,
72 cppu::UnoType<css::style::ParagraphAdjust>::get(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
76 rOutProperties.emplace_back( "ParaLastLineAdjust",
77 PROP_TITLE_PARA_LAST_LINE_ADJUST,
78 cppu::UnoType<sal_Int16>::get(),
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT );
82 rOutProperties.emplace_back( "ParaLeftMargin",
83 PROP_TITLE_PARA_LEFT_MARGIN,
84 cppu::UnoType<sal_Int32>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT );
88 rOutProperties.emplace_back( "ParaRightMargin",
89 PROP_TITLE_PARA_RIGHT_MARGIN,
90 cppu::UnoType<sal_Int32>::get(),
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEDEFAULT );
94 rOutProperties.emplace_back( "ParaTopMargin",
95 PROP_TITLE_PARA_TOP_MARGIN,
96 cppu::UnoType<sal_Int32>::get(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEDEFAULT );
100 rOutProperties.emplace_back( "ParaBottomMargin",
101 PROP_TITLE_PARA_BOTTOM_MARGIN,
102 cppu::UnoType<sal_Int32>::get(),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT );
106 rOutProperties.emplace_back( "ParaIsHyphenation",
107 PROP_TITLE_PARA_IS_HYPHENATION,
108 cppu::UnoType<bool>::get(),
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::MAYBEDEFAULT );
113 rOutProperties.emplace_back( "Visible",
114 PROP_TITLE_VISIBLE,
115 cppu::UnoType<bool>::get(),
116 beans::PropertyAttribute::BOUND
117 | beans::PropertyAttribute::MAYBEDEFAULT );
119 rOutProperties.emplace_back( "TextRotation",
120 PROP_TITLE_TEXT_ROTATION,
121 cppu::UnoType<double>::get(),
122 beans::PropertyAttribute::BOUND
123 | beans::PropertyAttribute::MAYBEDEFAULT );
124 rOutProperties.emplace_back( "StackCharacters",
125 PROP_TITLE_TEXT_STACKED,
126 cppu::UnoType<bool>::get(),
127 beans::PropertyAttribute::BOUND
128 | beans::PropertyAttribute::MAYBEDEFAULT );
130 rOutProperties.emplace_back( "RelativePosition",
131 PROP_TITLE_REL_POS,
132 cppu::UnoType<chart2::RelativePosition>::get(),
133 beans::PropertyAttribute::BOUND
134 | beans::PropertyAttribute::MAYBEVOID );
136 rOutProperties.emplace_back( "ReferencePageSize",
137 PROP_TITLE_REF_PAGE_SIZE,
138 cppu::UnoType<awt::Size>::get(),
139 beans::PropertyAttribute::BOUND
140 | beans::PropertyAttribute::MAYBEVOID );
143 struct StaticTitleDefaults_Initializer
145 ::chart::tPropertyValueMap* operator()()
147 static ::chart::tPropertyValueMap aStaticDefaults;
148 lcl_AddDefaultsToMap( aStaticDefaults );
149 return &aStaticDefaults;
151 private:
152 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
154 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap );
155 ::chart::FillProperties::AddDefaultsToMap( rOutMap );
157 // ParagraphProperties
158 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST,
159 css::style::ParagraphAdjust_CENTER );
160 // PROP_TITLE_PARA_LAST_LINE_ADJUST
162 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
163 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
164 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 );
165 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
166 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true );
167 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_VISIBLE, true );
169 // own properties
170 ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 );
171 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false );
173 // override other defaults
174 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
175 ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
179 struct StaticTitleDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticTitleDefaults_Initializer >
183 struct StaticTitleInfoHelper_Initializer
185 ::cppu::OPropertyArrayHelper* operator()()
187 static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
188 return &aPropHelper;
191 private:
192 static uno::Sequence< Property > lcl_GetPropertySequence()
194 std::vector< css::beans::Property > aProperties;
195 lcl_AddPropertiesToVector( aProperties );
196 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
197 ::chart::FillProperties::AddPropertiesToVector( aProperties );
199 std::sort( aProperties.begin(), aProperties.end(),
200 ::chart::PropertyNameLess() );
202 return comphelper::containerToSequence( aProperties );
207 struct StaticTitleInfoHelper : public rtl::StaticAggregate< ::cppu::OPropertyArrayHelper, StaticTitleInfoHelper_Initializer >
211 struct StaticTitleInfo_Initializer
213 uno::Reference< beans::XPropertySetInfo >* operator()()
215 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
216 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticTitleInfoHelper::get() ) );
217 return &xPropertySetInfo;
221 struct StaticTitleInfo : public rtl::StaticAggregate< uno::Reference< beans::XPropertySetInfo >, StaticTitleInfo_Initializer >
225 } // anonymous namespace
227 namespace chart
230 Title::Title() :
231 ::property::OPropertySet( m_aMutex ),
232 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
235 Title::Title( const Title & rOther ) :
236 impl::Title_Base(rOther),
237 ::property::OPropertySet( rOther, m_aMutex ),
238 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
240 CloneHelper::CloneRefSequence<chart2::XFormattedString>(
241 rOther.m_aStrings, m_aStrings );
242 ModifyListenerHelper::addListenerToAllElements(
243 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
244 m_xModifyEventForwarder );
247 Title::~Title()
249 ModifyListenerHelper::removeListenerFromAllElements(
250 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
251 m_xModifyEventForwarder );
254 // ____ XCloneable ____
255 uno::Reference< util::XCloneable > SAL_CALL Title::createClone()
257 return uno::Reference< util::XCloneable >( new Title( *this ));
260 // ____ XTitle ____
261 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
263 MutexGuard aGuard( m_aMutex );
264 return m_aStrings;
267 void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
269 uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
271 MutexGuard aGuard( m_aMutex );
272 std::swap( m_aStrings, aOldStrings );
273 m_aStrings = rNewStrings;
275 //don't keep the mutex locked while calling out
276 ModifyListenerHelper::removeListenerFromAllElements(
277 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( aOldStrings ),
278 m_xModifyEventForwarder );
279 ModifyListenerHelper::addListenerToAllElements(
280 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( rNewStrings ),
281 m_xModifyEventForwarder );
282 fireModifyEvent();
285 // ____ OPropertySet ____
286 uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const
288 const tPropertyValueMap& rStaticDefaults = *StaticTitleDefaults::get();
289 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
290 if( aFound == rStaticDefaults.end() )
291 return uno::Any();
292 return (*aFound).second;
295 ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
297 return *StaticTitleInfoHelper::get();
300 // ____ XPropertySet ____
301 uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo()
303 return *StaticTitleInfo::get();
306 // ____ XModifyBroadcaster ____
307 void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
311 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
312 xBroadcaster->addModifyListener( aListener );
314 catch( const uno::Exception & )
316 DBG_UNHANDLED_EXCEPTION("chart2");
320 void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
324 uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
325 xBroadcaster->removeModifyListener( aListener );
327 catch( const uno::Exception & )
329 DBG_UNHANDLED_EXCEPTION("chart2");
333 // ____ XModifyListener ____
334 void SAL_CALL Title::modified( const lang::EventObject& aEvent )
336 m_xModifyEventForwarder->modified( aEvent );
339 // ____ XEventListener (base of XModifyListener) ____
340 void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
342 // nothing
345 // ____ OPropertySet ____
346 void Title::firePropertyChangeEvent()
348 fireModifyEvent();
351 void Title::fireModifyEvent()
353 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
356 OUString SAL_CALL Title::getImplementationName()
358 return "com.sun.star.comp.chart2.Title";
361 sal_Bool SAL_CALL Title::supportsService( const OUString& rServiceName )
363 return cppu::supportsService(this, rServiceName);
366 css::uno::Sequence< OUString > SAL_CALL Title::getSupportedServiceNames()
368 return {
369 "com.sun.star.chart2.Title",
370 "com.sun.star.style.ParagraphProperties",
371 "com.sun.star.beans.PropertySet",
372 "com.sun.star.layout.LayoutElement" };
375 // needed by MSC compiler
376 using impl::Title_Base;
378 IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
379 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
381 } // namespace chart
383 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
384 com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext *,
385 css::uno::Sequence<css::uno::Any> const &)
387 return cppu::acquire(new ::chart::Title);
390 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */