Line data Source code
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/unoapi.hxx>
24 : #include <svx/unoshape.hxx>
25 : #include "ReportDrawPage.hxx"
26 :
27 : namespace rptui
28 : {
29 : using namespace ::com::sun::star;
30 0 : TYPEINIT1( OReportPage, SdrPage );
31 :
32 : //----------------------------------------------------------------------------
33 : DBG_NAME( rpt_OReportPage )
34 0 : OReportPage::OReportPage( OReportModel& _rModel
35 : ,const uno::Reference< report::XSection >& _xSection
36 : ,bool bMasterPage )
37 : :SdrPage( _rModel, bMasterPage )
38 : ,rModel(_rModel)
39 : ,m_xSection(_xSection)
40 0 : ,m_bSpecialInsertMode(false)
41 : {
42 : DBG_CTOR( rpt_OReportPage,NULL);
43 0 : }
44 :
45 : //----------------------------------------------------------------------------
46 :
47 0 : OReportPage::OReportPage( const OReportPage& rPage )
48 : :SdrPage( rPage )
49 : ,rModel(rPage.rModel)
50 : ,m_xSection(rPage.m_xSection)
51 : ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
52 0 : ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
53 : {
54 : DBG_CTOR( rpt_OReportPage,NULL);
55 0 : }
56 :
57 : //----------------------------------------------------------------------------
58 :
59 0 : OReportPage::~OReportPage()
60 : {
61 : DBG_DTOR( rpt_OReportPage,NULL);
62 0 : }
63 :
64 : //----------------------------------------------------------------------------
65 :
66 0 : SdrPage* OReportPage::Clone() const
67 : {
68 : DBG_CHKTHIS( rpt_OReportPage,NULL);
69 0 : return new OReportPage( *this );
70 : }
71 :
72 : //----------------------------------------------------------------------------
73 0 : sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
74 : {
75 : DBG_CHKTHIS( rpt_OReportPage,NULL);
76 0 : sal_uLong nCount = GetObjCount();
77 0 : sal_uLong i = 0;
78 0 : for (; i < nCount; ++i)
79 : {
80 0 : OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
81 : OSL_ENSURE(pObj,"Invalid object found!");
82 0 : if ( pObj && pObj->getReportComponent() == _xObject )
83 : {
84 0 : break;
85 : }
86 : }
87 0 : return i;
88 : }
89 : //----------------------------------------------------------------------------
90 0 : void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
91 : {
92 : DBG_CHKTHIS( rpt_OReportPage,NULL);
93 0 : sal_uLong nPos = getIndexOf(_xObject);
94 0 : if ( nPos < GetObjCount() )
95 : {
96 0 : OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
97 : OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
98 0 : if ( pBase )
99 0 : pBase->EndListening();
100 0 : RemoveObject(nPos);
101 : }
102 0 : }
103 : // -----------------------------------------------------------------------------
104 0 : SdrObject* OReportPage::RemoveObject(sal_uLong nObjNum)
105 : {
106 0 : SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
107 0 : if (getSpecialMode())
108 : {
109 0 : return pObj;
110 : }
111 :
112 : // this code is evil, but what else shall I do
113 0 : reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
114 0 : uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
115 0 : pSection->notifyElementRemoved(xShape);
116 0 : if (pObj->ISA(OUnoObject))
117 : {
118 0 : OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj);
119 0 : uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
120 0 : if ( xChild.is() )
121 0 : xChild->setParent(NULL);
122 : }
123 0 : return pObj;
124 : }
125 : //----------------------------------------------------------------------------
126 0 : void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
127 : {
128 : DBG_CHKTHIS( rpt_OReportPage,NULL);
129 : OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
130 0 : if ( !_xObject.is() )
131 0 : return;
132 0 : sal_uLong nPos = getIndexOf(_xObject);
133 0 : if ( nPos < GetObjCount() )
134 0 : return; // Object already in list
135 :
136 0 : SvxShape* pShape = SvxShape::getImplementation( _xObject );
137 0 : OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL;
138 : OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
139 0 : if ( pObject )
140 0 : pObject->StartListening();
141 : }
142 : // -----------------------------------------------------------------------------
143 0 : uno::Reference< report::XSection > OReportPage::getSection() const
144 : {
145 0 : return m_xSection;
146 : }
147 : // -----------------------------------------------------------------------------
148 0 : uno::Reference< uno::XInterface > OReportPage::createUnoPage()
149 : {
150 0 : return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
151 : }
152 : // -----------------------------------------------------------------------------
153 0 : void OReportPage::removeTempObject(SdrObject *_pToRemoveObj)
154 : {
155 0 : if (_pToRemoveObj)
156 : {
157 0 : for (sal_uLong i=0;i<GetObjCount();i++)
158 : {
159 0 : SdrObject *aObj = GetObj(i);
160 0 : if (aObj && aObj == _pToRemoveObj)
161 : {
162 0 : SdrObject* pObject = RemoveObject(i);
163 : (void)pObject;
164 0 : break;
165 : }
166 : }
167 : }
168 0 : }
169 :
170 0 : void OReportPage::resetSpecialMode()
171 : {
172 0 : const sal_Bool bChanged = rModel.IsChanged();
173 0 : ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin();
174 0 : ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end();
175 :
176 0 : for (; aIter != aEnd; ++aIter)
177 : {
178 0 : removeTempObject(*aIter);
179 : }
180 0 : m_aTemporaryObjectList.clear();
181 0 : rModel.SetChanged(bChanged);
182 :
183 0 : m_bSpecialInsertMode = false;
184 0 : }
185 : // -----------------------------------------------------------------------------
186 0 : void OReportPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason)
187 : {
188 0 : SdrPage::NbcInsertObject(pObj, nPos, pReason);
189 :
190 0 : OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
191 0 : if (getSpecialMode())
192 : {
193 0 : m_aTemporaryObjectList.push_back(pObj);
194 0 : return;
195 : }
196 :
197 0 : if ( pUnoObj )
198 : {
199 0 : pUnoObj->CreateMediator();
200 0 : uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
201 0 : if ( xChild.is() && !xChild->getParent().is() )
202 0 : xChild->setParent(m_xSection);
203 : }
204 :
205 : // this code is evil, but what else shall I do
206 0 : reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
207 0 : uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
208 0 : pSection->notifyElementAdded(xShape);
209 :
210 : // now that the shape is inserted into its structures, we can allow the OObjectBase
211 : // to release the reference to it
212 0 : OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
213 : OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
214 0 : if ( pObjectBase )
215 0 : pObjectBase->releaseUnoShape();
216 : }
217 : //============================================================================
218 : } // rptui
219 : //============================================================================
220 :
221 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|