/src/libreoffice/chart2/source/model/main/Title.cxx
Line | Count | Source |
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 <CharacterProperties.hxx> |
22 | | #include <LinePropertiesHelper.hxx> |
23 | | #include <FillProperties.hxx> |
24 | | #include <CloneHelper.hxx> |
25 | | #include <PropertyHelper.hxx> |
26 | | #include <ModifyListenerHelper.hxx> |
27 | | #include <com/sun/star/beans/PropertyAttribute.hpp> |
28 | | #include <com/sun/star/style/ParagraphAdjust.hpp> |
29 | | #include <com/sun/star/drawing/FillStyle.hpp> |
30 | | #include <com/sun/star/drawing/LineStyle.hpp> |
31 | | #include <com/sun/star/chart2/RelativePosition.hpp> |
32 | | #include <com/sun/star/awt/Size.hpp> |
33 | | #include <cppuhelper/supportsservice.hxx> |
34 | | |
35 | | #include <vector> |
36 | | #include <algorithm> |
37 | | |
38 | | namespace com::sun::star::uno { class XComponentContext; } |
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 | | enum |
50 | | { |
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, |
59 | | |
60 | | PROP_TITLE_TEXT_ROTATION, |
61 | | PROP_TITLE_TEXT_STACKED, |
62 | | PROP_TITLE_REL_POS, |
63 | | |
64 | | PROP_TITLE_REF_PAGE_SIZE, |
65 | | PROP_TITLE_HAS_EXPLICIT_SPPR |
66 | | }; |
67 | | |
68 | | void lcl_AddPropertiesToVector( |
69 | | std::vector< Property > & rOutProperties ) |
70 | 0 | { |
71 | 0 | rOutProperties.emplace_back( "ParaAdjust", |
72 | 0 | PROP_TITLE_PARA_ADJUST, |
73 | 0 | cppu::UnoType<css::style::ParagraphAdjust>::get(), |
74 | 0 | beans::PropertyAttribute::BOUND |
75 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
76 | |
|
77 | 0 | rOutProperties.emplace_back( "ParaLastLineAdjust", |
78 | 0 | PROP_TITLE_PARA_LAST_LINE_ADJUST, |
79 | 0 | cppu::UnoType<sal_Int16>::get(), |
80 | 0 | beans::PropertyAttribute::BOUND |
81 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
82 | |
|
83 | 0 | rOutProperties.emplace_back( "ParaLeftMargin", |
84 | 0 | PROP_TITLE_PARA_LEFT_MARGIN, |
85 | 0 | cppu::UnoType<sal_Int32>::get(), |
86 | 0 | beans::PropertyAttribute::BOUND |
87 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
88 | |
|
89 | 0 | rOutProperties.emplace_back( "ParaRightMargin", |
90 | 0 | PROP_TITLE_PARA_RIGHT_MARGIN, |
91 | 0 | cppu::UnoType<sal_Int32>::get(), |
92 | 0 | beans::PropertyAttribute::BOUND |
93 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
94 | |
|
95 | 0 | rOutProperties.emplace_back( "ParaTopMargin", |
96 | 0 | PROP_TITLE_PARA_TOP_MARGIN, |
97 | 0 | cppu::UnoType<sal_Int32>::get(), |
98 | 0 | beans::PropertyAttribute::BOUND |
99 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
100 | |
|
101 | 0 | rOutProperties.emplace_back( "ParaBottomMargin", |
102 | 0 | PROP_TITLE_PARA_BOTTOM_MARGIN, |
103 | 0 | cppu::UnoType<sal_Int32>::get(), |
104 | 0 | beans::PropertyAttribute::BOUND |
105 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
106 | |
|
107 | 0 | rOutProperties.emplace_back( "ParaIsHyphenation", |
108 | 0 | PROP_TITLE_PARA_IS_HYPHENATION, |
109 | 0 | cppu::UnoType<bool>::get(), |
110 | 0 | beans::PropertyAttribute::BOUND |
111 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
112 | | |
113 | |
|
114 | 0 | rOutProperties.emplace_back( "Visible", |
115 | 0 | PROP_TITLE_VISIBLE, |
116 | 0 | cppu::UnoType<bool>::get(), |
117 | 0 | beans::PropertyAttribute::BOUND |
118 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
119 | |
|
120 | 0 | rOutProperties.emplace_back( "TextRotation", |
121 | 0 | PROP_TITLE_TEXT_ROTATION, |
122 | 0 | cppu::UnoType<double>::get(), |
123 | 0 | beans::PropertyAttribute::BOUND |
124 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
125 | 0 | rOutProperties.emplace_back( "StackCharacters", |
126 | 0 | PROP_TITLE_TEXT_STACKED, |
127 | 0 | cppu::UnoType<bool>::get(), |
128 | 0 | beans::PropertyAttribute::BOUND |
129 | 0 | | beans::PropertyAttribute::MAYBEDEFAULT ); |
130 | |
|
131 | 0 | rOutProperties.emplace_back( "RelativePosition", |
132 | 0 | PROP_TITLE_REL_POS, |
133 | 0 | cppu::UnoType<chart2::RelativePosition>::get(), |
134 | 0 | beans::PropertyAttribute::BOUND |
135 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
136 | |
|
137 | 0 | rOutProperties.emplace_back( "ReferencePageSize", |
138 | 0 | PROP_TITLE_REF_PAGE_SIZE, |
139 | 0 | cppu::UnoType<awt::Size>::get(), |
140 | 0 | beans::PropertyAttribute::BOUND |
141 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
142 | |
|
143 | 0 | rOutProperties.emplace_back( "HasExplicitSpPr", |
144 | 0 | PROP_TITLE_HAS_EXPLICIT_SPPR, |
145 | 0 | cppu::UnoType<bool>::get(), |
146 | 0 | beans::PropertyAttribute::BOUND |
147 | 0 | | beans::PropertyAttribute::MAYBEVOID ); |
148 | 0 | } |
149 | | |
150 | | const ::chart::tPropertyValueMap& StaticTitleDefaults() |
151 | 0 | { |
152 | 0 | static ::chart::tPropertyValueMap aStaticDefaults = []() |
153 | 0 | { |
154 | 0 | ::chart::tPropertyValueMap aTmp; |
155 | |
|
156 | 0 | ::chart::CharacterProperties::AddDefaultsToMap( aTmp ); |
157 | 0 | ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp ); |
158 | 0 | ::chart::FillProperties::AddDefaultsToMap( aTmp ); |
159 | | |
160 | | // ParagraphProperties |
161 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_ADJUST, |
162 | 0 | css::style::ParagraphAdjust_CENTER ); |
163 | | // PROP_TITLE_PARA_LAST_LINE_ADJUST |
164 | |
|
165 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_LEFT_MARGIN, 0 ); |
166 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_RIGHT_MARGIN, 0 ); |
167 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_TOP_MARGIN, 0 ); |
168 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 ); |
169 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_IS_HYPHENATION, true ); |
170 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_VISIBLE, true ); |
171 | | |
172 | | // own properties |
173 | 0 | ::chart::PropertyHelper::setPropertyValueDefault< double >( aTmp, PROP_TITLE_TEXT_ROTATION, 0.0 ); |
174 | 0 | ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_TEXT_STACKED, false ); |
175 | | |
176 | | // override other defaults |
177 | 0 | ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE ); |
178 | 0 | ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE ); |
179 | 0 | return aTmp; |
180 | 0 | }(); |
181 | 0 | return aStaticDefaults; |
182 | 0 | } |
183 | | |
184 | | ::cppu::OPropertyArrayHelper& StaticTitleInfoHelper() |
185 | 0 | { |
186 | 0 | static ::cppu::OPropertyArrayHelper aPropHelper = []() |
187 | 0 | { |
188 | 0 | std::vector< css::beans::Property > aProperties; |
189 | 0 | lcl_AddPropertiesToVector( aProperties ); |
190 | 0 | ::chart::CharacterProperties::AddPropertiesToVector( aProperties ); |
191 | 0 | ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties ); |
192 | 0 | ::chart::FillProperties::AddPropertiesToVector( aProperties ); |
193 | |
|
194 | 0 | std::sort( aProperties.begin(), aProperties.end(), |
195 | 0 | ::chart::PropertyNameLess() ); |
196 | |
|
197 | 0 | return comphelper::containerToSequence( aProperties ); |
198 | 0 | }(); |
199 | 0 | return aPropHelper; |
200 | 0 | } |
201 | | |
202 | | } // anonymous namespace |
203 | | |
204 | | namespace chart |
205 | | { |
206 | | |
207 | | Title::Title() : |
208 | 0 | m_xModifyEventForwarder( new ModifyEventForwarder() ) |
209 | 0 | {} |
210 | | |
211 | | Title::Title( const Title & rOther ) : |
212 | 0 | impl::Title_Base(rOther), |
213 | 0 | ::property::OPropertySet( rOther ), |
214 | 0 | m_xModifyEventForwarder( new ModifyEventForwarder() ) |
215 | 0 | { |
216 | 0 | CloneHelper::CloneRefSequence<chart2::XFormattedString>( |
217 | 0 | rOther.m_aStrings, m_aStrings ); |
218 | 0 | ModifyListenerHelper::addListenerToAllElements( |
219 | 0 | comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ), |
220 | 0 | m_xModifyEventForwarder ); |
221 | 0 | } |
222 | | |
223 | | Title::~Title() |
224 | 0 | { |
225 | 0 | ModifyListenerHelper::removeListenerFromAllElements( |
226 | 0 | comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ), |
227 | 0 | m_xModifyEventForwarder ); |
228 | 0 | } |
229 | | |
230 | | // ____ XCloneable ____ |
231 | | uno::Reference< util::XCloneable > SAL_CALL Title::createClone() |
232 | 0 | { |
233 | 0 | return uno::Reference< util::XCloneable >( new Title( *this )); |
234 | 0 | } |
235 | | |
236 | | // ____ XTitle ____ |
237 | | uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText() |
238 | 0 | { |
239 | 0 | MutexGuard aGuard( m_aMutex ); |
240 | 0 | return m_aStrings; |
241 | 0 | } |
242 | | |
243 | | void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings ) |
244 | 0 | { |
245 | 0 | uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings; |
246 | 0 | { |
247 | 0 | MutexGuard aGuard( m_aMutex ); |
248 | 0 | std::swap( m_aStrings, aOldStrings ); |
249 | 0 | m_aStrings = rNewStrings; |
250 | 0 | } |
251 | | //don't keep the mutex locked while calling out |
252 | 0 | ModifyListenerHelper::removeListenerFromAllElements( |
253 | 0 | comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( aOldStrings ), |
254 | 0 | m_xModifyEventForwarder ); |
255 | 0 | ModifyListenerHelper::addListenerToAllElements( |
256 | 0 | comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( rNewStrings ), |
257 | 0 | m_xModifyEventForwarder ); |
258 | 0 | fireModifyEvent(); |
259 | 0 | } |
260 | | |
261 | | // ____ OPropertySet ____ |
262 | | void Title::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const |
263 | 0 | { |
264 | 0 | const tPropertyValueMap& rStaticDefaults = StaticTitleDefaults(); |
265 | 0 | tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) ); |
266 | 0 | if( aFound == rStaticDefaults.end() ) |
267 | 0 | rAny.clear(); |
268 | 0 | else |
269 | 0 | rAny = (*aFound).second; |
270 | 0 | } |
271 | | |
272 | | ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper() |
273 | 0 | { |
274 | 0 | return StaticTitleInfoHelper(); |
275 | 0 | } |
276 | | |
277 | | // ____ XPropertySet ____ |
278 | | uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo() |
279 | 0 | { |
280 | 0 | static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo( |
281 | 0 | ::cppu::OPropertySetHelper::createPropertySetInfo(StaticTitleInfoHelper() ) ); |
282 | 0 | return xPropertySetInfo; |
283 | 0 | } |
284 | | |
285 | | // ____ XModifyBroadcaster ____ |
286 | | void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener ) |
287 | 0 | { |
288 | 0 | m_xModifyEventForwarder->addModifyListener( aListener ); |
289 | 0 | } |
290 | | |
291 | | void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener ) |
292 | 0 | { |
293 | 0 | m_xModifyEventForwarder->removeModifyListener( aListener ); |
294 | 0 | } |
295 | | |
296 | | // ____ XModifyListener ____ |
297 | | void SAL_CALL Title::modified( const lang::EventObject& aEvent ) |
298 | 0 | { |
299 | 0 | m_xModifyEventForwarder->modified( aEvent ); |
300 | 0 | } |
301 | | |
302 | | // ____ XEventListener (base of XModifyListener) ____ |
303 | | void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ ) |
304 | 0 | { |
305 | | // nothing |
306 | 0 | } |
307 | | |
308 | | // ____ OPropertySet ____ |
309 | | void Title::firePropertyChangeEvent() |
310 | 0 | { |
311 | 0 | fireModifyEvent(); |
312 | 0 | } |
313 | | |
314 | | void Title::fireModifyEvent() |
315 | 0 | { |
316 | 0 | m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this ))); |
317 | 0 | } |
318 | | |
319 | | OUString SAL_CALL Title::getImplementationName() |
320 | 0 | { |
321 | 0 | return u"com.sun.star.comp.chart2.Title"_ustr; |
322 | 0 | } |
323 | | |
324 | | sal_Bool SAL_CALL Title::supportsService( const OUString& rServiceName ) |
325 | 0 | { |
326 | 0 | return cppu::supportsService(this, rServiceName); |
327 | 0 | } |
328 | | |
329 | | css::uno::Sequence< OUString > SAL_CALL Title::getSupportedServiceNames() |
330 | 0 | { |
331 | 0 | return { |
332 | 0 | u"com.sun.star.chart2.Title"_ustr, |
333 | 0 | u"com.sun.star.style.ParagraphProperties"_ustr, |
334 | 0 | u"com.sun.star.beans.PropertySet"_ustr, |
335 | 0 | u"com.sun.star.layout.LayoutElement"_ustr }; |
336 | 0 | } |
337 | | |
338 | | // needed by MSC compiler |
339 | | using impl::Title_Base; |
340 | | |
341 | | IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet ) |
342 | | IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet ) |
343 | | |
344 | | } // namespace chart |
345 | | |
346 | | extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface * |
347 | | com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext *, |
348 | | css::uno::Sequence<css::uno::Any> const &) |
349 | 0 | { |
350 | 0 | return cppu::acquire(new ::chart::Title); |
351 | 0 | } |
352 | | |
353 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |