Update ooo320-m1
[ooovba.git] / reportdesign / source / core / sdr / RptPage.cxx
blob75a18d975c988e7486321c8751aeb8517d01305d
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RptPage.cxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "RptPage.hxx"
31 #include "RptModel.hxx"
32 #include "Section.hxx"
33 #include "RptObject.hxx"
34 #include <svx/unoapi.hxx>
35 #include <svx/unoshape.hxx>
36 #include "ReportDrawPage.hxx"
38 namespace rptui
40 using namespace ::com::sun::star;
41 TYPEINIT1( OReportPage, SdrPage );
43 //----------------------------------------------------------------------------
44 DBG_NAME( rpt_OReportPage )
45 OReportPage::OReportPage( OReportModel& _rModel
46 ,const uno::Reference< report::XSection >& _xSection
47 ,FASTBOOL bMasterPage )
48 :SdrPage( _rModel, bMasterPage )
49 ,rModel(_rModel)
50 ,m_xSection(_xSection)
51 ,m_bSpecialInsertMode(false)
53 DBG_CTOR( rpt_OReportPage,NULL);
56 //----------------------------------------------------------------------------
58 OReportPage::OReportPage( const OReportPage& rPage )
59 :SdrPage( rPage )
60 ,rModel(rPage.rModel)
61 ,m_xSection(rPage.m_xSection)
62 ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
63 ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
65 DBG_CTOR( rpt_OReportPage,NULL);
68 //----------------------------------------------------------------------------
70 OReportPage::~OReportPage()
72 DBG_DTOR( rpt_OReportPage,NULL);
75 //----------------------------------------------------------------------------
77 SdrPage* OReportPage::Clone() const
79 DBG_CHKTHIS( rpt_OReportPage,NULL);
80 return new OReportPage( *this );
83 //----------------------------------------------------------------------------
84 ULONG OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
86 DBG_CHKTHIS( rpt_OReportPage,NULL);
87 ULONG nCount = GetObjCount();
88 ULONG i = 0;
89 for (; i < nCount; ++i)
91 OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
92 OSL_ENSURE(pObj,"Invalid object found!");
93 if ( pObj && pObj->getReportComponent() == _xObject )
95 break;
97 } // for (; i < nCount; ++i)
98 return i;
100 //----------------------------------------------------------------------------
101 void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
103 DBG_CHKTHIS( rpt_OReportPage,NULL);
104 ULONG nPos = getIndexOf(_xObject);
105 if ( nPos < GetObjCount() )
107 OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
108 OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
109 if ( pBase )
110 pBase->EndListening();
111 /*delete */RemoveObject(nPos);
114 // -----------------------------------------------------------------------------
115 SdrObject* OReportPage::RemoveObject(ULONG nObjNum)
117 SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
118 if (getSpecialMode())
120 return pObj;
123 // this code is evil, but what else shall I do
124 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
125 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
126 pSection->notifyElementRemoved(xShape);
127 if (pObj->ISA(OUnoObject))
129 OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj);
130 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
131 if ( xChild.is() )
132 xChild->setParent(NULL);
134 return pObj;
136 //----------------------------------------------------------------------------
137 //namespace
139 // ::rtl::OUString lcl_getControlName(const uno::Reference< lang::XServiceInfo >& _xServiceInfo)
140 // {
141 // if ( _xServiceInfo->supportsService( SERVICE_FIXEDTEXT ))
142 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText"));
143 // if ( _xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD ))
144 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FormattedField"));
145 // if ( _xServiceInfo->supportsService( SERVICE_IMAGECONTROL))
146 // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.DatabaseImageControl"));
148 // return ::rtl::OUString();
149 // }
151 //----------------------------------------------------------------------------
152 void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
154 DBG_CHKTHIS( rpt_OReportPage,NULL);
155 OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
156 if ( !_xObject.is() ) // || !m_pView )
157 return;
158 ULONG nPos = getIndexOf(_xObject);
159 if ( nPos < GetObjCount() )
160 return; // Object already in list
162 SvxShape* pShape = SvxShape::getImplementation( _xObject );
163 OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL;
164 OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
165 if ( pObject )
166 pObject->StartListening();
168 // -----------------------------------------------------------------------------
169 uno::Reference< report::XSection > OReportPage::getSection() const
171 return m_xSection;
173 // -----------------------------------------------------------------------------
174 uno::Reference< uno::XInterface > OReportPage::createUnoPage()
176 return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
178 // -----------------------------------------------------------------------------
179 void OReportPage::removeTempObject(SdrObject *_pToRemoveObj)
181 if (_pToRemoveObj)
183 for (ULONG i=0;i<GetObjCount();i++)
185 SdrObject *aObj = GetObj(i);
186 if (aObj && aObj == _pToRemoveObj)
188 SdrObject* pObject = RemoveObject(i);
189 (void)pObject;
190 break;
191 // delete pObject;
197 void OReportPage::resetSpecialMode()
199 const sal_Bool bChanged = rModel.IsChanged();
200 ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin();
201 ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end();
203 for (; aIter != aEnd; ++aIter)
205 removeTempObject(*aIter);
207 m_aTemporaryObjectList.clear();
208 rModel.SetChanged(bChanged);
210 m_bSpecialInsertMode = false;
212 // -----------------------------------------------------------------------------
213 void OReportPage::NbcInsertObject(SdrObject* pObj, ULONG nPos, const SdrInsertReason* pReason)
215 SdrPage::NbcInsertObject(pObj, nPos, pReason);
217 OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
218 if (getSpecialMode())
220 m_aTemporaryObjectList.push_back(pObj);
221 return;
224 if ( pUnoObj )
226 pUnoObj->CreateMediator();
227 uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
228 if ( xChild.is() && !xChild->getParent().is() )
229 xChild->setParent(m_xSection);
232 // this code is evil, but what else shall I do
233 reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
234 uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
235 pSection->notifyElementAdded(xShape);
237 //// check if we are a shape
238 //uno::Reference<beans::XPropertySet> xProp(xShape,uno::UNO_QUERY);
239 //if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID"))) )
241 // // use MimeConfigurationHelper::GetStringClassIDRepresentation(MimeConfigurationHelper::GetSequenceClassID(SO3_SCH_OLE_EMBED_CLASSID_8))
242 // xProp->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID")),uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("12dcae26-281f-416f-a234-c3086127382e"))));
245 // now that the shape is inserted into its structures, we can allow the OObjectBase
246 // to release the reference to it
247 OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
248 OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
249 if ( pObjectBase )
250 pObjectBase->releaseUnoShape();
252 //============================================================================
253 } // rptui
254 //============================================================================