LibreOffice Module sw (master)  1
AnchorOverlayObject.cxx
Go to the documentation of this file.
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>
28 #include <tools/long.hxx>
29 
30 #include <sw_primitivetypes2d.hxx>
34 
35 namespace sw::sidebarwindows {
36 
37 namespace {
38 
39 // helper class: Primitive for discrete visualisation
41 {
42 private:
48 
49  // discrete line width
51 
52  bool mbLineSolid : 1;
53 
54 protected:
55  virtual void create2DDecomposition(
57  const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
58 
59 public:
60  AnchorPrimitive( const basegfx::B2DPolygon& rTriangle,
61  const basegfx::B2DPolygon& rLine,
62  const basegfx::B2DPolygon& rLineTop,
63  AnchorState aAnchorState,
64  const basegfx::BColor& rColor,
65  double fDiscreteLineWidth,
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  mbLineSolid(bLineSolid)
75  {}
76 
77  // data access
78  const basegfx::B2DPolygon& getLine() const { return maLine; }
79  const basegfx::BColor& getColor() const { return maColor; }
80  bool getLineSolid() const { return mbLineSolid; }
81 
82  virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
83 
84  virtual sal_uInt32 getPrimitive2DID() const override;
85 };
86 
87 }
88 
89 void AnchorPrimitive::create2DDecomposition(
91  const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
92 {
95  {
96  // create triangle
100  getColor()));
101 
102  rContainer.push_back(aTriangle);
103  }
104 
105  // prepare view-independent LineWidth and color
106  const drawinglayer::attribute::LineAttribute aLineAttribute(
107  getColor(),
108  mfDiscreteLineWidth * getDiscreteUnit());
109 
111  {
112  // create line start
113  if(getLineSolid())
114  {
117  getLine(),
118  aLineAttribute));
119 
120  rContainer.push_back(aSolidLine);
121  }
122  else
123  {
124  std::vector< double > aDotDashArray;
125  const double fDistance(3.0 * 15.0);
126  const double fDashLen(5.0 * 15.0);
127 
128  aDotDashArray.push_back(fDashLen);
129  aDotDashArray.push_back(fDistance);
130 
131  const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
132  aDotDashArray,
133  fDistance + fDashLen);
134 
137  getLine(),
138  aLineAttribute,
139  aStrokeAttribute));
140 
141  rContainer.push_back(aStrokedLine);
142  }
143  }
144 
147  {
148  // LineTop has to be created, too, but uses no shadow, so add after
149  // the other parts are created
152  maLineTop,
153  aLineAttribute));
154 
155  rContainer.push_back(aLineTop);
156  }
157 }
158 
159 bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
160 {
161  if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
162  {
163  const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
164 
165  return (maTriangle == rCompare.maTriangle
166  && getLine() == rCompare.getLine()
167  && maLineTop == rCompare.maLineTop
168  && maAnchorState == rCompare.maAnchorState
169  && getColor() == rCompare.getColor()
170  && mfDiscreteLineWidth == rCompare.mfDiscreteLineWidth
171  && getLineSolid() == rCompare.getLineSolid());
172  }
173 
174  return false;
175 }
176 
177 sal_uInt32 AnchorPrimitive::getPrimitive2DID() const
178 {
180 }
181 
182 /*static*/ std::unique_ptr<AnchorOverlayObject> AnchorOverlayObject::CreateAnchorOverlayObject(
183  SwView const & rDocView,
184  const SwRect& aAnchorRect,
185  tools::Long aPageBorder,
186  const Point& aLineStart,
187  const Point& aLineEnd,
188  const Color& aColorAnchor )
189 {
190  std::unique_ptr<AnchorOverlayObject> pAnchorOverlayObject;
191  if ( rDocView.GetDrawView() )
192  {
193  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
194  if( pPaintWindow )
195  {
196  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
197 
198  if ( xOverlayManager.is() )
199  {
200  pAnchorOverlayObject.reset(new AnchorOverlayObject(
201  basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
202  basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
203  basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
204  basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
205  basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
206  basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
207  basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
208  aColorAnchor));
209  xOverlayManager->add(*pAnchorOverlayObject);
210  }
211  }
212  }
213 
214  return pAnchorOverlayObject;
215 }
216 
218  const basegfx::B2DPoint& rSecondPos,
219  const basegfx::B2DPoint& rThirdPos,
220  const basegfx::B2DPoint& rFourthPos,
221  const basegfx::B2DPoint& rFifthPos,
222  const basegfx::B2DPoint& rSixthPos,
223  const basegfx::B2DPoint& rSeventhPos,
224  const Color& rBaseColor)
225  : OverlayObjectWithBasePosition(rBasePos, rBaseColor)
226  , maSecondPosition(rSecondPos)
227  , maThirdPosition(rThirdPos)
228  , maFourthPosition(rFourthPos)
229  , maFifthPosition(rFifthPos)
230  , maSixthPosition(rSixthPos)
231  , maSeventhPosition(rSeventhPos)
232  , maTriangle()
233  , maLine()
234  , maLineTop()
235  , mAnchorState(AnchorState::All)
236  , mbLineSolid(false)
237 {
238 }
239 
241 {
242  if ( getOverlayManager() )
243  {
244  // remove this object from the chain
245  getOverlayManager()->remove(*this);
246  }
247 }
248 
250 {
251  if(!maTriangle.count())
252  {
256  maTriangle.setClosed(true);
257  }
258 
259  if(!maLine.count())
260  {
264  }
265 
266  if(!maLineTop.count())
267  {
270  }
271 }
272 
274 {
275  maTriangle.clear();
276  maLine.clear();
277  maLineTop.clear();
278 }
279 
281 {
283 
284  static const double aDiscreteLineWidth(1.6);
286  new AnchorPrimitive( maTriangle,
287  maLine,
288  maLineTop,
289  GetAnchorState(),
290  getBaseColor().getBColor(),
291  ANCHORLINE_WIDTH * aDiscreteLineWidth,
292  getLineSolid()) );
293 
295 }
296 
298  const basegfx::B2DPoint& rPoint2,
299  const basegfx::B2DPoint& rPoint3,
300  const basegfx::B2DPoint& rPoint4,
301  const basegfx::B2DPoint& rPoint5,
302  const basegfx::B2DPoint& rPoint6,
303  const basegfx::B2DPoint& rPoint7)
304 {
305  if ( !(rPoint1 != getBasePosition() ||
306  rPoint2 != GetSecondPosition() ||
307  rPoint3 != GetThirdPosition() ||
308  rPoint4 != GetFourthPosition() ||
309  rPoint5 != GetFifthPosition() ||
310  rPoint6 != GetSixthPosition() ||
311  rPoint7 != GetSeventhPosition()) )
312  return;
313 
314  maBasePosition = rPoint1;
315  maSecondPosition = rPoint2;
316  maThirdPosition = rPoint3;
317  maFourthPosition = rPoint4;
318  maFifthPosition = rPoint5;
319  maSixthPosition = rPoint6;
320  maSeventhPosition = rPoint7;
321 
323  objectChange();
324 }
325 
327 {
328  if(rNew != maSixthPosition)
329  {
330  maSixthPosition = rNew;
332  objectChange();
333  }
334 }
335 
337 {
338  if(rNew != maSeventhPosition)
339  {
340  maSeventhPosition = rNew;
342  objectChange();
343  }
344 }
345 
347  const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
348 {
349  if(rPoint1 != getBasePosition()
350  || rPoint2 != GetSecondPosition()
351  || rPoint3 != GetThirdPosition()
352  || rPoint4 != GetFourthPosition()
353  || rPoint5 != GetFifthPosition())
354  {
355  maBasePosition = rPoint1;
356  maSecondPosition = rPoint2;
357  maThirdPosition = rPoint3;
358  maFourthPosition = rPoint4;
359  maFifthPosition = rPoint5;
360 
362  objectChange();
363  }
364 }
365 
366 void AnchorOverlayObject::setLineSolid( const bool bNew )
367 {
368  if ( bNew != getLineSolid() )
369  {
370  mbLineSolid = bNew;
371  objectChange();
372  }
373 }
374 
376 {
377  if ( mAnchorState != aState)
378  {
379  mAnchorState = aState;
380  objectChange();
381  }
382 }
383 
384 } // end of namespace sw::sidebarwindows
385 
386 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
#define PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE
void Left(const tools::Long nLeft)
Definition: swrect.hxx:194
long Long
double mfDiscreteLineWidth
basegfx::BColor maColor
basegfx::B2DPolygon maLineTop
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
OverlayManager * getOverlayManager() const
const sal_Int8 ANCHORLINE_WIDTH
void remove(OverlayObject &rOverlayObject)
void SetAllPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2, const basegfx::B2DPoint &rPoint3, const basegfx::B2DPoint &rPoint4, const basegfx::B2DPoint &rPoint5, const basegfx::B2DPoint &rPoint6, const basegfx::B2DPoint &rPoint7)
const basegfx::B2DPoint & GetFifthPosition() const
AnchorOverlayObject(const basegfx::B2DPoint &rBasePos, const basegfx::B2DPoint &rSecondPos, const basegfx::B2DPoint &rThirdPos, const basegfx::B2DPoint &rFourthPos, const basegfx::B2DPoint &rFifthPos, const basegfx::B2DPoint &rSixthPos, const basegfx::B2DPoint &rSeventhPos, const Color &rBaseColor)
const basegfx::B2DPoint & GetFourthPosition() const
void SetSixthPosition(const basegfx::B2DPoint &rNew)
basegfx::B2DPolygon maTriangle
void SetTriPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2, const basegfx::B2DPoint &rPoint3, const basegfx::B2DPoint &rPoint4, const basegfx::B2DPoint &rPoint5)
const basegfx::B2DPoint & GetSecondPosition() const
void SetSeventhPosition(const basegfx::B2DPoint &rNew)
const basegfx::B2DPoint & getBasePosition() const
const basegfx::B2DPoint & GetThirdPosition() const
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
void SetAnchorState(const AnchorState aState)
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:208
void setClosed(bool bNew)
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
static std::unique_ptr< AnchorOverlayObject > CreateAnchorOverlayObject(SwView const &rDocView, const SwRect &aAnchorRect, tools::Long aPageBorder, const Point &aLineStart, const Point &aLineEnd, const Color &aColorAnchor)
const basegfx::B2DPoint & GetSixthPosition() const
basegfx::B2DPoint maSecondPosition
const AnchorState maAnchorState
basegfx::B2DPolygon maLine
bool mbLineSolid
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
const basegfx::B2DPoint & GetSeventhPosition() const
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
Definition: view.hxx:144
sal_uInt32 count() const