]> git.saurik.com Git - wxWidgets.git/blame - include/wx/os2/region.h
Fixed ReadLine missing last character from text files with no final newline.
[wxWidgets.git] / include / wx / os2 / region.h
CommitLineData
0e320a79
DW
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.h
3// Purpose: wxRegion class
409c9842 4// Author: David Webster
0e320a79 5// Modified by:
409c9842 6// Created: 10/15/99
0e320a79 7// RCS-ID: $Id$
409c9842 8// Copyright: (c) David Webster
65571936 9// Licence: wxWindows licence
0e320a79
DW
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_REGION_H_
13#define _WX_REGION_H_
14
0e320a79
DW
15#include "wx/list.h"
16#include "wx/gdiobj.h"
17#include "wx/gdicmn.h"
85f6b408 18#include "wx/bitmap.h"
51a7e6af 19#include "wx/os2/private.h"
0e320a79
DW
20
21class WXDLLEXPORT wxRect;
22class WXDLLEXPORT wxPoint;
23
0e320a79 24// So far, for internal use only
5a56a532
DW
25enum wxRegionOp { wxRGN_AND // Creates the intersection of the two combined regions.
26 ,wxRGN_COPY // Creates a copy of the region identified by hrgnSrc1.
27 ,wxRGN_DIFF // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
28 ,wxRGN_OR // Creates the union of two combined regions.
29 ,wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
30 };
31
32class WXDLLEXPORT wxRegion : public wxGDIObject
33{
0e320a79 34public:
5a56a532
DW
35 wxRegion( wxCoord x
36 ,wxCoord y
37 ,wxCoord vWidth
38 ,wxCoord vHeight
39 );
40 wxRegion( const wxPoint& rTopLeft
41 ,const wxPoint& rBottomRight
42 );
43 wxRegion(const wxRect& rRect);
19193a2c 44 wxRegion(WXHRGN hRegion, WXHDC hPS); // Hangs on to this region
85f6b408
VS
45 wxRegion( const wxBitmap& bmp)
46 {
47 Union(bmp);
48 }
49 wxRegion( const wxBitmap& bmp,
50 const wxColour& transColour, int tolerance = 0)
51 {
52 Union(bmp, transColour, tolerance);
53 }
409c9842
DW
54
55 wxRegion();
d3c7fc99 56 virtual ~wxRegion();
409c9842 57
5a56a532
DW
58 //
59 // Modify region
60 //
61
62 //
409c9842 63 // Clear current region
5a56a532
DW
64 //
65 void Clear(void);
409c9842 66
45e0dc94
DW
67 bool Offset( wxCoord x
68 ,wxCoord y
69 );
70
5a56a532 71 //
409c9842 72 // Union rectangle or region with this.
5a56a532
DW
73 //
74 inline bool Union( wxCoord x
75 ,wxCoord y
76 ,wxCoord vWidth
77 ,wxCoord vHeight
78 )
79 {
80 return Combine( x
81 ,y
82 ,vWidth
83 ,vHeight
84 ,wxRGN_OR
85 );
86 }
87 inline bool Union( const wxRect& rRect) { return Combine(rRect, wxRGN_OR); }
88 inline bool Union(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_OR); }
89
90 //
409c9842 91 // Intersect rectangle or region with this.
5a56a532
DW
92 //
93 inline bool Intersect( wxCoord x
94 ,wxCoord y
95 ,wxCoord vWidth
96 ,wxCoord vHeight
97 )
98 {
99 return Combine( x
100 ,y
101 ,vWidth
102 ,vHeight
103 ,wxRGN_AND
104 );
105 }
106 inline bool Intersect(const wxRect& rRect) { return Combine(rRect, wxRGN_AND); }
107 inline bool Intersect(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_AND); }
108
109 //
409c9842 110 // Subtract rectangle or region from this:
0e320a79 111 // Combines the parts of 'this' that are not part of the second region.
5a56a532
DW
112 //
113 inline bool Subtract( wxCoord x
114 ,wxCoord y
115 ,wxCoord vWidth
116 ,wxCoord vHeight
117 )
118 {
119 return Combine( x
120 ,y
121 ,vWidth
122 ,vHeight
123 ,wxRGN_DIFF
124 );
125 }
126 inline bool Subtract(const wxRect& rRect) { return Combine(rRect, wxRGN_DIFF); }
127 inline bool Subtract(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_DIFF); }
128
129 //
409c9842 130 // XOR: the union of two combined regions except for any overlapping areas.
5a56a532
DW
131 //
132 inline bool Xor( wxCoord x
133 ,wxCoord y
134 ,wxCoord vWidth
135 ,wxCoord vHeight
136 )
137 {
138 return Combine( x
139 ,y
140 ,vWidth
141 ,vHeight
142 ,wxRGN_XOR
143 );
144 }
145 inline bool Xor(const wxRect& rRect) { return Combine(rRect, wxRGN_XOR); }
146 inline bool Xor(const wxRegion& rRegion) { return Combine(rRegion, wxRGN_XOR); }
147
148 //
149 // Information on region
409c9842 150 // Outer bounds of region
5a56a532
DW
151 //
152 void GetBox( wxCoord& rX
153 ,wxCoord& rY
154 ,wxCoord& rWidth
155 ,wxCoord& rHeight
156 ) const;
157 wxRect GetBox(void) const;
158
159 //
409c9842 160 // Is region empty?
5a56a532
DW
161 //
162 bool Empty(void) const;
0e320a79
DW
163 inline bool IsEmpty() const { return Empty(); }
164
5a56a532
DW
165 //
166 // Tests
409c9842 167 // Does the region contain the point (x,y)?
5a56a532 168 //
744c5946
SN
169 inline wxRegionContain Contains( wxCoord lX, wxCoord lY ) const{
170 return Contains( wxPoint( lX, lY ) );
171 }
4f5c180e
DW
172 //
173 // Convert the region to a B&W bitmap with the black pixels being inside
174 // the region.
175 //
176 wxBitmap ConvertToBitmap(void) const;
177
178 // Use the non-transparent pixels of a wxBitmap for the region to combine
85f6b408
VS
179 // with this region. First version takes transparency from bitmap's mask,
180 // second lets the user specify the colour to be treated as transparent
4f5c180e 181 // along with an optional tolerance value.
85f6b408
VS
182 // NOTE: implemented in common/rgncmn.cpp
183 bool Union(const wxBitmap& bmp);
184 bool Union(const wxBitmap& bmp,
185 const wxColour& transColour, int tolerance = 0);
4f5c180e 186
5a56a532 187 //
409c9842 188 // Does the region contain the point pt?
5a56a532
DW
189 //
190 wxRegionContain Contains(const wxPoint& rPoint) const;
191
192 //
409c9842 193 // Does the region contain the rectangle (x, y, w, h)?
5a56a532
DW
194 //
195 wxRegionContain Contains( wxCoord x
196 ,wxCoord y
197 ,wxCoord lWidth
198 ,wxCoord lHeight
199 ) const;
200
201 //
409c9842 202 // Does the region contain the rectangle rect?
5a56a532 203 //
744c5946
SN
204 inline wxRegionContain Contains(const wxRect& rRect) const{
205 return Contains( rRect.x, rRect.y,
206 rRect.GetWidth(), rRect.GetHeight());
207 }
5a56a532
DW
208
209 //
210 // Internal
211 //
212 bool Combine( wxCoord x
213 ,wxCoord y
214 ,wxCoord vWidth
215 ,wxCoord vHeight
216 ,wxRegionOp eOp
217 );
218 bool Combine( const wxRegion& rRegion
219 ,wxRegionOp eOp
220 );
221 bool Combine( const wxRect& rRect
222 ,wxRegionOp eOp
223 );
224
225 //
409c9842 226 // Get internal region handle
5a56a532
DW
227 //
228 WXHRGN GetHRGN(void) const;
229 void SetPS(HPS hPS);
45e0dc94
DW
230
231protected:
232 virtual wxObjectRefData* CreateData(void) const;
107e4338
DW
233 virtual wxObjectRefData* CloneData(const wxObjectRefData* pData) const;
234
45e0dc94
DW
235 friend class WXDLLEXPORT wxRegionIterator;
236 DECLARE_DYNAMIC_CLASS(wxRegion);
237
5a56a532 238}; // end of CLASS wxRegion
0e320a79 239
5a56a532
DW
240class WXDLLEXPORT wxRegionIterator : public wxObject
241{
0e320a79
DW
242DECLARE_DYNAMIC_CLASS(wxRegionIterator);
243public:
409c9842 244 wxRegionIterator();
5a56a532 245 wxRegionIterator(const wxRegion& rRegion);
d3c7fc99 246 virtual ~wxRegionIterator();
0e320a79 247
5a56a532
DW
248 void Reset(void) { m_lCurrent = 0; }
249 void Reset(const wxRegion& rRegion);
0e320a79 250
5a56a532
DW
251 operator bool (void) const { return m_lCurrent < m_lNumRects; }
252 bool HaveRects(void) const { return m_lCurrent < m_lNumRects; }
0e320a79 253
5a56a532 254 void operator ++ (void);
409c9842 255 void operator ++ (int);
0e320a79 256
5a56a532
DW
257 wxCoord GetX(void) const;
258 wxCoord GetY(void) const;
259 wxCoord GetW(void) const;
260 wxCoord GetWidth(void) const { return GetW(); }
261 wxCoord GetH(void) const;
262 wxCoord GetHeight(void) const { return GetH(); }
263 wxRect GetRect(void) const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
0e320a79
DW
264
265private:
5a56a532
DW
266 long m_lCurrent;
267 long m_lNumRects;
268 wxRegion m_vRegion;
269 wxRect* m_pRects;
270}; // end of wxRegionIterator
0e320a79
DW
271
272#endif
409c9842 273 // _WX_REGION_H_