tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / source / core / sdr / RptPage.cxx
blobc72d20ba506693623a39482dae1538210edddf00
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 <ReportDrawPage.hxx>
24 #include <utility>
26 namespace rptui
28 using namespace ::com::sun::star;
30 OReportPage::OReportPage(
31 OReportModel& _rModel,
32 uno::Reference< report::XSection > _xSection)
33 : SdrPage(_rModel, false/*bMasterPage*/)
34 ,rModel(_rModel)
35 ,m_xSection(std::move(_xSection))
36 ,m_bSpecialInsertMode(false)
40 OReportPage::~OReportPage()
44 rtl::Reference<SdrPage> OReportPage::CloneSdrPage(SdrModel& rTargetModel) const
46 OReportModel& rOReportModel(static_cast< OReportModel& >(rTargetModel));
47 rtl::Reference<OReportPage> pClonedOReportPage(
48 new OReportPage(
49 rOReportModel,
50 m_xSection));
51 pClonedOReportPage->SdrPage::lateInit(*this);
52 return pClonedOReportPage;
56 size_t OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
58 const size_t nCount = GetObjCount();
59 size_t i = 0;
60 for (; i < nCount; ++i)
62 OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
63 OSL_ENSURE(pObj,"Invalid object found!");
64 if ( pObj && pObj->getReportComponent() == _xObject )
66 break;
69 return i;
72 void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
74 size_t nPos = getIndexOf(_xObject);
75 if ( nPos < GetObjCount() )
77 OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
78 OSL_ENSURE(pBase,"Why is this not an OObjectBase?");
79 if ( pBase )
80 pBase->EndListening();
81 RemoveObject(nPos);
85 rtl::Reference<SdrObject> OReportPage::RemoveObject(size_t nObjNum)
87 rtl::Reference<SdrObject> pObj = SdrPage::RemoveObject(nObjNum);
88 if (getSpecialMode())
90 return pObj;
93 // this code is evil, but what else shall I do
94 reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection);
95 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
96 pSection->notifyElementRemoved(xShape);
97 if (dynamic_cast< const OUnoObject *>( pObj.get() ) != nullptr)
99 OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
100 uno::Reference< container::XChild> xChild(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
101 if ( xChild.is() )
102 xChild->setParent(nullptr);
104 return pObj;
107 void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
109 OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
110 if ( !_xObject.is() )
111 return;
112 size_t nPos = getIndexOf(_xObject);
113 if ( nPos < GetObjCount() )
114 return; // Object already in list
116 OObjectBase* pObject = dynamic_cast< OObjectBase* >(SdrObject::getSdrObjectFromXShape( _xObject ));
117 OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
118 if ( pObject )
119 pObject->StartListening();
123 uno::Reference< uno::XInterface > OReportPage::createUnoPage()
125 return cppu::getXWeak( new reportdesign::OReportDrawPage(this,m_xSection) );
128 void OReportPage::removeTempObject(SdrObject const *_pToRemoveObj)
130 if (_pToRemoveObj)
132 for (size_t i=0; i<GetObjCount(); ++i)
134 SdrObject *aObj = GetObj(i);
135 if (aObj && aObj == _pToRemoveObj)
137 (void) RemoveObject(i);
138 break;
144 void OReportPage::resetSpecialMode()
146 const bool bChanged = rModel.IsChanged();
148 for (const auto& pTemporaryObject : m_aTemporaryObjectList)
150 removeTempObject(pTemporaryObject);
152 m_aTemporaryObjectList.clear();
153 rModel.SetChanged(bChanged);
155 m_bSpecialInsertMode = false;
158 void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
160 SdrPage::NbcInsertObject(pObj, nPos);
162 OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
163 if (getSpecialMode())
165 m_aTemporaryObjectList.push_back(pObj);
166 return;
169 if ( pUnoObj )
171 pUnoObj->CreateMediator();
172 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
173 if ( xChild.is() && !xChild->getParent().is() )
174 xChild->setParent(m_xSection);
177 // this code is evil, but what else shall I do
178 reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection);
179 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
180 pSection->notifyElementAdded(xShape);
182 // now that the shape is inserted into its structures, we can allow the OObjectBase
183 // to release the reference to it
184 OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
185 OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
186 if ( pObjectBase )
187 pObjectBase->releaseUnoShape();
190 } // rptui
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */