xref: /trunk/main/svx/source/sdr/contact/viewcontactofsdrcaptionobj.cxx (revision 3be598994e7b43df5b6acf9cd98e334f564d9374)
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>
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(
67cdf0e10cSrcweir                     rItemSet,
684bf7a51aSArmin Le Grand                     rCaptionObj.getText(0),
694bf7a51aSArmin Le Grand                     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(
74cdf0e10cSrcweir                 rRectangle.Left(), rRectangle.Top(),
75cdf0e10cSrcweir                 rRectangle.Right(), rRectangle.Bottom());
76cdf0e10cSrcweir             const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
77cdf0e10cSrcweir 
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(
95cdf0e10cSrcweir                     aObjectMatrix,
96cdf0e10cSrcweir                     aAttribute,
97cdf0e10cSrcweir                     rCaptionObj.getTailPolygon(),
98cdf0e10cSrcweir                     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());
146cdf0e10cSrcweir 
1477074a11eSArmin Le Grand                     if(nXDist || nYDist)
1487074a11eSArmin Le Grand                     {
149*3be59899Smseidel                         // #119750# create object and shadow outline, clip shadow outline
1507074a11eSArmin Le Grand                         // on object outline. If there is a rest, create shadow. Do this to
1517074a11eSArmin Le Grand                         // emulate that shadow is *not* visible behind the object for
1527074a11eSArmin Le Grand                         // transparent object fill for comments in excel
1537074a11eSArmin Le Grand                         basegfx::B2DPolygon aObjectOutline(
1547074a11eSArmin Le Grand                             basegfx::tools::createPolygonFromRect(
1557074a11eSArmin Le Grand                                 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
1567074a11eSArmin Le Grand                                 fCornerRadiusX,
1577074a11eSArmin Le Grand                                 fCornerRadiusY));
1587074a11eSArmin Le Grand                         aObjectOutline.transform(aObjectMatrix);
159cdf0e10cSrcweir 
1607074a11eSArmin Le Grand                         // create shadow outline
1617074a11eSArmin Le Grand                         basegfx::B2DPolygon aShadowOutline(aObjectOutline);
1627074a11eSArmin Le Grand                         aShadowOutline.transform(
1637074a11eSArmin Le Grand                             basegfx::tools::createTranslateB2DHomMatrix(nXDist, nYDist));
1647074a11eSArmin Le Grand 
1657074a11eSArmin Le Grand                         // clip shadow outline against object outline
1667074a11eSArmin Le Grand                         const basegfx::B2DPolyPolygon aClippedShadow(
1677074a11eSArmin Le Grand                             basegfx::tools::clipPolygonOnPolyPolygon(
1687074a11eSArmin Le Grand                                 aShadowOutline,
1697074a11eSArmin Le Grand                                 basegfx::B2DPolyPolygon(aObjectOutline),
1707074a11eSArmin Le Grand                                 false, // take the outside
1717074a11eSArmin Le Grand                                 false));
1727074a11eSArmin Le Grand 
1737074a11eSArmin Le Grand                         if(aClippedShadow.count())
1747074a11eSArmin Le Grand                         {
1757074a11eSArmin Le Grand                             // if there is shadow, create the specialized shadow primitive
176cdf0e10cSrcweir                             xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
1777074a11eSArmin Le Grand                                 aClippedShadow,
178cdf0e10cSrcweir                                 aFill,
179cdf0e10cSrcweir                                 drawinglayer::attribute::FillGradientAttribute());
180cdf0e10cSrcweir                         }
1817074a11eSArmin Le Grand                     }
1827074a11eSArmin Le Grand                 }
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);
189cdf0e10cSrcweir 
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