]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // File: region.cpp | |
3 | // Purpose: Region class | |
4 | // Author: David Webster | |
5 | // Modified by: | |
6 | // Created: 10/15/99 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) Davdi Webster | |
9 | // Licence: wxWindows licence | |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // For compilers that support precompilation, includes "wx.h". | |
13 | #include "wx/wxprec.h" | |
14 | ||
15 | #include "wx/os2/region.h" | |
16 | #include "wx/gdicmn.h" | |
17 | ||
18 | #include "wx/window.h" | |
19 | #include "wx/os2/private.h" | |
20 | ||
21 | #if !USE_SHARED_LIBRARY | |
22 | IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) | |
23 | IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) | |
24 | #endif | |
25 | ||
26 | //----------------------------------------------------------------------------- | |
27 | // wxRegionRefData implementation | |
28 | //----------------------------------------------------------------------------- | |
29 | ||
30 | class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { | |
31 | public: | |
32 | wxRegionRefData() | |
33 | { | |
34 | m_region = 0; | |
35 | } | |
36 | ||
37 | wxRegionRefData(const wxRegionRefData& data) | |
38 | { | |
39 | // TODO | |
40 | } | |
41 | ||
42 | ~wxRegionRefData() | |
43 | { | |
44 | // TODO | |
45 | ||
46 | } | |
47 | ||
48 | HRGN m_region; | |
49 | }; | |
50 | ||
51 | #define M_REGION (((wxRegionRefData*)m_refData)->m_region) | |
52 | ||
53 | //----------------------------------------------------------------------------- | |
54 | // wxRegion | |
55 | //----------------------------------------------------------------------------- | |
56 | ||
57 | /*! | |
58 | * Create an empty region. | |
59 | */ | |
60 | wxRegion::wxRegion() | |
61 | { | |
62 | m_refData = new wxRegionRefData; | |
63 | // TODO create empty region | |
64 | } | |
65 | ||
66 | wxRegion::wxRegion(WXHRGN hRegion) | |
67 | { | |
68 | m_refData = new wxRegionRefData; | |
69 | M_REGION = (HRGN) hRegion; | |
70 | } | |
71 | ||
72 | wxRegion::wxRegion(long x, long y, long w, long h) | |
73 | { | |
74 | m_refData = new wxRegionRefData; | |
75 | // TODO create rect region | |
76 | } | |
77 | ||
78 | wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) | |
79 | { | |
80 | m_refData = new wxRegionRefData; | |
81 | // TODO create rect region | |
82 | } | |
83 | ||
84 | wxRegion::wxRegion(const wxRect& rect) | |
85 | { | |
86 | m_refData = new wxRegionRefData; | |
87 | // TODO create rect region | |
88 | } | |
89 | ||
90 | /*! | |
91 | * Destroy the region. | |
92 | */ | |
93 | wxRegion::~wxRegion() | |
94 | { | |
95 | // m_refData unrefed in ~wxObject | |
96 | } | |
97 | ||
98 | //----------------------------------------------------------------------------- | |
99 | //# Modify region | |
100 | //----------------------------------------------------------------------------- | |
101 | ||
102 | //! Clear current region | |
103 | void wxRegion::Clear() | |
104 | { | |
105 | UnRef(); | |
106 | } | |
107 | ||
108 | //! Combine rectangle (x, y, w, h) with this. | |
109 | bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op) | |
110 | { | |
111 | // Don't change shared data | |
112 | if (!m_refData) { | |
113 | m_refData = new wxRegionRefData(); | |
114 | } else if (m_refData->GetRefCount() > 1) { | |
115 | wxRegionRefData* ref = (wxRegionRefData*)m_refData; | |
116 | UnRef(); | |
117 | m_refData = new wxRegionRefData(*ref); | |
118 | } | |
119 | // If ref count is 1, that means it's 'ours' anyway so no action. | |
120 | ||
121 | // TODO create rect region | |
122 | ||
123 | int mode = 0; // TODO platform-specific code | |
124 | switch (op) | |
125 | { | |
126 | case wxRGN_AND: | |
127 | // TODO | |
128 | break ; | |
129 | case wxRGN_OR: | |
130 | // TODO | |
131 | break ; | |
132 | case wxRGN_XOR: | |
133 | // TODO | |
134 | break ; | |
135 | case wxRGN_DIFF: | |
136 | // TODO | |
137 | break ; | |
138 | case wxRGN_COPY: | |
139 | default: | |
140 | // TODO | |
141 | break ; | |
142 | } | |
143 | ||
144 | // TODO do combine region | |
145 | ||
146 | return FALSE; | |
147 | } | |
148 | ||
149 | //! Union /e region with this. | |
150 | bool wxRegion::Combine(const wxRegion& region, wxRegionOp op) | |
151 | { | |
152 | if (region.Empty()) | |
153 | return FALSE; | |
154 | ||
155 | // Don't change shared data | |
156 | if (!m_refData) { | |
157 | m_refData = new wxRegionRefData(); | |
158 | } else if (m_refData->GetRefCount() > 1) { | |
159 | wxRegionRefData* ref = (wxRegionRefData*)m_refData; | |
160 | UnRef(); | |
161 | m_refData = new wxRegionRefData(*ref); | |
162 | } | |
163 | ||
164 | int mode = 0; // TODO platform-specific code | |
165 | switch (op) | |
166 | { | |
167 | case wxRGN_AND: | |
168 | // TODO | |
169 | break ; | |
170 | case wxRGN_OR: | |
171 | // TODO | |
172 | break ; | |
173 | case wxRGN_XOR: | |
174 | // TODO | |
175 | break ; | |
176 | case wxRGN_DIFF: | |
177 | // TODO | |
178 | break ; | |
179 | case wxRGN_COPY: | |
180 | default: | |
181 | // TODO | |
182 | break ; | |
183 | } | |
184 | ||
185 | // TODO combine region | |
186 | ||
187 | return FALSE; | |
188 | } | |
189 | ||
190 | bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) | |
191 | { | |
192 | return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op); | |
193 | } | |
194 | ||
195 | //----------------------------------------------------------------------------- | |
196 | //# Information on region | |
197 | //----------------------------------------------------------------------------- | |
198 | ||
199 | // Outer bounds of region | |
200 | void wxRegion::GetBox(long& x, long& y, long&w, long &h) const | |
201 | { | |
202 | if (m_refData) { | |
203 | // TODO get box | |
204 | } else { | |
205 | x = y = w = h = 0; | |
206 | } | |
207 | } | |
208 | ||
209 | wxRect wxRegion::GetBox() const | |
210 | { | |
211 | long x, y, w, h; | |
212 | GetBox(x, y, w, h); | |
213 | return wxRect(x, y, w, h); | |
214 | } | |
215 | ||
216 | // Is region empty? | |
217 | bool wxRegion::Empty() const | |
218 | { | |
219 | // TODO | |
220 | return FALSE; | |
221 | } | |
222 | ||
223 | //----------------------------------------------------------------------------- | |
224 | //# Tests | |
225 | //----------------------------------------------------------------------------- | |
226 | ||
227 | // Does the region contain the point (x,y)? | |
228 | wxRegionContain wxRegion::Contains(long x, long y) const | |
229 | { | |
230 | bool bOK = FALSE; // temporary | |
231 | if (!m_refData) | |
232 | return wxOutRegion; | |
233 | ||
234 | // TODO. Return wxInRegion if within region. | |
235 | if (bOK) | |
236 | return wxInRegion; | |
237 | return wxOutRegion; | |
238 | } | |
239 | ||
240 | // Does the region contain the point pt? | |
241 | wxRegionContain wxRegion::Contains(const wxPoint& pt) const | |
242 | { | |
243 | bool bOK = FALSE; // temporary | |
244 | if (!m_refData) | |
245 | return wxOutRegion; | |
246 | ||
247 | // TODO. Return wxInRegion if within region. | |
248 | if (bOK) | |
249 | return wxInRegion; | |
250 | else | |
251 | return wxOutRegion; | |
252 | } | |
253 | ||
254 | // Does the region contain the rectangle (x, y, w, h)? | |
255 | wxRegionContain wxRegion::Contains(long x, long y, long w, long h) const | |
256 | { | |
257 | bool bOK = FALSE; // temporary | |
258 | if (!m_refData) | |
259 | return wxOutRegion; | |
260 | ||
261 | // TODO. Return wxInRegion if within region. | |
262 | if (bOK) | |
263 | return wxInRegion; | |
264 | else | |
265 | return wxOutRegion; | |
266 | } | |
267 | ||
268 | // Does the region contain the rectangle rect | |
269 | wxRegionContain wxRegion::Contains(const wxRect& rect) const | |
270 | { | |
271 | if (!m_refData) | |
272 | return wxOutRegion; | |
273 | ||
274 | long x, y, w, h; | |
275 | x = rect.x; | |
276 | y = rect.y; | |
277 | w = rect.GetWidth(); | |
278 | h = rect.GetHeight(); | |
279 | return Contains(x, y, w, h); | |
280 | } | |
281 | ||
282 | // Get internal region handle | |
283 | WXHRGN wxRegion::GetHRGN() const | |
284 | { | |
285 | if (!m_refData) | |
286 | return (WXHRGN) 0; | |
287 | return (WXHRGN) M_REGION; | |
288 | } | |
289 | ||
290 | /////////////////////////////////////////////////////////////////////////////// | |
291 | // // | |
292 | // wxRegionIterator // | |
293 | // // | |
294 | /////////////////////////////////////////////////////////////////////////////// | |
295 | ||
296 | /*! | |
297 | * Initialize empty iterator | |
298 | */ | |
299 | wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL) | |
300 | { | |
301 | } | |
302 | ||
303 | wxRegionIterator::~wxRegionIterator() | |
304 | { | |
305 | if (m_rects) | |
306 | delete[] m_rects; | |
307 | } | |
308 | ||
309 | /*! | |
310 | * Initialize iterator for region | |
311 | */ | |
312 | wxRegionIterator::wxRegionIterator(const wxRegion& region) | |
313 | { | |
314 | m_rects = NULL; | |
315 | ||
316 | Reset(region); | |
317 | } | |
318 | ||
319 | /*! | |
320 | * Reset iterator for a new /e region. | |
321 | */ | |
322 | void wxRegionIterator::Reset(const wxRegion& region) | |
323 | { | |
324 | m_current = 0; | |
325 | m_region = region; | |
326 | ||
327 | if (m_rects) | |
328 | delete[] m_rects; | |
329 | ||
330 | m_rects = NULL; | |
331 | ||
332 | if (m_region.Empty()) | |
333 | m_numRects = 0; | |
334 | else | |
335 | { | |
336 | // TODO create m_rects and fill with rectangles for this region | |
337 | m_numRects = 0; | |
338 | } | |
339 | } | |
340 | ||
341 | /*! | |
342 | * Increment iterator. The rectangle returned is the one after the | |
343 | * incrementation. | |
344 | */ | |
345 | void wxRegionIterator::operator ++ () | |
346 | { | |
347 | if (m_current < m_numRects) | |
348 | ++m_current; | |
349 | } | |
350 | ||
351 | /*! | |
352 | * Increment iterator. The rectangle returned is the one before the | |
353 | * incrementation. | |
354 | */ | |
355 | void wxRegionIterator::operator ++ (int) | |
356 | { | |
357 | if (m_current < m_numRects) | |
358 | ++m_current; | |
359 | } | |
360 | ||
361 | long wxRegionIterator::GetX() const | |
362 | { | |
363 | if (m_current < m_numRects) | |
364 | return m_rects[m_current].x; | |
365 | return 0; | |
366 | } | |
367 | ||
368 | long wxRegionIterator::GetY() const | |
369 | { | |
370 | if (m_current < m_numRects) | |
371 | return m_rects[m_current].y; | |
372 | return 0; | |
373 | } | |
374 | ||
375 | long wxRegionIterator::GetW() const | |
376 | { | |
377 | if (m_current < m_numRects) | |
378 | return m_rects[m_current].width ; | |
379 | return 0; | |
380 | } | |
381 | ||
382 | long wxRegionIterator::GetH() const | |
383 | { | |
384 | if (m_current < m_numRects) | |
385 | return m_rects[m_current].height; | |
386 | return 0; | |
387 | } | |
388 |