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