xref: /AOO41X/main/reportdesign/source/core/sdr/RptObject.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 "precompiled_reportdesign.hxx"
28 #include "RptObject.hxx"
29 #include <vector>
30 #include <algorithm>
31 
32 #include <RptDef.hxx>
33 #include <svx/unoshape.hxx>
34 #include "RptModel.hxx"
35 #include "RptObjectListener.hxx"
36 #include <toolkit/helper/vclunohelper.hxx>
37 #include <toolkit/helper/convert.hxx>
38 #include "RptPage.hxx"
39 #include "corestrings.hrc"
40 #include <dbaccess/dbsubcomponentcontroller.hxx>
41 #include "ModuleHelper.hxx"
42 
43 #include <RptResId.hrc>
44 #include <svx/xflclit.hxx>
45 #include <svx/xlnclit.hxx>
46 #include <svx/xlndsit.hxx>
47 #include <svx/xlineit0.hxx>
48 #include <svx/sderitm.hxx>
49 #include <svx/xlnwtit.hxx>
50 #include <svx/xlntrit.hxx>
51 #include <com/sun/star/style/XStyle.hpp>
52 #include <com/sun/star/awt/XTabControllerModel.hpp>
53 #include <com/sun/star/awt/XUnoControlContainer.hpp>
54 #include <com/sun/star/awt/XVclContainerPeer.hpp>
55 #include <com/sun/star/awt/XWindow.hpp>
56 #include <com/sun/star/awt/TextAlign.hpp>
57 #include <com/sun/star/beans/XPropertySet.hpp>
58 #include <com/sun/star/beans/PropertyAttribute.hpp>
59 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
60 #include <com/sun/star/container/XContainer.hpp>
61 #include <com/sun/star/lang/XServiceInfo.hpp>
62 #include <com/sun/star/report/XShape.hpp>
63 #include <com/sun/star/report/XFixedLine.hpp>
64 #include <com/sun/star/chart/ChartDataRowSource.hpp>
65 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
66 #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
67 #include <com/sun/star/chart2/XChartDocument.hpp>
68 #include <com/sun/star/style/VerticalAlignment.hpp>
69 #include <com/sun/star/style/ParagraphAdjust.hpp>
70 #include <com/sun/star/report/XFormattedField.hpp>
71 #include <comphelper/genericpropertyset.hxx>
72 #include <comphelper/processfactory.hxx>
73 #include <comphelper/property.hxx>
74 #include <tools/diagnose_ex.h>
75 #include "PropertyForward.hxx"
76 #include <connectivity/dbtools.hxx>
77 #include <connectivity/dbconversion.hxx>
78 #include "UndoActions.hxx"
79 #include "UndoEnv.hxx"
80 #include <algorithm>
81 #include <functional>
82 
83 namespace rptui
84 {
85 
86 using namespace ::com::sun::star;
87 using namespace uno;
88 using namespace beans;
89 using namespace reportdesign;
90 using namespace container;
91 using namespace script;
92 using namespace report;
93 //----------------------------------------------------------------------------
94 sal_uInt16 OObjectBase::getObjectType(const uno::Reference< report::XReportComponent>& _xComponent)
95 {
96 	uno::Reference< lang::XServiceInfo > xServiceInfo( _xComponent , uno::UNO_QUERY );
97     OSL_ENSURE(xServiceInfo.is(),"Who deletes the XServiceInfo interface!");
98     if ( xServiceInfo.is() )
99     {
100 	    if ( xServiceInfo->supportsService( SERVICE_FIXEDTEXT ))
101 		    return OBJ_DLG_FIXEDTEXT;
102         if ( xServiceInfo->supportsService( SERVICE_FIXEDLINE ))
103         {
104             uno::Reference< report::XFixedLine> xFixedLine(_xComponent,uno::UNO_QUERY);
105             return xFixedLine->getOrientation() ? OBJ_DLG_HFIXEDLINE : OBJ_DLG_VFIXEDLINE;
106         }
107 	    if ( xServiceInfo->supportsService( SERVICE_IMAGECONTROL))
108 		    return OBJ_DLG_IMAGECONTROL;
109 	    if ( xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD ))
110 		    return OBJ_DLG_FORMATTEDFIELD;
111         if ( xServiceInfo->supportsService( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.drawing.OLE2Shape")) ) )
112             return OBJ_OLE2;
113         if ( xServiceInfo->supportsService( SERVICE_SHAPE ))
114 		    return OBJ_CUSTOMSHAPE;
115         if ( xServiceInfo->supportsService( SERVICE_REPORTDEFINITION ) )
116             return OBJ_DLG_SUBREPORT;
117         return OBJ_OLE2;
118     }
119 	return 0;
120 }
121 // -----------------------------------------------------------------------------
122 SdrObject* OObjectBase::createObject(const uno::Reference< report::XReportComponent>& _xComponent)
123 {
124     SdrObject* pNewObj = NULL;
125     sal_uInt16 nType = OObjectBase::getObjectType(_xComponent);
126     switch( nType )
127 	{
128 		case OBJ_DLG_FIXEDTEXT:
129             {
130 			    OUnoObject* pUnoObj = new OUnoObject( _xComponent
131                                     ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText"))
132                                     ,OBJ_DLG_FIXEDTEXT);
133                 pNewObj = pUnoObj;
134 
135                 uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
136                 if ( xControlModel.is() )
137                     xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::makeAny(sal_True));
138             }
139 			break;
140 		case OBJ_DLG_IMAGECONTROL:
141 			pNewObj = new OUnoObject(_xComponent
142 									,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.DatabaseImageControl"))
143 								    ,OBJ_DLG_IMAGECONTROL);
144 			break;
145 		case OBJ_DLG_FORMATTEDFIELD:
146 			pNewObj = new OUnoObject( _xComponent
147 									,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FormattedField"))
148 									,OBJ_DLG_FORMATTEDFIELD);
149 			break;
150         case OBJ_DLG_HFIXEDLINE:
151         case OBJ_DLG_VFIXEDLINE:
152 			pNewObj = new OUnoObject( _xComponent
153 									,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.awt.UnoControlFixedLineModel"))
154 									,nType);
155 			break;
156         case OBJ_CUSTOMSHAPE:
157             pNewObj = OCustomShape::Create( _xComponent );
158             try
159             {
160                 sal_Bool bOpaque = sal_False;
161                 _xComponent->getPropertyValue(PROPERTY_OPAQUE) >>= bOpaque;
162                 pNewObj->SetLayer(bOpaque ? RPT_LAYER_FRONT : RPT_LAYER_BACK);
163             }
164             catch(const uno::Exception&)
165             {
166                 DBG_UNHANDLED_EXCEPTION();
167             }
168             break;
169         case OBJ_DLG_SUBREPORT:
170         case OBJ_OLE2:
171             pNewObj = OOle2Obj::Create( _xComponent,nType );
172             break;
173 		default:
174 			OSL_ENSURE(0,"Unknown object id");
175 			break;
176 	}
177 
178     ensureSdrObjectOwnership( _xComponent );
179 
180     return pNewObj;
181 }
182 // -----------------------------------------------------------------------------
183 namespace
184 {
185     class ParaAdjust : public AnyConverter
186     {
187     public:
188         virtual ::com::sun::star::uno::Any operator() (const ::rtl::OUString& _sPropertyName,const ::com::sun::star::uno::Any& lhs) const
189 	    {
190             uno::Any aRet;
191             if ( _sPropertyName.equalsAscii(PROPERTY_PARAADJUST) )
192             {
193                 sal_Int16 nTextAlign = 0;
194                 lhs >>= nTextAlign;
195                 switch(nTextAlign)
196                 {
197                     case awt::TextAlign::LEFT:
198                         nTextAlign = style::ParagraphAdjust_LEFT;
199                         break;
200                     case awt::TextAlign::CENTER:
201                         nTextAlign = style::ParagraphAdjust_CENTER;
202                         break;
203                     case awt::TextAlign::RIGHT:
204                         nTextAlign = style::ParagraphAdjust_RIGHT;
205                         break;
206                     default:
207                         OSL_ENSURE(0,"Illegal text alignment value!");
208                         break;
209                 } // switch(nTextAlign)
210                 aRet <<= (style::ParagraphAdjust)nTextAlign;
211             }
212             else
213             {
214                 sal_Int16 nTextAlign = 0;
215                 sal_Int16 eParagraphAdjust = 0;
216                 lhs >>= eParagraphAdjust;
217                 switch(eParagraphAdjust)
218                 {
219                     case style::ParagraphAdjust_LEFT:
220                     case style::ParagraphAdjust_BLOCK:
221                         nTextAlign = awt::TextAlign::LEFT;
222                         break;
223                     case style::ParagraphAdjust_CENTER:
224                         nTextAlign = awt::TextAlign::CENTER;
225                         break;
226                     case style::ParagraphAdjust_RIGHT:
227                         nTextAlign = awt::TextAlign::RIGHT;
228                         break;
229                     default:
230                         OSL_ENSURE(0,"Illegal text alignment value!");
231                         break;
232                 } // switch(eParagraphAdjust)
233                 aRet <<= nTextAlign;
234             }
235 		    return aRet;
236 	    }
237     };
238 }
239 // -----------------------------------------------------------------------------
240 const TPropertyNamePair& getPropertyNameMap(sal_uInt16 _nObjectId)
241 {
242 	switch(_nObjectId)
243 	{
244         case OBJ_DLG_IMAGECONTROL:
245             {
246 				static TPropertyNamePair s_aNameMap;
247 				if ( s_aNameMap.empty() )
248 				{
249                     ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
250 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
251                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
252                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
253                     //s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,PROPERTY_ALIGN));
254 				}
255 				return s_aNameMap;
256 			}
257 
258 		case OBJ_DLG_FIXEDTEXT:
259             {
260 				static TPropertyNamePair s_aNameMap;
261 				if ( s_aNameMap.empty() )
262 				{
263                     ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
264 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter)));
265 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
266 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter)));
267 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter)));
268                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter)));
269                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter)));
270                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter)));
271                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
272                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
273 
274                     ::boost::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust());
275                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust)));
276 				}
277 				return s_aNameMap;
278 			}
279         case OBJ_DLG_FORMATTEDFIELD:
280 			{
281 				static TPropertyNamePair s_aNameMap;
282 				if ( s_aNameMap.empty() )
283 				{
284                     ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
285 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter)));
286 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter)));
287 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter)));
288 					s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter)));
289                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter)));
290                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter)));
291                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter)));
292                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter)));
293                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter)));
294                     //s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aNoConverter)));
295                     ::boost::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust());
296                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust)));
297 				}
298 				return s_aNameMap;
299 			}
300 
301         case OBJ_CUSTOMSHAPE:
302             {
303 				static TPropertyNamePair s_aNameMap;
304 				if ( s_aNameMap.empty() )
305 				{
306                     ::boost::shared_ptr<AnyConverter> aNoConverter(new AnyConverter());
307                     s_aNameMap.insert(TPropertyNamePair::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")),TPropertyConverter(PROPERTY_CONTROLBACKGROUND,aNoConverter)));
308                     s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aNoConverter)));
309                 }
310 				return s_aNameMap;
311 			}
312 
313         default:
314             break;
315 	}
316 	static TPropertyNamePair s_aEmptyNameMap;
317 	return s_aEmptyNameMap;
318 }
319 // -----------------------------------------------------------------------------
320 
321 DBG_NAME( rpt_OObjectBase )
322 OObjectBase::OObjectBase(const uno::Reference< report::XReportComponent>& _xComponent)
323 :m_bIsListening(sal_False)
324 {
325 	DBG_CTOR( rpt_OObjectBase,NULL);
326 	m_xReportComponent = _xComponent;
327 }
328 //----------------------------------------------------------------------------
329 OObjectBase::OObjectBase(const ::rtl::OUString& _sComponentName)
330 :m_sComponentName(_sComponentName)
331 ,m_bIsListening(sal_False)
332 {
333 	DBG_CTOR( rpt_OObjectBase,NULL);
334 }
335 //----------------------------------------------------------------------------
336 OObjectBase::~OObjectBase()
337 {
338 	DBG_DTOR( rpt_OObjectBase,NULL);
339     m_xMediator.reset();
340 	if ( isListening() )
341 		EndListening();
342 	m_xReportComponent.clear();
343 }
344 // -----------------------------------------------------------------------------
345 uno::Reference< report::XSection> OObjectBase::getSection() const
346 {
347     uno::Reference< report::XSection> xSection;
348     OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
349 	if ( pPage )
350         xSection = pPage->getSection();
351     return xSection;
352 }
353 // -----------------------------------------------------------------------------
354 uno::Reference< report::XReportComponent> OObjectBase::getReportComponent() const
355 {
356 	return m_xReportComponent;
357 }
358 // -----------------------------------------------------------------------------
359 uno::Reference< beans::XPropertySet> OObjectBase::getAwtComponent()
360 {
361 	return uno::Reference< beans::XPropertySet>();
362 }
363 //----------------------------------------------------------------------------
364 void OObjectBase::StartListening()
365 {
366 	DBG_CHKTHIS( rpt_OObjectBase,NULL);
367 	OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
368 
369 	if ( !isListening() && m_xReportComponent.is() )
370 	{
371 		m_bIsListening = sal_True;
372 
373 		if ( !m_xPropertyChangeListener.is() )
374 		{
375 			m_xPropertyChangeListener = new OObjectListener( this );
376 			// register listener to all properties
377 			m_xReportComponent->addPropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
378 		}
379 	}
380 }
381 //----------------------------------------------------------------------------
382 void OObjectBase::EndListening(sal_Bool /*bRemoveListener*/)
383 {
384 	DBG_CHKTHIS( rpt_OObjectBase,NULL);
385 	OSL_ENSURE(!m_xReportComponent.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
386 
387     m_bIsListening = sal_False;
388 	if ( isListening() && m_xReportComponent.is() )
389 	{
390 		// XPropertyChangeListener
391 		if ( m_xPropertyChangeListener.is() )
392 		{
393 			// remove listener
394             try
395             {
396 			    m_xReportComponent->removePropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener );
397             }
398             catch(uno::Exception)
399             {
400                 OSL_ENSURE(0,"OObjectBase::EndListening: Exception caught!");
401             }
402 		}
403 		m_xPropertyChangeListener.clear();
404 	}
405 }
406 //----------------------------------------------------------------------------
407 void OObjectBase::SetPropsFromRect(const Rectangle& _rRect)
408 {
409 	DBG_CHKTHIS( rpt_OObjectBase,NULL);
410     // set properties
411 	OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
412     if ( pPage && !_rRect.IsEmpty() )
413     {
414 		uno::Reference<report::XSection> xSection = pPage->getSection();
415 		if ( xSection.is() && (static_cast<sal_uInt32>(_rRect.getHeight() + _rRect.Top()) > xSection->getHeight()) )
416 			xSection->setHeight(_rRect.getHeight() + _rRect.Top());
417 
418         // TODO
419 		//pModel->GetRefDevice()->Invalidate(INVALIDATE_CHILDREN);
420 	}
421 }
422 //----------------------------------------------------------------------------
423 void OObjectBase::_propertyChange( const  beans::PropertyChangeEvent& /*evt*/ ) throw( uno::RuntimeException)
424 {
425 	DBG_CHKTHIS( rpt_OObjectBase,NULL);
426 }
427 //----------------------------------------------------------------------------
428 void OObjectBase::SetObjectItemHelper(const SfxPoolItem& /*rItem*/)
429 {
430     // do nothing
431 }
432 
433 //----------------------------------------------------------------------------
434 sal_Bool OObjectBase::supportsService( const ::rtl::OUString& _sServiceName ) const
435 {
436 	DBG_CHKTHIS( rpt_OObjectBase,NULL);
437 	sal_Bool bSupports = sal_False;
438 
439 	Reference< lang::XServiceInfo > xServiceInfo( m_xReportComponent , UNO_QUERY );
440 		// TODO: cache xServiceInfo as member?
441 	if ( xServiceInfo.is() )
442 		bSupports = xServiceInfo->supportsService( _sServiceName );
443 
444 	return bSupports;
445 }
446 
447 //----------------------------------------------------------------------------
448 void OObjectBase::ensureSdrObjectOwnership( const uno::Reference< uno::XInterface >& _rxShape )
449 {
450     // UNDO in the report designer is implemented at the level of the XShapes, not
451     // at the level of SdrObjects. That is, if an object is removed from the report
452     // design, then this happens by removing the XShape from the UNO DrawPage, and
453     // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
454     // action.
455     // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
456     // which are removed from it, which is deadly for us. To prevent this,
457     // we give the XShape implementation the ownership of the SdrObject, which
458     // ensures the SvxDrawPage won't delete it.
459     SvxShape* pShape = SvxShape::getImplementation( _rxShape );
460     OSL_ENSURE( pShape, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
461     if ( pShape )
462     {
463         OSL_ENSURE( !pShape->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
464         pShape->TakeSdrObjectOwnership();
465     }
466 }
467 
468 //----------------------------------------------------------------------------
469 uno::Reference< uno::XInterface > OObjectBase::getUnoShapeOf( SdrObject& _rSdrObject )
470 {
471     uno::Reference< uno::XInterface > xShape( _rSdrObject.getWeakUnoShape() );
472     if ( xShape.is() )
473         return xShape;
474 
475     xShape = _rSdrObject.SdrObject::getUnoShape();
476     if ( !xShape.is() )
477         return xShape;
478 
479     ensureSdrObjectOwnership( xShape );
480 
481     m_xKeepShapeAlive = xShape;
482     return xShape;
483 }
484 
485 //----------------------------------------------------------------------------
486 TYPEINIT1(OCustomShape, SdrObjCustomShape);
487 DBG_NAME( rpt_OCustomShape );
488 OCustomShape::OCustomShape(const uno::Reference< report::XReportComponent>& _xComponent
489                            )
490 		  :SdrObjCustomShape()
491 		  ,OObjectBase(_xComponent)
492 {
493 	DBG_CTOR( rpt_OCustomShape, NULL);
494     impl_setUnoShape( uno::Reference< uno::XInterface >(_xComponent,uno::UNO_QUERY) );
495     m_bIsListening = sal_True;
496 }
497 //----------------------------------------------------------------------------
498 OCustomShape::OCustomShape(const ::rtl::OUString& _sComponentName)
499 		  :SdrObjCustomShape()
500 		  ,OObjectBase(_sComponentName)
501 {
502 	DBG_CTOR( rpt_OCustomShape, NULL);
503     m_bIsListening = sal_True;
504 }
505 
506 //----------------------------------------------------------------------------
507 OCustomShape::~OCustomShape()
508 {
509 	DBG_DTOR( rpt_OCustomShape, NULL);
510 }
511 // -----------------------------------------------------------------------------
512 sal_uInt16 OCustomShape::GetObjIdentifier() const
513 {
514 	return sal_uInt16(OBJ_CUSTOMSHAPE);
515 }
516 //----------------------------------------------------------------------------
517 sal_uInt32 OCustomShape::GetObjInventor() const
518 {
519 	return ReportInventor;
520 }
521 //----------------------------------------------------------------------------
522 SdrPage* OCustomShape::GetImplPage() const
523 {
524 	return GetPage();
525 }
526 //----------------------------------------------------------------------------
527 void OCustomShape::SetSnapRectImpl(const Rectangle& _rRect)
528 {
529 	SetSnapRect( _rRect );
530 }
531 //----------------------------------------------------------------------------
532 sal_Int32 OCustomShape::GetStep() const
533 {
534 	// get step property
535 	sal_Int32 nStep = 0;
536 	OSL_ENSURE(0,"Who called me!");
537 	return nStep;
538 }
539 //----------------------------------------------------------------------------
540 void OCustomShape::NbcMove( const Size& rSize )
541 {
542     if ( m_bIsListening )
543     {
544         m_bIsListening = sal_False;
545 
546         if ( m_xReportComponent.is() )
547         {
548             OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
549             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
550             m_xReportComponent->setPositionX(m_xReportComponent->getPositionX() + rSize.A());
551             m_xReportComponent->setPositionY(m_xReportComponent->getPositionY() + rSize.B());
552         }
553 
554 	    // set geometry properties
555 	    SetPropsFromRect(GetSnapRect());
556 
557 	    m_bIsListening = sal_True;
558     }
559     else
560 	    SdrObjCustomShape::NbcMove( rSize );
561 }
562 //----------------------------------------------------------------------------
563 void OCustomShape::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
564 {
565 	SdrObjCustomShape::NbcResize( rRef, xFract, yFract );
566 
567 	SetPropsFromRect(GetSnapRect());
568 }
569 //----------------------------------------------------------------------------
570 void OCustomShape::NbcSetLogicRect(const Rectangle& rRect)
571 {
572     SdrObjCustomShape::NbcSetLogicRect(rRect);
573 	SetPropsFromRect(rRect);
574 }
575 //----------------------------------------------------------------------------
576 FASTBOOL OCustomShape::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
577 {
578 	FASTBOOL bResult = SdrObjCustomShape::EndCreate(rStat, eCmd);
579     if ( bResult )
580     {
581         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
582         if ( pRptModel )
583         {
584             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
585             if ( !m_xReportComponent.is() )
586                 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
587         }
588         SetPropsFromRect(GetSnapRect());
589     }
590 
591 	return bResult;
592 }
593 
594 //----------------------------------------------------------------------------
595 void OCustomShape::SetObjectItemHelper(const SfxPoolItem& rItem)
596 {
597     SetObjectItem(rItem);
598     // TODO
599     //getSectionWindow()->getView()->AdjustMarkHdl();
600 }
601 
602 // -----------------------------------------------------------------------------
603 uno::Reference< beans::XPropertySet> OCustomShape::getAwtComponent()
604 {
605     return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
606 }
607 
608 //----------------------------------------------------------------------------
609 uno::Reference< uno::XInterface > OCustomShape::getUnoShape()
610 {
611     uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
612     if ( !m_xReportComponent.is() )
613     {
614         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
615         OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
616         m_xReportComponent.set(xShape,uno::UNO_QUERY);
617     }
618     return xShape;
619 }
620 
621 //----------------------------------------------------------------------------
622 //----------------------------------------------------------------------------
623 TYPEINIT1(OUnoObject, SdrUnoObj);
624 DBG_NAME( rpt_OUnoObject );
625 //----------------------------------------------------------------------------
626 OUnoObject::OUnoObject(const ::rtl::OUString& _sComponentName
627 					   ,const ::rtl::OUString& rModelName
628                        ,sal_uInt16   _nObjectType)
629 		  :SdrUnoObj(rModelName, sal_True)
630 		  ,OObjectBase(_sComponentName)
631           ,m_nObjectType(_nObjectType)
632 {
633 	DBG_CTOR( rpt_OUnoObject, NULL);
634     if ( rModelName.getLength() )
635         impl_initializeModel_nothrow();
636 }
637 //----------------------------------------------------------------------------
638 OUnoObject::OUnoObject(const uno::Reference< report::XReportComponent>& _xComponent
639 					   ,const ::rtl::OUString& rModelName
640                        ,sal_uInt16   _nObjectType)
641 		  :SdrUnoObj(rModelName, sal_True)
642 		  ,OObjectBase(_xComponent)
643           ,m_nObjectType(_nObjectType)
644 {
645 	DBG_CTOR( rpt_OUnoObject, NULL);
646     impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
647 
648     if ( rModelName.getLength() )
649         impl_initializeModel_nothrow();
650 
651     if ( rModelName.getLength() )
652         impl_initializeModel_nothrow();
653 }
654 //----------------------------------------------------------------------------
655 OUnoObject::~OUnoObject()
656 {
657 	DBG_DTOR( rpt_OUnoObject, NULL);
658 }
659 // -----------------------------------------------------------------------------
660 void OUnoObject::impl_initializeModel_nothrow()
661 {
662     try
663     {
664         Reference< XFormattedField > xFormatted( m_xReportComponent, UNO_QUERY );
665         if ( xFormatted.is() )
666         {
667             const Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY_THROW );
668             const ::rtl::OUString sTreatAsNumberProperty = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "TreatAsNumber" ) );
669             xModelProps->setPropertyValue( sTreatAsNumberProperty, makeAny( sal_False ) );
670             xModelProps->setPropertyValue( PROPERTY_VERTICALALIGN,m_xReportComponent->getPropertyValue(PROPERTY_VERTICALALIGN));
671         }
672     }
673     catch( const Exception& )
674     {
675     	DBG_UNHANDLED_EXCEPTION();
676     }
677 }
678 // -----------------------------------------------------------------------------
679 void OUnoObject::impl_setReportComponent_nothrow()
680 {
681     if ( m_xReportComponent.is() )
682         return;
683 
684     OReportModel* pReportModel = static_cast<OReportModel*>(GetModel());
685     OSL_ENSURE( pReportModel, "OUnoObject::impl_setReportComponent_nothrow: no report model!" );
686     if ( !pReportModel )
687         return;
688 
689     OXUndoEnvironment::OUndoEnvLock aLock( pReportModel->GetUndoEnv() );
690     m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
691 
692     impl_initializeModel_nothrow();
693 }
694 // -----------------------------------------------------------------------------
695 sal_uInt16 OUnoObject::GetObjIdentifier() const
696 {
697 	return sal_uInt16(m_nObjectType);
698 }
699 //----------------------------------------------------------------------------
700 sal_uInt32 OUnoObject::GetObjInventor() const
701 {
702 	return ReportInventor;
703 }
704 //----------------------------------------------------------------------------
705 SdrPage* OUnoObject::GetImplPage() const
706 {
707 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
708 	return GetPage();
709 }
710 //----------------------------------------------------------------------------
711 void OUnoObject::SetSnapRectImpl(const Rectangle& _rRect)
712 {
713 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
714 	SetSnapRect( _rRect );
715 }
716 //----------------------------------------------------------------------------
717 sal_Int32 OUnoObject::GetStep() const
718 {
719 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
720 	// get step property
721 	sal_Int32 nStep = 0;
722 	OSL_ENSURE(0,"Who called me!");
723 	return nStep;
724 }
725 
726 //----------------------------------------------------------------------------
727 void OUnoObject::NbcMove( const Size& rSize )
728 {
729 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
730 
731     if ( m_bIsListening )
732     {
733 	    // stop listening
734 	    OObjectBase::EndListening(sal_False);
735 
736         bool bPositionFixed = false;
737         Size aUndoSize(0,0);
738         bool bUndoMode = false;
739         if ( m_xReportComponent.is() )
740         {
741             OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
742             if (pRptModel->GetUndoEnv().IsUndoMode())
743             {
744                 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
745                 bUndoMode = true;
746             }
747             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
748 
749             // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
750             int nNewX = m_xReportComponent->getPositionX() + rSize.A();
751             // can this hinder us to set components outside the area?
752             // if (nNewX < 0)
753             // {
754             //     nNewX = 0;
755             // }
756             m_xReportComponent->setPositionX(nNewX);
757             int nNewY = m_xReportComponent->getPositionY() + rSize.B();
758             if (nNewY < 0 && !bUndoMode)
759             {
760                 aUndoSize.B() = abs(nNewY);
761                 bPositionFixed = true;
762                 nNewY = 0;
763             }
764             m_xReportComponent->setPositionY(nNewY);
765         }
766         if (bPositionFixed)
767         {
768             GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
769         }
770 	    // set geometry properties
771 	    SetPropsFromRect(GetLogicRect());
772 
773 	    // start listening
774 	    OObjectBase::StartListening();
775     }
776     else
777         SdrUnoObj::NbcMove( rSize );
778 }
779 
780 //----------------------------------------------------------------------------
781 
782 void OUnoObject::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
783 {
784 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
785 	SdrUnoObj::NbcResize( rRef, xFract, yFract );
786 
787 	// stop listening
788 	OObjectBase::EndListening(sal_False);
789 
790 	// set geometry properties
791 	SetPropsFromRect(GetLogicRect());
792 
793 	// start listening
794 	OObjectBase::StartListening();
795 }
796 //----------------------------------------------------------------------------
797 void OUnoObject::NbcSetLogicRect(const Rectangle& rRect)
798 {
799     SdrUnoObj::NbcSetLogicRect(rRect);
800     // stop listening
801 	OObjectBase::EndListening(sal_False);
802 
803 	// set geometry properties
804 	SetPropsFromRect(rRect);
805 
806 	// start listening
807 	OObjectBase::StartListening();
808 }
809 //----------------------------------------------------------------------------
810 
811 FASTBOOL OUnoObject::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
812 {
813 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
814 	FASTBOOL bResult = SdrUnoObj::EndCreate(rStat, eCmd);
815     if ( bResult )
816     {
817         impl_setReportComponent_nothrow();
818         // set labels
819         if ( m_xReportComponent.is() )
820         {
821             try
822             {
823                 if ( supportsService( SERVICE_FIXEDTEXT ) )
824                 {
825                     m_xReportComponent->setPropertyValue( PROPERTY_LABEL, uno::makeAny(GetDefaultName(this)) );
826                 }
827             }
828             catch(const uno::Exception&)
829             {
830                 DBG_UNHANDLED_EXCEPTION();
831             }
832 
833             impl_initializeModel_nothrow();
834         }
835         // set geometry properties
836         SetPropsFromRect(GetLogicRect());
837     }
838 
839 	return bResult;
840 }
841 //----------------------------------------------------------------------------
842 ::rtl::OUString OUnoObject::GetDefaultName(const OUnoObject* _pObj)
843 {
844 	sal_uInt16 nResId = 0;
845 	::rtl::OUString aDefaultName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HERE WE HAVE TO INSERT OUR NAME!"));
846     if ( _pObj->supportsService( SERVICE_FIXEDTEXT ) )
847 	{
848 		nResId = RID_STR_CLASS_FIXEDTEXT;
849 	}
850     else if ( _pObj->supportsService( SERVICE_FIXEDLINE ) )
851 	{
852 		nResId = RID_STR_CLASS_FIXEDLINE;
853 	}
854     else if ( _pObj->supportsService( SERVICE_IMAGECONTROL ) )
855 	{
856 		nResId = RID_STR_CLASS_IMAGECONTROL;
857 	}
858 	else if ( _pObj->supportsService( SERVICE_FORMATTEDFIELD ) )
859 	{
860 		nResId = RID_STR_CLASS_FORMATTEDFIELD;
861 	}
862 
863 	if (nResId)
864 		aDefaultName = ::rtl::OUString( String(ModuleRes(nResId)) );
865 
866 	return aDefaultName;
867 }
868 
869 // -----------------------------------------------------------------------------
870 void OUnoObject::_propertyChange( const  beans::PropertyChangeEvent& evt ) throw( uno::RuntimeException)
871 {
872 	DBG_CHKTHIS( rpt_OUnoObject,NULL);
873 	OObjectBase::_propertyChange(evt);
874 	if (isListening())
875 	{
876         if ( evt.PropertyName == PROPERTY_CHARCOLOR )
877         {
878 			Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
879 			if ( xControlModel.is() )
880             {
881                 OObjectBase::EndListening(sal_False);
882 				try
883 				{
884 					xControlModel->setPropertyValue(PROPERTY_TEXTCOLOR,evt.NewValue);
885 				}
886 				catch(uno::Exception&)
887 				{
888 				}
889                 OObjectBase::StartListening();
890             }
891 		}
892         else if ( evt.PropertyName == PROPERTY_NAME )
893 		{
894             Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
895             if ( xControlModel.is() && xControlModel->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) )
896             {
897                 // get old name
898 	            ::rtl::OUString aOldName;
899 	            evt.OldValue >>= aOldName;
900 
901 	            // get new name
902 	            ::rtl::OUString aNewName;
903 	            evt.NewValue >>= aNewName;
904 
905 	            if ( !aNewName.equals(aOldName) )
906 	            {
907 		            // set old name property
908 		            OObjectBase::EndListening(sal_False);
909                     if ( m_xMediator.is() )
910                         m_xMediator.get()->stopListening();
911                     try
912                     {
913                         xControlModel->setPropertyValue( PROPERTY_NAME, evt.NewValue );
914                     }
915                     catch(uno::Exception&)
916                     {
917                     }
918                     if ( m_xMediator.is() )
919                         m_xMediator.get()->startListening();
920 		            OObjectBase::StartListening();
921 	            }
922             }
923 		}
924 	}
925 }
926 // -----------------------------------------------------------------------------
927 void OUnoObject::CreateMediator(sal_Bool _bReverse)
928 {
929     if ( !m_xMediator.is() )
930     {
931         impl_setReportComponent_nothrow();
932 
933 	    Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
934 	    if ( !m_xMediator.is() && m_xReportComponent.is() && xControlModel.is() )
935             m_xMediator = TMediator::createFromQuery(new OPropertyMediator(m_xReportComponent.get(),xControlModel,getPropertyNameMap(GetObjIdentifier()),_bReverse));
936         OObjectBase::StartListening();
937     }
938 }
939 // -----------------------------------------------------------------------------
940 uno::Reference< beans::XPropertySet> OUnoObject::getAwtComponent()
941 {
942     return Reference<XPropertySet>(GetUnoControlModel(),uno::UNO_QUERY);
943 }
944 
945 // -----------------------------------------------------------------------------
946 uno::Reference< uno::XInterface > OUnoObject::getUnoShape()
947 {
948     return OObjectBase::getUnoShapeOf( *this );
949 }
950 // -----------------------------------------------------------------------------
951 SdrObject* OUnoObject::Clone() const
952 {
953     SdrObject* pClone = SdrUnoObj::Clone();
954     if ( pClone )
955     {
956         Reference<XPropertySet> xSource(const_cast<OUnoObject*>(this)->getUnoShape(),uno::UNO_QUERY);
957         Reference<XPropertySet> xDest(pClone->getUnoShape(),uno::UNO_QUERY);
958         if ( xSource.is() && xDest.is() )
959             comphelper::copyProperties(xSource.get(),xDest.get());
960     } // if ( pClone )
961     return pClone;
962 }
963 //----------------------------------------------------------------------------
964 // OOle2Obj
965 //----------------------------------------------------------------------------
966 TYPEINIT1(OOle2Obj, SdrOle2Obj);
967 DBG_NAME( rpt_OOle2Obj );
968 OOle2Obj::OOle2Obj(const uno::Reference< report::XReportComponent>& _xComponent,sal_uInt16 _nType)
969 		  :SdrOle2Obj()
970 		  ,OObjectBase(_xComponent)
971           ,m_nType(_nType)
972           ,m_bOnlyOnce(true)
973 {
974 	DBG_CTOR( rpt_OOle2Obj, NULL);
975 
976     impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
977     m_bIsListening = sal_True;
978 }
979 //----------------------------------------------------------------------------
980 OOle2Obj::OOle2Obj(const ::rtl::OUString& _sComponentName,sal_uInt16 _nType)
981 		  :SdrOle2Obj()
982 		  ,OObjectBase(_sComponentName)
983           ,m_nType(_nType)
984           ,m_bOnlyOnce(true)
985 {
986 	DBG_CTOR( rpt_OOle2Obj, NULL);
987 	m_bIsListening = sal_True;
988 }
989 //----------------------------------------------------------------------------
990 OOle2Obj::~OOle2Obj()
991 {
992 	DBG_DTOR( rpt_OOle2Obj, NULL);
993 }
994 // -----------------------------------------------------------------------------
995 sal_uInt16 OOle2Obj::GetObjIdentifier() const
996 {
997 	return m_nType;
998 }
999 //----------------------------------------------------------------------------
1000 sal_uInt32 OOle2Obj::GetObjInventor() const
1001 {
1002 	return ReportInventor;
1003 }
1004 //----------------------------------------------------------------------------
1005 SdrPage* OOle2Obj::GetImplPage() const
1006 {
1007 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1008 	return GetPage();
1009 }
1010 //----------------------------------------------------------------------------
1011 void OOle2Obj::SetSnapRectImpl(const Rectangle& _rRect)
1012 {
1013 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1014 	SetSnapRect( _rRect );
1015 }
1016 //----------------------------------------------------------------------------
1017 sal_Int32 OOle2Obj::GetStep() const
1018 {
1019 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1020 	// get step property
1021 	sal_Int32 nStep = 0;
1022 	OSL_ENSURE(0,"Who called me!");
1023 	return nStep;
1024 }
1025 
1026 //----------------------------------------------------------------------------
1027 void OOle2Obj::NbcMove( const Size& rSize )
1028 {
1029 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1030 
1031     if ( m_bIsListening )
1032     {
1033 	    // stop listening
1034 	    OObjectBase::EndListening(sal_False);
1035 
1036         bool bPositionFixed = false;
1037         Size aUndoSize(0,0);
1038         bool bUndoMode = false;
1039         if ( m_xReportComponent.is() )
1040         {
1041             OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1042             if (pRptModel->GetUndoEnv().IsUndoMode())
1043             {
1044                 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
1045                 bUndoMode = true;
1046             }
1047             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1048 
1049             // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
1050             int nNewX = m_xReportComponent->getPositionX() + rSize.A();
1051             // can this hinder us to set components outside the area?
1052             // if (nNewX < 0)
1053             // {
1054             //     nNewX = 0;
1055             // }
1056             m_xReportComponent->setPositionX(nNewX);
1057             int nNewY = m_xReportComponent->getPositionY() + rSize.B();
1058             if (nNewY < 0 && !bUndoMode)
1059             {
1060                 aUndoSize.B() = abs(nNewY);
1061                 bPositionFixed = true;
1062                 nNewY = 0;
1063             }
1064             m_xReportComponent->setPositionY(nNewY);
1065         }
1066         if (bPositionFixed)
1067         {
1068             GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
1069         }
1070 	    // set geometry properties
1071 	    SetPropsFromRect(GetLogicRect());
1072 
1073 	    // start listening
1074 	    OObjectBase::StartListening();
1075     }
1076     else
1077         SdrOle2Obj::NbcMove( rSize );
1078 }
1079 
1080 //----------------------------------------------------------------------------
1081 
1082 void OOle2Obj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1083 {
1084 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1085 	SdrOle2Obj::NbcResize( rRef, xFract, yFract );
1086 
1087 	// stop listening
1088 	OObjectBase::EndListening(sal_False);
1089 
1090 	// set geometry properties
1091 	SetPropsFromRect(GetLogicRect());
1092 
1093 	// start listening
1094 	OObjectBase::StartListening();
1095 }
1096 //----------------------------------------------------------------------------
1097 void OOle2Obj::NbcSetLogicRect(const Rectangle& rRect)
1098 {
1099     SdrOle2Obj::NbcSetLogicRect(rRect);
1100     // stop listening
1101 	OObjectBase::EndListening(sal_False);
1102 
1103 	// set geometry properties
1104 	SetPropsFromRect(rRect);
1105 
1106 	// start listening
1107 	OObjectBase::StartListening();
1108 }
1109 //----------------------------------------------------------------------------
1110 
1111 FASTBOOL OOle2Obj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1112 {
1113 	DBG_CHKTHIS( rpt_OOle2Obj,NULL);
1114 	FASTBOOL bResult = SdrOle2Obj::EndCreate(rStat, eCmd);
1115     if ( bResult )
1116     {
1117         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1118         if ( pRptModel )
1119         {
1120             OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1121             if ( !m_xReportComponent.is() )
1122                 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
1123         }
1124         // set geometry properties
1125         SetPropsFromRect(GetLogicRect());
1126     }
1127 
1128 	return bResult;
1129 }
1130 
1131 uno::Reference< beans::XPropertySet> OOle2Obj::getAwtComponent()
1132 {
1133     return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
1134 }
1135 
1136 // -----------------------------------------------------------------------------
1137 uno::Reference< uno::XInterface > OOle2Obj::getUnoShape()
1138 {
1139     uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
1140     if ( !m_xReportComponent.is() )
1141     {
1142         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1143         OXUndoEnvironment::OUndoEnvLock aLock(pRptModel->GetUndoEnv());
1144         m_xReportComponent.set(xShape,uno::UNO_QUERY);
1145     }
1146     return xShape;
1147 }
1148 // -----------------------------------------------------------------------------
1149 uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const uno::Reference < embed::XEmbeddedObject >& _xObj)
1150 {
1151     uno::Reference< chart2::data::XDatabaseDataProvider > xSource;
1152     uno::Reference< embed::XComponentSupplier > xCompSupp(_xObj,uno::UNO_QUERY);
1153     if( xCompSupp.is())
1154     {
1155         uno::Reference< chart2::XChartDocument> xChartDoc( xCompSupp->getComponent(), uno::UNO_QUERY );
1156         if ( xChartDoc.is() )
1157         {
1158             xSource.set(xChartDoc->getDataProvider(),uno::UNO_QUERY);
1159         }
1160     } // if( xCompSupp.is())
1161     return xSource;
1162 }
1163 // -----------------------------------------------------------------------------
1164 // Clone() soll eine komplette Kopie des Objektes erzeugen.
1165 SdrObject* OOle2Obj::Clone() const
1166 {
1167     OOle2Obj* pObj = static_cast<OOle2Obj*>(SdrOle2Obj::Clone());
1168     OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1169     svt::EmbeddedObjectRef::TryRunningState( pObj->GetObjRef() );
1170     pObj->impl_createDataProvider_nothrow(pRptModel->getReportDefinition().get());
1171 
1172     uno::Reference< chart2::data::XDatabaseDataProvider > xSource( lcl_getDataProvider(GetObjRef()) );
1173     uno::Reference< chart2::data::XDatabaseDataProvider > xDest( lcl_getDataProvider(pObj->GetObjRef()) );
1174     if ( xSource.is() && xDest.is() )
1175         comphelper::copyProperties(xSource.get(),xDest.get());
1176 
1177     pObj->initializeChart(pRptModel->getReportDefinition().get());
1178     return pObj;
1179 }
1180 // -----------------------------------------------------------------------------
1181 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference< frame::XModel>& _xModel)
1182 {
1183     try
1184     {
1185         uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1186         uno::Reference< chart2::data::XDataReceiver > xReceiver;
1187         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1188         if( xCompSupp.is())
1189             xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1190         OSL_ASSERT( xReceiver.is());
1191         if( xReceiver.is() )
1192         {
1193             uno::Reference< lang::XMultiServiceFactory> xFac(_xModel,uno::UNO_QUERY);
1194             uno::Reference< chart2::data::XDatabaseDataProvider > xDataProvider( xFac->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider"))),uno::UNO_QUERY);
1195             xReceiver->attachDataProvider( xDataProvider.get() );
1196         } // if( xReceiver.is() )
1197     }
1198     catch(uno::Exception)
1199     {
1200     }
1201 }
1202 // -----------------------------------------------------------------------------
1203 void OOle2Obj::initializeOle()
1204 {
1205     if ( m_bOnlyOnce )
1206     {
1207         m_bOnlyOnce = false;
1208         uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1209         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1210         pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1211 
1212         uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1213         if( xCompSupp.is() )
1214         {
1215             uno::Reference< beans::XPropertySet > xChartProps( xCompSupp->getComponent(), uno::UNO_QUERY );
1216             if ( xChartProps.is() )
1217                 xChartProps->setPropertyValue(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NullDate")),uno::makeAny(util::DateTime(0,0,0,0,1,1,1900)));
1218         }
1219     }
1220 }
1221 // -----------------------------------------------------------------------------
1222 void OOle2Obj::initializeChart( const uno::Reference< frame::XModel>& _xModel)
1223 {
1224     uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1225     uno::Reference< chart2::data::XDataReceiver > xReceiver;
1226     uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1227     if( xCompSupp.is())
1228         xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1229     OSL_ASSERT( xReceiver.is());
1230     if( xReceiver.is() )
1231     {
1232         // lock the model to suppress any internal updates
1233         uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
1234         if( xChartModel.is() )
1235             xChartModel->lockControllers();
1236 
1237         if ( !lcl_getDataProvider(xObj).is() )
1238             impl_createDataProvider_nothrow(_xModel);
1239 
1240         OReportModel* pRptModel = static_cast<OReportModel*>(GetModel());
1241         pRptModel->GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1242 
1243         ::comphelper::NamedValueCollection aArgs;
1244         aArgs.put( "CellRangeRepresentation", uno::makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "all" ) ) ) );
1245         aArgs.put( "HasCategories", uno::makeAny( sal_True ) );
1246         aArgs.put( "FirstCellAsLabel", uno::makeAny( sal_True ) );
1247         aArgs.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS ) );
1248         xReceiver->setArguments( aArgs.getPropertyValues() );
1249 
1250         if( xChartModel.is() )
1251             xChartModel->unlockControllers();
1252     }
1253 }
1254 // -----------------------------------------------------------------------------
1255 uno::Reference< style::XStyle> getUsedStyle(const uno::Reference< report::XReportDefinition>& _xReport)
1256 {
1257     uno::Reference<container::XNameAccess> xStyles = _xReport->getStyleFamilies();
1258     uno::Reference<container::XNameAccess> xPageStyles(xStyles->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyles"))),uno::UNO_QUERY);
1259 
1260     uno::Reference< style::XStyle> xReturn;
1261     uno::Sequence< ::rtl::OUString> aSeq = xPageStyles->getElementNames();
1262     const ::rtl::OUString* pIter = aSeq.getConstArray();
1263     const ::rtl::OUString* pEnd	  = pIter + aSeq.getLength();
1264     for(;pIter != pEnd && !xReturn.is() ;++pIter)
1265     {
1266         uno::Reference< style::XStyle> xStyle(xPageStyles->getByName(*pIter),uno::UNO_QUERY);
1267         if ( xStyle->isInUse() )
1268             xReturn = xStyle;
1269     }
1270     return xReturn;
1271 }
1272 //----------------------------------------------------------------------------
1273 //============================================================================
1274 } // rptui
1275 //============================================================================
1276