tdf#130857 qt weld: Implement QtInstanceWidget::strip_mnemonic
[LibreOffice.git] / reportdesign / source / core / sdr / RptObject.cxx
blobe6d0496a954861ade08a975c520ac9582a428eb6
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 <algorithm>
22 #include <RptDef.hxx>
23 #include <svx/unoshape.hxx>
24 #include <RptModel.hxx>
25 #include <RptObjectListener.hxx>
26 #include <RptPage.hxx>
28 #include <strings.hxx>
29 #include <svtools/embedhlp.hxx>
30 #include <com/sun/star/style/XStyle.hpp>
31 #include <com/sun/star/awt/TextAlign.hpp>
32 #include <com/sun/star/beans/XPropertySet.hpp>
33 #include <com/sun/star/embed/XComponentSupplier.hpp>
34 #include <com/sun/star/embed/XEmbeddedObject.hpp>
35 #include <com/sun/star/lang/XServiceInfo.hpp>
36 #include <com/sun/star/report/XFixedLine.hpp>
37 #include <com/sun/star/chart/ChartDataRowSource.hpp>
38 #include <com/sun/star/chart2/data/XDataReceiver.hpp>
39 #include <com/sun/star/chart2/data/XDatabaseDataProvider.hpp>
40 #include <com/sun/star/chart2/XChartDocument.hpp>
41 #include <com/sun/star/style/ParagraphAdjust.hpp>
42 #include <com/sun/star/report/XFormattedField.hpp>
43 #include <cppuhelper/supportsservice.hxx>
44 #include <comphelper/namedvaluecollection.hxx>
45 #include <comphelper/property.hxx>
46 #include <svx/svdundo.hxx>
47 #include <comphelper/diagnose_ex.hxx>
48 #include <PropertyForward.hxx>
49 #include <UndoEnv.hxx>
50 #include <utility>
52 namespace rptui
55 using namespace ::com::sun::star;
56 using namespace uno;
57 using namespace beans;
58 using namespace reportdesign;
59 using namespace container;
60 using namespace report;
62 SdrObjKind OObjectBase::getObjectType(const uno::Reference< report::XReportComponent>& _xComponent)
64 uno::Reference< lang::XServiceInfo > xServiceInfo( _xComponent , uno::UNO_QUERY );
65 OSL_ENSURE(xServiceInfo.is(),"Who deletes the XServiceInfo interface!");
66 if ( !xServiceInfo )
67 return SdrObjKind::NONE;
69 if ( xServiceInfo->supportsService( SERVICE_FIXEDTEXT ))
70 return SdrObjKind::ReportDesignFixedText;
71 if ( xServiceInfo->supportsService( SERVICE_FIXEDLINE ))
73 uno::Reference< report::XFixedLine> xFixedLine(_xComponent,uno::UNO_QUERY);
74 return xFixedLine->getOrientation() ? SdrObjKind::ReportDesignHorizontalFixedLine : SdrObjKind::ReportDesignVerticalFixedLine;
76 if ( xServiceInfo->supportsService( SERVICE_IMAGECONTROL))
77 return SdrObjKind::ReportDesignImageControl;
78 if ( xServiceInfo->supportsService( SERVICE_FORMATTEDFIELD ))
79 return SdrObjKind::ReportDesignFormattedField;
80 if ( xServiceInfo->supportsService(u"com.sun.star.drawing.OLE2Shape"_ustr) )
81 return SdrObjKind::OLE2;
82 if ( xServiceInfo->supportsService( SERVICE_SHAPE ))
83 return SdrObjKind::CustomShape;
84 if ( xServiceInfo->supportsService( SERVICE_REPORTDEFINITION ) )
85 return SdrObjKind::ReportDesignSubReport;
86 return SdrObjKind::OLE2;
89 rtl::Reference<SdrObject> OObjectBase::createObject(
90 SdrModel& rTargetModel,
91 const uno::Reference< report::XReportComponent>& _xComponent)
93 rtl::Reference<SdrObject> pNewObj;
94 SdrObjKind nType = OObjectBase::getObjectType(_xComponent);
95 switch( nType )
97 case SdrObjKind::ReportDesignFixedText:
99 rtl::Reference<OUnoObject> pUnoObj = new OUnoObject(
100 rTargetModel,
101 _xComponent,
102 u"com.sun.star.form.component.FixedText"_ustr,
103 SdrObjKind::ReportDesignFixedText);
104 pNewObj = pUnoObj;
106 uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
107 if ( xControlModel.is() )
108 xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::Any(true));
110 break;
111 case SdrObjKind::ReportDesignImageControl:
112 pNewObj = new OUnoObject(
113 rTargetModel,
114 _xComponent,
115 u"com.sun.star.form.component.DatabaseImageControl"_ustr,
116 SdrObjKind::ReportDesignImageControl);
117 break;
118 case SdrObjKind::ReportDesignFormattedField:
119 pNewObj = new OUnoObject(
120 rTargetModel,
121 _xComponent,
122 u"com.sun.star.form.component.FormattedField"_ustr,
123 SdrObjKind::ReportDesignFormattedField);
124 break;
125 case SdrObjKind::ReportDesignHorizontalFixedLine:
126 case SdrObjKind::ReportDesignVerticalFixedLine:
127 pNewObj = new OUnoObject(
128 rTargetModel,
129 _xComponent,
130 u"com.sun.star.awt.UnoControlFixedLineModel"_ustr,
131 nType);
132 break;
133 case SdrObjKind::CustomShape:
134 pNewObj = OCustomShape::Create(
135 rTargetModel,
136 _xComponent);
139 bool bOpaque = false;
140 _xComponent->getPropertyValue(PROPERTY_OPAQUE) >>= bOpaque;
141 pNewObj->NbcSetLayer(bOpaque ? RPT_LAYER_FRONT : RPT_LAYER_BACK);
143 catch(const uno::Exception&)
145 DBG_UNHANDLED_EXCEPTION("reportdesign");
147 break;
148 case SdrObjKind::ReportDesignSubReport:
149 case SdrObjKind::OLE2:
150 pNewObj = OOle2Obj::Create(
151 rTargetModel,
152 _xComponent,
153 nType);
154 break;
155 default:
156 OSL_FAIL("Unknown object id");
157 break;
160 if ( pNewObj )
161 pNewObj->SetDoNotInsertIntoPageAutomatically( true );
163 return pNewObj;
166 namespace
168 class ParaAdjust : public AnyConverter
170 public:
171 virtual css::uno::Any operator() (const OUString& _sPropertyName,const css::uno::Any& lhs) const override
173 uno::Any aRet;
174 if (_sPropertyName == PROPERTY_PARAADJUST)
176 sal_Int16 nTextAlign = 0;
177 lhs >>= nTextAlign;
178 style::ParagraphAdjust eAdjust;
179 switch(nTextAlign)
181 case awt::TextAlign::LEFT:
182 eAdjust = style::ParagraphAdjust_LEFT;
183 break;
184 case awt::TextAlign::CENTER:
185 eAdjust = style::ParagraphAdjust_CENTER;
186 break;
187 case awt::TextAlign::RIGHT:
188 eAdjust = style::ParagraphAdjust_RIGHT;
189 break;
190 default:
191 OSL_FAIL("Illegal text alignment value!");
192 break;
194 aRet <<= eAdjust;
196 else
198 sal_Int16 nTextAlign = 0;
199 sal_Int16 eParagraphAdjust = 0;
200 lhs >>= eParagraphAdjust;
201 switch(static_cast<style::ParagraphAdjust>(eParagraphAdjust))
203 case style::ParagraphAdjust_LEFT:
204 case style::ParagraphAdjust_BLOCK:
205 nTextAlign = awt::TextAlign::LEFT;
206 break;
207 case style::ParagraphAdjust_CENTER:
208 nTextAlign = awt::TextAlign::CENTER;
209 break;
210 case style::ParagraphAdjust_RIGHT:
211 nTextAlign = awt::TextAlign::RIGHT;
212 break;
213 default:
214 OSL_FAIL("Illegal text alignment value!");
215 break;
217 aRet <<= nTextAlign;
219 return aRet;
224 const TPropertyNamePair& getPropertyNameMap(SdrObjKind _nObjectId)
226 switch(_nObjectId)
228 case SdrObjKind::ReportDesignImageControl:
230 static TPropertyNamePair s_aNameMap = []()
232 auto aNoConverter = std::make_shared<AnyConverter>();
233 TPropertyNamePair tmp;
234 tmp.emplace(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter));
235 tmp.emplace(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter));
236 tmp.emplace(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter));
237 return tmp;
238 }();
239 return s_aNameMap;
242 case SdrObjKind::ReportDesignFixedText:
244 static TPropertyNamePair s_aNameMap = []()
246 auto aNoConverter = std::make_shared<AnyConverter>();
247 TPropertyNamePair tmp;
248 tmp.emplace(PROPERTY_CHARCOLOR,TPropertyConverter(PROPERTY_TEXTCOLOR,aNoConverter));
249 tmp.emplace(PROPERTY_CONTROLBACKGROUND,TPropertyConverter(PROPERTY_BACKGROUNDCOLOR,aNoConverter));
250 tmp.emplace(PROPERTY_CHARUNDERLINECOLOR,TPropertyConverter(PROPERTY_TEXTLINECOLOR,aNoConverter));
251 tmp.emplace(PROPERTY_CHARRELIEF,TPropertyConverter(PROPERTY_FONTRELIEF,aNoConverter));
252 tmp.emplace(PROPERTY_CHARFONTHEIGHT,TPropertyConverter(PROPERTY_FONTHEIGHT,aNoConverter));
253 tmp.emplace(PROPERTY_CHARSTRIKEOUT,TPropertyConverter(PROPERTY_FONTSTRIKEOUT,aNoConverter));
254 tmp.emplace(PROPERTY_CONTROLTEXTEMPHASISMARK,TPropertyConverter(PROPERTY_FONTEMPHASISMARK,aNoConverter));
255 tmp.emplace(PROPERTY_CONTROLBORDER,TPropertyConverter(PROPERTY_BORDER,aNoConverter));
256 tmp.emplace(PROPERTY_CONTROLBORDERCOLOR,TPropertyConverter(PROPERTY_BORDERCOLOR,aNoConverter));
258 auto aParaAdjust = std::make_shared<ParaAdjust>();
259 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust));
260 return tmp;
261 }();
262 return s_aNameMap;
264 case SdrObjKind::ReportDesignFormattedField:
266 static TPropertyNamePair s_aNameMap = []()
268 auto aNoConverter = std::make_shared<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));
279 auto aParaAdjust = std::make_shared<ParaAdjust>();
280 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aParaAdjust));
281 return tmp;
282 }();
283 return s_aNameMap;
286 case SdrObjKind::CustomShape:
288 static TPropertyNamePair s_aNameMap = []()
290 auto aNoConverter = std::make_shared<AnyConverter>();
291 TPropertyNamePair tmp;
292 tmp.emplace(u"FillColor"_ustr,TPropertyConverter(PROPERTY_CONTROLBACKGROUND,aNoConverter));
293 tmp.emplace(PROPERTY_PARAADJUST,TPropertyConverter(PROPERTY_ALIGN,aNoConverter));
294 return tmp;
295 }();
296 return s_aNameMap;
299 default:
300 break;
302 static TPropertyNamePair s_aEmptyNameMap;
303 return s_aEmptyNameMap;
307 OObjectBase::OObjectBase(const uno::Reference< report::XReportComponent>& _xComponent)
308 :m_bIsListening(false)
310 m_xReportComponent = _xComponent;
313 OObjectBase::OObjectBase(OUString _sComponentName)
314 :m_sComponentName(std::move(_sComponentName))
315 ,m_bIsListening(false)
317 assert(!m_sComponentName.isEmpty());
320 OObjectBase::~OObjectBase()
322 m_xMediator.clear();
323 if ( isListening() )
324 EndListening();
325 m_xReportComponent.clear();
328 uno::Reference< report::XSection> OObjectBase::getSection() const
330 uno::Reference< report::XSection> xSection;
331 OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
332 if ( pPage )
333 xSection = pPage->getSection();
334 return xSection;
338 uno::Reference< beans::XPropertySet> OObjectBase::getAwtComponent()
340 return uno::Reference< beans::XPropertySet>();
343 void OObjectBase::StartListening()
345 OSL_ENSURE(!isListening(), "OUnoObject::StartListening: already listening!");
347 if ( !isListening() && m_xReportComponent.is() )
349 m_bIsListening = true;
351 if ( !m_xPropertyChangeListener.is() )
353 m_xPropertyChangeListener = new OObjectListener( this );
354 // register listener to all properties
355 m_xReportComponent->addPropertyChangeListener( OUString() , m_xPropertyChangeListener );
360 void OObjectBase::EndListening()
362 OSL_ENSURE(!m_xReportComponent.is() || isListening(), "OUnoObject::EndListening: not listening currently!");
364 if ( isListening() && m_xReportComponent.is() )
366 // XPropertyChangeListener
367 if ( m_xPropertyChangeListener.is() )
369 // remove listener
372 m_xReportComponent->removePropertyChangeListener( OUString() , m_xPropertyChangeListener );
374 catch(const uno::Exception &)
376 TOOLS_WARN_EXCEPTION( "package", "OObjectBase::EndListening");
379 m_xPropertyChangeListener.clear();
381 m_bIsListening = false;
384 void OObjectBase::SetPropsFromRect(const tools::Rectangle& _rRect)
386 // set properties
387 OReportPage* pPage = dynamic_cast<OReportPage*>(GetImplPage());
388 if ( pPage && !_rRect.IsEmpty() )
390 const uno::Reference<report::XSection>& xSection = pPage->getSection();
391 assert(_rRect.getOpenHeight() >= 0);
392 const sal_uInt32 newHeight( ::std::max(tools::Long(0), _rRect.getOpenHeight()+_rRect.Top()) );
393 if ( xSection.is() && ( newHeight > xSection->getHeight() ) )
394 xSection->setHeight( newHeight );
396 // TODO
397 //pModel->GetRefDevice()->Invalidate(InvalidateFlags::Children);
401 void OObjectBase::_propertyChange( const beans::PropertyChangeEvent& /*evt*/ )
405 bool OObjectBase::supportsService( const OUString& _sServiceName ) const
407 // TODO: cache xServiceInfo as member?
408 Reference< lang::XServiceInfo > xServiceInfo( m_xReportComponent , UNO_QUERY );
410 if ( xServiceInfo.is() )
411 return cppu::supportsService(xServiceInfo.get(), _sServiceName);
412 else
413 return false;
417 uno::Reference< drawing::XShape > OObjectBase::getUnoShapeOf( SdrObject& _rSdrObject )
419 uno::Reference< drawing::XShape > xShape( _rSdrObject.getWeakUnoShape() );
420 if ( xShape.is() )
421 return xShape;
423 xShape = _rSdrObject.SdrObject::getUnoShape();
424 if ( !xShape.is() )
425 return xShape;
427 m_xKeepShapeAlive = xShape;
428 return xShape;
431 OCustomShape::OCustomShape(
432 SdrModel& rSdrModel,
433 const uno::Reference< report::XReportComponent>& _xComponent)
434 : SdrObjCustomShape(rSdrModel)
435 ,OObjectBase(_xComponent)
437 setUnoShape( uno::Reference< drawing::XShape >(_xComponent,uno::UNO_QUERY_THROW) );
438 m_bIsListening = true;
441 OCustomShape::OCustomShape(
442 SdrModel& rSdrModel)
443 : SdrObjCustomShape(rSdrModel)
444 ,OObjectBase(SERVICE_SHAPE)
446 m_bIsListening = true;
450 OCustomShape::~OCustomShape()
454 SdrObjKind OCustomShape::GetObjIdentifier() const
456 return SdrObjKind::CustomShape;
459 SdrInventor OCustomShape::GetObjInventor() const
461 return SdrInventor::ReportDesign;
464 SdrPage* OCustomShape::GetImplPage() const
466 return getSdrPageFromSdrObject();
469 void OCustomShape::NbcMove( const Size& rSize )
471 if ( m_bIsListening )
473 m_bIsListening = false;
475 if ( m_xReportComponent.is() )
477 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
478 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
479 m_xReportComponent->setPositionX(m_xReportComponent->getPositionX() + rSize.Width());
480 m_xReportComponent->setPositionY(m_xReportComponent->getPositionY() + rSize.Height());
483 // set geometry properties
484 SetPropsFromRect(GetSnapRect());
486 m_bIsListening = true;
488 else
489 SdrObjCustomShape::NbcMove( rSize );
492 void OCustomShape::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
494 SdrObjCustomShape::NbcResize( rRef, xFract, yFract );
496 SetPropsFromRect(GetSnapRect());
499 void OCustomShape::NbcSetLogicRect(const tools::Rectangle& rRect, bool bAdaptTextMinSize)
501 SdrObjCustomShape::NbcSetLogicRect(rRect, bAdaptTextMinSize);
502 SetPropsFromRect(rRect);
505 bool OCustomShape::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
507 bool bResult = SdrObjCustomShape::EndCreate(rStat, eCmd);
508 if ( bResult )
510 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
511 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
513 if ( !m_xReportComponent.is() )
514 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
516 SetPropsFromRect(GetSnapRect());
519 return bResult;
523 uno::Reference< beans::XPropertySet> OCustomShape::getAwtComponent()
525 return m_xReportComponent;
529 uno::Reference< drawing::XShape > OCustomShape::getUnoShape()
531 uno::Reference<drawing::XShape> xShape = OObjectBase::getUnoShapeOf( *this );
532 if ( !m_xReportComponent.is() )
534 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
535 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
536 m_xReportComponent.set(xShape,uno::UNO_QUERY);
538 return xShape;
541 void OCustomShape::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape )
543 SdrObjCustomShape::setUnoShape( rxUnoShape );
544 releaseUnoShape();
545 m_xReportComponent.clear();
548 static OUString ObjectTypeToServiceName(SdrObjKind _nObjectType)
550 switch (_nObjectType)
552 case SdrObjKind::ReportDesignFixedText:
553 return SERVICE_FIXEDTEXT;
554 case SdrObjKind::ReportDesignImageControl:
555 return SERVICE_IMAGECONTROL;
556 case SdrObjKind::ReportDesignFormattedField:
557 return SERVICE_FORMATTEDFIELD;
558 case SdrObjKind::ReportDesignVerticalFixedLine:
559 case SdrObjKind::ReportDesignHorizontalFixedLine:
560 return SERVICE_FIXEDLINE;
561 case SdrObjKind::CustomShape:
562 return SERVICE_SHAPE;
563 case SdrObjKind::ReportDesignSubReport:
564 return SERVICE_REPORTDEFINITION;
565 case SdrObjKind::OLE2:
566 return u"com.sun.star.chart2.ChartDocument"_ustr;
567 default:
568 break;
570 assert(false && "Unknown object id");
571 return u""_ustr;
573 OUnoObject::OUnoObject(
574 SdrModel& rSdrModel,
575 const OUString& rModelName,
576 SdrObjKind _nObjectType)
577 : SdrUnoObj(rSdrModel, rModelName)
578 ,OObjectBase(ObjectTypeToServiceName(_nObjectType))
579 ,m_nObjectType(_nObjectType)
580 // tdf#119067
581 ,m_bSetDefaultLabel(false)
583 if ( !rModelName.isEmpty() )
584 impl_initializeModel_nothrow();
587 OUnoObject::OUnoObject(
588 SdrModel& rSdrModel, OUnoObject const & rSource)
589 : SdrUnoObj(rSdrModel, rSource)
590 ,OObjectBase(ObjectTypeToServiceName(rSource.m_nObjectType)) // source may not have a service name
591 ,m_nObjectType(rSource.m_nObjectType)
592 // tdf#119067
593 ,m_bSetDefaultLabel(rSource.m_bSetDefaultLabel)
595 osl_atomic_increment(&m_refCount); // getUnoShape will ref-count this
597 if ( !rSource.getUnoControlModelTypeName().isEmpty() )
598 impl_initializeModel_nothrow();
599 Reference<XPropertySet> xSource(const_cast<OUnoObject&>(rSource).getUnoShape(), uno::UNO_QUERY);
600 Reference<XPropertySet> xDest(getUnoShape(), uno::UNO_QUERY);
601 if ( xSource.is() && xDest.is() )
602 comphelper::copyProperties(xSource, xDest);
604 osl_atomic_decrement(&m_refCount);
607 OUnoObject::OUnoObject(
608 SdrModel& rSdrModel,
609 const uno::Reference< report::XReportComponent>& _xComponent,
610 const OUString& rModelName,
611 SdrObjKind _nObjectType)
612 : SdrUnoObj(rSdrModel, rModelName)
613 ,OObjectBase(_xComponent)
614 ,m_nObjectType(_nObjectType)
615 // tdf#119067
616 ,m_bSetDefaultLabel(false)
618 setUnoShape( uno::Reference< drawing::XShape >( _xComponent, uno::UNO_QUERY_THROW ) );
620 if ( !rModelName.isEmpty() )
621 impl_initializeModel_nothrow();
625 OUnoObject::~OUnoObject()
629 void OUnoObject::impl_initializeModel_nothrow()
633 Reference< XFormattedField > xFormatted( m_xReportComponent, UNO_QUERY );
634 if ( xFormatted.is() )
636 const Reference< XPropertySet > xModelProps( GetUnoControlModel(), UNO_QUERY_THROW );
637 xModelProps->setPropertyValue( u"TreatAsNumber"_ustr, Any( false ) );
638 xModelProps->setPropertyValue( PROPERTY_VERTICALALIGN,m_xReportComponent->getPropertyValue(PROPERTY_VERTICALALIGN));
641 catch( const Exception& )
643 DBG_UNHANDLED_EXCEPTION("reportdesign");
647 SdrObjKind OUnoObject::GetObjIdentifier() const
649 return m_nObjectType;
652 SdrInventor OUnoObject::GetObjInventor() const
654 return SdrInventor::ReportDesign;
657 SdrPage* OUnoObject::GetImplPage() const
659 return getSdrPageFromSdrObject();
662 void OUnoObject::NbcMove( const Size& rSize )
665 if ( m_bIsListening )
667 // stop listening
668 OObjectBase::EndListening();
670 bool bPositionFixed = false;
671 Size aUndoSize(0,0);
672 if ( m_xReportComponent.is() )
674 bool bUndoMode = false;
675 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
677 if (rRptModel.GetUndoEnv().IsUndoMode())
679 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
680 bUndoMode = true;
682 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
684 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
685 int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
686 m_xReportComponent->setPositionX(nNewX);
687 int nNewY = m_xReportComponent->getPositionY() + rSize.Height();
688 if (nNewY < 0 && !bUndoMode)
690 aUndoSize.setHeight( abs(nNewY) );
691 bPositionFixed = true;
692 nNewY = 0;
694 m_xReportComponent->setPositionY(nNewY);
696 if (bPositionFixed)
698 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
700 // set geometry properties
701 SetPropsFromRect(GetLogicRect());
703 // start listening
704 OObjectBase::StartListening();
706 else
707 SdrUnoObj::NbcMove( rSize );
711 void OUnoObject::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
713 SdrUnoObj::NbcResize( rRef, xFract, yFract );
715 // stop listening
716 OObjectBase::EndListening();
718 // set geometry properties
719 SetPropsFromRect(GetLogicRect());
721 // start listening
722 OObjectBase::StartListening();
725 void OUnoObject::NbcSetLogicRect(const tools::Rectangle& rRect, bool bAdaptTextMinSize)
727 SdrUnoObj::NbcSetLogicRect(rRect, bAdaptTextMinSize);
728 // stop listening
729 OObjectBase::EndListening();
731 // set geometry properties
732 SetPropsFromRect(rRect);
734 // start listening
735 OObjectBase::StartListening();
738 bool OUnoObject::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
740 const bool bResult(SdrUnoObj::EndCreate(rStat, eCmd));
742 if(bResult)
744 // tdf#118730 remember if this object was created interactively (due to ::EndCreate being called)
745 m_bSetDefaultLabel = true;
747 // set geometry properties
748 SetPropsFromRect(GetLogicRect());
751 return bResult;
754 OUString OUnoObject::GetDefaultName(const OUnoObject* _pObj)
756 OUString aDefaultName = u"HERE WE HAVE TO INSERT OUR NAME!"_ustr;
757 if ( _pObj->supportsService( SERVICE_FIXEDTEXT ) )
759 aDefaultName = RID_STR_CLASS_FIXEDTEXT;
761 else if ( _pObj->supportsService( SERVICE_FIXEDLINE ) )
763 aDefaultName = RID_STR_CLASS_FIXEDLINE;
765 else if ( _pObj->supportsService( SERVICE_IMAGECONTROL ) )
767 aDefaultName = RID_STR_CLASS_IMAGECONTROL;
769 else if ( _pObj->supportsService( SERVICE_FORMATTEDFIELD ) )
771 aDefaultName = RID_STR_CLASS_FORMATTEDFIELD;
774 return aDefaultName;
777 void OUnoObject::_propertyChange( const beans::PropertyChangeEvent& evt )
779 OObjectBase::_propertyChange(evt);
780 if (!isListening())
781 return;
783 if ( evt.PropertyName == PROPERTY_CHARCOLOR )
785 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
786 if ( xControlModel.is() )
788 OObjectBase::EndListening();
791 xControlModel->setPropertyValue(PROPERTY_TEXTCOLOR,evt.NewValue);
793 catch(uno::Exception&)
796 OObjectBase::StartListening();
799 else if ( evt.PropertyName == PROPERTY_NAME )
801 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
802 if ( xControlModel.is() && xControlModel->getPropertySetInfo()->hasPropertyByName(PROPERTY_NAME) )
804 // get old name
805 OUString aOldName;
806 evt.OldValue >>= aOldName;
808 // get new name
809 OUString aNewName;
810 evt.NewValue >>= aNewName;
812 if ( aNewName != aOldName )
814 // set old name property
815 OObjectBase::EndListening();
816 if ( m_xMediator.is() )
817 m_xMediator->stopListening();
820 xControlModel->setPropertyValue( PROPERTY_NAME, evt.NewValue );
822 catch(uno::Exception&)
825 if ( m_xMediator.is() )
826 m_xMediator->startListening();
827 OObjectBase::StartListening();
833 void OUnoObject::CreateMediator(bool _bReverse)
835 if ( m_xMediator.is() )
836 return;
838 // tdf#118730 Directly do things formerly done in
839 // OUnoObject::impl_setReportComponent_nothrow here
840 if(!m_xReportComponent.is())
842 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
843 OXUndoEnvironment::OUndoEnvLock aLock( rRptModel.GetUndoEnv() );
844 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
846 impl_initializeModel_nothrow();
849 if(m_xReportComponent.is() && m_bSetDefaultLabel)
851 // tdf#118730 Directly do things formerly done in
852 // OUnoObject::EndCreate here
853 // tdf#119067 ...but *only* if result of interactive
854 // creation in Report DesignView
855 m_bSetDefaultLabel = false;
859 if ( supportsService( SERVICE_FIXEDTEXT ) )
861 m_xReportComponent->setPropertyValue(
862 PROPERTY_LABEL,
863 uno::Any(GetDefaultName(this)));
866 catch(const uno::Exception&)
868 DBG_UNHANDLED_EXCEPTION("reportdesign");
872 if(!m_xMediator.is() && m_xReportComponent.is())
874 Reference<XPropertySet> xControlModel(GetUnoControlModel(),uno::UNO_QUERY);
876 if(xControlModel.is())
878 m_xMediator = new OPropertyMediator(
879 m_xReportComponent,
880 xControlModel,
881 TPropertyNamePair(getPropertyNameMap(GetObjIdentifier())),
882 _bReverse);
886 OObjectBase::StartListening();
889 uno::Reference< beans::XPropertySet> OUnoObject::getAwtComponent()
891 return Reference<XPropertySet>(GetUnoControlModel(),uno::UNO_QUERY);
895 uno::Reference< drawing::XShape > OUnoObject::getUnoShape()
897 return OObjectBase::getUnoShapeOf( *this );
900 void OUnoObject::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape )
902 SdrUnoObj::setUnoShape( rxUnoShape );
903 releaseUnoShape();
906 rtl::Reference<SdrObject> OUnoObject::CloneSdrObject(SdrModel& rTargetModel) const
908 return new OUnoObject(rTargetModel, *this);
911 // OOle2Obj
912 OOle2Obj::OOle2Obj(
913 SdrModel& rSdrModel,
914 const uno::Reference< report::XReportComponent>& _xComponent,
915 SdrObjKind _nType)
916 : SdrOle2Obj(rSdrModel)
917 ,OObjectBase(_xComponent)
918 ,m_nType(_nType)
919 ,m_bOnlyOnce(true)
921 setUnoShape( uno::Reference< drawing::XShape >( _xComponent, uno::UNO_QUERY_THROW ) );
922 m_bIsListening = true;
925 OOle2Obj::OOle2Obj(
926 SdrModel& rSdrModel,
927 SdrObjKind _nType)
928 : SdrOle2Obj(rSdrModel)
929 ,OObjectBase(ObjectTypeToServiceName(_nType))
930 ,m_nType(_nType)
931 ,m_bOnlyOnce(true)
933 m_bIsListening = true;
936 static uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const uno::Reference < embed::XEmbeddedObject >& _xObj);
938 OOle2Obj::OOle2Obj(SdrModel& rSdrModel, OOle2Obj const & rSource)
939 : SdrOle2Obj(rSdrModel, rSource)
940 ,OObjectBase(rSource.getServiceName())
941 ,m_nType(rSource.m_nType)
942 ,m_bOnlyOnce(rSource.m_bOnlyOnce)
944 m_bIsListening = true;
946 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
947 (void)svt::EmbeddedObjectRef::TryRunningState( GetObjRef() );
948 impl_createDataProvider_nothrow(rRptModel.getReportDefinition());
950 uno::Reference< chart2::data::XDatabaseDataProvider > xSource( lcl_getDataProvider(rSource.GetObjRef()) );
951 uno::Reference< chart2::data::XDatabaseDataProvider > xDest( lcl_getDataProvider(GetObjRef()) );
952 if ( xSource.is() && xDest.is() )
953 comphelper::copyProperties(xSource, xDest);
955 initializeChart(rRptModel.getReportDefinition());
958 OOle2Obj::~OOle2Obj()
962 SdrObjKind OOle2Obj::GetObjIdentifier() const
964 return m_nType;
967 SdrInventor OOle2Obj::GetObjInventor() const
969 return SdrInventor::ReportDesign;
972 SdrPage* OOle2Obj::GetImplPage() const
974 return getSdrPageFromSdrObject();
977 void OOle2Obj::NbcMove( const Size& rSize )
980 if ( m_bIsListening )
982 // stop listening
983 OObjectBase::EndListening();
985 bool bPositionFixed = false;
986 Size aUndoSize(0,0);
987 if ( m_xReportComponent.is() )
989 bool bUndoMode = false;
990 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
992 if (rRptModel.GetUndoEnv().IsUndoMode())
994 // if we are locked from outside, then we must not handle wrong moves, we are in UNDO mode
995 bUndoMode = true;
997 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
999 // LLA: why there exists getPositionX and getPositionY and NOT getPosition() which return a Point?
1000 int nNewX = m_xReportComponent->getPositionX() + rSize.Width();
1001 // can this hinder us to set components outside the area?
1002 // if (nNewX < 0)
1003 // {
1004 // nNewX = 0;
1005 // }
1006 m_xReportComponent->setPositionX(nNewX);
1007 int nNewY = m_xReportComponent->getPositionY() + rSize.Height();
1008 if (nNewY < 0 && !bUndoMode)
1010 aUndoSize.setHeight( abs(nNewY) );
1011 bPositionFixed = true;
1012 nNewY = 0;
1014 m_xReportComponent->setPositionY(nNewY);
1016 if (bPositionFixed)
1018 getSdrModelFromSdrObject().AddUndo(getSdrModelFromSdrObject().GetSdrUndoFactory().CreateUndoMoveObject(*this, aUndoSize));
1020 // set geometry properties
1021 SetPropsFromRect(GetLogicRect());
1023 // start listening
1024 OObjectBase::StartListening();
1026 else
1027 SdrOle2Obj::NbcMove( rSize );
1031 void OOle2Obj::NbcResize(const Point& rRef, const Fraction& xFract, const Fraction& yFract)
1033 SdrOle2Obj::NbcResize( rRef, xFract, yFract );
1035 // stop listening
1036 OObjectBase::EndListening();
1038 // set geometry properties
1039 SetPropsFromRect(GetLogicRect());
1041 // start listening
1042 OObjectBase::StartListening();
1045 void OOle2Obj::NbcSetLogicRect(const tools::Rectangle& rRect, bool bAdaptTextMinSize)
1047 SdrOle2Obj::NbcSetLogicRect(rRect, bAdaptTextMinSize);
1048 // stop listening
1049 OObjectBase::EndListening();
1051 // set geometry properties
1052 SetPropsFromRect(rRect);
1054 // start listening
1055 OObjectBase::StartListening();
1059 bool OOle2Obj::EndCreate(SdrDragStat& rStat, SdrCreateCmd eCmd)
1061 bool bResult = SdrOle2Obj::EndCreate(rStat, eCmd);
1062 if ( bResult )
1064 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1065 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
1067 if ( !m_xReportComponent.is() )
1068 m_xReportComponent.set(getUnoShape(),uno::UNO_QUERY);
1070 // set geometry properties
1071 SetPropsFromRect(GetLogicRect());
1074 return bResult;
1077 uno::Reference< beans::XPropertySet> OOle2Obj::getAwtComponent()
1079 return m_xReportComponent;
1083 uno::Reference< drawing::XShape > OOle2Obj::getUnoShape()
1085 uno::Reference< drawing::XShape> xShape = OObjectBase::getUnoShapeOf( *this );
1086 if ( !m_xReportComponent.is() )
1088 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1089 OXUndoEnvironment::OUndoEnvLock aLock(rRptModel.GetUndoEnv());
1090 m_xReportComponent.set(xShape,uno::UNO_QUERY);
1092 return xShape;
1095 void OOle2Obj::setUnoShape( const uno::Reference< drawing::XShape >& rxUnoShape )
1097 SdrOle2Obj::setUnoShape( rxUnoShape );
1098 releaseUnoShape();
1099 m_xReportComponent.clear();
1103 static uno::Reference< chart2::data::XDatabaseDataProvider > lcl_getDataProvider(const uno::Reference < embed::XEmbeddedObject >& _xObj)
1105 uno::Reference< chart2::data::XDatabaseDataProvider > xSource;
1106 uno::Reference< embed::XComponentSupplier > xCompSupp(_xObj);
1107 if( xCompSupp.is())
1109 uno::Reference< chart2::XChartDocument> xChartDoc( xCompSupp->getComponent(), uno::UNO_QUERY );
1110 if ( xChartDoc.is() )
1112 xSource.set(xChartDoc->getDataProvider(),uno::UNO_QUERY);
1115 return xSource;
1118 // Clone() should make a complete copy of the object.
1119 rtl::Reference<SdrObject> OOle2Obj::CloneSdrObject(SdrModel& rTargetModel) const
1121 return new OOle2Obj(rTargetModel, *this);
1124 void OOle2Obj::impl_createDataProvider_nothrow(const uno::Reference< frame::XModel>& _xModel)
1128 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1129 uno::Reference< chart2::data::XDataReceiver > xReceiver;
1130 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj );
1131 if( xCompSupp.is())
1132 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1133 OSL_ASSERT( xReceiver.is());
1134 if( xReceiver.is() )
1136 uno::Reference< lang::XMultiServiceFactory> xFac(_xModel,uno::UNO_QUERY);
1137 uno::Reference< chart2::data::XDatabaseDataProvider > xDataProvider( xFac->createInstance(u"com.sun.star.chart2.data.DataProvider"_ustr),uno::UNO_QUERY);
1138 xReceiver->attachDataProvider( xDataProvider );
1141 catch(const uno::Exception &)
1146 void OOle2Obj::initializeOle()
1148 if ( !m_bOnlyOnce )
1149 return;
1151 m_bOnlyOnce = false;
1152 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1153 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1154 rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1156 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj );
1157 if( xCompSupp.is() )
1159 uno::Reference< beans::XPropertySet > xChartProps( xCompSupp->getComponent(), uno::UNO_QUERY );
1160 if ( xChartProps.is() )
1161 xChartProps->setPropertyValue(u"NullDate"_ustr,
1162 uno::Any(util::DateTime(0,0,0,0,30,12,1899,false)));
1166 void OOle2Obj::initializeChart( const uno::Reference< frame::XModel>& _xModel)
1168 uno::Reference < embed::XEmbeddedObject > xObj = GetObjRef();
1169 uno::Reference< chart2::data::XDataReceiver > xReceiver;
1170 uno::Reference< embed::XComponentSupplier > xCompSupp( xObj );
1171 if( xCompSupp.is())
1172 xReceiver.set( xCompSupp->getComponent(), uno::UNO_QUERY );
1173 OSL_ASSERT( xReceiver.is());
1174 if( !xReceiver.is() )
1175 return;
1177 // lock the model to suppress any internal updates
1178 uno::Reference< frame::XModel > xChartModel( xReceiver, uno::UNO_QUERY );
1179 if( xChartModel.is() )
1180 xChartModel->lockControllers();
1182 if ( !lcl_getDataProvider(xObj).is() )
1183 impl_createDataProvider_nothrow(_xModel);
1185 OReportModel& rRptModel(static_cast< OReportModel& >(getSdrModelFromSdrObject()));
1186 rRptModel.GetUndoEnv().AddElement(lcl_getDataProvider(xObj));
1188 ::comphelper::NamedValueCollection aArgs;
1189 aArgs.put( u"CellRangeRepresentation"_ustr, uno::Any( u"all"_ustr ) );
1190 aArgs.put( u"HasCategories"_ustr, uno::Any( true ) );
1191 aArgs.put( u"FirstCellAsLabel"_ustr, uno::Any( true ) );
1192 aArgs.put( u"DataRowSource"_ustr, uno::Any( chart::ChartDataRowSource_COLUMNS ) );
1193 xReceiver->setArguments( aArgs.getPropertyValues() );
1195 if( xChartModel.is() )
1196 xChartModel->unlockControllers();
1199 uno::Reference< style::XStyle> getUsedStyle(const uno::Reference< report::XReportDefinition>& _xReport)
1201 uno::Reference<container::XNameAccess> xStyles = _xReport->getStyleFamilies();
1202 uno::Reference<container::XNameAccess> xPageStyles(xStyles->getByName(u"PageStyles"_ustr),uno::UNO_QUERY);
1204 const uno::Sequence< OUString> aSeq = xPageStyles->getElementNames();
1205 for(const OUString& rName : aSeq)
1207 uno::Reference< style::XStyle> xStyle(xPageStyles->getByName(rName),uno::UNO_QUERY);
1208 if ( xStyle->isInUse() )
1210 return xStyle;
1211 break;
1214 return nullptr;
1218 } // rptui
1221 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */