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