Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <AnchorOverlayObject.hxx>
21 : #include <SidebarWindowsConsts.hxx>
22 :
23 : #include <swrect.hxx>
24 : #include <view.hxx>
25 : #include <svx/sdrpaintwindow.hxx>
26 : #include <svx/svdview.hxx>
27 : #include <svx/sdr/overlay/overlaymanager.hxx>
28 :
29 : #include <sw_primitivetypes2d.hxx>
30 : #include <drawinglayer/primitive2d/primitivetools2d.hxx>
31 : #include <drawinglayer/primitive2d/polypolygonprimitive2d.hxx>
32 : #include <drawinglayer/primitive2d/polygonprimitive2d.hxx>
33 : #include <drawinglayer/primitive2d/shadowprimitive2d.hxx>
34 :
35 : namespace sw { namespace sidebarwindows {
36 :
37 : // helper class: Primitive for discrete visualisation
38 0 : class AnchorPrimitive : public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
39 : {
40 : private:
41 : basegfx::B2DPolygon maTriangle;
42 : basegfx::B2DPolygon maLine;
43 : basegfx::B2DPolygon maLineTop;
44 : const AnchorState maAnchorState;
45 : basegfx::BColor maColor;
46 :
47 : // discrete line width
48 : double mfDiscreteLineWidth;
49 :
50 : // bitfield
51 : bool mbShadow : 1;
52 : bool mbLineSolid : 1;
53 :
54 : protected:
55 : virtual drawinglayer::primitive2d::Primitive2DSequence create2DDecomposition(
56 : const drawinglayer::geometry::ViewInformation2D& rViewInformation) const SAL_OVERRIDE;
57 :
58 : public:
59 0 : AnchorPrimitive( const basegfx::B2DPolygon& rTriangle,
60 : const basegfx::B2DPolygon& rLine,
61 : const basegfx::B2DPolygon& rLineTop,
62 : AnchorState aAnchorState,
63 : const basegfx::BColor& rColor,
64 : double fDiscreteLineWidth,
65 : bool bShadow,
66 : bool bLineSolid )
67 : : drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
68 : maTriangle(rTriangle),
69 : maLine(rLine),
70 : maLineTop(rLineTop),
71 : maAnchorState(aAnchorState),
72 : maColor(rColor),
73 : mfDiscreteLineWidth(fDiscreteLineWidth),
74 : mbShadow(bShadow),
75 0 : mbLineSolid(bLineSolid)
76 0 : {}
77 :
78 : // data access
79 0 : const basegfx::B2DPolygon& getTriangle() const { return maTriangle; }
80 0 : const basegfx::B2DPolygon& getLine() const { return maLine; }
81 0 : const basegfx::B2DPolygon& getLineTop() const { return maLineTop; }
82 0 : AnchorState getAnchorState() const { return maAnchorState; }
83 0 : const basegfx::BColor& getColor() const { return maColor; }
84 0 : double getDiscreteLineWidth() const { return mfDiscreteLineWidth; }
85 0 : bool getShadow() const { return mbShadow; }
86 0 : bool getLineSolid() const { return mbLineSolid; }
87 :
88 : virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const SAL_OVERRIDE;
89 :
90 : DeclPrimitive2DIDBlock()
91 : };
92 :
93 0 : drawinglayer::primitive2d::Primitive2DSequence AnchorPrimitive::create2DDecomposition(
94 : const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
95 : {
96 0 : drawinglayer::primitive2d::Primitive2DSequence aRetval;
97 :
98 0 : if ( AS_TRI == maAnchorState ||
99 0 : AS_ALL == maAnchorState ||
100 0 : AS_START == maAnchorState )
101 : {
102 : // create triangle
103 : const drawinglayer::primitive2d::Primitive2DReference aTriangle(
104 : new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
105 0 : basegfx::B2DPolyPolygon(getTriangle()),
106 0 : getColor()));
107 :
108 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aTriangle);
109 : }
110 :
111 : // prepare view-independent LineWidth and color
112 : const drawinglayer::attribute::LineAttribute aLineAttribute(
113 0 : getColor(),
114 0 : getDiscreteLineWidth() * getDiscreteUnit());
115 :
116 0 : if ( AS_ALL == maAnchorState ||
117 0 : AS_START == maAnchorState )
118 : {
119 : // create line start
120 0 : if(getLineSolid())
121 : {
122 : const drawinglayer::primitive2d::Primitive2DReference aSolidLine(
123 : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
124 : getLine(),
125 0 : aLineAttribute));
126 :
127 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aSolidLine);
128 : }
129 : else
130 : {
131 0 : ::std::vector< double > aDotDashArray;
132 0 : const double fDistance(3.0 * 15.0);
133 0 : const double fDashLen(5.0 * 15.0);
134 :
135 0 : aDotDashArray.push_back(fDashLen);
136 0 : aDotDashArray.push_back(fDistance);
137 :
138 : const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
139 : aDotDashArray,
140 0 : fDistance + fDashLen);
141 :
142 : const drawinglayer::primitive2d::Primitive2DReference aStrokedLine(
143 : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
144 : getLine(),
145 : aLineAttribute,
146 0 : aStrokeAttribute));
147 :
148 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aStrokedLine);
149 : }
150 : }
151 :
152 0 : if(aRetval.hasElements() && getShadow())
153 : {
154 : // shadow is only for triangle and line start, and in upper left
155 : // and lower right direction, in different colors
156 0 : const double fColorChange(20.0 / 255.0);
157 0 : const basegfx::B3DTuple aColorChange(fColorChange, fColorChange, fColorChange);
158 0 : basegfx::BColor aLighterColor(getColor() + aColorChange);
159 0 : basegfx::BColor aDarkerColor(getColor() - aColorChange);
160 :
161 0 : aLighterColor.clamp();
162 0 : aDarkerColor.clamp();
163 :
164 : // create shadow sequence
165 0 : drawinglayer::primitive2d::Primitive2DSequence aShadows(2);
166 0 : basegfx::B2DHomMatrix aTransform;
167 :
168 0 : aTransform.set(0, 2, -getDiscreteUnit());
169 0 : aTransform.set(1, 2, -getDiscreteUnit());
170 :
171 0 : aShadows[0] = drawinglayer::primitive2d::Primitive2DReference(
172 : new drawinglayer::primitive2d::ShadowPrimitive2D(
173 : aTransform,
174 : aLighterColor,
175 0 : aRetval));
176 :
177 0 : aTransform.set(0, 2, getDiscreteUnit());
178 0 : aTransform.set(1, 2, getDiscreteUnit());
179 :
180 0 : aShadows[1] = drawinglayer::primitive2d::Primitive2DReference(
181 : new drawinglayer::primitive2d::ShadowPrimitive2D(
182 : aTransform,
183 : aDarkerColor,
184 0 : aRetval));
185 :
186 : // add shadow before geometry to make it be proccessed first
187 0 : const drawinglayer::primitive2d::Primitive2DSequence aTemporary(aRetval);
188 :
189 0 : aRetval = aShadows;
190 0 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(aRetval, aTemporary);
191 : }
192 :
193 0 : if ( AS_ALL == maAnchorState ||
194 0 : AS_END == maAnchorState )
195 : {
196 : // LineTop has to be created, too, but uses no shadow, so add after
197 : // the other parts are created
198 : const drawinglayer::primitive2d::Primitive2DReference aLineTop(
199 : new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
200 : getLineTop(),
201 0 : aLineAttribute));
202 :
203 0 : drawinglayer::primitive2d::appendPrimitive2DReferenceToPrimitive2DSequence(aRetval, aLineTop);
204 : }
205 :
206 0 : return aRetval;
207 : }
208 :
209 0 : bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
210 : {
211 0 : if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
212 : {
213 0 : const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
214 :
215 0 : return (getTriangle() == rCompare.getTriangle()
216 0 : && getLine() == rCompare.getLine()
217 0 : && getLineTop() == rCompare.getLineTop()
218 0 : && getAnchorState() == rCompare.getAnchorState()
219 0 : && getColor() == rCompare.getColor()
220 0 : && getDiscreteLineWidth() == rCompare.getDiscreteLineWidth()
221 0 : && getShadow() == rCompare.getShadow()
222 0 : && getLineSolid() == rCompare.getLineSolid());
223 : }
224 :
225 0 : return false;
226 : }
227 :
228 0 : ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE)
229 :
230 0 : /*static*/ AnchorOverlayObject* AnchorOverlayObject::CreateAnchorOverlayObject(
231 : SwView& rDocView,
232 : const SwRect& aAnchorRect,
233 : const long& aPageBorder,
234 : const Point& aLineStart,
235 : const Point& aLineEnd,
236 : const Color& aColorAnchor )
237 : {
238 0 : AnchorOverlayObject* pAnchorOverlayObject( 0 );
239 0 : if ( rDocView.GetDrawView() )
240 : {
241 0 : SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
242 0 : if( pPaintWindow )
243 : {
244 0 : rtl::Reference< ::sdr::overlay::OverlayManager > xOverlayManager = pPaintWindow->GetOverlayManager();
245 :
246 0 : if ( xOverlayManager.is() )
247 : {
248 : pAnchorOverlayObject = new AnchorOverlayObject(
249 0 : basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
250 0 : basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
251 0 : basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
252 0 : basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
253 0 : basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
254 0 : basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
255 0 : basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
256 : aColorAnchor,
257 : false,
258 0 : false);
259 0 : xOverlayManager->add(*pAnchorOverlayObject);
260 0 : }
261 : }
262 : }
263 :
264 0 : return pAnchorOverlayObject;
265 : }
266 :
267 0 : /*static*/ void AnchorOverlayObject::DestroyAnchorOverlayObject( AnchorOverlayObject* pAnchor )
268 : {
269 0 : if ( pAnchor )
270 : {
271 0 : if ( pAnchor->getOverlayManager() )
272 : {
273 : // remove this object from the chain
274 0 : pAnchor->getOverlayManager()->remove(*pAnchor);
275 : }
276 0 : delete pAnchor;
277 : }
278 0 : }
279 :
280 0 : AnchorOverlayObject::AnchorOverlayObject( const basegfx::B2DPoint& rBasePos,
281 : const basegfx::B2DPoint& rSecondPos,
282 : const basegfx::B2DPoint& rThirdPos,
283 : const basegfx::B2DPoint& rFourthPos,
284 : const basegfx::B2DPoint& rFifthPos,
285 : const basegfx::B2DPoint& rSixthPos,
286 : const basegfx::B2DPoint& rSeventhPos,
287 : const Color aBaseColor,
288 : const bool bShadowedEffect,
289 : const bool bLineSolid)
290 : : OverlayObjectWithBasePosition( rBasePos, aBaseColor )
291 : , maSecondPosition(rSecondPos)
292 : , maThirdPosition(rThirdPos)
293 : , maFourthPosition(rFourthPos)
294 : , maFifthPosition(rFifthPos)
295 : , maSixthPosition(rSixthPos)
296 : , maSeventhPosition(rSeventhPos)
297 : , maTriangle()
298 : , maLine()
299 : , maLineTop()
300 : , mHeight(0)
301 : , mAnchorState(AS_ALL)
302 : , mbShadowedEffect(bShadowedEffect)
303 0 : , mbLineSolid(bLineSolid)
304 : {
305 0 : }
306 :
307 0 : AnchorOverlayObject::~AnchorOverlayObject()
308 : {
309 0 : }
310 :
311 0 : void AnchorOverlayObject::implEnsureGeometry()
312 : {
313 0 : if(!maTriangle.count())
314 : {
315 0 : maTriangle.append(getBasePosition());
316 0 : maTriangle.append(GetSecondPosition());
317 0 : maTriangle.append(GetThirdPosition());
318 0 : maTriangle.setClosed(true);
319 : }
320 :
321 0 : if(!maLine.count())
322 : {
323 0 : maLine.append(GetFourthPosition());
324 0 : maLine.append(GetFifthPosition());
325 0 : maLine.append(GetSixthPosition());
326 : }
327 :
328 0 : if(!maLineTop.count())
329 : {
330 0 : maLineTop.append(GetSixthPosition());
331 0 : maLineTop.append(GetSeventhPosition());
332 : }
333 0 : }
334 :
335 0 : void AnchorOverlayObject::implResetGeometry()
336 : {
337 0 : maTriangle.clear();
338 0 : maLine.clear();
339 0 : maLineTop.clear();
340 0 : }
341 :
342 0 : drawinglayer::primitive2d::Primitive2DSequence AnchorOverlayObject::createOverlayObjectPrimitive2DSequence()
343 : {
344 0 : implEnsureGeometry();
345 :
346 : static double aDiscreteLineWidth(1.6);
347 : const drawinglayer::primitive2d::Primitive2DReference aReference(
348 : new AnchorPrimitive( maTriangle,
349 : maLine,
350 : maLineTop,
351 : GetAnchorState(),
352 0 : getBaseColor().getBColor(),
353 : ANCHORLINE_WIDTH * aDiscreteLineWidth,
354 0 : getShadowedEffect(),
355 0 : getLineSolid()) );
356 :
357 0 : return drawinglayer::primitive2d::Primitive2DSequence(&aReference, 1);
358 : }
359 :
360 0 : void AnchorOverlayObject::SetAllPosition( const basegfx::B2DPoint& rPoint1,
361 : const basegfx::B2DPoint& rPoint2,
362 : const basegfx::B2DPoint& rPoint3,
363 : const basegfx::B2DPoint& rPoint4,
364 : const basegfx::B2DPoint& rPoint5,
365 : const basegfx::B2DPoint& rPoint6,
366 : const basegfx::B2DPoint& rPoint7)
367 : {
368 0 : if ( rPoint1 != getBasePosition() ||
369 0 : rPoint2 != GetSecondPosition() ||
370 0 : rPoint3 != GetThirdPosition() ||
371 0 : rPoint4 != GetFourthPosition() ||
372 0 : rPoint5 != GetFifthPosition() ||
373 0 : rPoint6 != GetSixthPosition() ||
374 0 : rPoint7 != GetSeventhPosition() )
375 : {
376 0 : maBasePosition = rPoint1;
377 0 : maSecondPosition = rPoint2;
378 0 : maThirdPosition = rPoint3;
379 0 : maFourthPosition = rPoint4;
380 0 : maFifthPosition = rPoint5;
381 0 : maSixthPosition = rPoint6;
382 0 : maSeventhPosition = rPoint7;
383 :
384 0 : implResetGeometry();
385 0 : objectChange();
386 : }
387 0 : }
388 :
389 0 : void AnchorOverlayObject::SetSixthPosition(const basegfx::B2DPoint& rNew)
390 : {
391 0 : if(rNew != maSixthPosition)
392 : {
393 0 : maSixthPosition = rNew;
394 0 : implResetGeometry();
395 0 : objectChange();
396 : }
397 0 : }
398 :
399 0 : void AnchorOverlayObject::SetSeventhPosition(const basegfx::B2DPoint& rNew)
400 : {
401 0 : if(rNew != maSeventhPosition)
402 : {
403 0 : maSeventhPosition = rNew;
404 0 : implResetGeometry();
405 0 : objectChange();
406 : }
407 0 : }
408 :
409 0 : void AnchorOverlayObject::SetTriPosition(const basegfx::B2DPoint& rPoint1,const basegfx::B2DPoint& rPoint2,const basegfx::B2DPoint& rPoint3,
410 : const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
411 : {
412 0 : if(rPoint1 != getBasePosition()
413 0 : || rPoint2 != GetSecondPosition()
414 0 : || rPoint3 != GetThirdPosition()
415 0 : || rPoint4 != GetFourthPosition()
416 0 : || rPoint5 != GetFifthPosition())
417 : {
418 0 : maBasePosition = rPoint1;
419 0 : maSecondPosition = rPoint2;
420 0 : maThirdPosition = rPoint3;
421 0 : maFourthPosition = rPoint4;
422 0 : maFifthPosition = rPoint5;
423 :
424 0 : implResetGeometry();
425 0 : objectChange();
426 : }
427 0 : }
428 :
429 0 : void AnchorOverlayObject::setLineSolid( const bool bNew )
430 : {
431 0 : if ( bNew != getLineSolid() )
432 : {
433 0 : mbLineSolid = bNew;
434 0 : objectChange();
435 : }
436 0 : }
437 :
438 0 : void AnchorOverlayObject::SetAnchorState( const AnchorState aState)
439 : {
440 0 : if ( mAnchorState != aState)
441 : {
442 0 : mAnchorState = aState;
443 0 : objectChange();
444 : }
445 0 : }
446 :
447 : } } // end of namespace sw::annotation
448 :
449 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|