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