bump product version to 7.6.3.2-android
[LibreOffice.git] / reportdesign / source / core / api / Section.cxx
blob1c98d239243f0e845b052d9c258ae7ae341bc793
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 <comphelper/enumhelper.hxx>
21 #include <comphelper/servicehelper.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <com/sun/star/report/XReportComponent.hpp>
24 #include <com/sun/star/report/ForceNewPage.hpp>
25 #include <com/sun/star/lang/NoSupportException.hpp>
26 #include <strings.hxx>
27 #include <Tools.hxx>
28 #include <RptModel.hxx>
29 #include <RptPage.hxx>
30 #include <ReportControlModel.hxx>
31 #include <ReportDefinition.hxx>
32 #include <vcl/svapp.hxx>
34 namespace reportdesign
37 using namespace com::sun::star;
38 using namespace comphelper;
41 static uno::Sequence< OUString> lcl_getGroupAbsent()
43 const OUString pProps[] = {
44 OUString(PROPERTY_CANGROW)
45 ,OUString(PROPERTY_CANSHRINK)
48 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
52 static uno::Sequence< OUString> lcl_getAbsent(bool _bPageSection)
54 if ( _bPageSection )
56 const OUString pProps[] = {
57 OUString(PROPERTY_FORCENEWPAGE)
58 ,OUString(PROPERTY_NEWROWORCOL)
59 ,OUString(PROPERTY_KEEPTOGETHER)
60 ,OUString(PROPERTY_CANGROW)
61 ,OUString(PROPERTY_CANSHRINK)
62 ,OUString(PROPERTY_REPEATSECTION)
64 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
67 const OUString pProps[] = {
68 OUString(PROPERTY_CANGROW)
69 ,OUString(PROPERTY_CANSHRINK)
70 ,OUString(PROPERTY_REPEATSECTION)
73 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
76 uno::Reference<report::XSection> OSection::createOSection(
77 const uno::Reference< report::XReportDefinition >& xParentDef,
78 const uno::Reference< uno::XComponentContext >& context,
79 bool const bPageSection)
81 rtl::Reference<OSection> pNew =
82 new OSection(xParentDef, nullptr, context, lcl_getAbsent(bPageSection));
83 pNew->init();
84 return pNew;
87 uno::Reference<report::XSection> OSection::createOSection(
88 const uno::Reference< report::XGroup >& xParentGroup,
89 const uno::Reference< uno::XComponentContext >& context)
91 rtl::Reference<OSection> pNew =
92 new OSection(nullptr, xParentGroup, context, lcl_getGroupAbsent());
93 pNew->init();
94 return pNew;
98 OSection::OSection(const uno::Reference< report::XReportDefinition >& xParentDef
99 ,const uno::Reference< report::XGroup >& xParentGroup
100 ,const uno::Reference< uno::XComponentContext >& context
101 ,uno::Sequence< OUString> const& rStrings)
102 :SectionBase(m_aMutex)
103 ,SectionPropertySet(context,SectionPropertySet::IMPLEMENTS_PROPERTY_SET,rStrings)
104 ,m_aContainerListeners(m_aMutex)
105 ,m_xGroup(xParentGroup)
106 ,m_xReportDefinition(xParentDef)
107 ,m_nHeight(3000)
108 ,m_nBackgroundColor(COL_TRANSPARENT)
109 ,m_nForceNewPage(report::ForceNewPage::NONE)
110 ,m_nNewRowOrCol(report::ForceNewPage::NONE)
111 ,m_bKeepTogether(false)
112 ,m_bRepeatSection(false)
113 ,m_bVisible(true)
114 ,m_bBacktransparent(true)
115 ,m_bInRemoveNotify(false)
116 ,m_bInInsertNotify(false)
120 // TODO: VirtualFunctionFinder: This is virtual function!
122 OSection::~OSection()
126 //IMPLEMENT_FORWARD_XINTERFACE2(OSection,SectionBase,SectionPropertySet)
127 IMPLEMENT_FORWARD_REFCOUNT( OSection, SectionBase )
129 uno::Any SAL_CALL OSection::queryInterface( const uno::Type& _rType )
131 uno::Any aReturn = SectionBase::queryInterface(_rType);
132 if ( !aReturn.hasValue() )
133 aReturn = SectionPropertySet::queryInterface(_rType);
135 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
136 return aReturn;
138 return aReturn;
142 void SAL_CALL OSection::dispose()
144 OSL_ENSURE(!rBHelper.bDisposed,"Already disposed!");
145 SectionPropertySet::dispose();
146 uno::Reference<lang::XComponent> const xPageComponent(m_xDrawPage,
147 uno::UNO_QUERY);
148 if (xPageComponent.is())
150 xPageComponent->dispose();
152 cppu::WeakComponentImplHelperBase::dispose();
156 // TODO: VirtualFunctionFinder: This is virtual function!
158 void SAL_CALL OSection::disposing()
160 lang::EventObject aDisposeEvent( getXWeak() );
161 m_aContainerListeners.disposeAndClear( aDisposeEvent );
164 OUString SAL_CALL OSection::getImplementationName( )
166 return "com.sun.star.comp.report.Section";
169 uno::Sequence< OUString> OSection::getSupportedServiceNames_Static()
171 uno::Sequence<OUString> aSupported { SERVICE_SECTION };
172 return aSupported;
175 uno::Sequence< OUString> SAL_CALL OSection::getSupportedServiceNames()
177 return getSupportedServiceNames_Static();
180 sal_Bool SAL_CALL OSection::supportsService( const OUString& _rServiceName )
182 return cppu::supportsService(this, _rServiceName);
185 void OSection::init()
187 SolarMutexGuard g; // lock while manipulating SdrModel
188 uno::Reference< report::XReportDefinition> xReport = getReportDefinition();
189 std::shared_ptr<rptui::OReportModel> pModel = OReportDefinition::getSdrModel(xReport);
190 assert(pModel && "No model set at the report definition!");
191 if ( !pModel )
192 return;
194 uno::Reference<report::XSection> const xSection(this);
195 SdrPage & rSdrPage(*pModel->createNewPage(xSection));
196 m_xDrawPage.set(rSdrPage.getUnoPage(), uno::UNO_QUERY_THROW);
197 m_xDrawPage_ShapeGrouper.set(m_xDrawPage, uno::UNO_QUERY_THROW);
198 // apparently we may also get OReportDrawPage which doesn't support this
199 m_xDrawPage_FormSupplier.set(m_xDrawPage, uno::UNO_QUERY);
200 m_xDrawPage_Tunnel.set(m_xDrawPage, uno::UNO_QUERY_THROW);
201 // fdo#53872: now also exchange the XDrawPage in the SdrPage so that
202 // rSdrPage.getUnoPage returns this
203 rSdrPage.SetUnoPage(this);
204 // createNewPage _should_ have stored away 2 uno::References to this,
205 // so our ref count cannot be 1 here, so this isn't destroyed here
206 assert(m_refCount > 1);
209 // XSection
211 sal_Bool SAL_CALL OSection::getVisible()
213 ::osl::MutexGuard aGuard(m_aMutex);
214 return m_bVisible;
217 void SAL_CALL OSection::setVisible( sal_Bool _visible )
219 set(PROPERTY_VISIBLE,_visible,m_bVisible);
222 OUString SAL_CALL OSection::getName()
224 ::osl::MutexGuard aGuard(m_aMutex);
225 return m_sName;
228 void SAL_CALL OSection::setName( const OUString& _name )
230 set(PROPERTY_NAME,_name,m_sName);
233 ::sal_uInt32 SAL_CALL OSection::getHeight()
235 ::osl::MutexGuard aGuard(m_aMutex);
236 return m_nHeight;
239 void SAL_CALL OSection::setHeight( ::sal_uInt32 _height )
241 set(PROPERTY_HEIGHT,_height,m_nHeight);
244 ::sal_Int32 SAL_CALL OSection::getBackColor()
246 ::osl::MutexGuard aGuard(m_aMutex);
247 return m_bBacktransparent ? static_cast<sal_Int32>(COL_TRANSPARENT) : m_nBackgroundColor;
250 void SAL_CALL OSection::setBackColor( ::sal_Int32 _backgroundcolor )
252 bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
253 setBackTransparent(bTransparent);
254 if ( !bTransparent )
255 set(PROPERTY_BACKCOLOR,_backgroundcolor,m_nBackgroundColor);
258 sal_Bool SAL_CALL OSection::getBackTransparent()
260 ::osl::MutexGuard aGuard(m_aMutex);
261 return m_bBacktransparent;
264 void SAL_CALL OSection::setBackTransparent( sal_Bool _backtransparent )
266 set(PROPERTY_BACKTRANSPARENT,_backtransparent,m_bBacktransparent);
267 if ( _backtransparent )
268 set(PROPERTY_BACKCOLOR,static_cast<sal_Int32>(COL_TRANSPARENT),m_nBackgroundColor);
271 OUString SAL_CALL OSection::getConditionalPrintExpression()
273 ::osl::MutexGuard aGuard(m_aMutex);
274 return m_sConditionalPrintExpression;
277 void SAL_CALL OSection::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
279 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_sConditionalPrintExpression);
282 void OSection::checkNotPageHeaderFooter()
284 ::osl::MutexGuard aGuard(m_aMutex);
285 uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
286 if ( xRet.is() )
288 if ( xRet->getPageHeaderOn() && xRet->getPageHeader() == *this )
289 throw beans::UnknownPropertyException();
290 if ( xRet->getPageFooterOn() && xRet->getPageFooter() == *this )
291 throw beans::UnknownPropertyException();
295 ::sal_Int16 SAL_CALL OSection::getForceNewPage()
297 ::osl::MutexGuard aGuard(m_aMutex);
299 checkNotPageHeaderFooter();
300 return m_nForceNewPage;
303 void SAL_CALL OSection::setForceNewPage( ::sal_Int16 _forcenewpage )
305 if ( _forcenewpage < report::ForceNewPage::NONE || _forcenewpage > report::ForceNewPage::BEFORE_AFTER_SECTION )
306 throwIllegallArgumentException(u"css::report::ForceNewPage"
307 ,*this
308 ,1);
309 checkNotPageHeaderFooter();
310 set(PROPERTY_FORCENEWPAGE,_forcenewpage,m_nForceNewPage);
313 ::sal_Int16 SAL_CALL OSection::getNewRowOrCol()
315 ::osl::MutexGuard aGuard(m_aMutex);
316 checkNotPageHeaderFooter();
317 return m_nNewRowOrCol;
320 void SAL_CALL OSection::setNewRowOrCol( ::sal_Int16 _newroworcol )
322 if ( _newroworcol < report::ForceNewPage::NONE || _newroworcol > report::ForceNewPage::BEFORE_AFTER_SECTION )
323 throwIllegallArgumentException(u"css::report::ForceNewPage"
324 ,*this
325 ,1);
326 checkNotPageHeaderFooter();
328 set(PROPERTY_NEWROWORCOL,_newroworcol,m_nNewRowOrCol);
331 sal_Bool SAL_CALL OSection::getKeepTogether()
333 ::osl::MutexGuard aGuard(m_aMutex);
334 checkNotPageHeaderFooter();
335 return m_bKeepTogether;
338 void SAL_CALL OSection::setKeepTogether( sal_Bool _keeptogether )
341 ::osl::MutexGuard aGuard(m_aMutex);
342 checkNotPageHeaderFooter();
345 set(PROPERTY_KEEPTOGETHER,_keeptogether,m_bKeepTogether);
348 sal_Bool SAL_CALL OSection::getCanGrow()
350 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
353 void SAL_CALL OSection::setCanGrow( sal_Bool /*_cangrow*/ )
355 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
358 sal_Bool SAL_CALL OSection::getCanShrink()
360 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
363 void SAL_CALL OSection::setCanShrink( sal_Bool /*_canshrink*/ )
365 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
368 sal_Bool SAL_CALL OSection::getRepeatSection()
370 ::osl::MutexGuard aGuard(m_aMutex);
371 uno::Reference< report::XGroup > xGroup = m_xGroup;
372 if ( !xGroup.is() )
373 throw beans::UnknownPropertyException();
374 return m_bRepeatSection;
377 void SAL_CALL OSection::setRepeatSection( sal_Bool _repeatsection )
380 ::osl::MutexGuard aGuard(m_aMutex);
381 uno::Reference< report::XGroup > xGroup = m_xGroup;
382 if ( !xGroup.is() )
383 throw beans::UnknownPropertyException();
385 set(PROPERTY_REPEATSECTION,_repeatsection,m_bRepeatSection);
388 uno::Reference< report::XGroup > SAL_CALL OSection::getGroup()
390 ::osl::MutexGuard aGuard(m_aMutex);
391 return m_xGroup;
394 uno::Reference< report::XReportDefinition > SAL_CALL OSection::getReportDefinition()
396 ::osl::MutexGuard aGuard(m_aMutex);
397 uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
398 uno::Reference< report::XGroup > xGroup = m_xGroup;
399 if ( !xRet.is() && xGroup.is() )
401 uno::Reference< report::XGroups> xGroups(xGroup->getGroups());
402 if ( xGroups.is() )
403 xRet = xGroups->getReportDefinition();
406 return xRet;
409 // XChild
410 uno::Reference< uno::XInterface > SAL_CALL OSection::getParent( )
412 uno::Reference< uno::XInterface > xRet;
414 ::osl::MutexGuard aGuard(m_aMutex);
415 xRet = m_xReportDefinition;
416 if ( !xRet.is() )
417 xRet = m_xGroup;
419 return xRet;
422 void SAL_CALL OSection::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
424 throw lang::NoSupportException();
427 // XContainer
428 void SAL_CALL OSection::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
430 m_aContainerListeners.addInterface(xListener);
433 void SAL_CALL OSection::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
435 m_aContainerListeners.removeInterface(xListener);
438 // XElementAccess
439 uno::Type SAL_CALL OSection::getElementType( )
441 return cppu::UnoType<report::XReportComponent>::get();
444 sal_Bool SAL_CALL OSection::hasElements( )
446 ::osl::MutexGuard aGuard(m_aMutex);
447 return m_xDrawPage.is() && m_xDrawPage->hasElements();
450 // XIndexAccess
451 ::sal_Int32 SAL_CALL OSection::getCount( )
453 ::osl::MutexGuard aGuard(m_aMutex);
454 return m_xDrawPage.is() ? m_xDrawPage->getCount() : 0;
457 uno::Any SAL_CALL OSection::getByIndex( ::sal_Int32 Index )
459 ::osl::MutexGuard aGuard(m_aMutex);
460 return m_xDrawPage.is() ? m_xDrawPage->getByIndex(Index) : uno::Any();
463 // XEnumerationAccess
464 uno::Reference< container::XEnumeration > SAL_CALL OSection::createEnumeration( )
466 ::osl::MutexGuard aGuard(m_aMutex);
467 return new ::comphelper::OEnumerationByIndex(static_cast<XSection*>(this));
470 uno::Reference< beans::XPropertySetInfo > SAL_CALL OSection::getPropertySetInfo( )
472 return SectionPropertySet::getPropertySetInfo();
475 void SAL_CALL OSection::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
477 SectionPropertySet::setPropertyValue( aPropertyName, aValue );
480 uno::Any SAL_CALL OSection::getPropertyValue( const OUString& PropertyName )
482 return SectionPropertySet::getPropertyValue( PropertyName);
485 void SAL_CALL OSection::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
487 SectionPropertySet::addPropertyChangeListener( aPropertyName, xListener );
490 void SAL_CALL OSection::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
492 SectionPropertySet::removePropertyChangeListener( aPropertyName, aListener );
495 void SAL_CALL OSection::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
497 SectionPropertySet::addVetoableChangeListener( PropertyName, aListener );
500 void SAL_CALL OSection::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
502 SectionPropertySet::removeVetoableChangeListener( PropertyName, aListener );
505 void SAL_CALL OSection::add( const uno::Reference< drawing::XShape >& xShape )
508 ::osl::MutexGuard aGuard(m_aMutex);
509 m_bInInsertNotify = true;
510 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
511 m_xDrawPage->add(xShape);
512 m_bInInsertNotify = false;
514 notifyElementAdded(xShape);
517 void SAL_CALL OSection::remove( const uno::Reference< drawing::XShape >& xShape )
520 ::osl::MutexGuard aGuard(m_aMutex);
521 m_bInRemoveNotify = true;
522 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
523 m_xDrawPage->remove(xShape);
524 m_bInRemoveNotify = false;
526 notifyElementRemoved(xShape);
529 // XShapeGrouper
530 uno::Reference< drawing::XShapeGroup > SAL_CALL
531 OSection::group(uno::Reference< drawing::XShapes > const& xShapes)
533 // no lock because m_xDrawPage_ShapeGrouper is const
534 return (m_xDrawPage_ShapeGrouper.is())
535 ? m_xDrawPage_ShapeGrouper->group(xShapes)
536 : nullptr;
538 void SAL_CALL
539 OSection::ungroup(uno::Reference<drawing::XShapeGroup> const& xGroup)
541 // no lock because m_xDrawPage_ShapeGrouper is const
542 if (m_xDrawPage_ShapeGrouper.is()) {
543 m_xDrawPage_ShapeGrouper->ungroup(xGroup);
547 // XFormsSupplier
548 uno::Reference<container::XNameContainer> SAL_CALL OSection::getForms()
550 // no lock because m_xDrawPage_FormSupplier is const
551 return (m_xDrawPage_FormSupplier.is())
552 ? m_xDrawPage_FormSupplier->getForms()
553 : nullptr;
555 // XFormsSupplier2
556 sal_Bool SAL_CALL OSection::hasForms()
558 // no lock because m_xDrawPage_FormSupplier is const
559 return (m_xDrawPage_FormSupplier.is())
560 && m_xDrawPage_FormSupplier->hasForms();
564 // css::lang::XUnoTunnel
566 sal_Int64 OSection::getSomething( const uno::Sequence< sal_Int8 > & rId )
568 if (comphelper::isUnoTunnelId<OSection>(rId) )
569 return comphelper::getSomething_cast(this);
570 return (m_xDrawPage_Tunnel.is()) ? m_xDrawPage_Tunnel->getSomething(rId) : 0;
573 const uno::Sequence< sal_Int8 > & OSection::getUnoTunnelId()
575 static const comphelper::UnoIdInit implId;
576 return implId.getSeq();
579 void OSection::notifyElementAdded(const uno::Reference< drawing::XShape >& xShape )
581 if ( !m_bInInsertNotify )
583 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::Any(xShape), uno::Any());
584 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
588 void OSection::notifyElementRemoved(const uno::Reference< drawing::XShape >& xShape)
590 if ( !m_bInRemoveNotify )
592 // notify our container listeners
593 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::Any(xShape), uno::Any());
594 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
598 } // namespace reportdesign
601 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */