1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10*f6e50924SAndrew Rist * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f6e50924SAndrew Rist * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19*f6e50924SAndrew Rist * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #include "precompiled_svx.hxx" 25cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx> 26cdf0e10cSrcweir #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx> 27cdf0e10cSrcweir #include <svx/svdoole2.hxx> 28cdf0e10cSrcweir #include <vcl/svapp.hxx> 29cdf0e10cSrcweir #include <drawinglayer/primitive2d/graphicprimitive2d.hxx> 30cdf0e10cSrcweir #include <svtools/colorcfg.hxx> 31cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx> 32cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygon.hxx> 33cdf0e10cSrcweir #include <drawinglayer/primitive2d/polygonprimitive2d.hxx> 34cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx> 35cdf0e10cSrcweir 36cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 37cdf0e10cSrcweir 38cdf0e10cSrcweir namespace drawinglayer 39cdf0e10cSrcweir { 40cdf0e10cSrcweir namespace primitive2d 41cdf0e10cSrcweir { 42cdf0e10cSrcweir Primitive2DSequence SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const 43cdf0e10cSrcweir { 44cdf0e10cSrcweir Primitive2DSequence aRetval; 45cdf0e10cSrcweir const SdrOle2Obj* pSource = (mpSdrOle2Obj.is() ? static_cast< SdrOle2Obj* >(mpSdrOle2Obj.get()) : 0); 46cdf0e10cSrcweir bool bScaleContent(false); 47cdf0e10cSrcweir Graphic aGraphic; 48cdf0e10cSrcweir 49cdf0e10cSrcweir if(pSource) 50cdf0e10cSrcweir { 51cdf0e10cSrcweir Graphic* pOLEGraphic = (getHighContrast()) 52cdf0e10cSrcweir ? pSource->getEmbeddedObjectRef().GetHCGraphic() 53cdf0e10cSrcweir : pSource->GetGraphic(); 54cdf0e10cSrcweir 55cdf0e10cSrcweir if(pOLEGraphic) 56cdf0e10cSrcweir { 57cdf0e10cSrcweir aGraphic = *pOLEGraphic; 58cdf0e10cSrcweir bScaleContent = pSource->IsEmptyPresObj(); 59cdf0e10cSrcweir } 60cdf0e10cSrcweir } 61cdf0e10cSrcweir 62cdf0e10cSrcweir if(GRAPHIC_NONE == aGraphic.GetType()) 63cdf0e10cSrcweir { 64cdf0e10cSrcweir // no source, use fallback ressource emty OLE graphic 65cdf0e10cSrcweir const Bitmap aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap()); 66cdf0e10cSrcweir aGraphic = Graphic(aEmptyOLEBitmap); 67cdf0e10cSrcweir bScaleContent = true; 68cdf0e10cSrcweir } 69cdf0e10cSrcweir 70cdf0e10cSrcweir if(GRAPHIC_NONE != aGraphic.GetType()) 71cdf0e10cSrcweir { 72cdf0e10cSrcweir const GraphicObject aGraphicObject(aGraphic); 73cdf0e10cSrcweir const GraphicAttr aGraphicAttr; 74cdf0e10cSrcweir drawinglayer::primitive2d::Primitive2DSequence xOLEContent; 75cdf0e10cSrcweir 76cdf0e10cSrcweir if(bScaleContent) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir // get transformation atoms 79cdf0e10cSrcweir basegfx::B2DVector aScale, aTranslate; 80cdf0e10cSrcweir double fRotate, fShearX; 81cdf0e10cSrcweir getObjectTransform().decompose(aScale, aTranslate, fRotate, fShearX); 82cdf0e10cSrcweir 83cdf0e10cSrcweir // get PrefSize from the graphic in 100th mm 84cdf0e10cSrcweir Size aPrefSize(aGraphic.GetPrefSize()); 85cdf0e10cSrcweir 86cdf0e10cSrcweir if(MAP_PIXEL == aGraphic.GetPrefMapMode().GetMapUnit()) 87cdf0e10cSrcweir { 88cdf0e10cSrcweir aPrefSize = Application::GetDefaultDevice()->PixelToLogic(aPrefSize, MAP_100TH_MM); 89cdf0e10cSrcweir } 90cdf0e10cSrcweir else 91cdf0e10cSrcweir { 92cdf0e10cSrcweir aPrefSize = Application::GetDefaultDevice()->LogicToLogic(aPrefSize, aGraphic.GetPrefMapMode(), MAP_100TH_MM); 93cdf0e10cSrcweir } 94cdf0e10cSrcweir 95cdf0e10cSrcweir const double fOffsetX((aScale.getX() - aPrefSize.getWidth()) / 2.0); 96cdf0e10cSrcweir const double fOffsetY((aScale.getY() - aPrefSize.getHeight()) / 2.0); 97cdf0e10cSrcweir 98cdf0e10cSrcweir if(basegfx::fTools::moreOrEqual(fOffsetX, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY, 0.0)) 99cdf0e10cSrcweir { 100cdf0e10cSrcweir // if content fits into frame, create it 101cdf0e10cSrcweir basegfx::B2DHomMatrix aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix( 102cdf0e10cSrcweir aPrefSize.getWidth(), aPrefSize.getHeight(), fOffsetX, fOffsetY)); 103cdf0e10cSrcweir aInnerObjectMatrix = basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX, fRotate, aTranslate) 104cdf0e10cSrcweir * aInnerObjectMatrix; 105cdf0e10cSrcweir 106cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( 107cdf0e10cSrcweir new drawinglayer::primitive2d::GraphicPrimitive2D( 108cdf0e10cSrcweir aInnerObjectMatrix, 109cdf0e10cSrcweir aGraphicObject, 110cdf0e10cSrcweir aGraphicAttr)); 111cdf0e10cSrcweir drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive); 112cdf0e10cSrcweir } 113cdf0e10cSrcweir } 114cdf0e10cSrcweir else 115cdf0e10cSrcweir { 116cdf0e10cSrcweir // create graphic primitive for content 117cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference aGraphicPrimitive( 118cdf0e10cSrcweir new drawinglayer::primitive2d::GraphicPrimitive2D( 119cdf0e10cSrcweir getObjectTransform(), 120cdf0e10cSrcweir aGraphicObject, 121cdf0e10cSrcweir aGraphicAttr)); 122cdf0e10cSrcweir drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aGraphicPrimitive); 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir // a standard gray outline is created for scaled content 126cdf0e10cSrcweir if(bScaleContent) 127cdf0e10cSrcweir { 128cdf0e10cSrcweir const svtools::ColorConfig aColorConfig; 129cdf0e10cSrcweir const svtools::ColorConfigValue aColor(aColorConfig.GetColorValue(svtools::OBJECTBOUNDARIES)); 130cdf0e10cSrcweir 131cdf0e10cSrcweir if(aColor.bIsVisible) 132cdf0e10cSrcweir { 133cdf0e10cSrcweir basegfx::B2DPolygon aOutline(basegfx::tools::createUnitPolygon()); 134cdf0e10cSrcweir const Color aVclColor(aColor.nColor); 135cdf0e10cSrcweir aOutline.transform(getObjectTransform()); 136cdf0e10cSrcweir const drawinglayer::primitive2d::Primitive2DReference xOutline( 137cdf0e10cSrcweir new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline, aVclColor.getBColor())); 138cdf0e10cSrcweir drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, xOutline); 139cdf0e10cSrcweir } 140cdf0e10cSrcweir } 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir // get graphic and check scale content state 144cdf0e10cSrcweir return aRetval; 145cdf0e10cSrcweir } 146cdf0e10cSrcweir 147cdf0e10cSrcweir SdrOleContentPrimitive2D::SdrOleContentPrimitive2D( 148cdf0e10cSrcweir const SdrOle2Obj& rSdrOle2Obj, 149cdf0e10cSrcweir const basegfx::B2DHomMatrix& rObjectTransform, 150cdf0e10cSrcweir sal_uInt32 nGraphicVersion, 151cdf0e10cSrcweir bool bHighContrast) 152cdf0e10cSrcweir : BufferedDecompositionPrimitive2D(), 153cdf0e10cSrcweir mpSdrOle2Obj(const_cast< SdrOle2Obj* >(&rSdrOle2Obj)), 154cdf0e10cSrcweir maObjectTransform(rObjectTransform), 155cdf0e10cSrcweir mnGraphicVersion(nGraphicVersion), 156cdf0e10cSrcweir mbHighContrast(bHighContrast) 157cdf0e10cSrcweir { 158cdf0e10cSrcweir } 159cdf0e10cSrcweir 160cdf0e10cSrcweir bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const 161cdf0e10cSrcweir { 162cdf0e10cSrcweir if(BufferedDecompositionPrimitive2D::operator==(rPrimitive)) 163cdf0e10cSrcweir { 164cdf0e10cSrcweir const SdrOleContentPrimitive2D& rCompare = (SdrOleContentPrimitive2D&)rPrimitive; 165cdf0e10cSrcweir const bool bBothNot(!mpSdrOle2Obj.is() && !rCompare.mpSdrOle2Obj.is()); 166cdf0e10cSrcweir const bool bBothAndEqual(mpSdrOle2Obj.is() && rCompare.mpSdrOle2Obj.is() 167cdf0e10cSrcweir && mpSdrOle2Obj.get() == rCompare.mpSdrOle2Obj.get()); 168cdf0e10cSrcweir 169cdf0e10cSrcweir return ((bBothNot || bBothAndEqual) 170cdf0e10cSrcweir && getObjectTransform() == rCompare.getObjectTransform() 171cdf0e10cSrcweir 172cdf0e10cSrcweir // #i104867# to find out if the Graphic content of the 173cdf0e10cSrcweir // OLE has changed, use GraphicVersion number 174cdf0e10cSrcweir && getGraphicVersion() == rCompare.getGraphicVersion() 175cdf0e10cSrcweir 176cdf0e10cSrcweir && getHighContrast() == rCompare.getHighContrast()); 177cdf0e10cSrcweir } 178cdf0e10cSrcweir 179cdf0e10cSrcweir return false; 180cdf0e10cSrcweir } 181cdf0e10cSrcweir 182cdf0e10cSrcweir basegfx::B2DRange SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D& /*rViewInformation*/) const 183cdf0e10cSrcweir { 184cdf0e10cSrcweir basegfx::B2DRange aRange(0.0, 0.0, 1.0, 1.0); 185cdf0e10cSrcweir aRange.transform(getObjectTransform()); 186cdf0e10cSrcweir 187cdf0e10cSrcweir return aRange; 188cdf0e10cSrcweir } 189cdf0e10cSrcweir 190cdf0e10cSrcweir // provide unique ID 191cdf0e10cSrcweir ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D) 192cdf0e10cSrcweir 193cdf0e10cSrcweir } // end of namespace primitive2d 194cdf0e10cSrcweir } // end of namespace drawinglayer 195cdf0e10cSrcweir 196cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////// 197cdf0e10cSrcweir // eof 198