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
;
30 TYPEINIT1( OReportPage
, SdrPage
);
33 OReportPage::OReportPage( OReportModel
& _rModel
34 ,const uno::Reference
< report::XSection
>& _xSection
36 :SdrPage( _rModel
, bMasterPage
)
38 ,m_xSection(_xSection
)
39 ,m_bSpecialInsertMode(false)
45 OReportPage::OReportPage( const OReportPage
& rPage
)
48 ,m_xSection(rPage
.m_xSection
)
49 ,m_bSpecialInsertMode(rPage
.m_bSpecialInsertMode
)
50 ,m_aTemporaryObjectList(rPage
.m_aTemporaryObjectList
)
56 OReportPage::~OReportPage()
62 SdrPage
* OReportPage::Clone() const
67 SdrPage
* OReportPage::Clone( SdrModel
* const pNewModel
) const
69 OReportPage
*const pNewPage
= new OReportPage( *this );
70 OReportModel
* pReportModel
= 0;
73 pReportModel
= dynamic_cast<OReportModel
*>( pNewModel
);
74 assert( pReportModel
);
76 pNewPage
->lateInit( *this, pReportModel
);
81 sal_uLong
OReportPage::getIndexOf(const uno::Reference
< report::XReportComponent
>& _xObject
)
83 const size_t nCount
= GetObjCount();
85 for (; i
< nCount
; ++i
)
87 OObjectBase
* pObj
= dynamic_cast<OObjectBase
*>(GetObj(i
));
88 OSL_ENSURE(pObj
,"Invalid object found!");
89 if ( pObj
&& pObj
->getReportComponent() == _xObject
)
94 return static_cast<sal_uLong
>(i
);
97 void OReportPage::removeSdrObject(const uno::Reference
< report::XReportComponent
>& _xObject
)
99 sal_uLong nPos
= getIndexOf(_xObject
);
100 if ( nPos
< GetObjCount() )
102 OObjectBase
* pBase
= dynamic_cast<OObjectBase
*>(GetObj(nPos
));
103 OSL_ENSURE(pBase
,"Why is this not a OObjectBase?");
105 pBase
->EndListening();
110 SdrObject
* OReportPage::RemoveObject(size_t nObjNum
)
112 SdrObject
* pObj
= SdrPage::RemoveObject(nObjNum
);
113 if (getSpecialMode())
118 // this code is evil, but what else shall I do
119 reportdesign::OSection
* pSection
= reportdesign::OSection::getImplementation(m_xSection
);
120 uno::Reference
< drawing::XShape
> xShape(pObj
->getUnoShape(),uno::UNO_QUERY
);
121 pSection
->notifyElementRemoved(xShape
);
122 if (pObj
->ISA(OUnoObject
))
124 OUnoObject
& rUnoObj
= dynamic_cast<OUnoObject
&>(*pObj
);
125 uno::Reference
< container::XChild
> xChild(rUnoObj
.GetUnoControlModel(),uno::UNO_QUERY
);
127 xChild
->setParent(NULL
);
132 void OReportPage::insertObject(const uno::Reference
< report::XReportComponent
>& _xObject
)
134 OSL_ENSURE(_xObject
.is(),"Object is not valid to create a SdrObject!");
135 if ( !_xObject
.is() )
137 sal_uLong nPos
= getIndexOf(_xObject
);
138 if ( nPos
< GetObjCount() )
139 return; // Object already in list
141 SvxShape
* pShape
= SvxShape::getImplementation( _xObject
);
142 OObjectBase
* pObject
= pShape
? dynamic_cast< OObjectBase
* >( pShape
->GetSdrObject() ) : NULL
;
143 OSL_ENSURE( pObject
, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
145 pObject
->StartListening();
149 uno::Reference
< uno::XInterface
> OReportPage::createUnoPage()
151 return static_cast<cppu::OWeakObject
*>( new reportdesign::OReportDrawPage(this,m_xSection
) );
154 void OReportPage::removeTempObject(SdrObject
*_pToRemoveObj
)
158 for (size_t i
=0; i
<GetObjCount(); ++i
)
160 SdrObject
*aObj
= GetObj(i
);
161 if (aObj
&& aObj
== _pToRemoveObj
)
163 SdrObject
* pObject
= RemoveObject(i
);
171 void OReportPage::resetSpecialMode()
173 const bool bChanged
= rModel
.IsChanged();
174 ::std::vector
<SdrObject
*>::iterator aIter
= m_aTemporaryObjectList
.begin();
175 ::std::vector
<SdrObject
*>::iterator aEnd
= m_aTemporaryObjectList
.end();
177 for (; aIter
!= aEnd
; ++aIter
)
179 removeTempObject(*aIter
);
181 m_aTemporaryObjectList
.clear();
182 rModel
.SetChanged(bChanged
);
184 m_bSpecialInsertMode
= false;
187 void OReportPage::NbcInsertObject(SdrObject
* pObj
, size_t nPos
, const SdrInsertReason
* pReason
)
189 SdrPage::NbcInsertObject(pObj
, nPos
, pReason
);
191 OUnoObject
* pUnoObj
= dynamic_cast< OUnoObject
* >( pObj
);
192 if (getSpecialMode())
194 m_aTemporaryObjectList
.push_back(pObj
);
200 pUnoObj
->CreateMediator();
201 uno::Reference
< container::XChild
> xChild(pUnoObj
->GetUnoControlModel(),uno::UNO_QUERY
);
202 if ( xChild
.is() && !xChild
->getParent().is() )
203 xChild
->setParent(m_xSection
);
206 // this code is evil, but what else shall I do
207 reportdesign::OSection
* pSection
= reportdesign::OSection::getImplementation(m_xSection
);
208 uno::Reference
< drawing::XShape
> xShape(pObj
->getUnoShape(),uno::UNO_QUERY
);
209 pSection
->notifyElementAdded(xShape
);
211 // now that the shape is inserted into its structures, we can allow the OObjectBase
212 // to release the reference to it
213 OObjectBase
* pObjectBase
= dynamic_cast< OObjectBase
* >( pObj
);
214 OSL_ENSURE( pObjectBase
, "OReportPage::NbcInsertObject: what is being inserted here?" );
216 pObjectBase
->releaseUnoShape();
222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */