LibreOffice Module sw (master) 1
swrect.hxx
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#pragma once
20
21#include <ostream>
22
23#include <sal/log.hxx>
24#include <tools/gen.hxx>
25#include "swdllapi.h"
26
27class SvStream;
28typedef struct _xmlTextWriter* xmlTextWriterPtr;
29
35{
38
39public:
40 inline SwRect();
41 inline SwRect( const SwRect &rRect ) = default;
42 inline SwRect( const Point& rLT, const Size& rSize );
43 inline SwRect( const Point& rLT, const Point& rRB );
44 inline SwRect( tools::Long X, tools::Long Y, tools::Long Width, tools::Long Height );
45
46 //SV-SS e.g. SwRect( pWin->GetClipRect() );
47 explicit SwRect( const tools::Rectangle &rRect );
48
49 //Set-Methods
50 inline void Chg( const Point& rNP, const Size &rNS );
51 inline void Pos( const Point& rNew );
52 inline void Pos( const tools::Long nNewX, const tools::Long nNewY );
53 inline void SSize( const Size& rNew );
54 inline void SSize( const tools::Long nHeight, const tools::Long nWidth );
55 inline void Width( tools::Long nNew );
56 inline void Height( tools::Long nNew );
57 inline void Left( const tools::Long nLeft );
58 inline void Right( const tools::Long nRight );
59 inline void Top( const tools::Long nTop );
60 inline void Bottom( const tools::Long nBottom );
61
62 //Get-Methods
63 inline const Point &Pos() const;
64 inline const Size &SSize() const;
65 inline tools::Long Width() const;
66 inline tools::Long Height() const;
67 inline tools::Long Left() const;
68 inline tools::Long Right() const;
69 inline tools::Long Top() const;
70 inline tools::Long Bottom() const;
71
72 // In order to be able to access the members of Pos and SSize from the layout side.
73 inline Point &Pos();
74
75 Point Center() const;
76
77 void Justify();
78
79 SwRect &Union( const SwRect& rRect );
80 SwRect &Intersection( const SwRect& rRect );
81
82 SwRect GetUnion( const SwRect& rRect ) const;
83 SwRect GetIntersection( const SwRect& rRect ) const;
84
85 // Same as Intersection, only assume that Rects are overlapping!
86 SwRect &Intersection_( const SwRect &rRect );
87
88 bool Contains( const Point& rPOINT ) const;
89 bool Contains( const SwRect& rRect ) const;
90 bool Overlaps( const SwRect& rRect ) const;
91 bool IsNear(const Point& rPoint, tools::Long nTolerance ) const;
92 inline bool HasArea() const;
93 inline bool IsEmpty() const;
94 inline void Clear();
95
96 SwRect &operator = ( const SwRect &rRect ) = default;
97
98 inline bool operator == ( const SwRect& rRect ) const;
99 inline bool operator != ( const SwRect& rRect ) const;
100
101 inline SwRect &operator+=( const Point &rPt );
102 inline SwRect &operator-=( const Point &rPt );
103
104 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
105 inline tools::Rectangle SVRect() const;
106
107 // Output operator for debugging.
108 friend SvStream& WriteSwRect( SvStream &rStream, const SwRect &rRect );
109 void dumpAsXmlAttributes(xmlTextWriterPtr writer) const;
110
111 void Top_( const tools::Long nTop );
112 void Bottom_( const tools::Long nBottom );
113 void Left_( const tools::Long nLeft );
114 void Right_( const tools::Long nRight );
115 void Width_( const tools::Long nNew );
116 void Height_( const tools::Long nNew );
117 tools::Long Top_() const;
118 tools::Long Bottom_() const;
119 tools::Long Left_() const;
120 tools::Long Right_() const;
121 tools::Long Width_() const;
122 tools::Long Height_() const;
123 void SubTop( const tools::Long nSub );
124 void AddTop( const tools::Long nAdd );
125 void AddBottom( const tools::Long nAdd );
126 void AddLeft( const tools::Long nAdd );
127 void SubLeft( const tools::Long nSub );
128 void AddRight( const tools::Long nAdd );
129 void AddWidth( const tools::Long nAdd );
130 void AddHeight( const tools::Long nAdd );
131 void SetPosX( const tools::Long nNew );
132 void SetPosY( const tools::Long nNew );
133 void SetLeftAndWidth( tools::Long nLeft, tools::Long nNew );
134 void SetTopAndHeight( tools::Long nTop, tools::Long nNew );
135 void SetRightAndWidth( tools::Long nRight, tools::Long nNew );
136 void SetBottomAndHeight( tools::Long nBottom, tools::Long nNew );
137 void SetUpperLeftCorner( const Point& rNew );
138 void SetUpperRightCorner( const Point& rNew );
139 void SetLowerLeftCorner( const Point& rNew );
140 Size Size_() const;
141 Point TopLeft() const;
142 Point TopRight() const;
143 Point BottomLeft() const;
144 Point BottomRight() const;
145 Size SwappedSize() const;
146 tools::Long GetLeftDistance( tools::Long ) const;
147 tools::Long GetBottomDistance( tools::Long ) const;
148 tools::Long GetRightDistance( tools::Long ) const;
149 tools::Long GetTopDistance( tools::Long ) const;
150 bool OverStepLeft( tools::Long ) const;
151 bool OverStepBottom( tools::Long ) const;
152 bool OverStepTop( tools::Long ) const;
153 bool OverStepRight( tools::Long ) const;
154};
155
156typedef void (SwRect::*SwRectSet)( const tools::Long nNew );
157typedef tools::Long (SwRect::*SwRectGet)() const;
158typedef Point (SwRect::*SwRectPoint)() const;
159typedef Size (SwRect::*SwRectSize)() const;
160typedef bool (SwRect::*SwRectMax)( tools::Long ) const;
163typedef void (SwRect::*SwRectSetPos)( const Point& );
164
165// Set-Methods
166inline void SwRect::Chg( const Point& rNP, const Size &rNS )
167{
168 m_Point = rNP;
169 m_Size = rNS;
170}
171inline void SwRect::Pos( const Point& rNew )
172{
173 m_Point = rNew;
174}
175inline void SwRect::Pos( const tools::Long nNewX, const tools::Long nNewY )
176{
177 m_Point.setX(nNewX);
178 m_Point.setY(nNewY);
179}
180inline void SwRect::SSize( const Size& rNew )
181{
182 m_Size = rNew;
183}
184inline void SwRect::SSize( const tools::Long nNewHeight, const tools::Long nNewWidth )
185{
186 m_Size.setWidth(nNewWidth);
187 m_Size.setHeight(nNewHeight);
188}
189inline void SwRect::Width( tools::Long nNew )
190{
191 m_Size.setWidth(nNew);
192}
193inline void SwRect::Height( tools::Long nNew )
194{
195 m_Size.setHeight(nNew);
196}
197inline void SwRect::Left( const tools::Long nLeft )
198{
199 m_Size.AdjustWidth( m_Point.getX() - nLeft );
200 m_Point.setX(nLeft);
201}
202inline void SwRect::Right( const tools::Long nRight )
203{
204 m_Size.setWidth(nRight - m_Point.getX() + 1);
205}
206inline void SwRect::Top( const tools::Long nTop )
207{
208 m_Size.AdjustHeight( m_Point.getY() - nTop );
209 m_Point.setY(nTop);
210}
211inline void SwRect::Bottom( const tools::Long nBottom )
212{
213 m_Size.setHeight(nBottom - m_Point.getY() + 1);
214}
215
216// Get-Methods
217inline const Point &SwRect::Pos() const
218{
219 return m_Point;
220}
222{
223 return m_Point;
224}
225inline const Size &SwRect::SSize() const
226{
227 return m_Size;
228}
230{
231 return m_Size.Width();
232}
234{
235 return m_Size.Height();
236}
238{
239 return m_Point.X();
240}
242{
243 return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
244}
246{
247 return m_Point.Y();
248}
250{
251 return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
252}
253
254inline Point SwRect::TopLeft() const
255{
256 return Point( Left(), Top());
257}
259{
260 return Point( Right(), Top());
261}
263{
264 return Point( Left(), Bottom());
265}
267{
268 return Point( Right(), Bottom());
269}
270
271inline bool SwRect::operator == ( const SwRect& rRect ) const
272{
273 return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
274}
275inline bool SwRect::operator != ( const SwRect& rRect ) const
276{
277 return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
278}
279
280inline SwRect &SwRect::operator+=( const Point &rPt )
281{
282 m_Point += rPt;
283 return *this;
284}
285inline SwRect &SwRect::operator-=( const Point &rPt )
286{
287 m_Point -= rPt;
288 return *this;
289}
290
291// other
293{
294 SAL_INFO_IF( IsEmpty(), "sw.core", "SVRect() without Width or Height" );
295 return tools::Rectangle( m_Point.getX(), m_Point.getY(),
296 m_Point.getX() + m_Size.getWidth() - 1, //Right()
297 m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
298}
299
300inline bool SwRect::HasArea() const
301{
302 return !IsEmpty();
303}
304inline bool SwRect::IsEmpty() const
305{
306 return !(m_Size.getHeight() && m_Size.getWidth());
307}
308inline void SwRect::Clear()
309{
310 m_Point.setX(0);
311 m_Point.setY(0);
312 m_Size.setWidth(0);
313 m_Size.setHeight(0);
314}
315
316// constructors
318 m_Point( 0, 0 ),
319 m_Size( 0, 0 )
320{
321}
322inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
323 m_Point( rLT ),
324 m_Size( rSize )
325{
326}
327inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
328 m_Point( rLT ),
329 m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
330{
331}
333 m_Point( X, Y ),
334 m_Size( W, H )
335{
336}
337
338inline Point SwRect::Center() const
339{
340 return Point( Left() + Width() / 2,
341 Top() + Height() / 2 );
342}
343
344inline bool SwRect::Contains( const SwRect& rRect ) const
345{
346 const tools::Long nRight = Right();
347 const tools::Long nBottom = Bottom();
348 const tools::Long nrRight = rRect.Right();
349 const tools::Long nrBottom= rRect.Bottom();
350 return (Left() <= rRect.Left()) && (rRect.Left()<= nRight) &&
351 (Left() <= nrRight) && (nrRight <= nRight) &&
352 (Top() <= rRect.Top()) && (rRect.Top() <= nBottom) &&
353 (Top() <= nrBottom) && (nrBottom <= nBottom);
354}
355
356inline bool SwRect::Contains( const Point& rPoint ) const
357{
358 return (Left() <= rPoint.X()) &&
359 (Top() <= rPoint.Y()) &&
360 (Right() >= rPoint.X()) &&
361 (Bottom()>= rPoint.Y());
362}
363
364// mouse moving of table borders
365inline bool SwRect::IsNear( const Point& rPoint, tools::Long nTolerance ) const
366{
367 bool bIsNearby = (((Left() - nTolerance) <= rPoint.X()) &&
368 ((Top() - nTolerance) <= rPoint.Y()) &&
369 ((Right() + nTolerance) >= rPoint.X()) &&
370 ((Bottom() + nTolerance) >= rPoint.Y()));
371 return Contains(rPoint) || bIsNearby;
372}
373
374inline bool SwRect::Overlaps( const SwRect& rRect ) const
375{
376 return (Top() <= rRect.Bottom()) &&
377 (Left() <= rRect.Right()) &&
378 (Right() >= rRect.Left()) &&
379 (Bottom()>= rRect.Top());
380}
381
382inline SwRect SwRect::GetUnion( const SwRect& rRect ) const
383{
384 return IsEmpty() ? rRect : rRect.IsEmpty() ? *this : SwRect(
385 Point( std::min( Left(), rRect.Left()),
386 std::min( Top(), rRect.Top())),
387 Point( std::max( Right(), rRect.Right()),
388 std::max( Bottom(), rRect.Bottom())));
389}
390
391inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
392{
393 return Overlaps( rRect )
394 ? SwRect(
395 Point( std::max( Left(), rRect.Left()),
396 std::max( Top(), rRect.Top())),
397 Point( std::min( Right(), rRect.Right()),
398 std::min( Bottom(), rRect.Bottom())))
399 : SwRect();
400}
401
402
403template< typename charT, typename traits >
404inline std::basic_ostream<charT, traits> & operator <<(
405 std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
406{
407 if (rectangle.IsEmpty())
408 stream << "EMPTY:";
409 return stream << rectangle.SSize()
410 << "@(" << rectangle.Pos() << ")";
411}
412
413/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
geometry::RealSize2D m_Size
struct _xmlTextWriter * xmlTextWriterPtr
constexpr tools::Long getHeight() const
constexpr tools::Long Height() const
tools::Long AdjustHeight(tools::Long n)
constexpr tools::Long getWidth() const
void setWidth(tools::Long nWidth)
tools::Long AdjustWidth(tools::Long n)
void setHeight(tools::Long nHeight)
constexpr tools::Long Width() const
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
tools::Long Bottom() const
Definition: swrect.hxx:249
SwRect & operator-=(const Point &rPt)
Definition: swrect.hxx:285
void Chg(const Point &rNP, const Size &rNS)
Definition: swrect.hxx:166
tools::Long Right() const
Definition: swrect.hxx:241
Point m_Point
Definition: swrect.hxx:36
bool IsEmpty() const
Definition: swrect.hxx:304
bool HasArea() const
Definition: swrect.hxx:300
Point TopLeft() const
Definition: swrect.hxx:254
void Top(const tools::Long nTop)
Definition: swrect.hxx:206
bool operator==(const SwRect &rRect) const
Definition: swrect.hxx:271
Point BottomLeft() const
Definition: swrect.hxx:262
void Right(const tools::Long nRight)
Definition: swrect.hxx:202
void Clear()
Definition: swrect.hxx:308
void Bottom(const tools::Long nBottom)
Definition: swrect.hxx:211
SwRect GetUnion(const SwRect &rRect) const
Definition: swrect.hxx:382
const Point & Pos() const
Definition: swrect.hxx:217
bool IsNear(const Point &rPoint, tools::Long nTolerance) const
Definition: swrect.hxx:365
SwRect GetIntersection(const SwRect &rRect) const
Definition: swrect.hxx:391
const Size & SSize() const
Definition: swrect.hxx:225
bool Contains(const Point &rPOINT) const
Definition: swrect.hxx:356
Point Center() const
Definition: swrect.hxx:338
bool Overlaps(const SwRect &rRect) const
Definition: swrect.hxx:374
Point BottomRight() const
Definition: swrect.hxx:266
tools::Long Left() const
Definition: swrect.hxx:237
tools::Long Width() const
Definition: swrect.hxx:229
SwRect(const SwRect &rRect)=default
Size m_Size
Definition: swrect.hxx:37
tools::Rectangle SVRect() const
Definition: swrect.hxx:292
void Left(const tools::Long nLeft)
Definition: swrect.hxx:197
tools::Long Height() const
Definition: swrect.hxx:233
SwRect & operator+=(const Point &rPt)
Definition: swrect.hxx:280
bool operator!=(const SwRect &rRect) const
Definition: swrect.hxx:275
SwRect()
Definition: swrect.hxx:317
Point TopRight() const
Definition: swrect.hxx:258
tools::Long Top() const
Definition: swrect.hxx:245
Reference< XOutputStream > stream
#define SAL_INFO_IF(condition, area, stream)
def rectangle(l)
long Long
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
#define Y
timeval & operator-=(timeval &t1, const timeval &t2)
TOOLS_DLLPUBLIC tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
SvStream & WriteSwRect(SvStream &rStream, const SwRect &rRect)
Definition: swrect.cxx:189
tools::Long(SwRect::* SwRectDist)(tools::Long) const
Definition: swrect.hxx:161
tools::Long(SwRect::* SwRectGet)() const
Definition: swrect.hxx:157
struct _xmlTextWriter * xmlTextWriterPtr
Definition: swrect.hxx:28
bool(SwRect::* SwRectMax)(tools::Long) const
Definition: swrect.hxx:160
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const SwRect &rectangle)
Definition: swrect.hxx:404
Point(SwRect::* SwRectPoint)() const
Definition: swrect.hxx:158
void(SwRect::* SwRectSetTwice)(tools::Long, tools::Long)
Definition: swrect.hxx:162
void(SwRect::* SwRectSetPos)(const Point &)
Definition: swrect.hxx:163
Size(SwRect::* SwRectSize)() const
Definition: swrect.hxx:159
void(SwRect::* SwRectSet)(const tools::Long nNew)
Definition: swrect.hxx:156
Left
Center
Right
#define SAL_WARN_UNUSED