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