xref: /AOO41X/main/svx/source/sdr/contact/viewcontactofsdrcaptionobj.cxx (revision 4bf7a51aae81eefaa1c594b1f2d068b2a05bd3a8)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
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
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
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.
19cdf0e10cSrcweir  *
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>
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,
67*4bf7a51aSArmin Le Grand                     rCaptionObj.getText(0),
68*4bf7a51aSArmin Le Grand                     false));
69cdf0e10cSrcweir 
70cdf0e10cSrcweir 			// take unrotated snap rect (direct model data) for position and size
71cdf0e10cSrcweir 			const Rectangle& rRectangle = rCaptionObj.GetGeoRect();
72cdf0e10cSrcweir 			const ::basegfx::B2DRange aObjectRange(
73cdf0e10cSrcweir 				rRectangle.Left(), rRectangle.Top(),
74cdf0e10cSrcweir 				rRectangle.Right(), rRectangle.Bottom());
75cdf0e10cSrcweir 			const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
76cdf0e10cSrcweir 
77cdf0e10cSrcweir 			// fill object matrix
78cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
79cdf0e10cSrcweir 				aObjectRange.getWidth(), aObjectRange.getHeight(),
80cdf0e10cSrcweir 				rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
81cdf0e10cSrcweir 				rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
82cdf0e10cSrcweir 				aObjectRange.getMinX(), aObjectRange.getMinY()));
83cdf0e10cSrcweir 
84cdf0e10cSrcweir 			// calculate corner radius
85cdf0e10cSrcweir 			double fCornerRadiusX;
86cdf0e10cSrcweir 			double fCornerRadiusY;
87cdf0e10cSrcweir 			drawinglayer::primitive2d::calculateRelativeCornerRadius(
88cdf0e10cSrcweir 				rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
89cdf0e10cSrcweir 
90cdf0e10cSrcweir 			// create primitive. Always create one (even if invisible) to let the decomposition
91cdf0e10cSrcweir 			// of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
92cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DReference xReference(
93cdf0e10cSrcweir 				new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
94cdf0e10cSrcweir 					aObjectMatrix,
95cdf0e10cSrcweir 					aAttribute,
96cdf0e10cSrcweir 					rCaptionObj.getTailPolygon(),
97cdf0e10cSrcweir 					fCornerRadiusX,
98cdf0e10cSrcweir 					fCornerRadiusY));
99cdf0e10cSrcweir 
100cdf0e10cSrcweir 			xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 			if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
103cdf0e10cSrcweir 			{
104cdf0e10cSrcweir 				// for SC, the caption object may have a specialized shadow. The usual object shadow is off
105cdf0e10cSrcweir 				// and a specialized shadow gets created here (see old paint)
106cdf0e10cSrcweir 				const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
107cdf0e10cSrcweir 				const sal_uInt16 nTransp(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
108cdf0e10cSrcweir 				const Color aShadCol(rShadColItem.GetColorValue());
109cdf0e10cSrcweir 				const XFillStyle eStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 				// Create own ItemSet and modify as needed
112cdf0e10cSrcweir 				// Always hide lines for special calc shadow
113cdf0e10cSrcweir 				SfxItemSet aSet(rItemSet);
114cdf0e10cSrcweir 				aSet.Put(XLineStyleItem(XLINE_NONE));
115cdf0e10cSrcweir 
116cdf0e10cSrcweir 				if(XFILL_HATCH == eStyle)
117cdf0e10cSrcweir 				{
118cdf0e10cSrcweir 					// #41666# Hatch color is set hard to shadow color
119cdf0e10cSrcweir 					XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
120cdf0e10cSrcweir 					aHatch.SetColor(aShadCol);
121cdf0e10cSrcweir 					aSet.Put(XFillHatchItem(String(),aHatch));
122cdf0e10cSrcweir 				}
123cdf0e10cSrcweir 				else
124cdf0e10cSrcweir 				{
125cdf0e10cSrcweir 					if(XFILL_NONE != eStyle && XFILL_SOLID != eStyle)
126cdf0e10cSrcweir 					{
127cdf0e10cSrcweir 						// force fill to solid (for Gradient and Bitmap)
128cdf0e10cSrcweir 						aSet.Put(XFillStyleItem(XFILL_SOLID));
129cdf0e10cSrcweir 					}
130cdf0e10cSrcweir 
131cdf0e10cSrcweir 					aSet.Put(XFillColorItem(String(),aShadCol));
132cdf0e10cSrcweir 					aSet.Put(XFillTransparenceItem(nTransp));
133cdf0e10cSrcweir 				}
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 				// crete FillAttribute from modified ItemSet
136cdf0e10cSrcweir 				const drawinglayer::attribute::SdrFillAttribute aFill(
137cdf0e10cSrcweir 					drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
138cdf0e10cSrcweir 				drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
139cdf0e10cSrcweir 
140cdf0e10cSrcweir 				if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
141cdf0e10cSrcweir 				{
142cdf0e10cSrcweir 					// add shadow offset to object matrix
143cdf0e10cSrcweir 					const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
144cdf0e10cSrcweir 					const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
145cdf0e10cSrcweir 					aObjectMatrix.translate(nXDist, nYDist);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir 					// create unit outline polygon as geometry (see SdrCaptionPrimitive2D::create2DDecomposition)
148cdf0e10cSrcweir 					basegfx::B2DPolygon aUnitOutline(basegfx::tools::createPolygonFromRect(
149cdf0e10cSrcweir 						basegfx::B2DRange(0.0, 0.0, 1.0, 1.0), fCornerRadiusX, fCornerRadiusY));
150cdf0e10cSrcweir 
151cdf0e10cSrcweir 					// create the specialized shadow primitive
152cdf0e10cSrcweir 					xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
153cdf0e10cSrcweir 						basegfx::B2DPolyPolygon(aUnitOutline),
154cdf0e10cSrcweir 						aObjectMatrix,
155cdf0e10cSrcweir 						aFill,
156cdf0e10cSrcweir 						drawinglayer::attribute::FillGradientAttribute());
157cdf0e10cSrcweir 				}
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 				if(xSpecialShadow.is())
160cdf0e10cSrcweir 				{
161cdf0e10cSrcweir 					// if we really got a special shadow, create a two-element retval with the shadow
162cdf0e10cSrcweir 					// behind the standard object's geometry
163cdf0e10cSrcweir 					xRetval.realloc(2);
164cdf0e10cSrcweir 
165cdf0e10cSrcweir 					xRetval[0] = xSpecialShadow;
166cdf0e10cSrcweir 					xRetval[1] = xReference;
167cdf0e10cSrcweir 				}
168cdf0e10cSrcweir 			}
169cdf0e10cSrcweir 
170cdf0e10cSrcweir 			return xRetval;
171cdf0e10cSrcweir 		}
172cdf0e10cSrcweir 	} // end of namespace contact
173cdf0e10cSrcweir } // end of namespace sdr
174cdf0e10cSrcweir 
175cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
176cdf0e10cSrcweir // eof
177