1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_chart2.hxx"
32 #include "FormattedString.hxx"
33 #include "LineProperties.hxx"
34 #include "FillProperties.hxx"
35 #include "ContainerHelper.hxx"
36 #include "CloneHelper.hxx"
37 #include "PropertyHelper.hxx"
38 #include <com/sun/star/beans/PropertyAttribute.hpp>
39 #include <com/sun/star/style/ParagraphAdjust.hpp>
40 #include <com/sun/star/drawing/FillStyle.hpp>
41 #include <com/sun/star/drawing/LineStyle.hpp>
42 #include <com/sun/star/chart2/RelativePosition.hpp>
43 #include <com/sun/star/awt/Size.hpp>
45 #include <cppuhelper/queryinterface.hxx>
50 using namespace ::com::sun::star
;
51 using namespace ::com::sun::star::beans::PropertyAttribute
;
53 using ::com::sun::star::beans::Property
;
54 using ::osl::MutexGuard
;
59 static const ::rtl::OUString
lcl_aServiceName(
60 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Title" ));
64 PROP_TITLE_PARA_ADJUST
,
65 PROP_TITLE_PARA_LAST_LINE_ADJUST
,
66 PROP_TITLE_PARA_LEFT_MARGIN
,
67 PROP_TITLE_PARA_RIGHT_MARGIN
,
68 PROP_TITLE_PARA_TOP_MARGIN
,
69 PROP_TITLE_PARA_BOTTOM_MARGIN
,
70 PROP_TITLE_PARA_IS_HYPHENATION
,
72 PROP_TITLE_TEXT_ROTATION
,
73 PROP_TITLE_TEXT_STACKED
,
76 PROP_TITLE_REF_PAGE_SIZE
79 void lcl_AddPropertiesToVector(
80 ::std::vector
< Property
> & rOutProperties
)
82 rOutProperties
.push_back(
83 Property( C2U( "ParaAdjust" ),
84 PROP_TITLE_PARA_ADJUST
,
85 ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust
* >(0)),
86 beans::PropertyAttribute::BOUND
87 | beans::PropertyAttribute::MAYBEDEFAULT
));
89 rOutProperties
.push_back(
90 Property( C2U( "ParaLastLineAdjust" ),
91 PROP_TITLE_PARA_LAST_LINE_ADJUST
,
92 ::getCppuType( reinterpret_cast< sal_Int16
* >(0)),
93 beans::PropertyAttribute::BOUND
94 | beans::PropertyAttribute::MAYBEDEFAULT
));
96 rOutProperties
.push_back(
97 Property( C2U( "ParaLeftMargin" ),
98 PROP_TITLE_PARA_LEFT_MARGIN
,
99 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
100 beans::PropertyAttribute::BOUND
101 | beans::PropertyAttribute::MAYBEDEFAULT
));
103 rOutProperties
.push_back(
104 Property( C2U( "ParaRightMargin" ),
105 PROP_TITLE_PARA_RIGHT_MARGIN
,
106 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
107 beans::PropertyAttribute::BOUND
108 | beans::PropertyAttribute::MAYBEDEFAULT
));
110 rOutProperties
.push_back(
111 Property( C2U( "ParaTopMargin" ),
112 PROP_TITLE_PARA_TOP_MARGIN
,
113 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
114 beans::PropertyAttribute::BOUND
115 | beans::PropertyAttribute::MAYBEDEFAULT
));
117 rOutProperties
.push_back(
118 Property( C2U( "ParaBottomMargin" ),
119 PROP_TITLE_PARA_BOTTOM_MARGIN
,
120 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
121 beans::PropertyAttribute::BOUND
122 | beans::PropertyAttribute::MAYBEDEFAULT
));
124 rOutProperties
.push_back(
125 Property( C2U( "ParaIsHyphenation" ),
126 PROP_TITLE_PARA_IS_HYPHENATION
,
127 ::getBooleanCppuType(),
128 beans::PropertyAttribute::BOUND
129 | beans::PropertyAttribute::MAYBEDEFAULT
));
131 rOutProperties
.push_back(
132 Property( C2U( "TextRotation" ),
133 PROP_TITLE_TEXT_ROTATION
,
134 ::getCppuType( reinterpret_cast< const double * >(0)),
135 beans::PropertyAttribute::BOUND
136 | beans::PropertyAttribute::MAYBEDEFAULT
));
137 rOutProperties
.push_back(
138 Property( C2U( "StackCharacters" ),
139 PROP_TITLE_TEXT_STACKED
,
140 ::getBooleanCppuType(),
141 beans::PropertyAttribute::BOUND
142 | beans::PropertyAttribute::MAYBEDEFAULT
));
144 rOutProperties
.push_back(
145 Property( C2U( "RelativePosition" ),
147 ::getCppuType( reinterpret_cast< const chart2::RelativePosition
* >(0)),
148 beans::PropertyAttribute::BOUND
149 | beans::PropertyAttribute::MAYBEVOID
));
151 rOutProperties
.push_back(
152 Property( C2U( "ReferencePageSize" ),
153 PROP_TITLE_REF_PAGE_SIZE
,
154 ::getCppuType( reinterpret_cast< const awt::Size
* >(0)),
155 beans::PropertyAttribute::BOUND
156 | beans::PropertyAttribute::MAYBEVOID
));
159 void lcl_AddDefaultsToMap(
160 ::chart::tPropertyValueMap
& rOutMap
)
162 // ParagraphProperties
163 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_ADJUST
,
164 ::com::sun::star::style::ParagraphAdjust_CENTER
);
165 // PROP_TITLE_PARA_LAST_LINE_ADJUST
167 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_LEFT_MARGIN
, 0 );
168 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_RIGHT_MARGIN
, 0 );
169 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_TOP_MARGIN
, 0 );
170 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_BOTTOM_MARGIN
, 0 );
171 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_IS_HYPHENATION
, true );
174 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_TITLE_TEXT_ROTATION
, 0.0 );
175 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_TEXT_STACKED
, false );
177 // override other defaults
178 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
179 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::LineProperties::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
182 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
184 static uno::Sequence
< Property
> aPropSeq
;
187 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
188 if( 0 == aPropSeq
.getLength() )
191 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
192 lcl_AddPropertiesToVector( aProperties
);
193 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
194 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
196 // and sort them for access via bsearch
197 ::std::sort( aProperties
.begin(), aProperties
.end(),
198 ::chart::PropertyNameLess() );
200 // transfer result to static Sequence
201 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
207 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
209 static ::cppu::OPropertyArrayHelper
aArrayHelper(
210 lcl_GetPropertySequence(),
211 /* bSorted = */ sal_True
);
216 } // anonymous namespace
218 // ================================================================================
223 Title::Title( uno::Reference
< uno::XComponentContext
> const & /* xContext */ ) :
224 ::property::OPropertySet( m_aMutex
),
225 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
228 Title::Title( const Title
& rOther
) :
231 ::property::OPropertySet( rOther
, m_aMutex
),
232 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
234 CloneHelper::CloneRefSequence
< uno::Reference
< chart2::XFormattedString
> >(
235 rOther
.m_aStrings
, m_aStrings
);
236 ModifyListenerHelper::addListenerToAllElements(
237 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
242 ModifyListenerHelper::removeListenerFromAllElements(
243 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
246 // ____ XCloneable ____
247 uno::Reference
< util::XCloneable
> SAL_CALL
Title::createClone()
248 throw (uno::RuntimeException
)
250 return uno::Reference
< util::XCloneable
>( new Title( *this ));
253 // --------------------------------------------------------------------------------
256 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
Title::getText()
257 throw (uno::RuntimeException
)
259 MutexGuard
aGuard( GetMutex() );
263 void SAL_CALL
Title::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& rNewStrings
)
264 throw (uno::RuntimeException
)
266 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > aOldStrings
;
268 MutexGuard
aGuard( GetMutex() );
269 std::swap( m_aStrings
, aOldStrings
);
270 m_aStrings
= rNewStrings
;
272 //don't keep the mutex locked while calling out
273 ModifyListenerHelper::removeListenerFromAllElements(
274 ContainerHelper::SequenceToVector( aOldStrings
), m_xModifyEventForwarder
);
275 ModifyListenerHelper::addListenerToAllElements(
276 ContainerHelper::SequenceToVector( rNewStrings
), m_xModifyEventForwarder
);
280 // ================================================================================
282 // ____ OPropertySet ____
283 uno::Any
Title::GetDefaultValue( sal_Int32 nHandle
) const
284 throw(beans::UnknownPropertyException
)
286 static tPropertyValueMap aStaticDefaults
;
289 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
290 if( 0 == aStaticDefaults
.size() )
292 LineProperties::AddDefaultsToMap( aStaticDefaults
);
293 FillProperties::AddDefaultsToMap( aStaticDefaults
);
295 // initialize defaults
296 // Note: this should be last to override defaults of the previously
298 lcl_AddDefaultsToMap( aStaticDefaults
);
301 tPropertyValueMap::const_iterator
aFound(
302 aStaticDefaults
.find( nHandle
));
304 if( aFound
== aStaticDefaults
.end())
307 return (*aFound
).second
;
311 ::cppu::IPropertyArrayHelper
& SAL_CALL
Title::getInfoHelper()
313 return lcl_getInfoHelper();
317 // ____ XPropertySet ____
318 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
319 Title::getPropertySetInfo()
320 throw (uno::RuntimeException
)
322 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
325 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
328 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
336 // ____ XModifyBroadcaster ____
337 void SAL_CALL
Title::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
338 throw (uno::RuntimeException
)
342 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
343 xBroadcaster
->addModifyListener( aListener
);
345 catch( const uno::Exception
& ex
)
347 ASSERT_EXCEPTION( ex
);
351 void SAL_CALL
Title::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
352 throw (uno::RuntimeException
)
356 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
357 xBroadcaster
->removeModifyListener( aListener
);
359 catch( const uno::Exception
& ex
)
361 ASSERT_EXCEPTION( ex
);
365 // ____ XModifyListener ____
366 void SAL_CALL
Title::modified( const lang::EventObject
& aEvent
)
367 throw (uno::RuntimeException
)
369 m_xModifyEventForwarder
->modified( aEvent
);
372 // ____ XEventListener (base of XModifyListener) ____
373 void SAL_CALL
Title::disposing( const lang::EventObject
& /* Source */ )
374 throw (uno::RuntimeException
)
379 // ____ OPropertySet ____
380 void Title::firePropertyChangeEvent()
385 void Title::fireModifyEvent()
387 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
391 // ================================================================================
393 uno::Sequence
< ::rtl::OUString
> Title::getSupportedServiceNames_Static()
395 uno::Sequence
< ::rtl::OUString
> aServices( 4 );
396 aServices
[ 0 ] = C2U( "com.sun.star.chart2.Title" );
397 aServices
[ 1 ] = C2U( "com.sun.star.style.ParagraphProperties" );
398 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
399 aServices
[ 3 ] = C2U( "com.sun.star.layout.LayoutElement" );
403 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
404 APPHELPER_XSERVICEINFO_IMPL( Title
, lcl_aServiceName
);
406 // needed by MSC compiler
407 using impl::Title_Base
;
409 IMPLEMENT_FORWARD_XINTERFACE2( Title
, Title_Base
, ::property::OPropertySet
)
410 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title
, Title_Base
, ::property::OPropertySet
)