]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/region.h
1. moved InheritAttributes() from wxControl to wxWindow
[wxWidgets.git] / include / wx / msw / region.h
CommitLineData
2bda0e17 1/////////////////////////////////////////////////////////////////////////////
5549e9f7 2// Name: wx/msw/region.h
2bda0e17 3// Purpose: wxRegion class
371a5b4e 4// Author: Julian Smart
2bda0e17
KB
5// Modified by:
6// Created: 01/02/97
7// RCS-ID: $Id$
2b5f62a0 8// Copyright: (c) 1997-2002 wxWindows team
5549e9f7 9// Licence: wxWindows licence
2bda0e17
KB
10/////////////////////////////////////////////////////////////////////////////
11
bbcdf8bc
JS
12#ifndef _WX_REGION_H_
13#define _WX_REGION_H_
2bda0e17 14
12028905 15#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
2b5f62a0 16 #pragma interface "region.h"
2bda0e17
KB
17#endif
18
2bda0e17 19#include "wx/gdiobj.h"
2432b92d 20#include "wx/gdicmn.h"
2bda0e17
KB
21
22class WXDLLEXPORT wxRect;
23class WXDLLEXPORT wxPoint;
24
5549e9f7
VZ
25enum wxRegionContain
26{
27 wxOutRegion = 0,
28 wxPartRegion = 1,
29 wxInRegion = 2
2bda0e17
KB
30};
31
32// So far, for internal use only
5549e9f7
VZ
33enum wxRegionOp
34{
35 wxRGN_AND, // Creates the intersection of the two combined regions.
36 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
37 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
38 wxRGN_OR, // Creates the union of two combined regions.
39 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
2bda0e17
KB
40};
41
5549e9f7
VZ
42class WXDLLEXPORT wxRegion : public wxGDIObject
43{
2bda0e17 44public:
5549e9f7 45 wxRegion();
9b1801c1 46 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
2bda0e17
KB
47 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
48 wxRegion(const wxRect& rect);
81d66cf3 49 wxRegion(WXHRGN hRegion); // Hangs on to this region
5549e9f7 50 wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
1542ea39
RD
51 wxRegion( const wxBitmap& bmp,
52 const wxColour& transColour = wxNullColour,
53 int tolerance = 0)
54 {
55 Union(bmp, transColour, tolerance);
56 }
2bda0e17 57
5549e9f7 58 virtual ~wxRegion();
2bda0e17 59
5549e9f7
VZ
60 // Copying
61 wxRegion(const wxRegion& r)
62 { Ref(r); }
63 wxRegion& operator = (const wxRegion& r)
64 { Ref(r); return (*this); }
2bda0e17 65
5549e9f7 66 // Modify region
0fb067bb
VZ
67 // -------------
68
5549e9f7 69 // Clear current region
0fb067bb
VZ
70 void Clear();
71
72 // Move the region
73 bool Offset(wxCoord x, wxCoord y);
2bda0e17 74
5549e9f7 75 // Union rectangle or region with this.
0fb067bb
VZ
76 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
77 bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
78 bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
2bda0e17 79
5549e9f7 80 // Intersect rectangle or region with this.
0fb067bb
VZ
81 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
82 bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
83 bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
2bda0e17 84
5549e9f7 85 // Subtract rectangle or region from this:
2bda0e17 86 // Combines the parts of 'this' that are not part of the second region.
0fb067bb
VZ
87 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
88 bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
89 bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
5549e9f7
VZ
90
91 // XOR: the union of two combined regions except for any overlapping areas.
0fb067bb
VZ
92 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
93 bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
94 bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
5549e9f7
VZ
95
96 // Information on region
0fb067bb
VZ
97 // ---------------------
98
5549e9f7
VZ
99 // Outer bounds of region
100 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
2b5f62a0 101 wxRect GetBox() const ;
5549e9f7
VZ
102
103 // Is region empty?
2b5f62a0
VZ
104 bool Empty() const;
105 inline bool IsEmpty() const { return Empty(); }
2bda0e17 106
5549e9f7
VZ
107 // Tests
108 // Does the region contain the point (x,y)?
109 wxRegionContain Contains(wxCoord x, wxCoord y) const;
110 // Does the region contain the point pt?
111 wxRegionContain Contains(const wxPoint& pt) const;
112 // Does the region contain the rectangle (x, y, w, h)?
113 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
114 // Does the region contain the rectangle rect?
115 wxRegionContain Contains(const wxRect& rect) const;
2bda0e17 116
819451b6 117 // Convert the region to a B&W bitmap with the white pixels being inside
1542ea39
RD
118 // the region.
119 wxBitmap ConvertToBitmap() const;
120
121 // Use the non-transparent pixels of a wxBitmap for the region to combine
122 // with this region. If the bitmap has a mask then it will be used,
123 // otherwise the colour to be treated as transparent may be specified,
124 // along with an optional tolerance value.
125 bool Union(const wxBitmap& bmp,
126 const wxColour& transColour = wxNullColour,
127 int tolerance = 0);
128
2bda0e17 129// Internal
5549e9f7
VZ
130 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
131 bool Combine(const wxRegion& region, wxRegionOp op);
132 bool Combine(const wxRect& rect, wxRegionOp op);
a724d789
JS
133
134 // Get internal region handle
135 WXHRGN GetHRGN() const;
5549e9f7 136
0fb067bb 137protected:
02576308 138 virtual wxObjectRefData *CreateRefData() const;
b8027888 139 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
0fb067bb 140
5549e9f7 141 friend class WXDLLEXPORT wxRegionIterator;
0fb067bb
VZ
142
143 DECLARE_DYNAMIC_CLASS(wxRegion)
2bda0e17
KB
144};
145
5549e9f7
VZ
146class WXDLLEXPORT wxRegionIterator : public wxObject
147{
2bda0e17 148public:
2b5f62a0 149 wxRegionIterator() { Init(); }
5549e9f7 150 wxRegionIterator(const wxRegion& region);
2b5f62a0 151 wxRegionIterator(const wxRegionIterator& ri) { Init(); *this = ri; }
2bda0e17 152
2b5f62a0
VZ
153 wxRegionIterator& operator=(const wxRegionIterator& ri);
154
155 virtual ~wxRegionIterator();
156
157 void Reset() { m_current = 0; }
5549e9f7 158 void Reset(const wxRegion& region);
2bda0e17 159
2b5f62a0
VZ
160 bool HaveRects() const { return (m_current < m_numRects); }
161
a3ef5bf5 162#ifndef __SALFORDC__
2b5f62a0 163 operator bool () const { return HaveRects(); }
a3ef5bf5
JS
164#endif
165
2b5f62a0
VZ
166 wxRegionIterator& operator++();
167 wxRegionIterator operator++(int);
2bda0e17 168
2b5f62a0
VZ
169 wxCoord GetX() const;
170 wxCoord GetY() const;
171 wxCoord GetW() const;
172 wxCoord GetWidth() const { return GetW(); }
173 wxCoord GetH() const;
174 wxCoord GetHeight() const { return GetH(); }
2bda0e17 175
2b5f62a0 176 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
2bda0e17
KB
177
178private:
2b5f62a0
VZ
179 // common part of all ctors
180 void Init();
181
5549e9f7
VZ
182 long m_current;
183 long m_numRects;
184 wxRegion m_region;
2bda0e17 185 wxRect* m_rects;
5549e9f7 186
57de2373 187 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
2bda0e17
KB
188};
189
190#endif
5549e9f7 191 // _WX_REGION_H_