1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sdr/primitive2d/sdrolecontentprimitive2d.hxx>
21 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
22 #include <svx/svdoole2.hxx>
23 #include <vcl/svapp.hxx>
24 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
25 #include <svtools/colorcfg.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
29 #include <basegfx/matrix/b2dhommatrixtools.hxx>
32 namespace drawinglayer::primitive2d
34 void SdrOleContentPrimitive2D::create2DDecomposition(Primitive2DContainer
& rContainer
, const geometry::ViewInformation2D
& /*aViewInformation*/) const
36 const SdrOle2Obj
* pSource
= mpSdrOle2Obj
.get();
37 bool bScaleContent(false);
42 const Graphic
* pOLEGraphic
= pSource
->GetGraphic();
46 aGraphic
= *pOLEGraphic
;
47 bScaleContent
= pSource
->IsEmptyPresObj();
50 #ifdef _WIN32 // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe?
51 if(GraphicType::NONE
== aGraphic
.GetType())
53 // no source, use fallback resource empty OLE graphic
54 aGraphic
= SdrOle2Obj::GetEmptyOLEReplacementGraphic();
58 if(GraphicType::NONE
== aGraphic
.GetType())
61 const GraphicObject
aGraphicObject(aGraphic
);
62 const GraphicAttr aGraphicAttr
;
66 // get transformation atoms
67 basegfx::B2DVector aScale
, aTranslate
;
68 double fRotate
, fShearX
;
69 getObjectTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
71 // get PrefSize from the graphic in 100th mm
72 Size
aPrefSize(aGraphic
.GetPrefSize());
74 if(MapUnit::MapPixel
== aGraphic
.GetPrefMapMode().GetMapUnit())
76 aPrefSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MapMode(MapUnit::Map100thMM
));
80 aPrefSize
= OutputDevice::LogicToLogic(aPrefSize
, aGraphic
.GetPrefMapMode(), MapMode(MapUnit::Map100thMM
));
83 const double fOffsetX((aScale
.getX() - aPrefSize
.getWidth()) / 2.0);
84 const double fOffsetY((aScale
.getY() - aPrefSize
.getHeight()) / 2.0);
86 if(basegfx::fTools::moreOrEqual(fOffsetX
, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY
, 0.0))
88 // if content fits into frame, create it
89 basegfx::B2DHomMatrix
aInnerObjectMatrix(basegfx::utils::createScaleTranslateB2DHomMatrix(
90 aPrefSize
.getWidth(), aPrefSize
.getHeight(), fOffsetX
, fOffsetY
));
91 aInnerObjectMatrix
= basegfx::utils::createShearXRotateTranslateB2DHomMatrix(fShearX
, fRotate
, aTranslate
)
94 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
95 new drawinglayer::primitive2d::GraphicPrimitive2D(
99 rContainer
.push_back(aGraphicPrimitive
);
104 // create graphic primitive for content
105 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
106 new drawinglayer::primitive2d::GraphicPrimitive2D(
107 getObjectTransform(),
110 rContainer
.push_back(aGraphicPrimitive
);
113 // a standard gray outline is created for scaled content
117 const svtools::ColorConfig aColorConfig
;
118 const svtools::ColorConfigValue
aColor(aColorConfig
.GetColorValue(svtools::OBJECTBOUNDARIES
));
120 if(aColor
.bIsVisible
)
122 basegfx::B2DPolygon
aOutline(basegfx::utils::createUnitPolygon());
123 const Color
aVclColor(aColor
.nColor
);
124 aOutline
.transform(getObjectTransform());
125 const drawinglayer::primitive2d::Primitive2DReference
xOutline(
126 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline
, aVclColor
.getBColor()));
127 rContainer
.push_back(xOutline
);
131 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
132 const SdrOle2Obj
& rSdrOle2Obj
,
133 const basegfx::B2DHomMatrix
& rObjectTransform
,
134 sal_uInt32 nGraphicVersion
136 : BufferedDecompositionPrimitive2D(),
137 mpSdrOle2Obj(const_cast< SdrOle2Obj
* >(&rSdrOle2Obj
)),
138 maObjectTransform(rObjectTransform
),
139 mnGraphicVersion(nGraphicVersion
)
143 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
145 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive
) )
147 const SdrOleContentPrimitive2D
& rCompare
= static_cast<const SdrOleContentPrimitive2D
&>(rPrimitive
);
148 const bool bBothNot(!mpSdrOle2Obj
.is() && !rCompare
.mpSdrOle2Obj
.is());
149 const bool bBothAndEqual(mpSdrOle2Obj
.is() && rCompare
.mpSdrOle2Obj
.is()
150 && mpSdrOle2Obj
.get() == rCompare
.mpSdrOle2Obj
.get());
152 return ((bBothNot
|| bBothAndEqual
)
153 && getObjectTransform() == rCompare
.getObjectTransform()
155 // #i104867# to find out if the Graphic content of the
156 // OLE has changed, use GraphicVersion number
157 && mnGraphicVersion
== rCompare
.mnGraphicVersion
164 basegfx::B2DRange
SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
166 basegfx::B2DRange
aRange(0.0, 0.0, 1.0, 1.0);
167 aRange
.transform(getObjectTransform());
173 ImplPrimitive2DIDBlock(SdrOleContentPrimitive2D
, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
)
175 } // end of namespace
177 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */