Version 6.4.0.3, tag libreoffice-6.4.0.3
[LibreOffice.git] / reportdesign / source / core / api / Section.cxx
blob6aa10a6acaa283d8bf48f36b3b9b77e8d164746c
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 <connectivity/dbtools.hxx>
22 #include <cppuhelper/supportsservice.hxx>
23 #include <cppuhelper/typeprovider.hxx>
24 #include <com/sun/star/report/XReportComponent.hpp>
25 #include <com/sun/star/report/ForceNewPage.hpp>
26 #include <com/sun/star/beans/PropertyAttribute.hpp>
27 #include <com/sun/star/lang/NoSupportException.hpp>
28 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
29 #include <strings.hxx>
30 #include <Tools.hxx>
31 #include <RptModel.hxx>
32 #include <RptPage.hxx>
33 #include <ReportDefinition.hxx>
34 #include <Shape.hxx>
35 #include <svx/unoshape.hxx>
36 #include <vcl/svapp.hxx>
37 #include <RptObject.hxx>
38 #include <ReportDrawPage.hxx>
40 namespace reportdesign
43 using namespace com::sun::star;
44 using namespace comphelper;
47 static uno::Sequence< OUString> lcl_getGroupAbsent()
49 const OUString pProps[] = {
50 OUString(PROPERTY_CANGROW)
51 ,OUString(PROPERTY_CANSHRINK)
54 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
58 static uno::Sequence< OUString> lcl_getAbsent(bool _bPageSection)
60 if ( _bPageSection )
62 const OUString pProps[] = {
63 OUString(PROPERTY_FORCENEWPAGE)
64 ,OUString(PROPERTY_NEWROWORCOL)
65 ,OUString(PROPERTY_KEEPTOGETHER)
66 ,OUString(PROPERTY_CANGROW)
67 ,OUString(PROPERTY_CANSHRINK)
68 ,OUString(PROPERTY_REPEATSECTION)
70 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
73 const OUString pProps[] = {
74 OUString(PROPERTY_CANGROW)
75 ,OUString(PROPERTY_CANSHRINK)
76 ,OUString(PROPERTY_REPEATSECTION)
79 return uno::Sequence< OUString >(pProps,SAL_N_ELEMENTS(pProps));
82 uno::Reference<report::XSection> OSection::createOSection(
83 const uno::Reference< report::XReportDefinition >& xParentDef,
84 const uno::Reference< uno::XComponentContext >& context,
85 bool const bPageSection)
87 OSection *const pNew =
88 new OSection(xParentDef, nullptr, context, lcl_getAbsent(bPageSection));
89 pNew->init();
90 return pNew;
93 uno::Reference<report::XSection> OSection::createOSection(
94 const uno::Reference< report::XGroup >& xParentGroup,
95 const uno::Reference< uno::XComponentContext >& context)
97 OSection *const pNew =
98 new OSection(nullptr, xParentGroup, context, lcl_getGroupAbsent());
99 pNew->init();
100 return pNew;
104 OSection::OSection(const uno::Reference< report::XReportDefinition >& xParentDef
105 ,const uno::Reference< report::XGroup >& xParentGroup
106 ,const uno::Reference< uno::XComponentContext >& context
107 ,uno::Sequence< OUString> const& rStrings)
108 :SectionBase(m_aMutex)
109 ,SectionPropertySet(context,SectionPropertySet::IMPLEMENTS_PROPERTY_SET,rStrings)
110 ,m_aContainerListeners(m_aMutex)
111 ,m_xGroup(xParentGroup)
112 ,m_xReportDefinition(xParentDef)
113 ,m_nHeight(3000)
114 ,m_nBackgroundColor(COL_TRANSPARENT)
115 ,m_nForceNewPage(report::ForceNewPage::NONE)
116 ,m_nNewRowOrCol(report::ForceNewPage::NONE)
117 ,m_bKeepTogether(false)
118 ,m_bRepeatSection(false)
119 ,m_bVisible(true)
120 ,m_bBacktransparent(true)
121 ,m_bInRemoveNotify(false)
122 ,m_bInInsertNotify(false)
126 // TODO: VirtualFunctionFinder: This is virtual function!
128 OSection::~OSection()
132 //IMPLEMENT_FORWARD_XINTERFACE2(OSection,SectionBase,SectionPropertySet)
133 IMPLEMENT_FORWARD_REFCOUNT( OSection, SectionBase )
135 uno::Any SAL_CALL OSection::queryInterface( const uno::Type& _rType )
137 uno::Any aReturn = SectionBase::queryInterface(_rType);
138 if ( !aReturn.hasValue() )
139 aReturn = SectionPropertySet::queryInterface(_rType);
141 if ( !aReturn.hasValue() && OReportControlModel::isInterfaceForbidden(_rType) )
142 return aReturn;
144 return aReturn;
148 void SAL_CALL OSection::dispose()
150 OSL_ENSURE(!rBHelper.bDisposed,"Already disposed!");
151 SectionPropertySet::dispose();
152 uno::Reference<lang::XComponent> const xPageComponent(m_xDrawPage,
153 uno::UNO_QUERY);
154 if (xPageComponent.is())
156 xPageComponent->dispose();
158 cppu::WeakComponentImplHelperBase::dispose();
162 // TODO: VirtualFunctionFinder: This is virtual function!
164 void SAL_CALL OSection::disposing()
166 lang::EventObject aDisposeEvent( static_cast< ::cppu::OWeakObject* >( this ) );
167 m_aContainerListeners.disposeAndClear( aDisposeEvent );
170 OUString SAL_CALL OSection::getImplementationName( )
172 return "com.sun.star.comp.report.Section";
175 uno::Sequence< OUString> OSection::getSupportedServiceNames_Static()
177 uno::Sequence<OUString> aSupported { SERVICE_SECTION };
178 return aSupported;
181 uno::Sequence< OUString> SAL_CALL OSection::getSupportedServiceNames()
183 return getSupportedServiceNames_Static();
186 sal_Bool SAL_CALL OSection::supportsService( const OUString& _rServiceName )
188 return cppu::supportsService(this, _rServiceName);
191 void OSection::init()
193 SolarMutexGuard g; // lock while manipulating SdrModel
194 uno::Reference< report::XReportDefinition> xReport = getReportDefinition();
195 std::shared_ptr<rptui::OReportModel> pModel = OReportDefinition::getSdrModel(xReport);
196 assert(pModel && "No model set at the report definition!");
197 if ( pModel )
199 uno::Reference<report::XSection> const xSection(this);
200 SdrPage & rSdrPage(*pModel->createNewPage(xSection));
201 m_xDrawPage.set(rSdrPage.getUnoPage(), uno::UNO_QUERY_THROW);
202 m_xDrawPage_ShapeGrouper.set(m_xDrawPage, uno::UNO_QUERY_THROW);
203 // apparently we may also get OReportDrawPage which doesn't support this
204 m_xDrawPage_FormSupplier.set(m_xDrawPage, uno::UNO_QUERY);
205 m_xDrawPage_Tunnel.set(m_xDrawPage, uno::UNO_QUERY_THROW);
206 // fdo#53872: now also exchange the XDrawPage in the SdrPage so that
207 // rSdrPage.getUnoPage returns this
208 rSdrPage.SetUnoPage(this);
209 // createNewPage _should_ have stored away 2 uno::References to this,
210 // so our ref count cannot be 1 here, so this isn't destroyed here
211 assert(m_refCount > 1);
215 // XSection
217 sal_Bool SAL_CALL OSection::getVisible()
219 ::osl::MutexGuard aGuard(m_aMutex);
220 return m_bVisible;
223 void SAL_CALL OSection::setVisible( sal_Bool _visible )
225 set(PROPERTY_VISIBLE,_visible,m_bVisible);
228 OUString SAL_CALL OSection::getName()
230 ::osl::MutexGuard aGuard(m_aMutex);
231 return m_sName;
234 void SAL_CALL OSection::setName( const OUString& _name )
236 set(PROPERTY_NAME,_name,m_sName);
239 ::sal_uInt32 SAL_CALL OSection::getHeight()
241 ::osl::MutexGuard aGuard(m_aMutex);
242 return m_nHeight;
245 void SAL_CALL OSection::setHeight( ::sal_uInt32 _height )
247 set(PROPERTY_HEIGHT,_height,m_nHeight);
250 ::sal_Int32 SAL_CALL OSection::getBackColor()
252 ::osl::MutexGuard aGuard(m_aMutex);
253 return sal_Int32(m_bBacktransparent ? COL_TRANSPARENT : m_nBackgroundColor);
256 void SAL_CALL OSection::setBackColor( ::sal_Int32 _backgroundcolor )
258 bool bTransparent = _backgroundcolor == static_cast<sal_Int32>(COL_TRANSPARENT);
259 setBackTransparent(bTransparent);
260 if ( !bTransparent )
261 set(PROPERTY_BACKCOLOR,_backgroundcolor,m_nBackgroundColor);
264 sal_Bool SAL_CALL OSection::getBackTransparent()
266 ::osl::MutexGuard aGuard(m_aMutex);
267 return m_bBacktransparent;
270 void SAL_CALL OSection::setBackTransparent( sal_Bool _backtransparent )
272 set(PROPERTY_BACKTRANSPARENT,_backtransparent,m_bBacktransparent);
273 if ( _backtransparent )
274 set(PROPERTY_BACKCOLOR,static_cast<sal_Int32>(COL_TRANSPARENT),m_nBackgroundColor);
277 OUString SAL_CALL OSection::getConditionalPrintExpression()
279 ::osl::MutexGuard aGuard(m_aMutex);
280 return m_sConditionalPrintExpression;
283 void SAL_CALL OSection::setConditionalPrintExpression( const OUString& _conditionalprintexpression )
285 set(PROPERTY_CONDITIONALPRINTEXPRESSION,_conditionalprintexpression,m_sConditionalPrintExpression);
288 void OSection::checkNotPageHeaderFooter()
290 ::osl::MutexGuard aGuard(m_aMutex);
291 uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
292 if ( xRet.is() )
294 if ( xRet->getPageHeaderOn() && xRet->getPageHeader() == *this )
295 throw beans::UnknownPropertyException();
296 if ( xRet->getPageFooterOn() && xRet->getPageFooter() == *this )
297 throw beans::UnknownPropertyException();
301 ::sal_Int16 SAL_CALL OSection::getForceNewPage()
303 ::osl::MutexGuard aGuard(m_aMutex);
305 checkNotPageHeaderFooter();
306 return m_nForceNewPage;
309 void SAL_CALL OSection::setForceNewPage( ::sal_Int16 _forcenewpage )
311 if ( _forcenewpage < report::ForceNewPage::NONE || _forcenewpage > report::ForceNewPage::BEFORE_AFTER_SECTION )
312 throwIllegallArgumentException("css::report::ForceNewPage"
313 ,*this
314 ,1);
315 checkNotPageHeaderFooter();
316 set(PROPERTY_FORCENEWPAGE,_forcenewpage,m_nForceNewPage);
319 ::sal_Int16 SAL_CALL OSection::getNewRowOrCol()
321 ::osl::MutexGuard aGuard(m_aMutex);
322 checkNotPageHeaderFooter();
323 return m_nNewRowOrCol;
326 void SAL_CALL OSection::setNewRowOrCol( ::sal_Int16 _newroworcol )
328 if ( _newroworcol < report::ForceNewPage::NONE || _newroworcol > report::ForceNewPage::BEFORE_AFTER_SECTION )
329 throwIllegallArgumentException("css::report::ForceNewPage"
330 ,*this
331 ,1);
332 checkNotPageHeaderFooter();
334 set(PROPERTY_NEWROWORCOL,_newroworcol,m_nNewRowOrCol);
337 sal_Bool SAL_CALL OSection::getKeepTogether()
339 ::osl::MutexGuard aGuard(m_aMutex);
340 checkNotPageHeaderFooter();
341 return m_bKeepTogether;
344 void SAL_CALL OSection::setKeepTogether( sal_Bool _keeptogether )
347 ::osl::MutexGuard aGuard(m_aMutex);
348 checkNotPageHeaderFooter();
351 set(PROPERTY_KEEPTOGETHER,_keeptogether,m_bKeepTogether);
354 sal_Bool SAL_CALL OSection::getCanGrow()
356 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
359 void SAL_CALL OSection::setCanGrow( sal_Bool /*_cangrow*/ )
361 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
364 sal_Bool SAL_CALL OSection::getCanShrink()
366 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
369 void SAL_CALL OSection::setCanShrink( sal_Bool /*_canshrink*/ )
371 throw beans::UnknownPropertyException(); ///TODO: unsupported at the moment
374 sal_Bool SAL_CALL OSection::getRepeatSection()
376 ::osl::MutexGuard aGuard(m_aMutex);
377 uno::Reference< report::XGroup > xGroup = m_xGroup;
378 if ( !xGroup.is() )
379 throw beans::UnknownPropertyException();
380 return m_bRepeatSection;
383 void SAL_CALL OSection::setRepeatSection( sal_Bool _repeatsection )
386 ::osl::MutexGuard aGuard(m_aMutex);
387 uno::Reference< report::XGroup > xGroup = m_xGroup;
388 if ( !xGroup.is() )
389 throw beans::UnknownPropertyException();
391 set(PROPERTY_REPEATSECTION,_repeatsection,m_bRepeatSection);
394 uno::Reference< report::XGroup > SAL_CALL OSection::getGroup()
396 ::osl::MutexGuard aGuard(m_aMutex);
397 return m_xGroup;
400 uno::Reference< report::XReportDefinition > SAL_CALL OSection::getReportDefinition()
402 ::osl::MutexGuard aGuard(m_aMutex);
403 uno::Reference< report::XReportDefinition > xRet = m_xReportDefinition;
404 uno::Reference< report::XGroup > xGroup = m_xGroup;
405 if ( !xRet.is() && xGroup.is() )
407 uno::Reference< report::XGroups> xGroups(xGroup->getGroups());
408 if ( xGroups.is() )
409 xRet = xGroups->getReportDefinition();
412 return xRet;
415 // XChild
416 uno::Reference< uno::XInterface > SAL_CALL OSection::getParent( )
418 uno::Reference< uno::XInterface > xRet;
420 ::osl::MutexGuard aGuard(m_aMutex);
421 xRet = m_xReportDefinition;
422 if ( !xRet.is() )
423 xRet = m_xGroup;
425 return xRet;
428 void SAL_CALL OSection::setParent( const uno::Reference< uno::XInterface >& /*Parent*/ )
430 throw lang::NoSupportException();
433 // XContainer
434 void SAL_CALL OSection::addContainerListener( const uno::Reference< container::XContainerListener >& xListener )
436 m_aContainerListeners.addInterface(xListener);
439 void SAL_CALL OSection::removeContainerListener( const uno::Reference< container::XContainerListener >& xListener )
441 m_aContainerListeners.removeInterface(xListener);
444 // XElementAccess
445 uno::Type SAL_CALL OSection::getElementType( )
447 return cppu::UnoType<report::XReportComponent>::get();
450 sal_Bool SAL_CALL OSection::hasElements( )
452 ::osl::MutexGuard aGuard(m_aMutex);
453 return m_xDrawPage.is() && m_xDrawPage->hasElements();
456 // XIndexAccess
457 ::sal_Int32 SAL_CALL OSection::getCount( )
459 ::osl::MutexGuard aGuard(m_aMutex);
460 return m_xDrawPage.is() ? m_xDrawPage->getCount() : 0;
463 uno::Any SAL_CALL OSection::getByIndex( ::sal_Int32 Index )
465 ::osl::MutexGuard aGuard(m_aMutex);
466 return m_xDrawPage.is() ? m_xDrawPage->getByIndex(Index) : uno::Any();
469 // XEnumerationAccess
470 uno::Reference< container::XEnumeration > SAL_CALL OSection::createEnumeration( )
472 ::osl::MutexGuard aGuard(m_aMutex);
473 return new ::comphelper::OEnumerationByIndex(static_cast<XSection*>(this));
476 uno::Reference< beans::XPropertySetInfo > SAL_CALL OSection::getPropertySetInfo( )
478 return SectionPropertySet::getPropertySetInfo();
481 void SAL_CALL OSection::setPropertyValue( const OUString& aPropertyName, const uno::Any& aValue )
483 SectionPropertySet::setPropertyValue( aPropertyName, aValue );
486 uno::Any SAL_CALL OSection::getPropertyValue( const OUString& PropertyName )
488 return SectionPropertySet::getPropertyValue( PropertyName);
491 void SAL_CALL OSection::addPropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& xListener )
493 SectionPropertySet::addPropertyChangeListener( aPropertyName, xListener );
496 void SAL_CALL OSection::removePropertyChangeListener( const OUString& aPropertyName, const uno::Reference< beans::XPropertyChangeListener >& aListener )
498 SectionPropertySet::removePropertyChangeListener( aPropertyName, aListener );
501 void SAL_CALL OSection::addVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
503 SectionPropertySet::addVetoableChangeListener( PropertyName, aListener );
506 void SAL_CALL OSection::removeVetoableChangeListener( const OUString& PropertyName, const uno::Reference< beans::XVetoableChangeListener >& aListener )
508 SectionPropertySet::removeVetoableChangeListener( PropertyName, aListener );
511 void SAL_CALL OSection::add( const uno::Reference< drawing::XShape >& xShape )
514 ::osl::MutexGuard aGuard(m_aMutex);
515 m_bInInsertNotify = true;
516 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
517 m_xDrawPage->add(xShape);
518 m_bInInsertNotify = false;
520 notifyElementAdded(xShape);
523 void SAL_CALL OSection::remove( const uno::Reference< drawing::XShape >& xShape )
526 ::osl::MutexGuard aGuard(m_aMutex);
527 m_bInRemoveNotify = true;
528 OSL_ENSURE(m_xDrawPage.is(),"No DrawPage!");
529 m_xDrawPage->remove(xShape);
530 m_bInRemoveNotify = false;
532 notifyElementRemoved(xShape);
535 // XShapeGrouper
536 uno::Reference< drawing::XShapeGroup > SAL_CALL
537 OSection::group(uno::Reference< drawing::XShapes > const& xShapes)
539 // no lock because m_xDrawPage_ShapeGrouper is const
540 return (m_xDrawPage_ShapeGrouper.is())
541 ? m_xDrawPage_ShapeGrouper->group(xShapes)
542 : nullptr;
544 void SAL_CALL
545 OSection::ungroup(uno::Reference<drawing::XShapeGroup> const& xGroup)
547 // no lock because m_xDrawPage_ShapeGrouper is const
548 if (m_xDrawPage_ShapeGrouper.is()) {
549 m_xDrawPage_ShapeGrouper->ungroup(xGroup);
553 // XFormsSupplier
554 uno::Reference<container::XNameContainer> SAL_CALL OSection::getForms()
556 // no lock because m_xDrawPage_FormSupplier is const
557 return (m_xDrawPage_FormSupplier.is())
558 ? m_xDrawPage_FormSupplier->getForms()
559 : nullptr;
561 // XFormsSupplier2
562 sal_Bool SAL_CALL OSection::hasForms()
564 // no lock because m_xDrawPage_FormSupplier is const
565 return (m_xDrawPage_FormSupplier.is())
566 && m_xDrawPage_FormSupplier->hasForms();
570 // css::lang::XUnoTunnel
572 sal_Int64 OSection::getSomething( const uno::Sequence< sal_Int8 > & rId )
574 if (isUnoTunnelId<OSection>(rId) )
575 return reinterpret_cast<sal_Int64>(this);
576 return (m_xDrawPage_Tunnel.is()) ? m_xDrawPage_Tunnel->getSomething(rId) : 0;
579 uno::Sequence< sal_Int8 > OSection::getUnoTunnelId()
581 static ::cppu::OImplementationId implId;
583 return implId.getImplementationId();
586 void OSection::notifyElementAdded(const uno::Reference< drawing::XShape >& xShape )
588 if ( !m_bInInsertNotify )
590 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::makeAny(xShape), uno::Any());
591 m_aContainerListeners.notifyEach(&container::XContainerListener::elementInserted,aEvent);
595 void OSection::notifyElementRemoved(const uno::Reference< drawing::XShape >& xShape)
597 if ( !m_bInRemoveNotify )
599 // notify our container listeners
600 container::ContainerEvent aEvent(static_cast<container::XContainer*>(this), uno::Any(), uno::makeAny(xShape), uno::Any());
601 m_aContainerListeners.notifyEach(&container::XContainerListener::elementRemoved,aEvent);
605 } // namespace reportdesign
608 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */