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/convert.hxx>
28 #include <RptPage.hxx>
29 #include <dbaccess/dbsubcomponentcontroller.hxx>
31 #include <strings.hrc>
32 #include <strings.hxx>
33 #include <svx/xflclit.hxx>
34 #include <svx/xlnclit.hxx>
35 #include <svx/xlndsit.hxx>
36 #include <svx/xlineit0.hxx>
37 #include <svx/sderitm.hxx>
38 #include <svx/xlnwtit.hxx>
39 #include <svx/xlntrit.hxx>
40 #include <svtools/embedhlp.hxx>
41 #include <com/sun/star/style/XStyle.hpp>
42 #include <com/sun/star/awt/XTabControllerModel.hpp>
43 #include <com/sun/star/awt/XUnoControlContainer.hpp>
44 #include <com/sun/star/awt/XVclContainerPeer.hpp>
45 #include <com/sun/star/awt/XWindow.hpp>
46 #include <com/sun/star/awt/TextAlign.hpp>
47 #include <com/sun/star/beans/XPropertySet.hpp>
48 #include <com/sun/star/beans/PropertyAttribute.hpp>
49 #include <com/sun/star/embed/XComponentSupplier.hpp>
50 #include <com/sun/star/container/XContainer.hpp>
51 #include <com/sun/star/lang/XServiceInfo.hpp>
52 #include <com/sun/star/report/XShape.hpp>
53 #include <com/sun/star/report/XFixedLine.hpp>
54 #include <com/sun/star/chart/ChartDataRowSource.hpp>
55 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
56 #include <com/sun/star/chart2/data/DatabaseDataProvider.hpp>
57 #include <com/sun/star/chart2/XChartDocument.hpp>
58 #include <com/sun/star/style/VerticalAlignment.hpp>
59 #include <com/sun/star/style/ParagraphAdjust.hpp>
60 #include <com/sun/star/report/XFormattedField.hpp>
61 #include <comphelper/property.hxx>
62 #include <tools/diagnose_ex.h>
63 #include <PropertyForward.hxx>
64 #include <connectivity/dbtools.hxx>
65 #include <connectivity/dbconversion.hxx>
66 #include <UndoActions.hxx>
67 #include <UndoEnv.hxx>
73 using namespace ::com::sun::star
;
75 using namespace beans
;
76 using namespace reportdesign
;
77 using namespace container
;
78 using namespace script
;
79 using namespace report
;
81 sal_uInt16
OObjectBase::getObjectType(const uno::Reference
< report::XReportComponent
>& _xComponent
)
83 uno::Reference
< lang::XServiceInfo
> xServiceInfo( _xComponent
, uno::UNO_QUERY
);
84 OSL_ENSURE(xServiceInfo
.is(),"Who deletes the XServiceInfo interface!");
85 if ( xServiceInfo
.is() )
87 if ( xServiceInfo
->supportsService( SERVICE_FIXEDTEXT
))
88 return OBJ_DLG_FIXEDTEXT
;
89 if ( xServiceInfo
->supportsService( SERVICE_FIXEDLINE
))
91 uno::Reference
< report::XFixedLine
> xFixedLine(_xComponent
,uno::UNO_QUERY
);
92 return xFixedLine
->getOrientation() ? OBJ_DLG_HFIXEDLINE
: OBJ_DLG_VFIXEDLINE
;
94 if ( xServiceInfo
->supportsService( SERVICE_IMAGECONTROL
))
95 return OBJ_DLG_IMAGECONTROL
;
96 if ( xServiceInfo
->supportsService( SERVICE_FORMATTEDFIELD
))
97 return OBJ_DLG_FORMATTEDFIELD
;
98 if ( xServiceInfo
->supportsService("com.sun.star.drawing.OLE2Shape") )
100 if ( xServiceInfo
->supportsService( SERVICE_SHAPE
))
101 return OBJ_CUSTOMSHAPE
;
102 if ( xServiceInfo
->supportsService( SERVICE_REPORTDEFINITION
) )
103 return OBJ_DLG_SUBREPORT
;
109 SdrObject
* OObjectBase::createObject(
110 SdrModel
& rTargetModel
,
111 const uno::Reference
< report::XReportComponent
>& _xComponent
)
113 SdrObject
* pNewObj
= nullptr;
114 sal_uInt16 nType
= OObjectBase::getObjectType(_xComponent
);
117 case OBJ_DLG_FIXEDTEXT
:
119 OUnoObject
* pUnoObj
= new OUnoObject(
122 OUString("com.sun.star.form.component.FixedText"),
126 uno::Reference
<beans::XPropertySet
> xControlModel(pUnoObj
->GetUnoControlModel(),uno::UNO_QUERY
);
127 if ( xControlModel
.is() )
128 xControlModel
->setPropertyValue( PROPERTY_MULTILINE
,uno::makeAny(true));
131 case OBJ_DLG_IMAGECONTROL
:
132 pNewObj
= new OUnoObject(
135 OUString("com.sun.star.form.component.DatabaseImageControl"),
136 OBJ_DLG_IMAGECONTROL
);
138 case OBJ_DLG_FORMATTEDFIELD
:
139 pNewObj
= new OUnoObject(
142 OUString("com.sun.star.form.component.FormattedField"),
143 OBJ_DLG_FORMATTEDFIELD
);
145 case OBJ_DLG_HFIXEDLINE
:
146 case OBJ_DLG_VFIXEDLINE
:
147 pNewObj
= new OUnoObject(
150 OUString("com.sun.star.awt.UnoControlFixedLineModel"),
153 case OBJ_CUSTOMSHAPE
:
154 pNewObj
= OCustomShape::Create(
159 bool bOpaque
= false;
160 _xComponent
->getPropertyValue(PROPERTY_OPAQUE
) >>= bOpaque
;
161 pNewObj
->NbcSetLayer(bOpaque
? RPT_LAYER_FRONT
: RPT_LAYER_BACK
);
163 catch(const uno::Exception
&)
165 DBG_UNHANDLED_EXCEPTION("reportdesign");
168 case OBJ_DLG_SUBREPORT
:
170 pNewObj
= OOle2Obj::Create(
176 OSL_FAIL("Unknown object id");
181 pNewObj
->SetDoNotInsertIntoPageAutomatically( true );
183 ensureSdrObjectOwnership( _xComponent
);
190 class ParaAdjust
: public AnyConverter
193 virtual css::uno::Any
operator() (const OUString
& _sPropertyName
,const css::uno::Any
& lhs
) const override
196 if (_sPropertyName
== PROPERTY_PARAADJUST
)
198 sal_Int16 nTextAlign
= 0;
200 style::ParagraphAdjust eAdjust
;
203 case awt::TextAlign::LEFT
:
204 eAdjust
= style::ParagraphAdjust_LEFT
;
206 case awt::TextAlign::CENTER
:
207 eAdjust
= style::ParagraphAdjust_CENTER
;
209 case awt::TextAlign::RIGHT
:
210 eAdjust
= style::ParagraphAdjust_RIGHT
;
213 OSL_FAIL("Illegal text alignment value!");
220 sal_Int16 nTextAlign
= 0;
221 sal_Int16 eParagraphAdjust
= 0;
222 lhs
>>= eParagraphAdjust
;
223 switch(static_cast<style::ParagraphAdjust
>(eParagraphAdjust
))
225 case style::ParagraphAdjust_LEFT
:
226 case style::ParagraphAdjust_BLOCK
:
227 nTextAlign
= awt::TextAlign::LEFT
;
229 case style::ParagraphAdjust_CENTER
:
230 nTextAlign
= awt::TextAlign::CENTER
;
232 case style::ParagraphAdjust_RIGHT
:
233 nTextAlign
= awt::TextAlign::RIGHT
;
236 OSL_FAIL("Illegal text alignment value!");
246 const TPropertyNamePair
& getPropertyNameMap(sal_uInt16 _nObjectId
)
250 case OBJ_DLG_IMAGECONTROL
:
252 static TPropertyNamePair s_aNameMap
;
253 if ( s_aNameMap
.empty() )
255 std::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter
);
256 s_aNameMap
.emplace(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
));
257 s_aNameMap
.emplace(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
));
258 s_aNameMap
.emplace(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
));
263 case OBJ_DLG_FIXEDTEXT
:
265 static TPropertyNamePair s_aNameMap
;
266 if ( s_aNameMap
.empty() )
268 std::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter
);
269 s_aNameMap
.emplace(PROPERTY_CHARCOLOR
,TPropertyConverter(PROPERTY_TEXTCOLOR
,aNoConverter
));
270 s_aNameMap
.emplace(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
));
271 s_aNameMap
.emplace(PROPERTY_CHARUNDERLINECOLOR
,TPropertyConverter(PROPERTY_TEXTLINECOLOR
,aNoConverter
));
272 s_aNameMap
.emplace(PROPERTY_CHARRELIEF
,TPropertyConverter(PROPERTY_FONTRELIEF
,aNoConverter
));
273 s_aNameMap
.emplace(PROPERTY_CHARFONTHEIGHT
,TPropertyConverter(PROPERTY_FONTHEIGHT
,aNoConverter
));
274 s_aNameMap
.emplace(PROPERTY_CHARSTRIKEOUT
,TPropertyConverter(PROPERTY_FONTSTRIKEOUT
,aNoConverter
));
275 s_aNameMap
.emplace(PROPERTY_CONTROLTEXTEMPHASISMARK
,TPropertyConverter(PROPERTY_FONTEMPHASISMARK
,aNoConverter
));
276 s_aNameMap
.emplace(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
));
277 s_aNameMap
.emplace(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
));
279 std::shared_ptr
<AnyConverter
> aParaAdjust(new ParaAdjust
);
280 s_aNameMap
.emplace(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aParaAdjust
));
284 case OBJ_DLG_FORMATTEDFIELD
:
286 static TPropertyNamePair s_aNameMap
;
287 if ( s_aNameMap
.empty() )
289 std::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter
);
290 s_aNameMap
.emplace(PROPERTY_CHARCOLOR
,TPropertyConverter(PROPERTY_TEXTCOLOR
,aNoConverter
));
291 s_aNameMap
.emplace(PROPERTY_CONTROLBACKGROUND
,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR
,aNoConverter
));
292 s_aNameMap
.emplace(PROPERTY_CHARUNDERLINECOLOR
,TPropertyConverter(PROPERTY_TEXTLINECOLOR
,aNoConverter
));
293 s_aNameMap
.emplace(PROPERTY_CHARRELIEF
,TPropertyConverter(PROPERTY_FONTRELIEF
,aNoConverter
));
294 s_aNameMap
.emplace(PROPERTY_CHARFONTHEIGHT
,TPropertyConverter(PROPERTY_FONTHEIGHT
,aNoConverter
));
295 s_aNameMap
.emplace(PROPERTY_CHARSTRIKEOUT
,TPropertyConverter(PROPERTY_FONTSTRIKEOUT
,aNoConverter
));
296 s_aNameMap
.emplace(PROPERTY_CONTROLTEXTEMPHASISMARK
,TPropertyConverter(PROPERTY_FONTEMPHASISMARK
,aNoConverter
));
297 s_aNameMap
.emplace(PROPERTY_CONTROLBORDER
,TPropertyConverter(PROPERTY_BORDER
,aNoConverter
));
298 s_aNameMap
.emplace(PROPERTY_CONTROLBORDERCOLOR
,TPropertyConverter(PROPERTY_BORDERCOLOR
,aNoConverter
));
299 std::shared_ptr
<AnyConverter
> aParaAdjust(new ParaAdjust
);
300 s_aNameMap
.emplace(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aParaAdjust
));
305 case OBJ_CUSTOMSHAPE
:
307 static TPropertyNamePair s_aNameMap
;
308 if ( s_aNameMap
.empty() )
310 std::shared_ptr
<AnyConverter
> aNoConverter(new AnyConverter
);
311 s_aNameMap
.emplace(OUString("FillColor"),TPropertyConverter(PROPERTY_CONTROLBACKGROUND
,aNoConverter
));
312 s_aNameMap
.emplace(PROPERTY_PARAADJUST
,TPropertyConverter(PROPERTY_ALIGN
,aNoConverter
));
320 static TPropertyNamePair s_aEmptyNameMap
;
321 return s_aEmptyNameMap
;
325 OObjectBase::OObjectBase(const uno::Reference
< report::XReportComponent
>& _xComponent
)
326 :m_bIsListening(false)
328 m_xReportComponent
= _xComponent
;
331 OObjectBase::OObjectBase(const OUString
& _sComponentName
)
332 :m_sComponentName(_sComponentName
)
333 ,m_bIsListening(false)
337 OObjectBase::~OObjectBase()
342 m_xReportComponent
.clear();
345 uno::Reference
< report::XSection
> OObjectBase::getSection() const
347 uno::Reference
< report::XSection
> xSection
;
348 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
350 xSection
= pPage
->getSection();
355 uno::Reference
< beans::XPropertySet
> OObjectBase::getAwtComponent()
357 return uno::Reference
< beans::XPropertySet
>();
360 void OObjectBase::StartListening()
362 OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
364 if ( !isListening() && m_xReportComponent
.is() )
366 m_bIsListening
= true;
368 if ( !m_xPropertyChangeListener
.is() )
370 m_xPropertyChangeListener
= new OObjectListener( this );
371 // register listener to all properties
372 m_xReportComponent
->addPropertyChangeListener( OUString() , m_xPropertyChangeListener
);
377 void OObjectBase::EndListening()
379 OSL_ENSURE(!m_xReportComponent
.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
381 if ( isListening() && m_xReportComponent
.is() )
383 // XPropertyChangeListener
384 if ( m_xPropertyChangeListener
.is() )
389 m_xReportComponent
->removePropertyChangeListener( OUString() , m_xPropertyChangeListener
);
391 catch(const uno::Exception
&)
393 OSL_FAIL("OObjectBase::EndListening: Exception caught!");
396 m_xPropertyChangeListener
.clear();
398 m_bIsListening
= false;
401 void OObjectBase::SetPropsFromRect(const tools::Rectangle
& _rRect
)
404 OReportPage
* pPage
= dynamic_cast<OReportPage
*>(GetImplPage());
405 if ( pPage
&& !_rRect
.IsEmpty() )
407 const uno::Reference
<report::XSection
>& xSection
= pPage
->getSection();
408 assert(_rRect
.getHeight() >= 0);
409 const sal_uInt32
newHeight( ::std::max(0l, _rRect
.getHeight()+_rRect
.Top()) );
410 if ( xSection
.is() && ( newHeight
> xSection
->getHeight() ) )
411 xSection
->setHeight( newHeight
);
414 //pModel->GetRefDevice()->Invalidate(InvalidateFlags::Children);
418 void OObjectBase::_propertyChange( const beans::PropertyChangeEvent
& /*evt*/ )
422 bool OObjectBase::supportsService( const OUString
& _sServiceName
) const
424 bool bSupports
= false;
426 Reference
< lang::XServiceInfo
> xServiceInfo( m_xReportComponent
, UNO_QUERY
);
427 // TODO: cache xServiceInfo as member?
428 if ( xServiceInfo
.is() )
429 bSupports
= xServiceInfo
->supportsService( _sServiceName
);
435 void OObjectBase::ensureSdrObjectOwnership( const uno::Reference
< uno::XInterface
>& _rxShape
)
437 // UNDO in the report designer is implemented at the level of the XShapes, not
438 // at the level of SdrObjects. That is, if an object is removed from the report
439 // design, then this happens by removing the XShape from the UNO DrawPage, and
440 // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
442 // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
443 // which are removed from it, which is deadly for us. To prevent this,
444 // we give the XShape implementation the ownership of the SdrObject, which
445 // ensures the SvxDrawPage won't delete it.
446 SvxShape
* pShape
= SvxShape::getImplementation( _rxShape
);
447 OSL_ENSURE( pShape
, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
450 OSL_ENSURE( !pShape
->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
451 pShape
->TakeSdrObjectOwnership();
456 uno::Reference
< uno::XInterface
> OObjectBase::getUnoShapeOf( SdrObject
& _rSdrObject
)
458 uno::Reference
< uno::XInterface
> xShape( _rSdrObject
.getWeakUnoShape() );
462 xShape
= _rSdrObject
.SdrObject::getUnoShape();
466 ensureSdrObjectOwnership( xShape
);
468 m_xKeepShapeAlive
= xShape
;
472 OCustomShape::OCustomShape(
474 const uno::Reference
< report::XReportComponent
>& _xComponent
)
475 : SdrObjCustomShape(rSdrModel
)
476 ,OObjectBase(_xComponent
)
478 impl_setUnoShape( uno::Reference
< uno::XInterface
>(_xComponent
,uno::UNO_QUERY
) );
479 m_bIsListening
= true;
482 OCustomShape::OCustomShape(
484 const OUString
& _sComponentName
)
485 : SdrObjCustomShape(rSdrModel
)
486 ,OObjectBase(_sComponentName
)
488 m_bIsListening
= true;
492 OCustomShape::~OCustomShape()
496 sal_uInt16
OCustomShape::GetObjIdentifier() const
498 return sal_uInt16(OBJ_CUSTOMSHAPE
);
501 SdrInventor
OCustomShape::GetObjInventor() const
503 return SdrInventor::ReportDesign
;
506 SdrPage
* OCustomShape::GetImplPage() const
508 return getSdrPageFromSdrObject();
511 void OCustomShape::NbcMove( const Size
& rSize
)
513 if ( m_bIsListening
)
515 m_bIsListening
= false;
517 if ( m_xReportComponent
.is() )
519 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
520 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
521 m_xReportComponent
->setPositionX(m_xReportComponent
->getPositionX() + rSize
.Width());
522 m_xReportComponent
->setPositionY(m_xReportComponent
->getPositionY() + rSize
.Height());
525 // set geometry properties
526 SetPropsFromRect(GetSnapRect());
528 m_bIsListening
= true;
531 SdrObjCustomShape::NbcMove( rSize
);
534 void OCustomShape::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
536 SdrObjCustomShape::NbcResize( rRef
, xFract
, yFract
);
538 SetPropsFromRect(GetSnapRect());
541 void OCustomShape::NbcSetLogicRect(const tools::Rectangle
& rRect
)
543 SdrObjCustomShape::NbcSetLogicRect(rRect
);
544 SetPropsFromRect(rRect
);
547 bool OCustomShape::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
549 bool bResult
= SdrObjCustomShape::EndCreate(rStat
, eCmd
);
552 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
553 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
555 if ( !m_xReportComponent
.is() )
556 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
558 SetPropsFromRect(GetSnapRect());
565 uno::Reference
< beans::XPropertySet
> OCustomShape::getAwtComponent()
567 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
571 uno::Reference
< uno::XInterface
> OCustomShape::getUnoShape()
573 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
574 if ( !m_xReportComponent
.is() )
576 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
577 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
578 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
583 void OCustomShape::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
585 SdrObjCustomShape::impl_setUnoShape( rxUnoShape
);
587 m_xReportComponent
.clear();
590 OUnoObject::OUnoObject(
592 const OUString
& _sComponentName
,
593 const OUString
& rModelName
,
594 sal_uInt16 _nObjectType
)
595 : SdrUnoObj(rSdrModel
, rModelName
)
596 ,OObjectBase(_sComponentName
)
597 ,m_nObjectType(_nObjectType
)
599 ,m_bSetDefaultLabel(false)
601 if ( !rModelName
.isEmpty() )
602 impl_initializeModel_nothrow();
605 OUnoObject::OUnoObject(
607 const uno::Reference
< report::XReportComponent
>& _xComponent
,
608 const OUString
& rModelName
,
609 sal_uInt16 _nObjectType
)
610 : SdrUnoObj(rSdrModel
, rModelName
)
611 ,OObjectBase(_xComponent
)
612 ,m_nObjectType(_nObjectType
)
614 ,m_bSetDefaultLabel(false)
616 impl_setUnoShape( uno::Reference
< uno::XInterface
>( _xComponent
, uno::UNO_QUERY
) );
618 if ( !rModelName
.isEmpty() )
619 impl_initializeModel_nothrow();
623 OUnoObject::~OUnoObject()
627 void OUnoObject::impl_initializeModel_nothrow()
631 Reference
< XFormattedField
> xFormatted( m_xReportComponent
, UNO_QUERY
);
632 if ( xFormatted
.is() )
634 const Reference
< XPropertySet
> xModelProps( GetUnoControlModel(), UNO_QUERY_THROW
);
635 const OUString sTreatAsNumberProperty
= "TreatAsNumber";
636 xModelProps
->setPropertyValue( sTreatAsNumberProperty
, makeAny( false ) );
637 xModelProps
->setPropertyValue( PROPERTY_VERTICALALIGN
,m_xReportComponent
->getPropertyValue(PROPERTY_VERTICALALIGN
));
640 catch( const Exception
& )
642 DBG_UNHANDLED_EXCEPTION("reportdesign");
646 sal_uInt16
OUnoObject::GetObjIdentifier() const
648 return m_nObjectType
;
651 SdrInventor
OUnoObject::GetObjInventor() const
653 return SdrInventor::ReportDesign
;
656 SdrPage
* OUnoObject::GetImplPage() const
658 return getSdrPageFromSdrObject();
661 void OUnoObject::NbcMove( const Size
& rSize
)
664 if ( m_bIsListening
)
667 OObjectBase::EndListening();
669 bool bPositionFixed
= false;
671 if ( m_xReportComponent
.is() )
673 bool bUndoMode
= false;
674 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
676 if (rRptModel
.GetUndoEnv().IsUndoMode())
678 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
681 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
683 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
684 int nNewX
= m_xReportComponent
->getPositionX() + rSize
.Width();
685 m_xReportComponent
->setPositionX(nNewX
);
686 int nNewY
= m_xReportComponent
->getPositionY() + rSize
.Height();
687 if (nNewY
< 0 && !bUndoMode
)
689 aUndoSize
.setHeight( abs(nNewY
) );
690 bPositionFixed
= true;
693 m_xReportComponent
->setPositionY(nNewY
);
697 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize
));
699 // set geometry properties
700 SetPropsFromRect(GetLogicRect());
703 OObjectBase::StartListening();
706 SdrUnoObj::NbcMove( rSize
);
710 void OUnoObject::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
712 SdrUnoObj::NbcResize( rRef
, xFract
, yFract
);
715 OObjectBase::EndListening();
717 // set geometry properties
718 SetPropsFromRect(GetLogicRect());
721 OObjectBase::StartListening();
724 void OUnoObject::NbcSetLogicRect(const tools::Rectangle
& rRect
)
726 SdrUnoObj::NbcSetLogicRect(rRect
);
728 OObjectBase::EndListening();
730 // set geometry properties
731 SetPropsFromRect(rRect
);
734 OObjectBase::StartListening();
737 bool OUnoObject::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
739 const bool bResult(SdrUnoObj::EndCreate(rStat
, eCmd
));
743 // tdf#118730 remember if this object was created interactively (due to ::EndCreate being called)
744 m_bSetDefaultLabel
= true;
746 // set geometry properties
747 SetPropsFromRect(GetLogicRect());
753 OUString
OUnoObject::GetDefaultName(const OUnoObject
* _pObj
)
755 OUString aDefaultName
= "HERE WE HAVE TO INSERT OUR NAME!";
756 if ( _pObj
->supportsService( SERVICE_FIXEDTEXT
) )
758 aDefaultName
= RID_STR_CLASS_FIXEDTEXT
;
760 else if ( _pObj
->supportsService( SERVICE_FIXEDLINE
) )
762 aDefaultName
= RID_STR_CLASS_FIXEDLINE
;
764 else if ( _pObj
->supportsService( SERVICE_IMAGECONTROL
) )
766 aDefaultName
= RID_STR_CLASS_IMAGECONTROL
;
768 else if ( _pObj
->supportsService( SERVICE_FORMATTEDFIELD
) )
770 aDefaultName
= RID_STR_CLASS_FORMATTEDFIELD
;
776 void OUnoObject::_propertyChange( const beans::PropertyChangeEvent
& evt
)
778 OObjectBase::_propertyChange(evt
);
781 if ( evt
.PropertyName
== PROPERTY_CHARCOLOR
)
783 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
784 if ( xControlModel
.is() )
786 OObjectBase::EndListening();
789 xControlModel
->setPropertyValue(PROPERTY_TEXTCOLOR
,evt
.NewValue
);
791 catch(uno::Exception
&)
794 OObjectBase::StartListening();
797 else if ( evt
.PropertyName
== PROPERTY_NAME
)
799 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
800 if ( xControlModel
.is() && xControlModel
->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME
) )
804 evt
.OldValue
>>= aOldName
;
808 evt
.NewValue
>>= aNewName
;
810 if ( aNewName
!= aOldName
)
812 // set old name property
813 OObjectBase::EndListening();
814 if ( m_xMediator
.is() )
815 m_xMediator
->stopListening();
818 xControlModel
->setPropertyValue( PROPERTY_NAME
, evt
.NewValue
);
820 catch(uno::Exception
&)
823 if ( m_xMediator
.is() )
824 m_xMediator
->startListening();
825 OObjectBase::StartListening();
832 void OUnoObject::CreateMediator(bool _bReverse
)
834 if ( !m_xMediator
.is() )
836 // tdf#118730 Directly do things formerly done in
837 // OUnoObject::impl_setReportComponent_nothrow here
838 if(!m_xReportComponent
.is())
840 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
841 OXUndoEnvironment::OUndoEnvLock
aLock( rRptModel
.GetUndoEnv() );
842 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
844 impl_initializeModel_nothrow();
847 if(m_xReportComponent
.is() && m_bSetDefaultLabel
)
849 // tdf#118730 Directly do things formerly done in
850 // OUnoObject::EndCreate here
851 // tdf#119067 ...but *only* if result of interactive
852 // creation in Report DesignView
853 m_bSetDefaultLabel
= false;
857 if ( supportsService( SERVICE_FIXEDTEXT
) )
859 m_xReportComponent
->setPropertyValue(
861 uno::makeAny(GetDefaultName(this)));
864 catch(const uno::Exception
&)
866 DBG_UNHANDLED_EXCEPTION("reportdesign");
870 if(!m_xMediator
.is() && m_xReportComponent
.is())
872 Reference
<XPropertySet
> xControlModel(GetUnoControlModel(),uno::UNO_QUERY
);
874 if(xControlModel
.is())
876 m_xMediator
= new OPropertyMediator(
877 m_xReportComponent
.get(),
879 getPropertyNameMap(GetObjIdentifier()),
884 OObjectBase::StartListening();
888 uno::Reference
< beans::XPropertySet
> OUnoObject::getAwtComponent()
890 return Reference
<XPropertySet
>(GetUnoControlModel(),uno::UNO_QUERY
);
894 uno::Reference
< uno::XInterface
> OUnoObject::getUnoShape()
896 return OObjectBase::getUnoShapeOf( *this );
899 void OUnoObject::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
901 SdrUnoObj::impl_setUnoShape( rxUnoShape
);
905 OUnoObject
* OUnoObject::CloneSdrObject(SdrModel
& rTargetModel
) const
907 return CloneHelper
< OUnoObject
>(rTargetModel
);
910 OUnoObject
& OUnoObject::operator=(const OUnoObject
& rObj
)
914 SdrUnoObj::operator=(rObj
);
916 Reference
<XPropertySet
> xSource(const_cast<OUnoObject
&>(rObj
).getUnoShape(), uno::UNO_QUERY
);
917 Reference
<XPropertySet
> xDest(getUnoShape(), uno::UNO_QUERY
);
918 if ( xSource
.is() && xDest
.is() )
919 comphelper::copyProperties(xSource
.get(), xDest
.get());
927 const uno::Reference
< report::XReportComponent
>& _xComponent
,
929 : SdrOle2Obj(rSdrModel
)
930 ,OObjectBase(_xComponent
)
934 impl_setUnoShape( uno::Reference
< uno::XInterface
>( _xComponent
, uno::UNO_QUERY
) );
935 m_bIsListening
= true;
940 const OUString
& _sComponentName
,
942 : SdrOle2Obj(rSdrModel
)
943 ,OObjectBase(_sComponentName
)
947 m_bIsListening
= true;
950 OOle2Obj::~OOle2Obj()
954 sal_uInt16
OOle2Obj::GetObjIdentifier() const
959 SdrInventor
OOle2Obj::GetObjInventor() const
961 return SdrInventor::ReportDesign
;
964 SdrPage
* OOle2Obj::GetImplPage() const
966 return getSdrPageFromSdrObject();
969 void OOle2Obj::NbcMove( const Size
& rSize
)
972 if ( m_bIsListening
)
975 OObjectBase::EndListening();
977 bool bPositionFixed
= false;
979 if ( m_xReportComponent
.is() )
981 bool bUndoMode
= false;
982 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
984 if (rRptModel
.GetUndoEnv().IsUndoMode())
986 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
989 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
991 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
992 int nNewX
= m_xReportComponent
->getPositionX() + rSize
.Width();
993 // can this hinder us to set components outside the area?
998 m_xReportComponent
->setPositionX(nNewX
);
999 int nNewY
= m_xReportComponent
->getPositionY() + rSize
.Height();
1000 if (nNewY
< 0 && !bUndoMode
)
1002 aUndoSize
.setHeight( abs(nNewY
) );
1003 bPositionFixed
= true;
1006 m_xReportComponent
->setPositionY(nNewY
);
1010 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize
));
1012 // set geometry properties
1013 SetPropsFromRect(GetLogicRect());
1016 OObjectBase::StartListening();
1019 SdrOle2Obj::NbcMove( rSize
);
1023 void OOle2Obj::NbcResize(const Point
& rRef
, const Fraction
& xFract
, const Fraction
& yFract
)
1025 SdrOle2Obj::NbcResize( rRef
, xFract
, yFract
);
1028 OObjectBase::EndListening();
1030 // set geometry properties
1031 SetPropsFromRect(GetLogicRect());
1034 OObjectBase::StartListening();
1037 void OOle2Obj::NbcSetLogicRect(const tools::Rectangle
& rRect
)
1039 SdrOle2Obj::NbcSetLogicRect(rRect
);
1041 OObjectBase::EndListening();
1043 // set geometry properties
1044 SetPropsFromRect(rRect
);
1047 OObjectBase::StartListening();
1051 bool OOle2Obj::EndCreate(SdrDragStat
& rStat
, SdrCreateCmd eCmd
)
1053 bool bResult
= SdrOle2Obj::EndCreate(rStat
, eCmd
);
1056 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
1057 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
1059 if ( !m_xReportComponent
.is() )
1060 m_xReportComponent
.set(getUnoShape(),uno::UNO_QUERY
);
1062 // set geometry properties
1063 SetPropsFromRect(GetLogicRect());
1069 uno::Reference
< beans::XPropertySet
> OOle2Obj::getAwtComponent()
1071 return uno::Reference
< beans::XPropertySet
>(m_xReportComponent
,uno::UNO_QUERY
);
1075 uno::Reference
< uno::XInterface
> OOle2Obj::getUnoShape()
1077 uno::Reference
< uno::XInterface
> xShape
= OObjectBase::getUnoShapeOf( *this );
1078 if ( !m_xReportComponent
.is() )
1080 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
1081 OXUndoEnvironment::OUndoEnvLock
aLock(rRptModel
.GetUndoEnv());
1082 m_xReportComponent
.set(xShape
,uno::UNO_QUERY
);
1087 void OOle2Obj::impl_setUnoShape( const uno::Reference
< uno::XInterface
>& rxUnoShape
)
1089 SdrOle2Obj::impl_setUnoShape( rxUnoShape
);
1091 m_xReportComponent
.clear();
1095 static uno::Reference
< chart2::data::XDatabaseDataProvider
> lcl_getDataProvider(const uno::Reference
< embed::XEmbeddedObject
>& _xObj
)
1097 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource
;
1098 uno::Reference
< embed::XComponentSupplier
> xCompSupp(_xObj
,uno::UNO_QUERY
);
1101 uno::Reference
< chart2::XChartDocument
> xChartDoc( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1102 if ( xChartDoc
.is() )
1104 xSource
.set(xChartDoc
->getDataProvider(),uno::UNO_QUERY
);
1110 // Clone() should make a complete copy of the object.
1111 OOle2Obj
* OOle2Obj::CloneSdrObject(SdrModel
& rTargetModel
) const
1113 return CloneHelper
< OOle2Obj
>(rTargetModel
);
1116 OOle2Obj
& OOle2Obj::operator=(const OOle2Obj
& rObj
)
1120 SdrOle2Obj::operator=(rObj
);
1122 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
1123 svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
1124 impl_createDataProvider_nothrow(rRptModel
.getReportDefinition().get());
1126 uno::Reference
< chart2::data::XDatabaseDataProvider
> xSource( lcl_getDataProvider(rObj
.GetObjRef()) );
1127 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDest( lcl_getDataProvider(GetObjRef()) );
1128 if ( xSource
.is() && xDest
.is() )
1129 comphelper::copyProperties(xSource
.get(),xDest
.get());
1131 initializeChart(rRptModel
.getReportDefinition().get());
1136 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference
< frame::XModel
>& _xModel
)
1140 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1141 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1142 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1144 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1145 OSL_ASSERT( xReceiver
.is());
1146 if( xReceiver
.is() )
1148 uno::Reference
< lang::XMultiServiceFactory
> xFac(_xModel
,uno::UNO_QUERY
);
1149 uno::Reference
< chart2::data::XDatabaseDataProvider
> xDataProvider( xFac
->createInstance("com.sun.star.chart2.data.DataProvider"),uno::UNO_QUERY
);
1150 xReceiver
->attachDataProvider( xDataProvider
.get() );
1153 catch(const uno::Exception
&)
1158 void OOle2Obj::initializeOle()
1162 m_bOnlyOnce
= false;
1163 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1164 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
1165 rRptModel
.GetUndoEnv().AddElement(lcl_getDataProvider(xObj
));
1167 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1168 if( xCompSupp
.is() )
1170 uno::Reference
< beans::XPropertySet
> xChartProps( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1171 if ( xChartProps
.is() )
1172 xChartProps
->setPropertyValue("NullDate",
1173 uno::makeAny(util::DateTime(0,0,0,0,30,12,1899,false)));
1178 void OOle2Obj::initializeChart( const uno::Reference
< frame::XModel
>& _xModel
)
1180 uno::Reference
< embed::XEmbeddedObject
> xObj
= GetObjRef();
1181 uno::Reference
< chart2::data::XDataReceiver
> xReceiver
;
1182 uno::Reference
< embed::XComponentSupplier
> xCompSupp( xObj
, uno::UNO_QUERY
);
1184 xReceiver
.set( xCompSupp
->getComponent(), uno::UNO_QUERY
);
1185 OSL_ASSERT( xReceiver
.is());
1186 if( xReceiver
.is() )
1188 // lock the model to suppress any internal updates
1189 uno::Reference
< frame::XModel
> xChartModel( xReceiver
, uno::UNO_QUERY
);
1190 if( xChartModel
.is() )
1191 xChartModel
->lockControllers();
1193 if ( !lcl_getDataProvider(xObj
).is() )
1194 impl_createDataProvider_nothrow(_xModel
);
1196 OReportModel
& rRptModel(static_cast< OReportModel
& >(getSdrModelFromSdrObject()));
1197 rRptModel
.GetUndoEnv().AddElement(lcl_getDataProvider(xObj
));
1199 ::comphelper::NamedValueCollection aArgs
;
1200 aArgs
.put( "CellRangeRepresentation", uno::makeAny( OUString( "all" ) ) );
1201 aArgs
.put( "HasCategories", uno::makeAny( true ) );
1202 aArgs
.put( "FirstCellAsLabel", uno::makeAny( true ) );
1203 aArgs
.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS
) );
1204 xReceiver
->setArguments( aArgs
.getPropertyValues() );
1206 if( xChartModel
.is() )
1207 xChartModel
->unlockControllers();
1211 uno::Reference
< style::XStyle
> getUsedStyle(const uno::Reference
< report::XReportDefinition
>& _xReport
)
1213 uno::Reference
<container::XNameAccess
> xStyles
= _xReport
->getStyleFamilies();
1214 uno::Reference
<container::XNameAccess
> xPageStyles(xStyles
->getByName("PageStyles"),uno::UNO_QUERY
);
1216 uno::Reference
< style::XStyle
> xReturn
;
1217 uno::Sequence
< OUString
> aSeq
= xPageStyles
->getElementNames();
1218 const OUString
* pIter
= aSeq
.getConstArray();
1219 const OUString
* pEnd
= pIter
+ aSeq
.getLength();
1220 for(;pIter
!= pEnd
&& !xReturn
.is() ;++pIter
)
1222 uno::Reference
< style::XStyle
> xStyle(xPageStyles
->getByName(*pIter
),uno::UNO_QUERY
);
1223 if ( xStyle
->isInUse() )
1233 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */