fdo#74697 Add Bluez 5 support for impress remote.
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofsdrcaptionobj.cxx
blob78e6c5e2c55d9e46646d74ea01aae790a68aa030
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
21 #include <svx/sdr/contact/viewcontactofsdrcaptionobj.hxx>
22 #include <svx/svdocapt.hxx>
23 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
24 #include <svx/sdr/primitive2d/sdrcaptionprimitive2d.hxx>
25 #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 //////////////////////////////////////////////////////////////////////////////
28 // includes for special text box shadow (SC)
30 #include <svl/itemset.hxx>
31 #include <svx/xhatch.hxx>
32 #include <svx/xflhtit.hxx>
33 #include <svx/xflclit.hxx>
34 #include <svx/xfltrit.hxx>
35 #include <basegfx/polygon/b2dpolygontools.hxx>
36 #include <svx/sdr/primitive2d/sdrdecompositiontools.hxx>
37 #include <basegfx/polygon/b2dpolygonclipper.hxx>
39 //////////////////////////////////////////////////////////////////////////////
41 namespace sdr
43 namespace contact
45 ViewContactOfSdrCaptionObj::ViewContactOfSdrCaptionObj(SdrCaptionObj& rCaptionObj)
46 : ViewContactOfSdrRectObj(rCaptionObj)
50 ViewContactOfSdrCaptionObj::~ViewContactOfSdrCaptionObj()
54 drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrCaptionObj::createViewIndependentPrimitive2DSequence() const
56 drawinglayer::primitive2d::Primitive2DSequence xRetval;
57 const SdrCaptionObj& rCaptionObj(GetCaptionObj());
58 const SfxItemSet& rItemSet = rCaptionObj.GetMergedItemSet();
59 const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
60 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
61 rItemSet,
62 rCaptionObj.getText(0),
63 false));
65 // take unrotated snap rect (direct model data) for position and size
66 Rectangle rRectangle = rCaptionObj.GetGeoRect();
67 // Hack for calc, transform position of object according
68 // to current zoom so as objects relative position to grid
69 // appears stable
70 Point aGridOff = rCaptionObj.GetGridOffset();
71 rRectangle += aGridOff;
73 const ::basegfx::B2DRange aObjectRange(
74 rRectangle.Left(), rRectangle.Top(),
75 rRectangle.Right(), rRectangle.Bottom());
76 const GeoStat& rGeoStat(rCaptionObj.GetGeoStat());
78 // fill object matrix
79 basegfx::B2DHomMatrix aObjectMatrix(basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
80 aObjectRange.getWidth(), aObjectRange.getHeight(),
81 rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
82 rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
83 aObjectRange.getMinX(), aObjectRange.getMinY()));
85 // calculate corner radius
86 double fCornerRadiusX;
87 double fCornerRadiusY;
88 drawinglayer::primitive2d::calculateRelativeCornerRadius(
89 rCaptionObj.GetEckenradius(), aObjectRange, fCornerRadiusX, fCornerRadiusY);
90 ::basegfx::B2DPolygon aTail = rCaptionObj.getTailPolygon();
91 // Hack for calc, transform position of tail according
92 // to current zoom so as objects relative position to grid
93 // appears stable
94 aTail.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
95 // create primitive. Always create one (even if invisible) to let the decomposition
96 // of SdrCaptionPrimitive2D create needed invisible elements for HitTest and BoundRect
97 const drawinglayer::primitive2d::Primitive2DReference xReference(
98 new drawinglayer::primitive2d::SdrCaptionPrimitive2D(
99 aObjectMatrix,
100 aAttribute,
101 aTail,
102 fCornerRadiusX,
103 fCornerRadiusY));
105 xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
107 if(!aAttribute.isDefault() && rCaptionObj.GetSpecialTextBoxShadow())
109 // for SC, the caption object may have a specialized shadow. The usual object shadow is off
110 // and a specialized shadow gets created here (see old paint)
111 const SdrShadowColorItem& rShadColItem = (SdrShadowColorItem&)(rItemSet.Get(SDRATTR_SHADOWCOLOR));
112 const sal_uInt16 nShadowTransparence(((SdrShadowTransparenceItem&)(rItemSet.Get(SDRATTR_SHADOWTRANSPARENCE))).GetValue());
113 const Color aShadowColor(rShadColItem.GetColorValue());
114 const XFillStyle eShadowStyle = ((XFillStyleItem&)(rItemSet.Get(XATTR_FILLSTYLE))).GetValue();
116 // Create own ItemSet and modify as needed
117 // Always hide lines for special calc shadow
118 SfxItemSet aSet(rItemSet);
119 aSet.Put(XLineStyleItem(XLINE_NONE));
121 if(XFILL_HATCH == eShadowStyle)
123 // #41666# Hatch color is set hard to shadow color
124 XHatch aHatch = ((XFillHatchItem&)(rItemSet.Get(XATTR_FILLHATCH))).GetHatchValue();
125 aHatch.SetColor(aShadowColor);
126 aSet.Put(XFillHatchItem(String(),aHatch));
128 else
130 if(XFILL_SOLID != eShadowStyle)
132 // force fill to solid (for Gradient, Bitmap and *no* fill (#119750# not filled comments *have* shadow))
133 aSet.Put(XFillStyleItem(XFILL_SOLID));
136 aSet.Put(XFillColorItem(String(),aShadowColor));
137 aSet.Put(XFillTransparenceItem(nShadowTransparence));
140 // crete FillAttribute from modified ItemSet
141 const drawinglayer::attribute::SdrFillAttribute aFill(
142 drawinglayer::primitive2d::createNewSdrFillAttribute(aSet));
143 drawinglayer::primitive2d::Primitive2DReference xSpecialShadow;
145 if(!aFill.isDefault() && 1.0 != aFill.getTransparence())
147 // add shadow offset to object matrix
148 const sal_uInt32 nXDist(((SdrShadowXDistItem&)(rItemSet.Get(SDRATTR_SHADOWXDIST))).GetValue());
149 const sal_uInt32 nYDist(((SdrShadowYDistItem&)(rItemSet.Get(SDRATTR_SHADOWYDIST))).GetValue());
151 if(nXDist || nYDist)
153 // #119750# create obect and shadow outline, clip shadow outline
154 // on object outline. If there is a rest, create shadow. Do this to
155 // emulate that shadow is *not* visible behind the object for
156 // transparent object fill for comments in excel
157 basegfx::B2DPolygon aObjectOutline(
158 basegfx::tools::createPolygonFromRect(
159 basegfx::B2DRange(0.0, 0.0, 1.0, 1.0),
160 fCornerRadiusX,
161 fCornerRadiusY));
162 aObjectOutline.transform(aObjectMatrix);
164 // create shadow outline
165 basegfx::B2DPolygon aShadowOutline(aObjectOutline);
166 aShadowOutline.transform(
167 basegfx::tools::createTranslateB2DHomMatrix(nXDist, nYDist));
169 // clip shadow outline against object outline
170 const basegfx::B2DPolyPolygon aClippedShadow(
171 basegfx::tools::clipPolygonOnPolyPolygon(
172 aShadowOutline,
173 basegfx::B2DPolyPolygon(aObjectOutline),
174 false, // take the outside
175 false));
177 if(aClippedShadow.count())
179 // if there is shadow, create the specialized shadow primitive
180 xSpecialShadow = drawinglayer::primitive2d::createPolyPolygonFillPrimitive(
181 aClippedShadow,
182 basegfx::B2DHomMatrix(),
183 aFill,
184 drawinglayer::attribute::FillGradientAttribute());
189 if(xSpecialShadow.is())
191 // if we really got a special shadow, create a two-element retval with the shadow
192 // behind the standard object's geometry
193 xRetval.realloc(2);
195 xRetval[0] = xSpecialShadow;
196 xRetval[1] = xReference;
200 return xRetval;
202 } // end of namespace contact
203 } // end of namespace sdr
205 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */