]> git.saurik.com Git - wxWidgets.git/blob - include/wx/msw/region.h
fixed wxDropFilesEvent dtor, added copy ctor and implemented Clone() for it
[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 // Clear current region
63 void Clear(void);
64
65 // Union rectangle or region with this.
66 inline bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
67 inline bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
68 inline bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
69
70 // Intersect rectangle or region with this.
71 inline bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
72 inline bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
73 inline bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
74
75 // Subtract rectangle or region from this:
76 // Combines the parts of 'this' that are not part of the second region.
77 inline bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
78 inline bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
79 inline bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
80
81 // XOR: the union of two combined regions except for any overlapping areas.
82 inline bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
83 inline bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
84 inline bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
85
86 // Information on region
87 // Outer bounds of region
88 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
89 wxRect GetBox(void) const ;
90
91 // Is region empty?
92 bool Empty(void) const;
93 inline bool IsEmpty(void) const { return Empty(); }
94
95 // Tests
96 // Does the region contain the point (x,y)?
97 wxRegionContain Contains(wxCoord x, wxCoord y) const;
98 // Does the region contain the point pt?
99 wxRegionContain Contains(const wxPoint& pt) const;
100 // Does the region contain the rectangle (x, y, w, h)?
101 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
102 // Does the region contain the rectangle rect?
103 wxRegionContain Contains(const wxRect& rect) const;
104
105 // Internal
106 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
107 bool Combine(const wxRegion& region, wxRegionOp op);
108 bool Combine(const wxRect& rect, wxRegionOp op);
109
110 // Get internal region handle
111 WXHRGN GetHRGN() const;
112
113 DECLARE_DYNAMIC_CLASS(wxRegion);
114 friend class WXDLLEXPORT wxRegionIterator;
115 };
116
117 class WXDLLEXPORT wxRegionIterator : public wxObject
118 {
119 public:
120 wxRegionIterator(void);
121 wxRegionIterator(const wxRegion& region);
122 ~wxRegionIterator(void);
123
124 void Reset(void) { m_current = 0; }
125 void Reset(const wxRegion& region);
126
127 #ifndef __SALFORDC__
128 operator bool (void) const { return (m_current < m_numRects); }
129 #endif
130
131 bool HaveRects(void) const { return (m_current < m_numRects); }
132
133 void operator ++ (void);
134 void operator ++ (int);
135
136 wxCoord GetX(void) const;
137 wxCoord GetY(void) const;
138 wxCoord GetW(void) const;
139 wxCoord GetWidth(void) const { return GetW(); }
140 wxCoord GetH(void) const;
141 wxCoord GetHeight(void) const { return GetH(); }
142 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
143
144 private:
145 long m_current;
146 long m_numRects;
147 wxRegion m_region;
148 wxRect* m_rects;
149
150 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
151 };
152
153 #endif
154 // _WX_REGION_H_