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 
29 #include <sw_primitivetypes2d.hxx>
33 
34 namespace sw::sidebarwindows {
35 
36 namespace {
37 
38 // helper class: Primitive for discrete visualisation
40 {
41 private:
47 
48  // discrete line width
50 
51  bool mbLineSolid : 1;
52 
53 protected:
54  virtual void create2DDecomposition(
56  const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
57 
58 public:
59  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 bLineSolid )
66  : drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D(),
67  maTriangle(rTriangle),
68  maLine(rLine),
69  maLineTop(rLineTop),
70  maAnchorState(aAnchorState),
71  maColor(rColor),
72  mfDiscreteLineWidth(fDiscreteLineWidth),
73  mbLineSolid(bLineSolid)
74  {}
75 
76  // data access
77  const basegfx::B2DPolygon& getLine() const { return maLine; }
78  const basegfx::BColor& getColor() const { return maColor; }
79  bool getLineSolid() const { return mbLineSolid; }
80 
81  virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
82 
83  virtual sal_uInt32 getPrimitive2DID() const override;
84 };
85 
86 }
87 
88 void AnchorPrimitive::create2DDecomposition(
90  const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
91 {
94  {
95  // create triangle
99  getColor()));
100 
101  rContainer.push_back(aTriangle);
102  }
103 
104  // prepare view-independent LineWidth and color
105  const drawinglayer::attribute::LineAttribute aLineAttribute(
106  getColor(),
107  mfDiscreteLineWidth * getDiscreteUnit());
108 
110  {
111  // create line start
112  if(getLineSolid())
113  {
116  getLine(),
117  aLineAttribute));
118 
119  rContainer.push_back(aSolidLine);
120  }
121  else
122  {
123  std::vector< double > aDotDashArray;
124  const double fDistance(3.0 * 15.0);
125  const double fDashLen(5.0 * 15.0);
126 
127  aDotDashArray.push_back(fDashLen);
128  aDotDashArray.push_back(fDistance);
129 
130  const drawinglayer::attribute::StrokeAttribute aStrokeAttribute(
131  aDotDashArray,
132  fDistance + fDashLen);
133 
136  getLine(),
137  aLineAttribute,
138  aStrokeAttribute));
139 
140  rContainer.push_back(aStrokedLine);
141  }
142  }
143 
146  {
147  // LineTop has to be created, too, but uses no shadow, so add after
148  // the other parts are created
151  maLineTop,
152  aLineAttribute));
153 
154  rContainer.push_back(aLineTop);
155  }
156 }
157 
158 bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
159 {
160  if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
161  {
162  const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
163 
164  return (maTriangle == rCompare.maTriangle
165  && getLine() == rCompare.getLine()
166  && maLineTop == rCompare.maLineTop
167  && maAnchorState == rCompare.maAnchorState
168  && getColor() == rCompare.getColor()
169  && mfDiscreteLineWidth == rCompare.mfDiscreteLineWidth
170  && getLineSolid() == rCompare.getLineSolid());
171  }
172 
173  return false;
174 }
175 
177 
178 /*static*/ std::unique_ptr<AnchorOverlayObject> AnchorOverlayObject::CreateAnchorOverlayObject(
179  SwView const & rDocView,
180  const SwRect& aAnchorRect,
181  long aPageBorder,
182  const Point& aLineStart,
183  const Point& aLineEnd,
184  const Color& aColorAnchor )
185 {
186  std::unique_ptr<AnchorOverlayObject> pAnchorOverlayObject;
187  if ( rDocView.GetDrawView() )
188  {
189  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
190  if( pPaintWindow )
191  {
192  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
193 
194  if ( xOverlayManager.is() )
195  {
196  pAnchorOverlayObject.reset(new AnchorOverlayObject(
197  basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
198  basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
199  basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
200  basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
201  basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
202  basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
203  basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
204  aColorAnchor));
205  xOverlayManager->add(*pAnchorOverlayObject);
206  }
207  }
208  }
209 
210  return pAnchorOverlayObject;
211 }
212 
214  const basegfx::B2DPoint& rSecondPos,
215  const basegfx::B2DPoint& rThirdPos,
216  const basegfx::B2DPoint& rFourthPos,
217  const basegfx::B2DPoint& rFifthPos,
218  const basegfx::B2DPoint& rSixthPos,
219  const basegfx::B2DPoint& rSeventhPos,
220  const Color& rBaseColor)
221  : OverlayObjectWithBasePosition(rBasePos, rBaseColor)
222  , maSecondPosition(rSecondPos)
223  , maThirdPosition(rThirdPos)
224  , maFourthPosition(rFourthPos)
225  , maFifthPosition(rFifthPos)
226  , maSixthPosition(rSixthPos)
227  , maSeventhPosition(rSeventhPos)
228  , maTriangle()
229  , maLine()
230  , maLineTop()
231  , mAnchorState(AnchorState::All)
232  , mbLineSolid(false)
233 {
234 }
235 
237 {
238  if ( getOverlayManager() )
239  {
240  // remove this object from the chain
241  getOverlayManager()->remove(*this);
242  }
243 }
244 
246 {
247  if(!maTriangle.count())
248  {
252  maTriangle.setClosed(true);
253  }
254 
255  if(!maLine.count())
256  {
260  }
261 
262  if(!maLineTop.count())
263  {
266  }
267 }
268 
270 {
271  maTriangle.clear();
272  maLine.clear();
273  maLineTop.clear();
274 }
275 
277 {
279 
280  static const double aDiscreteLineWidth(1.6);
282  new AnchorPrimitive( maTriangle,
283  maLine,
284  maLineTop,
285  GetAnchorState(),
286  getBaseColor().getBColor(),
287  ANCHORLINE_WIDTH * aDiscreteLineWidth,
288  getLineSolid()) );
289 
291 }
292 
294  const basegfx::B2DPoint& rPoint2,
295  const basegfx::B2DPoint& rPoint3,
296  const basegfx::B2DPoint& rPoint4,
297  const basegfx::B2DPoint& rPoint5,
298  const basegfx::B2DPoint& rPoint6,
299  const basegfx::B2DPoint& rPoint7)
300 {
301  if ( rPoint1 != getBasePosition() ||
302  rPoint2 != GetSecondPosition() ||
303  rPoint3 != GetThirdPosition() ||
304  rPoint4 != GetFourthPosition() ||
305  rPoint5 != GetFifthPosition() ||
306  rPoint6 != GetSixthPosition() ||
307  rPoint7 != GetSeventhPosition() )
308  {
309  maBasePosition = rPoint1;
310  maSecondPosition = rPoint2;
311  maThirdPosition = rPoint3;
312  maFourthPosition = rPoint4;
313  maFifthPosition = rPoint5;
314  maSixthPosition = rPoint6;
315  maSeventhPosition = rPoint7;
316 
318  objectChange();
319  }
320 }
321 
323 {
324  if(rNew != maSixthPosition)
325  {
326  maSixthPosition = rNew;
328  objectChange();
329  }
330 }
331 
333 {
334  if(rNew != maSeventhPosition)
335  {
336  maSeventhPosition = rNew;
338  objectChange();
339  }
340 }
341 
343  const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
344 {
345  if(rPoint1 != getBasePosition()
346  || rPoint2 != GetSecondPosition()
347  || rPoint3 != GetThirdPosition()
348  || rPoint4 != GetFourthPosition()
349  || rPoint5 != GetFifthPosition())
350  {
351  maBasePosition = rPoint1;
352  maSecondPosition = rPoint2;
353  maThirdPosition = rPoint3;
354  maFourthPosition = rPoint4;
355  maFifthPosition = rPoint5;
356 
358  objectChange();
359  }
360 }
361 
362 void AnchorOverlayObject::setLineSolid( const bool bNew )
363 {
364  if ( bNew != getLineSolid() )
365  {
366  mbLineSolid = bNew;
367  objectChange();
368  }
369 }
370 
372 {
373  if ( mAnchorState != aState)
374  {
375  mAnchorState = aState;
376  objectChange();
377  }
378 }
379 
380 } // end of namespace sw::sidebarwindows
381 
382 /* 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
double mfDiscreteLineWidth
basegfx::BColor maColor
basegfx::B2DPolygon maLineTop
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
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 setClosed(bool bNew)
const Color & getBaseColor() const
css::uno::Reference< css::graphic::XPrimitive2D > Primitive2DReference
const basegfx::B2DPoint & GetSixthPosition() const
basegfx::B2DPoint maSecondPosition
const AnchorState maAnchorState
basegfx::B2DPolygon maLine
bool mbLineSolid
const basegfx::B2DPoint & GetSeventhPosition() const
bool operator==(const ScCsvLayoutData &rData1, const ScCsvLayoutData &rData2)
Definition: view.hxx:144
ImplPrimitive2DIDBlock(AnchorPrimitive, PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE) std
sal_uInt32 count() const