1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx>
28cdf0e10cSrcweir #include <svx/svdocapt.hxx>
29cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
30cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx>
31cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
34cdf0e10cSrcweir // includes for special text box shadow (SC)
35cdf0e10cSrcweir 
36cdf0e10cSrcweir #include <svl/itemset.hxx>
37cdf0e10cSrcweir #include <svx/xhatch.hxx>
38cdf0e10cSrcweir #include <svx/xflhtit.hxx>
39cdf0e10cSrcweir #include <svx/xflclit.hxx>
40cdf0e10cSrcweir #include <svx/xfltrit.hxx>
41cdf0e10cSrcweir #include <basegfx/polygon/b2dpolygontools.hxx>
42cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
45cdf0e10cSrcweir 
46cdf0e10cSrcweir namespace sdr
47cdf0e10cSrcweir {
48cdf0e10cSrcweir 	namespace contact
49cdf0e10cSrcweir 	{
50cdf0e10cSrcweir 		ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
51cdf0e10cSrcweir 		:	ViewContactOfSdrRectObj(rCaptionObj)
52cdf0e10cSrcweir 		{
53cdf0e10cSrcweir 		}
54cdf0e10cSrcweir 
55cdf0e10cSrcweir 		ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
56cdf0e10cSrcweir 		{
57cdf0e10cSrcweir 		}
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
60cdf0e10cSrcweir 		{
61cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
62cdf0e10cSrcweir 			const SdrCaptionObj& rCaptionObj(GetCaptionObj());
63cdf0e10cSrcweir 			const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
64cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
65cdf0e10cSrcweir 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
66cdf0e10cSrcweir                     rItemSet,
67cdf0e10cSrcweir                     rCaptionObj.getText(0)));
68cdf0e10cSrcweir 
69cdf0e10cSrcweir 			// take unrotated snap rect (direct model data) for position and size
70cdf0e10cSrcweir 			const Rectangle& rRectangle = rCaptionObj.GetGeoRect();
71cdf0e10cSrcweir 			const ::basegfx::B2DRange aObjectRange(
72cdf0e10cSrcweir 				rRectangle.Left(), rRectangle.Top(),
73cdf0e10cSrcweir 				rRectangle.Right(), rRectangle.Bottom());
74cdf0e10cSrcweir 			const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			// fill object matrix
77cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
78cdf0e10cSrcweir 				aObjectRange.getWidth(), aObjectRange.getHeight(),
79cdf0e10cSrcweir 				rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
80cdf0e10cSrcweir 				rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
81cdf0e10cSrcweir 				aObjectRange.getMinX(), aObjectRange.getMinY()));
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 			// calculate corner radius
84cdf0e10cSrcweir 			double fCornerRadiusX;
85cdf0e10cSrcweir 			double fCornerRadiusY;
86cdf0e10cSrcweir 			drawinglayer::primitive2d::calculateRelativeCornerRadius(
87cdf0e10cSrcweir 				rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
88cdf0e10cSrcweir 
89cdf0e10cSrcweir 			// create primitive. Always create one (even if invisible) to let the decomposition
90cdf0e10cSrcweir 			// of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
91cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DReference xReference(
92cdf0e10cSrcweir 				new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
93cdf0e10cSrcweir 					aObjectMatrix,
94cdf0e10cSrcweir 					aAttribute,
95cdf0e10cSrcweir 					rCaptionObj.getTailPolygon(),
96cdf0e10cSrcweir 					fCornerRadiusX,
97cdf0e10cSrcweir 					fCornerRadiusY));
98cdf0e10cSrcweir 
99cdf0e10cSrcweir 			xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 			if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
102cdf0e10cSrcweir 			{
103cdf0e10cSrcweir 				// for SC, the caption object may have a specialized shadow. The usual object shadow is off
104cdf0e10cSrcweir 				// and a specialized shadow gets created here (see old paint)
105cdf0e10cSrcweir 				const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
106cdf0e10cSrcweir 				const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
107cdf0e10cSrcweir 				const Color aShadCol(rShadColItem.GetColorValue());
108cdf0e10cSrcweir 				const XFillStyle eStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
109cdf0e10cSrcweir 
110cdf0e10cSrcweir 				// Create own ItemSet and modify as needed
111cdf0e10cSrcweir 				// Always hide lines for special calc shadow
112cdf0e10cSrcweir 				SfxItemSet aSet(rItemSet);
113cdf0e10cSrcweir 				aSet.Put(XLineStyleItem(XLINE_NONE));
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 				if(XFILL_HATCH == eStyle)
116cdf0e10cSrcweir 				{
117cdf0e10cSrcweir 					// #41666# Hatch color is set hard to shadow color
118cdf0e10cSrcweir 					XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
119cdf0e10cSrcweir 					aHatch.SetColor(aShadCol);
120cdf0e10cSrcweir 					aSet.Put(XFillHatchItem(String(),aHatch));
121cdf0e10cSrcweir 				}
122cdf0e10cSrcweir 				else
123cdf0e10cSrcweir 				{
124cdf0e10cSrcweir 					if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle)
125cdf0e10cSrcweir 					{
126cdf0e10cSrcweir 						// force fill to solid (for Gradient and Bitmap)
127cdf0e10cSrcweir 						aSet.Put(XFillStyleItem(XFILL_SOLID));
128cdf0e10cSrcweir 					}
129cdf0e10cSrcweir 
130cdf0e10cSrcweir 					aSet.Put(XFillColorItem(String(),aShadCol));
131cdf0e10cSrcweir 					aSet.Put(XFillTransparenceItem(nTransp));
132cdf0e10cSrcweir 				}
133cdf0e10cSrcweir 
134cdf0e10cSrcweir 				// crete FillAttribute from modified ItemSet
135cdf0e10cSrcweir 				const drawinglayer::attribute::SdrFillAttribute aFill(
136cdf0e10cSrcweir 					drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
137cdf0e10cSrcweir 				drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 				if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
140cdf0e10cSrcweir 				{
141cdf0e10cSrcweir 					// add shadow offset to object matrix
142cdf0e10cSrcweir 					const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
143cdf0e10cSrcweir 					const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
144cdf0e10cSrcweir 					aObjectMatrix.translate(nXDist, nYDist);
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 					// create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition)
147cdf0e10cSrcweir 					basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
148cdf0e10cSrcweir 						basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY));
149cdf0e10cSrcweir 
150cdf0e10cSrcweir 					// create the specialized shadow primitive
151cdf0e10cSrcweir 					xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
152cdf0e10cSrcweir 						basegfx::B2DPolyPolygon(aUnitOutline),
153cdf0e10cSrcweir 						aObjectMatrix,
154cdf0e10cSrcweir 						aFill,
155cdf0e10cSrcweir 						drawinglayer::attribute::FillGradientAttribute());
156cdf0e10cSrcweir 				}
157cdf0e10cSrcweir 
158cdf0e10cSrcweir 				if(xSpecialShadow.is())
159cdf0e10cSrcweir 				{
160cdf0e10cSrcweir 					// if we really got a special shadow, create a two-element retval with the shadow
161cdf0e10cSrcweir 					// behind the standard object's geometry
162cdf0e10cSrcweir 					xRetval.realloc(2);
163cdf0e10cSrcweir 
164cdf0e10cSrcweir 					xRetval[0] = xSpecialShadow;
165cdf0e10cSrcweir 					xRetval[1] = xReference;
166cdf0e10cSrcweir 				}
167cdf0e10cSrcweir 			}
168cdf0e10cSrcweir 
169cdf0e10cSrcweir 			return xRetval;
170cdf0e10cSrcweir 		}
171cdf0e10cSrcweir 	} // end of namespace contact
172cdf0e10cSrcweir } // end of namespace sdr
173cdf0e10cSrcweir 
174cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
175cdf0e10cSrcweir // eof
176