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 <svx/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>
31 //////////////////////////////////////////////////////////////////////////////
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 const Bitmap
aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap());
59 aGraphic
= Graphic(aEmptyOLEBitmap
);
63 if(GRAPHIC_NONE
!= aGraphic
.GetType())
65 const GraphicObject
aGraphicObject(aGraphic
);
66 const GraphicAttr aGraphicAttr
;
67 drawinglayer::primitive2d::Primitive2DSequence xOLEContent
;
71 // get transformation atoms
72 basegfx::B2DVector aScale
, aTranslate
;
73 double fRotate
, fShearX
;
74 getObjectTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
76 // get PrefSize from the graphic in 100th mm
77 Size
aPrefSize(aGraphic
.GetPrefSize());
79 if(MAP_PIXEL
== aGraphic
.GetPrefMapMode().GetMapUnit())
81 aPrefSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MAP_100TH_MM
);
85 aPrefSize
= Application::GetDefaultDevice()->LogicToLogic(aPrefSize
, aGraphic
.GetPrefMapMode(), MAP_100TH_MM
);
88 const double fOffsetX((aScale
.getX() - aPrefSize
.getWidth()) / 2.0);
89 const double fOffsetY((aScale
.getY() - aPrefSize
.getHeight()) / 2.0);
91 if(basegfx::fTools::moreOrEqual(fOffsetX
, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY
, 0.0))
93 // if content fits into frame, create it
94 basegfx::B2DHomMatrix
aInnerObjectMatrix(basegfx::tools::createScaleTranslateB2DHomMatrix(
95 aPrefSize
.getWidth(), aPrefSize
.getHeight(), fOffsetX
, fOffsetY
));
96 aInnerObjectMatrix
= basegfx::tools::createShearXRotateTranslateB2DHomMatrix(fShearX
, fRotate
, aTranslate
)
99 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
100 new drawinglayer::primitive2d::GraphicPrimitive2D(
104 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
109 // create graphic primitive for content
110 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
111 new drawinglayer::primitive2d::GraphicPrimitive2D(
112 getObjectTransform(),
115 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
118 // a standard gray outline is created for scaled content
121 const svtools::ColorConfig aColorConfig
;
122 const svtools::ColorConfigValue
aColor(aColorConfig
.GetColorValue(svtools::OBJECTBOUNDARIES
));
124 if(aColor
.bIsVisible
)
126 basegfx::B2DPolygon
aOutline(basegfx::tools::createUnitPolygon());
127 const Color
aVclColor(aColor
.nColor
);
128 aOutline
.transform(getObjectTransform());
129 const drawinglayer::primitive2d::Primitive2DReference
xOutline(
130 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline
, aVclColor
.getBColor()));
131 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, xOutline
);
136 // get graphic and check scale content state
140 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
141 const SdrOle2Obj
& rSdrOle2Obj
,
142 const basegfx::B2DHomMatrix
& rObjectTransform
,
143 sal_uInt32 nGraphicVersion
145 : BufferedDecompositionPrimitive2D(),
146 mpSdrOle2Obj(const_cast< SdrOle2Obj
* >(&rSdrOle2Obj
)),
147 maObjectTransform(rObjectTransform
),
148 mnGraphicVersion(nGraphicVersion
)
152 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
154 if( BufferedDecompositionPrimitive2D::operator==(rPrimitive
) )
156 const SdrOleContentPrimitive2D
& rCompare
= (SdrOleContentPrimitive2D
&)rPrimitive
;
157 const bool bBothNot(!mpSdrOle2Obj
.is() && !rCompare
.mpSdrOle2Obj
.is());
158 const bool bBothAndEqual(mpSdrOle2Obj
.is() && rCompare
.mpSdrOle2Obj
.is()
159 && mpSdrOle2Obj
.get() == rCompare
.mpSdrOle2Obj
.get());
161 return ((bBothNot
|| bBothAndEqual
)
162 && getObjectTransform() == rCompare
.getObjectTransform()
164 // #i104867# to find out if the Graphic content of the
165 // OLE has changed, use GraphicVersion number
166 && getGraphicVersion() == rCompare
.getGraphicVersion()
173 basegfx::B2DRange
SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
175 basegfx::B2DRange
aRange(0.0, 0.0, 1.0, 1.0);
176 aRange
.transform(getObjectTransform());
182 ImplPrimitive2DIDBlock(SdrOleContentPrimitive2D
, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
)
184 } // end of namespace primitive2d
185 } // end of namespace drawinglayer
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */