]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/region.h
forward declare wxMenu
[wxWidgets.git] / include / wx / msw / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/msw/region.h
3 // Purpose: wxRegion class
4 // Author: Markus Holzem, Julian Smart
5 // Modified by:
6 // Created: 01/02/97
7 // RCS-ID: $Id$
8 // Copyright: (c) 1997-2002 wxWindows team
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_
13 #define _WX_REGION_H_
14
15 #ifdef __GNUG__
16 #pragma interface "region.h"
17 #endif
18
19 #include "wx/gdiobj.h"
20 #include "wx/gdicmn.h"
21
22 class WXDLLEXPORT wxRect;
23 class WXDLLEXPORT wxPoint;
24
25 enum wxRegionContain
26 {
27 wxOutRegion = 0,
28 wxPartRegion = 1,
29 wxInRegion = 2
30 };
31
32 // So far, for internal use only
33 enum 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.
40 };
41
42 class WXDLLEXPORT wxRegion : public wxGDIObject
43 {
44 public:
45 wxRegion();
46 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
47 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
48 wxRegion(const wxRect& rect);
49 wxRegion(WXHRGN hRegion); // Hangs on to this region
50 wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
51
52 virtual ~wxRegion();
53
54 // Copying
55 wxRegion(const wxRegion& r)
56 { Ref(r); }
57 wxRegion& operator = (const wxRegion& r)
58 { Ref(r); return (*this); }
59
60 // Modify region
61 // -------------
62
63 // Clear current region
64 void Clear();
65
66 // Move the region
67 bool Offset(wxCoord x, wxCoord y);
68
69 // Union rectangle or region with this.
70 bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
71 bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
72 bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
73
74 // Intersect rectangle or region with this.
75 bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
76 bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
77 bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
78
79 // Subtract rectangle or region from this:
80 // Combines the parts of 'this' that are not part of the second region.
81 bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
82 bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
83 bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
84
85 // XOR: the union of two combined regions except for any overlapping areas.
86 bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
87 bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
88 bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
89
90 // Information on region
91 // ---------------------
92
93 // Outer bounds of region
94 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
95 wxRect GetBox() const ;
96
97 // Is region empty?
98 bool Empty() const;
99 inline bool IsEmpty() const { return Empty(); }
100
101 // Tests
102 // Does the region contain the point (x,y)?
103 wxRegionContain Contains(wxCoord x, wxCoord y) const;
104 // Does the region contain the point pt?
105 wxRegionContain Contains(const wxPoint& pt) const;
106 // Does the region contain the rectangle (x, y, w, h)?
107 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
108 // Does the region contain the rectangle rect?
109 wxRegionContain Contains(const wxRect& rect) const;
110
111 // Internal
112 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
113 bool Combine(const wxRegion& region, wxRegionOp op);
114 bool Combine(const wxRect& rect, wxRegionOp op);
115
116 // Get internal region handle
117 WXHRGN GetHRGN() const;
118
119 protected:
120 virtual wxObjectRefData *CreateRefData() const;
121 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
122
123 friend class WXDLLEXPORT wxRegionIterator;
124
125 DECLARE_DYNAMIC_CLASS(wxRegion)
126 };
127
128 class WXDLLEXPORT wxRegionIterator : public wxObject
129 {
130 public:
131 wxRegionIterator() { Init(); }
132 wxRegionIterator(const wxRegion& region);
133 wxRegionIterator(const wxRegionIterator& ri) { Init(); *this = ri; }
134
135 wxRegionIterator& operator=(const wxRegionIterator& ri);
136
137 virtual ~wxRegionIterator();
138
139 void Reset() { m_current = 0; }
140 void Reset(const wxRegion& region);
141
142 bool HaveRects() const { return (m_current < m_numRects); }
143
144 #ifndef __SALFORDC__
145 operator bool () const { return HaveRects(); }
146 #endif
147
148 wxRegionIterator& operator++();
149 wxRegionIterator operator++(int);
150
151 wxCoord GetX() const;
152 wxCoord GetY() const;
153 wxCoord GetW() const;
154 wxCoord GetWidth() const { return GetW(); }
155 wxCoord GetH() const;
156 wxCoord GetHeight() const { return GetH(); }
157
158 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetW(), GetH()); }
159
160 private:
161 // common part of all ctors
162 void Init();
163
164 long m_current;
165 long m_numRects;
166 wxRegion m_region;
167 wxRect* m_rects;
168
169 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
170 };
171
172 #endif
173 // _WX_REGION_H_