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