LibreOffice Module reportdesign (master) 1
RptPage.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19#include <RptPage.hxx>
20#include <RptModel.hxx>
21#include <Section.hxx>
22#include <RptObject.hxx>
23#include <ReportDrawPage.hxx>
24#include <utility>
25
26namespace rptui
27{
28using namespace ::com::sun::star;
29
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)
37{
38}
39
40OReportPage::~OReportPage()
41{
42}
43
44rtl::Reference<SdrPage> OReportPage::CloneSdrPage(SdrModel& rTargetModel) const
45{
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;
53}
54
55
56size_t OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
57{
58 const size_t nCount = GetObjCount();
59 size_t i = 0;
60 for (; i < nCount; ++i)
61 {
62 OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
63 OSL_ENSURE(pObj,"Invalid object found!");
64 if ( pObj && pObj->getReportComponent() == _xObject )
65 {
66 break;
67 }
68 }
69 return i;
70}
71
72void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
73{
74 size_t nPos = getIndexOf(_xObject);
75 if ( nPos < GetObjCount() )
76 {
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);
82 }
83}
84
85rtl::Reference<SdrObject> OReportPage::RemoveObject(size_t nObjNum)
86{
88 if (getSpecialMode())
89 {
90 return pObj;
91 }
92
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)
98 {
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);
103 }
104 return pObj;
105}
106
107void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
108{
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
115
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();
120}
121
122
123uno::Reference< uno::XInterface > OReportPage::createUnoPage()
124{
125 return cppu::getXWeak( new reportdesign::OReportDrawPage(this,m_xSection) );
126}
127
128void OReportPage::removeTempObject(SdrObject const *_pToRemoveObj)
129{
130 if (_pToRemoveObj)
131 {
132 for (size_t i=0; i<GetObjCount(); ++i)
133 {
134 SdrObject *aObj = GetObj(i);
135 if (aObj && aObj == _pToRemoveObj)
136 {
137 (void) RemoveObject(i);
138 break;
139 }
140 }
141 }
142}
143
144void OReportPage::resetSpecialMode()
145{
146 const bool bChanged = rModel.IsChanged();
147
148 for (const auto& pTemporaryObject : m_aTemporaryObjectList)
149 {
150 removeTempObject(pTemporaryObject);
151 }
152 m_aTemporaryObjectList.clear();
153 rModel.SetChanged(bChanged);
154
155 m_bSpecialInsertMode = false;
156}
157
158void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
159{
161
162 OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
163 if (getSpecialMode())
164 {
165 m_aTemporaryObjectList.push_back(pObj);
166 return;
167 }
168
169 if ( pUnoObj )
170 {
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);
175 }
176
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);
181
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();
188}
189
190} // rptui
191
192
193/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
virtual rtl::Reference< SdrObject > RemoveObject(size_t nObjNum)
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
void notifyElementAdded(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: Section.cxx:579
void notifyElementRemoved(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: Section.cxx:588
OReportPage(const OReportPage &)=delete
void CreateMediator(bool _bReverse=false)
creates the m_xMediator when it doesn't already exist.
Definition: RptObject.cxx:833
int nCount
EmbeddedObjectRef * pObject
sal_uInt16 nPos
int i