1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewobjectcontactofsdrole2obj.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewobjectcontactofsdrole2obj.hxx>
36 #include <svx/sdr/contact/viewobjectcontactofsdrobj.hxx>
37 #include <svx/sdr/contact/viewcontactofsdrole2obj.hxx>
38 #include <svx/svdoole2.hxx>
39 #include <svx/sdr/contact/objectcontact.hxx>
40 #include <svx/svdview.hxx>
41 #include <drawinglayer/primitive2d/chartprimitive2d.hxx>
42 #include <drawinglayer/attribute/fillattribute.hxx>
43 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
44 #include <basegfx/polygon/b2dpolygontools.hxx>
45 #include <com/sun/star/embed/EmbedMisc.hpp>
46 #include <com/sun/star/embed/EmbedStates.hpp>
48 //////////////////////////////////////////////////////////////////////////////
50 using namespace com::sun::star
;
52 //////////////////////////////////////////////////////////////////////////////
58 const SdrOle2Obj
& ViewObjectContactOfSdrOle2Obj::getSdrOle2Object() const
60 return static_cast< ViewContactOfSdrOle2Obj
& >(GetViewContact()).GetOle2Obj();
63 drawinglayer::primitive2d::Primitive2DSequence
ViewObjectContactOfSdrOle2Obj::createPrimitive2DSequence(
64 const DisplayInfo
& /*rDisplayInfo*/) const
66 // this method is overloaded to do some things the old SdrOle2Obj::DoPaintObject did.
67 // In the future, some of these may be solved different, but ATM try to stay compatible
68 // with the old behaviour
69 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
70 const SdrOle2Obj
& rSdrOle2
= getSdrOle2Object();
74 const svt::EmbeddedObjectRef
& xObjRef
= rSdrOle2
.getEmbeddedObjectRef();
76 nState
= xObjRef
->getCurrentState();
79 const bool bIsOutplaceActive(nState
== embed::EmbedStates::ACTIVE
);
80 const bool bIsInplaceActive((nState
== embed::EmbedStates::INPLACE_ACTIVE
) || (nState
== embed::EmbedStates::UI_ACTIVE
));
81 const bool bIsChart(rSdrOle2
.IsChart());
84 if(!bDone
&& bIsInplaceActive
)
86 if( !GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile() )
88 //no need to create a primitive sequence here as the OLE object does render itself
89 //in case of charts the superfluous creation of a metafile is strongly performance relevant!
96 const Rectangle
& rObjectRectangle(rSdrOle2
.GetGeoRect());
97 const basegfx::B2DRange
aObjectRange(rObjectRectangle
.Left(), rObjectRectangle
.Top(), rObjectRectangle
.Right(), rObjectRectangle
.Bottom());
99 // create object transform
100 basegfx::B2DHomMatrix aObjectTransform
;
101 aObjectTransform
.set(0, 0, aObjectRange
.getWidth());
102 aObjectTransform
.set(1, 1, aObjectRange
.getHeight());
103 aObjectTransform
.set(0, 2, aObjectRange
.getMinX());
104 aObjectTransform
.set(1, 2, aObjectRange
.getMinY());
108 //charts must be painted resolution dependent!! #i82893#, #i75867#
110 // for chart, to not lose the current better quality visualisation which
111 // uses a direct paint, use a primtive wrapper for that exceptional case. The renderers
112 // will then ATM paint it to an OutputDevice directly.
113 // In later versions this should be replaced by getting the Primitive2DSequnce from
114 // the chart and using it.
115 // to be able to render something in non-VCL using renderers, the wrapper is a
116 // GroupPrimitive2D which automatically decomposes to the already created Metafile
118 // For being completely compatible, ATM Window and VDEV PrettyPrinting is suppressed.
119 // It works in the VCL renderers, though. So for activating again with VCL primitive
120 // renderers, change conditions here.
122 // determine if embedding and PrettyPrinting shall be done at all
123 uno::Reference
< frame::XModel
> xChartModel
;
124 bool bDoChartPrettyPrinting(true);
126 // the original ChartPrettyPainter does not do it for Window
127 if(bDoChartPrettyPrinting
&& GetObjectContact().isOutputToWindow())
129 bDoChartPrettyPrinting
= false;
132 // the original ChartPrettyPainter does not do it for VDEV
133 if(bDoChartPrettyPrinting
&& GetObjectContact().isOutputToVirtualDevice())
135 if(GetObjectContact().isOutputToPDFFile())
138 // For PDF files, allow PrettyPrinting
142 bDoChartPrettyPrinting
= false;
146 // the chart model is needed. Check if it's available
147 if(bDoChartPrettyPrinting
)
150 xChartModel
= rSdrOle2
.getXModel();
152 if(!xChartModel
.is())
154 bDoChartPrettyPrinting
= false;
158 if(bDoChartPrettyPrinting
)
160 // embed MetaFile data in a specialized Wrapper Primitive which holds also the ChartModel needed
161 // for PrettyPrinting
162 const drawinglayer::primitive2d::Primitive2DReference
xReference(new drawinglayer::primitive2d::ChartPrimitive2D(
163 xChartModel
, aObjectTransform
, xRetval
));
164 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
171 //old stuff that should be reworked
173 //if no replacement image is available load the OLE object
174 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#
176 // try to create embedded object
177 rSdrOle2
.GetObjRef(); //this loads the OLE object if it is not loaded already
179 const svt::EmbeddedObjectRef
& xObjRef
= rSdrOle2
.getEmbeddedObjectRef();
182 const sal_Int64
nMiscStatus(xObjRef
->getStatus(rSdrOle2
.GetAspect()));
184 // this hack (to change model data during PAINT argh(!)) should be reworked
185 if(!rSdrOle2
.IsResizeProtect() && (nMiscStatus
& embed::EmbedMisc::EMBED_NEVERRESIZE
))
187 const_cast< SdrOle2Obj
* >(&rSdrOle2
)->SetResizeProtect(true);
190 SdrPageView
* pPageView
= GetObjectContact().TryToGetSdrPageView();
191 if(pPageView
&& (nMiscStatus
& embed::EmbedMisc::MS_EMBED_ACTIVATEWHENVISIBLE
))
193 // connect plugin object
194 pPageView
->GetView().DoConnect(const_cast< SdrOle2Obj
* >(&rSdrOle2
));
197 }//end old stuff to rework
199 // create OLE primitive stuff directly at VC with HC as parameter
200 const ViewContactOfSdrOle2Obj
& rVC
= static_cast< const ViewContactOfSdrOle2Obj
& >(GetViewContact());
201 xRetval
= rVC
.createPrimitive2DSequenceWithParameters(GetObjectContact().isDrawModeHighContrast());
204 if(bIsOutplaceActive
)
206 // do not shade when printing or PDF exporting
207 if(!GetObjectContact().isOutputToPrinter() && !GetObjectContact().isOutputToRecordingMetaFile())
209 // shade the representation if the object is activated outplace
210 basegfx::B2DPolygon
aObjectOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
211 aObjectOutline
.transform(aObjectTransform
);
213 // Use a FillHatchPrimitive2D with necessary attributes
214 const drawinglayer::attribute::FillHatchAttribute
aFillHatch(
215 drawinglayer::attribute::HATCHSTYLE_SINGLE
, // single hatch
217 45.0 * F_PI180
, // 45 degree diagonal
218 Color(COL_BLACK
).getBColor(), // black color
219 false); // no filling
221 const drawinglayer::primitive2d::Primitive2DReference
xReference(new drawinglayer::primitive2d::PolyPolygonHatchPrimitive2D(
222 basegfx::B2DPolyPolygon(aObjectOutline
),
223 Color(COL_BLACK
).getBColor(),
226 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(xRetval
, xReference
);
235 ViewObjectContactOfSdrOle2Obj::ViewObjectContactOfSdrOle2Obj(ObjectContact
& rObjectContact
, ViewContact
& rViewContact
)
236 : ViewObjectContactOfSdrObj(rObjectContact
, rViewContact
)
240 ViewObjectContactOfSdrOle2Obj::~ViewObjectContactOfSdrOle2Obj()
243 } // end of namespace contact
244 } // end of namespace sdr
246 //////////////////////////////////////////////////////////////////////////////