1f6e50924SAndrew Rist /**************************************************************
2*672a9062Smseidel  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*672a9062Smseidel  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*672a9062Smseidel  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19*672a9062Smseidel  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22f6e50924SAndrew 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>
437074a11eSArmin Le Grand #include <basegfx/polygon/b2dpolygonclipper.hxx>
44cdf0e10cSrcweir 
45cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
46cdf0e10cSrcweir 
47cdf0e10cSrcweir namespace sdr
48cdf0e10cSrcweir {
49cdf0e10cSrcweir 	namespace contact
50cdf0e10cSrcweir 	{
ViewContactOfSdrCaptionObj(SdrCaptionObj & rCaptionObj)51cdf0e10cSrcweir 		ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
52cdf0e10cSrcweir 		:	ViewContactOfSdrRectObj(rCaptionObj)
53cdf0e10cSrcweir 		{
54cdf0e10cSrcweir 		}
55cdf0e10cSrcweir 
~ViewContactOfSdrCaptionObj()56cdf0e10cSrcweir 		ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
57cdf0e10cSrcweir 		{
58cdf0e10cSrcweir 		}
59cdf0e10cSrcweir 
createViewIndependentPrimitive2DSequence() const60cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
61cdf0e10cSrcweir 		{
62cdf0e10cSrcweir 			drawinglayer::primitive2d::Primitive2DSequence xRetval;
63cdf0e10cSrcweir 			const SdrCaptionObj& rCaptionObj(GetCaptionObj());
64cdf0e10cSrcweir 			const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
65cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
66cdf0e10cSrcweir 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
67*672a9062Smseidel 					rItemSet,
68*672a9062Smseidel 					rCaptionObj.getText(0),
69*672a9062Smseidel 					false));
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 			// take unrotated snap rect (direct model data) for position and size
72cdf0e10cSrcweir 			const Rectangle& rRectangle = rCaptionObj.GetGeoRect();
73cdf0e10cSrcweir 			const ::basegfx::B2DRange aObjectRange(
74*672a9062Smseidel 				rRectangle.Left(), rRectangle.Top(),
75cdf0e10cSrcweir 				rRectangle.Right(), rRectangle.Bottom());
76cdf0e10cSrcweir 			const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
77*672a9062Smseidel 
78cdf0e10cSrcweir 			// fill object matrix
79cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
80cdf0e10cSrcweir 				aObjectRange.getWidth(), aObjectRange.getHeight(),
81cdf0e10cSrcweir 				rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
82cdf0e10cSrcweir 				rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
83cdf0e10cSrcweir 				aObjectRange.getMinX(), aObjectRange.getMinY()));
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 			// calculate corner radius
86cdf0e10cSrcweir 			double fCornerRadiusX;
87cdf0e10cSrcweir 			double fCornerRadiusY;
88cdf0e10cSrcweir 			drawinglayer::primitive2d::calculateRelativeCornerRadius(
89cdf0e10cSrcweir 				rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 			// create primitive. Always create one (even if invisible) to let the decomposition
92cdf0e10cSrcweir 			// of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
93cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DReference xReference(
94cdf0e10cSrcweir 				new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
95*672a9062Smseidel 					aObjectMatrix,
96*672a9062Smseidel 					aAttribute,
97*672a9062Smseidel 					rCaptionObj.getTailPolygon(),
98*672a9062Smseidel 					fCornerRadiusX,
99cdf0e10cSrcweir 					fCornerRadiusY));
100cdf0e10cSrcweir 
101cdf0e10cSrcweir 			xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
102cdf0e10cSrcweir 
103cdf0e10cSrcweir 			if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
104cdf0e10cSrcweir 			{
105cdf0e10cSrcweir 				// for SC, the caption object may have a specialized shadow. The usual object shadow is off
106cdf0e10cSrcweir 				// and a specialized shadow gets created here (see old paint)
107cdf0e10cSrcweir 				const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
1087074a11eSArmin Le Grand 				const sal_uInt16 nShadowTransparence(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
1097074a11eSArmin Le Grand 				const Color aShadowColor(rShadColItem.GetColorValue());
1107074a11eSArmin Le Grand 				const XFillStyle eShadowStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
111cdf0e10cSrcweir 
112cdf0e10cSrcweir 				// Create own ItemSet and modify as needed
113cdf0e10cSrcweir 				// Always hide lines for special calc shadow
114cdf0e10cSrcweir 				SfxItemSet aSet(rItemSet);
115cdf0e10cSrcweir 				aSet.Put(XLineStyleItem(XLINE_NONE));
116cdf0e10cSrcweir 
1177074a11eSArmin Le Grand 				if(XFILL_HATCH == eShadowStyle)
118cdf0e10cSrcweir 				{
119cdf0e10cSrcweir 					// #41666# Hatch color is set hard to shadow color
120cdf0e10cSrcweir 					XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
1217074a11eSArmin Le Grand 					aHatch.SetColor(aShadowColor);
122cdf0e10cSrcweir 					aSet.Put(XFillHatchItem(String(),aHatch));
123cdf0e10cSrcweir 				}
124cdf0e10cSrcweir 				else
125cdf0e10cSrcweir 				{
1267074a11eSArmin Le Grand 					if(XFILL_SOLID != eShadowStyle)
127cdf0e10cSrcweir 					{
1287074a11eSArmin Le Grand 						// force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
129cdf0e10cSrcweir 						aSet.Put(XFillStyleItem(XFILL_SOLID));
130cdf0e10cSrcweir 					}
131cdf0e10cSrcweir 
1327074a11eSArmin Le Grand 					aSet.Put(XFillColorItem(String(),aShadowColor));
1337074a11eSArmin Le Grand 					aSet.Put(XFillTransparenceItem(nShadowTransparence));
134cdf0e10cSrcweir 				}
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 				// crete FillAttribute from modified ItemSet
137cdf0e10cSrcweir 				const drawinglayer::attribute::SdrFillAttribute aFill(
138cdf0e10cSrcweir 					drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
139cdf0e10cSrcweir 				drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir 				if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
142cdf0e10cSrcweir 				{
143cdf0e10cSrcweir 					// add shadow offset to object matrix
144cdf0e10cSrcweir 					const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
145cdf0e10cSrcweir 					const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
1467074a11eSArmin Le Grand 
147*672a9062Smseidel 					if(nXDist || nYDist)
148*672a9062Smseidel 					{
149*672a9062Smseidel 						// #119750# create object and shadow outline, clip shadow outline
150*672a9062Smseidel 						// on object outline. If there is a rest, create shadow. Do this to
151*672a9062Smseidel 						// emulate that shadow is *not* visible behind the object for
152*672a9062Smseidel 						// transparent object fill for comments in excel
153*672a9062Smseidel 						basegfx::B2DPolygon aObjectOutline(
154*672a9062Smseidel 							basegfx::tools::createPolygonFromRect(
155*672a9062Smseidel 								basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
156*672a9062Smseidel 								fCornerRadiusX,
157*672a9062Smseidel 								fCornerRadiusY));
158*672a9062Smseidel 						aObjectOutline.transform(aObjectMatrix);
159*672a9062Smseidel 
160*672a9062Smseidel 						// create shadow outline
161*672a9062Smseidel 						basegfx::B2DPolygon aShadowOutline(aObjectOutline);
162*672a9062Smseidel 						aShadowOutline.transform(
163*672a9062Smseidel 							basegfx::tools::createTranslateB2DHomMatrix(nXDist, nYDist));
164*672a9062Smseidel 
165*672a9062Smseidel 						// clip shadow outline against object outline
166*672a9062Smseidel 						const basegfx::B2DPolyPolygon aClippedShadow(
167*672a9062Smseidel 							basegfx::tools::clipPolygonOnPolyPolygon(
168*672a9062Smseidel 								aShadowOutline,
169*672a9062Smseidel 								basegfx::B2DPolyPolygon(aObjectOutline),
170*672a9062Smseidel 								false, // take the outside
171*672a9062Smseidel 								false));
172*672a9062Smseidel 
173*672a9062Smseidel 						if(aClippedShadow.count())
174*672a9062Smseidel 						{
175*672a9062Smseidel 							// if there is shadow, create the specialized shadow primitive
176*672a9062Smseidel 							xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
177*672a9062Smseidel 								aClippedShadow,
178*672a9062Smseidel 								aFill,
179*672a9062Smseidel 								drawinglayer::attribute::FillGradientAttribute());
180*672a9062Smseidel 						}
181*672a9062Smseidel 					}
182cdf0e10cSrcweir 				}
183cdf0e10cSrcweir 
184cdf0e10cSrcweir 				if(xSpecialShadow.is())
185cdf0e10cSrcweir 				{
186cdf0e10cSrcweir 					// if we really got a special shadow, create a two-element retval with the shadow
187cdf0e10cSrcweir 					// behind the standard object's geometry
188cdf0e10cSrcweir 					xRetval.realloc(2);
189*672a9062Smseidel 
190cdf0e10cSrcweir 					xRetval[0] = xSpecialShadow;
191cdf0e10cSrcweir 					xRetval[1] = xReference;
192cdf0e10cSrcweir 				}
193cdf0e10cSrcweir 			}
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 			return xRetval;
196cdf0e10cSrcweir 		}
197cdf0e10cSrcweir 	} // end of namespace contact
198cdf0e10cSrcweir } // end of namespace sdr
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
201cdf0e10cSrcweir // eof
202