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 1 : 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 1 : void lcl_AddPropertiesToVector(
70 : ::std::vector< Property > & rOutProperties )
71 : {
72 : rOutProperties.push_back(
73 : Property( C2U( "ParaAdjust" ),
74 : PROP_TITLE_PARA_ADJUST,
75 1 : ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust * >(0)),
76 : beans::PropertyAttribute::BOUND
77 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
78 :
79 : rOutProperties.push_back(
80 : Property( C2U( "ParaLastLineAdjust" ),
81 : PROP_TITLE_PARA_LAST_LINE_ADJUST,
82 1 : ::getCppuType( reinterpret_cast< sal_Int16 * >(0)),
83 : beans::PropertyAttribute::BOUND
84 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
85 :
86 : rOutProperties.push_back(
87 : Property( C2U( "ParaLeftMargin" ),
88 : PROP_TITLE_PARA_LEFT_MARGIN,
89 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
90 : beans::PropertyAttribute::BOUND
91 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
92 :
93 : rOutProperties.push_back(
94 : Property( C2U( "ParaRightMargin" ),
95 : PROP_TITLE_PARA_RIGHT_MARGIN,
96 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
97 : beans::PropertyAttribute::BOUND
98 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
99 :
100 : rOutProperties.push_back(
101 : Property( C2U( "ParaTopMargin" ),
102 : PROP_TITLE_PARA_TOP_MARGIN,
103 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
104 : beans::PropertyAttribute::BOUND
105 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
106 :
107 : rOutProperties.push_back(
108 : Property( C2U( "ParaBottomMargin" ),
109 : PROP_TITLE_PARA_BOTTOM_MARGIN,
110 1 : ::getCppuType( reinterpret_cast< sal_Int32 * >(0)),
111 : beans::PropertyAttribute::BOUND
112 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
113 :
114 : rOutProperties.push_back(
115 : Property( C2U( "ParaIsHyphenation" ),
116 : PROP_TITLE_PARA_IS_HYPHENATION,
117 1 : ::getBooleanCppuType(),
118 : beans::PropertyAttribute::BOUND
119 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
120 :
121 : rOutProperties.push_back(
122 : Property( C2U( "TextRotation" ),
123 : PROP_TITLE_TEXT_ROTATION,
124 1 : ::getCppuType( reinterpret_cast< const double * >(0)),
125 : beans::PropertyAttribute::BOUND
126 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
127 : rOutProperties.push_back(
128 : Property( C2U( "StackCharacters" ),
129 : PROP_TITLE_TEXT_STACKED,
130 1 : ::getBooleanCppuType(),
131 : beans::PropertyAttribute::BOUND
132 2 : | beans::PropertyAttribute::MAYBEDEFAULT ));
133 :
134 : rOutProperties.push_back(
135 : Property( C2U( "RelativePosition" ),
136 : PROP_TITLE_REL_POS,
137 1 : ::getCppuType( reinterpret_cast< const chart2::RelativePosition * >(0)),
138 : beans::PropertyAttribute::BOUND
139 2 : | beans::PropertyAttribute::MAYBEVOID ));
140 :
141 : rOutProperties.push_back(
142 : Property( C2U( "ReferencePageSize" ),
143 : PROP_TITLE_REF_PAGE_SIZE,
144 1 : ::getCppuType( reinterpret_cast< const awt::Size * >(0)),
145 : beans::PropertyAttribute::BOUND
146 2 : | beans::PropertyAttribute::MAYBEVOID ));
147 1 : }
148 :
149 : struct StaticTitleDefaults_Initializer
150 : {
151 1 : ::chart::tPropertyValueMap* operator()()
152 : {
153 1 : static ::chart::tPropertyValueMap aStaticDefaults;
154 1 : lcl_AddDefaultsToMap( aStaticDefaults );
155 1 : return &aStaticDefaults;
156 : }
157 : private:
158 1 : void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap & rOutMap )
159 : {
160 1 : ::chart::LineProperties::AddDefaultsToMap( rOutMap );
161 1 : ::chart::FillProperties::AddDefaultsToMap( rOutMap );
162 :
163 : // ParagraphProperties
164 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_ADJUST,
165 1 : ::com::sun::star::style::ParagraphAdjust_CENTER );
166 : // PROP_TITLE_PARA_LAST_LINE_ADJUST
167 :
168 1 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
169 1 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
170 1 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_TOP_MARGIN, 0 );
171 1 : ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( rOutMap, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
172 1 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_PARA_IS_HYPHENATION, true );
173 :
174 : // own properties
175 1 : ::chart::PropertyHelper::setPropertyValueDefault< double >( rOutMap, PROP_TITLE_TEXT_ROTATION, 0.0 );
176 1 : ::chart::PropertyHelper::setPropertyValueDefault( rOutMap, PROP_TITLE_TEXT_STACKED, false );
177 :
178 : // override other defaults
179 1 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
180 1 : ::chart::PropertyHelper::setPropertyValue( rOutMap, ::chart::LineProperties::PROP_LINE_STYLE, drawing::LineStyle_NONE );
181 1 : }
182 : };
183 :
184 : struct StaticTitleDefaults : public rtl::StaticAggregate< ::chart::tPropertyValueMap, StaticTitleDefaults_Initializer >
185 : {
186 : };
187 :
188 : struct StaticTitleInfoHelper_Initializer
189 : {
190 1 : ::cppu::OPropertyArrayHelper* operator()()
191 : {
192 1 : static ::cppu::OPropertyArrayHelper aPropHelper( lcl_GetPropertySequence() );
193 1 : return &aPropHelper;
194 : }
195 :
196 : private:
197 1 : uno::Sequence< Property > lcl_GetPropertySequence()
198 : {
199 1 : ::std::vector< ::com::sun::star::beans::Property > aProperties;
200 1 : lcl_AddPropertiesToVector( aProperties );
201 1 : ::chart::LineProperties::AddPropertiesToVector( aProperties );
202 1 : ::chart::FillProperties::AddPropertiesToVector( aProperties );
203 :
204 : ::std::sort( aProperties.begin(), aProperties.end(),
205 1 : ::chart::PropertyNameLess() );
206 :
207 1 : 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 21 : Title::Title( uno::Reference< uno::XComponentContext > const & /* xContext */ ) :
239 : ::property::OPropertySet( m_aMutex ),
240 21 : m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
241 21 : {}
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 63 : Title::~Title()
256 : {
257 : ModifyListenerHelper::removeListenerFromAllElements(
258 21 : ContainerHelper::SequenceToVector( m_aStrings ), m_xModifyEventForwarder );
259 42 : }
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 0 : uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
272 : throw (uno::RuntimeException)
273 : {
274 0 : MutexGuard aGuard( GetMutex() );
275 0 : return m_aStrings;
276 : }
277 :
278 21 : void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
279 : throw (uno::RuntimeException)
280 : {
281 21 : uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
282 : {
283 21 : MutexGuard aGuard( GetMutex() );
284 21 : std::swap( m_aStrings, aOldStrings );
285 21 : m_aStrings = rNewStrings;
286 : }
287 : //don't keep the mutex locked while calling out
288 : ModifyListenerHelper::removeListenerFromAllElements(
289 21 : ContainerHelper::SequenceToVector( aOldStrings ), m_xModifyEventForwarder );
290 : ModifyListenerHelper::addListenerToAllElements(
291 21 : ContainerHelper::SequenceToVector( rNewStrings ), m_xModifyEventForwarder );
292 21 : fireModifyEvent();
293 21 : }
294 :
295 : // ================================================================================
296 :
297 : // ____ OPropertySet ____
298 253 : uno::Any Title::GetDefaultValue( sal_Int32 nHandle ) const
299 : throw(beans::UnknownPropertyException)
300 : {
301 253 : const tPropertyValueMap& rStaticDefaults = *StaticTitleDefaults::get();
302 253 : tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
303 253 : if( aFound == rStaticDefaults.end() )
304 59 : return uno::Any();
305 194 : return (*aFound).second;
306 : }
307 :
308 258 : ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
309 : {
310 258 : 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 21 : void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
322 : throw (uno::RuntimeException)
323 : {
324 : try
325 : {
326 21 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
327 21 : xBroadcaster->addModifyListener( aListener );
328 : }
329 0 : catch( const uno::Exception & ex )
330 : {
331 : ASSERT_EXCEPTION( ex );
332 : }
333 21 : }
334 :
335 0 : void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
336 : throw (uno::RuntimeException)
337 : {
338 : try
339 : {
340 0 : uno::Reference< util::XModifyBroadcaster > xBroadcaster( m_xModifyEventForwarder, uno::UNO_QUERY_THROW );
341 0 : xBroadcaster->removeModifyListener( aListener );
342 : }
343 0 : catch( const uno::Exception & ex )
344 : {
345 : ASSERT_EXCEPTION( ex );
346 : }
347 0 : }
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 100 : void Title::firePropertyChangeEvent()
365 : {
366 100 : fireModifyEvent();
367 100 : }
368 :
369 121 : void Title::fireModifyEvent()
370 : {
371 121 : m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
372 121 : }
373 :
374 :
375 : // ================================================================================
376 :
377 1 : uno::Sequence< ::rtl::OUString > Title::getSupportedServiceNames_Static()
378 : {
379 1 : uno::Sequence< ::rtl::OUString > aServices( 4 );
380 1 : aServices[ 0 ] = C2U( "com.sun.star.chart2.Title" );
381 1 : aServices[ 1 ] = C2U( "com.sun.star.style.ParagraphProperties" );
382 1 : aServices[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
383 1 : aServices[ 3 ] = C2U( "com.sun.star.layout.LayoutElement" );
384 1 : return aServices;
385 : }
386 :
387 : // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
388 16 : APPHELPER_XSERVICEINFO_IMPL( Title, lcl_aServiceName );
389 :
390 : // needed by MSC compiler
391 : using impl::Title_Base;
392 :
393 1869 : IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
394 0 : IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
395 :
396 3 : } // namespace chart
397 :
398 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|