Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _SWRECT_HXX
29 : : #define _SWRECT_HXX
30 : : #include <osl/diagnose.h>
31 : : #include <tools/gen.hxx>
32 : : class SvStream;
33 : :
34 : : class SwRect
35 : : {
36 : : Point m_Point;
37 : : Size m_Size;
38 : :
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 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 : : inline SwRect GetIntersection( const SwRect& rRect ) const;
87 : :
88 : : sal_Bool IsInside( const Point& rPOINT ) const;
89 : : sal_Bool IsNear(const Point& rPoint, long nTolerance ) const;
90 : : sal_Bool IsInside( const SwRect& rRect ) const;
91 : : sal_Bool IsOver( const SwRect& rRect ) const;
92 : : inline sal_Bool HasArea() const;
93 : : inline sal_Bool IsEmpty() const;
94 : : inline void Clear();
95 : :
96 : : inline SwRect &operator = ( const SwRect &rRect );
97 : :
98 : : inline sal_Bool operator == ( const SwRect& rRect ) const;
99 : : inline sal_Bool operator != ( const SwRect& rRect ) const;
100 : :
101 : : inline SwRect &operator+=( const Point &rPt );
102 : : inline SwRect &operator-=( const Point &rPt );
103 : :
104 : : inline SwRect &operator+=( const Size &rSz );
105 : : inline SwRect &operator-=( const Size &rSz );
106 : :
107 : : //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
108 : : inline Rectangle SVRect() const;
109 : :
110 : : // Output operator for debugging.
111 : : friend SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
112 : :
113 : :
114 : : void _Top( const long nTop );
115 : : void _Bottom( const long nBottom );
116 : : void _Left( const long nLeft );
117 : : void _Right( const long nRight );
118 : : void _Width( const long nNew );
119 : : void _Height( const long nNew );
120 : : long _Top() const;
121 : : long _Bottom() const;
122 : : long _Left() const;
123 : : long _Right() const;
124 : : long _Width() const;
125 : : long _Height() const;
126 : : void SubTop( const long nSub );
127 : : void AddBottom( const long nAdd );
128 : : void SubLeft( const long nSub );
129 : : void AddRight( const long nAdd );
130 : : void AddWidth( const long nAdd );
131 : : void AddHeight( const long nAdd );
132 : : void SetPosX( const long nNew );
133 : : void SetPosY( const long nNew );
134 : : void SetLeftAndWidth( long nLeft, long nNew );
135 : : void SetTopAndHeight( long nTop, long nNew );
136 : : void SetRightAndWidth( long nRight, long nNew );
137 : : void SetBottomAndHeight( long nBottom, long nNew );
138 : : void SetUpperLeftCorner( const Point& rNew );
139 : : void SetUpperRightCorner( const Point& rNew );
140 : : void SetLowerLeftCorner( const Point& rNew );
141 : : const Size _Size() const;
142 : : const Point TopLeft() const;
143 : : const Point TopRight() const;
144 : : const Point BottomLeft() const;
145 : : const Point BottomRight() const;
146 : : const Size SwappedSize() const;
147 : : long GetLeftDistance( long ) const;
148 : : long GetBottomDistance( long ) const;
149 : : long GetRightDistance( long ) const;
150 : : long GetTopDistance( long ) const;
151 : : sal_Bool OverStepLeft( long ) const;
152 : : sal_Bool OverStepBottom( long ) const;
153 : : sal_Bool OverStepTop( long ) const;
154 : : sal_Bool OverStepRight( long ) const;
155 : : };
156 : :
157 : : #ifdef DBG_UTIL
158 : : // Implementation in swrect.cxx
159 : : extern SvStream &operator<<( SvStream &rStream, const SwRect &rRect );
160 : : #endif
161 : :
162 : : typedef void (SwRect:: *SwRectSet)( const long nNew );
163 : : typedef long (SwRect:: *SwRectGet)() const;
164 : : typedef const Point (SwRect:: *SwRectPoint)() const;
165 : : typedef const Size (SwRect:: *SwRectSize)() const;
166 : : typedef sal_Bool (SwRect:: *SwRectMax)( long ) const;
167 : : typedef long (SwRect:: *SwRectDist)( long ) const;
168 : : typedef void (SwRect:: *SwRectSetTwice)( long, long );
169 : : typedef void (SwRect:: *SwRectSetPos)( const Point& );
170 : :
171 : : // Set-Methods
172 : 49695 : inline void SwRect::Chg( const Point& rNP, const Size &rNS )
173 : : {
174 : 49695 : m_Point = rNP;
175 : 49695 : m_Size = rNS;
176 : 49695 : }
177 : 81733 : inline void SwRect::Pos( const Point& rNew )
178 : : {
179 : 81733 : m_Point = rNew;
180 : 81733 : }
181 : 0 : inline void SwRect::Pos( const long nNewX, const long nNewY )
182 : : {
183 : 0 : m_Point.setX(nNewX);
184 : 0 : m_Point.setY(nNewY);
185 : 0 : }
186 : 80484 : inline void SwRect::SSize( const Size& rNew )
187 : : {
188 : 80484 : m_Size = rNew;
189 : 80484 : }
190 : 14592 : inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
191 : : {
192 : 14592 : m_Size.setWidth(nNewWidth);
193 : 14592 : m_Size.setHeight(nNewHeight);
194 : 14592 : }
195 : 245790 : inline void SwRect::Width( long nNew )
196 : : {
197 : 245790 : m_Size.setWidth(nNew);
198 : 245790 : }
199 : 92641 : inline void SwRect::Height( long nNew )
200 : : {
201 : 92641 : m_Size.setHeight(nNew);
202 : 92641 : }
203 : 242700 : inline void SwRect::Left( const long nLeft )
204 : : {
205 : 242700 : m_Size.Width() += m_Point.getX() - nLeft;
206 : 242700 : m_Point.setX(nLeft);
207 : 242700 : }
208 : 275313 : inline void SwRect::Right( const long nRight )
209 : : {
210 : 275313 : m_Size.setWidth(nRight - m_Point.getX() + 1);
211 : 275313 : }
212 : 325922 : inline void SwRect::Top( const long nTop )
213 : : {
214 : 325922 : m_Size.Height() += m_Point.getY() - nTop;
215 : 325922 : m_Point.setY(nTop);
216 : 325922 : }
217 : 310864 : inline void SwRect::Bottom( const long nBottom )
218 : : {
219 : 310864 : m_Size.setHeight(nBottom - m_Point.getY() + 1);
220 : 310864 : }
221 : :
222 : : // Get-Methods
223 : 209116 : inline const Point &SwRect::Pos() const
224 : : {
225 : 209116 : return m_Point;
226 : : }
227 : 667670 : inline Point &SwRect::Pos()
228 : : {
229 : 667670 : return m_Point;
230 : : }
231 : 171053 : inline const Size &SwRect::SSize() const
232 : : {
233 : 171053 : return m_Size;
234 : : }
235 : 407705 : inline Size &SwRect::SSize()
236 : : {
237 : 407705 : return m_Size;
238 : : }
239 : 1449993 : inline long SwRect::Width() const
240 : : {
241 : 1449993 : return m_Size.Width();
242 : : }
243 : 1779337 : inline long SwRect::Height() const
244 : : {
245 : 1779337 : return m_Size.Height();
246 : : }
247 : 3764155 : inline long SwRect::Left() const
248 : : {
249 : 3764155 : return m_Point.X();
250 : : }
251 : 2563314 : inline long SwRect::Right() const
252 : : {
253 [ + + ]: 2563314 : return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
254 : : }
255 : 4163121 : inline long SwRect::Top() const
256 : : {
257 : 4163121 : return m_Point.Y();
258 : : }
259 : 2548090 : inline long SwRect::Bottom() const
260 : : {
261 [ + + ]: 2548090 : return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
262 : : }
263 : :
264 : : // operators
265 : 839081 : inline SwRect &SwRect::operator = ( const SwRect &rRect )
266 : : {
267 : 839081 : m_Point = rRect.m_Point;
268 : 839081 : m_Size = rRect.m_Size;
269 : 839081 : return *this;
270 : : }
271 : 86992 : inline sal_Bool SwRect::operator == ( const SwRect& rRect ) const
272 : : {
273 [ + + ][ + + ]: 86992 : return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
274 : : }
275 : 35595 : inline sal_Bool SwRect::operator != ( const SwRect& rRect ) const
276 : : {
277 [ + + ][ + + ]: 35595 : return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
278 : : }
279 : :
280 : 2559 : inline SwRect &SwRect::operator+=( const Point &rPt )
281 : : {
282 : 2559 : m_Point += rPt;
283 : 2559 : return *this;
284 : : }
285 : 0 : inline SwRect &SwRect::operator-=( const Point &rPt )
286 : : {
287 : 0 : m_Point -= rPt;
288 : 0 : return *this;
289 : : }
290 : :
291 : : inline SwRect &SwRect::operator+=( const Size &rSz )
292 : : {
293 : : m_Size.Width() += rSz.Width();
294 : : m_Size.Height() += rSz.Height();
295 : : return *this;
296 : : }
297 : : inline SwRect &SwRect::operator-=( const Size &rSz )
298 : : {
299 : : m_Size.Width() -= rSz.Width();
300 : : m_Size.Height() -= rSz.Height();
301 : : return *this;
302 : : }
303 : :
304 : :
305 : : // other
306 : 564293 : inline Rectangle SwRect::SVRect() const
307 : : {
308 : : OSL_ENSURE( !IsEmpty(), "SVRect() without Width or Height" );
309 : : return Rectangle( m_Point.getX(), m_Point.getY(),
310 : 564293 : m_Point.getX() + m_Size.getWidth() - 1, //Right()
311 : 1128586 : m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
312 : : }
313 : :
314 : : inline SwRect SwRect::GetIntersection( const SwRect& rRect ) const
315 : : {
316 : : return SwRect( *this ).Intersection( rRect );
317 : : }
318 : :
319 : 489535 : inline sal_Bool SwRect::HasArea() const
320 : : {
321 : 489535 : return !IsEmpty();
322 : : }
323 : 500966 : inline sal_Bool SwRect::IsEmpty() const
324 : : {
325 [ + + ][ + + ]: 500966 : return !(m_Size.getHeight() && m_Size.getWidth());
326 : : }
327 : 10514 : inline void SwRect::Clear()
328 : : {
329 : 10514 : m_Point.setX(0);
330 : 10514 : m_Point.setY(0);
331 : 10514 : m_Size.setWidth(0);
332 : 10514 : m_Size.setHeight(0);
333 : 10514 : }
334 : :
335 : : // constructors
336 : 964521 : inline SwRect::SwRect() :
337 : : m_Point( 0, 0 ),
338 : 964521 : m_Size( 0, 0 )
339 : : {
340 : 964521 : }
341 : 1217366 : inline SwRect::SwRect( const SwRect &rRect ) :
342 : : m_Point( rRect.m_Point ),
343 : 1217366 : m_Size( rRect.m_Size )
344 : : {
345 : 1217366 : }
346 : 68869 : inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
347 : : m_Point( rLT ),
348 : 68869 : m_Size( rSize )
349 : : {
350 : 68869 : }
351 : 75221 : inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
352 : : m_Point( rLT ),
353 : 75221 : m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
354 : : {
355 : 75221 : }
356 : 7389 : inline SwRect::SwRect( long X, long Y, long W, long H ) :
357 : : m_Point( X, Y ),
358 : 7389 : m_Size( W, H )
359 : : {
360 : 7389 : }
361 : :
362 : :
363 : : #endif //_SWRECT_HXX
364 : :
365 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|