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