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