]> git.saurik.com Git - wxWidgets.git/blame - include/wx/msw/region.h
Added DoLoadFile, DoSaveFile to wxTextCtrlBase
[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
2bda0e17 15#include "wx/gdiobj.h"
2432b92d 16#include "wx/gdicmn.h"
2bda0e17
KB
17
18class WXDLLEXPORT wxRect;
19class WXDLLEXPORT wxPoint;
20
2bda0e17 21// So far, for internal use only
5549e9f7
VZ
22enum wxRegionOp
23{
24 wxRGN_AND, // Creates the intersection of the two combined regions.
25 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
26 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
27 wxRGN_OR, // Creates the union of two combined regions.
28 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
2bda0e17
KB
29};
30
5549e9f7
VZ
31class WXDLLEXPORT wxRegion : public wxGDIObject
32{
2bda0e17 33public:
5549e9f7 34 wxRegion();
9b1801c1 35 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
2bda0e17
KB
36 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
37 wxRegion(const wxRect& rect);
81d66cf3 38 wxRegion(WXHRGN hRegion); // Hangs on to this region
5549e9f7 39 wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
85f6b408
VS
40 wxRegion( const wxBitmap& bmp)
41 {
42 Union(bmp);
43 }
1542ea39 44 wxRegion( const wxBitmap& bmp,
85f6b408 45 const wxColour& transColour, int tolerance = 0)
1542ea39
RD
46 {
47 Union(bmp, transColour, tolerance);
48 }
2bda0e17 49
5549e9f7 50 virtual ~wxRegion();
2bda0e17 51
5549e9f7 52 // Modify region
0fb067bb
VZ
53 // -------------
54
5549e9f7 55 // Clear current region
0fb067bb
VZ
56 void Clear();
57
58 // Move the region
59 bool Offset(wxCoord x, wxCoord y);
2bda0e17 60
5549e9f7 61 // Union rectangle or region with this.
0fb067bb
VZ
62 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
63 bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
64 bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
2bda0e17 65
5549e9f7 66 // Intersect rectangle or region with this.
0fb067bb
VZ
67 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
68 bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
69 bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
2bda0e17 70
5549e9f7 71 // Subtract rectangle or region from this:
2bda0e17 72 // Combines the parts of 'this' that are not part of the second region.
0fb067bb
VZ
73 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
74 bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
75 bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
5549e9f7
VZ
76
77 // XOR: the union of two combined regions except for any overlapping areas.
0fb067bb
VZ
78 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
79 bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
80 bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
5549e9f7
VZ
81
82 // Information on region
0fb067bb
VZ
83 // ---------------------
84
5549e9f7
VZ
85 // Outer bounds of region
86 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
2b5f62a0 87 wxRect GetBox() const ;
5549e9f7
VZ
88
89 // Is region empty?
2b5f62a0
VZ
90 bool Empty() const;
91 inline bool IsEmpty() const { return Empty(); }
2bda0e17 92
5549e9f7
VZ
93 // Tests
94 // Does the region contain the point (x,y)?
95 wxRegionContain Contains(wxCoord x, wxCoord y) const;
96 // Does the region contain the point pt?
97 wxRegionContain Contains(const wxPoint& pt) const;
98 // Does the region contain the rectangle (x, y, w, h)?
99 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
100 // Does the region contain the rectangle rect?
101 wxRegionContain Contains(const wxRect& rect) const;
2bda0e17 102
819451b6 103 // Convert the region to a B&W bitmap with the white pixels being inside
1542ea39
RD
104 // the region.
105 wxBitmap ConvertToBitmap() const;
106
107 // Use the non-transparent pixels of a wxBitmap for the region to combine
85f6b408
VS
108 // with this region. First version takes transparency from bitmap's mask,
109 // second lets the user specify the colour to be treated as transparent
1542ea39 110 // along with an optional tolerance value.
85f6b408
VS
111 // NOTE: implemented in common/rgncmn.cpp
112 bool Union(const wxBitmap& bmp);
1542ea39 113 bool Union(const wxBitmap& bmp,
85f6b408 114 const wxColour& transColour, int tolerance = 0);
1542ea39 115
2bda0e17 116// Internal
5549e9f7
VZ
117 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
118 bool Combine(const wxRegion& region, wxRegionOp op);
119 bool Combine(const wxRect& rect, wxRegionOp op);
a724d789
JS
120
121 // Get internal region handle
122 WXHRGN GetHRGN() const;
5549e9f7 123
0fb067bb 124protected:
02576308 125 virtual wxObjectRefData *CreateRefData() const;
b8027888 126 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
0fb067bb 127
5549e9f7 128 friend class WXDLLEXPORT wxRegionIterator;
0fb067bb
VZ
129
130 DECLARE_DYNAMIC_CLASS(wxRegion)
2bda0e17
KB
131};
132
5549e9f7
VZ
133class WXDLLEXPORT wxRegionIterator : public wxObject
134{
2bda0e17 135public:
2b5f62a0 136 wxRegionIterator() { Init(); }
5549e9f7 137 wxRegionIterator(const wxRegion& region);
4dddb8a2 138 wxRegionIterator(const wxRegionIterator& ri) : wxObject(ri) { Init(); *this = ri; }
2bda0e17 139
2b5f62a0
VZ
140 wxRegionIterator& operator=(const wxRegionIterator& ri);
141
142 virtual ~wxRegionIterator();
143
144 void Reset() { m_current = 0; }
5549e9f7 145 void Reset(const wxRegion& region);
2bda0e17 146
2b5f62a0
VZ
147 bool HaveRects() const { return (m_current < m_numRects); }
148
a3ef5bf5 149#ifndef __SALFORDC__
2b5f62a0 150 operator bool () const { return HaveRects(); }
a3ef5bf5
JS
151#endif
152
2b5f62a0
VZ
153 wxRegionIterator& operator++();
154 wxRegionIterator operator++(int);
2bda0e17 155
2b5f62a0
VZ
156 wxCoord GetX() const;
157 wxCoord GetY() const;
158 wxCoord GetW() const;
159 wxCoord GetWidth() const { return GetW(); }
160 wxCoord GetH() const;
161 wxCoord GetHeight() const { return GetH(); }
2bda0e17 162
2b5f62a0 163 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
2bda0e17
KB
164
165private:
2b5f62a0
VZ
166 // common part of all ctors
167 void Init();
168
5549e9f7
VZ
169 long m_current;
170 long m_numRects;
171 wxRegion m_region;
2bda0e17 172 wxRect* m_rects;
5549e9f7 173
57de2373 174 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
2bda0e17
KB
175};
176
177#endif
5549e9f7 178 // _WX_REGION_H_