Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #include "RptPage.hxx"
29 : : #include "RptModel.hxx"
30 : : #include "Section.hxx"
31 : : #include "RptObject.hxx"
32 : : #include <svx/unoapi.hxx>
33 : : #include <svx/unoshape.hxx>
34 : : #include "ReportDrawPage.hxx"
35 : :
36 : : namespace rptui
37 : : {
38 : : using namespace ::com::sun::star;
39 [ # # ][ # # ]: 0 : TYPEINIT1( OReportPage, SdrPage );
40 : :
41 : : //----------------------------------------------------------------------------
42 : : DBG_NAME( rpt_OReportPage )
43 : 0 : OReportPage::OReportPage( OReportModel& _rModel
44 : : ,const uno::Reference< report::XSection >& _xSection
45 : : ,bool bMasterPage )
46 : : :SdrPage( _rModel, bMasterPage )
47 : : ,rModel(_rModel)
48 : : ,m_xSection(_xSection)
49 [ # # ]: 0 : ,m_bSpecialInsertMode(false)
50 : : {
51 : : DBG_CTOR( rpt_OReportPage,NULL);
52 : 0 : }
53 : :
54 : : //----------------------------------------------------------------------------
55 : :
56 : 0 : OReportPage::OReportPage( const OReportPage& rPage )
57 : : :SdrPage( rPage )
58 : : ,rModel(rPage.rModel)
59 : : ,m_xSection(rPage.m_xSection)
60 : : ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
61 [ # # ]: 0 : ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
62 : : {
63 : : DBG_CTOR( rpt_OReportPage,NULL);
64 : 0 : }
65 : :
66 : : //----------------------------------------------------------------------------
67 : :
68 : 0 : OReportPage::~OReportPage()
69 : : {
70 : : DBG_DTOR( rpt_OReportPage,NULL);
71 [ # # ]: 0 : }
72 : :
73 : : //----------------------------------------------------------------------------
74 : :
75 : 0 : SdrPage* OReportPage::Clone() const
76 : : {
77 : : DBG_CHKTHIS( rpt_OReportPage,NULL);
78 [ # # ]: 0 : return new OReportPage( *this );
79 : : }
80 : :
81 : : //----------------------------------------------------------------------------
82 : 0 : sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
83 : : {
84 : : DBG_CHKTHIS( rpt_OReportPage,NULL);
85 : 0 : sal_uLong nCount = GetObjCount();
86 : 0 : sal_uLong i = 0;
87 [ # # ]: 0 : for (; i < nCount; ++i)
88 : : {
89 [ # # ]: 0 : OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
90 : : OSL_ENSURE(pObj,"Invalid object found!");
91 [ # # ][ # # ]: 0 : if ( pObj && pObj->getReportComponent() == _xObject )
[ # # ][ # # ]
[ # # ]
[ # # # # ]
92 : : {
93 : 0 : break;
94 : : }
95 : : }
96 : 0 : return i;
97 : : }
98 : : //----------------------------------------------------------------------------
99 : 0 : void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
100 : : {
101 : : DBG_CHKTHIS( rpt_OReportPage,NULL);
102 : 0 : sal_uLong nPos = getIndexOf(_xObject);
103 [ # # ]: 0 : if ( nPos < GetObjCount() )
104 : : {
105 [ # # ]: 0 : OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
106 : : OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
107 [ # # ]: 0 : if ( pBase )
108 : 0 : pBase->EndListening();
109 : 0 : RemoveObject(nPos);
110 : : }
111 : 0 : }
112 : : // -----------------------------------------------------------------------------
113 : 0 : SdrObject* OReportPage::RemoveObject(sal_uLong nObjNum)
114 : : {
115 [ # # ]: 0 : SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
116 [ # # ]: 0 : if (getSpecialMode())
117 : : {
118 : 0 : return pObj;
119 : : }
120 : :
121 : : // this code is evil, but what else shall I do
122 [ # # ]: 0 : reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
123 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
124 [ # # ]: 0 : pSection->notifyElementRemoved(xShape);
125 [ # # ][ # # ]: 0 : if (pObj->ISA(OUnoObject))
[ # # ]
126 : : {
127 [ # # ]: 0 : OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj);
128 [ # # ][ # # ]: 0 : uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
129 [ # # ]: 0 : if ( xChild.is() )
130 [ # # ][ # # ]: 0 : xChild->setParent(NULL);
[ # # ]
131 : : }
132 : 0 : return pObj;
133 : : }
134 : : //----------------------------------------------------------------------------
135 : 0 : void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
136 : : {
137 : : DBG_CHKTHIS( rpt_OReportPage,NULL);
138 : : OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
139 [ # # ]: 0 : if ( !_xObject.is() )
140 : 0 : return;
141 : 0 : sal_uLong nPos = getIndexOf(_xObject);
142 [ # # ]: 0 : if ( nPos < GetObjCount() )
143 : 0 : return; // Object already in list
144 : :
145 : 0 : SvxShape* pShape = SvxShape::getImplementation( _xObject );
146 [ # # ][ # # ]: 0 : OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL;
147 : : OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
148 [ # # ]: 0 : if ( pObject )
149 : 0 : pObject->StartListening();
150 : : }
151 : : // -----------------------------------------------------------------------------
152 : 0 : uno::Reference< report::XSection > OReportPage::getSection() const
153 : : {
154 : 0 : return m_xSection;
155 : : }
156 : : // -----------------------------------------------------------------------------
157 : 0 : uno::Reference< uno::XInterface > OReportPage::createUnoPage()
158 : : {
159 [ # # ]: 0 : return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
160 : : }
161 : : // -----------------------------------------------------------------------------
162 : 0 : void OReportPage::removeTempObject(SdrObject *_pToRemoveObj)
163 : : {
164 [ # # ]: 0 : if (_pToRemoveObj)
165 : : {
166 [ # # ]: 0 : for (sal_uLong i=0;i<GetObjCount();i++)
167 : : {
168 : 0 : SdrObject *aObj = GetObj(i);
169 [ # # ][ # # ]: 0 : if (aObj && aObj == _pToRemoveObj)
170 : : {
171 : 0 : SdrObject* pObject = RemoveObject(i);
172 : : (void)pObject;
173 : 0 : break;
174 : : }
175 : : }
176 : : }
177 : 0 : }
178 : :
179 : 0 : void OReportPage::resetSpecialMode()
180 : : {
181 : 0 : const sal_Bool bChanged = rModel.IsChanged();
182 : 0 : ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin();
183 : 0 : ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end();
184 : :
185 [ # # ][ # # ]: 0 : for (; aIter != aEnd; ++aIter)
[ # # ]
186 : : {
187 [ # # ][ # # ]: 0 : removeTempObject(*aIter);
188 : : }
189 : 0 : m_aTemporaryObjectList.clear();
190 [ # # ]: 0 : rModel.SetChanged(bChanged);
191 : :
192 : 0 : m_bSpecialInsertMode = false;
193 : 0 : }
194 : : // -----------------------------------------------------------------------------
195 : 0 : void OReportPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason)
196 : : {
197 [ # # ]: 0 : SdrPage::NbcInsertObject(pObj, nPos, pReason);
198 : :
199 [ # # ]: 0 : OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
200 [ # # ]: 0 : if (getSpecialMode())
201 : : {
202 [ # # ]: 0 : m_aTemporaryObjectList.push_back(pObj);
203 : 0 : return;
204 : : }
205 : :
206 [ # # ]: 0 : if ( pUnoObj )
207 : : {
208 [ # # ]: 0 : pUnoObj->CreateMediator();
209 [ # # ][ # # ]: 0 : uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
210 [ # # ][ # # ]: 0 : if ( xChild.is() && !xChild->getParent().is() )
[ # # ][ # # ]
[ # # # # ]
[ # # ]
211 [ # # ][ # # ]: 0 : xChild->setParent(m_xSection);
212 : : }
213 : :
214 : : // this code is evil, but what else shall I do
215 [ # # ]: 0 : reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
216 [ # # ][ # # ]: 0 : uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
217 [ # # ]: 0 : pSection->notifyElementAdded(xShape);
218 : :
219 : : // now that the shape is inserted into its structures, we can allow the OObjectBase
220 : : // to release the reference to it
221 [ # # ]: 0 : OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
222 : : OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
223 [ # # ]: 0 : if ( pObjectBase )
224 [ # # ]: 0 : pObjectBase->releaseUnoShape();
225 : : }
226 : : //============================================================================
227 : : } // rptui
228 : : //============================================================================
229 : :
230 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|