]> git.saurik.com Git - wxWidgets.git/blob - include/wx/motif/region.h
applied DBCS patch
[wxWidgets.git] / include / wx / motif / region.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: region.h
3 // Purpose: wxRegion class
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 17/09/98
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 // ----------------------------------------------------------------------------
24 // A list of rectangles type used by wxRegion and wxWindow
25 // ----------------------------------------------------------------------------
26
27 WX_DECLARE_LIST(wxRect, wxRectList);
28
29
30 enum wxRegionContain {
31 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
32 };
33
34 // So far, for internal use only
35 enum wxRegionOp {
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 DECLARE_DYNAMIC_CLASS(wxRegion);
45 friend class WXDLLEXPORT wxRegionIterator;
46 public:
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();
51 ~wxRegion();
52
53 //# Copying
54 inline wxRegion(const wxRegion& r)
55 { Ref(r); }
56 inline wxRegion& operator = (const wxRegion& r)
57 { Ref(r); return (*this); }
58
59 //# Modify region
60 // Clear current region
61 void Clear();
62
63 // Union rectangle or region with this.
64 inline bool Union(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_OR); }
65 inline bool Union(const wxRect& rect) { return Combine(rect, wxRGN_OR); }
66 inline bool Union(const wxRegion& region) { return Combine(region, wxRGN_OR); }
67
68 // Intersect rectangle or region with this.
69 inline bool Intersect(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_AND); }
70 inline bool Intersect(const wxRect& rect) { return Combine(rect, wxRGN_AND); }
71 inline bool Intersect(const wxRegion& region) { return Combine(region, wxRGN_AND); }
72
73 // Subtract rectangle or region from this:
74 // Combines the parts of 'this' that are not part of the second region.
75 inline bool Subtract(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_DIFF); }
76 inline bool Subtract(const wxRect& rect) { return Combine(rect, wxRGN_DIFF); }
77 inline bool Subtract(const wxRegion& region) { return Combine(region, wxRGN_DIFF); }
78
79 // XOR: the union of two combined regions except for any overlapping areas.
80 inline bool Xor(wxCoord x, wxCoord y, wxCoord width, wxCoord height) { return Combine(x, y, width, height, wxRGN_XOR); }
81 inline bool Xor(const wxRect& rect) { return Combine(rect, wxRGN_XOR); }
82 inline bool Xor(const wxRegion& region) { return Combine(region, wxRGN_XOR); }
83
84 //# Information on region
85 // Outer bounds of region
86 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
87 wxRect GetBox() const ;
88
89 // Is region empty?
90 bool Empty() const;
91 inline bool IsEmpty() const { return Empty(); }
92 bool Ok() const { return (m_refData != NULL) ; }
93
94 //# Tests
95 // Does the region contain the point (x,y)?
96 wxRegionContain Contains(wxCoord x, wxCoord y) const;
97 // Does the region contain the point pt?
98 wxRegionContain Contains(const wxPoint& pt) const;
99 // Does the region contain the rectangle (x, y, w, h)?
100 wxRegionContain Contains(wxCoord x, wxCoord y, wxCoord w, wxCoord h) const;
101 // Does the region contain the rectangle rect?
102 wxRegionContain Contains(const wxRect& rect) const;
103
104 // Internal
105 bool Combine(wxCoord x, wxCoord y, wxCoord width, wxCoord height, wxRegionOp op);
106 bool Combine(const wxRegion& region, wxRegionOp op);
107 bool Combine(const wxRect& rect, wxRegionOp op);
108
109 // Get the internal Region handle
110 WXRegion GetXRegion() const;
111
112 // 'Naughty' functions that allow wxWindows to use a list of rects
113 // instead of the region, in certain circumstances (e.g. when
114 // making a region out of the update rectangles).
115 // These are used by wxPaintDC::wxPaintDC and wxRegionIterator::Reset.
116 bool UsingRects() const;
117 wxRect* GetRects();
118 int GetRectCount() const;
119 void SetRects(const wxRectList& rectList);
120 void SetRects(int count, const wxRect* rects);
121 };
122
123 class WXDLLEXPORT wxRegionIterator : public wxObject {
124 DECLARE_DYNAMIC_CLASS(wxRegionIterator);
125 public:
126 wxRegionIterator();
127 wxRegionIterator(const wxRegion& region);
128 ~wxRegionIterator();
129
130 void Reset() { m_current = 0; }
131 void Reset(const wxRegion& region);
132
133 operator bool () const { return m_current < m_numRects; }
134 bool HaveRects() const { return m_current < m_numRects; }
135
136 void operator ++ ();
137 void operator ++ (int);
138
139 wxCoord GetX() const;
140 wxCoord GetY() const;
141 wxCoord GetW() const;
142 wxCoord GetWidth() const { return GetW(); }
143 wxCoord GetH() const;
144 wxCoord GetHeight() const { return GetH(); }
145 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
146
147 private:
148 size_t m_current;
149 size_t m_numRects;
150 wxRegion m_region;
151 wxRect* m_rects;
152 };
153
154 #endif
155 // _WX_REGION_H_