merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / primitive2d / sdrrectangleprimitive2d.cxx
blobe4b9d3f4ecb665933002243dbf2b083beae5fa41
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sdrrectangleprimitive2d.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/sdrrectangleprimitive2d.hxx>
34 #include <basegfx/polygon/b2dpolygontools.hxx>
35 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
36 #include <drawinglayer/primitive2d/groupprimitive2d.hxx>
37 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
38 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
40 //////////////////////////////////////////////////////////////////////////////
42 using namespace com::sun::star;
44 //////////////////////////////////////////////////////////////////////////////
46 namespace drawinglayer
48 namespace primitive2d
50 Primitive2DSequence SdrRectanglePrimitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
52 Primitive2DSequence aRetval;
53 Primitive2DSequence aHitTestContent;
55 // create unit outline polygon
56 const basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
57 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
58 getCornerRadiusX(),
59 getCornerRadiusY()));
61 // add fill
62 if(getSdrLFSTAttribute().getFill())
64 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
65 createPolyPolygonFillPrimitive(
66 basegfx::B2DPolyPolygon(aUnitOutline),
67 getTransform(),
68 *getSdrLFSTAttribute().getFill(),
69 getSdrLFSTAttribute().getFillFloatTransGradient()));
71 else if(getTextFrame())
73 // if no fill and it's a text frame, create a fill for HitTest and
74 // BoundRect fallback
75 appendPrimitive2DReferenceToPrimitive2DSequence(aHitTestContent,
76 createPolyPolygonFillPrimitive(
77 basegfx::B2DPolyPolygon(aUnitOutline),
78 getTransform(),
79 attribute::SdrFillAttribute(0.0, basegfx::BColor(0.0, 0.0, 0.0)),
80 getSdrLFSTAttribute().getFillFloatTransGradient()));
83 // add line
84 if(getSdrLFSTAttribute().getLine())
86 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
87 createPolygonLinePrimitive(
88 aUnitOutline,
89 getTransform(),
90 *getSdrLFSTAttribute().getLine()));
92 else if(!getTextFrame())
94 // if initially no line is defined and it's not a text frame, create
95 // a line for HitTest and BoundRect
96 appendPrimitive2DReferenceToPrimitive2DSequence(aHitTestContent,
97 createPolygonLinePrimitive(
98 aUnitOutline,
99 getTransform(),
100 attribute::SdrLineAttribute(basegfx::BColor(0.0, 0.0, 0.0))));
103 // add HitTest and BoundRect helper geometry (if exists)
104 if(aHitTestContent.hasElements())
106 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
107 Primitive2DReference(new HitTestPrimitive2D(aHitTestContent)));
110 // add text
111 if(getSdrLFSTAttribute().getText())
113 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createTextPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
116 // add shadow
117 if(getSdrLFSTAttribute().getShadow())
119 aRetval = createEmbeddedShadowPrimitive(aRetval, *getSdrLFSTAttribute().getShadow());
122 return aRetval;
125 SdrRectanglePrimitive2D::SdrRectanglePrimitive2D(
126 const basegfx::B2DHomMatrix& rTransform,
127 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute,
128 double fCornerRadiusX,
129 double fCornerRadiusY,
130 bool bTextFrame)
131 : BasePrimitive2D(),
132 maTransform(rTransform),
133 maSdrLFSTAttribute(rSdrLFSTAttribute),
134 mfCornerRadiusX(fCornerRadiusX),
135 mfCornerRadiusY(fCornerRadiusY),
136 mbTextFrame(bTextFrame)
140 bool SdrRectanglePrimitive2D::operator==(const BasePrimitive2D& rPrimitive) const
142 if(BasePrimitive2D::operator==(rPrimitive))
144 const SdrRectanglePrimitive2D& rCompare = (SdrRectanglePrimitive2D&)rPrimitive;
146 return (getCornerRadiusX() == rCompare.getCornerRadiusX()
147 && getCornerRadiusY() == rCompare.getCornerRadiusY()
148 && getTransform() == rCompare.getTransform()
149 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute()
150 && getTextFrame() == rCompare.getTextFrame());
153 return false;
156 // provide unique ID
157 ImplPrimitrive2DIDBlock(SdrRectanglePrimitive2D, PRIMITIVE2D_ID_SDRRECTANGLEPRIMITIVE2D)
159 } // end of namespace primitive2d
160 } // end of namespace drawinglayer
162 //////////////////////////////////////////////////////////////////////////////
163 // eof