merge the formfield patch from ooo-build
[ooovba.git] / svx / source / sdr / primitive2d / sdrole2primitive2d.cxx
bloba7d647d2c5878c5aa522698151538c0d635a73ca
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: sdrole2primitive2d.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/sdrole2primitive2d.hxx>
34 #include <svx/sdr/primitive2d/svx_primitivetypes2d.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
37 #include <drawinglayer/primitive2d/hittestprimitive2d.hxx>
39 //////////////////////////////////////////////////////////////////////////////
41 using namespace com::sun::star;
43 //////////////////////////////////////////////////////////////////////////////
45 namespace drawinglayer
47 namespace primitive2d
49 Primitive2DSequence SdrOle2Primitive2D::createLocalDecomposition(const geometry::ViewInformation2D& /*aViewInformation*/) const
51 // to take care of getSdrLFSTAttribute() later, the same as in SdrGrafPrimitive2D::createLocalDecomposition
52 // should happen. For the moment we only need the OLE itself
53 // Added complete primitive preparation using getSdrLFSTAttribute() now. To not do stuff which is not needed now, it
54 // may be supressed by using a static bool. The paint version only supported text.
55 static bool bBehaveCompatibleToPaintVersion(true);
56 Primitive2DSequence aRetval;
58 // create unit outline polygon
59 basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0)));
61 // add fill
62 if(!bBehaveCompatibleToPaintVersion && getSdrLFSTAttribute().getFill())
64 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval,
65 createPolyPolygonFillPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getFill(), getSdrLFSTAttribute().getFillFloatTransGradient()));
68 // add line
69 // #i97981# condition was inverse to purpose. When being compatible to paint version,
70 // border needs to be suppressed
71 if(!bBehaveCompatibleToPaintVersion && getSdrLFSTAttribute().getLine())
73 // if line width is given, polygon needs to be grown by half of it to make the
74 // outline to be outside of the bitmap
75 if(0.0 != getSdrLFSTAttribute().getLine()->getWidth())
77 // decompose to get scale
78 basegfx::B2DVector aScale, aTranslate;
79 double fRotate, fShearX;
80 getTransform().decompose(aScale, aTranslate, fRotate, fShearX);
82 // create expanded range (add relative half line width to unit rectangle)
83 double fHalfLineWidth(getSdrLFSTAttribute().getLine()->getWidth() * 0.5);
84 double fScaleX(0.0 != aScale.getX() ? fHalfLineWidth / fabs(aScale.getX()) : 1.0);
85 double fScaleY(0.0 != aScale.getY() ? fHalfLineWidth / fabs(aScale.getY()) : 1.0);
86 const basegfx::B2DRange aExpandedRange(-fScaleX, -fScaleY, 1.0 + fScaleX, 1.0 + fScaleY);
87 basegfx::B2DPolygon aExpandedUnitOutline(basegfx::tools::createPolygonFromRect(aExpandedRange));
89 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aExpandedUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine()));
91 else
93 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createPolygonLinePrimitive(aUnitOutline, getTransform(), *getSdrLFSTAttribute().getLine()));
96 else
98 // if initially no line is defined, create one for HitTest and BoundRect
99 const attribute::SdrLineAttribute aBlackHairline(basegfx::BColor(0.0, 0.0, 0.0));
100 const Primitive2DReference xHiddenLineReference(createPolygonLinePrimitive(aUnitOutline, getTransform(), aBlackHairline));
101 const Primitive2DSequence xHiddenLineSequence(&xHiddenLineReference, 1);
103 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, Primitive2DReference(new HitTestPrimitive2D(xHiddenLineSequence)));
106 // add graphic content
107 appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, getChildren());
109 // add text, no need to supress to stay compatible since text was
110 // always supported by the old paints, too
111 if(getSdrLFSTAttribute().getText())
113 appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, createTextPrimitive(basegfx::B2DPolyPolygon(aUnitOutline), getTransform(), *getSdrLFSTAttribute().getText(), getSdrLFSTAttribute().getLine(), false, false));
116 // add shadow
117 if(!bBehaveCompatibleToPaintVersion && getSdrLFSTAttribute().getShadow())
119 aRetval = createEmbeddedShadowPrimitive(aRetval, *getSdrLFSTAttribute().getShadow());
122 return aRetval;
125 SdrOle2Primitive2D::SdrOle2Primitive2D(
126 const Primitive2DSequence& rChildren,
127 const ::basegfx::B2DHomMatrix& rTransform,
128 const attribute::SdrLineFillShadowTextAttribute& rSdrLFSTAttribute)
129 : GroupPrimitive2D(rChildren),
130 maTransform(rTransform),
131 maSdrLFSTAttribute(rSdrLFSTAttribute)
135 bool SdrOle2Primitive2D::operator==(const BasePrimitive2D& rPrimitive) const
137 if(GroupPrimitive2D::operator==(rPrimitive))
139 const SdrOle2Primitive2D& rCompare = (SdrOle2Primitive2D&)rPrimitive;
141 if(getTransform() == rCompare.getTransform()
142 && getSdrLFSTAttribute() == rCompare.getSdrLFSTAttribute())
144 return true;
148 return false;
151 // provide unique ID
152 ImplPrimitrive2DIDBlock(SdrOle2Primitive2D, PRIMITIVE2D_ID_SDROLE2PRIMITIVE2D)
154 } // end of namespace primitive2d
155 } // end of namespace drawinglayer
157 //////////////////////////////////////////////////////////////////////////////
158 // eof