]> git.saurik.com Git - wxWidgets.git/blame - include/wx/mac/carbon/region.h
tentative fix for BestSize problems (non-native toolbar)
[wxWidgets.git] / include / wx / mac / carbon / region.h
CommitLineData
8cf73271
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.h
3// Purpose: wxRegion class
4// Author: Stefan Csomor
5// Modified by:
6// Created: 1998-01-01
7// RCS-ID: $Id$
8// Copyright: (c) Stefan Csomor
65571936 9// Licence: wxWindows licence
8cf73271
SC
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
23class WXDLLEXPORT wxRect;
24class WXDLLEXPORT wxPoint;
25
26enum wxRegionContain {
27 wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2
28};
29
30// So far, for internal use only
31enum wxRegionOp {
32wxRGN_AND, // Creates the intersection of the two combined regions.
33wxRGN_COPY, // Creates a copy of the region identified by hrgnSrc1.
34wxRGN_DIFF, // Combines the parts of hrgnSrc1 that are not part of hrgnSrc2.
35wxRGN_OR, // Creates the union of two combined regions.
36wxRGN_XOR // Creates the union of two combined regions except for any overlapping areas.
37};
38
39class WXDLLEXPORT wxRegion : public wxGDIObject {
48456801 40DECLARE_DYNAMIC_CLASS(wxRegion)
8cf73271
SC
41 friend class WXDLLEXPORT wxRegionIterator;
42public:
43 wxRegion(long x, long y, long w, long h);
44 wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight);
45 wxRegion(const wxRect& rect);
46 wxRegion( WXHRGN hRegion );
564cb9de 47 wxRegion(size_t n, const wxPoint *points, int fillStyle = wxODDEVEN_RULE );
8cf73271 48 wxRegion();
85f6b408
VS
49 wxRegion(const wxBitmap& bmp)
50 {
51 Union(bmp);
52 }
53 wxRegion(const wxBitmap& bmp,
54 const wxColour& transColour, int tolerance = 0)
8cf73271
SC
55 {
56 Union(bmp, transColour, tolerance);
57 }
58
59 ~wxRegion();
60
61 //# Copying
62 wxRegion(const wxRegion& r)
63 : wxGDIObject()
64 { Ref(r); }
65 wxRegion& operator = (const wxRegion& r)
66 { Ref(r); return (*this); }
67
68 //# Modify region
69 // Clear current region
70 void Clear();
71
c871c71b
SC
72 // Move the region
73 bool Offset(wxCoord x, wxCoord y);
74
8cf73271
SC
75 // Union rectangle or region with this.
76 bool Union(long x, long y, long width, long height)
77 { return Combine(x, y, width, height, wxRGN_OR); }
78 bool Union(const wxRect& rect)
79 { return Combine(rect, wxRGN_OR); }
80 bool Union(const wxRegion& region)
81 { return Combine(region, wxRGN_OR); }
82
83 // Intersect rectangle or region with this.
84 bool Intersect(long x, long y, long width, long height)
85 { return Combine(x, y, width, height, wxRGN_AND); }
86 bool Intersect(const wxRect& rect)
87 { return Combine(rect, wxRGN_AND); }
88 bool Intersect(const wxRegion& region)
89 { return Combine(region, wxRGN_AND); }
90
91 // Subtract rectangle or region from this:
92 // Combines the parts of 'this' that are not part of the second region.
93 bool Subtract(long x, long y, long width, long height)
94 { return Combine(x, y, width, height, wxRGN_DIFF); }
95 bool Subtract(const wxRect& rect)
96 { return Combine(rect, wxRGN_DIFF); }
97 bool Subtract(const wxRegion& region)
98 { return Combine(region, wxRGN_DIFF); }
99
100 // XOR: the union of two combined regions except for any overlapping areas.
101 bool Xor(long x, long y, long width, long height)
102 { return Combine(x, y, width, height, wxRGN_XOR); }
103 bool Xor(const wxRect& rect)
104 { return Combine(rect, wxRGN_XOR); }
105 bool Xor(const wxRegion& region)
106 { return Combine(region, wxRGN_XOR); }
107
108 //# Information on region
109 // Outer bounds of region
110 void GetBox(wxCoord& x, wxCoord& y, wxCoord&w, wxCoord &h) const;
111 wxRect GetBox() const ;
112
113 // Is region empty?
114 bool Empty() const;
115 inline bool IsEmpty() const { return Empty(); }
116
117 //# Tests
118 // Does the region contain the point (x,y)?
119 wxRegionContain Contains(long x, long y) const;
120 // Does the region contain the point pt?
121 wxRegionContain Contains(const wxPoint& pt) const;
122 // Does the region contain the rectangle (x, y, w, h)?
123 wxRegionContain Contains(long x, long y, long w, long h) const;
124 // Does the region contain the rectangle rect?
125 wxRegionContain Contains(const wxRect& rect) const;
126
127 // Convert the region to a B&W bitmap with the white pixels being inside
128 // the region.
129 wxBitmap ConvertToBitmap() const;
130
131 // Use the non-transparent pixels of a wxBitmap for the region to combine
85f6b408
VS
132 // with this region. First version takes transparency from bitmap's mask,
133 // second lets the user specify the colour to be treated as transparent
8cf73271 134 // along with an optional tolerance value.
85f6b408
VS
135 // NOTE: implemented in common/rgncmn.cpp
136 bool Union(const wxBitmap& bmp);
8cf73271 137 bool Union(const wxBitmap& bmp,
85f6b408 138 const wxColour& transColour, int tolerance = 0);
8cf73271
SC
139
140 // Internal
141 bool Combine(long x, long y, long width, long height, wxRegionOp op);
142 bool Combine(const wxRegion& region, wxRegionOp op);
143 bool Combine(const wxRect& rect, wxRegionOp op);
144 const WXHRGN GetWXHRGN() const ;
145};
146
147class WXDLLEXPORT wxRegionIterator : public wxObject
148{
149 DECLARE_DYNAMIC_CLASS(wxRegionIterator)
150
151public:
152 wxRegionIterator();
153 wxRegionIterator(const wxRegion& region);
154 wxRegionIterator(const wxRegionIterator& iterator);
155 ~wxRegionIterator();
156
157 wxRegionIterator& operator=(const wxRegionIterator& iterator);
158
159 void Reset() { m_current = 0; }
160 void Reset(const wxRegion& region);
161
162 operator bool () const { return m_current < m_numRects; }
163 bool HaveRects() const { return m_current < m_numRects; }
164
165 wxRegionIterator& operator++();
166 wxRegionIterator operator++(int);
167
168 long GetX() const;
169 long GetY() const;
170 long GetW() const;
171 long GetWidth() const { return GetW(); }
172 long GetH() const;
173 long GetHeight() const { return GetH(); }
174 wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); }
175private:
176 void SetRects(long numRects, wxRect *rects);
177
178 long m_current;
179 long m_numRects;
180 wxRegion m_region;
181 wxRect* m_rects;
182};
183
184#endif
185 // _WX_REGION_H_