]>
Commit | Line | Data |
---|---|---|
0e320a79 DW |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // File: region.cpp | |
3 | // Purpose: Region class | |
409c9842 DW |
4 | // Author: David Webster |
5 | // Modified by: | |
6 | // Created: 10/15/99 | |
19193a2c | 7 | // RCS-ID: $Id$ |
409c9842 | 8 | // Copyright: (c) Davdi Webster |
0e320a79 DW |
9 | // Licence: wxWindows licence |
10 | ///////////////////////////////////////////////////////////////////////////// | |
11 | ||
409c9842 DW |
12 | // For compilers that support precompilation, includes "wx.h". |
13 | #include "wx/wxprec.h" | |
0e320a79 | 14 | |
3417f661 | 15 | #include "wx/app.h" |
409c9842 | 16 | #include "wx/os2/region.h" |
0e320a79 DW |
17 | #include "wx/gdicmn.h" |
18 | ||
409c9842 DW |
19 | #include "wx/window.h" |
20 | #include "wx/os2/private.h" | |
21 | ||
19193a2c KB |
22 | IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) |
23 | IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) | |
0e320a79 DW |
24 | |
25 | //----------------------------------------------------------------------------- | |
26 | // wxRegionRefData implementation | |
27 | //----------------------------------------------------------------------------- | |
28 | ||
29 | class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { | |
30 | public: | |
409c9842 DW |
31 | wxRegionRefData() |
32 | { | |
8d854fa9 | 33 | m_hRegion = 0; |
19193a2c | 34 | m_hPS = 0; |
409c9842 | 35 | } |
0e320a79 | 36 | |
8d854fa9 | 37 | wxRegionRefData(const wxRegionRefData& rData) |
409c9842 | 38 | { |
8d854fa9 DW |
39 | RGNRECT vRgnData; |
40 | PRECTL pRect = NULL; | |
41 | ||
53e8757b | 42 | vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT; |
8d854fa9 DW |
43 | if (::GpiQueryRegionRects( rData.m_hPS // Pres space |
44 | ,rData.m_hRegion // Handle of region to query | |
45 | ,NULL // Return all RECTs | |
46 | ,&vRgnData // Will contain number or RECTs in region | |
47 | ,NULL // NULL to return number of RECTs | |
48 | )) | |
49 | { | |
50 | pRect = new RECTL[vRgnData.crcReturned]; | |
51 | vRgnData.crc = vRgnData.crcReturned; | |
52 | vRgnData.ircStart = 1; | |
53 | if (::GpiQueryRegionRects( rData.m_hPS // Pres space of source | |
54 | ,rData.m_hRegion // Handle of source region | |
55 | ,NULL // Return all RECTs | |
56 | ,&vRgnData // Operations set to return rects | |
57 | ,pRect // Will contain the actual RECTS | |
58 | )) | |
59 | { | |
60 | m_hRegion = ::GpiCreateRegion( rData.m_hPS | |
61 | ,vRgnData.crcReturned | |
62 | ,pRect | |
63 | ); | |
64 | m_hPS = rData.m_hPS; | |
65 | } | |
66 | delete [] pRect; | |
67 | } | |
409c9842 | 68 | } |
0e320a79 | 69 | |
409c9842 DW |
70 | ~wxRegionRefData() |
71 | { | |
8d854fa9 | 72 | ::GpiDestroyRegion(m_hPS, m_hRegion); |
409c9842 | 73 | } |
04701dd9 | 74 | |
8d854fa9 DW |
75 | HRGN m_hRegion; |
76 | HPS m_hPS; | |
0e320a79 DW |
77 | }; |
78 | ||
8d854fa9 | 79 | #define M_REGION (((wxRegionRefData*)m_refData)->m_hRegion) |
6ed98c6a | 80 | #define M_REGION_OF(rgn) (((wxRegionRefData*)(rgn.m_refData))->m_hRegion) |
0e320a79 DW |
81 | |
82 | //----------------------------------------------------------------------------- | |
83 | // wxRegion | |
84 | //----------------------------------------------------------------------------- | |
85 | ||
86 | /*! | |
87 | * Create an empty region. | |
88 | */ | |
89 | wxRegion::wxRegion() | |
90 | { | |
91 | m_refData = new wxRegionRefData; | |
8d854fa9 | 92 | } // end of wxRegion::wxRegion |
0e320a79 | 93 | |
8d854fa9 | 94 | wxRegion::wxRegion( |
19193a2c KB |
95 | WXHRGN hRegion, |
96 | WXHDC hPS | |
8d854fa9 | 97 | ) |
409c9842 DW |
98 | { |
99 | m_refData = new wxRegionRefData; | |
100 | M_REGION = (HRGN) hRegion; | |
19193a2c | 101 | (((wxRegionRefData*)m_refData)->m_hPS) = hPS; |
8d854fa9 DW |
102 | } // end of wxRegion::wxRegion |
103 | ||
104 | wxRegion::wxRegion( | |
105 | wxCoord x | |
106 | , wxCoord y | |
107 | , wxCoord vWidth | |
108 | , wxCoord vHeight | |
109 | ) | |
0e320a79 | 110 | { |
8d854fa9 DW |
111 | RECTL vRect; |
112 | SIZEL vSize = {0, 0}; | |
113 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
114 | HDC hDC = ::DevOpenDC( vHabmain | |
115 | ,OD_MEMORY | |
116 | ,"*" | |
117 | ,5L | |
118 | ,(PDEVOPENDATA)&vDop | |
119 | ,NULLHANDLE | |
120 | ); | |
121 | ||
122 | ||
123 | vRect.xLeft = x; | |
124 | vRect.xRight = x + vWidth; | |
125 | vRect.yBottom = y; | |
126 | vRect.yTop = y + vHeight; | |
127 | ||
128 | m_refData = new wxRegionRefData; | |
129 | ||
130 | // | |
131 | // Need a PS to create a Region | |
132 | // | |
133 | ((wxRegionRefData*)m_refData)->m_hPS = ::GpiCreatePS( vHabmain | |
134 | ,hDC | |
135 | ,&vSize | |
136 | ,PU_PELS | GPIT_MICRO | GPIA_ASSOC | |
137 | ); | |
138 | M_REGION = ::GpiCreateRegion( ((wxRegionRefData*)m_refData)->m_hPS | |
139 | ,1 | |
140 | ,&vRect | |
141 | ); | |
142 | } // end of wxRegion::wxRegion | |
143 | ||
144 | wxRegion::wxRegion( | |
145 | const wxPoint& rTopLeft | |
146 | , const wxPoint& rBottomRight | |
147 | ) | |
0e320a79 | 148 | { |
8d854fa9 DW |
149 | RECTL vRect; |
150 | SIZEL vSize = {0, 0}; | |
151 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
152 | HDC hDC = ::DevOpenDC( vHabmain | |
153 | ,OD_MEMORY | |
154 | ,"*" | |
155 | ,5L | |
156 | ,(PDEVOPENDATA)&vDop | |
157 | ,NULLHANDLE | |
158 | ); | |
159 | ||
160 | vRect.xLeft = rTopLeft.x; | |
161 | vRect.xRight = rBottomRight.x; | |
162 | vRect.yBottom = rBottomRight.y; | |
163 | vRect.yTop = rTopLeft.y; | |
164 | ||
165 | m_refData = new wxRegionRefData; | |
166 | ||
167 | // | |
168 | // Need a PS to create a Region | |
169 | // | |
170 | ((wxRegionRefData*)m_refData)->m_hPS = ::GpiCreatePS( vHabmain | |
171 | ,hDC | |
172 | ,&vSize | |
173 | ,PU_PELS | GPIT_MICRO | GPIA_ASSOC | |
174 | ); | |
175 | M_REGION = ::GpiCreateRegion( ((wxRegionRefData*)m_refData)->m_hPS | |
176 | ,1 | |
177 | ,&vRect | |
178 | ); | |
179 | } // end of wxRegion::wxRegion | |
180 | ||
181 | wxRegion::wxRegion( | |
182 | const wxRect& rRect | |
183 | ) | |
0e320a79 | 184 | { |
8d854fa9 DW |
185 | RECTL vRect; |
186 | SIZEL vSize = {0, 0}; | |
187 | DEVOPENSTRUC vDop = {0L, "DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L}; | |
188 | HDC hDC = ::DevOpenDC( vHabmain | |
189 | ,OD_MEMORY | |
190 | ,"*" | |
191 | ,5L | |
192 | ,(PDEVOPENDATA)&vDop | |
193 | ,NULLHANDLE | |
194 | ); | |
195 | ||
196 | ||
197 | vRect.xLeft = rRect.x; | |
198 | vRect.xRight = rRect.x + rRect.width; | |
199 | vRect.yBottom = rRect.y; | |
200 | vRect.yTop = rRect.y + rRect.height; | |
201 | ||
202 | m_refData = new wxRegionRefData; | |
203 | ||
204 | // | |
205 | // Need a PS to create a Region | |
206 | // | |
207 | ((wxRegionRefData*)m_refData)->m_hPS = ::GpiCreatePS( vHabmain | |
208 | ,hDC | |
209 | ,&vSize | |
210 | ,PU_PELS | GPIT_MICRO | GPIA_ASSOC | |
211 | ); | |
212 | M_REGION = ::GpiCreateRegion( ((wxRegionRefData*)m_refData)->m_hPS | |
213 | ,1 | |
214 | ,&vRect | |
215 | ); | |
216 | } // end of wxRegion::wxRegion | |
217 | ||
218 | // | |
219 | // Destroy the region. | |
220 | // | |
0e320a79 DW |
221 | wxRegion::~wxRegion() |
222 | { | |
8d854fa9 | 223 | } // end of wxRegion::~wxRegion |
0e320a79 | 224 | |
58238121 DW |
225 | wxObjectRefData *wxRegion::CreateData() const |
226 | { | |
227 | return new wxRegionRefData; | |
228 | } | |
229 | ||
70b7bcd1 | 230 | wxObjectRefData *wxRegion::CloneData(const wxObjectRefData *data) const |
58238121 DW |
231 | { |
232 | return new wxRegionRefData(*(wxRegionRefData *)data); | |
233 | } | |
234 | ||
0e320a79 DW |
235 | //----------------------------------------------------------------------------- |
236 | //# Modify region | |
237 | //----------------------------------------------------------------------------- | |
238 | ||
58238121 DW |
239 | bool wxRegion::Offset( |
240 | wxCoord x | |
241 | , wxCoord y | |
242 | ) | |
243 | { | |
244 | if ( !x && !y ) | |
245 | { | |
246 | // nothing to do | |
247 | return TRUE; | |
248 | } | |
249 | ||
250 | AllocExclusive(); | |
251 | ||
252 | #if 0 | |
253 | if ( ::OffsetRgn(GetHrgn(), x, y) == ERROR ) | |
254 | { | |
255 | wxLogLastError(_T("OffsetRgn")); | |
256 | ||
257 | return FALSE; | |
258 | } | |
259 | #endif | |
260 | return TRUE; | |
261 | } | |
262 | ||
8d854fa9 DW |
263 | // |
264 | // Clear current region | |
265 | // | |
0e320a79 DW |
266 | void wxRegion::Clear() |
267 | { | |
268 | UnRef(); | |
8d854fa9 DW |
269 | } // end of wxRegion::Clear |
270 | ||
271 | // | |
272 | // Combine rectangle (x, y, w, h) with this. | |
273 | // | |
274 | bool wxRegion::Combine( | |
275 | wxCoord x | |
276 | , wxCoord y | |
277 | , wxCoord vWidth | |
278 | , wxCoord vHeight | |
279 | , wxRegionOp eOp | |
280 | ) | |
0e320a79 | 281 | { |
6ed98c6a | 282 | return Combine(wxRegion(x, y, vWidth, vHeight), eOp); |
8d854fa9 DW |
283 | } // end of wxRegion::Combine |
284 | ||
285 | // | |
286 | // Union region with this. | |
287 | // | |
288 | bool wxRegion::Combine( | |
289 | const wxRegion& rRegion | |
290 | , wxRegionOp eOp | |
291 | ) | |
0e320a79 | 292 | { |
6ed98c6a DW |
293 | // |
294 | // We can't use the API functions if we don't have a valid region handle | |
295 | // | |
296 | if (!m_refData) | |
297 | { | |
298 | // combining with an empty/invalid region works differently depending | |
299 | // on the operation | |
300 | switch (eOp) | |
301 | { | |
302 | case wxRGN_COPY: | |
303 | case wxRGN_OR: | |
304 | case wxRGN_XOR: | |
305 | *this = rRegion; | |
306 | break; | |
307 | ||
308 | default: | |
309 | wxFAIL_MSG( _T("unknown region operation") ); | |
310 | // fall through | |
311 | ||
312 | case wxRGN_AND: | |
313 | case wxRGN_DIFF: | |
314 | // leave empty/invalid | |
315 | return FALSE; | |
316 | } | |
317 | } | |
318 | else // we have a valid region | |
319 | { | |
0e320a79 | 320 | |
6ed98c6a | 321 | LONG lMode = 0; |
8d854fa9 | 322 | |
6ed98c6a DW |
323 | switch (eOp) |
324 | { | |
325 | case wxRGN_AND: | |
326 | lMode = CRGN_AND; | |
327 | break; | |
328 | ||
329 | case wxRGN_OR: | |
330 | lMode = CRGN_OR; | |
331 | break; | |
332 | ||
333 | case wxRGN_XOR: | |
334 | lMode = CRGN_XOR; | |
335 | break; | |
336 | ||
337 | case wxRGN_DIFF: | |
338 | lMode = CRGN_DIFF; | |
339 | break; | |
340 | ||
341 | case wxRGN_COPY: | |
342 | default: | |
343 | lMode = CRGN_COPY; | |
344 | break; | |
345 | } | |
346 | return (::GpiCombineRegion( ((wxRegionRefData*)rRegion.m_refData)->m_hPS | |
347 | ,M_REGION | |
348 | ,M_REGION | |
349 | ,((wxRegionRefData*)rRegion.m_refData)->m_hRegion | |
350 | ,lMode | |
351 | ) != RGN_ERROR); | |
0e320a79 | 352 | } |
6ed98c6a | 353 | return TRUE; |
8d854fa9 DW |
354 | } // end of wxRegion::Combine |
355 | ||
356 | bool wxRegion::Combine( | |
357 | const wxRect& rRect | |
358 | , wxRegionOp eOp | |
359 | ) | |
0e320a79 | 360 | { |
8d854fa9 DW |
361 | return Combine( rRect.GetLeft() |
362 | ,rRect.GetTop() | |
363 | ,rRect.GetWidth() | |
364 | ,rRect.GetHeight() | |
365 | ,eOp | |
366 | ); | |
367 | } // end of wxRegion::Combine | |
0e320a79 DW |
368 | |
369 | //----------------------------------------------------------------------------- | |
370 | //# Information on region | |
371 | //----------------------------------------------------------------------------- | |
372 | ||
8d854fa9 | 373 | // |
0e320a79 | 374 | // Outer bounds of region |
8d854fa9 DW |
375 | // |
376 | void wxRegion::GetBox( | |
377 | wxCoord& x | |
378 | , wxCoord& y | |
379 | , wxCoord& vWidth | |
380 | , wxCoord& vHeight | |
381 | ) const | |
0e320a79 | 382 | { |
8d854fa9 DW |
383 | if (m_refData) |
384 | { | |
385 | RECTL vRect; | |
19193a2c | 386 | APIRET rc; |
8d854fa9 | 387 | |
19193a2c | 388 | rc = ::GpiQueryRegionBox( ((wxRegionRefData*)m_refData)->m_hPS |
8d854fa9 DW |
389 | ,M_REGION |
390 | ,&vRect | |
391 | ); | |
392 | x = vRect.xLeft; | |
4a46a5df | 393 | y = vRect.yBottom; |
8d854fa9 DW |
394 | vWidth = vRect.xRight - vRect.xLeft; |
395 | vHeight = vRect.yTop - vRect.yBottom; | |
409c9842 | 396 | } |
8d854fa9 DW |
397 | else |
398 | { | |
399 | x = y = vWidth = vHeight = 0L; | |
400 | } | |
401 | } // end of wxRegion::GetBox | |
0e320a79 DW |
402 | |
403 | wxRect wxRegion::GetBox() const | |
404 | { | |
0b7e7739 | 405 | wxCoord x, y, w, h; |
0e320a79 DW |
406 | GetBox(x, y, w, h); |
407 | return wxRect(x, y, w, h); | |
408 | } | |
409 | ||
8d854fa9 | 410 | // |
0e320a79 | 411 | // Is region empty? |
8d854fa9 | 412 | // |
0e320a79 DW |
413 | bool wxRegion::Empty() const |
414 | { | |
8d854fa9 DW |
415 | wxCoord x; |
416 | wxCoord y; | |
417 | wxCoord vWidth; | |
418 | wxCoord vHeight; | |
419 | ||
420 | if (M_REGION == 0) | |
421 | return TRUE; | |
422 | ||
423 | GetBox( x | |
424 | ,y | |
425 | ,vWidth | |
426 | ,vHeight | |
427 | ); | |
428 | return ((vWidth == 0) && (vHeight == 0)); | |
429 | } // end of wxRegion::Empty | |
0e320a79 DW |
430 | |
431 | //----------------------------------------------------------------------------- | |
8d854fa9 | 432 | // Tests |
0e320a79 DW |
433 | //----------------------------------------------------------------------------- |
434 | ||
8d854fa9 | 435 | // |
0e320a79 | 436 | // Does the region contain the point (x,y)? |
8d854fa9 DW |
437 | wxRegionContain wxRegion::Contains( |
438 | wxCoord x | |
439 | , wxCoord y | |
440 | ) const | |
0e320a79 | 441 | { |
8d854fa9 DW |
442 | POINTL vPoint; |
443 | ||
444 | vPoint.x = x; | |
445 | vPoint.y = y; | |
446 | ||
409c9842 DW |
447 | if (!m_refData) |
448 | return wxOutRegion; | |
0e320a79 | 449 | |
8d854fa9 DW |
450 | LONG lInside = ::GpiPtInRegion( ((wxRegionRefData*)m_refData)->m_hPS |
451 | ,M_REGION | |
452 | ,&vPoint | |
453 | ); | |
454 | if (lInside == PRGN_INSIDE) | |
0e320a79 DW |
455 | return wxInRegion; |
456 | return wxOutRegion; | |
8d854fa9 | 457 | } // end of wxRegion::Contains |
0e320a79 | 458 | |
8d854fa9 | 459 | // |
0e320a79 | 460 | // Does the region contain the point pt? |
8d854fa9 DW |
461 | // |
462 | wxRegionContain wxRegion::Contains( | |
463 | const wxPoint& rPoint | |
464 | ) const | |
0e320a79 | 465 | { |
8d854fa9 DW |
466 | POINTL vPoint = { rPoint.x, rPoint.y }; |
467 | ||
409c9842 DW |
468 | if (!m_refData) |
469 | return wxOutRegion; | |
0e320a79 | 470 | |
8d854fa9 DW |
471 | LONG lInside = ::GpiPtInRegion( ((wxRegionRefData*)m_refData)->m_hPS |
472 | ,M_REGION | |
473 | ,&vPoint | |
474 | ); | |
475 | if (lInside == PRGN_INSIDE) | |
0e320a79 DW |
476 | return wxInRegion; |
477 | else | |
478 | return wxOutRegion; | |
8d854fa9 | 479 | } // end of wxRegion::Contains |
0e320a79 | 480 | |
8d854fa9 | 481 | // |
0e320a79 | 482 | // Does the region contain the rectangle (x, y, w, h)? |
8d854fa9 DW |
483 | // |
484 | wxRegionContain wxRegion::Contains( | |
485 | wxCoord x | |
486 | , wxCoord y | |
487 | , wxCoord vWidth | |
488 | , wxCoord vHeight | |
489 | ) const | |
0e320a79 | 490 | { |
8d854fa9 DW |
491 | RECTL vRect; |
492 | ||
409c9842 DW |
493 | if (!m_refData) |
494 | return wxOutRegion; | |
0e320a79 | 495 | |
8d854fa9 DW |
496 | vRect.xLeft = x; |
497 | vRect.yTop = y; | |
498 | vRect.xRight = x + vWidth; | |
499 | vRect.yBottom = y + vHeight; | |
500 | ||
501 | if (PRGN_INSIDE == ::GpiRectInRegion( ((wxRegionRefData*)m_refData)->m_hPS | |
502 | ,M_REGION | |
503 | ,&vRect | |
504 | )) | |
0e320a79 DW |
505 | return wxInRegion; |
506 | else | |
507 | return wxOutRegion; | |
8d854fa9 | 508 | } // end of wxRegion::Contains |
0e320a79 | 509 | |
8d854fa9 | 510 | // |
0e320a79 | 511 | // Does the region contain the rectangle rect |
8d854fa9 DW |
512 | // |
513 | wxRegionContain wxRegion::Contains( | |
514 | const wxRect& rRect | |
515 | ) const | |
0e320a79 | 516 | { |
409c9842 DW |
517 | if (!m_refData) |
518 | return wxOutRegion; | |
0e320a79 | 519 | |
8d854fa9 DW |
520 | wxCoord x; |
521 | wxCoord y; | |
522 | wxCoord vWidth; | |
523 | wxCoord vHeight; | |
524 | ||
525 | x = rRect.x; | |
526 | y = rRect.y; | |
527 | vWidth = rRect.GetWidth(); | |
528 | vHeight = rRect.GetHeight(); | |
529 | return Contains( x | |
530 | ,y | |
531 | ,vWidth | |
532 | ,vHeight | |
533 | ); | |
534 | } // end of wxRegion::Contains | |
535 | ||
536 | // | |
409c9842 | 537 | // Get internal region handle |
8d854fa9 | 538 | // |
409c9842 DW |
539 | WXHRGN wxRegion::GetHRGN() const |
540 | { | |
541 | if (!m_refData) | |
542 | return (WXHRGN) 0; | |
543 | return (WXHRGN) M_REGION; | |
544 | } | |
545 | ||
44227537 DW |
546 | // |
547 | // Set a new PS, this means we have to recreate the old region in the new | |
548 | // PS | |
549 | // | |
550 | void wxRegion::SetPS( | |
551 | HPS hPS | |
552 | ) | |
553 | { | |
554 | RGNRECT vRgnData; | |
555 | PRECTL pRect = NULL; | |
556 | ||
53e8757b | 557 | vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT; |
44227537 DW |
558 | if (::GpiQueryRegionRects( ((wxRegionRefData*)m_refData)->m_hPS |
559 | ,((wxRegionRefData*)m_refData)->m_hRegion | |
560 | ,NULL | |
561 | ,&vRgnData | |
562 | ,NULL | |
563 | )) | |
564 | { | |
565 | pRect = new RECTL[vRgnData.crcReturned]; | |
566 | vRgnData.crc = vRgnData.crcReturned; | |
567 | vRgnData.ircStart = 1; | |
568 | if (::GpiQueryRegionRects( ((wxRegionRefData*)m_refData)->m_hPS | |
569 | ,((wxRegionRefData*)m_refData)->m_hRegion | |
570 | ,NULL | |
571 | ,&vRgnData | |
572 | ,pRect | |
573 | )) | |
574 | { | |
575 | // | |
576 | // First destroy the region out of the old PS | |
577 | // and then create it in the new and set the new to current | |
578 | // | |
579 | ::GpiDestroyRegion( ((wxRegionRefData*)m_refData)->m_hPS | |
580 | ,M_REGION | |
581 | ); | |
582 | ((wxRegionRefData*)m_refData)->m_hRegion = ::GpiCreateRegion( hPS | |
583 | ,vRgnData.crcReturned | |
584 | ,pRect | |
585 | ); | |
586 | ((wxRegionRefData*)m_refData)->m_hPS = hPS; | |
587 | } | |
588 | delete [] pRect; | |
589 | } | |
590 | } // end of wxRegion::SetPS | |
591 | ||
0e320a79 | 592 | /////////////////////////////////////////////////////////////////////////////// |
409c9842 DW |
593 | // // |
594 | // wxRegionIterator // | |
595 | // // | |
0e320a79 DW |
596 | /////////////////////////////////////////////////////////////////////////////// |
597 | ||
8d854fa9 DW |
598 | // |
599 | // Initialize empty iterator | |
600 | // | |
601 | wxRegionIterator::wxRegionIterator() | |
602 | : m_lCurrent(0) | |
603 | , m_lNumRects(0) | |
604 | , m_pRects(NULL) | |
0e320a79 | 605 | { |
8d854fa9 | 606 | } // end of wxRegionIterator::wxRegionIterator |
0e320a79 DW |
607 | |
608 | wxRegionIterator::~wxRegionIterator() | |
609 | { | |
8d854fa9 DW |
610 | if (m_pRects) |
611 | delete[] m_pRects; | |
612 | } // end of wxRegionIterator::~wxRegionIterator | |
613 | ||
614 | // | |
615 | // Initialize iterator for region | |
616 | // | |
617 | wxRegionIterator::wxRegionIterator( | |
618 | const wxRegion& rRegion | |
619 | ) | |
0e320a79 | 620 | { |
8d854fa9 DW |
621 | m_pRects = NULL; |
622 | Reset(rRegion); | |
623 | } // end of wxRegionIterator::wxRegionIterator | |
624 | ||
625 | // | |
626 | // Reset iterator for a new /e region. | |
627 | // | |
628 | void wxRegionIterator::Reset( | |
629 | const wxRegion& rRegion | |
630 | ) | |
0e320a79 | 631 | { |
8d854fa9 | 632 | m_lCurrent = 0; |
0b483d6e | 633 | m_lNumRects = 0; |
8d854fa9 | 634 | m_vRegion = rRegion; |
0e320a79 | 635 | |
8d854fa9 DW |
636 | if (m_pRects) |
637 | delete[] m_pRects; | |
0e320a79 | 638 | |
8d854fa9 | 639 | m_pRects = NULL; |
0e320a79 | 640 | |
8d854fa9 DW |
641 | if (m_vRegion.Empty()) |
642 | m_lNumRects = 0; | |
409c9842 | 643 | else |
0e320a79 | 644 | { |
8d854fa9 DW |
645 | RGNRECT vRgnData; |
646 | PRECTL pRect; | |
647 | ||
53e8757b | 648 | vRgnData.ulDirection = RECTDIR_LFRT_TOPBOT; |
8d854fa9 DW |
649 | if (::GpiQueryRegionRects( ((wxRegionRefData*)rRegion.m_refData)->m_hPS // Pres space |
650 | ,((wxRegionRefData*)rRegion.m_refData)->m_hRegion // Handle of region to query | |
651 | ,NULL // Return all RECTs | |
652 | ,&vRgnData // Will contain number or RECTs in region | |
653 | ,NULL // NULL to return number of RECTs | |
654 | )) | |
655 | { | |
656 | pRect = new RECTL[vRgnData.crcReturned]; | |
657 | m_pRects = new wxRect[vRgnData.crcReturned]; | |
658 | vRgnData.crc = vRgnData.crcReturned; | |
659 | m_lNumRects = vRgnData.crcReturned; | |
660 | vRgnData.ircStart = 1; | |
661 | if (::GpiQueryRegionRects( ((wxRegionRefData*)rRegion.m_refData)->m_hPS // Pres space of source | |
662 | ,((wxRegionRefData*)rRegion.m_refData)->m_hRegion // Handle of source region | |
663 | ,NULL // Return all RECTs | |
664 | ,&vRgnData // Operations set to return rects | |
665 | ,pRect // Will contain the actual RECTS | |
666 | )) | |
667 | { | |
53e8757b | 668 | #if 0 |
8d854fa9 DW |
669 | M_REGION = ::GpiCreateRegion( ((wxRegionRefData*)rRegion.m_refData)->m_hPS |
670 | ,vRgnData.crcReturned | |
671 | ,pRect | |
672 | ); | |
53e8757b | 673 | #endif |
8d854fa9 DW |
674 | for( LONG i = 0; i < m_lNumRects; i++) |
675 | { | |
676 | m_pRects[i].x = pRect[i].xLeft; | |
677 | m_pRects[i].width = pRect[i].xRight - pRect[i].xLeft; | |
678 | m_pRects[i].y = pRect[i].yBottom; | |
679 | m_pRects[i].height = pRect[i].yTop - pRect[i].yBottom; | |
680 | } | |
53e8757b | 681 | #if 0 |
8d854fa9 | 682 | ((wxRegionRefData*)m_refData)->m_hPS = ((wxRegionRefData*)rRegion.m_refData)->m_hPS; |
53e8757b | 683 | #endif |
8d854fa9 DW |
684 | } |
685 | } | |
0e320a79 | 686 | } |
8d854fa9 | 687 | } // end of wxRegionIterator::Reset |
0e320a79 | 688 | |
8d854fa9 DW |
689 | // |
690 | // Increment iterator. The rectangle returned is the one after the | |
691 | // incrementation. | |
692 | // | |
693 | void wxRegionIterator::operator++ () | |
0e320a79 | 694 | { |
8d854fa9 DW |
695 | if (m_lCurrent < m_lNumRects) |
696 | ++m_lCurrent; | |
697 | } // end of wxRegionIterator::operator ++ | |
698 | ||
699 | // | |
700 | // Increment iterator. The rectangle returned is the one before the | |
701 | // incrementation. | |
702 | // | |
703 | void wxRegionIterator::operator++ (int) | |
0e320a79 | 704 | { |
8d854fa9 DW |
705 | if (m_lCurrent < m_lNumRects) |
706 | ++m_lCurrent; | |
707 | } // end of wxRegionIterator::operator++ | |
0e320a79 | 708 | |
0b7e7739 | 709 | wxCoord wxRegionIterator::GetX() const |
0e320a79 | 710 | { |
8d854fa9 DW |
711 | if (m_lCurrent < m_lNumRects) |
712 | return m_pRects[m_lCurrent].x; | |
713 | return 0L; | |
714 | } // end of wxRegionIterator::GetX | |
0e320a79 | 715 | |
0b7e7739 | 716 | wxCoord wxRegionIterator::GetY() const |
0e320a79 | 717 | { |
8d854fa9 DW |
718 | if (m_lCurrent < m_lNumRects) |
719 | return m_pRects[m_lCurrent].y; | |
720 | return 0L; | |
721 | } // end of wxRegionIterator::GetY | |
0e320a79 | 722 | |
0b7e7739 | 723 | wxCoord wxRegionIterator::GetW() const |
0e320a79 | 724 | { |
8d854fa9 DW |
725 | if (m_lCurrent < m_lNumRects) |
726 | return m_pRects[m_lCurrent].width ; | |
727 | return 0L; | |
728 | } // end of wxRegionIterator::GetW | |
0e320a79 | 729 | |
0b7e7739 | 730 | wxCoord wxRegionIterator::GetH() const |
0e320a79 | 731 | { |
8d854fa9 DW |
732 | if (m_lCurrent < m_lNumRects) |
733 | return m_pRects[m_lCurrent].height; | |
734 | return 0L; | |
735 | } // end of wxRegionIterator::GetH | |
0e320a79 | 736 |