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