1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #include "RptObject.hxx"
24 #include <svx/unoshape.hxx>
25 #include "RptModel.hxx"
26 #include "RptObjectListener.hxx"
27 #include <toolkit/helper/vclunohelper.hxx>
28 #include <toolkit/helper/convert.hxx>
29 #include "RptPage.hxx"
30 #include "corestrings.hrc"
31 #include <dbaccess/dbsubcomponentcontroller.hxx>
32 #include "ModuleHelper.hxx"
34 #include <RptResId.hrc>
35 #include <svx/xflclit.hxx>
36 #include <svx/xlnclit.hxx>
37 #include <svx/xlndsit.hxx>
38 #include <svx/xlineit0.hxx>
39 #include <svx/sderitm.hxx>
40 #include <svx/xlnwtit.hxx>
41 #include <svx/xlntrit.hxx>
42 #include <svtools/embedhlp.hxx>
43 #include <com/sun/star/style/XStyle.hpp>
44 #include <com/sun/star/awt/XTabControllerModel.hpp>
45 #include <com/sun/star/awt/XUnoControlContainer.hpp>
46 #include <com/sun/star/awt/XVclContainerPeer.hpp>
47 #include <com/sun/star/awt/XWindow.hpp>
48 #include <com/sun/star/awt/TextAlign.hpp>
49 #include <com/sun/star/beans/XPropertySet.hpp>
50 #include <com/sun/star/beans/PropertyAttribute.hpp>
51 #include <com/sun/star/embed/XComponentSupplier.hpp>
52 #include <com/sun/star/script/XScriptEventsSupplier.hpp>
53 #include <com/sun/star/container/XContainer.hpp>
54 #include <com/sun/star/lang/XServiceInfo.hpp>
55 #include <com/sun/star/report/XShape.hpp>
56 #include <com/sun/star/report/XFixedLine.hpp>
57 #include <com/sun/star/chart/ChartDataRowSource.hpp>
58 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
59 #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
60 #include <com/sun/star/chart2/XChartDocument.hpp>
61 #include <com/sun/star/style/VerticalAlignment.hpp>
62 #include <com/sun/star/style/ParagraphAdjust.hpp>
63 #include <com/sun/star/report/XFormattedField.hpp>
64 #include <comphelper/genericpropertyset.hxx>
65 #include <comphelper/processfactory.hxx>
66 #include <comphelper/property.hxx>
67 #include <tools/diagnose_ex.h>
68 #include "PropertyForward.hxx"
69 #include <connectivity/dbtools.hxx>
70 #include <connectivity/dbconversion.hxx>
71 #include "UndoActions.hxx"
72 #include "UndoEnv.hxx"
78 using namespace ::com::sun::star
;
80 using namespace beans
;
81 using namespace reportdesign
;
82 using namespace container
;
83 using namespace script
;
84 using namespace report
;
86 sal_uInt16
OObjectBase::getObjectType(const uno::Reference
< report::XReportComponent
>& _xComponent
)
88 uno::Reference
< lang::XServiceInfo
> xServiceInfo( _xComponent
, uno::UNO_QUERY
);
89 OSL_ENSURE(xServiceInfo
.is(),"Who deletes the XServiceInfo interface!");
90 if ( xServiceInfo
.is() )
92 if ( xServiceInfo
->supportsService( SERVICE_FIXEDTEXT
))
93 return OBJ_DLG_FIXEDTEXT
;
94 if ( xServiceInfo
->supportsService( SERVICE_FIXEDLINE
))
96 uno::Reference
< report::XFixedLine
> xFixedLine(_xComponent
,uno::UNO_QUERY
);
97 return xFixedLine
->getOrientation() ? OBJ_DLG_HFIXEDLINE
: OBJ_DLG_VFIXEDLINE
;
99 if ( xServiceInfo
->supportsService( SERVICE_IMAGECONTROL
))
100 return OBJ_DLG_IMAGECONTROL
;
101 if ( xServiceInfo
->supportsService( SERVICE_FORMATTEDFIELD
))
102 return OBJ_DLG_FORMATTEDFIELD
;
103 if ( xServiceInfo
->supportsService("com.sun.star.drawing.OLE2Shape") )
105 if ( xServiceInfo
->supportsService( SERVICE_SHAPE
))
106 return OBJ_CUSTOMSHAPE
;
107 if ( xServiceInfo
->supportsService( SERVICE_REPORTDEFINITION
) )
108 return OBJ_DLG_SUBREPORT
;
114 SdrObject
* OObjectBase::createObject(const uno::Reference
< report::XReportComponent
>& _xComponent
)
116 SdrObject
* pNewObj
= NULL
;
117 sal_uInt16 nType
= OObjectBase::getObjectType(_xComponent
);
120 case OBJ_DLG_FIXEDTEXT
:
122 OUnoObject
* pUnoObj
= new OUnoObject( _xComponent
123 ,OUString("com.sun.star.form.component.FixedText")
127 uno::Reference
<beans::XPropertySet
> xControlModel(pUnoObj
->GetUnoControlModel(),uno::UNO_QUERY
);
128 if ( xControlModel
.is() )
129 xControlModel
->setPropertyValue( PROPERTY_MULTILINE
,uno::makeAny(sal_True
));
132 case OBJ_DLG_IMAGECONTROL
:
133 pNewObj
= new OUnoObject(_xComponent
134 ,OUString("com.sun.star.form.component.DatabaseImageControl")
135 ,OBJ_DLG_IMAGECONTROL
);
137 case OBJ_DLG_FORMATTEDFIELD
:
138 pNewObj
= new OUnoObject( _xComponent
139 ,OUString("com.sun.star.form.component.FormattedField")
140 ,OBJ_DLG_FORMATTEDFIELD
);
142 case OBJ_DLG_HFIXEDLINE
:
143 case OBJ_DLG_VFIXEDLINE
:
144 pNewObj
= new OUnoObject( _xComponent
145 ,OUString("com.sun.star.awt.UnoControlFixedLineModel")
148 case OBJ_CUSTOMSHAPE
:
149 pNewObj
= OCustomShape::Create( _xComponent
);
152 bool bOpaque
= false;
153 _xComponent
->getPropertyValue(PROPERTY_OPAQUE
) >>= bOpaque
;
154 pNewObj
->NbcSetLayer(bOpaque
? RPT_LAYER_FRONT
: RPT_LAYER_BACK
);
156 catch(const uno::Exception
&)
158 DBG_UNHANDLED_EXCEPTION();
161 case OBJ_DLG_SUBREPORT
:
163 pNewObj
= OOle2Obj::Create( _xComponent
,nType
);
166 OSL_FAIL("Unknown object id");
171 pNewObj
->SetDoNotInsertIntoPageAutomatically( true );
173 ensureSdrObjectOwnership( _xComponent
);
180 class ParaAdjust
: public AnyConverter
183 virtual ::com::sun::star::uno::Any
operator() (const OUString
& _sPropertyName
,const ::com::sun::star::uno::Any
& lhs
) const SAL_OVERRIDE
186 if (_sPropertyName
== PROPERTY_PARAADJUST
)
188 sal_Int16 nTextAlign
= 0;
192 case awt::TextAlign::LEFT
:
193 nTextAlign
= style::ParagraphAdjust_LEFT
;
195 case awt::TextAlign::CENTER
:
196 nTextAlign
= style::ParagraphAdjust_CENTER
;
198 case awt::TextAlign::RIGHT
:
199 nTextAlign
= style::ParagraphAdjust_RIGHT
;
202 OSL_FAIL("Illegal text alignment value!");
205 aRet
<<= (style::ParagraphAdjust
)nTextAlign
;
209 sal_Int16 nTextAlign
= 0;
210 sal_Int16 eParagraphAdjust
= 0;
211 lhs
>>= eParagraphAdjust
;
212 switch(eParagraphAdjust
)
214 case style::ParagraphAdjust_LEFT
:
215 case style::ParagraphAdjust_BLOCK
:
216 nTextAlign
= awt::TextAlign::LEFT
;
218 case style::ParagraphAdjust_CENTER
:
219 nTextAlign
= awt::TextAlign::CENTER
;
221 case style::ParagraphAdjust_RIGHT
:
222 nTextAlign
= awt::TextAlign::RIGHT
;
225 OSL_FAIL("Illegal text alignment value!");
235 const TPropertyNamePair
& getPropertyNameMap(sal_uInt16 _nObjectId
)
239 case OBJ_DLG_IMAGECONTROL
:
241 static TPropertyNamePair s_aNameMap
;
242 if ( s_aNameMap
.empty() )
244 ::boost::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter());
245 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
)));
246 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
)));
247 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
)));
252 case OBJ_DLG_FIXEDTEXT
:
254 static TPropertyNamePair s_aNameMap
;
255 if ( s_aNameMap
.empty() )
257 ::boost::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter());
258 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR
,TPropertyConverter(PROPERTY_TEXTCOLOR
,aNoConverter
)));
259 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
)));
260 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR
,TPropertyConverter(PROPERTY_TEXTLINECOLOR
,aNoConverter
)));
261 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF
,TPropertyConverter(PROPERTY_FONTRELIEF
,aNoConverter
)));
262 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT
,TPropertyConverter(PROPERTY_FONTHEIGHT
,aNoConverter
)));
263 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT
,TPropertyConverter(PROPERTY_FONTSTRIKEOUT
,aNoConverter
)));
264 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK
,TPropertyConverter(PROPERTY_FONTEMPHASISMARK
,aNoConverter
)));
265 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
)));
266 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
)));
268 ::boost::shared_ptr
<AnyConverter
> aParaAdjust(new ParaAdjust());
269 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aParaAdjust
)));
273 case OBJ_DLG_FORMATTEDFIELD
:
275 static TPropertyNamePair s_aNameMap
;
276 if ( s_aNameMap
.empty() )
278 ::boost::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter());
279 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARCOLOR
,TPropertyConverter(PROPERTY_TEXTCOLOR
,aNoConverter
)));
280 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
)));
281 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARUNDERLINECOLOR
,TPropertyConverter(PROPERTY_TEXTLINECOLOR
,aNoConverter
)));
282 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARRELIEF
,TPropertyConverter(PROPERTY_FONTRELIEF
,aNoConverter
)));
283 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARFONTHEIGHT
,TPropertyConverter(PROPERTY_FONTHEIGHT
,aNoConverter
)));
284 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CHARSTRIKEOUT
,TPropertyConverter(PROPERTY_FONTSTRIKEOUT
,aNoConverter
)));
285 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLTEXTEMPHASISMARK
,TPropertyConverter(PROPERTY_FONTEMPHASISMARK
,aNoConverter
)));
286 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
)));
287 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
)));
288 ::boost::shared_ptr
<AnyConverter
> aParaAdjust(new ParaAdjust());
289 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aParaAdjust
)));
294 case OBJ_CUSTOMSHAPE
:
296 static TPropertyNamePair s_aNameMap
;
297 if ( s_aNameMap
.empty() )
299 ::boost::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter());
300 s_aNameMap
.insert(TPropertyNamePair::value_type(OUString("FillColor"),TPropertyConverter(PROPERTY_CONTROLBACKGROUND
,aNoConverter
)));
301 s_aNameMap
.insert(TPropertyNamePair::value_type(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aNoConverter
)));
309 static TPropertyNamePair s_aEmptyNameMap
;
310 return s_aEmptyNameMap
;
314 OObjectBase::OObjectBase(const uno::Reference
< report::XReportComponent
>& _xComponent
)
315 :m_bIsListening(false)
317 m_xReportComponent
= _xComponent
;
320 OObjectBase::OObjectBase(const OUString
& _sComponentName
)
321 :m_sComponentName(_sComponentName
)
322 ,m_bIsListening(false)
326 OObjectBase::~OObjectBase()
331 m_xReportComponent
.clear();
334 uno::Reference
< report::XSection
> OObjectBase::getSection() const
336 uno::Reference
< report::XSection
> xSection
;
337 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
339 xSection
= pPage
->getSection();
344 uno::Reference
< beans::XPropertySet
> OObjectBase::getAwtComponent()
346 return uno::Reference
< beans::XPropertySet
>();
349 void OObjectBase::StartListening()
351 OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
353 if ( !isListening() && m_xReportComponent
.is() )
355 m_bIsListening
= true;
357 if ( !m_xPropertyChangeListener
.is() )
359 m_xPropertyChangeListener
= new OObjectListener( this );
360 // register listener to all properties
361 m_xReportComponent
->addPropertyChangeListener( OUString() , m_xPropertyChangeListener
);
366 void OObjectBase::EndListening(bool /*bRemoveListener*/)
368 OSL_ENSURE(!m_xReportComponent
.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
370 m_bIsListening
= false;
371 if ( isListening() && m_xReportComponent
.is() )
373 // XPropertyChangeListener
374 if ( m_xPropertyChangeListener
.is() )
379 m_xReportComponent
->removePropertyChangeListener( OUString() , m_xPropertyChangeListener
);
381 catch(const uno::Exception
&)
383 OSL_FAIL("OObjectBase::EndListening: Exception caught!");
386 m_xPropertyChangeListener
.clear();
390 void OObjectBase::SetPropsFromRect(const Rectangle
& _rRect
)
393 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
394 if ( pPage
&& !_rRect
.IsEmpty() )
396 uno::Reference
<report::XSection
> xSection
= pPage
->getSection();
397 assert(_rRect
.getHeight() >= 0);
398 const sal_uInt32
newHeight( ::std::max(0l, _rRect
.getHeight()+_rRect
.Top()) );
399 if ( xSection
.is() && ( newHeight
> xSection
->getHeight() ) )
400 xSection
->setHeight( newHeight
);
403 //pModel->GetRefDevice()->Invalidate(INVALIDATE_CHILDREN);
407 void OObjectBase::_propertyChange( const beans::PropertyChangeEvent
& /*evt*/ ) throw( uno::RuntimeException
)
411 void OObjectBase::SetObjectItemHelper(const SfxPoolItem
& /*rItem*/)
417 bool OObjectBase::supportsService( const OUString
& _sServiceName
) const
419 bool bSupports
= false;
421 Reference
< lang::XServiceInfo
> xServiceInfo( m_xReportComponent
, UNO_QUERY
);
422 // TODO: cache xServiceInfo as member?
423 if ( xServiceInfo
.is() )
424 bSupports
= xServiceInfo
->supportsService( _sServiceName
);
430 void OObjectBase::ensureSdrObjectOwnership( const uno::Reference
< uno::XInterface
>& _rxShape
)
432 // UNDO in the report designer is implemented at the level of the XShapes, not
433 // at the level of SdrObjects. That is, if an object is removed from the report
434 // design, then this happens by removing the XShape from the UNO DrawPage, and
435 // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
437 // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
438 // which are removed from it, which is deadly for us. To prevent this,
439 // we give the XShape implementation the ownership of the SdrObject, which
440 // ensures the SvxDrawPage won't delete it.
441 SvxShape
* pShape
= SvxShape::getImplementation( _rxShape
);
442 OSL_ENSURE( pShape
, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
445 OSL_ENSURE( !pShape
->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
446 pShape
->TakeSdrObjectOwnership();
451 uno::Reference
< uno::XInterface
> OObjectBase::getUnoShapeOf( SdrObject
& _rSdrObject
)
453 uno::Reference
< uno::XInterface
> xShape( _rSdrObject
.getWeakUnoShape() );
457 xShape
= _rSdrObject
.SdrObject::getUnoShape();
461 ensureSdrObjectOwnership( xShape
);
463 m_xKeepShapeAlive
= xShape
;
468 TYPEINIT1(OCustomShape
, SdrObjCustomShape
);
469 OCustomShape::OCustomShape(const uno::Reference
< report::XReportComponent
>& _xComponent
472 ,OObjectBase(_xComponent
)
474 impl_setUnoShape( uno::Reference
< uno::XInterface
>(_xComponent
,uno::UNO_QUERY
) );
475 m_bIsListening
= true;
478 OCustomShape::OCustomShape(const OUString
& _sComponentName
)
480 ,OObjectBase(_sComponentName
)
482 m_bIsListening
= true;
486 OCustomShape::~OCustomShape()
490 sal_uInt16
OCustomShape::GetObjIdentifier() const
492 return sal_uInt16(OBJ_CUSTOMSHAPE
);
495 sal_uInt32
OCustomShape::GetObjInventor() const
497 return ReportInventor
;
500 SdrPage
* OCustomShape::GetImplPage() const
505 void OCustomShape::SetSnapRectImpl(const Rectangle
& _rRect
)
507 SetSnapRect( _rRect
);
510 void OCustomShape::NbcMove( const Size
& rSize
)
512 if ( m_bIsListening
)
514 m_bIsListening
= false;
516 if ( m_xReportComponent
.is() )
518 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
519 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
520 m_xReportComponent
->setPositionX(m_xReportComponent
->getPositionX() + rSize
.A());
521 m_xReportComponent
->setPositionY(m_xReportComponent
->getPositionY() + rSize
.B());
524 // set geometry properties
525 SetPropsFromRect(GetSnapRect());
527 m_bIsListening
= true;
530 SdrObjCustomShape::NbcMove( rSize
);
533 void OCustomShape::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
535 SdrObjCustomShape::NbcResize( rRef
, xFract
, yFract
);
537 SetPropsFromRect(GetSnapRect());
540 void OCustomShape::NbcSetLogicRect(const Rectangle
& rRect
)
542 SdrObjCustomShape::NbcSetLogicRect(rRect
);
543 SetPropsFromRect(rRect
);
546 bool OCustomShape::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
548 bool bResult
= SdrObjCustomShape::EndCreate(rStat
, eCmd
);
551 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
554 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
555 if ( !m_xReportComponent
.is() )
556 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
558 SetPropsFromRect(GetSnapRect());
565 void OCustomShape::SetObjectItemHelper(const SfxPoolItem
& rItem
)
567 SetObjectItem(rItem
);
569 //getSectionWindow()->getView()->AdjustMarkHdl();
573 uno::Reference
< beans::XPropertySet
> OCustomShape::getAwtComponent()
575 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
579 uno::Reference
< uno::XInterface
> OCustomShape::getUnoShape()
581 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
582 if ( !m_xReportComponent
.is() )
584 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
585 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
586 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
591 void OCustomShape::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
593 SdrObjCustomShape::impl_setUnoShape( rxUnoShape
);
595 m_xReportComponent
.clear();
600 TYPEINIT1(OUnoObject
, SdrUnoObj
);
602 OUnoObject::OUnoObject(const OUString
& _sComponentName
603 ,const OUString
& rModelName
604 ,sal_uInt16 _nObjectType
)
605 :SdrUnoObj(rModelName
, true)
606 ,OObjectBase(_sComponentName
)
607 ,m_nObjectType(_nObjectType
)
609 if ( !rModelName
.isEmpty() )
610 impl_initializeModel_nothrow();
613 OUnoObject::OUnoObject(const uno::Reference
< report::XReportComponent
>& _xComponent
614 ,const OUString
& rModelName
615 ,sal_uInt16 _nObjectType
)
616 :SdrUnoObj(rModelName
, true)
617 ,OObjectBase(_xComponent
)
618 ,m_nObjectType(_nObjectType
)
620 impl_setUnoShape( uno::Reference
< uno::XInterface
>( _xComponent
, uno::UNO_QUERY
) );
622 if ( !rModelName
.isEmpty() )
623 impl_initializeModel_nothrow();
627 OUnoObject::~OUnoObject()
631 void OUnoObject::impl_initializeModel_nothrow()
635 Reference
< XFormattedField
> xFormatted( m_xReportComponent
, UNO_QUERY
);
636 if ( xFormatted
.is() )
638 const Reference
< XPropertySet
> xModelProps( GetUnoControlModel(), UNO_QUERY_THROW
);
639 const OUString sTreatAsNumberProperty
= "TreatAsNumber";
640 xModelProps
->setPropertyValue( sTreatAsNumberProperty
, makeAny( sal_False
) );
641 xModelProps
->setPropertyValue( PROPERTY_VERTICALALIGN
,m_xReportComponent
->getPropertyValue(PROPERTY_VERTICALALIGN
));
644 catch( const Exception
& )
646 DBG_UNHANDLED_EXCEPTION();
650 void OUnoObject::impl_setReportComponent_nothrow()
652 if ( m_xReportComponent
.is() )
655 OReportModel
* pReportModel
= static_cast<OReportModel
*>(GetModel());
656 OSL_ENSURE( pReportModel
, "OUnoObject::impl_setReportComponent_nothrow: no report model!" );
660 OXUndoEnvironment::OUndoEnvLock
aLock( pReportModel
->GetUndoEnv() );
661 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
663 impl_initializeModel_nothrow();
666 sal_uInt16
OUnoObject::GetObjIdentifier() const
668 return sal_uInt16(m_nObjectType
);
671 sal_uInt32
OUnoObject::GetObjInventor() const
673 return ReportInventor
;
676 SdrPage
* OUnoObject::GetImplPage() const
681 void OUnoObject::SetSnapRectImpl(const Rectangle
& _rRect
)
683 SetSnapRect( _rRect
);
686 void OUnoObject::NbcMove( const Size
& rSize
)
689 if ( m_bIsListening
)
692 OObjectBase::EndListening(false);
694 bool bPositionFixed
= false;
696 if ( m_xReportComponent
.is() )
698 bool bUndoMode
= false;
699 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
700 if (pRptModel
->GetUndoEnv().IsUndoMode())
702 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
705 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
707 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
708 int nNewX
= m_xReportComponent
->getPositionX() + rSize
.A();
709 m_xReportComponent
->setPositionX(nNewX
);
710 int nNewY
= m_xReportComponent
->getPositionY() + rSize
.B();
711 if (nNewY
< 0 && !bUndoMode
)
713 aUndoSize
.B() = abs(nNewY
);
714 bPositionFixed
= true;
717 m_xReportComponent
->setPositionY(nNewY
);
721 GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize
));
723 // set geometry properties
724 SetPropsFromRect(GetLogicRect());
727 OObjectBase::StartListening();
730 SdrUnoObj::NbcMove( rSize
);
735 void OUnoObject::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
737 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
740 OObjectBase::EndListening(false);
742 // set geometry properties
743 SetPropsFromRect(GetLogicRect());
746 OObjectBase::StartListening();
749 void OUnoObject::NbcSetLogicRect(const Rectangle
& rRect
)
751 SdrUnoObj::NbcSetLogicRect(rRect
);
753 OObjectBase::EndListening(false);
755 // set geometry properties
756 SetPropsFromRect(rRect
);
759 OObjectBase::StartListening();
763 bool OUnoObject::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
765 bool bResult
= SdrUnoObj::EndCreate(rStat
, eCmd
);
768 impl_setReportComponent_nothrow();
770 if ( m_xReportComponent
.is() )
774 if ( supportsService( SERVICE_FIXEDTEXT
) )
776 m_xReportComponent
->setPropertyValue( PROPERTY_LABEL
, uno::makeAny(GetDefaultName(this)) );
779 catch(const uno::Exception
&)
781 DBG_UNHANDLED_EXCEPTION();
784 impl_initializeModel_nothrow();
786 // set geometry properties
787 SetPropsFromRect(GetLogicRect());
793 OUString
OUnoObject::GetDefaultName(const OUnoObject
* _pObj
)
795 sal_uInt16 nResId
= 0;
796 OUString aDefaultName
= "HERE WE HAVE TO INSERT OUR NAME!";
797 if ( _pObj
->supportsService( SERVICE_FIXEDTEXT
) )
799 nResId
= RID_STR_CLASS_FIXEDTEXT
;
801 else if ( _pObj
->supportsService( SERVICE_FIXEDLINE
) )
803 nResId
= RID_STR_CLASS_FIXEDLINE
;
805 else if ( _pObj
->supportsService( SERVICE_IMAGECONTROL
) )
807 nResId
= RID_STR_CLASS_IMAGECONTROL
;
809 else if ( _pObj
->supportsService( SERVICE_FORMATTEDFIELD
) )
811 nResId
= RID_STR_CLASS_FORMATTEDFIELD
;
815 aDefaultName
= ModuleRes(nResId
);
821 void OUnoObject::_propertyChange( const beans::PropertyChangeEvent
& evt
) throw( uno::RuntimeException
)
823 OObjectBase::_propertyChange(evt
);
826 if ( evt
.PropertyName
== PROPERTY_CHARCOLOR
)
828 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
829 if ( xControlModel
.is() )
831 OObjectBase::EndListening(false);
834 xControlModel
->setPropertyValue(PROPERTY_TEXTCOLOR
,evt
.NewValue
);
836 catch(uno::Exception
&)
839 OObjectBase::StartListening();
842 else if ( evt
.PropertyName
== PROPERTY_NAME
)
844 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
845 if ( xControlModel
.is() && xControlModel
->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME
) )
849 evt
.OldValue
>>= aOldName
;
853 evt
.NewValue
>>= aNewName
;
855 if ( !aNewName
.equals(aOldName
) )
857 // set old name property
858 OObjectBase::EndListening(false);
859 if ( m_xMediator
.is() )
860 m_xMediator
.get()->stopListening();
863 xControlModel
->setPropertyValue( PROPERTY_NAME
, evt
.NewValue
);
865 catch(uno::Exception
&)
868 if ( m_xMediator
.is() )
869 m_xMediator
.get()->startListening();
870 OObjectBase::StartListening();
877 void OUnoObject::CreateMediator(bool _bReverse
)
879 if ( !m_xMediator
.is() )
881 impl_setReportComponent_nothrow();
883 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
884 if ( !m_xMediator
.is() && m_xReportComponent
.is() && xControlModel
.is() )
885 m_xMediator
= new OPropertyMediator(m_xReportComponent
.get(),xControlModel
,getPropertyNameMap(GetObjIdentifier()),_bReverse
);
886 OObjectBase::StartListening();
890 uno::Reference
< beans::XPropertySet
> OUnoObject::getAwtComponent()
892 return Reference
<XPropertySet
>(GetUnoControlModel(),uno::UNO_QUERY
);
896 uno::Reference
< uno::XInterface
> OUnoObject::getUnoShape()
898 return OObjectBase::getUnoShapeOf( *this );
901 void OUnoObject::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
903 SdrUnoObj::impl_setUnoShape( rxUnoShape
);
907 OUnoObject
& OUnoObject::operator=(const OUnoObject
& rObj
)
911 SdrUnoObj::operator=(rObj
);
913 Reference
<XPropertySet
> xSource(const_cast<OUnoObject
&>(rObj
).getUnoShape(), uno::UNO_QUERY
);
914 Reference
<XPropertySet
> xDest(getUnoShape(), uno::UNO_QUERY
);
915 if ( xSource
.is() && xDest
.is() )
916 comphelper::copyProperties(xSource
.get(), xDest
.get());
921 OUnoObject
* OUnoObject::Clone() const
923 return CloneHelper
< OUnoObject
>();
928 TYPEINIT1(OOle2Obj
, SdrOle2Obj
);
929 OOle2Obj::OOle2Obj(const uno::Reference
< report::XReportComponent
>& _xComponent
,sal_uInt16 _nType
)
931 ,OObjectBase(_xComponent
)
936 impl_setUnoShape( uno::Reference
< uno::XInterface
>( _xComponent
, uno::UNO_QUERY
) );
937 m_bIsListening
= true;
940 OOle2Obj::OOle2Obj(const OUString
& _sComponentName
,sal_uInt16 _nType
)
942 ,OObjectBase(_sComponentName
)
946 m_bIsListening
= true;
949 OOle2Obj::~OOle2Obj()
953 sal_uInt16
OOle2Obj::GetObjIdentifier() const
958 sal_uInt32
OOle2Obj::GetObjInventor() const
960 return ReportInventor
;
963 SdrPage
* OOle2Obj::GetImplPage() const
968 void OOle2Obj::SetSnapRectImpl(const Rectangle
& _rRect
)
970 SetSnapRect( _rRect
);
973 void OOle2Obj::NbcMove( const Size
& rSize
)
976 if ( m_bIsListening
)
979 OObjectBase::EndListening(false);
981 bool bPositionFixed
= false;
983 if ( m_xReportComponent
.is() )
985 bool bUndoMode
= false;
986 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
987 if (pRptModel
->GetUndoEnv().IsUndoMode())
989 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
992 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
994 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
995 int nNewX
= m_xReportComponent
->getPositionX() + rSize
.A();
996 // can this hinder us to set components outside the area?
1001 m_xReportComponent
->setPositionX(nNewX
);
1002 int nNewY
= m_xReportComponent
->getPositionY() + rSize
.B();
1003 if (nNewY
< 0 && !bUndoMode
)
1005 aUndoSize
.B() = abs(nNewY
);
1006 bPositionFixed
= true;
1009 m_xReportComponent
->setPositionY(nNewY
);
1013 GetModel()->AddUndo(GetModel()->GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize
));
1015 // set geometry properties
1016 SetPropsFromRect(GetLogicRect());
1019 OObjectBase::StartListening();
1022 SdrOle2Obj::NbcMove( rSize
);
1027 void OOle2Obj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1029 SdrOle2Obj::NbcResize( rRef
, xFract
, yFract
);
1032 OObjectBase::EndListening(false);
1034 // set geometry properties
1035 SetPropsFromRect(GetLogicRect());
1038 OObjectBase::StartListening();
1041 void OOle2Obj::NbcSetLogicRect(const Rectangle
& rRect
)
1043 SdrOle2Obj::NbcSetLogicRect(rRect
);
1045 OObjectBase::EndListening(false);
1047 // set geometry properties
1048 SetPropsFromRect(rRect
);
1051 OObjectBase::StartListening();
1055 bool OOle2Obj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1057 bool bResult
= SdrOle2Obj::EndCreate(rStat
, eCmd
);
1060 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1063 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
1064 if ( !m_xReportComponent
.is() )
1065 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
1067 // set geometry properties
1068 SetPropsFromRect(GetLogicRect());
1074 uno::Reference
< beans::XPropertySet
> OOle2Obj::getAwtComponent()
1076 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
1080 uno::Reference
< uno::XInterface
> OOle2Obj::getUnoShape()
1082 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
1083 if ( !m_xReportComponent
.is() )
1085 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1086 OXUndoEnvironment::OUndoEnvLock
aLock(pRptModel
->GetUndoEnv());
1087 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
1092 void OOle2Obj::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
1094 SdrOle2Obj::impl_setUnoShape( rxUnoShape
);
1096 m_xReportComponent
.clear();
1100 uno::Reference
< chart2::data::XDatabaseDataProvider
> lcl_getDataProvider(const uno::Reference
< embed::XEmbeddedObject
>& _xObj
)
1102 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource
;
1103 uno::Reference
< embed::XComponentSupplier
> xCompSupp(_xObj
,uno::UNO_QUERY
);
1106 uno::Reference
< chart2::XChartDocument
> xChartDoc( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1107 if ( xChartDoc
.is() )
1109 xSource
.set(xChartDoc
->getDataProvider(),uno::UNO_QUERY
);
1115 OOle2Obj
& OOle2Obj::operator=(const OOle2Obj
& rObj
)
1119 SdrOle2Obj::operator=(rObj
);
1121 OReportModel
* pRptModel
= static_cast<OReportModel
*>(rObj
.GetModel());
1122 svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
1123 impl_createDataProvider_nothrow(pRptModel
->getReportDefinition().get());
1125 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource( lcl_getDataProvider(rObj
.GetObjRef()) );
1126 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDest( lcl_getDataProvider(GetObjRef()) );
1127 if ( xSource
.is() && xDest
.is() )
1128 comphelper::copyProperties(xSource
.get(),xDest
.get());
1130 initializeChart(pRptModel
->getReportDefinition().get());
1136 // Clone() soll eine komplette Kopie des Objektes erzeugen.
1137 OOle2Obj
* OOle2Obj::Clone() const
1139 return CloneHelper
< OOle2Obj
>();
1142 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference
< frame::XModel
>& _xModel
)
1146 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1147 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1148 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1150 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1151 OSL_ASSERT( xReceiver
.is());
1152 if( xReceiver
.is() )
1154 uno::Reference
< lang::XMultiServiceFactory
> xFac(_xModel
,uno::UNO_QUERY
);
1155 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDataProvider( xFac
->createInstance("com.sun.star.chart2.data.DataProvider"),uno::UNO_QUERY
);
1156 xReceiver
->attachDataProvider( xDataProvider
.get() );
1159 catch(const uno::Exception
&)
1164 void OOle2Obj::initializeOle()
1168 m_bOnlyOnce
= false;
1169 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1170 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1171 pRptModel
->GetUndoEnv().AddElement(lcl_getDataProvider(xObj
));
1173 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1174 if( xCompSupp
.is() )
1176 uno::Reference
< beans::XPropertySet
> xChartProps( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1177 if ( xChartProps
.is() )
1178 xChartProps
->setPropertyValue("NullDate",
1179 uno::makeAny(util::DateTime(0,0,0,0,30,12,1899,false)));
1184 void OOle2Obj::initializeChart( const uno::Reference
< frame::XModel
>& _xModel
)
1186 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1187 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1188 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1190 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1191 OSL_ASSERT( xReceiver
.is());
1192 if( xReceiver
.is() )
1194 // lock the model to suppress any internal updates
1195 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
1196 if( xChartModel
.is() )
1197 xChartModel
->lockControllers();
1199 if ( !lcl_getDataProvider(xObj
).is() )
1200 impl_createDataProvider_nothrow(_xModel
);
1202 OReportModel
* pRptModel
= static_cast<OReportModel
*>(GetModel());
1203 pRptModel
->GetUndoEnv().AddElement(lcl_getDataProvider(xObj
));
1205 ::comphelper::NamedValueCollection aArgs
;
1206 aArgs
.put( "CellRangeRepresentation", uno::makeAny( OUString( "all" ) ) );
1207 aArgs
.put( "HasCategories", uno::makeAny( sal_True
) );
1208 aArgs
.put( "FirstCellAsLabel", uno::makeAny( sal_True
) );
1209 aArgs
.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS
) );
1210 xReceiver
->setArguments( aArgs
.getPropertyValues() );
1212 if( xChartModel
.is() )
1213 xChartModel
->unlockControllers();
1217 uno::Reference
< style::XStyle
> getUsedStyle(const uno::Reference
< report::XReportDefinition
>& _xReport
)
1219 uno::Reference
<container::XNameAccess
> xStyles
= _xReport
->getStyleFamilies();
1220 uno::Reference
<container::XNameAccess
> xPageStyles(xStyles
->getByName("PageStyles"),uno::UNO_QUERY
);
1222 uno::Reference
< style::XStyle
> xReturn
;
1223 uno::Sequence
< OUString
> aSeq
= xPageStyles
->getElementNames();
1224 const OUString
* pIter
= aSeq
.getConstArray();
1225 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
1226 for(;pIter
!= pEnd
&& !xReturn
.is() ;++pIter
)
1228 uno::Reference
< style::XStyle
> xStyle(xPageStyles
->getByName(*pIter
),uno::UNO_QUERY
);
1229 if ( xStyle
->isInUse() )
1239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */