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: viewcontactofsdrcaptionobj.cxx,v $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx>
36 #include <svx/svdocapt.hxx>
37 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
38 #include <svx/sdr/attribute/sdrallattribute.hxx>
39 #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx>
41 //////////////////////////////////////////////////////////////////////////////
42 // includes for special text box shadow (SC)
44 #include <svtools/itemset.hxx>
45 #include <svx/xhatch.hxx>
46 #include <svx/xflhtit.hxx>
47 #include <svx/xflclit.hxx>
48 #include <svx/xfltrit.hxx>
49 #include <basegfx/polygon/b2dpolygontools.hxx>
50 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
52 //////////////////////////////////////////////////////////////////////////////
58 ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj
& rCaptionObj
)
59 : ViewContactOfSdrRectObj(rCaptionObj
)
63 ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
67 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
69 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
70 const SdrCaptionObj
& rCaptionObj(GetCaptionObj());
71 const SfxItemSet
& rItemSet
= rCaptionObj
.GetMergedItemSet();
72 SdrText
* pSdrText
= rCaptionObj
.getText(0);
76 drawinglayer::attribute::SdrLineFillShadowTextAttribute
* pAttribute
= drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(rItemSet
, *pSdrText
);
80 if(pAttribute
->isVisible())
82 // take unrotated snap rect (direct model data) for position and size
83 const Rectangle
& rRectangle
= rCaptionObj
.GetGeoRect();
84 const ::basegfx::B2DRange
aObjectRange(rRectangle
.Left(), rRectangle
.Top(), rRectangle
.Right(), rRectangle
.Bottom());
85 const GeoStat
& rGeoStat(rCaptionObj
.GetGeoStat());
86 ::basegfx::B2DHomMatrix aObjectMatrix
;
89 if(!::basegfx::fTools::equalZero(aObjectRange
.getWidth()))
91 aObjectMatrix
.set(0, 0, aObjectRange
.getWidth());
94 if(!::basegfx::fTools::equalZero(aObjectRange
.getHeight()))
96 aObjectMatrix
.set(1, 1, aObjectRange
.getHeight());
99 if(rGeoStat
.nShearWink
)
101 aObjectMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
104 if(rGeoStat
.nDrehWink
)
106 aObjectMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
109 aObjectMatrix
.translate(aObjectRange
.getMinX(), aObjectRange
.getMinY());
111 // calculate corner radius
112 double fCornerRadiusX
;
113 double fCornerRadiusY
;
114 drawinglayer::primitive2d::calculateRelativeCornerRadius(rCaptionObj
.GetEckenradius(), aObjectRange
, fCornerRadiusX
, fCornerRadiusY
);
117 const drawinglayer::primitive2d::Primitive2DReference
xReference(new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
118 aObjectMatrix
, *pAttribute
, rCaptionObj
.getTailPolygon(), fCornerRadiusX
, fCornerRadiusY
));
119 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
121 if(rCaptionObj
.GetSpecialTextBoxShadow())
123 // for SC, the caption object may have a specialized shadow. The usual object shadow is off
124 // and a specialized shadow gets created here (see old paint)
125 const SdrShadowColorItem
& rShadColItem
= (SdrShadowColorItem
&)(rItemSet
.Get(SDRATTR_SHADOWCOLOR
));
126 const sal_uInt16
nTransp(((SdrShadowTransparenceItem
&)(rItemSet
.Get(SDRATTR_SHADOWTRANSPARENCE
))).GetValue());
127 const Color
aShadCol(rShadColItem
.GetColorValue());
128 const XFillStyle eStyle
= ((XFillStyleItem
&)(rItemSet
.Get(XATTR_FILLSTYLE
))).GetValue();
130 // Create own ItemSet and modify as needed
131 // Always hide lines for special calc shadow
132 SfxItemSet
aSet(rItemSet
);
133 aSet
.Put(XLineStyleItem(XLINE_NONE
));
135 if(XFILL_HATCH
== eStyle
)
137 // #41666# Hatch color is set hard to shadow color
138 XHatch aHatch
= ((XFillHatchItem
&)(rItemSet
.Get(XATTR_FILLHATCH
))).GetHatchValue();
139 aHatch
.SetColor(aShadCol
);
140 aSet
.Put(XFillHatchItem(String(),aHatch
));
144 if(XFILL_NONE
!= eStyle
&& XFILL_SOLID
!= eStyle
)
146 // force fill to solid (for Gradient and Bitmap)
147 aSet
.Put(XFillStyleItem(XFILL_SOLID
));
150 aSet
.Put(XFillColorItem(String(),aShadCol
));
151 aSet
.Put(XFillTransparenceItem(nTransp
));
154 // crete FillAttribute from modified ItemSet
155 drawinglayer::attribute::SdrFillAttribute
* pFill
= drawinglayer::primitive2d::createNewSdrFillAttribute(aSet
);
156 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow
;
160 if(pFill
->isVisible())
162 // add shadow offset to object matrix
163 const sal_uInt32
nXDist(((SdrShadowXDistItem
&)(rItemSet
.Get(SDRATTR_SHADOWXDIST
))).GetValue());
164 const sal_uInt32
nYDist(((SdrShadowYDistItem
&)(rItemSet
.Get(SDRATTR_SHADOWYDIST
))).GetValue());
165 aObjectMatrix
.translate(nXDist
, nYDist
);
167 // create unit outline polygon as geometry (see SdrCaptionPrimitive2D::createLocalDecomposition)
168 basegfx::B2DPolygon
aUnitOutline(basegfx::tools::createPolygonFromRect(basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX
, fCornerRadiusY
));
170 // create the specialized shadow primitive
171 xSpecialShadow
= drawinglayer::primitive2d::createPolyPolygonFillPrimitive(basegfx::B2DPolyPolygon(aUnitOutline
), aObjectMatrix
, *pFill
);
177 if(xSpecialShadow
.is())
179 // if we really got a special shadow, create a two-element retval with the shadow
180 // behind the standard object's geometry
183 xRetval
[0] = xSpecialShadow
;
184 xRetval
[1] = xReference
;
195 } // end of namespace contact
196 } // end of namespace sdr
198 //////////////////////////////////////////////////////////////////////////////