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