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 <svx/unoapi.hxx>
24 #include <svx/unoshape.hxx>
25 #include <ReportDrawPage.hxx>
29 using namespace ::com::sun::star
;
31 OReportPage::OReportPage(
32 OReportModel
& _rModel
,
33 const uno::Reference
< report::XSection
>& _xSection
)
34 : SdrPage(_rModel
, false/*bMasterPage*/)
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(
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();
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
)
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?");
81 pBase
->EndListening();
86 SdrObject
* OReportPage::RemoveObject(size_t nObjNum
)
88 SdrObject
* pObj
= SdrPage::RemoveObject(nObjNum
);
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
);
103 xChild
->setParent(nullptr);
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() )
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!" );
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
)
134 for (size_t i
=0; i
<GetObjCount(); ++i
)
136 SdrObject
*aObj
= GetObj(i
);
137 if (aObj
&& aObj
== _pToRemoveObj
)
139 (void) RemoveObject(i
);
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
);
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?" );
189 pObjectBase
->releaseUnoShape();
195 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */