tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / source / core / api / Section.cxx
blob6bff419b64e9ff5acab7c29a089e3ab421c1b588
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 .
19 #include <Section.hxx>
20 #include <Group.hxx>
21 #include <Groups.hxx>
22 #include <comphelper/enumhelper.hxx>
23 #include <comphelper/servicehelper.hxx>
24 #include <cppuhelper/supportsservice.hxx>
25 #include <com/sun/star/report/XReportComponent.hpp>
26 #include <com/sun/star/report/ForceNewPage.hpp>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <strings.hxx>
29 #include <Tools.hxx>
30 #include <RptModel.hxx>
31 #include <RptPage.hxx>
32 #include <ReportControlModel.hxx>
33 #include <ReportDefinition.hxx>
34 #include <vcl/svapp.hxx>
36 namespace reportdesign
39 using namespace com::sun::star;
40 using namespace comphelper;
43 static uno::Sequence< OUString> lcl_getGroupAbsent()
45 const OUString pProps[] = {
46 PROPERTY_CANGROW
47 ,PROPERTY_CANSHRINK
50 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
54 static uno::Sequence< OUString> lcl_getAbsent(bool _bPageSection)
56 if ( _bPageSection )
58 const OUString pProps[] = {
59 PROPERTY_FORCENEWPAGE
60 ,PROPERTY_NEWROWORCOL
61 ,PROPERTY_KEEPTOGETHER
62 ,PROPERTY_CANGROW
63 ,PROPERTY_CANSHRINK
64 ,PROPERTY_REPEATSECTION
66 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
69 const OUString pProps[] = {
70 PROPERTY_CANGROW
71 ,PROPERTY_CANSHRINK
72 ,PROPERTY_REPEATSECTION
75 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
78 rtl::Reference<OSection> OSection::createOSection(
79 const rtl::Reference< OReportDefinition >& xParentDef,
80 const uno::Reference< uno::XComponentContext >& context,
81 bool const bPageSection)
83 rtl::Reference<OSection> pNew =
84 new OSection(xParentDef, nullptr, context, lcl_getAbsent(bPageSection));
85 pNew->init();
86 return pNew;
89 rtl::Reference<OSection> OSection::createOSection(
90 const rtl::Reference< OGroup >& xParentGroup,
91 const uno::Reference< uno::XComponentContext >& context)
93 rtl::Reference<OSection> pNew =
94 new OSection(nullptr, xParentGroup, context, lcl_getGroupAbsent());
95 pNew->init();
96 return pNew;
100 OSection::OSection(const rtl::Reference< OReportDefinition >& xParentDef
101 ,const rtl::Reference< OGroup >& xParentGroup
102 ,const uno::Reference< uno::XComponentContext >& context
103 ,uno::Sequence< OUString> const& rStrings)
104 :SectionBase(m_aMutex)
105 ,SectionPropertySet(context,SectionPropertySet::IMPLEMENTS_PROPERTY_SET,rStrings)
106 ,m_aContainerListeners(m_aMutex)
107 ,m_xGroup(xParentGroup)
108 ,m_xReportDefinition(xParentDef)
109 ,m_nHeight(3000)
110 ,m_nBackgroundColor(COL_TRANSPARENT)
111 ,m_nForceNewPage(report::ForceNewPage::NONE)
112 ,m_nNewRowOrCol(report::ForceNewPage::NONE)
113 ,m_bKeepTogether(false)
114 ,m_bRepeatSection(false)
115 ,m_bVisible(true)
116 ,m_bBacktransparent(true)
117 ,m_bInRemoveNotify(false)
118 ,m_bInInsertNotify(false)
122 // TODO: VirtualFunctionFinder: This is virtual function!
124 OSection::~OSection()
128 //IMPLEMENT_FORWARD_XINTERFACE2(OSection,SectionBase,SectionPropertySet)
129 IMPLEMENT_FORWARD_REFCOUNT( OSection, SectionBase )
131 uno::Any SAL_CALL OSection::queryInterface( const uno::Type& _rType )
133 uno::Any aReturn = SectionBase::queryInterface(_rType);
134 if ( !aReturn.hasValue() )
135 aReturn = SectionPropertySet::queryInterface(_rType);
137 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
138 return aReturn;
140 return aReturn;
144 void SAL_CALL OSection::dispose()
146 OSL_ENSURE(!rBHelper.bDisposed,"Already disposed!");
147 SectionPropertySet::dispose();
148 uno::Reference<lang::XComponent> const xPageComponent(m_xDrawPage,
149 uno::UNO_QUERY);
150 if (xPageComponent.is())
152 xPageComponent->dispose();
154 cppu::WeakComponentImplHelperBase::dispose();
158 // TODO: VirtualFunctionFinder: This is virtual function!
160 void SAL_CALL OSection::disposing()
162 lang::EventObject aDisposeEvent( getXWeak() );
163 m_aContainerListeners.disposeAndClear( aDisposeEvent );
166 OUString SAL_CALL OSection::getImplementationName( )
168 return u"com.sun.star.comp.report.Section"_ustr;
171 uno::Sequence< OUString> OSection::getSupportedServiceNames_Static()
173 uno::Sequence<OUString> aSupported { SERVICE_SECTION };
174 return aSupported;
177 uno::Sequence< OUString> SAL_CALL OSection::getSupportedServiceNames()
179 return getSupportedServiceNames_Static();
182 sal_Bool SAL_CALL OSection::supportsService( const OUString& _rServiceName )
184 return cppu::supportsService(this, _rServiceName);
187 void OSection::init()
189 SolarMutexGuard g; // lock while manipulating SdrModel
190 uno::Reference< report::XReportDefinition> xReport = getReportDefinition();
191 std::shared_ptr<rptui::OReportModel> pModel = OReportDefinition::getSdrModel(xReport);
192 assert(pModel && "No model set at the report definition!");
193 if ( !pModel )
194 return;
196 uno::Reference<report::XSection> const xSection(this);
197 SdrPage & rSdrPage(*pModel->createNewPage(xSection));
198 m_xDrawPage.set(rSdrPage.getUnoPage(), uno::UNO_QUERY_THROW);
199 m_xDrawPage_ShapeGrouper.set(m_xDrawPage, uno::UNO_QUERY_THROW);
200 // apparently we may also get OReportDrawPage which doesn't support this
201 m_xDrawPage_FormSupplier.set(m_xDrawPage, uno::UNO_QUERY);
202 m_xDrawPage_Tunnel.set(m_xDrawPage, uno::UNO_QUERY_THROW);
203 // fdo#53872: now also exchange the XDrawPage in the SdrPage so that
204 // rSdrPage.getUnoPage returns this
205 rSdrPage.SetUnoPage(this);
206 // createNewPage _should_ have stored away 2 uno::References to this,
207 // so our ref count cannot be 1 here, so this isn't destroyed here
208 assert(m_refCount > 1);
211 // XSection
213 sal_Bool SAL_CALL OSection::getVisible()
215 ::osl::MutexGuard aGuard(m_aMutex);
216 return m_bVisible;
219 void SAL_CALL OSection::setVisible( sal_Bool _visible )
221 set(PROPERTY_VISIBLE,_visible,m_bVisible);
224 OUString SAL_CALL OSection::getName()
226 ::osl::MutexGuard aGuard(m_aMutex);
227 return m_sName;
230 void SAL_CALL OSection::setName( const OUString& _name )
232 set(PROPERTY_NAME,_name,m_sName);
235 ::sal_uInt32 SAL_CALL OSection::getHeight()
237 ::osl::MutexGuard aGuard(m_aMutex);
238 return m_nHeight;
241 void SAL_CALL OSection::setHeight( ::sal_uInt32 _height )
243 set(PROPERTY_HEIGHT,_height,m_nHeight);
246 ::sal_Int32 SAL_CALL OSection::getBackColor()
248 ::osl::MutexGuard aGuard(m_aMutex);
249 return m_bBacktransparent ? static_cast<sal_Int32>(COL_TRANSPARENT) : m_nBackgroundColor;
252 void SAL_CALL OSection::setBackColor( ::sal_Int32 _backgroundcolor )
254 bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
255 setBackTransparent(bTransparent);
256 if ( !bTransparent )
257 set(PROPERTY_BACKCOLOR,_backgroundcolor,m_nBackgroundColor);
260 sal_Bool SAL_CALL OSection::getBackTransparent()
262 ::osl::MutexGuard aGuard(m_aMutex);
263 return m_bBacktransparent;
266 void SAL_CALL OSection::setBackTransparent( sal_Bool _backtransparent )
268 set(PROPERTY_BACKTRANSPARENT,_backtransparent,m_bBacktransparent);
269 if ( _backtransparent )
270 set(PROPERTY_BACKCOLOR,static_cast<sal_Int32>(COL_TRANSPARENT),m_nBackgroundColor);
273 OUString SAL_CALL OSection::getConditionalPrintExpression()
275 ::osl::MutexGuard aGuard(m_aMutex);
276 return m_sConditionalPrintExpression;
279 void SAL_CALL OSection::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
281 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_sConditionalPrintExpression);
284 void OSection::checkNotPageHeaderFooter()
286 ::osl::MutexGuard aGuard(m_aMutex);
287 rtl::Reference< OReportDefinition > xRet = m_xReportDefinition;
288 if ( xRet.is() )
290 if ( xRet->getPageHeaderOn() && xRet->getPageHeader() == *this )
291 throw beans::UnknownPropertyException();
292 if ( xRet->getPageFooterOn() && xRet->getPageFooter() == *this )
293 throw beans::UnknownPropertyException();
297 ::sal_Int16 SAL_CALL OSection::getForceNewPage()
299 ::osl::MutexGuard aGuard(m_aMutex);
301 checkNotPageHeaderFooter();
302 return m_nForceNewPage;
305 void SAL_CALL OSection::setForceNewPage( ::sal_Int16 _forcenewpage )
307 if ( _forcenewpage < report::ForceNewPage::NONE || _forcenewpage > report::ForceNewPage::BEFORE_AFTER_SECTION )
308 throwIllegallArgumentException(u"css::report::ForceNewPage"
309 ,*this
310 ,1);
311 checkNotPageHeaderFooter();
312 set(PROPERTY_FORCENEWPAGE,_forcenewpage,m_nForceNewPage);
315 ::sal_Int16 SAL_CALL OSection::getNewRowOrCol()
317 ::osl::MutexGuard aGuard(m_aMutex);
318 checkNotPageHeaderFooter();
319 return m_nNewRowOrCol;
322 void SAL_CALL OSection::setNewRowOrCol( ::sal_Int16 _newroworcol )
324 if ( _newroworcol < report::ForceNewPage::NONE || _newroworcol > report::ForceNewPage::BEFORE_AFTER_SECTION )
325 throwIllegallArgumentException(u"css::report::ForceNewPage"
326 ,*this
327 ,1);
328 checkNotPageHeaderFooter();
330 set(PROPERTY_NEWROWORCOL,_newroworcol,m_nNewRowOrCol);
333 sal_Bool SAL_CALL OSection::getKeepTogether()
335 ::osl::MutexGuard aGuard(m_aMutex);
336 checkNotPageHeaderFooter();
337 return m_bKeepTogether;
340 void SAL_CALL OSection::setKeepTogether( sal_Bool _keeptogether )
343 ::osl::MutexGuard aGuard(m_aMutex);
344 checkNotPageHeaderFooter();
347 set(PROPERTY_KEEPTOGETHER,_keeptogether,m_bKeepTogether);
350 sal_Bool SAL_CALL OSection::getCanGrow()
352 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
355 void SAL_CALL OSection::setCanGrow( sal_Bool /*_cangrow*/ )
357 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
360 sal_Bool SAL_CALL OSection::getCanShrink()
362 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
365 void SAL_CALL OSection::setCanShrink( sal_Bool /*_canshrink*/ )
367 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
370 sal_Bool SAL_CALL OSection::getRepeatSection()
372 ::osl::MutexGuard aGuard(m_aMutex);
373 rtl::Reference< OGroup > xGroup = m_xGroup;
374 if ( !xGroup.is() )
375 throw beans::UnknownPropertyException();
376 return m_bRepeatSection;
379 void SAL_CALL OSection::setRepeatSection( sal_Bool _repeatsection )
382 ::osl::MutexGuard aGuard(m_aMutex);
383 rtl::Reference< OGroup > xGroup = m_xGroup;
384 if ( !xGroup.is() )
385 throw beans::UnknownPropertyException();
387 set(PROPERTY_REPEATSECTION,_repeatsection,m_bRepeatSection);
390 uno::Reference< report::XGroup > SAL_CALL OSection::getGroup()
392 ::osl::MutexGuard aGuard(m_aMutex);
393 return m_xGroup.get();
396 uno::Reference< report::XReportDefinition > SAL_CALL OSection::getReportDefinition()
398 ::osl::MutexGuard aGuard(m_aMutex);
399 rtl::Reference< OReportDefinition > xRet = m_xReportDefinition;
400 if (xRet.is())
401 return xRet;
402 rtl::Reference< OGroup > xGroup = m_xGroup;
403 if ( xGroup.is() )
405 rtl::Reference< OGroups> xGroups(xGroup->getOGroups());
406 if ( xGroups.is() )
407 return xGroups->getReportDefinition();
409 return {};
412 // XChild
413 uno::Reference< uno::XInterface > SAL_CALL OSection::getParent( )
415 uno::Reference< uno::XInterface > xRet;
417 ::osl::MutexGuard aGuard(m_aMutex);
418 xRet = m_xReportDefinition;
419 if ( !xRet.is() )
420 xRet = m_xGroup;
422 return xRet;
425 void SAL_CALL OSection::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
427 throw lang::NoSupportException();
430 // XContainer
431 void SAL_CALL OSection::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
433 m_aContainerListeners.addInterface(xListener);
436 void SAL_CALL OSection::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
438 m_aContainerListeners.removeInterface(xListener);
441 // XElementAccess
442 uno::Type SAL_CALL OSection::getElementType( )
444 return cppu::UnoType<report::XReportComponent>::get();
447 sal_Bool SAL_CALL OSection::hasElements( )
449 ::osl::MutexGuard aGuard(m_aMutex);
450 return m_xDrawPage.is() && m_xDrawPage->hasElements();
453 // XIndexAccess
454 ::sal_Int32 SAL_CALL OSection::getCount( )
456 ::osl::MutexGuard aGuard(m_aMutex);
457 return m_xDrawPage.is() ? m_xDrawPage->getCount() : 0;
460 uno::Any SAL_CALL OSection::getByIndex( ::sal_Int32 Index )
462 ::osl::MutexGuard aGuard(m_aMutex);
463 return m_xDrawPage.is() ? m_xDrawPage->getByIndex(Index) : uno::Any();
466 // XEnumerationAccess
467 uno::Reference< container::XEnumeration > SAL_CALL OSection::createEnumeration( )
469 ::osl::MutexGuard aGuard(m_aMutex);
470 return new ::comphelper::OEnumerationByIndex(static_cast<XSection*>(this));
473 uno::Reference< beans::XPropertySetInfo > SAL_CALL OSection::getPropertySetInfo( )
475 return SectionPropertySet::getPropertySetInfo();
478 void SAL_CALL OSection::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
480 SectionPropertySet::setPropertyValue( aPropertyName, aValue );
483 uno::Any SAL_CALL OSection::getPropertyValue( const OUString& PropertyName )
485 return SectionPropertySet::getPropertyValue( PropertyName);
488 void SAL_CALL OSection::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
490 SectionPropertySet::addPropertyChangeListener( aPropertyName, xListener );
493 void SAL_CALL OSection::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
495 SectionPropertySet::removePropertyChangeListener( aPropertyName, aListener );
498 void SAL_CALL OSection::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
500 SectionPropertySet::addVetoableChangeListener( PropertyName, aListener );
503 void SAL_CALL OSection::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
505 SectionPropertySet::removeVetoableChangeListener( PropertyName, aListener );
508 void SAL_CALL OSection::add( const uno::Reference< drawing::XShape >& xShape )
511 ::osl::MutexGuard aGuard(m_aMutex);
512 m_bInInsertNotify = true;
513 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
514 m_xDrawPage->add(xShape);
515 m_bInInsertNotify = false;
517 notifyElementAdded(xShape);
520 void SAL_CALL OSection::remove( const uno::Reference< drawing::XShape >& xShape )
523 ::osl::MutexGuard aGuard(m_aMutex);
524 m_bInRemoveNotify = true;
525 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
526 m_xDrawPage->remove(xShape);
527 m_bInRemoveNotify = false;
529 notifyElementRemoved(xShape);
532 // XShapeGrouper
533 uno::Reference< drawing::XShapeGroup > SAL_CALL
534 OSection::group(uno::Reference< drawing::XShapes > const& xShapes)
536 // no lock because m_xDrawPage_ShapeGrouper is const
537 return (m_xDrawPage_ShapeGrouper.is())
538 ? m_xDrawPage_ShapeGrouper->group(xShapes)
539 : nullptr;
541 void SAL_CALL
542 OSection::ungroup(uno::Reference<drawing::XShapeGroup> const& xGroup)
544 // no lock because m_xDrawPage_ShapeGrouper is const
545 if (m_xDrawPage_ShapeGrouper.is()) {
546 m_xDrawPage_ShapeGrouper->ungroup(xGroup);
550 // XFormsSupplier
551 uno::Reference<container::XNameContainer> SAL_CALL OSection::getForms()
553 // no lock because m_xDrawPage_FormSupplier is const
554 return (m_xDrawPage_FormSupplier.is())
555 ? m_xDrawPage_FormSupplier->getForms()
556 : nullptr;
558 // XFormsSupplier2
559 sal_Bool SAL_CALL OSection::hasForms()
561 // no lock because m_xDrawPage_FormSupplier is const
562 return (m_xDrawPage_FormSupplier.is())
563 && m_xDrawPage_FormSupplier->hasForms();
567 // css::lang::XUnoTunnel
569 sal_Int64 OSection::getSomething( const uno::Sequence< sal_Int8 > & rId )
571 if (comphelper::isUnoTunnelId<OSection>(rId) )
572 return comphelper::getSomething_cast(this);
573 return (m_xDrawPage_Tunnel.is()) ? m_xDrawPage_Tunnel->getSomething(rId) : 0;
576 const uno::Sequence< sal_Int8 > & OSection::getUnoTunnelId()
578 static const comphelper::UnoIdInit implId;
579 return implId.getSeq();
582 void OSection::notifyElementAdded(const uno::Reference< drawing::XShape >& xShape )
584 if ( !m_bInInsertNotify )
586 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::Any(xShape), uno::Any());
587 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
591 void OSection::notifyElementRemoved(const uno::Reference< drawing::XShape >& xShape)
593 if ( !m_bInRemoveNotify )
595 // notify our container listeners
596 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::Any(xShape), uno::Any());
597 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
601 } // namespace reportdesign
604 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */