1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
28 using namespace ::com::sun::star
;
30 OReportPage::OReportPage(
31 OReportModel
& _rModel
,
32 uno::Reference
< report::XSection
> _xSection
)
33 : SdrPage(_rModel
, false/*bMasterPage*/)
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(
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();
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
)
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?");
80 pBase
->EndListening();
85 rtl::Reference
<SdrObject
> OReportPage::RemoveObject(size_t nObjNum
)
87 rtl::Reference
<SdrObject
> pObj
= SdrPage::RemoveObject(nObjNum
);
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
);
102 xChild
->setParent(nullptr);
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() )
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!" );
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
)
132 for (size_t i
=0; i
<GetObjCount(); ++i
)
134 SdrObject
*aObj
= GetObj(i
);
135 if (aObj
&& aObj
== _pToRemoveObj
)
137 (void) RemoveObject(i
);
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
);
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?" );
187 pObjectBase
->releaseUnoShape();
193 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */