1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Title.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_chart2.hxx"
35 #include "FormattedString.hxx"
36 #include "LineProperties.hxx"
37 #include "FillProperties.hxx"
38 #include "ContainerHelper.hxx"
39 #include "CloneHelper.hxx"
40 #include "PropertyHelper.hxx"
41 #include <com/sun/star/beans/PropertyAttribute.hpp>
42 #include <com/sun/star/style/ParagraphAdjust.hpp>
43 #include <com/sun/star/drawing/FillStyle.hpp>
44 #include <com/sun/star/drawing/LineStyle.hpp>
45 #include <com/sun/star/chart2/RelativePosition.hpp>
46 #include <com/sun/star/awt/Size.hpp>
48 #include <cppuhelper/queryinterface.hxx>
53 using namespace ::com::sun::star
;
54 using namespace ::com::sun::star::beans::PropertyAttribute
;
56 using ::com::sun::star::beans::Property
;
57 using ::osl::MutexGuard
;
62 static const ::rtl::OUString
lcl_aServiceName(
63 RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.comp.chart2.Title" ));
67 PROP_TITLE_PARA_ADJUST
,
68 PROP_TITLE_PARA_LAST_LINE_ADJUST
,
69 PROP_TITLE_PARA_LEFT_MARGIN
,
70 PROP_TITLE_PARA_RIGHT_MARGIN
,
71 PROP_TITLE_PARA_TOP_MARGIN
,
72 PROP_TITLE_PARA_BOTTOM_MARGIN
,
73 PROP_TITLE_PARA_IS_HYPHENATION
,
75 PROP_TITLE_TEXT_ROTATION
,
76 PROP_TITLE_TEXT_STACKED
,
79 PROP_TITLE_REF_PAGE_SIZE
82 void lcl_AddPropertiesToVector(
83 ::std::vector
< Property
> & rOutProperties
)
85 rOutProperties
.push_back(
86 Property( C2U( "ParaAdjust" ),
87 PROP_TITLE_PARA_ADJUST
,
88 ::getCppuType( reinterpret_cast< ::com::sun::star::style::ParagraphAdjust
* >(0)),
89 beans::PropertyAttribute::BOUND
90 | beans::PropertyAttribute::MAYBEDEFAULT
));
92 rOutProperties
.push_back(
93 Property( C2U( "ParaLastLineAdjust" ),
94 PROP_TITLE_PARA_LAST_LINE_ADJUST
,
95 ::getCppuType( reinterpret_cast< sal_Int16
* >(0)),
96 beans::PropertyAttribute::BOUND
97 | beans::PropertyAttribute::MAYBEDEFAULT
));
99 rOutProperties
.push_back(
100 Property( C2U( "ParaLeftMargin" ),
101 PROP_TITLE_PARA_LEFT_MARGIN
,
102 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT
));
106 rOutProperties
.push_back(
107 Property( C2U( "ParaRightMargin" ),
108 PROP_TITLE_PARA_RIGHT_MARGIN
,
109 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
110 beans::PropertyAttribute::BOUND
111 | beans::PropertyAttribute::MAYBEDEFAULT
));
113 rOutProperties
.push_back(
114 Property( C2U( "ParaTopMargin" ),
115 PROP_TITLE_PARA_TOP_MARGIN
,
116 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
117 beans::PropertyAttribute::BOUND
118 | beans::PropertyAttribute::MAYBEDEFAULT
));
120 rOutProperties
.push_back(
121 Property( C2U( "ParaBottomMargin" ),
122 PROP_TITLE_PARA_BOTTOM_MARGIN
,
123 ::getCppuType( reinterpret_cast< sal_Int32
* >(0)),
124 beans::PropertyAttribute::BOUND
125 | beans::PropertyAttribute::MAYBEDEFAULT
));
127 rOutProperties
.push_back(
128 Property( C2U( "ParaIsHyphenation" ),
129 PROP_TITLE_PARA_IS_HYPHENATION
,
130 ::getBooleanCppuType(),
131 beans::PropertyAttribute::BOUND
132 | beans::PropertyAttribute::MAYBEDEFAULT
));
134 rOutProperties
.push_back(
135 Property( C2U( "TextRotation" ),
136 PROP_TITLE_TEXT_ROTATION
,
137 ::getCppuType( reinterpret_cast< const double * >(0)),
138 beans::PropertyAttribute::BOUND
139 | beans::PropertyAttribute::MAYBEDEFAULT
));
140 rOutProperties
.push_back(
141 Property( C2U( "StackCharacters" ),
142 PROP_TITLE_TEXT_STACKED
,
143 ::getBooleanCppuType(),
144 beans::PropertyAttribute::BOUND
145 | beans::PropertyAttribute::MAYBEDEFAULT
));
147 rOutProperties
.push_back(
148 Property( C2U( "RelativePosition" ),
150 ::getCppuType( reinterpret_cast< const chart2::RelativePosition
* >(0)),
151 beans::PropertyAttribute::BOUND
152 | beans::PropertyAttribute::MAYBEVOID
));
154 rOutProperties
.push_back(
155 Property( C2U( "ReferencePageSize" ),
156 PROP_TITLE_REF_PAGE_SIZE
,
157 ::getCppuType( reinterpret_cast< const awt::Size
* >(0)),
158 beans::PropertyAttribute::BOUND
159 | beans::PropertyAttribute::MAYBEVOID
));
162 void lcl_AddDefaultsToMap(
163 ::chart::tPropertyValueMap
& rOutMap
)
165 // ParagraphProperties
166 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_ADJUST
,
167 ::com::sun::star::style::ParagraphAdjust_CENTER
);
168 // PROP_TITLE_PARA_LAST_LINE_ADJUST
170 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_LEFT_MARGIN
, 0 );
171 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_RIGHT_MARGIN
, 0 );
172 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_TOP_MARGIN
, 0 );
173 ::chart::PropertyHelper::setPropertyValueDefault
< sal_Int32
>( rOutMap
, PROP_TITLE_PARA_BOTTOM_MARGIN
, 0 );
174 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_PARA_IS_HYPHENATION
, true );
177 ::chart::PropertyHelper::setPropertyValueDefault
< double >( rOutMap
, PROP_TITLE_TEXT_ROTATION
, 0.0 );
178 ::chart::PropertyHelper::setPropertyValueDefault( rOutMap
, PROP_TITLE_TEXT_STACKED
, false );
180 // override other defaults
181 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::FillProperties::PROP_FILL_STYLE
, drawing::FillStyle_NONE
);
182 ::chart::PropertyHelper::setPropertyValue( rOutMap
, ::chart::LineProperties::PROP_LINE_STYLE
, drawing::LineStyle_NONE
);
185 const uno::Sequence
< Property
> & lcl_GetPropertySequence()
187 static uno::Sequence
< Property
> aPropSeq
;
190 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
191 if( 0 == aPropSeq
.getLength() )
194 ::std::vector
< ::com::sun::star::beans::Property
> aProperties
;
195 lcl_AddPropertiesToVector( aProperties
);
196 ::chart::LineProperties::AddPropertiesToVector( aProperties
);
197 ::chart::FillProperties::AddPropertiesToVector( aProperties
);
199 // and sort them for access via bsearch
200 ::std::sort( aProperties
.begin(), aProperties
.end(),
201 ::chart::PropertyNameLess() );
203 // transfer result to static Sequence
204 aPropSeq
= ::chart::ContainerHelper::ContainerToSequence( aProperties
);
210 ::cppu::IPropertyArrayHelper
& lcl_getInfoHelper()
212 static ::cppu::OPropertyArrayHelper
aArrayHelper(
213 lcl_GetPropertySequence(),
214 /* bSorted = */ sal_True
);
219 } // anonymous namespace
221 // ================================================================================
226 Title::Title( uno::Reference
< uno::XComponentContext
> const & /* xContext */ ) :
227 ::property::OPropertySet( m_aMutex
),
228 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
231 Title::Title( const Title
& rOther
) :
234 ::property::OPropertySet( rOther
, m_aMutex
),
235 m_xModifyEventForwarder( ModifyListenerHelper::createModifyEventForwarder())
237 CloneHelper::CloneRefSequence
< uno::Reference
< chart2::XFormattedString
> >(
238 rOther
.m_aStrings
, m_aStrings
);
239 ModifyListenerHelper::addListenerToAllElements(
240 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
245 ModifyListenerHelper::removeListenerFromAllElements(
246 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
249 // ____ XCloneable ____
250 uno::Reference
< util::XCloneable
> SAL_CALL
Title::createClone()
251 throw (uno::RuntimeException
)
253 return uno::Reference
< util::XCloneable
>( new Title( *this ));
256 // --------------------------------------------------------------------------------
259 uno::Sequence
< uno::Reference
< chart2::XFormattedString
> > SAL_CALL
Title::getText()
260 throw (uno::RuntimeException
)
263 MutexGuard
aGuard( GetMutex() );
268 void SAL_CALL
Title::setText( const uno::Sequence
< uno::Reference
< chart2::XFormattedString
> >& Strings
)
269 throw (uno::RuntimeException
)
272 MutexGuard
aGuard( GetMutex() );
273 ModifyListenerHelper::removeListenerFromAllElements(
274 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
275 m_aStrings
= Strings
;
276 ModifyListenerHelper::addListenerToAllElements(
277 ContainerHelper::SequenceToVector( m_aStrings
), m_xModifyEventForwarder
);
282 // ================================================================================
284 // ____ OPropertySet ____
285 uno::Any
Title::GetDefaultValue( sal_Int32 nHandle
) const
286 throw(beans::UnknownPropertyException
)
288 static tPropertyValueMap aStaticDefaults
;
291 ::osl::MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
292 if( 0 == aStaticDefaults
.size() )
294 LineProperties::AddDefaultsToMap( aStaticDefaults
);
295 FillProperties::AddDefaultsToMap( aStaticDefaults
);
297 // initialize defaults
298 // Note: this should be last to override defaults of the previously
300 lcl_AddDefaultsToMap( aStaticDefaults
);
303 tPropertyValueMap::const_iterator
aFound(
304 aStaticDefaults
.find( nHandle
));
306 if( aFound
== aStaticDefaults
.end())
309 return (*aFound
).second
;
313 ::cppu::IPropertyArrayHelper
& SAL_CALL
Title::getInfoHelper()
315 return lcl_getInfoHelper();
319 // ____ XPropertySet ____
320 uno::Reference
< beans::XPropertySetInfo
> SAL_CALL
321 Title::getPropertySetInfo()
322 throw (uno::RuntimeException
)
324 static uno::Reference
< beans::XPropertySetInfo
> xInfo
;
327 MutexGuard
aGuard( ::osl::Mutex::getGlobalMutex() );
330 xInfo
= ::cppu::OPropertySetHelper::createPropertySetInfo(
338 // ____ XModifyBroadcaster ____
339 void SAL_CALL
Title::addModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
340 throw (uno::RuntimeException
)
344 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
345 xBroadcaster
->addModifyListener( aListener
);
347 catch( const uno::Exception
& ex
)
349 ASSERT_EXCEPTION( ex
);
353 void SAL_CALL
Title::removeModifyListener( const uno::Reference
< util::XModifyListener
>& aListener
)
354 throw (uno::RuntimeException
)
358 uno::Reference
< util::XModifyBroadcaster
> xBroadcaster( m_xModifyEventForwarder
, uno::UNO_QUERY_THROW
);
359 xBroadcaster
->removeModifyListener( aListener
);
361 catch( const uno::Exception
& ex
)
363 ASSERT_EXCEPTION( ex
);
367 // ____ XModifyListener ____
368 void SAL_CALL
Title::modified( const lang::EventObject
& aEvent
)
369 throw (uno::RuntimeException
)
371 m_xModifyEventForwarder
->modified( aEvent
);
374 // ____ XEventListener (base of XModifyListener) ____
375 void SAL_CALL
Title::disposing( const lang::EventObject
& /* Source */ )
376 throw (uno::RuntimeException
)
381 // ____ OPropertySet ____
382 void Title::firePropertyChangeEvent()
387 void Title::fireModifyEvent()
389 m_xModifyEventForwarder
->modified( lang::EventObject( static_cast< uno::XWeak
* >( this )));
393 // ================================================================================
395 uno::Sequence
< ::rtl::OUString
> Title::getSupportedServiceNames_Static()
397 uno::Sequence
< ::rtl::OUString
> aServices( 4 );
398 aServices
[ 0 ] = C2U( "com.sun.star.chart2.Title" );
399 aServices
[ 1 ] = C2U( "com.sun.star.style.ParagraphProperties" );
400 aServices
[ 2 ] = C2U( "com.sun.star.beans.PropertySet" );
401 aServices
[ 3 ] = C2U( "com.sun.star.layout.LayoutElement" );
405 // implement XServiceInfo methods basing upon getSupportedServiceNames_Static
406 APPHELPER_XSERVICEINFO_IMPL( Title
, lcl_aServiceName
);
408 // needed by MSC compiler
409 using impl::Title_Base
;
411 IMPLEMENT_FORWARD_XINTERFACE2( Title
, Title_Base
, ::property::OPropertySet
)
412 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title
, Title_Base
, ::property::OPropertySet
)