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 
27 class SvStream;
28 typedef struct _xmlTextWriter* xmlTextWriterPtr;
29 
35 {
38 
39 public:
40  inline SwRect();
41  inline SwRect( const SwRect &rRect );
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  // Same as Intersection, only assume that Rects are overlapping!
83  SwRect &Intersection_( const SwRect &rRect );
84 
85  bool IsInside( const Point& rPOINT ) const;
86  bool IsNear(const Point& rPoint, tools::Long nTolerance ) const;
87  bool IsInside( const SwRect& rRect ) const;
88  bool IsOver( const SwRect& rRect ) const;
89  inline bool HasArea() const;
90  inline bool IsEmpty() const;
91  inline void Clear();
92 
93  inline SwRect &operator = ( const SwRect &rRect );
94 
95  inline bool operator == ( const SwRect& rRect ) const;
96  inline bool operator != ( const SwRect& rRect ) const;
97 
98  inline SwRect &operator+=( const Point &rPt );
99  inline SwRect &operator-=( const Point &rPt );
100 
101  //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
102  inline tools::Rectangle SVRect() const;
103 
104  // Output operator for debugging.
105  friend SvStream& WriteSwRect( SvStream &rStream, const SwRect &rRect );
106  void dumpAsXmlAttributes(xmlTextWriterPtr writer) const;
107 
108  void Top_( const tools::Long nTop );
109  void Bottom_( const tools::Long nBottom );
110  void Left_( const tools::Long nLeft );
111  void Right_( const tools::Long nRight );
112  void Width_( const tools::Long nNew );
113  void Height_( const tools::Long nNew );
114  tools::Long Top_() const;
115  tools::Long Bottom_() const;
116  tools::Long Left_() const;
117  tools::Long Right_() const;
118  tools::Long Width_() const;
119  tools::Long Height_() const;
120  void SubTop( const tools::Long nSub );
121  void AddTop( const tools::Long nAdd );
122  void AddBottom( const tools::Long nAdd );
123  void AddLeft( const tools::Long nAdd );
124  void SubLeft( const tools::Long nSub );
125  void AddRight( const tools::Long nAdd );
126  void AddWidth( const tools::Long nAdd );
127  void AddHeight( const tools::Long nAdd );
128  void SetPosX( const tools::Long nNew );
129  void SetPosY( const tools::Long nNew );
130  void SetLeftAndWidth( tools::Long nLeft, tools::Long nNew );
131  void SetTopAndHeight( tools::Long nTop, tools::Long nNew );
132  void SetRightAndWidth( tools::Long nRight, tools::Long nNew );
133  void SetBottomAndHeight( tools::Long nBottom, tools::Long nNew );
134  void SetUpperLeftCorner( const Point& rNew );
135  void SetUpperRightCorner( const Point& rNew );
136  void SetLowerLeftCorner( const Point& rNew );
137  Size Size_() const;
138  Point TopLeft() const;
139  Point TopRight() const;
140  Point BottomLeft() const;
141  Point BottomRight() const;
142  Size SwappedSize() const;
143  tools::Long GetLeftDistance( tools::Long ) const;
144  tools::Long GetBottomDistance( tools::Long ) const;
145  tools::Long GetRightDistance( tools::Long ) const;
146  tools::Long GetTopDistance( tools::Long ) const;
147  bool OverStepLeft( tools::Long ) const;
148  bool OverStepBottom( tools::Long ) const;
149  bool OverStepTop( tools::Long ) const;
150  bool OverStepRight( tools::Long ) const;
151 };
152 
153 typedef void (SwRect::*SwRectSet)( const tools::Long nNew );
154 typedef tools::Long (SwRect::*SwRectGet)() const;
155 typedef Point (SwRect::*SwRectPoint)() const;
156 typedef Size (SwRect::*SwRectSize)() const;
157 typedef bool (SwRect::*SwRectMax)( tools::Long ) const;
160 typedef void (SwRect::*SwRectSetPos)( const Point& );
161 
162 // Set-Methods
163 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
164 {
165  m_Point = rNP;
166  m_Size = rNS;
167 }
168 inline void SwRect::Pos( const Point& rNew )
169 {
170  m_Point = rNew;
171 }
172 inline void SwRect::Pos( const tools::Long nNewX, const tools::Long nNewY )
173 {
174  m_Point.setX(nNewX);
175  m_Point.setY(nNewY);
176 }
177 inline void SwRect::SSize( const Size& rNew )
178 {
179  m_Size = rNew;
180 }
181 inline void SwRect::SSize( const tools::Long nNewHeight, const tools::Long nNewWidth )
182 {
183  m_Size.setWidth(nNewWidth);
184  m_Size.setHeight(nNewHeight);
185 }
186 inline void SwRect::Width( tools::Long nNew )
187 {
188  m_Size.setWidth(nNew);
189 }
190 inline void SwRect::Height( tools::Long nNew )
191 {
192  m_Size.setHeight(nNew);
193 }
194 inline void SwRect::Left( const tools::Long nLeft )
195 {
196  m_Size.AdjustWidth( m_Point.getX() - nLeft );
197  m_Point.setX(nLeft);
198 }
199 inline void SwRect::Right( const tools::Long nRight )
200 {
201  m_Size.setWidth(nRight - m_Point.getX() + 1);
202 }
203 inline void SwRect::Top( const tools::Long nTop )
204 {
205  m_Size.AdjustHeight( m_Point.getY() - nTop );
206  m_Point.setY(nTop);
207 }
208 inline void SwRect::Bottom( const tools::Long nBottom )
209 {
210  m_Size.setHeight(nBottom - m_Point.getY() + 1);
211 }
212 
213 // Get-Methods
214 inline const Point &SwRect::Pos() const
215 {
216  return m_Point;
217 }
219 {
220  return m_Point;
221 }
222 inline const Size &SwRect::SSize() const
223 {
224  return m_Size;
225 }
227 {
228  return m_Size.Width();
229 }
231 {
232  return m_Size.Height();
233 }
234 inline tools::Long SwRect::Left() const
235 {
236  return m_Point.X();
237 }
239 {
240  return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
241 }
242 inline tools::Long SwRect::Top() const
243 {
244  return m_Point.Y();
245 }
247 {
248  return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
249 }
250 
251 // operators
252 inline SwRect &SwRect::operator = ( const SwRect &rRect )
253 {
254  m_Point = rRect.m_Point;
255  m_Size = rRect.m_Size;
256  return *this;
257 }
258 inline bool SwRect::operator == ( const SwRect& rRect ) const
259 {
260  return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
261 }
262 inline bool SwRect::operator != ( const SwRect& rRect ) const
263 {
264  return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
265 }
266 
267 inline SwRect &SwRect::operator+=( const Point &rPt )
268 {
269  m_Point += rPt;
270  return *this;
271 }
272 inline SwRect &SwRect::operator-=( const Point &rPt )
273 {
274  m_Point -= rPt;
275  return *this;
276 }
277 
278 // other
280 {
281  SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
282  return tools::Rectangle( m_Point.getX(), m_Point.getY(),
283  m_Point.getX() + m_Size.getWidth() - 1, //Right()
284  m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
285 }
286 
287 inline bool SwRect::HasArea() const
288 {
289  return !IsEmpty();
290 }
291 inline bool SwRect::IsEmpty() const
292 {
293  return !(m_Size.getHeight() && m_Size.getWidth());
294 }
295 inline void SwRect::Clear()
296 {
297  m_Point.setX(0);
298  m_Point.setY(0);
299  m_Size.setWidth(0);
300  m_Size.setHeight(0);
301 }
302 
303 // constructors
304 inline SwRect::SwRect() :
305  m_Point( 0, 0 ),
306  m_Size( 0, 0 )
307 {
308 }
309 inline SwRect::SwRect( const SwRect &rRect ) :
310  m_Point( rRect.m_Point ),
311  m_Size( rRect.m_Size )
312 {
313 }
314 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
315  m_Point( rLT ),
316  m_Size( rSize )
317 {
318 }
319 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
320  m_Point( rLT ),
321  m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
322 {
323 }
325  m_Point( X, Y ),
326  m_Size( W, H )
327 {
328 }
329 
330 template< typename charT, typename traits >
331 inline std::basic_ostream<charT, traits> & operator <<(
332  std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
333 {
334  if (rectangle.IsEmpty())
335  stream << "EMPTY:";
336  return stream << rectangle.SSize()
337  << "@(" << rectangle.Pos() << ")";
338 }
339 
340 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
Size m_Size
Definition: swrect.hxx:37
bool(SwRect::* SwRectMax)(tools::Long) const
Definition: swrect.hxx:157
struct _xmlTextWriter * xmlTextWriterPtr
Definition: swrect.hxx:28
void setWidth(tools::Long nWidth)
long Long
tools::Long Right() const
Definition: swrect.hxx:238
timeval & operator-=(timeval &t1, const timeval &t2)
tools::Long Height() const
Definition: swrect.hxx:230
void Pos(const Point &rNew)
Definition: swrect.hxx:168
Of course Writer needs its own rectangles.
Definition: swrect.hxx:34
Center
constexpr tools::Long Width() const
tools::Long Bottom() const
Definition: swrect.hxx:246
tools::Long(SwRect::* SwRectDist)(tools::Long) const
Definition: swrect.hxx:158
constexpr tools::Long getHeight() const
bool IsEmpty() const
Definition: swrect.hxx:291
void(SwRect::* SwRectSet)(const tools::Long nNew)
Definition: swrect.hxx:153
struct _xmlTextWriter * xmlTextWriterPtr
Right
const Size & SSize() const
Definition: swrect.hxx:222
SwRect & operator=(const SwRect &rRect)
Definition: swrect.hxx:252
bool HasArea() const
Definition: swrect.hxx:287
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
void SSize(const Size &rNew)
Definition: swrect.hxx:177
#define Y
void(SwRect::* SwRectSetTwice)(tools::Long, tools::Long)
Definition: swrect.hxx:159
#define SAL_WARN_UNUSED
SwRect & operator+=(const Point &rPt)
Definition: swrect.hxx:267
tools::Long Left() const
Definition: swrect.hxx:234
tools::Rectangle SVRect() const
Definition: swrect.hxx:279
Point m_Point
Definition: swrect.hxx:36
tools::Long(SwRect::* SwRectGet)() const
Definition: swrect.hxx:154
#define SAL_WARN_IF(condition, area, stream)
constexpr tools::Long Height() const
tools::Long Top() const
Definition: swrect.hxx:242
tools::Long AdjustWidth(tools::Long n)
geometry::RealSize2D m_Size
tools::Rectangle & operator+=(tools::Rectangle &rRect, const SvBorder &rBorder)
tools::Long AdjustHeight(tools::Long n)
std::basic_ostream< charT, traits > & operator<<(std::basic_ostream< charT, traits > &stream, const SwRect &rectangle)
Definition: swrect.hxx:331
Size(SwRect::* SwRectSize)() const
Definition: swrect.hxx:156
void setHeight(tools::Long nHeight)
constexpr tools::Long getWidth() const
void Clear()
Definition: swrect.hxx:295
Left
bool operator!=(const SwRect &rRect) const
Definition: swrect.hxx:262
SwRect & operator-=(const Point &rPt)
Definition: swrect.hxx:272
Point(SwRect::* SwRectPoint)() const
Definition: swrect.hxx:155
void Chg(const Point &rNP, const Size &rNS)
Definition: swrect.hxx:163
tools::Long Width() const
Definition: swrect.hxx:226
const Point & Pos() const
Definition: swrect.hxx:214
void(SwRect::* SwRectSetPos)(const Point &)
Definition: swrect.hxx:160
bool operator==(const SwRect &rRect) const
Definition: swrect.hxx:258
SwRect()
Definition: swrect.hxx:304
SvStream & WriteSwRect(SvStream &rStream, const SwRect &rRect)
Definition: swrect.cxx:232
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo