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 
25 namespace rptui
26 {
27 using namespace ::com::sun::star;
28 
30  OReportModel& _rModel,
31  const uno::Reference< report::XSection >& _xSection)
32 : SdrPage(_rModel, false/*bMasterPage*/)
33  ,rModel(_rModel)
34  ,m_xSection(_xSection)
35  ,m_bSpecialInsertMode(false)
36 {
37 }
38 
40 {
41 }
42 
44 {
45  OReportModel& rOReportModel(static_cast< OReportModel& >(rTargetModel));
46  rtl::Reference<OReportPage> pClonedOReportPage(
47  new OReportPage(
48  rOReportModel,
49  m_xSection));
50  pClonedOReportPage->SdrPage::lateInit(*this);
51  return pClonedOReportPage;
52 }
53 
54 
55 size_t OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
56 {
57  const size_t nCount = GetObjCount();
58  size_t i = 0;
59  for (; i < nCount; ++i)
60  {
61  OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
62  OSL_ENSURE(pObj,"Invalid object found!");
63  if ( pObj && pObj->getReportComponent() == _xObject )
64  {
65  break;
66  }
67  }
68  return i;
69 }
70 
71 void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
72 {
73  size_t nPos = getIndexOf(_xObject);
74  if ( nPos < GetObjCount() )
75  {
76  OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
77  OSL_ENSURE(pBase,"Why is this not an OObjectBase?");
78  if ( pBase )
79  pBase->EndListening();
80  RemoveObject(nPos);
81  }
82 }
83 
85 {
86  SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
87  if (getSpecialMode())
88  {
89  return pObj;
90  }
91 
92  // this code is evil, but what else shall I do
93  reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection);
94  uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
95  pSection->notifyElementRemoved(xShape);
96  if (dynamic_cast< const OUnoObject *>( pObj ) != nullptr)
97  {
98  OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
99  uno::Reference< container::XChild> xChild(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
100  if ( xChild.is() )
101  xChild->setParent(nullptr);
102  }
103  return pObj;
104 }
105 
106 void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
107 {
108  OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
109  if ( !_xObject.is() )
110  return;
111  size_t nPos = getIndexOf(_xObject);
112  if ( nPos < GetObjCount() )
113  return; // Object already in list
114 
115  OObjectBase* pObject = dynamic_cast< OObjectBase* >(SdrObject::getSdrObjectFromXShape( _xObject ));
116  OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
117  if ( pObject )
118  pObject->StartListening();
119 }
120 
121 
122 uno::Reference< uno::XInterface > OReportPage::createUnoPage()
123 {
124  return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
125 }
126 
127 void OReportPage::removeTempObject(SdrObject const *_pToRemoveObj)
128 {
129  if (_pToRemoveObj)
130  {
131  for (size_t i=0; i<GetObjCount(); ++i)
132  {
133  SdrObject *aObj = GetObj(i);
134  if (aObj && aObj == _pToRemoveObj)
135  {
136  (void) RemoveObject(i);
137  break;
138  }
139  }
140  }
141 }
142 
144 {
145  const bool bChanged = rModel.IsChanged();
146 
147  for (const auto& pTemporaryObject : m_aTemporaryObjectList)
148  {
149  removeTempObject(pTemporaryObject);
150  }
151  m_aTemporaryObjectList.clear();
152  rModel.SetChanged(bChanged);
153 
154  m_bSpecialInsertMode = false;
155 }
156 
157 void OReportPage::NbcInsertObject(SdrObject* pObj, size_t nPos)
158 {
159  SdrPage::NbcInsertObject(pObj, nPos);
160 
161  OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
162  if (getSpecialMode())
163  {
164  m_aTemporaryObjectList.push_back(pObj);
165  return;
166  }
167 
168  if ( pUnoObj )
169  {
170  pUnoObj->CreateMediator();
171  uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
172  if ( xChild.is() && !xChild->getParent().is() )
173  xChild->setParent(m_xSection);
174  }
175 
176  // this code is evil, but what else shall I do
177  reportdesign::OSection* pSection = comphelper::getFromUnoTunnel<reportdesign::OSection>(m_xSection);
178  uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
179  pSection->notifyElementAdded(xShape);
180 
181  // now that the shape is inserted into its structures, we can allow the OObjectBase
182  // to release the reference to it
183  OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
184  OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
185  if ( pObjectBase )
186  pObjectBase->releaseUnoShape();
187 }
188 
189 } // rptui
190 
191 
192 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
OReportPage(const OReportPage &)=delete
virtual css::uno::Reference< css::uno::XInterface > createUnoPage() override
Definition: RptPage.cxx:122
virtual ~OReportPage() override
Definition: RptPage.cxx:39
OReportModel & rModel
Definition: RptPage.hxx:40
void CreateMediator(bool _bReverse=false)
creates the m_xMediator when it doesn't already exist.
Definition: RptObject.cxx:829
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:55
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:43
void removeSdrObject(const css::uno::Reference< css::report::XReportComponent > &_xObject)
removes the SdrObject which belongs to the report component.
Definition: RptPage.cxx:71
int i
virtual void NbcInsertObject(SdrObject *pObj, size_t nPos=SAL_MAX_SIZE) override
Definition: RptPage.cxx:157
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:127
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:106
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
virtual SdrObject * RemoveObject(size_t nObjNum) override
Definition: RptPage.cxx:84
sal_uInt16 nPos
void resetSpecialMode()
Definition: RptPage.cxx:143
bool m_bDetectedRangeSegmentation false
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo