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