LibreOffice Module chart2 (master) 1
TitleWrapper.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 "TitleWrapper.hxx"
23
26#include <com/sun/star/beans/PropertyAttribute.hpp>
27#include <com/sun/star/chart2/RelativePosition.hpp>
28#include <com/sun/star/chart2/XTitle.hpp>
29
32#include <FillProperties.hxx>
38
39#include <algorithm>
40#include <rtl/ustrbuf.hxx>
42#include <utility>
43
44using namespace ::com::sun::star;
45using ::com::sun::star::beans::Property;
46using ::com::sun::star::uno::Any;
47using ::com::sun::star::uno::Reference;
48using ::com::sun::star::uno::Sequence;
49
50namespace chart
51{
52namespace {
53
54class WrappedTitleStringProperty : public WrappedProperty
55{
56public:
57 explicit WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext );
58
59 virtual void setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const override;
60 virtual Any getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const override;
61 virtual Any getPropertyDefault( const Reference< beans::XPropertyState >& xInnerPropertyState ) const override;
62
63protected:
64 Reference< uno::XComponentContext > m_xContext;
65};
66
67}
68
69WrappedTitleStringProperty::WrappedTitleStringProperty( const Reference< uno::XComponentContext >& xContext )
70 : ::chart::WrappedProperty( "String", OUString() )
71 , m_xContext( xContext )
72{
73}
74
75void WrappedTitleStringProperty::setPropertyValue( const Any& rOuterValue, const Reference< beans::XPropertySet >& xInnerPropertySet ) const
76{
77 Title* pTitle = dynamic_cast<Title*>(xInnerPropertySet.get());
78 if(pTitle)
79 {
80 OUString aString;
81 rOuterValue >>= aString;
82 TitleHelper::setCompleteString( aString, pTitle, m_xContext );
83 }
84}
85Any WrappedTitleStringProperty::getPropertyValue( const Reference< beans::XPropertySet >& xInnerPropertySet ) const
86{
87 Any aRet( getPropertyDefault( Reference< beans::XPropertyState >( xInnerPropertySet, uno::UNO_QUERY ) ) );
88 Reference< chart2::XTitle > xTitle(xInnerPropertySet,uno::UNO_QUERY);
89 if(xTitle.is())
90 {
91 const Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
92
93 OUStringBuffer aBuf;
94 for( Reference< chart2::XFormattedString > const & formattedStr : aStrings )
95 {
96 aBuf.append( formattedStr->getString());
97 }
98 aRet <<= aBuf.makeStringAndClear();
99 }
100 return aRet;
101}
102Any WrappedTitleStringProperty::getPropertyDefault( const Reference< beans::XPropertyState >& /*xInnerPropertyState*/ ) const
103{
104 return uno::Any( OUString() );//default title is an empty String
105}
106
107namespace {
108
109class WrappedStackedTextProperty : public WrappedProperty
110{
111public:
112 WrappedStackedTextProperty();
113};
114
115}
116
117WrappedStackedTextProperty::WrappedStackedTextProperty()
118 : ::chart::WrappedProperty( "StackedText", "StackCharacters" )
119{
120}
121
122}// end namespace chart
123
124namespace
125{
126
127enum
128{
129 PROP_TITLE_STRING,
130 PROP_TITLE_TEXT_ROTATION,
131 PROP_TITLE_TEXT_STACKED
132};
133
134void lcl_AddPropertiesToVector(
135 std::vector< Property > & rOutProperties )
136{
137 rOutProperties.emplace_back( "String",
138 PROP_TITLE_STRING,
140 beans::PropertyAttribute::BOUND
141 | beans::PropertyAttribute::MAYBEVOID );
142
143 rOutProperties.emplace_back( "TextRotation",
144 PROP_TITLE_TEXT_ROTATION,
146 beans::PropertyAttribute::BOUND
147 | beans::PropertyAttribute::MAYBEDEFAULT );
148 rOutProperties.emplace_back( "StackedText",
149 PROP_TITLE_TEXT_STACKED,
151 beans::PropertyAttribute::BOUND
152 | beans::PropertyAttribute::MAYBEDEFAULT );
153}
154
155const Sequence< Property > & StaticTitleWrapperPropertyArray()
156{
157 static Sequence< Property > aPropSeq = []()
158 {
159 std::vector< beans::Property > aProperties;
160 lcl_AddPropertiesToVector( aProperties );
167
168 std::sort( aProperties.begin(), aProperties.end(),
170
171 return comphelper::containerToSequence( aProperties );
172 }();
173 return aPropSeq;
174};
175
176
177} // anonymous namespace
178
179namespace chart::wrapper
180{
181
183 std::shared_ptr<Chart2ModelContact> spChart2ModelContact ) :
184 m_spChart2ModelContact(std::move( spChart2ModelContact )),
185 m_eTitleType(eTitleType)
186{
187 ControllerLockGuardUNO aCtrlLockGuard( m_spChart2ModelContact->getDocumentModel() );
188 if( !getTitleObject().is() ) //#i83831# create an empty title at the model, thus references to properties can be mapped correctly
189 TitleHelper::createTitle( m_eTitleType, OUString(), m_spChart2ModelContact->getDocumentModel(), m_spChart2ModelContact->m_xContext );
190}
191
193{
194}
195
196// ____ XShape ____
197awt::Point SAL_CALL TitleWrapper::getPosition()
198{
199 return m_spChart2ModelContact->GetTitlePosition( getTitleObject() );
200}
201
202void SAL_CALL TitleWrapper::setPosition( const awt::Point& aPosition )
203{
205 if(xPropertySet.is())
206 {
207 awt::Size aPageSize( m_spChart2ModelContact->GetPageSize() );
208
209 chart2::RelativePosition aRelativePosition;
210 aRelativePosition.Anchor = drawing::Alignment_TOP_LEFT;
211 aRelativePosition.Primary = double(aPosition.X)/double(aPageSize.Width);
212 aRelativePosition.Secondary = double(aPosition.Y)/double(aPageSize.Height);
213 xPropertySet->setPropertyValue( "RelativePosition", uno::Any(aRelativePosition) );
214 }
215}
216
217awt::Size SAL_CALL TitleWrapper::getSize()
218{
219 return m_spChart2ModelContact->GetTitleSize( getTitleObject() );
220}
221
222void SAL_CALL TitleWrapper::setSize( const awt::Size& /*aSize*/ )
223{
224 OSL_FAIL( "trying to set size of title" );
225}
226
227// ____ XShapeDescriptor (base of XShape) ____
228OUString SAL_CALL TitleWrapper::getShapeType()
229{
230 return "com.sun.star.chart.ChartTitle";
231}
232
233// ____ XComponent ____
235{
236 std::unique_lock g(m_aMutex);
237 Reference< uno::XInterface > xSource( static_cast< ::cppu::OWeakObject* >( this ) );
238 m_aEventListenerContainer.disposeAndClear( g, lang::EventObject( xSource ) );
239
240 clearWrappedPropertySet();
241}
242
244 const Reference< lang::XEventListener >& xListener )
245{
246 std::unique_lock g(m_aMutex);
248}
249
251 const Reference< lang::XEventListener >& aListener )
252{
253 std::unique_lock g(m_aMutex);
255}
256
258{
260
262 if( xTitle.is())
263 {
264 Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
265 if( aStrings.hasElements() )
266 xProp.set( aStrings[0], uno::UNO_QUERY );
267 }
268
269 return xProp;
270}
271
272void TitleWrapper::getFastCharacterPropertyValue( sal_Int32 nHandle, Any& rValue )
273{
276
278 Reference< beans::XFastPropertySet > xFastProp( xProp, uno::UNO_QUERY );
279 if(xProp.is())
280 {
281 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
282 if( pWrappedProperty )
283 {
284 rValue = pWrappedProperty->getPropertyValue( xProp );
285 }
286 else if( xFastProp.is() )
287 {
288 rValue = xFastProp->getFastPropertyValue( nHandle );
289 }
290 }
291
292}
293
295 sal_Int32 nHandle, const Any& rValue )
296{
299
301 if( !xTitle.is())
302 return;
303
304 const Sequence< Reference< chart2::XFormattedString > > aStrings( xTitle->getText());
305 const WrappedProperty* pWrappedProperty = getWrappedProperty( nHandle );
306
307 for( Reference< chart2::XFormattedString > const & formattedStr : aStrings )
308 {
309 Reference< beans::XFastPropertySet > xFastPropertySet( formattedStr, uno::UNO_QUERY );
310 Reference< beans::XPropertySet > xPropSet( xFastPropertySet, uno::UNO_QUERY );
311
312 if( pWrappedProperty )
313 pWrappedProperty->setPropertyValue( rValue, xPropSet );
314 else if( xFastPropertySet.is() )
315 xFastPropertySet->setFastPropertyValue( nHandle, rValue );
316 }
317}
318
319// WrappedPropertySet
320
321void SAL_CALL TitleWrapper::setPropertyValue( const OUString& rPropertyName, const Any& rValue )
322{
323 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
325 {
327 }
328 else
329 WrappedPropertySet::setPropertyValue( rPropertyName, rValue );
330}
331
332Any SAL_CALL TitleWrapper::getPropertyValue( const OUString& rPropertyName )
333{
334 Any aRet;
335 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
338 else
339 aRet = WrappedPropertySet::getPropertyValue( rPropertyName );
340 return aRet;
341}
342
343beans::PropertyState SAL_CALL TitleWrapper::getPropertyState( const OUString& rPropertyName )
344{
345 beans::PropertyState aState( beans::PropertyState_DIRECT_VALUE );
346
347 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
349 {
351 if( xPropState.is() )
352 {
353 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
354 if( pWrappedProperty )
355 aState = pWrappedProperty->getPropertyState( xPropState );
356 else
357 aState = xPropState->getPropertyState( rPropertyName );
358 }
359 }
360 else
361 aState = WrappedPropertySet::getPropertyState( rPropertyName );
362
363 return aState;
364}
365void SAL_CALL TitleWrapper::setPropertyToDefault( const OUString& rPropertyName )
366{
367 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
369 {
370 Any aDefault = getPropertyDefault( rPropertyName );
372 }
373 else
375}
376Any SAL_CALL TitleWrapper::getPropertyDefault( const OUString& rPropertyName )
377{
378 Any aRet;
379
380 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
382 {
384 if( xPropState.is() )
385 {
386 const WrappedProperty* pWrappedProperty = getWrappedProperty( rPropertyName );
387 if( pWrappedProperty )
388 aRet = pWrappedProperty->getPropertyDefault(xPropState);
389 else
390 aRet = xPropState->getPropertyDefault( rPropertyName );
391 }
392 }
393 else
394 aRet = WrappedPropertySet::getPropertyDefault( rPropertyName );
395
396 return aRet;
397}
398
399void SAL_CALL TitleWrapper::addPropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener )
400{
401 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
403 {
405 if( xPropSet.is() )
406 xPropSet->addPropertyChangeListener( rPropertyName, xListener );
407 }
408 else
409 WrappedPropertySet::addPropertyChangeListener( rPropertyName, xListener );
410}
411void SAL_CALL TitleWrapper::removePropertyChangeListener( const OUString& rPropertyName, const Reference< beans::XPropertyChangeListener >& xListener )
412{
413 sal_Int32 nHandle = getInfoHelper().getHandleByName( rPropertyName );
415 {
417 if( xPropSet.is() )
418 xPropSet->removePropertyChangeListener( rPropertyName, xListener );
419 }
420 else
421 WrappedPropertySet::removePropertyChangeListener( rPropertyName, xListener );
422}
423
424//ReferenceSizePropertyProvider
426{
427 Reference< beans::XPropertySet > xProp( getTitleObject(), uno::UNO_QUERY );
428 if( xProp.is() )
429 {
430 if( xProp->getPropertyValue( "ReferencePageSize" ).hasValue() )
431 xProp->setPropertyValue( "ReferencePageSize", uno::Any(
432 m_spChart2ModelContact->GetPageSize() ));
433 }
434}
436{
437 Any aRet;
438 Reference< beans::XPropertySet > xProp( getTitleObject(), uno::UNO_QUERY );
439 if( xProp.is() )
440 aRet = xProp->getPropertyValue( "ReferencePageSize" );
441
442 return aRet;
443}
445{
446 return m_spChart2ModelContact->GetPageSize();
447}
448
450{
451 return TitleHelper::getTitle( m_eTitleType, m_spChart2ModelContact->getDocumentModel() );
452}
453
454// WrappedPropertySet
455
457{
458 return Reference< beans::XPropertySet >( getTitleObject(), uno::UNO_QUERY );
459}
460
462{
463 return StaticTitleWrapperPropertyArray();
464}
465
466std::vector< std::unique_ptr<WrappedProperty> > TitleWrapper::createWrappedProperties()
467{
468 std::vector< std::unique_ptr<WrappedProperty> > aWrappedProperties;
469
470 aWrappedProperties.emplace_back( new WrappedTitleStringProperty( m_spChart2ModelContact->m_xContext ) );
471 aWrappedProperties.emplace_back( new WrappedTextRotationProperty( true ) );
472 aWrappedProperties.emplace_back( new WrappedStackedTextProperty() );
476
477 return aWrappedProperties;
478}
479
481{
482 return "com.sun.star.comp.chart.Title";
483}
484
485sal_Bool SAL_CALL TitleWrapper::supportsService( const OUString& rServiceName )
486{
487 return cppu::supportsService(this, rServiceName);
488}
489
490css::uno::Sequence< OUString > SAL_CALL TitleWrapper::getSupportedServiceNames()
491{
492 return {
493 "com.sun.star.chart.ChartTitle",
494 "com.sun.star.drawing.Shape",
495 "com.sun.star.xml.UserDefinedAttributesSupplier",
496 "com.sun.star.style.CharacterProperties"
497 };
498}
499
500} // namespace chart
501
502/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
Reference< uno::XComponentContext > m_xContext
PropertiesInfo aProperties
TitleHelper::eTitleType m_eTitleType
This guard calls lockControllers at the given Model in the CTOR and unlockControllers in the DTOR.
static rtl::Reference< ::chart::Title > getTitle(eTitleType nTitleIndex, ChartModel &rModel)
static rtl::Reference< ::chart::Title > createTitle(eTitleType nTitleIndex, const OUString &rTitleText, const rtl::Reference< ::chart::ChartModel > &xModel, const css::uno::Reference< css::uno::XComponentContext > &xContext, ReferenceSizeProvider *pRefSizeProvider=nullptr)
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual css::beans::PropertyState getPropertyState(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyDefault(const css::uno::Reference< css::beans::XPropertyState > &xInnerPropertyState) const
virtual css::uno::Any getPropertyValue(const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
virtual void setPropertyValue(const css::uno::Any &rOuterValue, const css::uno::Reference< css::beans::XPropertySet > &xInnerPropertySet) const
virtual std::vector< std::unique_ptr< WrappedProperty > > createWrappedProperties() override
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
virtual void updateReferenceSize() override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual OUString SAL_CALL getImplementationName() override
XServiceInfo declarations.
virtual css::awt::Size SAL_CALL getSize() override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
virtual void SAL_CALL setPosition(const css::awt::Point &aPosition) override
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
virtual css::uno::Any SAL_CALL getPropertyDefault(const OUString &aPropertyName) override
TitleWrapper(::chart::TitleHelper::eTitleType eTitleType, std::shared_ptr< Chart2ModelContact > spChart2ModelContact)
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
void setFastCharacterPropertyValue(sal_Int32 nHandle, const css::uno::Any &rValue)
css::uno::Reference< css::chart2::XTitle > getTitleObject()
::comphelper::OInterfaceContainerHelper4< css::lang::XEventListener > m_aEventListenerContainer
virtual css::awt::Size getCurrentSizeForReference() override
virtual css::awt::Point SAL_CALL getPosition() override
virtual css::beans::PropertyState SAL_CALL getPropertyState(const OUString &PropertyName) override
virtual css::uno::Any getReferenceSize() override
virtual void SAL_CALL dispose() override
std::shared_ptr< Chart2ModelContact > m_spChart2ModelContact
::chart::TitleHelper::eTitleType m_eTitleType
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
virtual void SAL_CALL setSize(const css::awt::Size &aSize) override
virtual OUString SAL_CALL getShapeType() override
virtual const css::uno::Sequence< css::beans::Property > & getPropertySequence() override
virtual void SAL_CALL setPropertyToDefault(const OUString &PropertyName) override
void getFastCharacterPropertyValue(sal_Int32 nHandle, css::uno::Any &rValue)
virtual ~TitleWrapper() override
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual css::uno::Reference< css::beans::XPropertySet > getInnerPropertySet() override
css::uno::Reference< css::beans::XPropertySet > getFirstCharacterPropertySet()
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList)
static void addProperties(std::vector< css::beans::Property > &rOutProperties)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, ReferenceSizePropertyProvider *pRefSizePropProvider)
static void addProperties(std::vector< css::beans::Property > &rOutProperties)
static void addWrappedProperties(std::vector< std::unique_ptr< WrappedProperty > > &rList, const std::shared_ptr< Chart2ModelContact > &spChart2ModelContact)
sal_Int32 addInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(::std::unique_lock<::std::mutex > &rGuard, const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(std::unique_lock< std::mutex > &rGuard, const css::uno::Reference< ListenerT > &rxIFace)
std::mutex m_aMutex
aBuf
OOO_DLLPUBLIC_CHARTTOOLS bool IsCharacterPropertyHandle(sal_Int32 nHandle)
OOO_DLLPUBLIC_CHARTTOOLS void AddPropertiesToVector(std::vector< css::beans::Property > &rOutProperties)
void setPropertyValue(tPropertyValueMap &rOutMap, tPropertyValueMapKey key, const Value &value)
Set a property to a certain value in the given map.
@ FAST_PROPERTY_ID_START_CHAR_PROP
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
Title
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
sal_Int32 nHandle
unsigned char sal_Bool