bump product version to 6.3.0.0.beta1
[LibreOffice.git] / reportdesign / source / core / sdr / RptObject.cxx
blob0fe29d2d02527c8a8f2438e726ddf46c93631433
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
20 #include <vector>
21 #include <algorithm>
23 #include <RptDef.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>
68 #include <functional>
70 namespace rptui
73 using namespace ::com::sun::star;
74 using namespace uno;
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") )
99 return OBJ_OLE2;
100 if ( xServiceInfo->supportsService( SERVICE_SHAPE ))
101 return OBJ_CUSTOMSHAPE;
102 if ( xServiceInfo->supportsService( SERVICE_REPORTDEFINITION ) )
103 return OBJ_DLG_SUBREPORT;
104 return OBJ_OLE2;
106 return 0;
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);
115 switch( nType )
117 case OBJ_DLG_FIXEDTEXT:
119 OUnoObject* pUnoObj = new OUnoObject(
120 rTargetModel,
121 _xComponent,
122 OUString("com.sun.star.form.component.FixedText"),
123 OBJ_DLG_FIXEDTEXT);
124 pNewObj = pUnoObj;
126 uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
127 if ( xControlModel.is() )
128 xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::makeAny(true));
130 break;
131 case OBJ_DLG_IMAGECONTROL:
132 pNewObj = new OUnoObject(
133 rTargetModel,
134 _xComponent,
135 OUString("com.sun.star.form.component.DatabaseImageControl"),
136 OBJ_DLG_IMAGECONTROL);
137 break;
138 case OBJ_DLG_FORMATTEDFIELD:
139 pNewObj = new OUnoObject(
140 rTargetModel,
141 _xComponent,
142 OUString("com.sun.star.form.component.FormattedField"),
143 OBJ_DLG_FORMATTEDFIELD);
144 break;
145 case OBJ_DLG_HFIXEDLINE:
146 case OBJ_DLG_VFIXEDLINE:
147 pNewObj = new OUnoObject(
148 rTargetModel,
149 _xComponent,
150 OUString("com.sun.star.awt.UnoControlFixedLineModel"),
151 nType);
152 break;
153 case OBJ_CUSTOMSHAPE:
154 pNewObj = OCustomShape::Create(
155 rTargetModel,
156 _xComponent);
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");
167 break;
168 case OBJ_DLG_SUBREPORT:
169 case OBJ_OLE2:
170 pNewObj = OOle2Obj::Create(
171 rTargetModel,
172 _xComponent,
173 nType);
174 break;
175 default:
176 OSL_FAIL("Unknown object id");
177 break;
180 if ( pNewObj )
181 pNewObj->SetDoNotInsertIntoPageAutomatically( true );
183 ensureSdrObjectOwnership( _xComponent );
185 return pNewObj;
188 namespace
190 class ParaAdjust : public AnyConverter
192 public:
193 virtual css::uno::Any operator() (const OUString& _sPropertyName,const css::uno::Any& lhs) const override
195 uno::Any aRet;
196 if (_sPropertyName == PROPERTY_PARAADJUST)
198 sal_Int16 nTextAlign = 0;
199 lhs >>= nTextAlign;
200 style::ParagraphAdjust eAdjust;
201 switch(nTextAlign)
203 case awt::TextAlign::LEFT:
204 eAdjust = style::ParagraphAdjust_LEFT;
205 break;
206 case awt::TextAlign::CENTER:
207 eAdjust = style::ParagraphAdjust_CENTER;
208 break;
209 case awt::TextAlign::RIGHT:
210 eAdjust = style::ParagraphAdjust_RIGHT;
211 break;
212 default:
213 OSL_FAIL("Illegal text alignment value!");
214 break;
216 aRet <<= eAdjust;
218 else
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;
228 break;
229 case style::ParagraphAdjust_CENTER:
230 nTextAlign = awt::TextAlign::CENTER;
231 break;
232 case style::ParagraphAdjust_RIGHT:
233 nTextAlign = awt::TextAlign::RIGHT;
234 break;
235 default:
236 OSL_FAIL("Illegal text alignment value!");
237 break;
239 aRet <<= nTextAlign;
241 return aRet;
246 const TPropertyNamePair& getPropertyNameMap(sal_uInt16 _nObjectId)
248 switch(_nObjectId)
250 case OBJ_DLG_IMAGECONTROL:
252 static TPropertyNamePair s_aNameMap = [&]()
254 std::shared_ptr<AnyConverter> aNoConverter(new AnyConverter);
255 TPropertyNamePair tmp;
256 tmp.emplace(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter));
257 tmp.emplace(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter));
258 tmp.emplace(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter));
259 return tmp;
260 }();
261 return s_aNameMap;
264 case OBJ_DLG_FIXEDTEXT:
266 static TPropertyNamePair s_aNameMap = [&]()
268 std::shared_ptr<AnyConverter> aNoConverter(new AnyConverter);
269 TPropertyNamePair tmp;
270 tmp.emplace(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter));
271 tmp.emplace(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter));
272 tmp.emplace(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter));
273 tmp.emplace(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter));
274 tmp.emplace(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter));
275 tmp.emplace(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter));
276 tmp.emplace(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter));
277 tmp.emplace(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter));
278 tmp.emplace(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter));
280 std::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust);
281 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust));
282 return tmp;
283 }();
284 return s_aNameMap;
286 case OBJ_DLG_FORMATTEDFIELD:
288 static TPropertyNamePair s_aNameMap = [&]()
290 std::shared_ptr<AnyConverter> aNoConverter(new AnyConverter);
291 TPropertyNamePair tmp;
292 tmp.emplace(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter));
293 tmp.emplace(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter));
294 tmp.emplace(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter));
295 tmp.emplace(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter));
296 tmp.emplace(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter));
297 tmp.emplace(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter));
298 tmp.emplace(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter));
299 tmp.emplace(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter));
300 tmp.emplace(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter));
301 std::shared_ptr<AnyConverter> aParaAdjust(new ParaAdjust);
302 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust));
303 return tmp;
304 }();
305 return s_aNameMap;
308 case OBJ_CUSTOMSHAPE:
310 static TPropertyNamePair s_aNameMap = [&]()
312 std::shared_ptr<AnyConverter> aNoConverter(new AnyConverter);
313 TPropertyNamePair tmp;
314 tmp.emplace(OUString("FillColor"),TPropertyConverter(PROPERTY_CONTROLBACKGROUND,aNoConverter));
315 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aNoConverter));
316 return tmp;
317 }();
318 return s_aNameMap;
321 default:
322 break;
324 static TPropertyNamePair s_aEmptyNameMap;
325 return s_aEmptyNameMap;
329 OObjectBase::OObjectBase(const uno::Reference< report::XReportComponent>& _xComponent)
330 :m_bIsListening(false)
332 m_xReportComponent = _xComponent;
335 OObjectBase::OObjectBase(const OUString& _sComponentName)
336 :m_sComponentName(_sComponentName)
337 ,m_bIsListening(false)
341 OObjectBase::~OObjectBase()
343 m_xMediator.clear();
344 if ( isListening() )
345 EndListening();
346 m_xReportComponent.clear();
349 uno::Reference< report::XSection> OObjectBase::getSection() const
351 uno::Reference< report::XSection> xSection;
352 OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
353 if ( pPage )
354 xSection = pPage->getSection();
355 return xSection;
359 uno::Reference< beans::XPropertySet> OObjectBase::getAwtComponent()
361 return uno::Reference< beans::XPropertySet>();
364 void OObjectBase::StartListening()
366 OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
368 if ( !isListening() && m_xReportComponent.is() )
370 m_bIsListening = true;
372 if ( !m_xPropertyChangeListener.is() )
374 m_xPropertyChangeListener = new OObjectListener( this );
375 // register listener to all properties
376 m_xReportComponent->addPropertyChangeListener( OUString() , m_xPropertyChangeListener );
381 void OObjectBase::EndListening()
383 OSL_ENSURE(!m_xReportComponent.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
385 if ( isListening() && m_xReportComponent.is() )
387 // XPropertyChangeListener
388 if ( m_xPropertyChangeListener.is() )
390 // remove listener
393 m_xReportComponent->removePropertyChangeListener( OUString() , m_xPropertyChangeListener );
395 catch(const uno::Exception &)
397 OSL_FAIL("OObjectBase::EndListening: Exception caught!");
400 m_xPropertyChangeListener.clear();
402 m_bIsListening = false;
405 void OObjectBase::SetPropsFromRect(const tools::Rectangle& _rRect)
407 // set properties
408 OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
409 if ( pPage && !_rRect.IsEmpty() )
411 const uno::Reference<report::XSection>& xSection = pPage->getSection();
412 assert(_rRect.getHeight() >= 0);
413 const sal_uInt32 newHeight( ::std::max(0l, _rRect.getHeight()+_rRect.Top()) );
414 if ( xSection.is() && ( newHeight > xSection->getHeight() ) )
415 xSection->setHeight( newHeight );
417 // TODO
418 //pModel->GetRefDevice()->Invalidate(InvalidateFlags::Children);
422 void OObjectBase::_propertyChange( const beans::PropertyChangeEvent& /*evt*/ )
426 bool OObjectBase::supportsService( const OUString& _sServiceName ) const
428 bool bSupports = false;
430 Reference< lang::XServiceInfo > xServiceInfo( m_xReportComponent , UNO_QUERY );
431 // TODO: cache xServiceInfo as member?
432 if ( xServiceInfo.is() )
433 bSupports = xServiceInfo->supportsService( _sServiceName );
435 return bSupports;
439 void OObjectBase::ensureSdrObjectOwnership( const uno::Reference< uno::XInterface >& _rxShape )
441 // UNDO in the report designer is implemented at the level of the XShapes, not
442 // at the level of SdrObjects. That is, if an object is removed from the report
443 // design, then this happens by removing the XShape from the UNO DrawPage, and
444 // putting this XShape (resp. the ReportComponent which wraps it) into an UNDO
445 // action.
446 // Unfortunately, the SvxDrawPage implementation usually deletes SdrObjects
447 // which are removed from it, which is deadly for us. To prevent this,
448 // we give the XShape implementation the ownership of the SdrObject, which
449 // ensures the SvxDrawPage won't delete it.
450 SvxShape* pShape = SvxShape::getImplementation( _rxShape );
451 OSL_ENSURE( pShape, "OObjectBase::ensureSdrObjectOwnership: can't access the SvxShape!" );
452 if ( pShape )
454 OSL_ENSURE( !pShape->HasSdrObjectOwnership(), "OObjectBase::ensureSdrObjectOwnership: called twice?" );
455 pShape->TakeSdrObjectOwnership();
460 uno::Reference< uno::XInterface > OObjectBase::getUnoShapeOf( SdrObject& _rSdrObject )
462 uno::Reference< uno::XInterface > xShape( _rSdrObject.getWeakUnoShape() );
463 if ( xShape.is() )
464 return xShape;
466 xShape = _rSdrObject.SdrObject::getUnoShape();
467 if ( !xShape.is() )
468 return xShape;
470 ensureSdrObjectOwnership( xShape );
472 m_xKeepShapeAlive = xShape;
473 return xShape;
476 OCustomShape::OCustomShape(
477 SdrModel& rSdrModel,
478 const uno::Reference< report::XReportComponent>& _xComponent)
479 : SdrObjCustomShape(rSdrModel)
480 ,OObjectBase(_xComponent)
482 impl_setUnoShape( uno::Reference< uno::XInterface >(_xComponent,uno::UNO_QUERY) );
483 m_bIsListening = true;
486 OCustomShape::OCustomShape(
487 SdrModel& rSdrModel,
488 const OUString& _sComponentName)
489 : SdrObjCustomShape(rSdrModel)
490 ,OObjectBase(_sComponentName)
492 m_bIsListening = true;
496 OCustomShape::~OCustomShape()
500 sal_uInt16 OCustomShape::GetObjIdentifier() const
502 return sal_uInt16(OBJ_CUSTOMSHAPE);
505 SdrInventor OCustomShape::GetObjInventor() const
507 return SdrInventor::ReportDesign;
510 SdrPage* OCustomShape::GetImplPage() const
512 return getSdrPageFromSdrObject();
515 void OCustomShape::NbcMove( const Size& rSize )
517 if ( m_bIsListening )
519 m_bIsListening = false;
521 if ( m_xReportComponent.is() )
523 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
524 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
525 m_xReportComponent->setPositionX(m_xReportComponent->getPositionX() + rSize.Width());
526 m_xReportComponent->setPositionY(m_xReportComponent->getPositionY() + rSize.Height());
529 // set geometry properties
530 SetPropsFromRect(GetSnapRect());
532 m_bIsListening = true;
534 else
535 SdrObjCustomShape::NbcMove( rSize );
538 void OCustomShape::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
540 SdrObjCustomShape::NbcResize( rRef, xFract, yFract );
542 SetPropsFromRect(GetSnapRect());
545 void OCustomShape::NbcSetLogicRect(const tools::Rectangle& rRect)
547 SdrObjCustomShape::NbcSetLogicRect(rRect);
548 SetPropsFromRect(rRect);
551 bool OCustomShape::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
553 bool bResult = SdrObjCustomShape::EndCreate(rStat, eCmd);
554 if ( bResult )
556 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
557 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
559 if ( !m_xReportComponent.is() )
560 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
562 SetPropsFromRect(GetSnapRect());
565 return bResult;
569 uno::Reference< beans::XPropertySet> OCustomShape::getAwtComponent()
571 return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
575 uno::Reference< uno::XInterface > OCustomShape::getUnoShape()
577 uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
578 if ( !m_xReportComponent.is() )
580 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
581 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
582 m_xReportComponent.set(xShape,uno::UNO_QUERY);
584 return xShape;
587 void OCustomShape::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
589 SdrObjCustomShape::impl_setUnoShape( rxUnoShape );
590 releaseUnoShape();
591 m_xReportComponent.clear();
594 OUnoObject::OUnoObject(
595 SdrModel& rSdrModel,
596 const OUString& _sComponentName,
597 const OUString& rModelName,
598 sal_uInt16 _nObjectType)
599 : SdrUnoObj(rSdrModel, rModelName)
600 ,OObjectBase(_sComponentName)
601 ,m_nObjectType(_nObjectType)
602 // tdf#119067
603 ,m_bSetDefaultLabel(false)
605 if ( !rModelName.isEmpty() )
606 impl_initializeModel_nothrow();
609 OUnoObject::OUnoObject(
610 SdrModel& rSdrModel,
611 const uno::Reference< report::XReportComponent>& _xComponent,
612 const OUString& rModelName,
613 sal_uInt16 _nObjectType)
614 : SdrUnoObj(rSdrModel, rModelName)
615 ,OObjectBase(_xComponent)
616 ,m_nObjectType(_nObjectType)
617 // tdf#119067
618 ,m_bSetDefaultLabel(false)
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( false ) );
641 xModelProps->setPropertyValue( PROPERTY_VERTICALALIGN,m_xReportComponent->getPropertyValue(PROPERTY_VERTICALALIGN));
644 catch( const Exception& )
646 DBG_UNHANDLED_EXCEPTION("reportdesign");
650 sal_uInt16 OUnoObject::GetObjIdentifier() const
652 return m_nObjectType;
655 SdrInventor OUnoObject::GetObjInventor() const
657 return SdrInventor::ReportDesign;
660 SdrPage* OUnoObject::GetImplPage() const
662 return getSdrPageFromSdrObject();
665 void OUnoObject::NbcMove( const Size& rSize )
668 if ( m_bIsListening )
670 // stop listening
671 OObjectBase::EndListening();
673 bool bPositionFixed = false;
674 Size aUndoSize(0,0);
675 if ( m_xReportComponent.is() )
677 bool bUndoMode = false;
678 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
680 if (rRptModel.GetUndoEnv().IsUndoMode())
682 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
683 bUndoMode = true;
685 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
687 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
688 int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
689 m_xReportComponent->setPositionX(nNewX);
690 int nNewY = m_xReportComponent->getPositionY() + rSize.Height();
691 if (nNewY < 0 && !bUndoMode)
693 aUndoSize.setHeight( abs(nNewY) );
694 bPositionFixed = true;
695 nNewY = 0;
697 m_xReportComponent->setPositionY(nNewY);
699 if (bPositionFixed)
701 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
703 // set geometry properties
704 SetPropsFromRect(GetLogicRect());
706 // start listening
707 OObjectBase::StartListening();
709 else
710 SdrUnoObj::NbcMove( rSize );
714 void OUnoObject::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
716 SdrUnoObj::NbcResize( rRef, xFract, yFract );
718 // stop listening
719 OObjectBase::EndListening();
721 // set geometry properties
722 SetPropsFromRect(GetLogicRect());
724 // start listening
725 OObjectBase::StartListening();
728 void OUnoObject::NbcSetLogicRect(const tools::Rectangle& rRect)
730 SdrUnoObj::NbcSetLogicRect(rRect);
731 // stop listening
732 OObjectBase::EndListening();
734 // set geometry properties
735 SetPropsFromRect(rRect);
737 // start listening
738 OObjectBase::StartListening();
741 bool OUnoObject::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
743 const bool bResult(SdrUnoObj::EndCreate(rStat, eCmd));
745 if(bResult)
747 // tdf#118730 remember if this object was created interactively (due to ::EndCreate being called)
748 m_bSetDefaultLabel = true;
750 // set geometry properties
751 SetPropsFromRect(GetLogicRect());
754 return bResult;
757 OUString OUnoObject::GetDefaultName(const OUnoObject* _pObj)
759 OUString aDefaultName = "HERE WE HAVE TO INSERT OUR NAME!";
760 if ( _pObj->supportsService( SERVICE_FIXEDTEXT ) )
762 aDefaultName = RID_STR_CLASS_FIXEDTEXT;
764 else if ( _pObj->supportsService( SERVICE_FIXEDLINE ) )
766 aDefaultName = RID_STR_CLASS_FIXEDLINE;
768 else if ( _pObj->supportsService( SERVICE_IMAGECONTROL ) )
770 aDefaultName = RID_STR_CLASS_IMAGECONTROL;
772 else if ( _pObj->supportsService( SERVICE_FORMATTEDFIELD ) )
774 aDefaultName = RID_STR_CLASS_FORMATTEDFIELD;
777 return aDefaultName;
780 void OUnoObject::_propertyChange( const beans::PropertyChangeEvent& evt )
782 OObjectBase::_propertyChange(evt);
783 if (isListening())
785 if ( evt.PropertyName == PROPERTY_CHARCOLOR )
787 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
788 if ( xControlModel.is() )
790 OObjectBase::EndListening();
793 xControlModel->setPropertyValue(PROPERTY_TEXTCOLOR,evt.NewValue);
795 catch(uno::Exception&)
798 OObjectBase::StartListening();
801 else if ( evt.PropertyName == PROPERTY_NAME )
803 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
804 if ( xControlModel.is() && xControlModel->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) )
806 // get old name
807 OUString aOldName;
808 evt.OldValue >>= aOldName;
810 // get new name
811 OUString aNewName;
812 evt.NewValue >>= aNewName;
814 if ( aNewName != aOldName )
816 // set old name property
817 OObjectBase::EndListening();
818 if ( m_xMediator.is() )
819 m_xMediator->stopListening();
822 xControlModel->setPropertyValue( PROPERTY_NAME, evt.NewValue );
824 catch(uno::Exception&)
827 if ( m_xMediator.is() )
828 m_xMediator->startListening();
829 OObjectBase::StartListening();
836 void OUnoObject::CreateMediator(bool _bReverse)
838 if ( !m_xMediator.is() )
840 // tdf#118730 Directly do things formerly done in
841 // OUnoObject::impl_setReportComponent_nothrow here
842 if(!m_xReportComponent.is())
844 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
845 OXUndoEnvironment::OUndoEnvLock aLock( rRptModel.GetUndoEnv() );
846 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
848 impl_initializeModel_nothrow();
851 if(m_xReportComponent.is() && m_bSetDefaultLabel)
853 // tdf#118730 Directly do things formerly done in
854 // OUnoObject::EndCreate here
855 // tdf#119067 ...but *only* if result of interactive
856 // creation in Report DesignView
857 m_bSetDefaultLabel = false;
861 if ( supportsService( SERVICE_FIXEDTEXT ) )
863 m_xReportComponent->setPropertyValue(
864 PROPERTY_LABEL,
865 uno::makeAny(GetDefaultName(this)));
868 catch(const uno::Exception&)
870 DBG_UNHANDLED_EXCEPTION("reportdesign");
874 if(!m_xMediator.is() && m_xReportComponent.is())
876 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
878 if(xControlModel.is())
880 m_xMediator = new OPropertyMediator(
881 m_xReportComponent.get(),
882 xControlModel,
883 getPropertyNameMap(GetObjIdentifier()),
884 _bReverse);
888 OObjectBase::StartListening();
892 uno::Reference< beans::XPropertySet> OUnoObject::getAwtComponent()
894 return Reference<XPropertySet>(GetUnoControlModel(),uno::UNO_QUERY);
898 uno::Reference< uno::XInterface > OUnoObject::getUnoShape()
900 return OObjectBase::getUnoShapeOf( *this );
903 void OUnoObject::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
905 SdrUnoObj::impl_setUnoShape( rxUnoShape );
906 releaseUnoShape();
909 OUnoObject* OUnoObject::CloneSdrObject(SdrModel& rTargetModel) const
911 return CloneHelper< OUnoObject >(rTargetModel);
914 OUnoObject& OUnoObject::operator=(const OUnoObject& rObj)
916 if( this == &rObj )
917 return *this;
918 SdrUnoObj::operator=(rObj);
920 Reference<XPropertySet> xSource(const_cast<OUnoObject&>(rObj).getUnoShape(), uno::UNO_QUERY);
921 Reference<XPropertySet> xDest(getUnoShape(), uno::UNO_QUERY);
922 if ( xSource.is() && xDest.is() )
923 comphelper::copyProperties(xSource.get(), xDest.get());
925 return *this;
928 // OOle2Obj
929 OOle2Obj::OOle2Obj(
930 SdrModel& rSdrModel,
931 const uno::Reference< report::XReportComponent>& _xComponent,
932 sal_uInt16 _nType)
933 : SdrOle2Obj(rSdrModel)
934 ,OObjectBase(_xComponent)
935 ,m_nType(_nType)
936 ,m_bOnlyOnce(true)
938 impl_setUnoShape( uno::Reference< uno::XInterface >( _xComponent, uno::UNO_QUERY ) );
939 m_bIsListening = true;
942 OOle2Obj::OOle2Obj(
943 SdrModel& rSdrModel,
944 const OUString& _sComponentName,
945 sal_uInt16 _nType)
946 : SdrOle2Obj(rSdrModel)
947 ,OObjectBase(_sComponentName)
948 ,m_nType(_nType)
949 ,m_bOnlyOnce(true)
951 m_bIsListening = true;
954 OOle2Obj::~OOle2Obj()
958 sal_uInt16 OOle2Obj::GetObjIdentifier() const
960 return m_nType;
963 SdrInventor OOle2Obj::GetObjInventor() const
965 return SdrInventor::ReportDesign;
968 SdrPage* OOle2Obj::GetImplPage() const
970 return getSdrPageFromSdrObject();
973 void OOle2Obj::NbcMove( const Size& rSize )
976 if ( m_bIsListening )
978 // stop listening
979 OObjectBase::EndListening();
981 bool bPositionFixed = false;
982 Size aUndoSize(0,0);
983 if ( m_xReportComponent.is() )
985 bool bUndoMode = false;
986 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
988 if (rRptModel.GetUndoEnv().IsUndoMode())
990 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
991 bUndoMode = true;
993 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
995 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
996 int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
997 // can this hinder us to set components outside the area?
998 // if (nNewX < 0)
999 // {
1000 // nNewX = 0;
1001 // }
1002 m_xReportComponent->setPositionX(nNewX);
1003 int nNewY = m_xReportComponent->getPositionY() + rSize.Height();
1004 if (nNewY < 0 && !bUndoMode)
1006 aUndoSize.setHeight( abs(nNewY) );
1007 bPositionFixed = true;
1008 nNewY = 0;
1010 m_xReportComponent->setPositionY(nNewY);
1012 if (bPositionFixed)
1014 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
1016 // set geometry properties
1017 SetPropsFromRect(GetLogicRect());
1019 // start listening
1020 OObjectBase::StartListening();
1022 else
1023 SdrOle2Obj::NbcMove( rSize );
1027 void OOle2Obj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1029 SdrOle2Obj::NbcResize( rRef, xFract, yFract );
1031 // stop listening
1032 OObjectBase::EndListening();
1034 // set geometry properties
1035 SetPropsFromRect(GetLogicRect());
1037 // start listening
1038 OObjectBase::StartListening();
1041 void OOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect)
1043 SdrOle2Obj::NbcSetLogicRect(rRect);
1044 // stop listening
1045 OObjectBase::EndListening();
1047 // set geometry properties
1048 SetPropsFromRect(rRect);
1050 // start listening
1051 OObjectBase::StartListening();
1055 bool OOle2Obj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1057 bool bResult = SdrOle2Obj::EndCreate(rStat, eCmd);
1058 if ( bResult )
1060 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1061 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
1063 if ( !m_xReportComponent.is() )
1064 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
1066 // set geometry properties
1067 SetPropsFromRect(GetLogicRect());
1070 return bResult;
1073 uno::Reference< beans::XPropertySet> OOle2Obj::getAwtComponent()
1075 return uno::Reference< beans::XPropertySet>(m_xReportComponent,uno::UNO_QUERY);
1079 uno::Reference< uno::XInterface > OOle2Obj::getUnoShape()
1081 uno::Reference< uno::XInterface> xShape = OObjectBase::getUnoShapeOf( *this );
1082 if ( !m_xReportComponent.is() )
1084 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1085 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
1086 m_xReportComponent.set(xShape,uno::UNO_QUERY);
1088 return xShape;
1091 void OOle2Obj::impl_setUnoShape( const uno::Reference< uno::XInterface >& rxUnoShape )
1093 SdrOle2Obj::impl_setUnoShape( rxUnoShape );
1094 releaseUnoShape();
1095 m_xReportComponent.clear();
1099 static uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const uno::Reference < embed::XEmbeddedObject >& _xObj)
1101 uno::Reference< chart2::data::XDatabaseDataProvider > xSource;
1102 uno::Reference< embed::XComponentSupplier > xCompSupp(_xObj,uno::UNO_QUERY);
1103 if( xCompSupp.is())
1105 uno::Reference< chart2::XChartDocument> xChartDoc( xCompSupp->getComponent(), uno::UNO_QUERY );
1106 if ( xChartDoc.is() )
1108 xSource.set(xChartDoc->getDataProvider(),uno::UNO_QUERY);
1111 return xSource;
1114 // Clone() should make a complete copy of the object.
1115 OOle2Obj* OOle2Obj::CloneSdrObject(SdrModel& rTargetModel) const
1117 return CloneHelper< OOle2Obj >(rTargetModel);
1120 OOle2Obj& OOle2Obj::operator=(const OOle2Obj& rObj)
1122 if( this == &rObj )
1123 return *this;
1124 SdrOle2Obj::operator=(rObj);
1126 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1127 svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
1128 impl_createDataProvider_nothrow(rRptModel.getReportDefinition().get());
1130 uno::Reference< chart2::data::XDatabaseDataProvider > xSource( lcl_getDataProvider(rObj.GetObjRef()) );
1131 uno::Reference< chart2::data::XDatabaseDataProvider > xDest( lcl_getDataProvider(GetObjRef()) );
1132 if ( xSource.is() && xDest.is() )
1133 comphelper::copyProperties(xSource.get(),xDest.get());
1135 initializeChart(rRptModel.getReportDefinition().get());
1137 return *this;
1140 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference< frame::XModel>& _xModel)
1144 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1145 uno::Reference< chart2::data::XDataReceiver > xReceiver;
1146 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1147 if( xCompSupp.is())
1148 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1149 OSL_ASSERT( xReceiver.is());
1150 if( xReceiver.is() )
1152 uno::Reference< lang::XMultiServiceFactory> xFac(_xModel,uno::UNO_QUERY);
1153 uno::Reference< chart2::data::XDatabaseDataProvider > xDataProvider( xFac->createInstance("com.sun.star.chart2.data.DataProvider"),uno::UNO_QUERY);
1154 xReceiver->attachDataProvider( xDataProvider.get() );
1157 catch(const uno::Exception &)
1162 void OOle2Obj::initializeOle()
1164 if ( m_bOnlyOnce )
1166 m_bOnlyOnce = false;
1167 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1168 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1169 rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1171 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1172 if( xCompSupp.is() )
1174 uno::Reference< beans::XPropertySet > xChartProps( xCompSupp->getComponent(), uno::UNO_QUERY );
1175 if ( xChartProps.is() )
1176 xChartProps->setPropertyValue("NullDate",
1177 uno::makeAny(util::DateTime(0,0,0,0,30,12,1899,false)));
1182 void OOle2Obj::initializeChart( const uno::Reference< frame::XModel>& _xModel)
1184 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1185 uno::Reference< chart2::data::XDataReceiver > xReceiver;
1186 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj, uno::UNO_QUERY );
1187 if( xCompSupp.is())
1188 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1189 OSL_ASSERT( xReceiver.is());
1190 if( xReceiver.is() )
1192 // lock the model to suppress any internal updates
1193 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
1194 if( xChartModel.is() )
1195 xChartModel->lockControllers();
1197 if ( !lcl_getDataProvider(xObj).is() )
1198 impl_createDataProvider_nothrow(_xModel);
1200 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1201 rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1203 ::comphelper::NamedValueCollection aArgs;
1204 aArgs.put( "CellRangeRepresentation", uno::makeAny( OUString( "all" ) ) );
1205 aArgs.put( "HasCategories", uno::makeAny( true ) );
1206 aArgs.put( "FirstCellAsLabel", uno::makeAny( true ) );
1207 aArgs.put( "DataRowSource", uno::makeAny( chart::ChartDataRowSource_COLUMNS ) );
1208 xReceiver->setArguments( aArgs.getPropertyValues() );
1210 if( xChartModel.is() )
1211 xChartModel->unlockControllers();
1215 uno::Reference< style::XStyle> getUsedStyle(const uno::Reference< report::XReportDefinition>& _xReport)
1217 uno::Reference<container::XNameAccess> xStyles = _xReport->getStyleFamilies();
1218 uno::Reference<container::XNameAccess> xPageStyles(xStyles->getByName("PageStyles"),uno::UNO_QUERY);
1220 uno::Reference< style::XStyle> xReturn;
1221 uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
1222 const OUString* pIter = aSeq.getConstArray();
1223 const OUString* pEnd = pIter + aSeq.getLength();
1224 for(;pIter != pEnd && !xReturn.is() ;++pIter)
1226 uno::Reference< style::XStyle> xStyle(xPageStyles->getByName(*pIter),uno::UNO_QUERY);
1227 if ( xStyle->isInUse() )
1228 xReturn = xStyle;
1230 return xReturn;
1234 } // rptui
1237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */