1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
20 #include "AnchorOverlayObject.hxx"
21 #include <SidebarWindowsConsts.hxx>
26 #include <svx/sdrpaintwindow.hxx>
27 #include <svx/svdview.hxx>
28 #include <svx/sdr/overlay/overlaymanager.hxx>
29 #include <tools/long.hxx>
31 #include <sw_primitivetypes2d.hxx>
32 #include <drawinglayer/attribute/lineattribute.hxx>
33 #include <drawinglayer/attribute/strokeattribute.hxx>
34 #include <drawinglayer/primitive2d/primitivetools2d.hxx>
35 #include <drawinglayer/primitive2d/PolyPolygonColorPrimitive2D.hxx>
36 #include <drawinglayer/primitive2d/PolygonStrokePrimitive2D.hxx>
38 namespace sw::sidebarwindows
{
42 // helper class: Primitive for discrete visualisation
43 class AnchorPrimitive
: public drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D
46 basegfx::B2DPolygon maTriangle
;
47 basegfx::B2DPolygon maLine
;
48 basegfx::B2DPolygon maLineTop
;
49 const AnchorState maAnchorState
;
50 basegfx::BColor maColor
;
52 // discrete line width
53 double mfDiscreteLineWidth
;
58 virtual void create2DDecomposition(
59 drawinglayer::primitive2d::Primitive2DContainer
& rContainer
,
60 const drawinglayer::geometry::ViewInformation2D
& rViewInformation
) const override
;
63 AnchorPrimitive( basegfx::B2DPolygon aTriangle
,
64 basegfx::B2DPolygon aLine
,
65 basegfx::B2DPolygon aLineTop
,
66 AnchorState aAnchorState
,
67 const basegfx::BColor
& rColor
,
68 double fDiscreteLineWidth
,
70 : maTriangle(std::move(aTriangle
)),
71 maLine(std::move(aLine
)),
72 maLineTop(std::move(aLineTop
)),
73 maAnchorState(aAnchorState
),
75 mfDiscreteLineWidth(fDiscreteLineWidth
),
76 mbLineSolid(bLineSolid
)
80 const basegfx::B2DPolygon
& getLine() const { return maLine
; }
81 const basegfx::BColor
& getColor() const { return maColor
; }
82 bool getLineSolid() const { return mbLineSolid
; }
84 virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D
& rPrimitive
) const override
;
86 virtual sal_uInt32
getPrimitive2DID() const override
;
91 void AnchorPrimitive::create2DDecomposition(
92 drawinglayer::primitive2d::Primitive2DContainer
& rContainer
,
93 const drawinglayer::geometry::ViewInformation2D
& /*rViewInformation*/) const
95 if ( AnchorState::Tri
== maAnchorState
||
96 AnchorState::All
== maAnchorState
)
99 const drawinglayer::primitive2d::Primitive2DReference
aTriangle(
100 new drawinglayer::primitive2d::PolyPolygonColorPrimitive2D(
101 basegfx::B2DPolyPolygon(maTriangle
),
104 rContainer
.push_back(aTriangle
);
107 // prepare view-independent LineWidth and color
108 const drawinglayer::attribute::LineAttribute
aLineAttribute(
110 mfDiscreteLineWidth
* getDiscreteUnit());
112 if ( AnchorState::All
== maAnchorState
)
117 const drawinglayer::primitive2d::Primitive2DReference
aSolidLine(
118 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
122 rContainer
.push_back(aSolidLine
);
126 std::vector
< double > aDotDashArray
;
127 const double fDistance(3.0 * 15.0);
128 const double fDashLen(5.0 * 15.0);
130 aDotDashArray
.push_back(fDashLen
);
131 aDotDashArray
.push_back(fDistance
);
133 drawinglayer::attribute::StrokeAttribute
aStrokeAttribute(
134 std::move(aDotDashArray
),
135 fDistance
+ fDashLen
);
137 const drawinglayer::primitive2d::Primitive2DReference
aStrokedLine(
138 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
141 std::move(aStrokeAttribute
)));
143 rContainer
.push_back(aStrokedLine
);
147 if ( AnchorState::All
== maAnchorState
||
148 AnchorState::End
== maAnchorState
)
150 // LineTop has to be created, too, but uses no shadow, so add after
151 // the other parts are created
152 const drawinglayer::primitive2d::Primitive2DReference
aLineTop(
153 new drawinglayer::primitive2d::PolygonStrokePrimitive2D(
157 rContainer
.push_back(aLineTop
);
161 bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D
& rPrimitive
) const
163 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive
))
165 const AnchorPrimitive
& rCompare
= static_cast< const AnchorPrimitive
& >(rPrimitive
);
167 return (maTriangle
== rCompare
.maTriangle
168 && getLine() == rCompare
.getLine()
169 && maLineTop
== rCompare
.maLineTop
170 && maAnchorState
== rCompare
.maAnchorState
171 && getColor() == rCompare
.getColor()
172 && mfDiscreteLineWidth
== rCompare
.mfDiscreteLineWidth
173 && getLineSolid() == rCompare
.getLineSolid());
179 sal_uInt32
AnchorPrimitive::getPrimitive2DID() const
181 return PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE
;
184 /*static*/ std::unique_ptr
<AnchorOverlayObject
> AnchorOverlayObject::CreateAnchorOverlayObject(
185 SwView
const & rDocView
,
186 const SwRect
& aAnchorRect
,
187 tools::Long aPageBorder
,
188 const Point
& aLineStart
,
189 const Point
& aLineEnd
,
190 const Color
& aColorAnchor
)
192 std::unique_ptr
<AnchorOverlayObject
> pAnchorOverlayObject
;
193 if ( rDocView
.GetDrawView() )
195 SdrPaintWindow
* pPaintWindow
= rDocView
.GetDrawView()->GetPaintWindow(0);
198 const rtl::Reference
< sdr::overlay::OverlayManager
>& xOverlayManager
= pPaintWindow
->GetOverlayManager();
200 if ( xOverlayManager
.is() )
202 pAnchorOverlayObject
.reset(new AnchorOverlayObject(
203 basegfx::B2DPoint( aAnchorRect
.Left() , aAnchorRect
.Bottom()-5*15),
204 basegfx::B2DPoint( aAnchorRect
.Left()-5*15 , aAnchorRect
.Bottom()+5*15),
205 basegfx::B2DPoint( aAnchorRect
.Left()+5*15 , aAnchorRect
.Bottom()+5*15),
206 basegfx::B2DPoint( aAnchorRect
.Left(), aAnchorRect
.Bottom()+2*15),
207 basegfx::B2DPoint( aPageBorder
,aAnchorRect
.Bottom()+2*15),
208 basegfx::B2DPoint( aLineStart
.X(),aLineStart
.Y()),
209 basegfx::B2DPoint( aLineEnd
.X(),aLineEnd
.Y()) ,
211 xOverlayManager
->add(*pAnchorOverlayObject
);
216 return pAnchorOverlayObject
;
219 AnchorOverlayObject::AnchorOverlayObject( const basegfx::B2DPoint
& rBasePos
,
220 const basegfx::B2DPoint
& rSecondPos
,
221 const basegfx::B2DPoint
& rThirdPos
,
222 const basegfx::B2DPoint
& rFourthPos
,
223 const basegfx::B2DPoint
& rFifthPos
,
224 const basegfx::B2DPoint
& rSixthPos
,
225 const basegfx::B2DPoint
& rSeventhPos
,
226 const Color
& rBaseColor
)
227 : OverlayObjectWithBasePosition(rBasePos
, rBaseColor
)
228 , maSecondPosition(rSecondPos
)
229 , maThirdPosition(rThirdPos
)
230 , maFourthPosition(rFourthPos
)
231 , maFifthPosition(rFifthPos
)
232 , maSixthPosition(rSixthPos
)
233 , maSeventhPosition(rSeventhPos
)
234 , mAnchorState(AnchorState::All
)
239 AnchorOverlayObject::~AnchorOverlayObject()
241 if ( getOverlayManager() )
243 // remove this object from the chain
244 getOverlayManager()->remove(*this);
248 void AnchorOverlayObject::implEnsureGeometry()
250 if(!maTriangle
.count())
252 maTriangle
.append(getBasePosition());
253 maTriangle
.append(GetSecondPosition());
254 maTriangle
.append(GetThirdPosition());
255 maTriangle
.setClosed(true);
260 maLine
.append(GetFourthPosition());
261 maLine
.append(GetFifthPosition());
262 maLine
.append(GetSixthPosition());
265 if(!maLineTop
.count())
267 maLineTop
.append(GetSixthPosition());
268 maLineTop
.append(GetSeventhPosition());
272 void AnchorOverlayObject::implResetGeometry()
279 drawinglayer::primitive2d::Primitive2DContainer
AnchorOverlayObject::createOverlayObjectPrimitive2DSequence()
281 implEnsureGeometry();
283 static const double aDiscreteLineWidth(1.6);
284 const drawinglayer::primitive2d::Primitive2DReference
aReference(
285 new AnchorPrimitive( maTriangle
,
289 getBaseColor().getBColor(),
290 ANCHORLINE_WIDTH
* aDiscreteLineWidth
,
293 return drawinglayer::primitive2d::Primitive2DContainer
{ aReference
};
296 void AnchorOverlayObject::SetAllPosition( const basegfx::B2DPoint
& rPoint1
,
297 const basegfx::B2DPoint
& rPoint2
,
298 const basegfx::B2DPoint
& rPoint3
,
299 const basegfx::B2DPoint
& rPoint4
,
300 const basegfx::B2DPoint
& rPoint5
,
301 const basegfx::B2DPoint
& rPoint6
,
302 const basegfx::B2DPoint
& rPoint7
)
304 if ( !(rPoint1
!= getBasePosition() ||
305 rPoint2
!= GetSecondPosition() ||
306 rPoint3
!= GetThirdPosition() ||
307 rPoint4
!= GetFourthPosition() ||
308 rPoint5
!= GetFifthPosition() ||
309 rPoint6
!= GetSixthPosition() ||
310 rPoint7
!= GetSeventhPosition()) )
313 maBasePosition
= rPoint1
;
314 maSecondPosition
= rPoint2
;
315 maThirdPosition
= rPoint3
;
316 maFourthPosition
= rPoint4
;
317 maFifthPosition
= rPoint5
;
318 maSixthPosition
= rPoint6
;
319 maSeventhPosition
= rPoint7
;
325 void AnchorOverlayObject::SetSixthPosition(const basegfx::B2DPoint
& rNew
)
327 if(rNew
!= maSixthPosition
)
329 maSixthPosition
= rNew
;
335 void AnchorOverlayObject::SetSeventhPosition(const basegfx::B2DPoint
& rNew
)
337 if(rNew
!= maSeventhPosition
)
339 maSeventhPosition
= rNew
;
345 void AnchorOverlayObject::SetTriPosition(const basegfx::B2DPoint
& rPoint1
,const basegfx::B2DPoint
& rPoint2
,const basegfx::B2DPoint
& rPoint3
,
346 const basegfx::B2DPoint
& rPoint4
,const basegfx::B2DPoint
& rPoint5
)
348 if(rPoint1
!= getBasePosition()
349 || rPoint2
!= GetSecondPosition()
350 || rPoint3
!= GetThirdPosition()
351 || rPoint4
!= GetFourthPosition()
352 || rPoint5
!= GetFifthPosition())
354 maBasePosition
= rPoint1
;
355 maSecondPosition
= rPoint2
;
356 maThirdPosition
= rPoint3
;
357 maFourthPosition
= rPoint4
;
358 maFifthPosition
= rPoint5
;
365 void AnchorOverlayObject::setLineSolid( const bool bNew
)
367 if ( bNew
!= getLineSolid() )
374 void AnchorOverlayObject::SetAnchorState( const AnchorState aState
)
376 if ( mAnchorState
!= aState
)
378 mAnchorState
= aState
;
383 } // end of namespace sw::sidebarwindows
385 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */