1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrcaptionprimitive2d.cxx,v $
11 * $Revision: 1.2.18.1 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/primitive2d/sdrolecontentprimitive2d.hxx>
34 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
35 #include <svx/svdoole2.hxx>
36 #include <vcl/svapp.hxx>
37 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
38 #include <svtools/colorcfg.hxx>
39 #include <basegfx/polygon/b2dpolygontools.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
43 //////////////////////////////////////////////////////////////////////////////
45 namespace drawinglayer
49 Primitive2DSequence
SdrOleContentPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D
& /*aViewInformation*/) const
51 Primitive2DSequence aRetval
;
52 const SdrOle2Obj
* pSource
= (mpSdrOle2Obj
.is() ? static_cast< SdrOle2Obj
* >(mpSdrOle2Obj
.get()) : 0);
53 bool bScaleContent(false);
58 Graphic
* pOLEGraphic
= (getHighContrast())
59 ? pSource
->getEmbeddedObjectRef().GetHCGraphic()
60 : pSource
->GetGraphic();
64 aGraphic
= *pOLEGraphic
;
65 bScaleContent
= pSource
->IsEmptyPresObj();
69 if(GRAPHIC_NONE
== aGraphic
.GetType())
71 // no source, use fallback ressource emty OLE graphic
72 const Bitmap
aEmptyOLEBitmap(SdrOle2Obj::GetEmtyOLEReplacementBitmap());
73 aGraphic
= Graphic(aEmptyOLEBitmap
);
77 if(GRAPHIC_NONE
!= aGraphic
.GetType())
79 const GraphicObject
aGraphicObject(aGraphic
);
80 const GraphicAttr aGraphicAttr
;
81 drawinglayer::primitive2d::Primitive2DSequence xOLEContent
;
85 // get transformation atoms
86 basegfx::B2DVector aScale
, aTranslate
;
87 double fRotate
, fShearX
;
88 getObjectTransform().decompose(aScale
, aTranslate
, fRotate
, fShearX
);
90 // get PrefSize from the graphic in 100th mm
91 Size
aPrefSize(aGraphic
.GetPrefSize());
93 if(MAP_PIXEL
== aGraphic
.GetPrefMapMode().GetMapUnit())
95 aPrefSize
= Application::GetDefaultDevice()->PixelToLogic(aPrefSize
, MAP_100TH_MM
);
99 aPrefSize
= Application::GetDefaultDevice()->LogicToLogic(aPrefSize
, aGraphic
.GetPrefMapMode(), MAP_100TH_MM
);
102 const double fOffsetX((aScale
.getX() - aPrefSize
.getWidth()) / 2.0);
103 const double fOffsetY((aScale
.getY() - aPrefSize
.getHeight()) / 2.0);
105 if(basegfx::fTools::moreOrEqual(fOffsetX
, 0.0) && basegfx::fTools::moreOrEqual(fOffsetY
, 0.0))
107 // if content fits into frame, create it
108 basegfx::B2DHomMatrix aInnerObjectMatrix
;
110 aInnerObjectMatrix
.scale(aPrefSize
.getWidth(), aPrefSize
.getHeight());
111 aInnerObjectMatrix
.translate(fOffsetX
, fOffsetY
);
112 aInnerObjectMatrix
.shearX(fShearX
);
113 aInnerObjectMatrix
.rotate(fRotate
);
114 aInnerObjectMatrix
.translate(aTranslate
.getX(), aTranslate
.getY());
116 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
117 new drawinglayer::primitive2d::GraphicPrimitive2D(
121 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
126 // create graphic primitive for content
127 const drawinglayer::primitive2d::Primitive2DReference
aGraphicPrimitive(
128 new drawinglayer::primitive2d::GraphicPrimitive2D(
129 getObjectTransform(),
132 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, aGraphicPrimitive
);
135 // a standard gray outline is created for scaled content
138 const svtools::ColorConfig aColorConfig
;
139 const svtools::ColorConfigValue
aColor(aColorConfig
.GetColorValue(svtools::OBJECTBOUNDARIES
));
141 if(aColor
.bIsVisible
)
143 basegfx::B2DPolygon
aOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
144 const Color
aVclColor(aColor
.nColor
);
145 aOutline
.transform(getObjectTransform());
146 const drawinglayer::primitive2d::Primitive2DReference
xOutline(
147 new drawinglayer::primitive2d::PolygonHairlinePrimitive2D(aOutline
, aVclColor
.getBColor()));
148 drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval
, xOutline
);
153 // get graphic and check scale content state
157 SdrOleContentPrimitive2D::SdrOleContentPrimitive2D(
158 const SdrOle2Obj
& rSdrOle2Obj
,
159 const basegfx::B2DHomMatrix
& rObjectTransform
,
162 mpSdrOle2Obj(const_cast< SdrOle2Obj
* >(&rSdrOle2Obj
)),
163 maObjectTransform(rObjectTransform
),
164 mbHighContrast(bHighContrast
)
168 bool SdrOleContentPrimitive2D::operator==(const BasePrimitive2D
& rPrimitive
) const
170 if(BasePrimitive2D::operator==(rPrimitive
))
172 const SdrOleContentPrimitive2D
& rCompare
= (SdrOleContentPrimitive2D
&)rPrimitive
;
173 const bool bBothNot(!mpSdrOle2Obj
.is() && !rCompare
.mpSdrOle2Obj
.is());
174 const bool bBothAndEqual(mpSdrOle2Obj
.is() && rCompare
.mpSdrOle2Obj
.is()
175 && mpSdrOle2Obj
.get() == rCompare
.mpSdrOle2Obj
.get());
177 return ((bBothNot
|| bBothAndEqual
)
178 && getObjectTransform() == rCompare
.getObjectTransform()
179 && getHighContrast() == rCompare
.getHighContrast());
185 basegfx::B2DRange
SdrOleContentPrimitive2D::getB2DRange(const geometry::ViewInformation2D
& /*rViewInformation*/) const
187 basegfx::B2DRange
aRange(0.0, 0.0, 1.0, 1.0);
188 aRange
.transform(getObjectTransform());
194 ImplPrimitrive2DIDBlock(SdrOleContentPrimitive2D
, PRIMITIVE2D_ID_SDROLECONTENTPRIMITIVE2D
)
196 } // end of namespace primitive2d
197 } // end of namespace drawinglayer
199 //////////////////////////////////////////////////////////////////////////////