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 typedef struct _xmlTextWriter* xmlTextWriterPtr;
30 
36 {
39 
40 public:
41  inline SwRect();
42  inline SwRect( const SwRect &rRect );
43  inline SwRect( const Point& rLT, const Size& rSize );
44  inline SwRect( const Point& rLT, const Point& rRB );
45  inline SwRect( long X, long Y, long Width, long Height );
46 
47  //SV-SS e.g. SwRect( pWin->GetClipRect() );
48  SwRect( const tools::Rectangle &rRect );
49 
50  //Set-Methods
51  inline void Chg( const Point& rNP, const Size &rNS );
52  inline void Pos( const Point& rNew );
53  inline void Pos( const long nNewX, const long nNewY );
54  inline void SSize( const Size& rNew );
55  inline void SSize( const long nHeight, const long nWidth );
56  inline void Width( long nNew );
57  inline void Height( long nNew );
58  inline void Left( const long nLeft );
59  inline void Right( const long nRight );
60  inline void Top( const long nTop );
61  inline void Bottom( const long nBottom );
62 
63  //Get-Methods
64  inline const Point &Pos() const;
65  inline const Size &SSize() const;
66  inline long Width() const;
67  inline long Height() const;
68  inline long Left() const;
69  inline long Right() const;
70  inline long Top() const;
71  inline long Bottom() const;
72 
73  // In order to be able to access the members of Pos and SSize from the layout side.
74  inline Point &Pos();
75  inline Size &SSize();
76 
77  Point Center() const;
78 
79  void Justify();
80 
81  SwRect &Union( const SwRect& rRect );
82  SwRect &Intersection( const SwRect& rRect );
83 
84  // Same as Intersection, only assume that Rects are overlapping!
85  SwRect &Intersection_( const SwRect &rRect );
86 
87  bool IsInside( const Point& rPOINT ) const;
88  bool IsNear(const Point& rPoint, long nTolerance ) const;
89  bool IsInside( const SwRect& rRect ) const;
90  bool IsOver( const SwRect& rRect ) const;
91  inline bool HasArea() const;
92  inline bool IsEmpty() const;
93  inline void Clear();
94 
95  inline SwRect &operator = ( const SwRect &rRect );
96 
97  inline bool operator == ( const SwRect& rRect ) const;
98  inline bool operator != ( const SwRect& rRect ) const;
99 
100  inline SwRect &operator+=( const Point &rPt );
101  inline SwRect &operator-=( const Point &rPt );
102 
103  //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
104  inline tools::Rectangle SVRect() const;
105 
106  // Output operator for debugging.
107  friend SvStream& WriteSwRect( SvStream &rStream, const SwRect &rRect );
108  void dumpAsXmlAttributes(xmlTextWriterPtr writer) const;
109 
110  void Top_( const long nTop );
111  void Bottom_( const long nBottom );
112  void Left_( const long nLeft );
113  void Right_( const long nRight );
114  void Width_( const long nNew );
115  void Height_( const long nNew );
116  long Top_() const;
117  long Bottom_() const;
118  long Left_() const;
119  long Right_() const;
120  long Width_() const;
121  long Height_() const;
122  void SubTop( const long nSub );
123  void AddBottom( const long nAdd );
124  void SubLeft( const long nSub );
125  void AddRight( const long nAdd );
126  void AddWidth( const long nAdd );
127  void AddHeight( const long nAdd );
128  void SetPosX( const long nNew );
129  void SetPosY( const long nNew );
130  void SetLeftAndWidth( long nLeft, long nNew );
131  void SetTopAndHeight( long nTop, long nNew );
132  void SetRightAndWidth( long nRight, long nNew );
133  void SetBottomAndHeight( long nBottom, 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  long GetLeftDistance( long ) const;
144  long GetBottomDistance( long ) const;
145  long GetRightDistance( long ) const;
146  long GetTopDistance( long ) const;
147  bool OverStepLeft( long ) const;
148  bool OverStepBottom( long ) const;
149  bool OverStepTop( long ) const;
150  bool OverStepRight( long ) const;
151 };
152 
153 typedef void (SwRect:: *SwRectSet)( const long nNew );
154 typedef long (SwRect:: *SwRectGet)() const;
155 typedef Point (SwRect:: *SwRectPoint)() const;
156 typedef Size (SwRect:: *SwRectSize)() const;
157 typedef bool (SwRect:: *SwRectMax)( long ) const;
158 typedef long (SwRect:: *SwRectDist)( long ) const;
159 typedef void (SwRect:: *SwRectSetTwice)( long, long );
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 long nNewX, const 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 long nNewHeight, const long nNewWidth )
182 {
183  m_Size.setWidth(nNewWidth);
184  m_Size.setHeight(nNewHeight);
185 }
186 inline void SwRect::Width( long nNew )
187 {
188  m_Size.setWidth(nNew);
189 }
190 inline void SwRect::Height( long nNew )
191 {
192  m_Size.setHeight(nNew);
193 }
194 inline void SwRect::Left( const long nLeft )
195 {
196  m_Size.AdjustWidth( m_Point.getX() - nLeft );
197  m_Point.setX(nLeft);
198 }
199 inline void SwRect::Right( const long nRight )
200 {
201  m_Size.setWidth(nRight - m_Point.getX() + 1);
202 }
203 inline void SwRect::Top( const long nTop )
204 {
205  m_Size.AdjustHeight( m_Point.getY() - nTop );
206  m_Point.setY(nTop);
207 }
208 inline void SwRect::Bottom( const 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;
229 }
230 inline long SwRect::Width() const
231 {
232  return m_Size.Width();
233 }
234 inline long SwRect::Height() const
235 {
236  return m_Size.Height();
237 }
238 inline long SwRect::Left() const
239 {
240  return m_Point.X();
241 }
242 inline long SwRect::Right() const
243 {
244  return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
245 }
246 inline long SwRect::Top() const
247 {
248  return m_Point.Y();
249 }
250 inline long SwRect::Bottom() const
251 {
252  return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
253 }
254 
255 // operators
256 inline SwRect &SwRect::operator = ( const SwRect &rRect )
257 {
258  m_Point = rRect.m_Point;
259  m_Size = rRect.m_Size;
260  return *this;
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 inline bool SwRect::operator != ( const SwRect& rRect ) const
267 {
268  return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
269 }
270 
271 inline SwRect &SwRect::operator+=( const Point &rPt )
272 {
273  m_Point += rPt;
274  return *this;
275 }
276 inline SwRect &SwRect::operator-=( const Point &rPt )
277 {
278  m_Point -= rPt;
279  return *this;
280 }
281 
282 // other
284 {
285  SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
286  return tools::Rectangle( m_Point.getX(), m_Point.getY(),
287  m_Point.getX() + m_Size.getWidth() - 1, //Right()
288  m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
289 }
290 
291 inline bool SwRect::HasArea() const
292 {
293  return !IsEmpty();
294 }
295 inline bool SwRect::IsEmpty() const
296 {
297  return !(m_Size.getHeight() && m_Size.getWidth());
298 }
299 inline void SwRect::Clear()
300 {
301  m_Point.setX(0);
302  m_Point.setY(0);
303  m_Size.setWidth(0);
304  m_Size.setHeight(0);
305 }
306 
307 // constructors
308 inline SwRect::SwRect() :
309  m_Point( 0, 0 ),
310  m_Size( 0, 0 )
311 {
312 }
313 inline SwRect::SwRect( const SwRect &rRect ) :
314  m_Point( rRect.m_Point ),
315  m_Size( rRect.m_Size )
316 {
317 }
318 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
319  m_Point( rLT ),
320  m_Size( rSize )
321 {
322 }
323 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
324  m_Point( rLT ),
325  m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
326 {
327 }
328 inline SwRect::SwRect( long X, long Y, long W, long H ) :
329  m_Point( X, Y ),
330  m_Size( W, H )
331 {
332 }
333 
334 template< typename charT, typename traits >
335 inline std::basic_ostream<charT, traits> & operator <<(
336  std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
337 {
338  if (rectangle.IsEmpty())
339  stream << "EMPTY:";
340  return stream << rectangle.SSize()
341  << "@(" << rectangle.Pos() << ")";
342 }
343 
344 #endif // INCLUDED_SW_INC_SWRECT_HXX
345 
346 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void(SwRect::* SwRectSet)(const long nNew)
Definition: swrect.hxx:153
long Width() const
Size m_Size
Definition: swrect.hxx:38
long Right() const
Definition: swrect.hxx:242
struct _xmlTextWriter * xmlTextWriterPtr
Definition: swrect.hxx:29
long AdjustWidth(long n)
long Height() const
void(SwRect::* SwRectSetTwice)(long, long)
Definition: swrect.hxx:159
Point(SwRect::* SwRectPoint)() const
Definition: swrect.hxx:155
timeval & operator-=(timeval &t1, const timeval &t2)
void Pos(const Point &rNew)
Definition: swrect.hxx:168
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
long Left() const
Definition: swrect.hxx:238
Center
long AdjustHeight(long n)
long Width() const
Definition: swrect.hxx:230
#define X
bool IsEmpty() const
Definition: swrect.hxx:295
long(SwRect::* SwRectDist)(long) const
Definition: swrect.hxx:158
long Height() const
Definition: swrect.hxx:234
RealSize2D m_Size
struct _xmlTextWriter * xmlTextWriterPtr
Right
long(SwRect::* SwRectGet)() const
Definition: swrect.hxx:154
const Size & SSize() const
Definition: swrect.hxx:222
void(SwRect::* SwRectSetPos)(const Point &)
Definition: swrect.hxx:160
SwRect & operator=(const SwRect &rRect)
Definition: swrect.hxx:256
bool HasArea() const
Definition: swrect.hxx:291
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
void SSize(const Size &rNew)
Definition: swrect.hxx:177
Size(SwRect::* SwRectSize)() const
Definition: swrect.hxx:156
#define Y
#define SAL_WARN_UNUSED
SwRect & operator+=(const Point &rPt)
Definition: swrect.hxx:271
tools::Rectangle SVRect() const
Definition: swrect.hxx:283
long Bottom() const
Definition: swrect.hxx:250
long Top() const
Definition: swrect.hxx:246
Point m_Point
Definition: swrect.hxx:37
#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:335
bool(SwRect::* SwRectMax)(long) const
Definition: swrect.hxx:157
void Clear()
Definition: swrect.hxx:299
Left
bool operator!=(const SwRect &rRect) const
Definition: swrect.hxx:266
long getHeight() const
SwRect & operator-=(const Point &rPt)
Definition: swrect.hxx:276
long getWidth() const
void Chg(const Point &rNP, const Size &rNS)
Definition: swrect.hxx:163
void setWidth(long nWidth)
const Point & Pos() const
Definition: swrect.hxx:214
bool operator==(const SwRect &rRect) const
Definition: swrect.hxx:262
SwRect()
Definition: swrect.hxx:308
SvStream & WriteSwRect(SvStream &rStream, const SwRect &rRect)
Definition: swrect.cxx:234
void setHeight(long nHeight)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo