]> git.saurik.com Git - wxWidgets.git/blob - include/wx/cocoa/region.h
Make DoGetBestSize() always return a width of 100
[wxWidgets.git] / include / wx / cocoa / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: AUTHOR
5 // Modified by:
6 // Created: ??/??/98
7 // RCS-ID: $Id$
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_REGION_H_
13 #define _WX_REGION_H_
14
15 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
28 };
29
30 // So far, for internal use only
31 enum wxRegionOp {
32 wxRGN_AND, // Creates the intersection of the two combined regions.
33 wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
34 wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
35 wxRGN_OR, // Creates the union of two combined regions.
36 wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
37 };
38
39 class WXDLLEXPORT wxRegion : public wxGDIObject {
40 DECLARE_DYNAMIC_CLASS(wxRegion);
41 friend class WXDLLEXPORT wxRegionIterator;
42 public:
43 wxRegion(wxCoord x, wxCoord y, wxCoord w, wxCoord h);
44 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
45 wxRegion(const wxRect& rect);
46 wxRegion();
47 wxRegion( const wxBitmap& bmp,
48 const wxColour& transColour = wxNullColour,
49 int tolerance = 0)
50 {
51 Union(bmp, transColour, tolerance);
52 }
53
54 ~wxRegion();
55
56 //# Copying
57 wxRegion(const wxRegion& r)
58 : wxGDIObject()
59 { Ref(r); }
60 wxRegion& operator = (const wxRegion& r)
61 { Ref(r); return (*this); }
62
63 //# Modify region
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(long x, long y, long width, long height)
72 { return Combine(x, y, width, height, wxRGN_OR); }
73 bool Union(const wxRect& rect)
74 { return Combine(rect, wxRGN_OR); }
75 bool Union(const wxRegion& region)
76 { return Combine(region, wxRGN_OR); }
77
78 // Intersect rectangle or region with this.
79 bool Intersect(long x, long y, long width, long height)
80 { return Combine(x, y, width, height, wxRGN_AND); }
81 bool Intersect(const wxRect& rect)
82 { return Combine(rect, wxRGN_AND); }
83 bool Intersect(const wxRegion& region)
84 { return Combine(region, wxRGN_AND); }
85
86 // Subtract rectangle or region from this:
87 // Combines the parts of 'this' that are not part of the second region.
88 bool Subtract(long x, long y, long width, long height)
89 { return Combine(x, y, width, height, wxRGN_DIFF); }
90 bool Subtract(const wxRect& rect)
91 { return Combine(rect, wxRGN_DIFF); }
92 bool Subtract(const wxRegion& region)
93 { return Combine(region, wxRGN_DIFF); }
94
95 // XOR: the union of two combined regions except for any overlapping areas.
96 bool Xor(long x, long y, long width, long height)
97 { return Combine(x, y, width, height, wxRGN_XOR); }
98 bool Xor(const wxRect& rect)
99 { return Combine(rect, wxRGN_XOR); }
100 bool Xor(const wxRegion& region)
101 { return Combine(region, wxRGN_XOR); }
102
103 //# Information on region
104 // Outer bounds of region
105 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
106 wxRect GetBox() const ;
107
108 // Is region empty?
109 bool Empty() const;
110 inline bool IsEmpty() const { return Empty(); }
111
112 //# Tests
113 // Does the region contain the point (x,y)?
114 wxRegionContain Contains(long x, long y) const;
115 // Does the region contain the point pt?
116 wxRegionContain Contains(const wxPoint& pt) const;
117 // Does the region contain the rectangle (x, y, w, h)?
118 wxRegionContain Contains(long x, long y, long w, long h) const;
119 // Does the region contain the rectangle rect?
120 wxRegionContain Contains(const wxRect& rect) const;
121
122 // Convert the region to a B&W bitmap with the black pixels being inside
123 // the region.
124 wxBitmap ConvertToBitmap() const;
125
126 // Use the non-transparent pixels of a wxBitmap for the region to combine
127 // with this region. If the bitmap has a mask then it will be used,
128 // otherwise the colour to be treated as transparent may be specified,
129 // along with an optional tolerance value.
130 bool Union(const wxBitmap& bmp,
131 const wxColour& transColour = wxNullColour,
132 int tolerance = 0);
133
134
135 // Internal
136 bool Combine(long x, long y, long width, long height, wxRegionOp op);
137 bool Combine(const wxRegion& region, wxRegionOp op);
138 bool Combine(const wxRect& rect, wxRegionOp op);
139 };
140
141 class WXDLLEXPORT wxRegionIterator : public wxObject
142 {
143 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
144
145 public:
146 wxRegionIterator();
147 wxRegionIterator(const wxRegion& region);
148 wxRegionIterator(const wxRegionIterator& iterator);
149 ~wxRegionIterator();
150
151 wxRegionIterator& operator=(const wxRegionIterator& iterator);
152
153 void Reset() { m_current = 0; }
154 void Reset(const wxRegion& region);
155
156 operator bool () const { return m_current < m_numRects; }
157 bool HaveRects() const { return m_current < m_numRects; }
158
159 wxRegionIterator& operator++();
160 wxRegionIterator operator++(int);
161
162 long GetX() const;
163 long GetY() const;
164 long GetW() const;
165 long GetWidth() const { return GetW(); }
166 long GetH() const;
167 long GetHeight() const { return GetH(); }
168 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
169 private:
170 void SetRects(long numRects, wxRect *rects);
171
172 long m_current;
173 long m_numRects;
174 wxRegion m_region;
175 wxRect* m_rects;
176 };
177
178 #endif
179 // _WX_REGION_H_