bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / core / sdr / RptPage.cxx
blobd344397bd6dbf0e4580f9c740ad0c022bd3f6f47
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 <RptPage.hxx>
20 #include <RptModel.hxx>
21 #include <Section.hxx>
22 #include <RptObject.hxx>
23 #include <svx/unoapi.hxx>
24 #include <svx/unoshape.hxx>
25 #include <ReportDrawPage.hxx>
27 namespace rptui
29 using namespace ::com::sun::star;
31 OReportPage::OReportPage(
32 OReportModel& _rModel,
33 const uno::Reference< report::XSection >& _xSection)
34 : SdrPage(_rModel, false/*bMasterPage*/)
35 ,rModel(_rModel)
36 ,m_xSection(_xSection)
37 ,m_bSpecialInsertMode(false)
41 OReportPage::~OReportPage()
45 SdrPage* OReportPage::CloneSdrPage(SdrModel& rTargetModel) const
47 OReportModel& rOReportModel(static_cast< OReportModel& >(rTargetModel));
48 OReportPage* pClonedOReportPage(
49 new OReportPage(
50 rOReportModel,
51 m_xSection));
52 pClonedOReportPage->SdrPage::lateInit(*this);
53 return pClonedOReportPage;
57 sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
59 const size_t nCount = GetObjCount();
60 size_t i = 0;
61 for (; i < nCount; ++i)
63 OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
64 OSL_ENSURE(pObj,"Invalid object found!");
65 if ( pObj && pObj->getReportComponent() == _xObject )
67 break;
70 return static_cast<sal_uLong>(i);
73 void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
75 sal_uLong nPos = getIndexOf(_xObject);
76 if ( nPos < GetObjCount() )
78 OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
79 OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
80 if ( pBase )
81 pBase->EndListening();
82 RemoveObject(nPos);
86 SdrObject* OReportPage::RemoveObject(size_t nObjNum)
88 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
89 if (getSpecialMode())
91 return pObj;
94 // this code is evil, but what else shall I do
95 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
96 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
97 pSection->notifyElementRemoved(xShape);
98 if (dynamic_cast< const OUnoObject *>( pObj ) != nullptr)
100 OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
101 uno::Reference< container::XChild> xChild(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
102 if ( xChild.is() )
103 xChild->setParent(nullptr);
105 return pObj;
108 void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
110 OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
111 if ( !_xObject.is() )
112 return;
113 sal_uLong nPos = getIndexOf(_xObject);
114 if ( nPos < GetObjCount() )
115 return; // Object already in list
117 SvxShape* pShape = SvxShape::getImplementation( _xObject );
118 OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : nullptr;
119 OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
120 if ( pObject )
121 pObject->StartListening();
125 uno::Reference< uno::XInterface > OReportPage::createUnoPage()
127 return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
130 void OReportPage::removeTempObject(SdrObject const *_pToRemoveObj)
132 if (_pToRemoveObj)
134 for (size_t i=0; i<GetObjCount(); ++i)
136 SdrObject *aObj = GetObj(i);
137 if (aObj && aObj == _pToRemoveObj)
139 (void) RemoveObject(i);
140 break;
146 void OReportPage::resetSpecialMode()
148 const bool bChanged = rModel.IsChanged();
150 for (const auto& pTemporaryObject : m_aTemporaryObjectList)
152 removeTempObject(pTemporaryObject);
154 m_aTemporaryObjectList.clear();
155 rModel.SetChanged(bChanged);
157 m_bSpecialInsertMode = false;
160 void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
162 SdrPage::NbcInsertObject(pObj, nPos);
164 OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
165 if (getSpecialMode())
167 m_aTemporaryObjectList.push_back(pObj);
168 return;
171 if ( pUnoObj )
173 pUnoObj->CreateMediator();
174 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
175 if ( xChild.is() && !xChild->getParent().is() )
176 xChild->setParent(m_xSection);
179 // this code is evil, but what else shall I do
180 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
181 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
182 pSection->notifyElementAdded(xShape);
184 // now that the shape is inserted into its structures, we can allow the OObjectBase
185 // to release the reference to it
186 OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
187 OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
188 if ( pObjectBase )
189 pObjectBase->releaseUnoShape();
192 } // rptui
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */