1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #include "precompiled_svx.hxx" 29 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx> 30 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 31 #include <svx/svdoole2.hxx> 32 #include <vcl/svapp.hxx> 33 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> 34 #include <svtools/colorcfg.hxx> 35 #include <basegfx/polygon/b2dpolygontools.hxx> 36 #include <basegfx/polygon/b2dpolygon.hxx> 37 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 38 #include <basegfx/matrix/b2dhommatrixtools.hxx> 39 40 ////////////////////////////////////////////////////////////////////////////// 41 42 namespace drawinglayer 43 { 44 namespace primitive2d 45 { 46 Primitive2DSequence SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 47 { 48 Primitive2DSequence aRetval; 49 const SdrOle2Obj* pSource = (mpSdrOle2Obj.is() ? static_cast< SdrOle2Obj* >(mpSdrOle2Obj.get()) : 0); 50 bool bScaleContent(false); 51 Graphic aGraphic; 52 53 if(pSource) 54 { 55 Graphic* pOLEGraphic = (getHighContrast()) 56 ? pSource->getEmbeddedObjectRef().GetHCGraphic() 57 : pSource->GetGraphic(); 58 59 if(pOLEGraphic) 60 { 61 aGraphic = *pOLEGraphic; 62 bScaleContent = pSource->IsEmptyPresObj(); 63 } 64 } 65 66 if(GRAPHIC_NONE == aGraphic.GetType()) 67 { 68 // no source, use fallback ressource emty OLE graphic 69 const Bitmap aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap()); 70 aGraphic = Graphic(aEmptyOLEBitmap); 71 bScaleContent = true; 72 } 73 74 if(GRAPHIC_NONE != aGraphic.GetType()) 75 { 76 const GraphicObject aGraphicObject(aGraphic); 77 const GraphicAttr aGraphicAttr; 78 drawinglayer::primitive2d::Primitive2DSequence xOLEContent; 79 80 if(bScaleContent) 81 { 82 // get transformation atoms 83 basegfx::B2DVector aScale, aTranslate; 84 double fRotate, fShearX; 85 getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX); 86 87 // get PrefSize from the graphic in 100th mm 88 Size aPrefSize(aGraphic.GetPrefSize()); 89 90 if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit()) 91 { 92 aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM); 93 } 94 else 95 { 96 aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MAP_100TH_MM); 97 } 98 99 const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0); 100 const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0); 101 102 if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0)) 103 { 104 // if content fits into frame, create it 105 basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix( 106 aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY)); 107 aInnerObjectMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate) 108 * aInnerObjectMatrix; 109 110 const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( 111 new drawinglayer::primitive2d::GraphicPrimitive2D( 112 aInnerObjectMatrix, 113 aGraphicObject, 114 aGraphicAttr)); 115 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive); 116 } 117 } 118 else 119 { 120 // create graphic primitive for content 121 const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( 122 new drawinglayer::primitive2d::GraphicPrimitive2D( 123 getObjectTransform(), 124 aGraphicObject, 125 aGraphicAttr)); 126 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive); 127 } 128 129 // a standard gray outline is created for scaled content 130 if(bScaleContent) 131 { 132 const svtools::ColorConfig aColorConfig; 133 const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES)); 134 135 if(aColor.bIsVisible) 136 { 137 basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon()); 138 const Color aVclColor(aColor.nColor); 139 aOutline.transform(getObjectTransform()); 140 const drawinglayer::primitive2d::Primitive2DReference xOutline( 141 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aVclColor.getBColor())); 142 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xOutline); 143 } 144 } 145 } 146 147 // get graphic and check scale content state 148 return aRetval; 149 } 150 151 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D( 152 const SdrOle2Obj& rSdrOle2Obj, 153 const basegfx::B2DHomMatrix& rObjectTransform, 154 sal_uInt32 nGraphicVersion, 155 bool bHighContrast) 156 : BufferedDecompositionPrimitive2D(), 157 mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)), 158 maObjectTransform(rObjectTransform), 159 mnGraphicVersion(nGraphicVersion), 160 mbHighContrast(bHighContrast) 161 { 162 } 163 164 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 165 { 166 if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 167 { 168 const SdrOleContentPrimitive2D& rCompare = (SdrOleContentPrimitive2D&)rPrimitive; 169 const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is()); 170 const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is() 171 && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get()); 172 173 return ((bBothNot || bBothAndEqual) 174 && getObjectTransform() == rCompare.getObjectTransform() 175 176 // #i104867# to find out if the Graphic content of the 177 // OLE has changed, use GraphicVersion number 178 && getGraphicVersion() == rCompare.getGraphicVersion() 179 180 && getHighContrast() == rCompare.getHighContrast()); 181 } 182 183 return false; 184 } 185 186 basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 187 { 188 basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0); 189 aRange.transform(getObjectTransform()); 190 191 return aRange; 192 } 193 194 // provide unique ID 195 ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D) 196 197 } // end of namespace primitive2d 198 } // end of namespace drawinglayer 199 200 ////////////////////////////////////////////////////////////////////////////// 201 // eof 202