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