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