1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
35 #include <cppuhelper/queryinterface.hxx>
36 #include <cppuhelper/supportsservice.hxx>
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::beans::PropertyAttribute
;
44 using ::com::sun::star::beans::Property
;
45 using ::osl::MutexGuard
;
50 static const char lcl_aServiceName
[] = "com.sun.star.comp.chart2.Title";
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
,
62 PROP_TITLE_TEXT_ROTATION
,
63 PROP_TITLE_TEXT_STACKED
,
66 PROP_TITLE_REF_PAGE_SIZE
69 void lcl_AddPropertiesToVector(
70 ::std::vector
< Property
> & rOutProperties
)
72 rOutProperties
.push_back(
73 Property( "ParaAdjust",
74 PROP_TITLE_PARA_ADJUST
,
75 cppu::UnoType
<com::sun::star::style::ParagraphAdjust
>::get(),
76 beans::PropertyAttribute::BOUND
77 | beans::PropertyAttribute::MAYBEDEFAULT
));
79 rOutProperties
.push_back(
80 Property( "ParaLastLineAdjust",
81 PROP_TITLE_PARA_LAST_LINE_ADJUST
,
82 cppu::UnoType
<sal_Int16
>::get(),
83 beans::PropertyAttribute::BOUND
84 | beans::PropertyAttribute::MAYBEDEFAULT
));
86 rOutProperties
.push_back(
87 Property( "ParaLeftMargin",
88 PROP_TITLE_PARA_LEFT_MARGIN
,
89 cppu::UnoType
<sal_Int32
>::get(),
90 beans::PropertyAttribute::BOUND
91 | beans::PropertyAttribute::MAYBEDEFAULT
));
93 rOutProperties
.push_back(
94 Property( "ParaRightMargin",
95 PROP_TITLE_PARA_RIGHT_MARGIN
,
96 cppu::UnoType
<sal_Int32
>::get(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEDEFAULT
));
100 rOutProperties
.push_back(
101 Property( "ParaTopMargin",
102 PROP_TITLE_PARA_TOP_MARGIN
,
103 cppu::UnoType
<sal_Int32
>::get(),
104 beans::PropertyAttribute::BOUND
105 | beans::PropertyAttribute::MAYBEDEFAULT
));
107 rOutProperties
.push_back(
108 Property( "ParaBottomMargin",
109 PROP_TITLE_PARA_BOTTOM_MARGIN
,
110 cppu::UnoType
<sal_Int32
>::get(),
111 beans::PropertyAttribute::BOUND
112 | beans::PropertyAttribute::MAYBEDEFAULT
));
114 rOutProperties
.push_back(
115 Property( "ParaIsHyphenation",
116 PROP_TITLE_PARA_IS_HYPHENATION
,
117 cppu::UnoType
<bool>::get(),
118 beans::PropertyAttribute::BOUND
119 | beans::PropertyAttribute::MAYBEDEFAULT
));
121 rOutProperties
.push_back(
122 Property( "TextRotation",
123 PROP_TITLE_TEXT_ROTATION
,
124 cppu::UnoType
<double>::get(),
125 beans::PropertyAttribute::BOUND
126 | beans::PropertyAttribute::MAYBEDEFAULT
));
127 rOutProperties
.push_back(
128 Property( "StackCharacters",
129 PROP_TITLE_TEXT_STACKED
,
130 cppu::UnoType
<bool>::get(),
131 beans::PropertyAttribute::BOUND
132 | beans::PropertyAttribute::MAYBEDEFAULT
));
134 rOutProperties
.push_back(
135 Property( "RelativePosition",
137 cppu::UnoType
<chart2::RelativePosition
>::get(),
138 beans::PropertyAttribute::BOUND
139 | beans::PropertyAttribute::MAYBEVOID
));
141 rOutProperties
.push_back(
142 Property( "ReferencePageSize",
143 PROP_TITLE_REF_PAGE_SIZE
,
144 cppu::UnoType
<awt::Size
>::get(),
145 beans::PropertyAttribute::BOUND
146 | beans::PropertyAttribute::MAYBEVOID
));
149 struct StaticTitleDefaults_Initializer
151 ::chart::tPropertyValueMap
* operator()()
153 static ::chart::tPropertyValueMap aStaticDefaults
;
154 lcl_AddDefaultsToMap( aStaticDefaults
);
155 return &aStaticDefaults
;
158 static void lcl_AddDefaultsToMap( ::chart::tPropertyValueMap
& rOutMap
)
160 ::chart::LinePropertiesHelper::AddDefaultsToMap( rOutMap
);
161 ::chart::FillProperties::AddDefaultsToMap( rOutMap
);
163 // ParagraphProperties
164 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_ADJUST
,
165 ::com::sun::star::style::ParagraphAdjust_CENTER
);
166 // PROP_TITLE_PARA_LAST_LINE_ADJUST
168 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_LEFT_MARGIN
, 0 );
169 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_RIGHT_MARGIN
, 0 );
170 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_TOP_MARGIN
, 0 );
171 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_BOTTOM_MARGIN
, 0 );
172 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_IS_HYPHENATION
, true );
175 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_TITLE_TEXT_ROTATION
, 0.0 );
176 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_TEXT_STACKED
, false );
178 // override other defaults
179 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
180 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::LinePropertiesHelper::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
184 struct StaticTitleDefaults
: public rtl::StaticAggregate
< ::chart::tPropertyValueMap
, StaticTitleDefaults_Initializer
>
188 struct StaticTitleInfoHelper_Initializer
190 ::cppu::OPropertyArrayHelper
* operator()()
192 static ::cppu::OPropertyArrayHelper
aPropHelper( lcl_GetPropertySequence() );
197 static uno::Sequence
< Property
> lcl_GetPropertySequence()
199 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
200 lcl_AddPropertiesToVector( aProperties
);
201 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties
);
202 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
204 ::std::sort( aProperties
.begin(), aProperties
.end(),
205 ::chart::PropertyNameLess() );
207 return ::chart::ContainerHelper::ContainerToSequence( aProperties
);
212 struct StaticTitleInfoHelper
: public rtl::StaticAggregate
< ::cppu::OPropertyArrayHelper
, StaticTitleInfoHelper_Initializer
>
216 struct StaticTitleInfo_Initializer
218 uno::Reference
< beans::XPropertySetInfo
>* operator()()
220 static uno::Reference
< beans::XPropertySetInfo
> xPropertySetInfo(
221 ::cppu::OPropertySetHelper::createPropertySetInfo(*StaticTitleInfoHelper::get() ) );
222 return &xPropertySetInfo
;
226 struct StaticTitleInfo
: public rtl::StaticAggregate
< uno::Reference
< beans::XPropertySetInfo
>, StaticTitleInfo_Initializer
>
230 } // anonymous namespace
235 Title::Title( uno::Reference
< uno::XComponentContext
> const & /* xContext */ ) :
236 ::property::OPropertySet( m_aMutex
),
237 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
240 Title::Title( const Title
& rOther
) :
243 ::property::OPropertySet( rOther
, m_aMutex
),
244 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
246 CloneHelper::CloneRefSequence
< uno::Reference
< chart2::XFormattedString
> >(
247 rOther
.m_aStrings
, m_aStrings
);
248 ModifyListenerHelper::addListenerToAllElements(
249 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
254 ModifyListenerHelper::removeListenerFromAllElements(
255 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
258 // ____ XCloneable ____
259 uno::Reference
< util::XCloneable
> SAL_CALL
Title::createClone()
260 throw (uno::RuntimeException
, std::exception
)
262 return uno::Reference
< util::XCloneable
>( new Title( *this ));
266 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
Title::getText()
267 throw (uno::RuntimeException
, std::exception
)
269 MutexGuard
aGuard( GetMutex() );
273 void SAL_CALL
Title::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& rNewStrings
)
274 throw (uno::RuntimeException
, std::exception
)
276 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > aOldStrings
;
278 MutexGuard
aGuard( GetMutex() );
279 std::swap( m_aStrings
, aOldStrings
);
280 m_aStrings
= rNewStrings
;
282 //don't keep the mutex locked while calling out
283 ModifyListenerHelper::removeListenerFromAllElements(
284 ContainerHelper::SequenceToVector( aOldStrings
), m_xModifyEventForwarder
);
285 ModifyListenerHelper::addListenerToAllElements(
286 ContainerHelper::SequenceToVector( rNewStrings
), m_xModifyEventForwarder
);
290 // ____ OPropertySet ____
291 uno::Any
Title::GetDefaultValue( sal_Int32 nHandle
) const
292 throw(beans::UnknownPropertyException
)
294 const tPropertyValueMap
& rStaticDefaults
= *StaticTitleDefaults::get();
295 tPropertyValueMap::const_iterator
aFound( rStaticDefaults
.find( nHandle
) );
296 if( aFound
== rStaticDefaults
.end() )
298 return (*aFound
).second
;
301 ::cppu::IPropertyArrayHelper
& SAL_CALL
Title::getInfoHelper()
303 return *StaticTitleInfoHelper::get();
306 // ____ XPropertySet ____
307 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
Title::getPropertySetInfo()
308 throw (uno::RuntimeException
, std::exception
)
310 return *StaticTitleInfo::get();
313 // ____ XModifyBroadcaster ____
314 void SAL_CALL
Title::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
315 throw (uno::RuntimeException
, std::exception
)
319 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
320 xBroadcaster
->addModifyListener( aListener
);
322 catch( const uno::Exception
& ex
)
324 ASSERT_EXCEPTION( ex
);
328 void SAL_CALL
Title::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
329 throw (uno::RuntimeException
, std::exception
)
333 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
334 xBroadcaster
->removeModifyListener( aListener
);
336 catch( const uno::Exception
& ex
)
338 ASSERT_EXCEPTION( ex
);
342 // ____ XModifyListener ____
343 void SAL_CALL
Title::modified( const lang::EventObject
& aEvent
)
344 throw (uno::RuntimeException
, std::exception
)
346 m_xModifyEventForwarder
->modified( aEvent
);
349 // ____ XEventListener (base of XModifyListener) ____
350 void SAL_CALL
Title::disposing( const lang::EventObject
& /* Source */ )
351 throw (uno::RuntimeException
, std::exception
)
356 // ____ OPropertySet ____
357 void Title::firePropertyChangeEvent()
362 void Title::fireModifyEvent()
364 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
367 uno::Sequence
< OUString
> Title::getSupportedServiceNames_Static()
369 uno::Sequence
< OUString
> aServices( 4 );
370 aServices
[ 0 ] = "com.sun.star.chart2.Title";
371 aServices
[ 1 ] = "com.sun.star.style.ParagraphProperties";
372 aServices
[ 2 ] = "com.sun.star.beans.PropertySet";
373 aServices
[ 3 ] = "com.sun.star.layout.LayoutElement";
377 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
378 OUString SAL_CALL
Title::getImplementationName()
379 throw( css::uno::RuntimeException
, std::exception
)
381 return getImplementationName_Static();
384 OUString
Title::getImplementationName_Static()
386 return OUString(lcl_aServiceName
);
389 sal_Bool SAL_CALL
Title::supportsService( const OUString
& rServiceName
)
390 throw( css::uno::RuntimeException
, std::exception
)
392 return cppu::supportsService(this, rServiceName
);
395 css::uno::Sequence
< OUString
> SAL_CALL
Title::getSupportedServiceNames()
396 throw( css::uno::RuntimeException
, std::exception
)
398 return getSupportedServiceNames_Static();
401 // needed by MSC compiler
402 using impl::Title_Base
;
404 IMPLEMENT_FORWARD_XINTERFACE2( Title
, Title_Base
, ::property::OPropertySet
)
405 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title
, Title_Base
, ::property::OPropertySet
)
409 extern "C" SAL_DLLPUBLIC_EXPORT
css::uno::XInterface
* SAL_CALL
410 com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext
*context
,
411 css::uno::Sequence
<css::uno::Any
> const &)
413 return cppu::acquire(new ::chart::Title(context
));
416 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */