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>
36 
37 namespace sw::sidebarwindows {
38 
39 namespace {
40 
41 // helper class: Primitive for discrete visualisation
43 {
44 private:
50 
51  // discrete line width
53 
54  bool mbLineSolid : 1;
55 
56 protected:
57  virtual void create2DDecomposition(
59  const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
60 
61 public:
62  AnchorPrimitive( const basegfx::B2DPolygon& rTriangle,
63  const basegfx::B2DPolygon& rLine,
64  const basegfx::B2DPolygon& rLineTop,
65  AnchorState aAnchorState,
66  const basegfx::BColor& rColor,
67  double fDiscreteLineWidth,
68  bool bLineSolid )
69  : maTriangle(rTriangle),
70  maLine(rLine),
71  maLineTop(rLineTop),
72  maAnchorState(aAnchorState),
73  maColor(rColor),
74  mfDiscreteLineWidth(fDiscreteLineWidth),
75  mbLineSolid(bLineSolid)
76  {}
77 
78  // data access
79  const basegfx::B2DPolygon& getLine() const { return maLine; }
80  const basegfx::BColor& getColor() const { return maColor; }
81  bool getLineSolid() const { return mbLineSolid; }
82 
83  virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
84 
85  virtual sal_uInt32 getPrimitive2DID() const override;
86 };
87 
88 }
89 
90 void AnchorPrimitive::create2DDecomposition(
92  const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
93 {
96  {
97  // create triangle
101  getColor()));
102 
103  rContainer.push_back(aTriangle);
104  }
105 
106  // prepare view-independent LineWidth and color
107  const drawinglayer::attribute::LineAttribute aLineAttribute(
108  getColor(),
109  mfDiscreteLineWidth * getDiscreteUnit());
110 
112  {
113  // create line start
114  if(getLineSolid())
115  {
118  getLine(),
119  aLineAttribute));
120 
121  rContainer.push_back(aSolidLine);
122  }
123  else
124  {
125  std::vector< double > aDotDashArray;
126  const double fDistance(3.0 * 15.0);
127  const double fDashLen(5.0 * 15.0);
128 
129  aDotDashArray.push_back(fDashLen);
130  aDotDashArray.push_back(fDistance);
131 
132  const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
133  std::move(aDotDashArray),
134  fDistance + fDashLen);
135 
138  getLine(),
139  aLineAttribute,
140  aStrokeAttribute));
141 
142  rContainer.push_back(aStrokedLine);
143  }
144  }
145 
148  {
149  // LineTop has to be created, too, but uses no shadow, so add after
150  // the other parts are created
153  maLineTop,
154  aLineAttribute));
155 
156  rContainer.push_back(aLineTop);
157  }
158 }
159 
160 bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
161 {
162  if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
163  {
164  const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
165 
166  return (maTriangle == rCompare.maTriangle
167  && getLine() == rCompare.getLine()
168  && maLineTop == rCompare.maLineTop
169  && maAnchorState == rCompare.maAnchorState
170  && getColor() == rCompare.getColor()
171  && mfDiscreteLineWidth == rCompare.mfDiscreteLineWidth
172  && getLineSolid() == rCompare.getLineSolid());
173  }
174 
175  return false;
176 }
177 
178 sal_uInt32 AnchorPrimitive::getPrimitive2DID() const
179 {
181 }
182 
183 /*static*/ std::unique_ptr<AnchorOverlayObject> AnchorOverlayObject::CreateAnchorOverlayObject(
184  SwView const & rDocView,
185  const SwRect& aAnchorRect,
186  tools::Long aPageBorder,
187  const Point& aLineStart,
188  const Point& aLineEnd,
189  const Color& aColorAnchor )
190 {
191  std::unique_ptr<AnchorOverlayObject> pAnchorOverlayObject;
192  if ( rDocView.GetDrawView() )
193  {
194  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
195  if( pPaintWindow )
196  {
197  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
198 
199  if ( xOverlayManager.is() )
200  {
201  pAnchorOverlayObject.reset(new AnchorOverlayObject(
202  basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
203  basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
204  basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
205  basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
206  basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
207  basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
208  basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
209  aColorAnchor));
210  xOverlayManager->add(*pAnchorOverlayObject);
211  }
212  }
213  }
214 
215  return pAnchorOverlayObject;
216 }
217 
219  const basegfx::B2DPoint& rSecondPos,
220  const basegfx::B2DPoint& rThirdPos,
221  const basegfx::B2DPoint& rFourthPos,
222  const basegfx::B2DPoint& rFifthPos,
223  const basegfx::B2DPoint& rSixthPos,
224  const basegfx::B2DPoint& rSeventhPos,
225  const Color& rBaseColor)
226  : OverlayObjectWithBasePosition(rBasePos, rBaseColor)
227  , maSecondPosition(rSecondPos)
228  , maThirdPosition(rThirdPos)
229  , maFourthPosition(rFourthPos)
230  , maFifthPosition(rFifthPos)
231  , maSixthPosition(rSixthPos)
232  , maSeventhPosition(rSeventhPos)
233  , mAnchorState(AnchorState::All)
234  , mbLineSolid(false)
235 {
236 }
237 
239 {
240  if ( getOverlayManager() )
241  {
242  // remove this object from the chain
243  getOverlayManager()->remove(*this);
244  }
245 }
246 
248 {
249  if(!maTriangle.count())
250  {
254  maTriangle.setClosed(true);
255  }
256 
257  if(!maLine.count())
258  {
262  }
263 
264  if(!maLineTop.count())
265  {
268  }
269 }
270 
272 {
273  maTriangle.clear();
274  maLine.clear();
275  maLineTop.clear();
276 }
277 
279 {
281 
282  static const double aDiscreteLineWidth(1.6);
284  new AnchorPrimitive( maTriangle,
285  maLine,
286  maLineTop,
287  GetAnchorState(),
288  getBaseColor().getBColor(),
289  ANCHORLINE_WIDTH * aDiscreteLineWidth,
290  getLineSolid()) );
291 
293 }
294 
296  const basegfx::B2DPoint& rPoint2,
297  const basegfx::B2DPoint& rPoint3,
298  const basegfx::B2DPoint& rPoint4,
299  const basegfx::B2DPoint& rPoint5,
300  const basegfx::B2DPoint& rPoint6,
301  const basegfx::B2DPoint& rPoint7)
302 {
303  if ( !(rPoint1 != getBasePosition() ||
304  rPoint2 != GetSecondPosition() ||
305  rPoint3 != GetThirdPosition() ||
306  rPoint4 != GetFourthPosition() ||
307  rPoint5 != GetFifthPosition() ||
308  rPoint6 != GetSixthPosition() ||
309  rPoint7 != GetSeventhPosition()) )
310  return;
311 
312  maBasePosition = rPoint1;
313  maSecondPosition = rPoint2;
314  maThirdPosition = rPoint3;
315  maFourthPosition = rPoint4;
316  maFifthPosition = rPoint5;
317  maSixthPosition = rPoint6;
318  maSeventhPosition = rPoint7;
319 
321  objectChange();
322 }
323 
325 {
326  if(rNew != maSixthPosition)
327  {
328  maSixthPosition = rNew;
330  objectChange();
331  }
332 }
333 
335 {
336  if(rNew != maSeventhPosition)
337  {
338  maSeventhPosition = rNew;
340  objectChange();
341  }
342 }
343 
345  const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
346 {
347  if(rPoint1 != getBasePosition()
348  || rPoint2 != GetSecondPosition()
349  || rPoint3 != GetThirdPosition()
350  || rPoint4 != GetFourthPosition()
351  || rPoint5 != GetFifthPosition())
352  {
353  maBasePosition = rPoint1;
354  maSecondPosition = rPoint2;
355  maThirdPosition = rPoint3;
356  maFourthPosition = rPoint4;
357  maFifthPosition = rPoint5;
358 
360  objectChange();
361  }
362 }
363 
364 void AnchorOverlayObject::setLineSolid( const bool bNew )
365 {
366  if ( bNew != getLineSolid() )
367  {
368  mbLineSolid = bNew;
369  objectChange();
370  }
371 }
372 
374 {
375  if ( mAnchorState != aState)
376  {
377  mAnchorState = aState;
378  objectChange();
379  }
380 }
381 
382 } // end of namespace sw::sidebarwindows
383 
384 /* 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:197
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:211
void setClosed(bool bNew)
const Color & getBaseColor() const
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
bool m_bDetectedRangeSegmentation false