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>
33 namespace drawinglayer
37 Primitive2DSequence
SdrOleContentPrimitive2D::create2DDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
39 Primitive2DSequence aRetval
;
40 const SdrOle2Obj
* pSource
= (mpSdrOle2Obj
.is() ? static_cast< SdrOle2Obj
* >(mpSdrOle2Obj
.get()) : 0);
41 bool bScaleContent(false);
46 const Graphic
* pOLEGraphic
= pSource
->GetGraphic();
50 aGraphic
= *pOLEGraphic
;
51 bScaleContent
= pSource
->IsEmptyPresObj();
54 #ifdef WNT // Little point in displaying the "broken OLE" graphic on OSes that don't have real OLE, maybe?
55 if(GRAPHIC_NONE
== aGraphic
.GetType())
57 // no source, use fallback resource emty OLE graphic
58 aGraphic
= SdrOle2Obj::GetEmptyOLEReplacementGraphic();
62 if(GRAPHIC_NONE
!= aGraphic
.GetType())
64 const GraphicObject
aGraphicObject(aGraphic
);
65 const GraphicAttr aGraphicAttr
;
69 // get transformation atoms
70 basegfx::B2DVector aScale
, aTranslate
;
71 double fRotate
, fShearX
;
72 getObjectTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
74 // get PrefSize from the graphic in 100th mm
75 Size
aPrefSize(aGraphic
.GetPrefSize());
77 if(MAP_PIXEL
== aGraphic
.GetPrefMapMode().GetMapUnit())
79 aPrefSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MAP_100TH_MM
);
83 aPrefSize
= OutputDevice::LogicToLogic(aPrefSize
, aGraphic
.GetPrefMapMode(), MAP_100TH_MM
);
86 const double fOffsetX((aScale
.getX() - aPrefSize
.getWidth()) / 2.0);
87 const double fOffsetY((aScale
.getY() - aPrefSize
.getHeight()) / 2.0);
89 if(basegfx::fTools::moreOrEqual(fOffsetX
, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY
, 0.0))
91 // if content fits into frame, create it
92 basegfx::B2DHomMatrix
aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
93 aPrefSize
.getWidth(), aPrefSize
.getHeight(), fOffsetX
, fOffsetY
));
94 aInnerObjectMatrix
= basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX
, fRotate
, aTranslate
)
97 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
98 new drawinglayer::primitive2d::GraphicPrimitive2D(
102 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
107 // create graphic primitive for content
108 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
109 new drawinglayer::primitive2d::GraphicPrimitive2D(
110 getObjectTransform(),
113 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
116 // a standard gray outline is created for scaled content
119 const svtools::ColorConfig aColorConfig
;
120 const svtools::ColorConfigValue
aColor(aColorConfig
.GetColorValue(svtools::OBJECTBOUNDARIES
));
122 if(aColor
.bIsVisible
)
124 basegfx::B2DPolygon
aOutline(basegfx::tools::createUnitPolygon());
125 const Color
aVclColor(aColor
.nColor
);
126 aOutline
.transform(getObjectTransform());
127 const drawinglayer::primitive2d::Primitive2DReference
xOutline(
128 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline
, aVclColor
.getBColor()));
129 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, xOutline
);
134 // get graphic and check scale content state
138 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
139 const SdrOle2Obj
& rSdrOle2Obj
,
140 const basegfx::B2DHomMatrix
& rObjectTransform
,
141 sal_uInt32 nGraphicVersion
143 : BufferedDecompositionPrimitive2D(),
144 mpSdrOle2Obj(const_cast< SdrOle2Obj
* >(&rSdrOle2Obj
)),
145 maObjectTransform(rObjectTransform
),
146 mnGraphicVersion(nGraphicVersion
)
150 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
152 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive
) )
154 const SdrOleContentPrimitive2D
& rCompare
= static_cast<const SdrOleContentPrimitive2D
&>(rPrimitive
);
155 const bool bBothNot(!mpSdrOle2Obj
.is() && !rCompare
.mpSdrOle2Obj
.is());
156 const bool bBothAndEqual(mpSdrOle2Obj
.is() && rCompare
.mpSdrOle2Obj
.is()
157 && mpSdrOle2Obj
.get() == rCompare
.mpSdrOle2Obj
.get());
159 return ((bBothNot
|| bBothAndEqual
)
160 && getObjectTransform() == rCompare
.getObjectTransform()
162 // #i104867# to find out if the Graphic content of the
163 // OLE has changed, use GraphicVersion number
164 && getGraphicVersion() == rCompare
.getGraphicVersion()
171 basegfx::B2DRange
SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
173 basegfx::B2DRange
aRange(0.0, 0.0, 1.0, 1.0);
174 aRange
.transform(getObjectTransform());
180 ImplPrimitive2DIDBlock(SdrOleContentPrimitive2D
, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
)
182 } // end of namespace primitive2d
183 } // end of namespace drawinglayer
185 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */