]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/region.h
fixing 'id' objc.h collisions, listbox rewrite
[wxWidgets.git] / include / wx / generic / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/generic/region.h
3 // Purpose: generic wxRegion class
4 // Author: David Elliott
5 // Modified by:
6 // Created: 2004/04/12
7 // RCS-ID: $Id$
8 // Copyright: (c) 2004 David Elliott
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_REGION_H__
13 #define _WX_GENERIC_REGION_H__
14
15 #include "wx/gdiobj.h"
16 #include "wx/gdicmn.h"
17
18 class WXDLLEXPORT wxRect;
19 class WXDLLEXPORT wxPoint;
20
21 enum wxRegionContain
22 { wxOutRegion = 0
23 , wxPartRegion = 1
24 , wxInRegion = 2
25 };
26
27 class WXDLLEXPORT wxRegionGeneric : public wxGDIObject
28 {
29 // DECLARE_DYNAMIC_CLASS(wxRegionGeneric);
30 friend class WXDLLEXPORT wxRegionIteratorGeneric;
31 public:
32 wxRegionGeneric(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
33 wxRegionGeneric(const wxPoint& topLeft, const wxPoint& bottomRight);
34 wxRegionGeneric(const wxRect& rect);
35 wxRegionGeneric();
36 ~wxRegionGeneric();
37
38 bool Ok() const { return m_refData != NULL; }
39
40 bool operator == ( const wxRegionGeneric& region ) const;
41 bool operator != ( const wxRegionGeneric& region ) const { return !(*this == region); }
42
43 //# Modify region
44 // Clear current region
45 void Clear();
46
47 // Move the region
48 bool Offset(wxCoord x, wxCoord y);
49
50 // Union rectangle or region with this.
51 bool Union(long x, long y, long width, long height)
52 { return Union(wxRect(x,y,width,height)); }
53 bool Union(const wxRect& rect);
54 bool Union(const wxRegionGeneric& region);
55
56 // Intersect rectangle or region with this.
57 bool Intersect(long x, long y, long width, long height)
58 { return Intersect(wxRect(x,y,width,height)); }
59 bool Intersect(const wxRect& rect);
60 bool Intersect(const wxRegionGeneric& region);
61
62 // Subtract rectangle or region from this:
63 // Combines the parts of 'this' that are not part of the second region.
64 bool Subtract(long x, long y, long width, long height)
65 { return Subtract(wxRect(x,y,width,height)); }
66 bool Subtract(const wxRect& rect);
67 bool Subtract(const wxRegionGeneric& region);
68
69 // XOR: the union of two combined regions except for any overlapping areas.
70 bool Xor(long x, long y, long width, long height);
71 bool Xor(const wxRect& rect);
72 bool Xor(const wxRegionGeneric& region);
73
74 //# Information on region
75 // Outer bounds of region
76 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
77 wxRect GetBox() const;
78
79 // Is region empty?
80 bool Empty() const;
81 inline bool IsEmpty() const { return Empty(); }
82
83 //# Tests
84 // Does the region contain the point (x,y)?
85 wxRegionContain Contains(long x, long y) const;
86 // Does the region contain the point pt?
87 wxRegionContain Contains(const wxPoint& pt) const;
88 // Does the region contain the rectangle (x, y, w, h)?
89 wxRegionContain Contains(long x, long y, long w, long h) const;
90 // Does the region contain the rectangle rect?
91 wxRegionContain Contains(const wxRect& rect) const;
92
93 protected:
94 virtual wxObjectRefData *CreateRefData() const;
95 virtual wxObjectRefData *CloneRefData(const wxObjectRefData *data) const;
96 };
97
98 class WXDLLEXPORT wxRegionIteratorGeneric : public wxObject
99 {
100 // DECLARE_DYNAMIC_CLASS(wxRegionIteratorGeneric);
101 public:
102 wxRegionIteratorGeneric();
103 wxRegionIteratorGeneric(const wxRegionGeneric& region);
104 wxRegionIteratorGeneric(const wxRegionIteratorGeneric& iterator);
105 ~wxRegionIteratorGeneric();
106
107 wxRegionIteratorGeneric& operator=(const wxRegionIteratorGeneric& iterator);
108
109 void Reset() { m_current = 0; }
110 void Reset(const wxRegionGeneric& region);
111
112 operator bool () const { return HaveRects(); }
113 bool HaveRects() const;
114
115 wxRegionIteratorGeneric& operator++();
116 wxRegionIteratorGeneric operator++(int);
117
118 long GetX() const;
119 long GetY() const;
120 long GetW() const;
121 long GetWidth() const { return GetW(); }
122 long GetH() const;
123 long GetHeight() const { return GetH(); }
124 wxRect GetRect() const;
125 private:
126 long m_current;
127 wxRegionGeneric m_region;
128 };
129
130 #endif //ndef _WX_GENERIC_REGION_H__