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 
178 
179 /*static*/ std::unique_ptr<AnchorOverlayObject> AnchorOverlayObject::CreateAnchorOverlayObject(
180  SwView const & rDocView,
181  const SwRect& aAnchorRect,
182  tools::Long aPageBorder,
183  const Point& aLineStart,
184  const Point& aLineEnd,
185  const Color& aColorAnchor )
186 {
187  std::unique_ptr<AnchorOverlayObject> pAnchorOverlayObject;
188  if ( rDocView.GetDrawView() )
189  {
190  SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
191  if( pPaintWindow )
192  {
193  const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
194 
195  if ( xOverlayManager.is() )
196  {
197  pAnchorOverlayObject.reset(new AnchorOverlayObject(
198  basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
199  basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
200  basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
201  basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
202  basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
203  basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
204  basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
205  aColorAnchor));
206  xOverlayManager->add(*pAnchorOverlayObject);
207  }
208  }
209  }
210 
211  return pAnchorOverlayObject;
212 }
213 
215  const basegfx::B2DPoint& rSecondPos,
216  const basegfx::B2DPoint& rThirdPos,
217  const basegfx::B2DPoint& rFourthPos,
218  const basegfx::B2DPoint& rFifthPos,
219  const basegfx::B2DPoint& rSixthPos,
220  const basegfx::B2DPoint& rSeventhPos,
221  const Color& rBaseColor)
222  : OverlayObjectWithBasePosition(rBasePos, rBaseColor)
223  , maSecondPosition(rSecondPos)
224  , maThirdPosition(rThirdPos)
225  , maFourthPosition(rFourthPos)
226  , maFifthPosition(rFifthPos)
227  , maSixthPosition(rSixthPos)
228  , maSeventhPosition(rSeventhPos)
229  , maTriangle()
230  , maLine()
231  , maLineTop()
232  , mAnchorState(AnchorState::All)
233  , mbLineSolid(false)
234 {
235 }
236 
238 {
239  if ( getOverlayManager() )
240  {
241  // remove this object from the chain
242  getOverlayManager()->remove(*this);
243  }
244 }
245 
247 {
248  if(!maTriangle.count())
249  {
253  maTriangle.setClosed(true);
254  }
255 
256  if(!maLine.count())
257  {
261  }
262 
263  if(!maLineTop.count())
264  {
267  }
268 }
269 
271 {
272  maTriangle.clear();
273  maLine.clear();
274  maLineTop.clear();
275 }
276 
278 {
280 
281  static const double aDiscreteLineWidth(1.6);
283  new AnchorPrimitive( maTriangle,
284  maLine,
285  maLineTop,
286  GetAnchorState(),
287  getBaseColor().getBColor(),
288  ANCHORLINE_WIDTH * aDiscreteLineWidth,
289  getLineSolid()) );
290 
292 }
293 
295  const basegfx::B2DPoint& rPoint2,
296  const basegfx::B2DPoint& rPoint3,
297  const basegfx::B2DPoint& rPoint4,
298  const basegfx::B2DPoint& rPoint5,
299  const basegfx::B2DPoint& rPoint6,
300  const basegfx::B2DPoint& rPoint7)
301 {
302  if ( !(rPoint1 != getBasePosition() ||
303  rPoint2 != GetSecondPosition() ||
304  rPoint3 != GetThirdPosition() ||
305  rPoint4 != GetFourthPosition() ||
306  rPoint5 != GetFifthPosition() ||
307  rPoint6 != GetSixthPosition() ||
308  rPoint7 != GetSeventhPosition()) )
309  return;
310 
311  maBasePosition = rPoint1;
312  maSecondPosition = rPoint2;
313  maThirdPosition = rPoint3;
314  maFourthPosition = rPoint4;
315  maFifthPosition = rPoint5;
316  maSixthPosition = rPoint6;
317  maSeventhPosition = rPoint7;
318 
320  objectChange();
321 }
322 
324 {
325  if(rNew != maSixthPosition)
326  {
327  maSixthPosition = rNew;
329  objectChange();
330  }
331 }
332 
334 {
335  if(rNew != maSeventhPosition)
336  {
337  maSeventhPosition = rNew;
339  objectChange();
340  }
341 }
342 
344  const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
345 {
346  if(rPoint1 != getBasePosition()
347  || rPoint2 != GetSecondPosition()
348  || rPoint3 != GetThirdPosition()
349  || rPoint4 != GetFourthPosition()
350  || rPoint5 != GetFifthPosition())
351  {
352  maBasePosition = rPoint1;
353  maSecondPosition = rPoint2;
354  maThirdPosition = rPoint3;
355  maFourthPosition = rPoint4;
356  maFifthPosition = rPoint5;
357 
359  objectChange();
360  }
361 }
362 
363 void AnchorOverlayObject::setLineSolid( const bool bNew )
364 {
365  if ( bNew != getLineSolid() )
366  {
367  mbLineSolid = bNew;
368  objectChange();
369  }
370 }
371 
373 {
374  if ( mAnchorState != aState)
375  {
376  mAnchorState = aState;
377  objectChange();
378  }
379 }
380 
381 } // end of namespace sw::sidebarwindows
382 
383 /* 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
long Long
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