1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 #include "ReportDrawPage.hxx"
25 #include "RptObject.hxx"
26 #include "RptModel.hxx"
27 #include "RptDef.hxx"
28 #include "corestrings.hrc"
29 #include <comphelper/mimeconfighelper.hxx>
30 #include <comphelper/classids.hxx>
31 #include <comphelper/embeddedobjectcontainer.hxx>
32 #include <comphelper/documentconstants.hxx>
33 
34 #include <svx/svdmodel.hxx>
35 #include <com/sun/star/report/XFixedLine.hpp>
36 #include <com/sun/star/beans/NamedValue.hpp>
37 
38 #include <tools/diagnose_ex.h>
39 #include <svx/unoshape.hxx>
40 
41 namespace reportdesign
42 {
43     using namespace ::com::sun::star;
44     using namespace rptui;
45 
OReportDrawPage(SdrPage * _pPage,const uno::Reference<report::XSection> & _xSection)46 OReportDrawPage::OReportDrawPage(SdrPage* _pPage
47                                  ,const uno::Reference< report::XSection >& _xSection)
48 : SvxDrawPage(_pPage)
49 ,m_xSection(_xSection)
50 {
51 }
52 
_CreateSdrObject(const uno::Reference<drawing::XShape> & xDescr)53 SdrObject* OReportDrawPage::_CreateSdrObject( const uno::Reference< drawing::XShape > & xDescr ) throw ()
54 {
55     uno::Reference< report::XReportComponent> xReportComponent(xDescr,uno::UNO_QUERY);
56     if ( xReportComponent.is() )
57         return OObjectBase::createObject(xReportComponent);
58 	return SvxDrawPage::_CreateSdrObject( xDescr );
59 }
60 
_CreateShape(SdrObject * pObj) const61 uno::Reference< drawing::XShape >  OReportDrawPage::_CreateShape( SdrObject *pObj ) const throw ()
62 {
63     OObjectBase* pBaseObj = dynamic_cast<OObjectBase*>(pObj);
64     if ( !pBaseObj )
65 	    return SvxDrawPage::_CreateShape( pObj );
66 
67     uno::Reference< report::XSection> xSection = m_xSection;
68     uno::Reference< lang::XMultiServiceFactory> xFactory;
69     if ( xSection.is() )
70         xFactory.set(xSection->getReportDefinition(),uno::UNO_QUERY);
71     uno::Reference< drawing::XShape > xRet;
72 	uno::Reference< drawing::XShape > xShape;
73     if ( xFactory.is() )
74     {
75         bool bChangeOrientation = false;
76         ::rtl::OUString sServiceName = pBaseObj->getServiceName();
77         OSL_ENSURE(sServiceName.getLength(),"No Service Name given!");
78 
79         if ( pObj->ISA(OUnoObject) )
80         {
81             OUnoObject* pUnoObj = dynamic_cast<OUnoObject*>(pObj);
82             if ( pUnoObj->GetObjIdentifier() == OBJ_DLG_FIXEDTEXT )
83             {
84                 uno::Reference<beans::XPropertySet> xControlModel(pUnoObj->GetUnoControlModel(),uno::UNO_QUERY);
85                 if ( xControlModel.is() )
86                     xControlModel->setPropertyValue( PROPERTY_MULTILINE,uno::makeAny(sal_True));
87             }
88             else
89                 bChangeOrientation = pUnoObj->GetObjIdentifier() == OBJ_DLG_HFIXEDLINE;
90             SvxShapeControl* pShape = new SvxShapeControl( pObj );
91             xShape.set(*pShape,uno::UNO_QUERY);
92             pShape->setShapeKind(pObj->GetObjIdentifier());
93         }
94 		else if ( pObj->ISA(OCustomShape) )
95 		{
96 			SvxCustomShape* pShape = new SvxCustomShape( pObj );
97             uno::Reference < drawing::XEnhancedCustomShapeDefaulter > xShape2 = pShape;
98             xShape.set(xShape2,uno::UNO_QUERY);
99 			pShape->setShapeKind(pObj->GetObjIdentifier());
100 		}
101         else if ( pObj->ISA(SdrOle2Obj) )
102         {
103             SdrOle2Obj* pOle2Obj = dynamic_cast<SdrOle2Obj*>(pObj);
104             if ( !pOle2Obj->GetObjRef().is() )
105             {
106                 sal_Int64 nAspect = embed::Aspects::MSOLE_CONTENT;
107                 uno::Reference < embed::XEmbeddedObject > xObj;
108                 ::rtl::OUString sName;
109                 xObj = pObj->GetModel()->GetPersist()->getEmbeddedObjectContainer().CreateEmbeddedObject(
110                     ::comphelper::MimeConfigurationHelper::GetSequenceClassIDRepresentation(
111                     ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("80243D39-6741-46C5-926E-069164FF87BB"))), sName );
112                 OSL_ENSURE(xObj.is(),"Embedded Object could not be created!");
113 
114                 /**************************************************
115                 * Das leere OLE-Objekt bekommt ein neues IPObj
116                 **************************************************/
117                 pObj->SetEmptyPresObj(sal_False);
118                 pOle2Obj->SetOutlinerParaObject(NULL);
119                 pOle2Obj->SetObjRef(xObj);
120                 pOle2Obj->SetPersistName(sName);
121                 pOle2Obj->SetName(sName);
122                 pOle2Obj->SetAspect(nAspect);
123                 Rectangle aRect = pOle2Obj->GetLogicRect();
124 
125                 Size aTmp = aRect.GetSize();
126             	awt::Size aSz( aTmp.Width(), aTmp.Height() );
127                 xObj->setVisualAreaSize( nAspect, aSz );
128             }
129 			SvxOle2Shape* pShape = new SvxOle2Shape( pObj );
130             xShape.set(*pShape,uno::UNO_QUERY);
131 			pShape->setShapeKind(pObj->GetObjIdentifier());
132 			//xShape = new SvxOle2Shape( pOle2Obj );
133         }
134 
135 		if ( !xShape.is() )
136 			xShape.set( SvxDrawPage::_CreateShape( pObj ) );
137 
138         try
139         {
140             OReportModel* pRptModel = static_cast<OReportModel*>(pObj->GetModel());
141             xRet.set( pRptModel->createShape(sServiceName,xShape,bChangeOrientation ? 0 : 1), uno::UNO_QUERY_THROW );
142         }
143         catch( const uno::Exception& )
144         {
145             DBG_UNHANDLED_EXCEPTION();
146         }
147     }
148 
149     return xRet;
150 }
151 
152 }
153