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
22
23#include <swrect.hxx>
24#include <utility>
25#include <view.hxx>
27#include <svx/svdview.hxx>
29#include <tools/long.hxx>
30
37
39
40namespace {
41
42// helper class: Primitive for discrete visualisation
44{
45private:
51
52 // discrete line width
54
55 bool mbLineSolid : 1;
56
57protected:
58 virtual void create2DDecomposition(
60 const drawinglayer::geometry::ViewInformation2D& rViewInformation) const override;
61
62public:
63 AnchorPrimitive( basegfx::B2DPolygon aTriangle,
65 basegfx::B2DPolygon aLineTop,
66 AnchorState aAnchorState,
67 const basegfx::BColor& rColor,
68 double fDiscreteLineWidth,
69 bool bLineSolid )
70 : maTriangle(std::move(aTriangle)),
71 maLine(std::move(aLine)),
72 maLineTop(std::move(aLineTop)),
73 maAnchorState(aAnchorState),
74 maColor(rColor),
75 mfDiscreteLineWidth(fDiscreteLineWidth),
76 mbLineSolid(bLineSolid)
77 {}
78
79 // data access
80 const basegfx::B2DPolygon& getLine() const { return maLine; }
81 const basegfx::BColor& getColor() const { return maColor; }
82 bool getLineSolid() const { return mbLineSolid; }
83
84 virtual bool operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const override;
85
86 virtual sal_uInt32 getPrimitive2DID() const override;
87};
88
89}
90
91void AnchorPrimitive::create2DDecomposition(
93 const drawinglayer::geometry::ViewInformation2D& /*rViewInformation*/) const
94{
97 {
98 // create triangle
102 getColor()));
103
104 rContainer.push_back(aTriangle);
105 }
106
107 // prepare view-independent LineWidth and color
108 const drawinglayer::attribute::LineAttribute aLineAttribute(
109 getColor(),
110 mfDiscreteLineWidth * getDiscreteUnit());
111
113 {
114 // create line start
115 if(getLineSolid())
116 {
119 getLine(),
120 aLineAttribute));
121
122 rContainer.push_back(aSolidLine);
123 }
124 else
125 {
126 std::vector< double > aDotDashArray;
127 const double fDistance(3.0 * 15.0);
128 const double fDashLen(5.0 * 15.0);
129
130 aDotDashArray.push_back(fDashLen);
131 aDotDashArray.push_back(fDistance);
132
134 std::move(aDotDashArray),
135 fDistance + fDashLen);
136
139 getLine(),
140 aLineAttribute,
141 std::move(aStrokeAttribute)));
142
143 rContainer.push_back(aStrokedLine);
144 }
145 }
146
149 {
150 // LineTop has to be created, too, but uses no shadow, so add after
151 // the other parts are created
154 maLineTop,
155 aLineAttribute));
156
157 rContainer.push_back(aLineTop);
158 }
159}
160
161bool AnchorPrimitive::operator==( const drawinglayer::primitive2d::BasePrimitive2D& rPrimitive ) const
162{
163 if(drawinglayer::primitive2d::DiscreteMetricDependentPrimitive2D::operator==(rPrimitive))
164 {
165 const AnchorPrimitive& rCompare = static_cast< const AnchorPrimitive& >(rPrimitive);
166
167 return (maTriangle == rCompare.maTriangle
168 && getLine() == rCompare.getLine()
169 && maLineTop == rCompare.maLineTop
170 && maAnchorState == rCompare.maAnchorState
171 && getColor() == rCompare.getColor()
172 && mfDiscreteLineWidth == rCompare.mfDiscreteLineWidth
173 && getLineSolid() == rCompare.getLineSolid());
174 }
175
176 return false;
177}
178
179sal_uInt32 AnchorPrimitive::getPrimitive2DID() const
180{
182}
183
184/*static*/ std::unique_ptr<AnchorOverlayObject> AnchorOverlayObject::CreateAnchorOverlayObject(
185 SwView const & rDocView,
186 const SwRect& aAnchorRect,
187 tools::Long aPageBorder,
188 const Point& aLineStart,
189 const Point& aLineEnd,
190 const Color& aColorAnchor )
191{
192 std::unique_ptr<AnchorOverlayObject> pAnchorOverlayObject;
193 if ( rDocView.GetDrawView() )
194 {
195 SdrPaintWindow* pPaintWindow = rDocView.GetDrawView()->GetPaintWindow(0);
196 if( pPaintWindow )
197 {
198 const rtl::Reference< sdr::overlay::OverlayManager >& xOverlayManager = pPaintWindow->GetOverlayManager();
199
200 if ( xOverlayManager.is() )
201 {
202 pAnchorOverlayObject.reset(new AnchorOverlayObject(
203 basegfx::B2DPoint( aAnchorRect.Left() , aAnchorRect.Bottom()-5*15),
204 basegfx::B2DPoint( aAnchorRect.Left()-5*15 , aAnchorRect.Bottom()+5*15),
205 basegfx::B2DPoint( aAnchorRect.Left()+5*15 , aAnchorRect.Bottom()+5*15),
206 basegfx::B2DPoint( aAnchorRect.Left(), aAnchorRect.Bottom()+2*15),
207 basegfx::B2DPoint( aPageBorder ,aAnchorRect.Bottom()+2*15),
208 basegfx::B2DPoint( aLineStart.X(),aLineStart.Y()),
209 basegfx::B2DPoint( aLineEnd.X(),aLineEnd.Y()) ,
210 aColorAnchor));
211 xOverlayManager->add(*pAnchorOverlayObject);
212 }
213 }
214 }
215
216 return pAnchorOverlayObject;
217}
218
220 const basegfx::B2DPoint& rSecondPos,
221 const basegfx::B2DPoint& rThirdPos,
222 const basegfx::B2DPoint& rFourthPos,
223 const basegfx::B2DPoint& rFifthPos,
224 const basegfx::B2DPoint& rSixthPos,
225 const basegfx::B2DPoint& rSeventhPos,
226 const Color& rBaseColor)
227 : OverlayObjectWithBasePosition(rBasePos, rBaseColor)
228 , maSecondPosition(rSecondPos)
229 , maThirdPosition(rThirdPos)
230 , maFourthPosition(rFourthPos)
231 , maFifthPosition(rFifthPos)
232 , maSixthPosition(rSixthPos)
233 , maSeventhPosition(rSeventhPos)
234 , mAnchorState(AnchorState::All)
235 , mbLineSolid(false)
236{
237}
238
240{
241 if ( getOverlayManager() )
242 {
243 // remove this object from the chain
244 getOverlayManager()->remove(*this);
245 }
246}
247
249{
250 if(!maTriangle.count())
251 {
255 maTriangle.setClosed(true);
256 }
257
258 if(!maLine.count())
259 {
263 }
264
265 if(!maLineTop.count())
266 {
269 }
270}
271
273{
275 maLine.clear();
277}
278
280{
282
283 static const double aDiscreteLineWidth(1.6);
285 new AnchorPrimitive( maTriangle,
286 maLine,
287 maLineTop,
289 getBaseColor().getBColor(),
290 ANCHORLINE_WIDTH * aDiscreteLineWidth,
291 getLineSolid()) );
292
294}
295
297 const basegfx::B2DPoint& rPoint2,
298 const basegfx::B2DPoint& rPoint3,
299 const basegfx::B2DPoint& rPoint4,
300 const basegfx::B2DPoint& rPoint5,
301 const basegfx::B2DPoint& rPoint6,
302 const basegfx::B2DPoint& rPoint7)
303{
304 if ( !(rPoint1 != getBasePosition() ||
305 rPoint2 != GetSecondPosition() ||
306 rPoint3 != GetThirdPosition() ||
307 rPoint4 != GetFourthPosition() ||
308 rPoint5 != GetFifthPosition() ||
309 rPoint6 != GetSixthPosition() ||
310 rPoint7 != GetSeventhPosition()) )
311 return;
312
313 maBasePosition = rPoint1;
314 maSecondPosition = rPoint2;
315 maThirdPosition = rPoint3;
316 maFourthPosition = rPoint4;
317 maFifthPosition = rPoint5;
318 maSixthPosition = rPoint6;
319 maSeventhPosition = rPoint7;
320
322 objectChange();
323}
324
326{
327 if(rNew != maSixthPosition)
328 {
329 maSixthPosition = rNew;
331 objectChange();
332 }
333}
334
336{
337 if(rNew != maSeventhPosition)
338 {
339 maSeventhPosition = rNew;
341 objectChange();
342 }
343}
344
346 const basegfx::B2DPoint& rPoint4,const basegfx::B2DPoint& rPoint5)
347{
348 if(rPoint1 != getBasePosition()
349 || rPoint2 != GetSecondPosition()
350 || rPoint3 != GetThirdPosition()
351 || rPoint4 != GetFourthPosition()
352 || rPoint5 != GetFifthPosition())
353 {
354 maBasePosition = rPoint1;
355 maSecondPosition = rPoint2;
356 maThirdPosition = rPoint3;
357 maFourthPosition = rPoint4;
358 maFifthPosition = rPoint5;
359
361 objectChange();
362 }
363}
364
366{
367 if ( bNew != getLineSolid() )
368 {
369 mbLineSolid = bNew;
370 objectChange();
371 }
372}
373
375{
376 if ( mAnchorState != aState)
377 {
378 mAnchorState = aState;
379 objectChange();
380 }
381}
382
383} // end of namespace sw::sidebarwindows
384
385/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
basegfx::B2DPolygon maLineTop
basegfx::B2DPolygon maLine
basegfx::B2DPolygon maTriangle
const AnchorState maAnchorState
basegfx::BColor maColor
double mfDiscreteLineWidth
bool mbLineSolid
basegfx::B2DPoint maSecondPosition
constexpr tools::Long Y() const
constexpr tools::Long X() const
SdrPaintWindow * GetPaintWindow(sal_uInt32 nIndex) const
rtl::Reference< sdr::overlay::OverlayManager > const & GetOverlayManager() const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
Definition: view.hxx:146
virtual SdrView * GetDrawView() const override
Definition: viewdraw.cxx:621
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
sal_uInt32 count() const
void setClosed(bool bNew)
void remove(OverlayObject &rOverlayObject)
const basegfx::B2DPoint & getBasePosition() const
const Color & getBaseColor() const
OverlayManager * getOverlayManager() const
const basegfx::B2DPoint & GetSecondPosition() const
const basegfx::B2DPoint & GetSixthPosition() const
const basegfx::B2DPoint & GetThirdPosition() const
const basegfx::B2DPoint & GetSeventhPosition() const
const basegfx::B2DPoint & GetFifthPosition() const
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)
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)
virtual drawinglayer::primitive2d::Primitive2DContainer createOverlayObjectPrimitive2DSequence() override
void SetSixthPosition(const basegfx::B2DPoint &rNew)
const basegfx::B2DPoint & GetFourthPosition() const
void SetTriPosition(const basegfx::B2DPoint &rPoint1, const basegfx::B2DPoint &rPoint2, const basegfx::B2DPoint &rPoint3, const basegfx::B2DPoint &rPoint4, const basegfx::B2DPoint &rPoint5)
void SetSeventhPosition(const basegfx::B2DPoint &rNew)
static std::unique_ptr< AnchorOverlayObject > CreateAnchorOverlayObject(SwView const &rDocView, const SwRect &aAnchorRect, tools::Long aPageBorder, const Point &aLineStart, const Point &aLineEnd, const Color &aColorAnchor)
void SetAnchorState(const AnchorState aState)
const sal_Int8 ANCHORLINE_WIDTH
long Long
#define PRIMITIVE2D_ID_SWSIDEBARANCHORPRIMITIVE
bool operator==(const XclFontData &rLeft, const XclFontData &rRight)