merge the formfield patch from ooo-build
[ooovba.git] / drawinglayer / source / primitive2d / mediaprimitive2d.cxx
blob198bc04c640dae77381580e5abaca0ef6329d587
1 /*************************************************************************
3 * OpenOffice.org - a multi-platform office productivity suite
5 * $RCSfile: mediaprimitive2d.cxx,v $
7 * $Revision: 1.4 $
9 * last change: $Author: aw $ $Date: 2008-06-24 15:31:08 $
11 * The Contents of this file are made available subject to
12 * the terms of GNU Lesser General Public License Version 2.1.
15 * GNU Lesser General Public License Version 2.1
16 * =============================================
17 * Copyright 2005 by Sun Microsystems, Inc.
18 * 901 San Antonio Road, Palo Alto, CA 94303, USA
20 * This library is free software; you can redistribute it and/or
21 * modify it under the terms of the GNU Lesser General Public
22 * License version 2.1, as published by the Free Software Foundation.
24 * This library is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
27 * Lesser General Public License for more details.
29 * You should have received a copy of the GNU Lesser General Public
30 * License along with this library; if not, write to the Free Software
31 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
32 * MA 02111-1307 USA
34 ************************************************************************/
36 // MARKER(update_precomp.py): autogen include statement, do not remove
37 #include "precompiled_drawinglayer.hxx"
39 #include <drawinglayer/primitive2d/mediaprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygon.hxx>
41 #include <basegfx/polygon/b2dpolygontools.hxx>
42 #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
43 #include <avmedia/mediawindow.hxx>
44 #include <goodies/grfmgr.hxx>
45 #include <drawinglayer/primitive2d/graphicprimitive2d.hxx>
46 #include <drawinglayer/geometry/viewinformation2d.hxx>
47 #include <drawinglayer/primitive2d/transformprimitive2d.hxx>
48 #include <drawinglayer/primitive2d/drawinglayer_primitivetypes2d.hxx>
50 //////////////////////////////////////////////////////////////////////////////
52 namespace drawinglayer
54 namespace primitive2d
56 Primitive2DSequence MediaPrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& rViewInformation) const
58 Primitive2DSequence xRetval(1);
60 // create background object
61 basegfx::B2DPolygon aBackgroundPolygon(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
62 aBackgroundPolygon.transform(getTransform());
63 const Primitive2DReference xRefBackground(new PolyPolygonColorPrimitive2D(basegfx::B2DPolyPolygon(aBackgroundPolygon), getBackgroundColor()));
64 xRetval[0] = xRefBackground;
66 // try to get graphic snapshot
67 const Graphic aGraphic(avmedia::MediaWindow::grabFrame(getURL(), true));
69 if(GRAPHIC_BITMAP == aGraphic.GetType() || GRAPHIC_GDIMETAFILE == aGraphic.GetType())
71 const GraphicObject aGraphicObject(aGraphic);
72 const GraphicAttr aGraphicAttr;
73 xRetval.realloc(2);
74 xRetval[0] = xRefBackground;
75 xRetval[1] = Primitive2DReference(new GraphicPrimitive2D(getTransform(), aGraphicObject, aGraphicAttr));
78 if(getDiscreteBorder())
80 const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
81 basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
82 const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
84 basegfx::B2DRange aSourceRange(0.0, 0.0, 1.0, 1.0);
85 aSourceRange.transform(getTransform());
87 basegfx::B2DRange aDestRange(aSourceRange);
88 aDestRange.grow(-0.5 * fDiscreteSize);
90 if(::basegfx::fTools::equalZero(aDestRange.getWidth()) || ::basegfx::fTools::equalZero(aDestRange.getHeight()))
92 // shrunk primitive has no content (zero size in X or Y), nothing to display, nothing to return
93 xRetval = Primitive2DSequence();
95 else
97 // create transformation matrix from original range to shrunk range
98 basegfx::B2DHomMatrix aTransform;
99 aTransform.translate(-aSourceRange.getMinX(), -aSourceRange.getMinY());
100 aTransform.scale(aDestRange.getWidth() / aSourceRange.getWidth(), aDestRange.getHeight() / aSourceRange.getHeight());
101 aTransform.translate(aDestRange.getMinX(), aDestRange.getMinY());
103 // add transform primitive
104 const Primitive2DReference aScaled(new TransformPrimitive2D(aTransform, xRetval));
105 xRetval = Primitive2DSequence(&aScaled, 1L);
109 return xRetval;
112 MediaPrimitive2D::MediaPrimitive2D(
113 const basegfx::B2DHomMatrix& rTransform,
114 const rtl::OUString& rURL,
115 const basegfx::BColor& rBackgroundColor,
116 sal_uInt32 nDiscreteBorder)
117 : BasePrimitive2D(),
118 maTransform(rTransform),
119 maURL(rURL),
120 maBackgroundColor(rBackgroundColor),
121 mnDiscreteBorder(nDiscreteBorder)
125 bool MediaPrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
127 if(BasePrimitive2D::operator==(rPrimitive))
129 const MediaPrimitive2D& rCompare = (MediaPrimitive2D&)rPrimitive;
131 return (getTransform() == rCompare.getTransform()
132 && getURL() == rCompare.getURL()
133 && getBackgroundColor() == rCompare.getBackgroundColor()
134 && getDiscreteBorder() == rCompare.getDiscreteBorder());
137 return false;
140 basegfx::B2DRange MediaPrimitive2D::getB2DRange(const geometry::ViewInformation2D& rViewInformation) const
142 basegfx::B2DRange aRetval(0.0, 0.0, 1.0, 1.0);
143 aRetval.transform(getTransform());
145 if(getDiscreteBorder())
147 const basegfx::B2DVector aDiscreteInLogic(rViewInformation.getInverseObjectToViewTransformation() *
148 basegfx::B2DVector((double)getDiscreteBorder(), (double)getDiscreteBorder()));
149 const double fDiscreteSize(aDiscreteInLogic.getX() + aDiscreteInLogic.getY());
151 aRetval.grow(-0.5 * fDiscreteSize);
154 return aRetval;
157 // provide unique ID
158 ImplPrimitrive2DIDBlock(MediaPrimitive2D, PRIMITIVE2D_ID_MEDIAPRIMITIVE2D)
160 } // end of namespace primitive2d
161 } // end of namespace drawinglayer
163 //////////////////////////////////////////////////////////////////////////////
164 // eof