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 <RptDef.hxx>
23 #include <strings.hxx>
26 #include <editeng/outlobj.hxx>
27 
28 #include <svx/svdmodel.hxx>
29 #include <com/sun/star/embed/Aspects.hpp>
30 #include <com/sun/star/embed/XEmbeddedObject.hpp>
31 #include <tools/diagnose_ex.h>
32 #include <svx/unoshape.hxx>
33 #include <svx/svdpage.hxx>
34 
35 namespace reportdesign
36 {
37  using namespace ::com::sun::star;
38  using namespace rptui;
39 
41  ,const uno::Reference< report::XSection >& _xSection)
42 : SvxDrawPage(_pPage)
43 ,m_xSection(_xSection)
44 {
45 }
46 
47 SdrObject* OReportDrawPage::CreateSdrObject_(const uno::Reference< drawing::XShape > & xDescr)
48 {
49  uno::Reference< report::XReportComponent> xReportComponent(xDescr,uno::UNO_QUERY);
50  if ( xReportComponent.is() )
51  {
53  GetSdrPage()->getSdrModelFromSdrPage(),
54  xReportComponent);
55  }
56 
57  return SvxDrawPage::CreateSdrObject_( xDescr );
58 }
59 
60 uno::Reference< drawing::XShape > OReportDrawPage::CreateShape( SdrObject *pObj ) const
61 {
62  OObjectBase* pBaseObj = dynamic_cast<OObjectBase*>(pObj);
63  if ( !pBaseObj )
64  return SvxDrawPage::CreateShape( pObj );
65 
66  uno::Reference< report::XSection> xSection = m_xSection;
67  uno::Reference< lang::XMultiServiceFactory> xFactory;
68  if ( xSection.is() )
69  xFactory.set(xSection->getReportDefinition(),uno::UNO_QUERY);
70  uno::Reference< drawing::XShape > xRet;
71  uno::Reference< drawing::XShape > xShape;
72  if ( xFactory.is() )
73  {
74  bool bChangeOrientation = false;
75  const OUString& sServiceName = pBaseObj->getServiceName();
76  OSL_ENSURE(!sServiceName.isEmpty(),"No Service Name given!");
77 
78  if (dynamic_cast< const OUnoObject* >(pObj) != nullptr)
79  {
80  OUnoObject& rUnoObj = dynamic_cast<OUnoObject&>(*pObj);
81  if (rUnoObj.GetObjIdentifier() == OBJ_RD_FIXEDTEXT)
82  {
83  uno::Reference<beans::XPropertySet> xControlModel(rUnoObj.GetUnoControlModel(),uno::UNO_QUERY);
84  if ( xControlModel.is() )
85  xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::makeAny(true));
86  }
87  else
88  bChangeOrientation = rUnoObj.GetObjIdentifier() == OBJ_RD_HFIXEDLINE;
90  xShape = static_cast<SvxShape_UnoImplHelper *>(pShape.get());
91  pShape->setShapeKind(pObj->GetObjIdentifier());
92  }
93  else if (dynamic_cast< const OCustomShape* >(pObj) != nullptr)
94  {
96  xShape = pShape;
97  pShape->setShapeKind(pObj->GetObjIdentifier());
98  }
99  else if (dynamic_cast< const SdrOle2Obj* >(pObj) != nullptr)
100  {
101  SdrOle2Obj& rOle2Obj = dynamic_cast<SdrOle2Obj&>(*pObj);
102  if (!rOle2Obj.GetObjRef().is())
103  {
104  sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
105  uno::Reference < embed::XEmbeddedObject > xObj;
106  OUString sName;
109  "80243D39-6741-46C5-926E-069164FF87BB"), sName );
110  OSL_ENSURE(xObj.is(),"Embedded Object could not be created!");
111 
112  /**************************************************
113  * The empty OLE object gets a new IPObj
114  **************************************************/
115  pObj->SetEmptyPresObj(false);
116  rOle2Obj.SetOutlinerParaObject(std::nullopt);
117  rOle2Obj.SetObjRef(xObj);
118  rOle2Obj.SetPersistName(sName);
119  rOle2Obj.SetName(sName);
120  rOle2Obj.SetAspect(nAspect);
121  tools::Rectangle aRect = rOle2Obj.GetLogicRect();
122 
123  Size aTmp = aRect.GetSize();
124  awt::Size aSz( aTmp.Width(), aTmp.Height() );
125  xObj->setVisualAreaSize( nAspect, aSz );
126  }
127  rtl::Reference<SvxOle2Shape> pShape = new SvxOle2Shape( pObj );
128  xShape = pShape;
129  pShape->setShapeKind(pObj->GetObjIdentifier());
130  }
131 
132  if ( !xShape.is() )
133  xShape.set( SvxDrawPage::CreateShape( pObj ) );
134 
135  try
136  {
137  OReportModel& rRptModel(static_cast< OReportModel& >(pObj->getSdrModelFromSdrObject()));
138  xRet.set( rRptModel.createShape(sServiceName,xShape,bChangeOrientation ? 0 : 1), uno::UNO_QUERY_THROW );
139  }
140  catch( const uno::Exception& )
141  {
142  DBG_UNHANDLED_EXCEPTION("reportdesign");
143  }
144  }
145 
146  return xRet;
147 }
148 
149 }
150 
151 /* 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)
OBJ_RD_HFIXEDLINE
#define PROPERTY_MULTILINE
Definition: strings.hxx:192
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:89
const char * sName
SdrPage * GetSdrPage() const
#define DBG_UNHANDLED_EXCEPTION(...)
css::uno::WeakReference< css::report::XSection > m_xSection
OBJ_RD_FIXEDTEXT
static css::uno::Sequence< sal_Int8 > GetSequenceClassIDRepresentation(const OUString &aClassID)
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:644
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