xref: /AOO41X/main/svx/source/sdr/contact/viewobjectcontactofsdrole2obj.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svx.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
32*cdf0e10cSrcweir #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
33*cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
34*cdf0e10cSrcweir #include <svx/svdoole2.hxx>
35*cdf0e10cSrcweir #include <svx/sdr/contact/objectcontact.hxx>
36*cdf0e10cSrcweir #include <svx/svdview.hxx>
37*cdf0e10cSrcweir #include <drawinglayer/primitive2d/chartprimitive2d.hxx>
38*cdf0e10cSrcweir #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
39*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
40*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedMisc.hpp>
41*cdf0e10cSrcweir #include <com/sun/star/embed/EmbedStates.hpp>
42*cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx>
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir using namespace com::sun::star;
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir namespace sdr
51*cdf0e10cSrcweir {
52*cdf0e10cSrcweir 	namespace contact
53*cdf0e10cSrcweir 	{
54*cdf0e10cSrcweir 		const SdrOle2Obj& ViewObjectContactOfSdrOle2Obj::getSdrOle2Object() const
55*cdf0e10cSrcweir 		{
56*cdf0e10cSrcweir 			return static_cast< ViewContactOfSdrOle2Obj& >(GetViewContact()).GetOle2Obj();
57*cdf0e10cSrcweir 		}
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
60*cdf0e10cSrcweir             const DisplayInfo& /*rDisplayInfo*/) const
61*cdf0e10cSrcweir 		{
62*cdf0e10cSrcweir 			// this method is overloaded to do some things the old SdrOle2Obj::DoPaintObject did.
63*cdf0e10cSrcweir 		    // In the future, some of these may be solved different, but ATM try to stay compatible
64*cdf0e10cSrcweir 		    // with the old behaviour
65*cdf0e10cSrcweir 		    drawinglayer::primitive2d::Primitive2DSequence xRetval;
66*cdf0e10cSrcweir 		    const SdrOle2Obj& rSdrOle2 = getSdrOle2Object();
67*cdf0e10cSrcweir             sal_Int32 nState(-1);
68*cdf0e10cSrcweir 
69*cdf0e10cSrcweir             {
70*cdf0e10cSrcweir                 const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
71*cdf0e10cSrcweir                 if ( xObjRef.is() )
72*cdf0e10cSrcweir                     nState = xObjRef->getCurrentState();
73*cdf0e10cSrcweir             }
74*cdf0e10cSrcweir 
75*cdf0e10cSrcweir             const bool bIsOutplaceActive(nState == embed::EmbedStates::ACTIVE);
76*cdf0e10cSrcweir             const bool bIsInplaceActive((nState == embed::EmbedStates::INPLACE_ACTIVE) || (nState == embed::EmbedStates::UI_ACTIVE));
77*cdf0e10cSrcweir             const bool bIsChart(rSdrOle2.IsChart());
78*cdf0e10cSrcweir             bool bDone(false);
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir             if(!bDone && bIsInplaceActive)
81*cdf0e10cSrcweir             {
82*cdf0e10cSrcweir                 if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
83*cdf0e10cSrcweir                 {
84*cdf0e10cSrcweir                     //no need to create a primitive sequence here as the OLE object does render itself
85*cdf0e10cSrcweir                     //in case of charts the superfluous creation of a metafile is strongly performance relevant!
86*cdf0e10cSrcweir                     bDone = true;
87*cdf0e10cSrcweir                 }
88*cdf0e10cSrcweir             }
89*cdf0e10cSrcweir 
90*cdf0e10cSrcweir             if( !bDone )
91*cdf0e10cSrcweir             {
92*cdf0e10cSrcweir                 const Rectangle& rObjectRectangle(rSdrOle2.GetGeoRect());
93*cdf0e10cSrcweir 		        const basegfx::B2DRange aObjectRange(rObjectRectangle.Left(), rObjectRectangle.Top(), rObjectRectangle.Right(), rObjectRectangle.Bottom());
94*cdf0e10cSrcweir 
95*cdf0e10cSrcweir 		        // create object transform
96*cdf0e10cSrcweir 		        basegfx::B2DHomMatrix aObjectTransform;
97*cdf0e10cSrcweir 		        aObjectTransform.set(0, 0, aObjectRange.getWidth());
98*cdf0e10cSrcweir 		        aObjectTransform.set(1, 1, aObjectRange.getHeight());
99*cdf0e10cSrcweir 		        aObjectTransform.set(0, 2, aObjectRange.getMinX());
100*cdf0e10cSrcweir 		        aObjectTransform.set(1, 2, aObjectRange.getMinY());
101*cdf0e10cSrcweir 
102*cdf0e10cSrcweir                 if(bIsChart)
103*cdf0e10cSrcweir 		        {
104*cdf0e10cSrcweir                     //charts must be painted resolution dependent!! #i82893#, #i75867#
105*cdf0e10cSrcweir 
106*cdf0e10cSrcweir 			        // for chart, to not lose the current better quality visualisation which
107*cdf0e10cSrcweir 			        // uses a direct paint, use a primtive wrapper for that exceptional case. The renderers
108*cdf0e10cSrcweir 			        // will then ATM paint it to an OutputDevice directly.
109*cdf0e10cSrcweir 			        // In later versions this should be replaced by getting the Primitive2DSequnce from
110*cdf0e10cSrcweir 			        // the chart and using it.
111*cdf0e10cSrcweir 			        // to be able to render something in non-VCL using renderers, the wrapper is a
112*cdf0e10cSrcweir 			        // GroupPrimitive2D which automatically decomposes to the already created Metafile
113*cdf0e10cSrcweir 			        // content.
114*cdf0e10cSrcweir 			        // For being completely compatible, ATM Window and VDEV PrettyPrinting is suppressed.
115*cdf0e10cSrcweir 			        // It works in the VCL renderers, though. So for activating again with VCL primitive
116*cdf0e10cSrcweir 			        // renderers, change conditions here.
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir 			        // determine if embedding and PrettyPrinting shall be done at all
119*cdf0e10cSrcweir 			        uno::Reference< frame::XModel > xChartModel;
120*cdf0e10cSrcweir 			        bool bDoChartPrettyPrinting(true);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir 			        // the original ChartPrettyPainter does not do it for Window
123*cdf0e10cSrcweir 			        if(bDoChartPrettyPrinting && GetObjectContact().isOutputToWindow())
124*cdf0e10cSrcweir 			        {
125*cdf0e10cSrcweir 				        bDoChartPrettyPrinting = false;
126*cdf0e10cSrcweir 			        }
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir 			        // the original ChartPrettyPainter does not do it for VDEV
129*cdf0e10cSrcweir 			        if(bDoChartPrettyPrinting && GetObjectContact().isOutputToVirtualDevice())
130*cdf0e10cSrcweir 			        {
131*cdf0e10cSrcweir 				        if(GetObjectContact().isOutputToPDFFile())
132*cdf0e10cSrcweir 				        {
133*cdf0e10cSrcweir 					        // #i97982#
134*cdf0e10cSrcweir 					        // For PDF files, allow PrettyPrinting
135*cdf0e10cSrcweir 				        }
136*cdf0e10cSrcweir 				        else
137*cdf0e10cSrcweir 				        {
138*cdf0e10cSrcweir 					        bDoChartPrettyPrinting = false;
139*cdf0e10cSrcweir 				        }
140*cdf0e10cSrcweir 			        }
141*cdf0e10cSrcweir 
142*cdf0e10cSrcweir 			        // the chart model is needed. Check if it's available
143*cdf0e10cSrcweir 			        if(bDoChartPrettyPrinting)
144*cdf0e10cSrcweir 			        {
145*cdf0e10cSrcweir 				        // get chart model
146*cdf0e10cSrcweir 				        xChartModel = rSdrOle2.getXModel();
147*cdf0e10cSrcweir 
148*cdf0e10cSrcweir 				        if(!xChartModel.is())
149*cdf0e10cSrcweir 				        {
150*cdf0e10cSrcweir 					        bDoChartPrettyPrinting = false;
151*cdf0e10cSrcweir 				        }
152*cdf0e10cSrcweir 			        }
153*cdf0e10cSrcweir 
154*cdf0e10cSrcweir 			        if(bDoChartPrettyPrinting)
155*cdf0e10cSrcweir 			        {
156*cdf0e10cSrcweir 				        // embed MetaFile data in a specialized Wrapper Primitive which holds also the ChartModel needed
157*cdf0e10cSrcweir 				        // for PrettyPrinting
158*cdf0e10cSrcweir 				        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::ChartPrimitive2D(
159*cdf0e10cSrcweir 					        xChartModel, aObjectTransform, xRetval));
160*cdf0e10cSrcweir 				        xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
161*cdf0e10cSrcweir                         bDone = true;
162*cdf0e10cSrcweir 			        }
163*cdf0e10cSrcweir 		        }
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir                 if( !bDone )
166*cdf0e10cSrcweir                 {
167*cdf0e10cSrcweir                     //old stuff that should be reworked
168*cdf0e10cSrcweir                     {
169*cdf0e10cSrcweir                         //if no replacement image is available load the OLE object
170*cdf0e10cSrcweir                         if(!rSdrOle2.GetGraphic()) //try to fetch the metafile - this can lead to the actual creation of the metafile what can be extremely expensive (e.g. for big charts)!!! #i101925#
171*cdf0e10cSrcweir                         {
172*cdf0e10cSrcweir 	                        // try to create embedded object
173*cdf0e10cSrcweir                             rSdrOle2.GetObjRef(); //this loads the OLE object if it is not loaded already
174*cdf0e10cSrcweir                         }
175*cdf0e10cSrcweir                         const svt::EmbeddedObjectRef& xObjRef  = rSdrOle2.getEmbeddedObjectRef();
176*cdf0e10cSrcweir                         if(xObjRef.is())
177*cdf0e10cSrcweir                         {
178*cdf0e10cSrcweir                             const sal_Int64 nMiscStatus(xObjRef->getStatus(rSdrOle2.GetAspect()));
179*cdf0e10cSrcweir 
180*cdf0e10cSrcweir                             // this hack (to change model data during PAINT argh(!)) should be reworked
181*cdf0e10cSrcweir                             if(!rSdrOle2.IsResizeProtect() && (nMiscStatus & embed::EmbedMisc::EMBED_NEVERRESIZE))
182*cdf0e10cSrcweir                             {
183*cdf0e10cSrcweir 	                            const_cast< SdrOle2Obj* >(&rSdrOle2)->SetResizeProtect(true);
184*cdf0e10cSrcweir                             }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir                             SdrPageView* pPageView = GetObjectContact().TryToGetSdrPageView();
187*cdf0e10cSrcweir 	                        if(pPageView && (nMiscStatus & embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE))
188*cdf0e10cSrcweir 	                        {
189*cdf0e10cSrcweir 		                        // connect plugin object
190*cdf0e10cSrcweir 		                        pPageView->GetView().DoConnect(const_cast< SdrOle2Obj* >(&rSdrOle2));
191*cdf0e10cSrcweir 	                        }
192*cdf0e10cSrcweir                         }
193*cdf0e10cSrcweir                     }//end old stuff to rework
194*cdf0e10cSrcweir 
195*cdf0e10cSrcweir                     // create OLE primitive stuff directly at VC with HC as parameter
196*cdf0e10cSrcweir 		            const ViewContactOfSdrOle2Obj& rVC = static_cast< const ViewContactOfSdrOle2Obj& >(GetViewContact());
197*cdf0e10cSrcweir                     xRetval = rVC.createPrimitive2DSequenceWithParameters(GetObjectContact().isDrawModeHighContrast());
198*cdf0e10cSrcweir                 }
199*cdf0e10cSrcweir 
200*cdf0e10cSrcweir                 if(bIsOutplaceActive)
201*cdf0e10cSrcweir 		        {
202*cdf0e10cSrcweir 			        // do not shade when printing or PDF exporting
203*cdf0e10cSrcweir 			        if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
204*cdf0e10cSrcweir 			        {
205*cdf0e10cSrcweir 				        // shade the representation if the object is activated outplace
206*cdf0e10cSrcweir 				        basegfx::B2DPolygon aObjectOutline(basegfx::tools::createUnitPolygon());
207*cdf0e10cSrcweir 				        aObjectOutline.transform(aObjectTransform);
208*cdf0e10cSrcweir 
209*cdf0e10cSrcweir 				        // Use a FillHatchPrimitive2D with necessary attributes
210*cdf0e10cSrcweir 				        const drawinglayer::attribute::FillHatchAttribute aFillHatch(
211*cdf0e10cSrcweir 					        drawinglayer::attribute::HATCHSTYLE_SINGLE, // single hatch
212*cdf0e10cSrcweir 					        125.0, // 1.25 mm
213*cdf0e10cSrcweir 					        45.0 * F_PI180, // 45 degree diagonal
214*cdf0e10cSrcweir 					        Color(COL_BLACK).getBColor(), // black color
215*cdf0e10cSrcweir 					        false); // no filling
216*cdf0e10cSrcweir 
217*cdf0e10cSrcweir 				        const drawinglayer::primitive2d::Primitive2DReference xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
218*cdf0e10cSrcweir 					        basegfx::B2DPolyPolygon(aObjectOutline),
219*cdf0e10cSrcweir 					        Color(COL_BLACK).getBColor(),
220*cdf0e10cSrcweir 					        aFillHatch));
221*cdf0e10cSrcweir 
222*cdf0e10cSrcweir 				        drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval, xReference);
223*cdf0e10cSrcweir 			        }
224*cdf0e10cSrcweir 		        }
225*cdf0e10cSrcweir 
226*cdf0e10cSrcweir             }
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir 		    return xRetval;
229*cdf0e10cSrcweir 		}
230*cdf0e10cSrcweir 
231*cdf0e10cSrcweir 		ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact& rObjectContact, ViewContact& rViewContact)
232*cdf0e10cSrcweir 		:	ViewObjectContactOfSdrObj(rObjectContact, rViewContact)
233*cdf0e10cSrcweir 		{
234*cdf0e10cSrcweir 		}
235*cdf0e10cSrcweir 
236*cdf0e10cSrcweir 		ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
237*cdf0e10cSrcweir 		{
238*cdf0e10cSrcweir 		}
239*cdf0e10cSrcweir 	} // end of namespace contact
240*cdf0e10cSrcweir } // end of namespace sdr
241*cdf0e10cSrcweir 
242*cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
243*cdf0e10cSrcweir // eof
244