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 <ReportDrawPage.hxx>
20 #include <RptObject.hxx>
21 #include <RptModel.hxx>
23 #include <strings.hxx>
24 #include <comphelper/mimeconfighelper.hxx>
25 #include <comphelper/classids.hxx>
26 #include <comphelper/embeddedobjectcontainer.hxx>
27 #include <comphelper/documentconstants.hxx>
28 #include <editeng/outlobj.hxx>
30 #include <svx/svdmodel.hxx>
31 #include <com/sun/star/beans/NamedValue.hpp>
32 #include <com/sun/star/embed/Aspects.hpp>
33 #include <com/sun/star/embed/XEmbeddedObject.hpp>
34 #include <tools/diagnose_ex.h>
35 #include <svx/unoshape.hxx>
36 #include <svx/svdpage.hxx>
38 namespace reportdesign
40 using namespace ::com::sun::star
;
41 using namespace rptui
;
43 OReportDrawPage::OReportDrawPage(SdrPage
* _pPage
44 ,const uno::Reference
< report::XSection
>& _xSection
)
46 ,m_xSection(_xSection
)
50 SdrObject
* OReportDrawPage::CreateSdrObject_(const uno::Reference
< drawing::XShape
> & xDescr
)
52 uno::Reference
< report::XReportComponent
> xReportComponent(xDescr
,uno::UNO_QUERY
);
53 if ( xReportComponent
.is() )
55 return OObjectBase::createObject(
56 GetSdrPage()->getSdrModelFromSdrPage(),
60 return SvxDrawPage::CreateSdrObject_( xDescr
);
63 uno::Reference
< drawing::XShape
> OReportDrawPage::CreateShape( SdrObject
*pObj
) const
65 OObjectBase
* pBaseObj
= dynamic_cast<OObjectBase
*>(pObj
);
67 return SvxDrawPage::CreateShape( pObj
);
69 uno::Reference
< report::XSection
> xSection
= m_xSection
;
70 uno::Reference
< lang::XMultiServiceFactory
> xFactory
;
72 xFactory
.set(xSection
->getReportDefinition(),uno::UNO_QUERY
);
73 uno::Reference
< drawing::XShape
> xRet
;
74 uno::Reference
< drawing::XShape
> xShape
;
77 bool bChangeOrientation
= false;
78 const OUString
& sServiceName
= pBaseObj
->getServiceName();
79 OSL_ENSURE(!sServiceName
.isEmpty(),"No Service Name given!");
81 if (dynamic_cast< const OUnoObject
* >(pObj
) != nullptr)
83 OUnoObject
& rUnoObj
= dynamic_cast<OUnoObject
&>(*pObj
);
84 if (rUnoObj
.GetObjIdentifier() == OBJ_DLG_FIXEDTEXT
)
86 uno::Reference
<beans::XPropertySet
> xControlModel(rUnoObj
.GetUnoControlModel(),uno::UNO_QUERY
);
87 if ( xControlModel
.is() )
88 xControlModel
->setPropertyValue( PROPERTY_MULTILINE
,uno::makeAny(true));
91 bChangeOrientation
= rUnoObj
.GetObjIdentifier() == OBJ_DLG_HFIXEDLINE
;
92 SvxShapeControl
* pShape
= new SvxShapeControl( pObj
);
93 xShape
.set(static_cast<cppu::OWeakObject
*>(static_cast<SvxShape_UnoImplHelper
*>(pShape
)),uno::UNO_QUERY
);
94 pShape
->setShapeKind(pObj
->GetObjIdentifier());
96 else if (dynamic_cast< const OCustomShape
* >(pObj
) != nullptr)
98 SvxCustomShape
* pShape
= new SvxCustomShape( pObj
);
99 uno::Reference
< drawing::XEnhancedCustomShapeDefaulter
> xShape2
= pShape
;
100 xShape
.set(xShape2
,uno::UNO_QUERY
);
101 pShape
->setShapeKind(pObj
->GetObjIdentifier());
103 else if (dynamic_cast< const SdrOle2Obj
* >(pObj
) != nullptr)
105 SdrOle2Obj
& rOle2Obj
= dynamic_cast<SdrOle2Obj
&>(*pObj
);
106 if (!rOle2Obj
.GetObjRef().is())
108 sal_Int64 nAspect
= embed::Aspects::MSOLE_CONTENT
;
109 uno::Reference
< embed::XEmbeddedObject
> xObj
;
111 xObj
= pObj
->getSdrModelFromSdrObject().GetPersist()->getEmbeddedObjectContainer().CreateEmbeddedObject(
112 ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(
113 "80243D39-6741-46C5-926E-069164FF87BB"), sName
);
114 OSL_ENSURE(xObj
.is(),"Embedded Object could not be created!");
116 /**************************************************
117 * The empty OLE object gets a new IPObj
118 **************************************************/
119 pObj
->SetEmptyPresObj(false);
120 rOle2Obj
.SetOutlinerParaObject(nullptr);
121 rOle2Obj
.SetObjRef(xObj
);
122 rOle2Obj
.SetPersistName(sName
);
123 rOle2Obj
.SetName(sName
);
124 rOle2Obj
.SetAspect(nAspect
);
125 tools::Rectangle aRect
= rOle2Obj
.GetLogicRect();
127 Size aTmp
= aRect
.GetSize();
128 awt::Size
aSz( aTmp
.Width(), aTmp
.Height() );
129 xObj
->setVisualAreaSize( nAspect
, aSz
);
131 SvxOle2Shape
* pShape
= new SvxOle2Shape( pObj
);
132 xShape
.set(*pShape
,uno::UNO_QUERY
);
133 pShape
->setShapeKind(pObj
->GetObjIdentifier());
137 xShape
.set( SvxDrawPage::CreateShape( pObj
) );
141 OReportModel
& rRptModel(static_cast< OReportModel
& >(pObj
->getSdrModelFromSdrObject()));
142 xRet
.set( rRptModel
.createShape(sServiceName
,xShape
,bChangeOrientation
? 0 : 1), uno::UNO_QUERY_THROW
);
144 catch( const uno::Exception
& )
146 DBG_UNHANDLED_EXCEPTION("reportdesign");
155 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */