Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / sw / inc / swrect.hxx
blob18bd97149e30039bbe6349b1b880f6cfe042efa4
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 INCLUDED_SW_INC_SWRECT_HXX
20 #define INCLUDED_SW_INC_SWRECT_HXX
22 #include <ostream>
24 #include <sal/log.hxx>
25 #include <tools/gen.hxx>
27 class SvStream;
29 /// *Of course* Writer needs its own rectangles.
30 /// This is half-open so m_Point.X() + m_Size.getWidth() is *not* included.
31 /// Note the tools Rectangle is (usually? sometimes?) closed so there's a
32 /// SVRect() to subtract 1 for the conversion.
33 class SAL_WARN_UNUSED SwRect
35 Point m_Point;
36 Size m_Size;
38 public:
39 inline SwRect();
40 inline SwRect( const SwRect &rRect );
41 inline SwRect( const Point& rLT, const Size& rSize );
42 inline SwRect( const Point& rLT, const Point& rRB );
43 inline SwRect( long X, long Y, long Width, long Height );
45 //SV-SS e.g. SwRect( pWin->GetClipRect() );
46 SwRect( const tools::Rectangle &rRect );
48 //Set-Methods
49 inline void Chg( const Point& rNP, const Size &rNS );
50 inline void Pos( const Point& rNew );
51 inline void Pos( const long nNewX, const long nNewY );
52 inline void SSize( const Size& rNew );
53 inline void SSize( const long nHeight, const long nWidth );
54 inline void Width( long nNew );
55 inline void Height( long nNew );
56 inline void Left( const long nLeft );
57 inline void Right( const long nRight );
58 inline void Top( const long nTop );
59 inline void Bottom( const long nBottom );
61 //Get-Methods
62 inline const Point &Pos() const;
63 inline const Size &SSize() const;
64 inline long Width() const;
65 inline long Height() const;
66 inline long Left() const;
67 inline long Right() const;
68 inline long Top() const;
69 inline long Bottom() const;
71 // In order to be able to access the members of Pos and SSize from the layout side.
72 inline Point &Pos();
73 inline Size &SSize();
75 Point Center() const;
77 void Justify();
79 SwRect &Union( const SwRect& rRect );
80 SwRect &Intersection( const SwRect& rRect );
82 // Same as Intersection, only assume that Rects are overlapping!
83 SwRect &Intersection_( const SwRect &rRect );
85 bool IsInside( const Point& rPOINT ) const;
86 bool IsNear(const Point& rPoint, 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();
93 inline SwRect &operator = ( const SwRect &rRect );
95 inline bool operator == ( const SwRect& rRect ) const;
96 inline bool operator != ( const SwRect& rRect ) const;
98 inline SwRect &operator+=( const Point &rPt );
99 inline SwRect &operator-=( const Point &rPt );
101 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
102 inline tools::Rectangle SVRect() const;
104 // Output operator for debugging.
105 friend SvStream& WriteSwRect( SvStream &rStream, const SwRect &rRect );
108 void Top_( const long nTop );
109 void Bottom_( const long nBottom );
110 void Left_( const long nLeft );
111 void Rigth_( const long nRight );
112 void Width_( const long nNew );
113 void Height_( const long nNew );
114 long Top_() const;
115 long Bottom_() const;
116 long Left_() const;
117 long Rigth_() const;
118 long Width_() const;
119 long Height_() const;
120 void SubTop( const long nSub );
121 void AddBottom( const long nAdd );
122 void SubLeft( const long nSub );
123 void AddRight( const long nAdd );
124 void AddWidth( const long nAdd );
125 void AddHeight( const long nAdd );
126 void SetPosX( const long nNew );
127 void SetPosY( const long nNew );
128 void SetLeftAndWidth( long nLeft, long nNew );
129 void SetTopAndHeight( long nTop, long nNew );
130 void SetRightAndWidth( long nRight, long nNew );
131 void SetBottomAndHeight( long nBottom, long nNew );
132 void SetUpperLeftCorner( const Point& rNew );
133 void SetUpperRightCorner( const Point& rNew );
134 void SetLowerLeftCorner( const Point& rNew );
135 const Size Size_() const;
136 const Point TopLeft() const;
137 const Point TopRight() const;
138 const Point BottomLeft() const;
139 const Point BottomRight() const;
140 const Size SwappedSize() const;
141 long GetLeftDistance( long ) const;
142 long GetBottomDistance( long ) const;
143 long GetRightDistance( long ) const;
144 long GetTopDistance( long ) const;
145 bool OverStepLeft( long ) const;
146 bool OverStepBottom( long ) const;
147 bool OverStepTop( long ) const;
148 bool OverStepRight( long ) const;
151 typedef void (SwRect:: *SwRectSet)( const long nNew );
152 typedef long (SwRect:: *SwRectGet)() const;
153 typedef const Point (SwRect:: *SwRectPoint)() const;
154 typedef const Size (SwRect:: *SwRectSize)() const;
155 typedef bool (SwRect:: *SwRectMax)( long ) const;
156 typedef long (SwRect:: *SwRectDist)( long ) const;
157 typedef void (SwRect:: *SwRectSetTwice)( long, long );
158 typedef void (SwRect:: *SwRectSetPos)( const Point& );
160 // Set-Methods
161 inline void SwRect::Chg( const Point& rNP, const Size &rNS )
163 m_Point = rNP;
164 m_Size = rNS;
166 inline void SwRect::Pos( const Point& rNew )
168 m_Point = rNew;
170 inline void SwRect::Pos( const long nNewX, const long nNewY )
172 m_Point.setX(nNewX);
173 m_Point.setY(nNewY);
175 inline void SwRect::SSize( const Size& rNew )
177 m_Size = rNew;
179 inline void SwRect::SSize( const long nNewHeight, const long nNewWidth )
181 m_Size.setWidth(nNewWidth);
182 m_Size.setHeight(nNewHeight);
184 inline void SwRect::Width( long nNew )
186 m_Size.setWidth(nNew);
188 inline void SwRect::Height( long nNew )
190 m_Size.setHeight(nNew);
192 inline void SwRect::Left( const long nLeft )
194 m_Size.Width() += m_Point.getX() - nLeft;
195 m_Point.setX(nLeft);
197 inline void SwRect::Right( const long nRight )
199 m_Size.setWidth(nRight - m_Point.getX() + 1);
201 inline void SwRect::Top( const long nTop )
203 m_Size.Height() += m_Point.getY() - nTop;
204 m_Point.setY(nTop);
206 inline void SwRect::Bottom( const long nBottom )
208 m_Size.setHeight(nBottom - m_Point.getY() + 1);
211 // Get-Methods
212 inline const Point &SwRect::Pos() const
214 return m_Point;
216 inline Point &SwRect::Pos()
218 return m_Point;
220 inline const Size &SwRect::SSize() const
222 return m_Size;
224 inline Size &SwRect::SSize()
226 return m_Size;
228 inline long SwRect::Width() const
230 return m_Size.Width();
232 inline long SwRect::Height() const
234 return m_Size.Height();
236 inline long SwRect::Left() const
238 return m_Point.X();
240 inline long SwRect::Right() const
242 return m_Size.getWidth() ? m_Point.getX() + m_Size.getWidth() - 1 : m_Point.getX();
244 inline long SwRect::Top() const
246 return m_Point.Y();
248 inline long SwRect::Bottom() const
250 return m_Size.getHeight() ? m_Point.getY() + m_Size.getHeight() - 1 : m_Point.getY();
253 // operators
254 inline SwRect &SwRect::operator = ( const SwRect &rRect )
256 m_Point = rRect.m_Point;
257 m_Size = rRect.m_Size;
258 return *this;
260 inline bool SwRect::operator == ( const SwRect& rRect ) const
262 return (m_Point == rRect.m_Point && m_Size == rRect.m_Size);
264 inline bool SwRect::operator != ( const SwRect& rRect ) const
266 return (m_Point != rRect.m_Point || m_Size != rRect.m_Size);
269 inline SwRect &SwRect::operator+=( const Point &rPt )
271 m_Point += rPt;
272 return *this;
274 inline SwRect &SwRect::operator-=( const Point &rPt )
276 m_Point -= rPt;
277 return *this;
280 // other
281 inline tools::Rectangle SwRect::SVRect() const
283 SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
284 return tools::Rectangle( m_Point.getX(), m_Point.getY(),
285 m_Point.getX() + m_Size.getWidth() - 1, //Right()
286 m_Point.getY() + m_Size.getHeight() - 1 ); //Bottom()
289 inline bool SwRect::HasArea() const
291 return !IsEmpty();
293 inline bool SwRect::IsEmpty() const
295 return !(m_Size.getHeight() && m_Size.getWidth());
297 inline void SwRect::Clear()
299 m_Point.setX(0);
300 m_Point.setY(0);
301 m_Size.setWidth(0);
302 m_Size.setHeight(0);
305 // constructors
306 inline SwRect::SwRect() :
307 m_Point( 0, 0 ),
308 m_Size( 0, 0 )
311 inline SwRect::SwRect( const SwRect &rRect ) :
312 m_Point( rRect.m_Point ),
313 m_Size( rRect.m_Size )
316 inline SwRect::SwRect( const Point& rLT, const Size& rSize ) :
317 m_Point( rLT ),
318 m_Size( rSize )
321 inline SwRect::SwRect( const Point& rLT, const Point& rRB ) :
322 m_Point( rLT ),
323 m_Size( rRB.X() - rLT.X() + 1, rRB.Y() - rLT.Y() + 1 )
326 inline SwRect::SwRect( long X, long Y, long W, long H ) :
327 m_Point( X, Y ),
328 m_Size( W, H )
332 template< typename charT, typename traits >
333 inline std::basic_ostream<charT, traits> & operator <<(
334 std::basic_ostream<charT, traits> & stream, const SwRect& rectangle )
336 if (rectangle.IsEmpty())
337 return stream << "EMPTY";
338 else
339 return stream << rectangle.SSize()
340 << "@(" << rectangle.Pos() << ")";
343 #endif // INCLUDED_SW_INC_SWRECT_HXX
345 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */