LibreOffice Module reportdesign (master)  1
ReportDrawPage.cxx
Go to the documentation of this file.
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
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/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
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 .
18  */
19 #include <ReportDrawPage.hxx>
20 #include <RptObject.hxx>
21 #include <RptModel.hxx>
22 #include <strings.hxx>
25 
26 #include <svx/svdmodel.hxx>
27 #include <com/sun/star/embed/Aspects.hpp>
28 #include <com/sun/star/embed/XEmbeddedObject.hpp>
29 #include <tools/diagnose_ex.h>
30 #include <svx/unoshape.hxx>
31 #include <svx/svdpage.hxx>
32 
33 namespace reportdesign
34 {
35  using namespace ::com::sun::star;
36  using namespace rptui;
37 
39  ,const uno::Reference< report::XSection >& _xSection)
40 : SvxDrawPage(_pPage)
41 ,m_xSection(_xSection)
42 {
43 }
44 
45 SdrObject* OReportDrawPage::CreateSdrObject_(const uno::Reference< drawing::XShape > & xDescr)
46 {
47  uno::Reference< report::XReportComponent> xReportComponent(xDescr,uno::UNO_QUERY);
48  if ( xReportComponent.is() )
49  {
51  GetSdrPage()->getSdrModelFromSdrPage(),
52  xReportComponent);
53  }
54 
55  return SvxDrawPage::CreateSdrObject_( xDescr );
56 }
57 
58 uno::Reference< drawing::XShape > OReportDrawPage::CreateShape( SdrObject *pObj ) const
59 {
60  OObjectBase* pBaseObj = dynamic_cast<OObjectBase*>(pObj);
61  if ( !pBaseObj )
62  return SvxDrawPage::CreateShape( pObj );
63 
64  uno::Reference< report::XSection> xSection = m_xSection;
65  uno::Reference< lang::XMultiServiceFactory> xFactory;
66  if ( xSection.is() )
67  xFactory.set(xSection->getReportDefinition(),uno::UNO_QUERY);
68  uno::Reference< drawing::XShape > xRet;
69  uno::Reference< drawing::XShape > xShape;
70  if ( xFactory.is() )
71  {
72  bool bChangeOrientation = false;
73  const OUString& sServiceName = pBaseObj->getServiceName();
74  OSL_ENSURE(!sServiceName.isEmpty(),"No Service Name given!");
75 
76  if (dynamic_cast< const OUnoObject* >(pObj) != nullptr)
77  {
78  OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
79  if (rUnoObj.GetObjIdentifier() == SdrObjKind::ReportDesignFixedText)
80  {
81  uno::Reference<beans::XPropertySet> xControlModel(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
82  if ( xControlModel.is() )
83  xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::Any(true));
84  }
85  else
86  bChangeOrientation = rUnoObj.GetObjIdentifier() == SdrObjKind::ReportDesignHorizontalFixedLine;
88  xShape = static_cast<SvxShape_UnoImplHelper *>(pShape.get());
89  pShape->setShapeKind(pObj->GetObjIdentifier());
90  }
91  else if (dynamic_cast< const OCustomShape* >(pObj) != nullptr)
92  {
94  xShape = pShape;
95  pShape->setShapeKind(pObj->GetObjIdentifier());
96  }
97  else if (dynamic_cast< const SdrOle2Obj* >(pObj) != nullptr)
98  {
99  SdrOle2Obj& rOle2Obj = dynamic_cast<SdrOle2Obj&>(*pObj);
100  if (!rOle2Obj.GetObjRef().is())
101  {
102  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
103  uno::Reference < embed::XEmbeddedObject > xObj;
104  OUString sName;
107  u"80243D39-6741-46C5-926E-069164FF87BB"), sName );
108  OSL_ENSURE(xObj.is(),"Embedded Object could not be created!");
109 
110  /**************************************************
111  * The empty OLE object gets a new IPObj
112  **************************************************/
113  pObj->SetEmptyPresObj(false);
114  rOle2Obj.SetOutlinerParaObject(std::nullopt);
115  rOle2Obj.SetObjRef(xObj);
116  rOle2Obj.SetPersistName(sName);
117  rOle2Obj.SetName(sName);
118  rOle2Obj.SetAspect(nAspect);
119  tools::Rectangle aRect = rOle2Obj.GetLogicRect();
120 
121  Size aTmp = aRect.GetSize();
122  awt::Size aSz( aTmp.Width(), aTmp.Height() );
123  xObj->setVisualAreaSize( nAspect, aSz );
124  }
125  rtl::Reference<SvxOle2Shape> pShape = new SvxOle2Shape( pObj );
126  xShape = pShape;
127  pShape->setShapeKind(pObj->GetObjIdentifier());
128  }
129 
130  if ( !xShape.is() )
131  xShape.set( SvxDrawPage::CreateShape( pObj ) );
132 
133  try
134  {
135  OReportModel& rRptModel(static_cast< OReportModel& >(pObj->getSdrModelFromSdrObject()));
136  xRet.set( rRptModel.createShape(sServiceName,xShape,bChangeOrientation ? 0 : 1), uno::UNO_QUERY_THROW );
137  }
138  catch( const uno::Exception& )
139  {
140  DBG_UNHANDLED_EXCEPTION("reportdesign");
141  }
142  }
143 
144  return xRet;
145 }
146 
147 }
148 
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::embed::XEmbeddedObject > CreateEmbeddedObject(const css::uno::Sequence< sal_Int8 > &, OUString &, OUString const *pBaseURL=nullptr)
css::uno::Reference< css::embed::XEmbeddedObject > const & GetObjRef() const
void SetName(const OUString &rStr, const bool bSetChanged=true)
void SetPersistName(const OUString &rPersistName)
#define PROPERTY_MULTILINE
Definition: strings.hxx:186
void SetEmptyPresObj(bool bEpt)
virtual css::uno::Reference< css::drawing::XShape > CreateShape(SdrObject *pObj) const override
virtual SdrObjKind GetObjIdentifier() const
void SetOutlinerParaObject(std::optional< OutlinerParaObject > pTextObject)
virtual SdrObject * CreateSdrObject_(const css::uno::Reference< css::drawing::XShape > &xShape)
css::uno::Reference< css::uno::XInterface > createShape(const OUString &aServiceSpecifier, css::uno::Reference< css::drawing::XShape > &_rShape, sal_Int32 nOrientation=-1)
Definition: RptModel.cxx:138
void SetObjRef(const css::uno::Reference< css::embed::XEmbeddedObject > &rNewObjRef)
constexpr tools::Long Width() const
constexpr OUStringLiteral sServiceName
virtual EmbeddedObjectContainer & getEmbeddedObjectContainer() const =0
static SdrObject * createObject(SdrModel &rTargetModel, const css::uno::Reference< css::report::XReportComponent > &_xComponent)
Definition: RptObject.cxx:88
const char * sName
SdrPage * GetSdrPage() const
#define DBG_UNHANDLED_EXCEPTION(...)
css::uno::WeakReference< css::report::XSection > m_xSection
static css::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation(std::u16string_view aClassID)
float u
SdrModel & getSdrModelFromSdrObject() const
virtual css::uno::Reference< css::drawing::XShape > CreateShape(SdrObject *pObj) const
const OUString & getServiceName() const
Definition: RptObject.hxx:108
virtual SdrObjKind GetObjIdentifier() const override
Definition: RptObject.cxx:643
constexpr Size GetSize() const
constexpr tools::Long Height() const
::comphelper::IEmbeddedHelper * GetPersist() const
OReportDrawPage(const OReportDrawPage &)=delete
const css::uno::Reference< css::awt::XControlModel > & GetUnoControlModel() const
Reference< XSingleServiceFactory > xFactory
virtual SdrObject * CreateSdrObject_(const css::uno::Reference< css::drawing::XShape > &xShape) override
void SetAspect(sal_Int64 nAspect)
virtual const tools::Rectangle & GetLogicRect() const override