LibreOffice Module chart2 (master) 1
Title.cxx
Go to the documentation of this file.
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>
22#include <FillProperties.hxx>
23#include <CloneHelper.hxx>
24#include <PropertyHelper.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>
33
34#include <vector>
35#include <algorithm>
36
37namespace com::sun::star::uno { class XComponentContext; }
38
39using namespace ::com::sun::star;
40using namespace ::com::sun::star::beans::PropertyAttribute;
41
42using ::com::sun::star::beans::Property;
43using ::osl::MutexGuard;
44
45namespace
46{
47
48enum
49{
50 PROP_TITLE_PARA_ADJUST,
51 PROP_TITLE_PARA_LAST_LINE_ADJUST,
52 PROP_TITLE_PARA_LEFT_MARGIN,
53 PROP_TITLE_PARA_RIGHT_MARGIN,
54 PROP_TITLE_PARA_TOP_MARGIN,
55 PROP_TITLE_PARA_BOTTOM_MARGIN,
56 PROP_TITLE_PARA_IS_HYPHENATION,
57 PROP_TITLE_VISIBLE,
58
59 PROP_TITLE_TEXT_ROTATION,
60 PROP_TITLE_TEXT_STACKED,
61 PROP_TITLE_REL_POS,
62
63 PROP_TITLE_REF_PAGE_SIZE
64};
65
66void lcl_AddPropertiesToVector(
67 std::vector< Property > & rOutProperties )
68{
69 rOutProperties.emplace_back( "ParaAdjust",
70 PROP_TITLE_PARA_ADJUST,
72 beans::PropertyAttribute::BOUND
73 | beans::PropertyAttribute::MAYBEDEFAULT );
74
75 rOutProperties.emplace_back( "ParaLastLineAdjust",
76 PROP_TITLE_PARA_LAST_LINE_ADJUST,
78 beans::PropertyAttribute::BOUND
79 | beans::PropertyAttribute::MAYBEDEFAULT );
80
81 rOutProperties.emplace_back( "ParaLeftMargin",
82 PROP_TITLE_PARA_LEFT_MARGIN,
84 beans::PropertyAttribute::BOUND
85 | beans::PropertyAttribute::MAYBEDEFAULT );
86
87 rOutProperties.emplace_back( "ParaRightMargin",
88 PROP_TITLE_PARA_RIGHT_MARGIN,
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEDEFAULT );
92
93 rOutProperties.emplace_back( "ParaTopMargin",
94 PROP_TITLE_PARA_TOP_MARGIN,
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEDEFAULT );
98
99 rOutProperties.emplace_back( "ParaBottomMargin",
100 PROP_TITLE_PARA_BOTTOM_MARGIN,
102 beans::PropertyAttribute::BOUND
103 | beans::PropertyAttribute::MAYBEDEFAULT );
104
105 rOutProperties.emplace_back( "ParaIsHyphenation",
106 PROP_TITLE_PARA_IS_HYPHENATION,
108 beans::PropertyAttribute::BOUND
109 | beans::PropertyAttribute::MAYBEDEFAULT );
110
111
112 rOutProperties.emplace_back( "Visible",
113 PROP_TITLE_VISIBLE,
115 beans::PropertyAttribute::BOUND
116 | beans::PropertyAttribute::MAYBEDEFAULT );
117
118 rOutProperties.emplace_back( "TextRotation",
119 PROP_TITLE_TEXT_ROTATION,
121 beans::PropertyAttribute::BOUND
122 | beans::PropertyAttribute::MAYBEDEFAULT );
123 rOutProperties.emplace_back( "StackCharacters",
124 PROP_TITLE_TEXT_STACKED,
126 beans::PropertyAttribute::BOUND
127 | beans::PropertyAttribute::MAYBEDEFAULT );
128
129 rOutProperties.emplace_back( "RelativePosition",
130 PROP_TITLE_REL_POS,
132 beans::PropertyAttribute::BOUND
133 | beans::PropertyAttribute::MAYBEVOID );
134
135 rOutProperties.emplace_back( "ReferencePageSize",
136 PROP_TITLE_REF_PAGE_SIZE,
138 beans::PropertyAttribute::BOUND
139 | beans::PropertyAttribute::MAYBEVOID );
140}
141
142const ::chart::tPropertyValueMap& StaticTitleDefaults()
143{
144 static ::chart::tPropertyValueMap aStaticDefaults = []()
145 {
147
150
151 // ParagraphProperties
152 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_ADJUST,
153 css::style::ParagraphAdjust_CENTER );
154 // PROP_TITLE_PARA_LAST_LINE_ADJUST
155
156 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
157 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
158 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_TOP_MARGIN, 0 );
159 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
160 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_IS_HYPHENATION, true );
161 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_VISIBLE, true );
162
163 // own properties
164 ::chart::PropertyHelper::setPropertyValueDefault< double >( aTmp, PROP_TITLE_TEXT_ROTATION, 0.0 );
165 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_TEXT_STACKED, false );
166
167 // override other defaults
168 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
170 return aTmp;
171 }();
172 return aStaticDefaults;
173};
174
175::cppu::OPropertyArrayHelper& StaticTitleInfoHelper()
176{
177 static ::cppu::OPropertyArrayHelper aPropHelper = []()
178 {
179 std::vector< css::beans::Property > aProperties;
180 lcl_AddPropertiesToVector( aProperties );
183
184 std::sort( aProperties.begin(), aProperties.end(),
186
187 return comphelper::containerToSequence( aProperties );
188 }();
189 return aPropHelper;
190};
191
192} // anonymous namespace
193
194namespace chart
195{
196
198 m_xModifyEventForwarder( new ModifyEventForwarder() )
199{}
200
201Title::Title( const Title & rOther ) :
202 impl::Title_Base(rOther),
203 ::property::OPropertySet( rOther ),
204 m_xModifyEventForwarder( new ModifyEventForwarder() )
205{
206 CloneHelper::CloneRefSequence<chart2::XFormattedString>(
207 rOther.m_aStrings, m_aStrings );
211}
212
214{
218}
219
220// ____ XCloneable ____
222{
223 return uno::Reference< util::XCloneable >( new Title( *this ));
224}
225
226// ____ XTitle ____
228{
229 MutexGuard aGuard( m_aMutex );
230 return m_aStrings;
231}
232
234{
236 {
237 MutexGuard aGuard( m_aMutex );
238 std::swap( m_aStrings, aOldStrings );
239 m_aStrings = rNewStrings;
240 }
241 //don't keep the mutex locked while calling out
249}
250
251// ____ OPropertySet ____
252void Title::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
253{
254 const tPropertyValueMap& rStaticDefaults = StaticTitleDefaults();
255 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
256 if( aFound == rStaticDefaults.end() )
257 rAny.clear();
258 else
259 rAny = (*aFound).second;
260}
261
263{
264 return StaticTitleInfoHelper();
265}
266
267// ____ XPropertySet ____
269{
270 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
271 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticTitleInfoHelper() ) );
272 return xPropertySetInfo;
273}
274
275// ____ XModifyBroadcaster ____
277{
278 m_xModifyEventForwarder->addModifyListener( aListener );
279}
280
282{
283 m_xModifyEventForwarder->removeModifyListener( aListener );
284}
285
286// ____ XModifyListener ____
287void SAL_CALL Title::modified( const lang::EventObject& aEvent )
288{
289 m_xModifyEventForwarder->modified( aEvent );
290}
291
292// ____ XEventListener (base of XModifyListener) ____
293void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
294{
295 // nothing
296}
297
298// ____ OPropertySet ____
300{
302}
303
305{
306 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
307}
308
310{
311 return "com.sun.star.comp.chart2.Title";
312}
313
314sal_Bool SAL_CALL Title::supportsService( const OUString& rServiceName )
315{
316 return cppu::supportsService(this, rServiceName);
317}
318
319css::uno::Sequence< OUString > SAL_CALL Title::getSupportedServiceNames()
320{
321 return {
322 "com.sun.star.chart2.Title",
323 "com.sun.star.style.ParagraphProperties",
324 "com.sun.star.beans.PropertySet",
325 "com.sun.star.layout.LayoutElement" };
326}
327
328// needed by MSC compiler
329using impl::Title_Base;
330
333
334} // namespace chart
335
336extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
338 css::uno::Sequence<css::uno::Any> const &)
339{
340 return cppu::acquire(new ::chart::Title);
341}
342
343/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SAL_DLLPUBLIC_EXPORT css::uno::XInterface * com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext *, css::uno::Sequence< css::uno::Any > const &)
Definition: Title.cxx:337
PropertiesInfo aProperties
AnyEventRef aEvent
This helper class serves as forwarder of modify events.
css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > m_aStrings
Definition: Title.hxx:102
virtual void firePropertyChangeEvent() override
implement this method in derived classes to get called when properties change.
Definition: Title.cxx:299
virtual void GetDefaultValue(sal_Int32 nHandle, css::uno::Any &rAny) const override
implement this method to provide default values for all properties supporting defaults.
Definition: Title.cxx:252
virtual css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > SAL_CALL getText() override
Definition: Title.cxx:227
virtual ::cppu::IPropertyArrayHelper &SAL_CALL getInfoHelper() override
The InfoHelper table contains all property names and types of this object.
Definition: Title.cxx:262
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
Definition: Title.cxx:309
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
Definition: Title.cxx:268
virtual ~Title() override
Definition: Title.cxx:213
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
Definition: Title.cxx:314
void fireModifyEvent()
Definition: Title.cxx:304
virtual void SAL_CALL setText(const css::uno::Sequence< css::uno::Reference< css::chart2::XFormattedString > > &Strings) override
Definition: Title.cxx:233
virtual css::uno::Reference< css::util::XCloneable > SAL_CALL createClone() override
Definition: Title.cxx:221
rtl::Reference< ModifyEventForwarder > m_xModifyEventForwarder
Definition: Title.hxx:104
virtual void SAL_CALL modified(const css::lang::EventObject &aEvent) override
Definition: Title.cxx:287
virtual void SAL_CALL removeModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: Title.cxx:281
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
Definition: Title.cxx:319
virtual void SAL_CALL addModifyListener(const css::uno::Reference< css::util::XModifyListener > &aListener) override
Definition: Title.cxx:276
mutable::osl::Mutex m_aMutex
static css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL createPropertySetInfo(IPropertyArrayHelper &rProperties)
void SAL_CALL disposing()
OOO_DLLPUBLIC_CHARTTOOLS void AddDefaultsToMap(::chart::tPropertyValueMap &rOutMap)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void removeListenerFromAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void addListenerToAllElements(const Container &rContainer, const css::uno::Reference< css::util::XModifyListener > &xListener)
void setPropertyValueDefault(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Calls setPropertyValue() but asserts that the given property hasn't been set before.
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
::cppu::WeakImplHelper< css::chart2::XTitle, css::lang::XServiceInfo, css::util::XCloneable, css::util::XModifyBroadcaster, css::util::XModifyListener > Title_Base
Definition: Title.hxx:40
std::unordered_map< tPropertyValueMapKey, css::uno::Any > tPropertyValueMap
DstType sequenceToContainer(const css::uno::Sequence< SrcType > &i_Sequence)
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
IMPLEMENT_FORWARD_XTYPEPROVIDER2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
IMPLEMENT_FORWARD_XINTERFACE2(ChildWindowPane, ChildWindowPaneInterfaceBase, Pane)
sal_Int32 nHandle
unsigned char sal_Bool