19e0e4191SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
39e0e4191SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
49e0e4191SAndrew Rist * or more contributor license agreements. See the NOTICE file
59e0e4191SAndrew Rist * distributed with this work for additional information
69e0e4191SAndrew Rist * regarding copyright ownership. The ASF licenses this file
79e0e4191SAndrew Rist * to you under the Apache License, Version 2.0 (the
89e0e4191SAndrew Rist * "License"); you may not use this file except in compliance
99e0e4191SAndrew Rist * with the License. You may obtain a copy of the License at
10cdf0e10cSrcweir *
119e0e4191SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir *
139e0e4191SAndrew Rist * Unless required by applicable law or agreed to in writing,
149e0e4191SAndrew Rist * software distributed under the License is distributed on an
159e0e4191SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
169e0e4191SAndrew Rist * KIND, either express or implied. See the License for the
179e0e4191SAndrew Rist * specific language governing permissions and limitations
189e0e4191SAndrew Rist * under the License.
19cdf0e10cSrcweir *
209e0e4191SAndrew Rist *************************************************************/
219e0e4191SAndrew Rist
229e0e4191SAndrew Rist
23*b63233d8Sdamjan #include "precompiled_reportdesign.hxx"
24cdf0e10cSrcweir #include "RptPage.hxx"
25cdf0e10cSrcweir #include "RptModel.hxx"
26cdf0e10cSrcweir #include "Section.hxx"
27cdf0e10cSrcweir #include "RptObject.hxx"
28cdf0e10cSrcweir #include <svx/unoapi.hxx>
29cdf0e10cSrcweir #include <svx/unoshape.hxx>
30cdf0e10cSrcweir #include "ReportDrawPage.hxx"
31cdf0e10cSrcweir
32cdf0e10cSrcweir namespace rptui
33cdf0e10cSrcweir {
34cdf0e10cSrcweir using namespace ::com::sun::star;
35cdf0e10cSrcweir TYPEINIT1( OReportPage, SdrPage );
36cdf0e10cSrcweir
37cdf0e10cSrcweir //----------------------------------------------------------------------------
DBG_NAME(rpt_OReportPage)38cdf0e10cSrcweir DBG_NAME( rpt_OReportPage )
39cdf0e10cSrcweir OReportPage::OReportPage( OReportModel& _rModel
40cdf0e10cSrcweir ,const uno::Reference< report::XSection >& _xSection
41cdf0e10cSrcweir ,FASTBOOL bMasterPage )
42cdf0e10cSrcweir :SdrPage( _rModel, bMasterPage )
43cdf0e10cSrcweir ,rModel(_rModel)
44cdf0e10cSrcweir ,m_xSection(_xSection)
45cdf0e10cSrcweir ,m_bSpecialInsertMode(false)
46cdf0e10cSrcweir {
47cdf0e10cSrcweir DBG_CTOR( rpt_OReportPage,NULL);
48cdf0e10cSrcweir }
49cdf0e10cSrcweir
50cdf0e10cSrcweir //----------------------------------------------------------------------------
51cdf0e10cSrcweir
OReportPage(const OReportPage & rPage)52cdf0e10cSrcweir OReportPage::OReportPage( const OReportPage& rPage )
53cdf0e10cSrcweir :SdrPage( rPage )
54cdf0e10cSrcweir ,rModel(rPage.rModel)
55cdf0e10cSrcweir ,m_xSection(rPage.m_xSection)
56cdf0e10cSrcweir ,m_bSpecialInsertMode(rPage.m_bSpecialInsertMode)
57cdf0e10cSrcweir ,m_aTemporaryObjectList(rPage.m_aTemporaryObjectList)
58cdf0e10cSrcweir {
59cdf0e10cSrcweir DBG_CTOR( rpt_OReportPage,NULL);
60cdf0e10cSrcweir }
61cdf0e10cSrcweir
62cdf0e10cSrcweir //----------------------------------------------------------------------------
63cdf0e10cSrcweir
~OReportPage()64cdf0e10cSrcweir OReportPage::~OReportPage()
65cdf0e10cSrcweir {
66cdf0e10cSrcweir DBG_DTOR( rpt_OReportPage,NULL);
67cdf0e10cSrcweir }
68cdf0e10cSrcweir
69cdf0e10cSrcweir //----------------------------------------------------------------------------
70cdf0e10cSrcweir
Clone() const71cdf0e10cSrcweir SdrPage* OReportPage::Clone() const
72cdf0e10cSrcweir {
73cdf0e10cSrcweir DBG_CHKTHIS( rpt_OReportPage,NULL);
74cdf0e10cSrcweir return new OReportPage( *this );
75cdf0e10cSrcweir }
76cdf0e10cSrcweir
77cdf0e10cSrcweir //----------------------------------------------------------------------------
getIndexOf(const uno::Reference<report::XReportComponent> & _xObject)78cdf0e10cSrcweir sal_uLong OReportPage::getIndexOf(const uno::Reference< report::XReportComponent >& _xObject)
79cdf0e10cSrcweir {
80cdf0e10cSrcweir DBG_CHKTHIS( rpt_OReportPage,NULL);
81cdf0e10cSrcweir sal_uLong nCount = GetObjCount();
82cdf0e10cSrcweir sal_uLong i = 0;
83cdf0e10cSrcweir for (; i < nCount; ++i)
84cdf0e10cSrcweir {
85cdf0e10cSrcweir OObjectBase* pObj = dynamic_cast<OObjectBase*>(GetObj(i));
86cdf0e10cSrcweir OSL_ENSURE(pObj,"Invalid object found!");
87cdf0e10cSrcweir if ( pObj && pObj->getReportComponent() == _xObject )
88cdf0e10cSrcweir {
89cdf0e10cSrcweir break;
90cdf0e10cSrcweir }
91cdf0e10cSrcweir } // for (; i < nCount; ++i)
92cdf0e10cSrcweir return i;
93cdf0e10cSrcweir }
94cdf0e10cSrcweir //----------------------------------------------------------------------------
removeSdrObject(const uno::Reference<report::XReportComponent> & _xObject)95cdf0e10cSrcweir void OReportPage::removeSdrObject(const uno::Reference< report::XReportComponent >& _xObject)
96cdf0e10cSrcweir {
97cdf0e10cSrcweir DBG_CHKTHIS( rpt_OReportPage,NULL);
98cdf0e10cSrcweir sal_uLong nPos = getIndexOf(_xObject);
99cdf0e10cSrcweir if ( nPos < GetObjCount() )
100cdf0e10cSrcweir {
101cdf0e10cSrcweir OObjectBase* pBase = dynamic_cast<OObjectBase*>(GetObj(nPos));
102cdf0e10cSrcweir OSL_ENSURE(pBase,"Why is this not a OObjectBase?");
103cdf0e10cSrcweir if ( pBase )
104cdf0e10cSrcweir pBase->EndListening();
105cdf0e10cSrcweir /*delete */RemoveObject(nPos);
106cdf0e10cSrcweir }
107cdf0e10cSrcweir }
108cdf0e10cSrcweir // -----------------------------------------------------------------------------
RemoveObject(sal_uLong nObjNum)109cdf0e10cSrcweir SdrObject* OReportPage::RemoveObject(sal_uLong nObjNum)
110cdf0e10cSrcweir {
111cdf0e10cSrcweir SdrObject* pObj = SdrPage::RemoveObject(nObjNum);
112cdf0e10cSrcweir if (getSpecialMode())
113cdf0e10cSrcweir {
114cdf0e10cSrcweir return pObj;
115cdf0e10cSrcweir }
116cdf0e10cSrcweir
117cdf0e10cSrcweir // this code is evil, but what else shall I do
118cdf0e10cSrcweir reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
119cdf0e10cSrcweir uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
120cdf0e10cSrcweir pSection->notifyElementRemoved(xShape);
121cdf0e10cSrcweir if (pObj->ISA(OUnoObject))
122cdf0e10cSrcweir {
123cdf0e10cSrcweir OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj);
124cdf0e10cSrcweir uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
125cdf0e10cSrcweir if ( xChild.is() )
126cdf0e10cSrcweir xChild->setParent(NULL);
127cdf0e10cSrcweir }
128cdf0e10cSrcweir return pObj;
129cdf0e10cSrcweir }
130cdf0e10cSrcweir //----------------------------------------------------------------------------
131cdf0e10cSrcweir //namespace
132cdf0e10cSrcweir //{
133cdf0e10cSrcweir // ::rtl::OUString lcl_getControlName(const uno::Reference< lang::XServiceInfo >& _xServiceInfo)
134cdf0e10cSrcweir // {
135cdf0e10cSrcweir // if ( _xServiceInfo->supportsService( SERVICE_FIXEDTEXT ))
136cdf0e10cSrcweir // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText"));
137cdf0e10cSrcweir // if ( _xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD ))
138cdf0e10cSrcweir // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FormattedField"));
139cdf0e10cSrcweir // if ( _xServiceInfo->supportsService( SERVICE_IMAGECONTROL))
140cdf0e10cSrcweir // return ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.DatabaseImageControl"));
141cdf0e10cSrcweir //
142cdf0e10cSrcweir // return ::rtl::OUString();
143cdf0e10cSrcweir // }
144cdf0e10cSrcweir //}
145cdf0e10cSrcweir //----------------------------------------------------------------------------
insertObject(const uno::Reference<report::XReportComponent> & _xObject)146cdf0e10cSrcweir void OReportPage::insertObject(const uno::Reference< report::XReportComponent >& _xObject)
147cdf0e10cSrcweir {
148cdf0e10cSrcweir DBG_CHKTHIS( rpt_OReportPage,NULL);
149cdf0e10cSrcweir OSL_ENSURE(_xObject.is(),"Object is not valid to create a SdrObject!");
150cdf0e10cSrcweir if ( !_xObject.is() ) // || !m_pView )
151cdf0e10cSrcweir return;
152cdf0e10cSrcweir sal_uLong nPos = getIndexOf(_xObject);
153cdf0e10cSrcweir if ( nPos < GetObjCount() )
154cdf0e10cSrcweir return; // Object already in list
155cdf0e10cSrcweir
156cdf0e10cSrcweir SvxShape* pShape = SvxShape::getImplementation( _xObject );
157cdf0e10cSrcweir OObjectBase* pObject = pShape ? dynamic_cast< OObjectBase* >( pShape->GetSdrObject() ) : NULL;
158cdf0e10cSrcweir OSL_ENSURE( pObject, "OReportPage::insertObject: no implementation object found for the given shape/component!" );
159cdf0e10cSrcweir if ( pObject )
160cdf0e10cSrcweir pObject->StartListening();
161cdf0e10cSrcweir }
162cdf0e10cSrcweir // -----------------------------------------------------------------------------
getSection() const163cdf0e10cSrcweir uno::Reference< report::XSection > OReportPage::getSection() const
164cdf0e10cSrcweir {
165cdf0e10cSrcweir return m_xSection;
166cdf0e10cSrcweir }
167cdf0e10cSrcweir // -----------------------------------------------------------------------------
createUnoPage()168cdf0e10cSrcweir uno::Reference< uno::XInterface > OReportPage::createUnoPage()
169cdf0e10cSrcweir {
170cdf0e10cSrcweir return static_cast<cppu::OWeakObject*>( new reportdesign::OReportDrawPage(this,m_xSection) );
171cdf0e10cSrcweir }
172cdf0e10cSrcweir // -----------------------------------------------------------------------------
removeTempObject(SdrObject * _pToRemoveObj)173cdf0e10cSrcweir void OReportPage::removeTempObject(SdrObject *_pToRemoveObj)
174cdf0e10cSrcweir {
175cdf0e10cSrcweir if (_pToRemoveObj)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir for (sal_uLong i=0;i<GetObjCount();i++)
178cdf0e10cSrcweir {
179cdf0e10cSrcweir SdrObject *aObj = GetObj(i);
180cdf0e10cSrcweir if (aObj && aObj == _pToRemoveObj)
181cdf0e10cSrcweir {
182cdf0e10cSrcweir SdrObject* pObject = RemoveObject(i);
183cdf0e10cSrcweir (void)pObject;
184cdf0e10cSrcweir break;
185cdf0e10cSrcweir // delete pObject;
186cdf0e10cSrcweir }
187cdf0e10cSrcweir }
188cdf0e10cSrcweir }
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
resetSpecialMode()191cdf0e10cSrcweir void OReportPage::resetSpecialMode()
192cdf0e10cSrcweir {
193cdf0e10cSrcweir const sal_Bool bChanged = rModel.IsChanged();
194cdf0e10cSrcweir ::std::vector<SdrObject*>::iterator aIter = m_aTemporaryObjectList.begin();
195cdf0e10cSrcweir ::std::vector<SdrObject*>::iterator aEnd = m_aTemporaryObjectList.end();
196cdf0e10cSrcweir
197cdf0e10cSrcweir for (; aIter != aEnd; ++aIter)
198cdf0e10cSrcweir {
199cdf0e10cSrcweir removeTempObject(*aIter);
200cdf0e10cSrcweir }
201cdf0e10cSrcweir m_aTemporaryObjectList.clear();
202cdf0e10cSrcweir rModel.SetChanged(bChanged);
203cdf0e10cSrcweir
204cdf0e10cSrcweir m_bSpecialInsertMode = false;
205cdf0e10cSrcweir }
206cdf0e10cSrcweir // -----------------------------------------------------------------------------
NbcInsertObject(SdrObject * pObj,sal_uLong nPos,const SdrInsertReason * pReason)207cdf0e10cSrcweir void OReportPage::NbcInsertObject(SdrObject* pObj, sal_uLong nPos, const SdrInsertReason* pReason)
208cdf0e10cSrcweir {
209cdf0e10cSrcweir SdrPage::NbcInsertObject(pObj, nPos, pReason);
210cdf0e10cSrcweir
211cdf0e10cSrcweir OUnoObject* pUnoObj = dynamic_cast< OUnoObject* >( pObj );
212cdf0e10cSrcweir if (getSpecialMode())
213cdf0e10cSrcweir {
214cdf0e10cSrcweir m_aTemporaryObjectList.push_back(pObj);
215cdf0e10cSrcweir return;
216cdf0e10cSrcweir }
217cdf0e10cSrcweir
218cdf0e10cSrcweir if ( pUnoObj )
219cdf0e10cSrcweir {
220cdf0e10cSrcweir pUnoObj->CreateMediator();
221cdf0e10cSrcweir uno::Reference< container::XChild> xChild(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
222cdf0e10cSrcweir if ( xChild.is() && !xChild->getParent().is() )
223cdf0e10cSrcweir xChild->setParent(m_xSection);
224cdf0e10cSrcweir }
225cdf0e10cSrcweir
226cdf0e10cSrcweir // this code is evil, but what else shall I do
227cdf0e10cSrcweir reportdesign::OSection* pSection = reportdesign::OSection::getImplementation(m_xSection);
228cdf0e10cSrcweir uno::Reference< drawing::XShape> xShape(pObj->getUnoShape(),uno::UNO_QUERY);
229cdf0e10cSrcweir pSection->notifyElementAdded(xShape);
230cdf0e10cSrcweir
231cdf0e10cSrcweir //// check if we are a shape
232cdf0e10cSrcweir //uno::Reference<beans::XPropertySet> xProp(xShape,uno::UNO_QUERY);
233cdf0e10cSrcweir //if ( xProp.is() && xProp->getPropertySetInfo()->hasPropertyByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID"))) )
234cdf0e10cSrcweir //{
235cdf0e10cSrcweir // // use MimeConfigurationHelper::GetStringClassIDRepresentation(MimeConfigurationHelper::GetSequenceClassID(SO3_SCH_OLE_EMBED_CLASSID_8))
236cdf0e10cSrcweir // xProp->setPropertyValue(rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CLSID")),uno::makeAny(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("12dcae26-281f-416f-a234-c3086127382e"))));
237cdf0e10cSrcweir //}
238cdf0e10cSrcweir
239cdf0e10cSrcweir // now that the shape is inserted into its structures, we can allow the OObjectBase
240cdf0e10cSrcweir // to release the reference to it
241cdf0e10cSrcweir OObjectBase* pObjectBase = dynamic_cast< OObjectBase* >( pObj );
242cdf0e10cSrcweir OSL_ENSURE( pObjectBase, "OReportPage::NbcInsertObject: what is being inserted here?" );
243cdf0e10cSrcweir if ( pObjectBase )
244cdf0e10cSrcweir pObjectBase->releaseUnoShape();
245cdf0e10cSrcweir }
246cdf0e10cSrcweir //============================================================================
247cdf0e10cSrcweir } // rptui
248cdf0e10cSrcweir //============================================================================
249