1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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
24 #include <sal/log.hxx>
25 #include <tools/gen.hxx>
29 typedef struct _xmlTextWriter
* xmlTextWriterPtr
;
31 /// *Of course* Writer needs its own rectangles.
32 /// This is half-open so m_Point.X() + m_Size.getWidth() is *not* included.
33 /// Note the tools Rectangle is (usually? sometimes?) closed so there's a
34 /// SVRect() to subtract 1 for the conversion.
35 class SAL_WARN_UNUSED SW_DLLPUBLIC SwRect
42 inline SwRect( const SwRect
&rRect
) = default;
43 inline SwRect( const Point
& rLT
, const Size
& rSize
);
44 inline SwRect( const Point
& rLT
, const Point
& rRB
);
45 inline SwRect( tools::Long X
, tools::Long Y
, tools::Long Width
, tools::Long Height
);
47 //SV-SS e.g. SwRect( pWin->GetClipRect() );
48 SwRect( const tools::Rectangle
&rRect
);
51 inline void Chg( const Point
& rNP
, const Size
&rNS
);
52 inline void Pos( const Point
& rNew
);
53 inline void Pos( const tools::Long nNewX
, const tools::Long nNewY
);
54 inline void SSize( const Size
& rNew
);
55 inline void SSize( const tools::Long nHeight
, const tools::Long nWidth
);
56 inline void Width( tools::Long nNew
);
57 inline void Height( tools::Long nNew
);
58 inline void Left( const tools::Long nLeft
);
59 inline void Right( const tools::Long nRight
);
60 inline void Top( const tools::Long nTop
);
61 inline void Bottom( const tools::Long nBottom
);
64 inline const Point
&Pos() const;
65 inline const Size
&SSize() const;
66 inline tools::Long
Width() const;
67 inline tools::Long
Height() const;
68 inline tools::Long
Left() const;
69 inline tools::Long
Right() const;
70 inline tools::Long
Top() const;
71 inline tools::Long
Bottom() const;
73 // In order to be able to access the members of Pos and SSize from the layout side.
80 SwRect
&Union( const SwRect
& rRect
)
82 if ( Top() > rRect
.Top() )
84 if ( Left() > rRect
.Left() )
86 tools::Long n
= rRect
.Right();
94 SwRect
&Intersection( const SwRect
& rRect
);
96 // Same as Intersection, only assume that Rects are overlapping!
97 SwRect
&Intersection_( const SwRect
&rRect
);
99 bool IsInside( const Point
& rPoint
) const
101 return (Left() <= rPoint
.X()) &&
102 (Top() <= rPoint
.Y()) &&
103 (Right() >= rPoint
.X()) &&
104 (Bottom()>= rPoint
.Y());
106 bool IsNear(const Point
& rPoint
, tools::Long nTolerance
) const;
107 bool IsInside( const SwRect
& rRect
) const
109 const tools::Long nRight
= Right();
110 const tools::Long nBottom
= Bottom();
111 const tools::Long nrRight
= rRect
.Right();
112 const tools::Long nrBottom
= rRect
.Bottom();
113 return (Left() <= rRect
.Left()) && (rRect
.Left()<= nRight
) &&
114 (Left() <= nrRight
) && (nrRight
<= nRight
) &&
115 (Top() <= rRect
.Top()) && (rRect
.Top() <= nBottom
) &&
116 (Top() <= nrBottom
) && (nrBottom
<= nBottom
);
118 bool IsOver( const SwRect
& rRect
) const;
119 inline bool HasArea() const;
120 inline bool IsEmpty() const;
123 SwRect
&operator = ( const SwRect
&rRect
) = default;
125 inline bool operator == ( const SwRect
& rRect
) const;
126 inline bool operator != ( const SwRect
& rRect
) const;
128 inline SwRect
&operator+=( const Point
&rPt
);
129 inline SwRect
&operator-=( const Point
&rPt
);
131 //SV-SS e.g. pWin->DrawRect( aSwRect.SVRect() );
132 inline tools::Rectangle
SVRect() const;
134 // Output operator for debugging.
135 friend SvStream
& WriteSwRect( SvStream
&rStream
, const SwRect
&rRect
);
136 void dumpAsXmlAttributes(xmlTextWriterPtr writer
) const;
138 void Top_( const tools::Long nTop
);
139 void Bottom_( const tools::Long nBottom
);
140 void Left_( const tools::Long nLeft
);
141 void Right_( const tools::Long nRight
);
142 void Width_( const tools::Long nNew
);
143 void Height_( const tools::Long nNew
);
144 tools::Long
Top_() const;
145 tools::Long
Bottom_() const;
146 tools::Long
Left_() const;
147 tools::Long
Right_() const;
148 tools::Long
Width_() const;
149 tools::Long
Height_() const;
150 void SubTop( const tools::Long nSub
);
151 void AddTop( const tools::Long nAdd
);
152 void AddBottom( const tools::Long nAdd
);
153 void AddLeft( const tools::Long nAdd
);
154 void SubLeft( const tools::Long nSub
);
155 void AddRight( const tools::Long nAdd
);
156 void AddWidth( const tools::Long nAdd
);
157 void AddHeight( const tools::Long nAdd
);
158 void SetPosX( const tools::Long nNew
);
159 void SetPosY( const tools::Long nNew
);
160 void SetLeftAndWidth( tools::Long nLeft
, tools::Long nNew
);
161 void SetTopAndHeight( tools::Long nTop
, tools::Long nNew
);
162 void SetRightAndWidth( tools::Long nRight
, tools::Long nNew
);
163 void SetBottomAndHeight( tools::Long nBottom
, tools::Long nNew
);
164 void SetUpperLeftCorner( const Point
& rNew
);
165 void SetUpperRightCorner( const Point
& rNew
);
166 void SetLowerLeftCorner( const Point
& rNew
);
168 Point
TopLeft() const;
169 Point
TopRight() const;
170 Point
BottomLeft() const;
171 Point
BottomRight() const;
172 Size
SwappedSize() const;
173 tools::Long
GetLeftDistance( tools::Long
) const;
174 tools::Long
GetBottomDistance( tools::Long
) const;
175 tools::Long
GetRightDistance( tools::Long
) const;
176 tools::Long
GetTopDistance( tools::Long
) const;
177 bool OverStepLeft( tools::Long
) const;
178 bool OverStepBottom( tools::Long
) const;
179 bool OverStepTop( tools::Long
) const;
180 bool OverStepRight( tools::Long
) const;
183 typedef void (SwRect::*SwRectSet
)( const tools::Long nNew
);
184 typedef tools::Long (SwRect::*SwRectGet
)() const;
185 typedef Point (SwRect::*SwRectPoint
)() const;
186 typedef Size (SwRect::*SwRectSize
)() const;
187 typedef bool (SwRect::*SwRectMax
)( tools::Long
) const;
188 typedef tools::Long (SwRect::*SwRectDist
)( tools::Long
) const;
189 typedef void (SwRect::*SwRectSetTwice
)( tools::Long
, tools::Long
);
190 typedef void (SwRect::*SwRectSetPos
)( const Point
& );
193 inline void SwRect::Chg( const Point
& rNP
, const Size
&rNS
)
198 inline void SwRect::Pos( const Point
& rNew
)
202 inline void SwRect::Pos( const tools::Long nNewX
, const tools::Long nNewY
)
207 inline void SwRect::SSize( const Size
& rNew
)
211 inline void SwRect::SSize( const tools::Long nNewHeight
, const tools::Long nNewWidth
)
213 m_Size
.setWidth(nNewWidth
);
214 m_Size
.setHeight(nNewHeight
);
216 inline void SwRect::Width( tools::Long nNew
)
218 m_Size
.setWidth(nNew
);
220 inline void SwRect::Height( tools::Long nNew
)
222 m_Size
.setHeight(nNew
);
224 inline void SwRect::Left( const tools::Long nLeft
)
226 m_Size
.AdjustWidth( m_Point
.getX() - nLeft
);
229 inline void SwRect::Right( const tools::Long nRight
)
231 m_Size
.setWidth(nRight
- m_Point
.getX() + 1);
233 inline void SwRect::Top( const tools::Long nTop
)
235 m_Size
.AdjustHeight( m_Point
.getY() - nTop
);
238 inline void SwRect::Bottom( const tools::Long nBottom
)
240 m_Size
.setHeight(nBottom
- m_Point
.getY() + 1);
244 inline const Point
&SwRect::Pos() const
248 inline Point
&SwRect::Pos()
252 inline const Size
&SwRect::SSize() const
256 inline tools::Long
SwRect::Width() const
258 return m_Size
.Width();
260 inline tools::Long
SwRect::Height() const
262 return m_Size
.Height();
264 inline tools::Long
SwRect::Left() const
268 inline tools::Long
SwRect::Right() const
270 return m_Size
.getWidth() ? m_Point
.getX() + m_Size
.getWidth() - 1 : m_Point
.getX();
272 inline tools::Long
SwRect::Top() const
276 inline tools::Long
SwRect::Bottom() const
278 return m_Size
.getHeight() ? m_Point
.getY() + m_Size
.getHeight() - 1 : m_Point
.getY();
281 inline Point
SwRect::TopLeft() const
283 return Point( Left(), Top());
285 inline Point
SwRect::TopRight() const
287 return Point( Right(), Top());
289 inline Point
SwRect::BottomLeft() const
291 return Point( Left(), Bottom());
293 inline Point
SwRect::BottomRight() const
295 return Point( Right(), Bottom());
298 inline bool SwRect::operator == ( const SwRect
& rRect
) const
300 return (m_Point
== rRect
.m_Point
&& m_Size
== rRect
.m_Size
);
302 inline bool SwRect::operator != ( const SwRect
& rRect
) const
304 return (m_Point
!= rRect
.m_Point
|| m_Size
!= rRect
.m_Size
);
307 inline SwRect
&SwRect::operator+=( const Point
&rPt
)
312 inline SwRect
&SwRect::operator-=( const Point
&rPt
)
319 inline tools::Rectangle
SwRect::SVRect() const
321 SAL_WARN_IF( IsEmpty(), "sw", "SVRect() without Width or Height" );
322 return tools::Rectangle( m_Point
.getX(), m_Point
.getY(),
323 m_Point
.getX() + m_Size
.getWidth() - 1, //Right()
324 m_Point
.getY() + m_Size
.getHeight() - 1 ); //Bottom()
327 inline bool SwRect::HasArea() const
331 inline bool SwRect::IsEmpty() const
333 return !(m_Size
.getHeight() && m_Size
.getWidth());
335 inline void SwRect::Clear()
344 inline SwRect::SwRect() :
349 inline SwRect::SwRect( const Point
& rLT
, const Size
& rSize
) :
354 inline SwRect::SwRect( const Point
& rLT
, const Point
& rRB
) :
356 m_Size( rRB
.X() - rLT
.X() + 1, rRB
.Y() - rLT
.Y() + 1 )
359 inline SwRect::SwRect( tools::Long X
, tools::Long Y
, tools::Long W
, tools::Long H
) :
365 template< typename charT
, typename traits
>
366 inline std::basic_ostream
<charT
, traits
> & operator <<(
367 std::basic_ostream
<charT
, traits
> & stream
, const SwRect
& rectangle
)
369 if (rectangle
.IsEmpty())
371 return stream
<< rectangle
.SSize()
372 << "@(" << rectangle
.Pos() << ")";
375 #endif // INCLUDED_SW_INC_SWRECT_HXX
377 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */