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