tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / chart2 / source / model / main / Title.cxx
blobd882304d43d36dd1ee87c7b11d96fbc586cf6617
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
20 #include <Title.hxx>
21 #include <CharacterProperties.hxx>
22 #include <LinePropertiesHelper.hxx>
23 #include <FillProperties.hxx>
24 #include <CloneHelper.hxx>
25 #include <PropertyHelper.hxx>
26 #include <ModifyListenerHelper.hxx>
27 #include <com/sun/star/beans/PropertyAttribute.hpp>
28 #include <com/sun/star/style/ParagraphAdjust.hpp>
29 #include <com/sun/star/drawing/FillStyle.hpp>
30 #include <com/sun/star/drawing/LineStyle.hpp>
31 #include <com/sun/star/chart2/RelativePosition.hpp>
32 #include <com/sun/star/awt/Size.hpp>
33 #include <cppuhelper/supportsservice.hxx>
35 #include <vector>
36 #include <algorithm>
38 namespace com::sun::star::uno { class XComponentContext; }
40 using namespace ::com::sun::star;
41 using namespace ::com::sun::star::beans::PropertyAttribute;
43 using ::com::sun::star::beans::Property;
44 using ::osl::MutexGuard;
46 namespace
49 enum
51 PROP_TITLE_PARA_ADJUST,
52 PROP_TITLE_PARA_LAST_LINE_ADJUST,
53 PROP_TITLE_PARA_LEFT_MARGIN,
54 PROP_TITLE_PARA_RIGHT_MARGIN,
55 PROP_TITLE_PARA_TOP_MARGIN,
56 PROP_TITLE_PARA_BOTTOM_MARGIN,
57 PROP_TITLE_PARA_IS_HYPHENATION,
58 PROP_TITLE_VISIBLE,
60 PROP_TITLE_TEXT_ROTATION,
61 PROP_TITLE_TEXT_STACKED,
62 PROP_TITLE_REL_POS,
64 PROP_TITLE_REF_PAGE_SIZE
67 void lcl_AddPropertiesToVector(
68 std::vector< Property > & rOutProperties )
70 rOutProperties.emplace_back( "ParaAdjust",
71 PROP_TITLE_PARA_ADJUST,
72 cppu::UnoType<css::style::ParagraphAdjust>::get(),
73 beans::PropertyAttribute::BOUND
74 | beans::PropertyAttribute::MAYBEDEFAULT );
76 rOutProperties.emplace_back( "ParaLastLineAdjust",
77 PROP_TITLE_PARA_LAST_LINE_ADJUST,
78 cppu::UnoType<sal_Int16>::get(),
79 beans::PropertyAttribute::BOUND
80 | beans::PropertyAttribute::MAYBEDEFAULT );
82 rOutProperties.emplace_back( "ParaLeftMargin",
83 PROP_TITLE_PARA_LEFT_MARGIN,
84 cppu::UnoType<sal_Int32>::get(),
85 beans::PropertyAttribute::BOUND
86 | beans::PropertyAttribute::MAYBEDEFAULT );
88 rOutProperties.emplace_back( "ParaRightMargin",
89 PROP_TITLE_PARA_RIGHT_MARGIN,
90 cppu::UnoType<sal_Int32>::get(),
91 beans::PropertyAttribute::BOUND
92 | beans::PropertyAttribute::MAYBEDEFAULT );
94 rOutProperties.emplace_back( "ParaTopMargin",
95 PROP_TITLE_PARA_TOP_MARGIN,
96 cppu::UnoType<sal_Int32>::get(),
97 beans::PropertyAttribute::BOUND
98 | beans::PropertyAttribute::MAYBEDEFAULT );
100 rOutProperties.emplace_back( "ParaBottomMargin",
101 PROP_TITLE_PARA_BOTTOM_MARGIN,
102 cppu::UnoType<sal_Int32>::get(),
103 beans::PropertyAttribute::BOUND
104 | beans::PropertyAttribute::MAYBEDEFAULT );
106 rOutProperties.emplace_back( "ParaIsHyphenation",
107 PROP_TITLE_PARA_IS_HYPHENATION,
108 cppu::UnoType<bool>::get(),
109 beans::PropertyAttribute::BOUND
110 | beans::PropertyAttribute::MAYBEDEFAULT );
113 rOutProperties.emplace_back( "Visible",
114 PROP_TITLE_VISIBLE,
115 cppu::UnoType<bool>::get(),
116 beans::PropertyAttribute::BOUND
117 | beans::PropertyAttribute::MAYBEDEFAULT );
119 rOutProperties.emplace_back( "TextRotation",
120 PROP_TITLE_TEXT_ROTATION,
121 cppu::UnoType<double>::get(),
122 beans::PropertyAttribute::BOUND
123 | beans::PropertyAttribute::MAYBEDEFAULT );
124 rOutProperties.emplace_back( "StackCharacters",
125 PROP_TITLE_TEXT_STACKED,
126 cppu::UnoType<bool>::get(),
127 beans::PropertyAttribute::BOUND
128 | beans::PropertyAttribute::MAYBEDEFAULT );
130 rOutProperties.emplace_back( "RelativePosition",
131 PROP_TITLE_REL_POS,
132 cppu::UnoType<chart2::RelativePosition>::get(),
133 beans::PropertyAttribute::BOUND
134 | beans::PropertyAttribute::MAYBEVOID );
136 rOutProperties.emplace_back( "ReferencePageSize",
137 PROP_TITLE_REF_PAGE_SIZE,
138 cppu::UnoType<awt::Size>::get(),
139 beans::PropertyAttribute::BOUND
140 | beans::PropertyAttribute::MAYBEVOID );
143 const ::chart::tPropertyValueMap& StaticTitleDefaults()
145 static ::chart::tPropertyValueMap aStaticDefaults = []()
147 ::chart::tPropertyValueMap aTmp;
149 ::chart::CharacterProperties::AddDefaultsToMap( aTmp );
150 ::chart::LinePropertiesHelper::AddDefaultsToMap( aTmp );
151 ::chart::FillProperties::AddDefaultsToMap( aTmp );
153 // ParagraphProperties
154 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_ADJUST,
155 css::style::ParagraphAdjust_CENTER );
156 // PROP_TITLE_PARA_LAST_LINE_ADJUST
158 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_LEFT_MARGIN, 0 );
159 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_RIGHT_MARGIN, 0 );
160 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_TOP_MARGIN, 0 );
161 ::chart::PropertyHelper::setPropertyValueDefault< sal_Int32 >( aTmp, PROP_TITLE_PARA_BOTTOM_MARGIN, 0 );
162 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_PARA_IS_HYPHENATION, true );
163 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_VISIBLE, true );
165 // own properties
166 ::chart::PropertyHelper::setPropertyValueDefault< double >( aTmp, PROP_TITLE_TEXT_ROTATION, 0.0 );
167 ::chart::PropertyHelper::setPropertyValueDefault( aTmp, PROP_TITLE_TEXT_STACKED, false );
169 // override other defaults
170 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::FillProperties::PROP_FILL_STYLE, drawing::FillStyle_NONE );
171 ::chart::PropertyHelper::setPropertyValue( aTmp, ::chart::LinePropertiesHelper::PROP_LINE_STYLE, drawing::LineStyle_NONE );
172 return aTmp;
173 }();
174 return aStaticDefaults;
177 ::cppu::OPropertyArrayHelper& StaticTitleInfoHelper()
179 static ::cppu::OPropertyArrayHelper aPropHelper = []()
181 std::vector< css::beans::Property > aProperties;
182 lcl_AddPropertiesToVector( aProperties );
183 ::chart::CharacterProperties::AddPropertiesToVector( aProperties );
184 ::chart::LinePropertiesHelper::AddPropertiesToVector( aProperties );
185 ::chart::FillProperties::AddPropertiesToVector( aProperties );
187 std::sort( aProperties.begin(), aProperties.end(),
188 ::chart::PropertyNameLess() );
190 return comphelper::containerToSequence( aProperties );
191 }();
192 return aPropHelper;
195 } // anonymous namespace
197 namespace chart
200 Title::Title() :
201 m_xModifyEventForwarder( new ModifyEventForwarder() )
204 Title::Title( const Title & rOther ) :
205 impl::Title_Base(rOther),
206 ::property::OPropertySet( rOther ),
207 m_xModifyEventForwarder( new ModifyEventForwarder() )
209 CloneHelper::CloneRefSequence<chart2::XFormattedString>(
210 rOther.m_aStrings, m_aStrings );
211 ModifyListenerHelper::addListenerToAllElements(
212 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
213 m_xModifyEventForwarder );
216 Title::~Title()
218 ModifyListenerHelper::removeListenerFromAllElements(
219 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( m_aStrings ),
220 m_xModifyEventForwarder );
223 // ____ XCloneable ____
224 uno::Reference< util::XCloneable > SAL_CALL Title::createClone()
226 return uno::Reference< util::XCloneable >( new Title( *this ));
229 // ____ XTitle ____
230 uno::Sequence< uno::Reference< chart2::XFormattedString > > SAL_CALL Title::getText()
232 MutexGuard aGuard( m_aMutex );
233 return m_aStrings;
236 void SAL_CALL Title::setText( const uno::Sequence< uno::Reference< chart2::XFormattedString > >& rNewStrings )
238 uno::Sequence< uno::Reference< chart2::XFormattedString > > aOldStrings;
240 MutexGuard aGuard( m_aMutex );
241 std::swap( m_aStrings, aOldStrings );
242 m_aStrings = rNewStrings;
244 //don't keep the mutex locked while calling out
245 ModifyListenerHelper::removeListenerFromAllElements(
246 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( aOldStrings ),
247 m_xModifyEventForwarder );
248 ModifyListenerHelper::addListenerToAllElements(
249 comphelper::sequenceToContainer<std::vector<uno::Reference< chart2::XFormattedString > > >( rNewStrings ),
250 m_xModifyEventForwarder );
251 fireModifyEvent();
254 // ____ OPropertySet ____
255 void Title::GetDefaultValue( sal_Int32 nHandle, uno::Any& rAny ) const
257 const tPropertyValueMap& rStaticDefaults = StaticTitleDefaults();
258 tPropertyValueMap::const_iterator aFound( rStaticDefaults.find( nHandle ) );
259 if( aFound == rStaticDefaults.end() )
260 rAny.clear();
261 else
262 rAny = (*aFound).second;
265 ::cppu::IPropertyArrayHelper & SAL_CALL Title::getInfoHelper()
267 return StaticTitleInfoHelper();
270 // ____ XPropertySet ____
271 uno::Reference< beans::XPropertySetInfo > SAL_CALL Title::getPropertySetInfo()
273 static uno::Reference< beans::XPropertySetInfo > xPropertySetInfo(
274 ::cppu::OPropertySetHelper::createPropertySetInfo(StaticTitleInfoHelper() ) );
275 return xPropertySetInfo;
278 // ____ XModifyBroadcaster ____
279 void SAL_CALL Title::addModifyListener( const uno::Reference< util::XModifyListener >& aListener )
281 m_xModifyEventForwarder->addModifyListener( aListener );
284 void SAL_CALL Title::removeModifyListener( const uno::Reference< util::XModifyListener >& aListener )
286 m_xModifyEventForwarder->removeModifyListener( aListener );
289 // ____ XModifyListener ____
290 void SAL_CALL Title::modified( const lang::EventObject& aEvent )
292 m_xModifyEventForwarder->modified( aEvent );
295 // ____ XEventListener (base of XModifyListener) ____
296 void SAL_CALL Title::disposing( const lang::EventObject& /* Source */ )
298 // nothing
301 // ____ OPropertySet ____
302 void Title::firePropertyChangeEvent()
304 fireModifyEvent();
307 void Title::fireModifyEvent()
309 m_xModifyEventForwarder->modified( lang::EventObject( static_cast< uno::XWeak* >( this )));
312 OUString SAL_CALL Title::getImplementationName()
314 return u"com.sun.star.comp.chart2.Title"_ustr;
317 sal_Bool SAL_CALL Title::supportsService( const OUString& rServiceName )
319 return cppu::supportsService(this, rServiceName);
322 css::uno::Sequence< OUString > SAL_CALL Title::getSupportedServiceNames()
324 return {
325 u"com.sun.star.chart2.Title"_ustr,
326 u"com.sun.star.style.ParagraphProperties"_ustr,
327 u"com.sun.star.beans.PropertySet"_ustr,
328 u"com.sun.star.layout.LayoutElement"_ustr };
331 // needed by MSC compiler
332 using impl::Title_Base;
334 IMPLEMENT_FORWARD_XINTERFACE2( Title, Title_Base, ::property::OPropertySet )
335 IMPLEMENT_FORWARD_XTYPEPROVIDER2( Title, Title_Base, ::property::OPropertySet )
337 } // namespace chart
339 extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface *
340 com_sun_star_comp_chart2_Title_get_implementation(css::uno::XComponentContext *,
341 css::uno::Sequence<css::uno::Any> const &)
343 return cppu::acquire(new ::chart::Title);
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */