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