bump product version to 4.1.6.2
[LibreOffice.git] / sw / inc / swrect.hxx
blob62e521865a24a14bd647ccb904557d22f8685fae
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef _SWRECT_HXX
20 #define _SWRECT_HXX
21 #include <osl/diagnose.h>
22 #include <tools/gen.hxx>
23 class SvStream;
25 class SAL_WARN_UNUSED SwRect
27 Point m_Point;
28 Size m_Size;
31 public:
32 inline SwRect();
33 inline SwRect( const SwRect &rRect );
34 inline SwRect( const Point& rLT, const Size& rSize );
35 inline SwRect( const Point& rLT, const Point& rRB );
36 inline SwRect( long X, long Y, long Width, long Height );
38 //SV-SS e.g. SwRect( pWin->GetClipRect() );
39 SwRect( const Rectangle &rRect );
41 //Set-Methods
42 inline void Chg( const Point& rNP, const Size &rNS );
43 inline void Pos( const Point& rNew );
44 inline void Pos( const long nNewX, const long nNewY );
45 inline void SSize( const Size& rNew );
46 inline void SSize( const long nHeight, const long nWidth );
47 inline void Width( long nNew );
48 inline void Height( long nNew );
49 inline void Left( const long nLeft );
50 inline void Right( const long nRight );
51 inline void Top( const long nTop );
52 inline void Bottom( const long nBottom );
54 //Get-Methods
55 inline const Point &Pos() const;
56 inline const Size &SSize() const;
57 inline long Width() const;
58 inline long Height() const;
59 inline long Left() const;
60 inline long Right() const;
61 inline long Top() const;
62 inline long Bottom() const;
64 // In order to be able to access the members of Pos and SSize from the layout side.
65 inline Point &Pos();
66 inline Size &SSize();
68 Point Center() const;
70 void Justify();
72 SwRect &Union( const SwRect& rRect );
73 SwRect &Intersection( const SwRect& rRect );
75 // Same as Intersection, only assume that Rects are overlapping!
76 SwRect &_Intersection( const SwRect &rRect );
77 inline SwRect GetIntersection( const SwRect& rRect ) const;
79 sal_Bool IsInside( const Point& rPOINT ) const;
80 sal_Bool IsNear(const Point& rPoint, long nTolerance ) const;
81 sal_Bool IsInside( const SwRect& rRect ) const;
82 sal_Bool IsOver( const SwRect& rRect ) const;
83 inline sal_Bool HasArea() const;
84 inline sal_Bool IsEmpty() const;
85 inline void Clear();
87 inline SwRect &operator = ( const SwRect &rRect );
89 inline sal_Bool operator == ( const SwRect& rRect ) const;
90 inline sal_Bool operator != ( const SwRect& rRect ) const;
92 inline SwRect &operator+=( const Point &rPt );
93 inline SwRect &operator-=( const Point &rPt );
95 inline SwRect &operator+=( const Size &rSz );
96 inline SwRect &operator-=( const Size &rSz );
98 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
99 inline Rectangle SVRect() const;
101 // Output operator for debugging.
102 friend SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
105 void _Top( const long nTop );
106 void _Bottom( const long nBottom );
107 void _Left( const long nLeft );
108 void _Right( const long nRight );
109 void _Width( const long nNew );
110 void _Height( const long nNew );
111 long _Top() const;
112 long _Bottom() const;
113 long _Left() const;
114 long _Right() const;
115 long _Width() const;
116 long _Height() const;
117 void SubTop( const long nSub );
118 void AddBottom( const long nAdd );
119 void SubLeft( const long nSub );
120 void AddRight( const long nAdd );
121 void AddWidth( const long nAdd );
122 void AddHeight( const long nAdd );
123 void SetPosX( const long nNew );
124 void SetPosY( const long nNew );
125 void SetLeftAndWidth( long nLeft, long nNew );
126 void SetTopAndHeight( long nTop, long nNew );
127 void SetRightAndWidth( long nRight, long nNew );
128 void SetBottomAndHeight( long nBottom, long nNew );
129 void SetUpperLeftCorner( const Point& rNew );
130 void SetUpperRightCorner( const Point& rNew );
131 void SetLowerLeftCorner( const Point& rNew );
132 const Size _Size() const;
133 const Point TopLeft() const;
134 const Point TopRight() const;
135 const Point BottomLeft() const;
136 const Point BottomRight() const;
137 const Size SwappedSize() const;
138 long GetLeftDistance( long ) const;
139 long GetBottomDistance( long ) const;
140 long GetRightDistance( long ) const;
141 long GetTopDistance( long ) const;
142 sal_Bool OverStepLeft( long ) const;
143 sal_Bool OverStepBottom( long ) const;
144 sal_Bool OverStepTop( long ) const;
145 sal_Bool OverStepRight( long ) const;
148 #ifdef DBG_UTIL
149 // Implementation in swrect.cxx
150 extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
151 #endif
153 typedef void (SwRect:: *SwRectSet)( const long nNew );
154 typedef long (SwRect:: *SwRectGet)() const;
155 typedef const Point (SwRect:: *SwRectPoint)() const;
156 typedef const Size (SwRect:: *SwRectSize)() const;
157 typedef sal_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& );
162 // Set-Methods
163 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
165 m_Point = rNP;
166 m_Size = rNS;
168 inline void SwRect::Pos( const Point& rNew )
170 m_Point = rNew;
172 inline void SwRect::Pos( const long nNewX, const long nNewY )
174 m_Point.setX(nNewX);
175 m_Point.setY(nNewY);
177 inline void SwRect::SSize( const Size& rNew )
179 m_Size = rNew;
181 inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
183 m_Size.setWidth(nNewWidth);
184 m_Size.setHeight(nNewHeight);
186 inline void SwRect::Width( long nNew )
188 m_Size.setWidth(nNew);
190 inline void SwRect::Height( long nNew )
192 m_Size.setHeight(nNew);
194 inline void SwRect::Left( const long nLeft )
196 m_Size.Width() += m_Point.getX() - nLeft;
197 m_Point.setX(nLeft);
199 inline void SwRect::Right( const long nRight )
201 m_Size.setWidth(nRight - m_Point.getX() + 1);
203 inline void SwRect::Top( const long nTop )
205 m_Size.Height() += m_Point.getY() - nTop;
206 m_Point.setY(nTop);
208 inline void SwRect::Bottom( const long nBottom )
210 m_Size.setHeight(nBottom - m_Point.getY() + 1);
213 // Get-Methods
214 inline const Point &SwRect::Pos() const
216 return m_Point;
218 inline Point &SwRect::Pos()
220 return m_Point;
222 inline const Size &SwRect::SSize() const
224 return m_Size;
226 inline Size &SwRect::SSize()
228 return m_Size;
230 inline long SwRect::Width() const
232 return m_Size.Width();
234 inline long SwRect::Height() const
236 return m_Size.Height();
238 inline long SwRect::Left() const
240 return m_Point.X();
242 inline long SwRect::Right() const
244 return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
246 inline long SwRect::Top() const
248 return m_Point.Y();
250 inline long SwRect::Bottom() const
252 return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
255 // operators
256 inline SwRect &SwRect::operator = ( const SwRect &rRect )
258 m_Point = rRect.m_Point;
259 m_Size = rRect.m_Size;
260 return *this;
262 inline sal_Bool SwRect::operator == ( const SwRect& rRect ) const
264 return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
266 inline sal_Bool SwRect::operator != ( const SwRect& rRect ) const
268 return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
271 inline SwRect &SwRect::operator+=( const Point &rPt )
273 m_Point += rPt;
274 return *this;
276 inline SwRect &SwRect::operator-=( const Point &rPt )
278 m_Point -= rPt;
279 return *this;
282 inline SwRect &SwRect::operator+=( const Size &rSz )
284 m_Size.Width() += rSz.Width();
285 m_Size.Height() += rSz.Height();
286 return *this;
288 inline SwRect &SwRect::operator-=( const Size &rSz )
290 m_Size.Width() -= rSz.Width();
291 m_Size.Height() -= rSz.Height();
292 return *this;
296 // other
297 inline Rectangle SwRect::SVRect() const
299 OSL_ENSURE( !IsEmpty(), "SVRect() without Width or Height" );
300 return Rectangle( m_Point.getX(), m_Point.getY(),
301 m_Point.getX() + m_Size.getWidth() - 1, //Right()
302 m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
305 inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
307 return SwRect( *this ).Intersection( rRect );
310 inline sal_Bool SwRect::HasArea() const
312 return !IsEmpty();
314 inline sal_Bool SwRect::IsEmpty() const
316 return !(m_Size.getHeight() && m_Size.getWidth());
318 inline void SwRect::Clear()
320 m_Point.setX(0);
321 m_Point.setY(0);
322 m_Size.setWidth(0);
323 m_Size.setHeight(0);
326 // constructors
327 inline SwRect::SwRect() :
328 m_Point( 0, 0 ),
329 m_Size( 0, 0 )
332 inline SwRect::SwRect( const SwRect &rRect ) :
333 m_Point( rRect.m_Point ),
334 m_Size( rRect.m_Size )
337 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
338 m_Point( rLT ),
339 m_Size( rSize )
342 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
343 m_Point( rLT ),
344 m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
347 inline SwRect::SwRect( long X, long Y, long W, long H ) :
348 m_Point( X, Y ),
349 m_Size( W, H )
354 #endif //_SWRECT_HXX
356 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */