]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/region.h
more 64 bit correctness fixes
[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$
77ffb593 8// Copyright: (c) 1997-2002 wxWidgets team
65571936 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 );
85f6b408
VS
51 wxRegion( const wxBitmap& bmp)
52 {
53 Union(bmp);
54 }
1542ea39 55 wxRegion( const wxBitmap& bmp,
85f6b408 56 const wxColour& transColour, int tolerance = 0)
1542ea39
RD
57 {
58 Union(bmp, transColour, tolerance);
59 }
2bda0e17 60
5549e9f7 61 virtual ~wxRegion();
2bda0e17 62
5549e9f7 63 // Copying
4dddb8a2 64 wxRegion(const wxRegion& r) : wxGDIObject(r)
5549e9f7
VZ
65 { Ref(r); }
66 wxRegion& operator = (const wxRegion& r)
67 { Ref(r); return (*this); }
2bda0e17 68
5549e9f7 69 // Modify region
0fb067bb
VZ
70 // -------------
71
5549e9f7 72 // Clear current region
0fb067bb
VZ
73 void Clear();
74
75 // Move the region
76 bool Offset(wxCoord x, wxCoord y);
2bda0e17 77
5549e9f7 78 // Union rectangle or region with this.
0fb067bb
VZ
79 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
80 bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
81 bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
2bda0e17 82
5549e9f7 83 // Intersect rectangle or region with this.
0fb067bb
VZ
84 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
85 bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
86 bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
2bda0e17 87
5549e9f7 88 // Subtract rectangle or region from this:
2bda0e17 89 // Combines the parts of 'this' that are not part of the second region.
0fb067bb
VZ
90 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
91 bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
92 bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
5549e9f7
VZ
93
94 // XOR: the union of two combined regions except for any overlapping areas.
0fb067bb
VZ
95 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
96 bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
97 bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
5549e9f7
VZ
98
99 // Information on region
0fb067bb
VZ
100 // ---------------------
101
5549e9f7
VZ
102 // Outer bounds of region
103 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
2b5f62a0 104 wxRect GetBox() const ;
5549e9f7
VZ
105
106 // Is region empty?
2b5f62a0
VZ
107 bool Empty() const;
108 inline bool IsEmpty() const { return Empty(); }
2bda0e17 109
5549e9f7
VZ
110 // Tests
111 // Does the region contain the point (x,y)?
112 wxRegionContain Contains(wxCoord x, wxCoord y) const;
113 // Does the region contain the point pt?
114 wxRegionContain Contains(const wxPoint& pt) const;
115 // Does the region contain the rectangle (x, y, w, h)?
116 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
117 // Does the region contain the rectangle rect?
118 wxRegionContain Contains(const wxRect& rect) const;
2bda0e17 119
819451b6 120 // Convert the region to a B&W bitmap with the white pixels being inside
1542ea39
RD
121 // the region.
122 wxBitmap ConvertToBitmap() const;
123
124 // Use the non-transparent pixels of a wxBitmap for the region to combine
85f6b408
VS
125 // with this region. First version takes transparency from bitmap's mask,
126 // second lets the user specify the colour to be treated as transparent
1542ea39 127 // along with an optional tolerance value.
85f6b408
VS
128 // NOTE: implemented in common/rgncmn.cpp
129 bool Union(const wxBitmap& bmp);
1542ea39 130 bool Union(const wxBitmap& bmp,
85f6b408 131 const wxColour& transColour, int tolerance = 0);
1542ea39 132
2bda0e17 133// Internal
5549e9f7
VZ
134 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
135 bool Combine(const wxRegion& region, wxRegionOp op);
136 bool Combine(const wxRect& rect, wxRegionOp op);
a724d789
JS
137
138 // Get internal region handle
139 WXHRGN GetHRGN() const;
5549e9f7 140
0fb067bb 141protected:
02576308 142 virtual wxObjectRefData *CreateRefData() const;
b8027888 143 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
0fb067bb 144
5549e9f7 145 friend class WXDLLEXPORT wxRegionIterator;
0fb067bb
VZ
146
147 DECLARE_DYNAMIC_CLASS(wxRegion)
2bda0e17
KB
148};
149
5549e9f7
VZ
150class WXDLLEXPORT wxRegionIterator : public wxObject
151{
2bda0e17 152public:
2b5f62a0 153 wxRegionIterator() { Init(); }
5549e9f7 154 wxRegionIterator(const wxRegion& region);
4dddb8a2 155 wxRegionIterator(const wxRegionIterator& ri) : wxObject(ri) { Init(); *this = ri; }
2bda0e17 156
2b5f62a0
VZ
157 wxRegionIterator& operator=(const wxRegionIterator& ri);
158
159 virtual ~wxRegionIterator();
160
161 void Reset() { m_current = 0; }
5549e9f7 162 void Reset(const wxRegion& region);
2bda0e17 163
2b5f62a0
VZ
164 bool HaveRects() const { return (m_current < m_numRects); }
165
a3ef5bf5 166#ifndef __SALFORDC__
2b5f62a0 167 operator bool () const { return HaveRects(); }
a3ef5bf5
JS
168#endif
169
2b5f62a0
VZ
170 wxRegionIterator& operator++();
171 wxRegionIterator operator++(int);
2bda0e17 172
2b5f62a0
VZ
173 wxCoord GetX() const;
174 wxCoord GetY() const;
175 wxCoord GetW() const;
176 wxCoord GetWidth() const { return GetW(); }
177 wxCoord GetH() const;
178 wxCoord GetHeight() const { return GetH(); }
2bda0e17 179
2b5f62a0 180 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
2bda0e17
KB
181
182private:
2b5f62a0
VZ
183 // common part of all ctors
184 void Init();
185
5549e9f7
VZ
186 long m_current;
187 long m_numRects;
188 wxRegion m_region;
2bda0e17 189 wxRect* m_rects;
5549e9f7 190
57de2373 191 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
2bda0e17
KB
192};
193
194#endif
5549e9f7 195 // _WX_REGION_H_