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