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