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