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 <svx/unoshape.hxx>
24 #include <ReportDrawPage.hxx>
25 
26 namespace rptui
27 {
28 using namespace ::com::sun::star;
29 
31  OReportModel& _rModel,
32  const uno::Reference< report::XSection >& _xSection)
33 : SdrPage(_rModel, false/*bMasterPage*/)
34  ,rModel(_rModel)
35  ,m_xSection(_xSection)
36  ,m_bSpecialInsertMode(false)
37 {
38 }
39 
41 {
42 }
43 
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 
56 size_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 
72 void 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 
86 {
87  SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
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 ) != 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 
107 void 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 
123 uno::Reference< uno::XInterface > OReportPage::createUnoPage()
124 {
125  return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
126 }
127 
128 void 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 
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 
158 void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
159 {
160  SdrPage::NbcInsertObject(pObj, nPos);
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: */
OReportPage(const OReportPage &)=delete
virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override
Definition: RptPage.cxx:123
virtual ~OReportPage() override
Definition: RptPage.cxx:40
OReportModel & rModel
Definition: RptPage.hxx:40
void CreateMediator(bool _bReverse=false)
creates the m_xMediator when it doesn't already exist.
Definition: RptObject.cxx:830
static SdrObject * getSdrObjectFromXShape(const css::uno::Reference< css::uno::XInterface > &xInt)
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE)
void notifyElementAdded(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: Section.cxx:579
SdrObject * GetObj(size_t nNum) const
size_t getIndexOf(const css::uno::Reference< css::report::XReportComponent > &_xObject)
returns the index inside the object list which belongs to the report component.
Definition: RptPage.cxx:56
size_t GetObjCount() const
void notifyElementRemoved(const css::uno::Reference< css::drawing::XShape > &xShape)
Definition: Section.cxx:588
EmbeddedObjectRef * pObject
const css::uno::Reference< css::report::XReportComponent > & getReportComponent() const
Definition: RptObject.hxx:105
void releaseUnoShape()
releases the reference to our UNO shape (m_xKeepShapeAlive)
Definition: RptObject.hxx:112
int nCount
virtual css::uno::Reference< css::drawing::XShape > getUnoShape()
virtual rtl::Reference< SdrPage > CloneSdrPage(SdrModel &rTargetModel) const override
Definition: RptPage.cxx:44
void removeSdrObject(const css::uno::Reference< css::report::XReportComponent > &_xObject)
removes the SdrObject which belongs to the report component.
Definition: RptPage.cxx:72
int i
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
Definition: RptPage.cxx:158
std::vector< SdrObject * > m_aTemporaryObjectList
Definition: RptPage.hxx:43
bool m_bSpecialInsertMode
Definition: RptPage.hxx:42
bool getSpecialMode() const
Definition: RptPage.hxx:73
virtual SdrObject * RemoveObject(size_t nObjNum)
bool IsChanged() const
void removeTempObject(SdrObject const *_pToRemoveObj)
Definition: RptPage.cxx:128
css::uno::Reference< css::report::XSection > m_xSection
Definition: RptPage.hxx:41
virtual void SetChanged(bool bFlg=true) override
Definition: RptModel.cxx:76
void insertObject(const css::uno::Reference< css::report::XReportComponent > &_xObject)
insert a new SdrObject which belongs to the report component.
Definition: RptPage.cxx:107
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
virtual SdrObject * RemoveObject(size_t nObjNum) override
Definition: RptPage.cxx:85
sal_uInt16 nPos
void resetSpecialMode()
Definition: RptPage.cxx:144
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo