1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: RptObject.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
30 #include "precompiled_reportdesign.hxx"
31 #include "RptObject.hxx"
36 #include <svx/unoshape.hxx>
37 #include "RptModel.hxx"
38 #include "RptObjectListener.hxx"
39 #include <toolkit/helper/vclunohelper.hxx>
40 #include <toolkit/helper/convert.hxx>
41 #include "RptPage.hxx"
42 #include "corestrings.hrc"
43 #include <dbaccess/singledoccontroller.hxx>
44 #include "ModuleHelper.hxx"
46 #include <RptResId.hrc>
47 #include <svx/xflclit.hxx>
48 #include <svx/xlnclit.hxx>
49 #include <svx/xlndsit.hxx>
50 #include <svx/xlineit0.hxx>
51 #include <svx/sderitm.hxx>
52 #include <svx/xlnwtit.hxx>
53 #include <svx/xlntrit.hxx>
54 #include <com/sun/star/style/XStyle.hpp>
55 #include <com/sun/star/awt/XTabControllerModel.hpp>
56 #include <com/sun/star/awt/XUnoControlContainer.hpp>
57 #include <com/sun/star/awt/XVclContainerPeer.hpp>
58 #include <com/sun/star/awt/XWindow.hpp>
59 #include <com/sun/star/beans/XPropertySet.hpp>
60 #include <com/sun/star/beans/PropertyAttribute.hpp>
61 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
62 #include <com/sun/star/container/XContainer.hpp>
63 #include <com/sun/star/lang/XServiceInfo.hpp>
64 #include <com/sun/star/report/XShape.hpp>
65 #include <com/sun/star/report/XFixedLine.hpp>
66 #include <com/sun/star/chart/ChartDataRowSource.hpp>
67 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
68 #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
69 #include <com/sun/star/chart2/XChartDocument.hpp>
70 #include <comphelper/genericpropertyset.hxx>
71 #include <comphelper/processfactory.hxx>
72 #include <comphelper/property.hxx>
73 #include "PropertyForward.hxx"
74 #include <connectivity/dbtools.hxx>
75 #include "UndoActions.hxx"
76 #include "UndoEnv.hxx"
83 using namespace ::com::sun::star
;
85 using namespace beans
;
86 using namespace reportdesign
;
87 using namespace container
;
88 using namespace script
;
89 //----------------------------------------------------------------------------
90 sal_uInt16
OObjectBase::getObjectType(const uno::Reference
< report::XReportComponent
>& _xComponent
)
92 uno::Reference
< lang::XServiceInfo
> xServiceInfo( _xComponent
, uno::UNO_QUERY
);
93 OSL_ENSURE(xServiceInfo
.is(),"Who deletes the XServiceInfo interface!");
94 if ( xServiceInfo
.is() )
96 if ( xServiceInfo
->supportsService( SERVICE_FIXEDTEXT
))
97 return OBJ_DLG_FIXEDTEXT
;
98 if ( xServiceInfo
->supportsService( SERVICE_FIXEDLINE
))
100 uno::Reference
< report::XFixedLine
> xFixedLine(_xComponent
,uno::UNO_QUERY
);
101 return xFixedLine
->getOrientation() ? OBJ_DLG_HFIXEDLINE
: OBJ_DLG_VFIXEDLINE
;
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")) ) )
109 if ( xServiceInfo
->supportsService( SERVICE_SHAPE
))
110 return OBJ_CUSTOMSHAPE
;
111 if ( xServiceInfo
->supportsService( SERVICE_REPORTDEFINITION
) )
112 return OBJ_DLG_SUBREPORT
;
117 // -----------------------------------------------------------------------------
118 SdrObject
* OObjectBase::createObject(const uno::Reference
< report::XReportComponent
>& _xComponent
)
120 SdrObject
* pNewObj
= NULL
;
121 sal_uInt16 nType
= OObjectBase::getObjectType(_xComponent
);
124 case OBJ_DLG_FIXEDTEXT
:
126 OUnoObject
* pUnoObj
= new OUnoObject( _xComponent
127 ,::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.form.component.FixedText"))
131 uno::Reference
<beans::XPropertySet
> xControlModel(pUnoObj
->GetUnoControlModel(),uno::UNO_QUERY
);
132 if ( xControlModel
.is() )
133 xControlModel
->setPropertyValue( PROPERTY_MULTILINE
,uno::makeAny(sal_True
));
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
);
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
);
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"))
152 case OBJ_CUSTOMSHAPE
:
153 pNewObj
= OCustomShape::Create( _xComponent
);
155 case OBJ_DLG_SUBREPORT
:
157 pNewObj
= OOle2Obj::Create( _xComponent
,nType
);
160 OSL_ENSURE(0,"Unknown object id");
164 ensureSdrObjectOwnership( _xComponent
);
168 // -----------------------------------------------------------------------------
169 const TPropertyNamePair
& getPropertyNameMap(sal_uInt16 _nObjectId
)
173 case OBJ_DLG_IMAGECONTROL
:
175 static TPropertyNamePair s_aNameMap
;
176 if ( s_aNameMap
.empty() )
178 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND
,PROPERTY_BACKGROUNDCOLOR
));
179 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER
,PROPERTY_BORDER
));
180 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR
,PROPERTY_BORDERCOLOR
));
181 //s_aNameMap.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST,PROPERTY_ALIGN));
186 case OBJ_DLG_FIXEDTEXT
:
187 case OBJ_DLG_FORMATTEDFIELD
:
189 static TPropertyNamePair s_aNameMap
;
190 if ( s_aNameMap
.empty() )
192 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR
,PROPERTY_TEXTCOLOR
));
193 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND
,PROPERTY_BACKGROUNDCOLOR
));
194 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR
,PROPERTY_TEXTLINECOLOR
));
195 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF
,PROPERTY_FONTRELIEF
));
196 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT
,PROPERTY_FONTHEIGHT
));
197 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT
,PROPERTY_FONTSTRIKEOUT
));
198 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK
,PROPERTY_FONTEMPHASISMARK
));
199 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER
,PROPERTY_BORDER
));
200 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR
,PROPERTY_BORDERCOLOR
));
201 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST
,PROPERTY_ALIGN
));
206 case OBJ_CUSTOMSHAPE
:
208 static TPropertyNamePair s_aNameMap
;
209 if ( s_aNameMap
.empty() )
211 s_aNameMap
.insert(TPropertyNamePair::value_type(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FillColor")),PROPERTY_CONTROLBACKGROUND
));
212 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST
,PROPERTY_ALIGN
));
220 static TPropertyNamePair s_aEmptyNameMap
;
221 return s_aEmptyNameMap
;
223 // -----------------------------------------------------------------------------
225 DBG_NAME( rpt_OObjectBase
)
226 OObjectBase::OObjectBase(const uno::Reference
< report::XReportComponent
>& _xComponent
)
227 :m_bIsListening(sal_False
)
229 DBG_CTOR( rpt_OObjectBase
,NULL
);
230 m_xReportComponent
= _xComponent
;
232 //----------------------------------------------------------------------------
233 OObjectBase::OObjectBase(const ::rtl::OUString
& _sComponentName
)
234 :m_sComponentName(_sComponentName
)
235 ,m_bIsListening(sal_False
)
237 DBG_CTOR( rpt_OObjectBase
,NULL
);
239 //----------------------------------------------------------------------------
240 OObjectBase::~OObjectBase()
242 DBG_DTOR( rpt_OObjectBase
,NULL
);
246 m_xReportComponent
.clear();
248 // -----------------------------------------------------------------------------
249 uno::Reference
< report::XSection
> OObjectBase::getSection() const
251 uno::Reference
< report::XSection
> xSection
;
252 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
254 xSection
= pPage
->getSection();
257 // -----------------------------------------------------------------------------
258 uno::Reference
< report::XReportComponent
> OObjectBase::getReportComponent() const
260 return m_xReportComponent
;
262 // -----------------------------------------------------------------------------
263 uno::Reference
< beans::XPropertySet
> OObjectBase::getAwtComponent()
265 return uno::Reference
< beans::XPropertySet
>();
267 // -----------------------------------------------------------------------------
268 sal_Bool
OObjectBase::IsInside(const Rectangle
& _rRect
,const Point
& rPnt
,USHORT nTol
) const
270 sal_Bool bRet
= sal_False
;
271 Rectangle
aRect( _rRect
);
272 if ( !aRect
.IsEmpty() )
274 aRect
.Left() -= nTol
;
276 aRect
.Right() = ( aRect
.Right() == RECT_EMPTY
? _rRect
.Left() + nTol
: aRect
.Right() + nTol
);
277 aRect
.Bottom() = ( aRect
.Bottom() == RECT_EMPTY
? _rRect
.Top() + nTol
: aRect
.Bottom() + nTol
);
279 bRet
= aRect
.IsInside( rPnt
);
283 //----------------------------------------------------------------------------
284 void OObjectBase::StartListening()
286 DBG_CHKTHIS( rpt_OObjectBase
,NULL
);
287 OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
289 if ( !isListening() && m_xReportComponent
.is() )
291 m_bIsListening
= sal_True
;
293 if ( !m_xPropertyChangeListener
.is() )
295 m_xPropertyChangeListener
= new OObjectListener( this );
296 // register listener to all properties
297 m_xReportComponent
->addPropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener
);
301 //----------------------------------------------------------------------------
302 void OObjectBase::EndListening(sal_Bool
/*bRemoveListener*/)
304 DBG_CHKTHIS( rpt_OObjectBase
,NULL
);
305 OSL_ENSURE(!m_xReportComponent
.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
307 m_bIsListening
= sal_False
;
308 if ( isListening() && m_xReportComponent
.is() )
310 // XPropertyChangeListener
311 if ( m_xPropertyChangeListener
.is() )
316 m_xReportComponent
->removePropertyChangeListener( ::rtl::OUString() , m_xPropertyChangeListener
);
318 catch(uno::Exception
)
320 OSL_ENSURE(0,"OObjectBase::EndListening: Exception caught!");
323 m_xPropertyChangeListener
.clear();
326 //----------------------------------------------------------------------------
327 void OObjectBase::SetPropsFromRect(const Rectangle
& _rRect
)
329 DBG_CHKTHIS( rpt_OObjectBase
,NULL
);
331 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
332 if ( pPage
&& !_rRect
.IsEmpty() )
334 uno::Reference
<report::XSection
> xSection
= pPage
->getSection();
335 if ( xSection
.is() && (static_cast<sal_uInt32
>(_rRect
.getHeight() + _rRect
.Top()) > xSection
->getHeight()) )
336 xSection
->setHeight(_rRect
.getHeight() + _rRect
.Top());
339 //pModel->GetRefDevice()->Invalidate(INVALIDATE_CHILDREN);
342 //----------------------------------------------------------------------------
343 void OObjectBase::_propertyChange( const beans::PropertyChangeEvent
& /*evt*/ ) throw( uno::RuntimeException
)
345 DBG_CHKTHIS( rpt_OObjectBase
,NULL
);
347 //----------------------------------------------------------------------------
348 void OObjectBase::SetObjectItemHelper(const SfxPoolItem
& /*rItem*/)
353 //----------------------------------------------------------------------------
354 sal_Bool
OObjectBase::supportsService( const ::rtl::OUString
& _sServiceName
) const
356 DBG_CHKTHIS( rpt_OObjectBase
,NULL
);
357 sal_Bool bSupports
= sal_False
;
359 Reference
< lang::XServiceInfo
> xServiceInfo( m_xReportComponent
, UNO_QUERY
);
360 // TODO: cache xServiceInfo as member?
361 if ( xServiceInfo
.is() )
362 bSupports
= xServiceInfo
->supportsService( _sServiceName
);
367 //----------------------------------------------------------------------------
368 void OObjectBase::ensureSdrObjectOwnership( const uno::Reference
< uno::XInterface
>& _rxShape
)
370 // UNDO in the report designer is implemented at the level of the XShapes, not
371 // at the level of SdrObjects. That is, if an object is removed from the report
372 // design, then this happens by removing the XShape from the UNO DrawPage, and
373 // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
375 // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
376 // which are removed from it, which is deadly for us. To prevent this,
377 // we give the XShape implementation the ownership of the SdrObject, which
378 // ensures the SvxDrawPage won't delete it.
379 SvxShape
* pShape
= SvxShape::getImplementation( _rxShape
);
380 OSL_ENSURE( pShape
, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
383 OSL_ENSURE( !pShape
->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
384 pShape
->TakeSdrObjectOwnership();
388 //----------------------------------------------------------------------------
389 uno::Reference
< uno::XInterface
> OObjectBase::getUnoShapeOf( SdrObject
& _rSdrObject
)
391 uno::Reference
< uno::XInterface
> xShape( _rSdrObject
.getWeakUnoShape() );
395 xShape
= _rSdrObject
.SdrObject::getUnoShape();
399 ensureSdrObjectOwnership( xShape
);
401 m_xKeepShapeAlive
= xShape
;
405 //----------------------------------------------------------------------------
406 TYPEINIT1(OCustomShape
, SdrObjCustomShape
);
407 DBG_NAME( rpt_OCustomShape
);
408 OCustomShape::OCustomShape(const uno::Reference
< report::XReportComponent
>& _xComponent
411 ,OObjectBase(_xComponent
)
413 DBG_CTOR( rpt_OCustomShape
, NULL
);
415 mxUnoShape
= uno::Reference
< uno::XInterface
>(_xComponent
,uno::UNO_QUERY
);
416 m_bIsListening
= sal_True
;
418 //----------------------------------------------------------------------------
419 OCustomShape::OCustomShape(const ::rtl::OUString
& _sComponentName
)
421 ,OObjectBase(_sComponentName
)
423 DBG_CTOR( rpt_OCustomShape
, NULL
);
424 m_bIsListening
= sal_True
;
427 //----------------------------------------------------------------------------
428 OCustomShape::~OCustomShape()
430 DBG_DTOR( rpt_OCustomShape
, NULL
);
431 //mxUnoShape = uno::WeakReference< uno::XInterface >();
433 // -----------------------------------------------------------------------------
434 UINT16
OCustomShape::GetObjIdentifier() const
436 return UINT16(OBJ_CUSTOMSHAPE
);
438 //----------------------------------------------------------------------------
439 UINT32
OCustomShape::GetObjInventor() const
441 return ReportInventor
;
443 //----------------------------------------------------------------------------
444 SdrPage
* OCustomShape::GetImplPage() const
448 //----------------------------------------------------------------------------
449 void OCustomShape::SetSnapRectImpl(const Rectangle
& _rRect
)
451 SetSnapRect( _rRect
);
453 //----------------------------------------------------------------------------
454 sal_Int32
OCustomShape::GetStep() const
458 OSL_ENSURE(0,"Who called me!");
461 //----------------------------------------------------------------------------
462 void OCustomShape::NbcMove( const Size
& rSize
)
464 if ( m_bIsListening
)
466 m_bIsListening
= sal_False
;
468 if ( m_xReportComponent
.is() )
470 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
471 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
472 m_xReportComponent
->setPositionX(m_xReportComponent
->getPositionX() + rSize
.A());
473 m_xReportComponent
->setPositionY(m_xReportComponent
->getPositionY() + rSize
.B());
476 // set geometry properties
477 SetPropsFromRect(GetSnapRect());
479 m_bIsListening
= sal_True
;
482 SdrObjCustomShape::NbcMove( rSize
);
484 //----------------------------------------------------------------------------
485 void OCustomShape::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
487 SdrObjCustomShape::NbcResize( rRef
, xFract
, yFract
);
489 SetPropsFromRect(GetSnapRect());
491 //----------------------------------------------------------------------------
492 void OCustomShape::NbcSetLogicRect(const Rectangle
& rRect
)
494 SdrObjCustomShape::NbcSetLogicRect(rRect
);
495 SetPropsFromRect(rRect
);
497 //----------------------------------------------------------------------------
498 FASTBOOL
OCustomShape::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
500 FASTBOOL bResult
= SdrObjCustomShape::EndCreate(rStat
, eCmd
);
503 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
506 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
507 if ( !m_xReportComponent
.is() )
508 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
510 SetPropsFromRect(GetSnapRect());
515 //----------------------------------------------------------------------------
516 SdrObject
* OCustomShape::CheckHit( const Point
& rPnt
, USHORT nTol
,const SetOfByte
* pSet
) const
518 // #109994# fixed here, because the drawing layer doesn't handle objects
519 // with a width or height of 0 in a proper way
520 if ( IsInside(aOutRect
,rPnt
,nTol
) )
521 return const_cast<OCustomShape
*>(this);
523 return SdrObjCustomShape::CheckHit( rPnt
, nTol
, pSet
);
526 //----------------------------------------------------------------------------
527 void OCustomShape::SetObjectItemHelper(const SfxPoolItem
& rItem
)
529 SetObjectItem(rItem
);
531 //getSectionWindow()->getView()->AdjustMarkHdl();
534 // -----------------------------------------------------------------------------
535 uno::Reference
< beans::XPropertySet
> OCustomShape::getAwtComponent()
537 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
540 //----------------------------------------------------------------------------
541 uno::Reference
< uno::XInterface
> OCustomShape::getUnoShape()
543 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
544 if ( !m_xReportComponent
.is() )
546 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
547 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
548 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
553 //----------------------------------------------------------------------------
554 //----------------------------------------------------------------------------
555 TYPEINIT1(OUnoObject
, SdrUnoObj
);
556 DBG_NAME( rpt_OUnoObject
);
557 //----------------------------------------------------------------------------
558 OUnoObject::OUnoObject(const ::rtl::OUString
& _sComponentName
559 ,const ::rtl::OUString
& rModelName
560 ,sal_uInt16 _nObjectType
)
561 :SdrUnoObj(rModelName
, sal_True
)
562 ,OObjectBase(_sComponentName
)
563 ,m_nObjectType(_nObjectType
)
565 DBG_CTOR( rpt_OUnoObject
, NULL
);
567 //----------------------------------------------------------------------------
568 OUnoObject::OUnoObject(const uno::Reference
< report::XReportComponent
>& _xComponent
569 ,const ::rtl::OUString
& rModelName
570 ,sal_uInt16 _nObjectType
)
571 :SdrUnoObj(rModelName
, sal_True
)
572 ,OObjectBase(_xComponent
)
573 ,m_nObjectType(_nObjectType
)
575 DBG_CTOR( rpt_OUnoObject
, NULL
);
576 mxUnoShape
= uno::Reference
< uno::XInterface
>(_xComponent
,uno::UNO_QUERY
);
578 //----------------------------------------------------------------------------
579 OUnoObject::~OUnoObject()
581 DBG_DTOR( rpt_OUnoObject
, NULL
);
582 //mxUnoShape = uno::WeakReference< uno::XInterface >();
584 // -----------------------------------------------------------------------------
585 UINT16
OUnoObject::GetObjIdentifier() const
587 return UINT16(m_nObjectType
);
589 //----------------------------------------------------------------------------
590 UINT32
OUnoObject::GetObjInventor() const
592 return ReportInventor
;
594 //----------------------------------------------------------------------------
595 SdrPage
* OUnoObject::GetImplPage() const
597 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
600 //----------------------------------------------------------------------------
601 void OUnoObject::SetSnapRectImpl(const Rectangle
& _rRect
)
603 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
604 SetSnapRect( _rRect
);
606 //----------------------------------------------------------------------------
607 sal_Int32
OUnoObject::GetStep() const
609 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
612 OSL_ENSURE(0,"Who called me!");
616 //----------------------------------------------------------------------------
617 void OUnoObject::NbcMove( const Size
& rSize
)
619 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
621 if ( m_bIsListening
)
624 OObjectBase::EndListening(sal_False
);
626 if ( m_xReportComponent
.is() )
628 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
629 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
630 m_xReportComponent
->setPositionX(m_xReportComponent
->getPositionX() + rSize
.A());
631 m_xReportComponent
->setPositionY(m_xReportComponent
->getPositionY() + rSize
.B());
634 // set geometry properties
635 SetPropsFromRect(GetLogicRect());
638 OObjectBase::StartListening();
641 SdrUnoObj::NbcMove( rSize
);
644 //----------------------------------------------------------------------------
646 void OUnoObject::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
648 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
649 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
652 OObjectBase::EndListening(sal_False
);
654 // set geometry properties
655 SetPropsFromRect(GetLogicRect());
658 OObjectBase::StartListening();
660 //----------------------------------------------------------------------------
661 void OUnoObject::NbcSetLogicRect(const Rectangle
& rRect
)
663 SdrUnoObj::NbcSetLogicRect(rRect
);
665 OObjectBase::EndListening(sal_False
);
667 // set geometry properties
668 SetPropsFromRect(rRect
);
671 OObjectBase::StartListening();
673 //----------------------------------------------------------------------------
675 FASTBOOL
OUnoObject::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
677 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
678 FASTBOOL bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
681 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
684 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
685 if ( !m_xReportComponent
.is() )
686 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
688 if ( m_xReportComponent
.is() )
692 if ( supportsService( SERVICE_FIXEDTEXT
) )
694 m_xReportComponent
->setPropertyValue( PROPERTY_LABEL
, uno::makeAny(GetDefaultName(this)) );
697 catch(const uno::Exception
&)
699 OSL_ENSURE(0,"OUnoObject::EndCreate: Exception caught!");
703 // set geometry properties
704 SetPropsFromRect(GetLogicRect());
709 //----------------------------------------------------------------------------
710 ::rtl::OUString
OUnoObject::GetDefaultName(const OUnoObject
* _pObj
)
712 sal_uInt16 nResId
= 0;
713 ::rtl::OUString aDefaultName
= ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HERE WE HAVE TO INSERT OUR NAME!"));
714 if ( _pObj
->supportsService( SERVICE_FIXEDTEXT
) )
716 nResId
= RID_STR_CLASS_FIXEDTEXT
;
718 else if ( _pObj
->supportsService( SERVICE_FIXEDLINE
) )
720 nResId
= RID_STR_CLASS_FIXEDLINE
;
722 else if ( _pObj
->supportsService( SERVICE_IMAGECONTROL
) )
724 nResId
= RID_STR_CLASS_IMAGECONTROL
;
726 else if ( _pObj
->supportsService( SERVICE_FORMATTEDFIELD
) )
728 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
732 aDefaultName
= ::rtl::OUString( String(ModuleRes(nResId
)) );
736 //----------------------------------------------------------------------------
737 SdrObject
* OUnoObject::CheckHit( const Point
& rPnt
, USHORT nTol
,const SetOfByte
* pSet
) const
739 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
740 if ( IsInside(aOutRect
,rPnt
,nTol
) )
741 return const_cast<OUnoObject
*>(this);
743 return SdrUnoObj::CheckHit( rPnt
, nTol
, pSet
);
745 // -----------------------------------------------------------------------------
746 void OUnoObject::_propertyChange( const beans::PropertyChangeEvent
& evt
) throw( uno::RuntimeException
)
748 DBG_CHKTHIS( rpt_OUnoObject
,NULL
);
749 OObjectBase::_propertyChange(evt
);
752 if ( evt
.PropertyName
== PROPERTY_CHARCOLOR
)
754 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
755 if ( xControlModel
.is() )
757 OObjectBase::EndListening(sal_False
);
760 xControlModel
->setPropertyValue(PROPERTY_TEXTCOLOR
,evt
.NewValue
);
762 catch(uno::Exception
&)
765 OObjectBase::StartListening();
768 else if ( evt
.PropertyName
== PROPERTY_NAME
)
770 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
771 if ( xControlModel
.is() && xControlModel
->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME
) )
774 ::rtl::OUString aOldName
;
775 evt
.OldValue
>>= aOldName
;
778 ::rtl::OUString aNewName
;
779 evt
.NewValue
>>= aNewName
;
781 if ( !aNewName
.equals(aOldName
) )
783 // set old name property
784 OObjectBase::EndListening(sal_False
);
785 if ( m_xMediator
.is() )
786 m_xMediator
.get()->stopListening();
789 xControlModel
->setPropertyValue( PROPERTY_NAME
, evt
.NewValue
);
791 catch(uno::Exception
&)
794 if ( m_xMediator
.is() )
795 m_xMediator
.get()->startListening();
796 OObjectBase::StartListening();
802 // -----------------------------------------------------------------------------
803 void OUnoObject::CreateMediator(sal_Bool _bReverse
)
805 if ( !m_xMediator
.is() )
807 if ( !m_xReportComponent
.is() )
808 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
810 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
811 if ( !m_xMediator
.is() && m_xReportComponent
.is() && xControlModel
.is() )
812 m_xMediator
= TMediator::createFromQuery(new OPropertyMediator(m_xReportComponent
.get(),xControlModel
,getPropertyNameMap(GetObjIdentifier()),_bReverse
));
813 OObjectBase::StartListening();
816 // -----------------------------------------------------------------------------
817 uno::Reference
< beans::XPropertySet
> OUnoObject::getAwtComponent()
819 return Reference
<XPropertySet
>(GetUnoControlModel(),uno::UNO_QUERY
);
822 // -----------------------------------------------------------------------------
823 uno::Reference
< uno::XInterface
> OUnoObject::getUnoShape()
825 return OObjectBase::getUnoShapeOf( *this );
827 // -----------------------------------------------------------------------------
828 SdrObject
* OUnoObject::Clone() const
830 SdrObject
* pClone
= SdrUnoObj::Clone();
833 Reference
<XPropertySet
> xSource(const_cast<OUnoObject
*>(this)->getUnoShape(),uno::UNO_QUERY
);
834 Reference
<XPropertySet
> xDest(pClone
->getUnoShape(),uno::UNO_QUERY
);
835 if ( xSource
.is() && xDest
.is() )
836 comphelper::copyProperties(xSource
.get(),xDest
.get());
840 //----------------------------------------------------------------------------
842 //----------------------------------------------------------------------------
843 TYPEINIT1(OOle2Obj
, SdrOle2Obj
);
844 DBG_NAME( rpt_OOle2Obj
);
845 OOle2Obj::OOle2Obj(const uno::Reference
< report::XReportComponent
>& _xComponent
,UINT16 _nType
)
847 ,OObjectBase(_xComponent
)
850 DBG_CTOR( rpt_OOle2Obj
, NULL
);
853 mxUnoShape
= uno::Reference
< uno::XInterface
>(_xComponent
,uno::UNO_QUERY
);
854 m_bIsListening
= sal_True
;
855 //uno::Reference< embed::XEmbeddedObject > xEmbed(_xComponent,uno::UNO_QUERY);
856 //OSL_ENSURE(xEmbed.is(),"This is no embedded object!");
860 //----------------------------------------------------------------------------
861 OOle2Obj::OOle2Obj(const ::rtl::OUString
& _sComponentName
,UINT16 _nType
)
863 ,OObjectBase(_sComponentName
)
866 DBG_CTOR( rpt_OOle2Obj
, NULL
);
867 m_bIsListening
= sal_True
;
869 //----------------------------------------------------------------------------
870 OOle2Obj::~OOle2Obj()
872 DBG_DTOR( rpt_OOle2Obj
, NULL
);
874 // -----------------------------------------------------------------------------
875 UINT16
OOle2Obj::GetObjIdentifier() const
879 //----------------------------------------------------------------------------
880 UINT32
OOle2Obj::GetObjInventor() const
882 return ReportInventor
;
884 //----------------------------------------------------------------------------
885 SdrPage
* OOle2Obj::GetImplPage() const
887 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
890 //----------------------------------------------------------------------------
891 void OOle2Obj::SetSnapRectImpl(const Rectangle
& _rRect
)
893 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
894 SetSnapRect( _rRect
);
896 //----------------------------------------------------------------------------
897 sal_Int32
OOle2Obj::GetStep() const
899 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
902 OSL_ENSURE(0,"Who called me!");
906 //----------------------------------------------------------------------------
907 void OOle2Obj::NbcMove( const Size
& rSize
)
909 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
911 if ( m_bIsListening
)
914 OObjectBase::EndListening(sal_False
);
916 if ( m_xReportComponent
.is() )
918 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
919 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
920 m_xReportComponent
->setPositionX(m_xReportComponent
->getPositionX() + rSize
.A());
921 m_xReportComponent
->setPositionY(m_xReportComponent
->getPositionY() + rSize
.B());
924 // set geometry properties
925 SetPropsFromRect(GetLogicRect());
928 OObjectBase::StartListening();
931 SdrOle2Obj::NbcMove( rSize
);
934 //----------------------------------------------------------------------------
936 void OOle2Obj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
938 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
939 SdrOle2Obj::NbcResize( rRef
, xFract
, yFract
);
942 OObjectBase::EndListening(sal_False
);
944 // set geometry properties
945 SetPropsFromRect(GetLogicRect());
948 OObjectBase::StartListening();
950 //----------------------------------------------------------------------------
951 void OOle2Obj::NbcSetLogicRect(const Rectangle
& rRect
)
953 SdrOle2Obj::NbcSetLogicRect(rRect
);
955 OObjectBase::EndListening(sal_False
);
957 // set geometry properties
958 SetPropsFromRect(rRect
);
961 OObjectBase::StartListening();
963 //----------------------------------------------------------------------------
965 FASTBOOL
OOle2Obj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
967 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
968 FASTBOOL bResult
= SdrOle2Obj::EndCreate(rStat
, eCmd
);
971 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
974 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
975 if ( !m_xReportComponent
.is() )
976 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
978 // set geometry properties
979 SetPropsFromRect(GetLogicRect());
984 //----------------------------------------------------------------------------
985 SdrObject
* OOle2Obj::CheckHit( const Point
& rPnt
, USHORT nTol
,const SetOfByte
* pSet
) const
987 DBG_CHKTHIS( rpt_OOle2Obj
,NULL
);
988 if ( IsInside(aOutRect
,rPnt
,nTol
) )
989 return const_cast<OOle2Obj
*>(this);
991 return SdrOle2Obj::CheckHit( rPnt
, nTol
, pSet
);
993 // -----------------------------------------------------------------------------
994 uno::Reference
< beans::XPropertySet
> OOle2Obj::getAwtComponent()
996 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
999 // -----------------------------------------------------------------------------
1000 uno::Reference
< uno::XInterface
> OOle2Obj::getUnoShape()
1002 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
1003 if ( !m_xReportComponent
.is() )
1005 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1006 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
1007 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
1011 // -----------------------------------------------------------------------------
1012 uno::Reference
< chart2::data::XDatabaseDataProvider
> lcl_getDataProvider(const uno::Reference
< embed::XEmbeddedObject
>& _xObj
)
1014 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource
;
1015 uno::Reference
< embed::XComponentSupplier
> xCompSupp(_xObj
,uno::UNO_QUERY
);
1018 uno::Reference
< chart2::XChartDocument
> xChartDoc( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1019 if ( xChartDoc
.is() )
1021 xSource
.set(xChartDoc
->getDataProvider(),uno::UNO_QUERY
);
1023 } // if( xCompSupp.is())
1026 // -----------------------------------------------------------------------------
1027 // Clone() soll eine komplette Kopie des Objektes erzeugen.
1028 SdrObject
* OOle2Obj::Clone() const
1030 OOle2Obj
* pObj
= static_cast<OOle2Obj
*>(SdrOle2Obj::Clone());
1031 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1032 svt::EmbeddedObjectRef::TryRunningState( pObj
->GetObjRef() );
1033 pObj
->impl_createDataProvider_nothrow(pRptModel
->getReportDefinition().get());
1035 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource( lcl_getDataProvider(GetObjRef()) );
1036 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDest( lcl_getDataProvider(pObj
->GetObjRef()) );
1037 if ( xSource
.is() && xDest
.is() )
1038 comphelper::copyProperties(xSource
.get(),xDest
.get());
1040 pObj
->initializeChart(pRptModel
->getReportDefinition().get());
1043 // -----------------------------------------------------------------------------
1044 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference
< frame::XModel
>& _xModel
)
1046 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1047 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1048 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1050 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1051 OSL_ASSERT( xReceiver
.is());
1052 if( xReceiver
.is() )
1054 uno::Reference
< lang::XMultiServiceFactory
> xFac(_xModel
,uno::UNO_QUERY
);
1055 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDataProvider( xFac
->createInstance(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.chart2.data.DataProvider"))),uno::UNO_QUERY
);
1056 xReceiver
->attachDataProvider( xDataProvider
.get() );
1059 // -----------------------------------------------------------------------------
1060 void OOle2Obj::initializeChart( const uno::Reference
< frame::XModel
>& _xModel
)
1062 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1063 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1064 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1066 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1067 OSL_ASSERT( xReceiver
.is());
1068 if( xReceiver
.is() )
1070 // lock the model to suppress any internal updates
1071 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
1072 if( xChartModel
.is() )
1073 xChartModel
->lockControllers();
1075 if ( !lcl_getDataProvider(xObj
).is() )
1076 impl_createDataProvider_nothrow(_xModel
);
1078 uno::Reference
< util::XNumberFormatsSupplier
> xNumberFormatsSupplier( _xModel
, uno::UNO_QUERY
);
1079 xReceiver
->attachNumberFormatsSupplier( xNumberFormatsSupplier
);
1081 uno::Sequence
< beans::PropertyValue
> aArgs( 4 );
1082 aArgs
[0] = beans::PropertyValue(
1083 ::rtl::OUString::createFromAscii("CellRangeRepresentation"), -1,
1084 uno::makeAny( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("all")) ), beans::PropertyState_DIRECT_VALUE
);
1085 aArgs
[1] = beans::PropertyValue(
1086 ::rtl::OUString::createFromAscii("HasCategories"), -1,
1087 uno::makeAny( sal_True
), beans::PropertyState_DIRECT_VALUE
);
1088 aArgs
[2] = beans::PropertyValue(
1089 ::rtl::OUString::createFromAscii("FirstCellAsLabel"), -1,
1090 uno::makeAny( sal_False
), beans::PropertyState_DIRECT_VALUE
);
1091 aArgs
[3] = beans::PropertyValue(
1092 ::rtl::OUString::createFromAscii("DataRowSource"), -1,
1093 uno::makeAny( chart::ChartDataRowSource_COLUMNS
), beans::PropertyState_DIRECT_VALUE
);
1094 xReceiver
->setArguments( aArgs
);
1096 if( xChartModel
.is() )
1097 xChartModel
->unlockControllers();
1100 // -----------------------------------------------------------------------------
1101 uno::Reference
< style::XStyle
> getUsedStyle(const uno::Reference
< report::XReportDefinition
>& _xReport
)
1103 uno::Reference
<container::XNameAccess
> xStyles
= _xReport
->getStyleFamilies();
1104 uno::Reference
<container::XNameAccess
> xPageStyles(xStyles
->getByName(::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageStyles"))),uno::UNO_QUERY
);
1106 uno::Reference
< style::XStyle
> xReturn
;
1107 uno::Sequence
< ::rtl::OUString
> aSeq
= xPageStyles
->getElementNames();
1108 const ::rtl::OUString
* pIter
= aSeq
.getConstArray();
1109 const ::rtl::OUString
* pEnd
= pIter
+ aSeq
.getLength();
1110 for(;pIter
!= pEnd
&& !xReturn
.is() ;++pIter
)
1112 uno::Reference
< style::XStyle
> xStyle(xPageStyles
->getByName(*pIter
),uno::UNO_QUERY
);
1113 if ( xStyle
->isInUse() )
1118 //----------------------------------------------------------------------------
1119 //============================================================================
1121 //============================================================================