]>
Commit | Line | Data |
---|---|---|
c801d85f | 1 | ///////////////////////////////////////////////////////////////////////////// |
5fc7ede9 | 2 | // Name: gtk/region.cpp |
c801d85f KB |
3 | // Purpose: |
4 | // Author: Robert Roebling | |
f96aa4d9 RR |
5 | // Id: $Id$ |
6 | // Copyright: (c) 1998 Robert Roebling | |
5fc7ede9 | 7 | // Licence: wxWindows licence |
c801d85f KB |
8 | ///////////////////////////////////////////////////////////////////////////// |
9 | ||
c801d85f KB |
10 | #ifdef __GNUG__ |
11 | #pragma implementation "region.h" | |
12 | #endif | |
13 | ||
14 | #include "wx/region.h" | |
15 | ||
aed8ac3f RR |
16 | #include <gdk/gdk.h> |
17 | #include <gtk/gtk.h> | |
bbe0af5b | 18 | |
d52e91c9 JS |
19 | // Unfortunately the new way of implementing the region iterator |
20 | // doesn't work with GTK+ 2.0 or above (can't access a Region in | |
21 | // GdkPrivateRegion) | |
22 | #ifdef __WXGTK20__ | |
23 | #define OLDCODE 1 | |
24 | #else | |
3d0c4d2e | 25 | #define OLDCODE 0 |
d52e91c9 | 26 | #endif |
864e8bd0 | 27 | |
c801d85f KB |
28 | //----------------------------------------------------------------------------- |
29 | // wxRegion | |
30 | //----------------------------------------------------------------------------- | |
31 | ||
32 | class wxRegionRefData: public wxObjectRefData | |
33 | { | |
864e8bd0 | 34 | public: |
bf57d1ad VZ |
35 | wxRegionRefData(); |
36 | ~wxRegionRefData(); | |
5fc7ede9 | 37 | |
c801d85f | 38 | GdkRegion *m_region; |
3d0c4d2e | 39 | #if OLDCODE |
8429bec1 | 40 | wxList m_rects; |
3d0c4d2e | 41 | #endif |
c801d85f KB |
42 | }; |
43 | ||
bf57d1ad | 44 | wxRegionRefData::wxRegionRefData() |
c801d85f | 45 | { |
bbe0af5b | 46 | m_region = (GdkRegion *) NULL; |
ff7b1510 | 47 | } |
c801d85f | 48 | |
bf57d1ad | 49 | wxRegionRefData::~wxRegionRefData() |
c801d85f | 50 | { |
bbe0af5b | 51 | if (m_region) gdk_region_destroy( m_region ); |
5fc7ede9 | 52 | |
3d0c4d2e | 53 | #if OLDCODE |
bbe0af5b RR |
54 | wxNode *node = m_rects.First(); |
55 | while (node) | |
56 | { | |
57 | wxRect *r = (wxRect*)node->Data(); | |
58 | delete r; | |
59 | node = node->Next(); | |
60 | } | |
3d0c4d2e | 61 | #endif |
ff7b1510 | 62 | } |
c801d85f KB |
63 | |
64 | //----------------------------------------------------------------------------- | |
65 | ||
66 | #define M_REGIONDATA ((wxRegionRefData *)m_refData) | |
67 | ||
68 | IMPLEMENT_DYNAMIC_CLASS(wxRegion,wxGDIObject); | |
5fc7ede9 VZ |
69 | |
70 | wxRegion::wxRegion( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) | |
c801d85f | 71 | { |
bbe0af5b RR |
72 | m_refData = new wxRegionRefData(); |
73 | GdkRegion *reg = gdk_region_new(); | |
74 | GdkRectangle rect; | |
75 | rect.x = x; | |
76 | rect.y = y; | |
77 | rect.width = w; | |
78 | rect.height = h; | |
b7c2d6ff OK |
79 | #ifdef __WXGTK20__ |
80 | gdk_region_union_with_rect( reg, &rect ); | |
81 | M_REGIONDATA->m_region = reg; | |
82 | #else | |
bbe0af5b RR |
83 | M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect ); |
84 | gdk_region_destroy( reg ); | |
b7c2d6ff | 85 | #endif |
3d0c4d2e | 86 | #if OLDCODE |
bbe0af5b | 87 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,w,h) ); |
3d0c4d2e | 88 | #endif |
ff7b1510 | 89 | } |
c801d85f KB |
90 | |
91 | wxRegion::wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight ) | |
92 | { | |
bbe0af5b RR |
93 | m_refData = new wxRegionRefData(); |
94 | GdkRegion *reg = gdk_region_new(); | |
95 | GdkRectangle rect; | |
96 | rect.x = topLeft.x; | |
97 | rect.y = topLeft.y; | |
98 | rect.width = bottomRight.x - rect.x; | |
99 | rect.height = bottomRight.y - rect.y; | |
b7c2d6ff OK |
100 | #ifdef __WXGTK20__ |
101 | gdk_region_union_with_rect( reg, &rect ); | |
102 | M_REGIONDATA->m_region = reg; | |
103 | #else | |
bbe0af5b RR |
104 | M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect ); |
105 | gdk_region_destroy( reg ); | |
b7c2d6ff | 106 | #endif |
3d0c4d2e | 107 | #if OLDCODE |
bbe0af5b | 108 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(topLeft,bottomRight) ); |
3d0c4d2e | 109 | #endif |
ff7b1510 | 110 | } |
c801d85f KB |
111 | |
112 | wxRegion::wxRegion( const wxRect& rect ) | |
113 | { | |
bbe0af5b RR |
114 | m_refData = new wxRegionRefData(); |
115 | GdkRegion *reg = gdk_region_new(); | |
116 | GdkRectangle g_rect; | |
117 | g_rect.x = rect.x; | |
118 | g_rect.y = rect.y; | |
119 | g_rect.width = rect.width; | |
120 | g_rect.height = rect.height; | |
b7c2d6ff OK |
121 | #ifdef __WXGTK20__ |
122 | gdk_region_union_with_rect( reg, &g_rect ); | |
123 | M_REGIONDATA->m_region = reg; | |
124 | #else | |
bbe0af5b RR |
125 | M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect ); |
126 | gdk_region_destroy( reg ); | |
b7c2d6ff | 127 | #endif |
3d0c4d2e | 128 | #if OLDCODE |
e1208c31 | 129 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(rect.x,rect.y,rect.width,rect.height) ); |
3d0c4d2e | 130 | #endif |
ff7b1510 | 131 | } |
c801d85f | 132 | |
bf57d1ad | 133 | wxRegion::wxRegion() |
c801d85f | 134 | { |
ff7b1510 | 135 | } |
c801d85f | 136 | |
bf57d1ad | 137 | wxRegion::~wxRegion() |
c801d85f | 138 | { |
ff7b1510 | 139 | } |
c801d85f | 140 | |
76ed8f8d RR |
141 | bool wxRegion::operator == ( const wxRegion& region ) |
142 | { | |
5fc7ede9 | 143 | return m_refData == region.m_refData; |
76ed8f8d RR |
144 | } |
145 | ||
146 | bool wxRegion::operator != ( const wxRegion& region ) | |
147 | { | |
5fc7ede9 | 148 | return m_refData != region.m_refData; |
76ed8f8d RR |
149 | } |
150 | ||
bf57d1ad | 151 | void wxRegion::Clear() |
c801d85f | 152 | { |
bbe0af5b | 153 | UnRef(); |
ff7b1510 | 154 | } |
c801d85f | 155 | |
5fc7ede9 | 156 | bool wxRegion::Union( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 157 | { |
bbe0af5b RR |
158 | GdkRectangle rect; |
159 | rect.x = x; | |
160 | rect.y = y; | |
161 | rect.width = width; | |
162 | rect.height = height; | |
e1208c31 RR |
163 | if (!m_refData) |
164 | { | |
165 | m_refData = new wxRegionRefData(); | |
166 | GdkRegion *reg = gdk_region_new(); | |
b7c2d6ff OK |
167 | #ifdef __WXGTK20__ |
168 | gdk_region_union_with_rect( reg, &rect ); | |
169 | M_REGIONDATA->m_region = reg; | |
170 | #else | |
e1208c31 RR |
171 | M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect ); |
172 | gdk_region_destroy( reg ); | |
b7c2d6ff | 173 | #endif |
e1208c31 RR |
174 | } |
175 | else | |
176 | { | |
b7c2d6ff OK |
177 | #ifdef __WXGTK20__ |
178 | gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); | |
179 | #else | |
e1208c31 RR |
180 | GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect ); |
181 | gdk_region_destroy( M_REGIONDATA->m_region ); | |
182 | M_REGIONDATA->m_region = reg; | |
b7c2d6ff | 183 | #endif |
e1208c31 RR |
184 | } |
185 | ||
3d0c4d2e | 186 | #if OLDCODE |
bbe0af5b | 187 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(x,y,width,height) ); |
3d0c4d2e | 188 | #endif |
e1208c31 | 189 | |
bbe0af5b | 190 | return TRUE; |
ff7b1510 | 191 | } |
c801d85f KB |
192 | |
193 | bool wxRegion::Union( const wxRect& rect ) | |
194 | { | |
e1208c31 | 195 | return Union( rect.x, rect.y, rect.width, rect.height ); |
ff7b1510 | 196 | } |
c801d85f KB |
197 | |
198 | bool wxRegion::Union( const wxRegion& region ) | |
199 | { | |
e1208c31 RR |
200 | if (region.IsNull()) |
201 | return FALSE; | |
202 | ||
203 | if (!m_refData) | |
204 | { | |
205 | m_refData = new wxRegionRefData(); | |
206 | M_REGIONDATA->m_region = gdk_region_new(); | |
207 | } | |
208 | ||
b7c2d6ff OK |
209 | #ifdef __WXGTK20__ |
210 | gdk_region_union( M_REGIONDATA->m_region, region.GetRegion() ); | |
211 | #else | |
bbe0af5b RR |
212 | GdkRegion *reg = gdk_regions_union( M_REGIONDATA->m_region, region.GetRegion() ); |
213 | gdk_region_destroy( M_REGIONDATA->m_region ); | |
214 | M_REGIONDATA->m_region = reg; | |
b7c2d6ff | 215 | #endif |
5fc7ede9 | 216 | |
3d0c4d2e | 217 | #if OLDCODE |
bbe0af5b RR |
218 | wxNode *node = region.GetRectList()->First(); |
219 | while (node) | |
220 | { | |
221 | wxRect *r = (wxRect*)node->Data(); | |
222 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) ); | |
223 | node = node->Next(); | |
224 | } | |
3d0c4d2e | 225 | #endif |
5fc7ede9 | 226 | |
bbe0af5b | 227 | return TRUE; |
ff7b1510 | 228 | } |
c801d85f | 229 | |
5fc7ede9 | 230 | bool wxRegion::Intersect( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 231 | { |
e1208c31 RR |
232 | if (!m_refData) |
233 | { | |
234 | m_refData = new wxRegionRefData(); | |
235 | M_REGIONDATA->m_region = gdk_region_new(); | |
236 | } | |
237 | ||
bbe0af5b RR |
238 | wxRegion reg( x, y, width, height ); |
239 | Intersect( reg ); | |
240 | return TRUE; | |
ff7b1510 | 241 | } |
c801d85f KB |
242 | |
243 | bool wxRegion::Intersect( const wxRect& rect ) | |
244 | { | |
e1208c31 RR |
245 | if (!m_refData) |
246 | { | |
247 | m_refData = new wxRegionRefData(); | |
248 | M_REGIONDATA->m_region = gdk_region_new(); | |
249 | } | |
250 | ||
bbe0af5b RR |
251 | wxRegion reg( rect ); |
252 | Intersect( reg ); | |
253 | return TRUE; | |
ff7b1510 | 254 | } |
c801d85f KB |
255 | |
256 | bool wxRegion::Intersect( const wxRegion& region ) | |
257 | { | |
e1208c31 RR |
258 | if (region.IsNull()) |
259 | return FALSE; | |
260 | ||
261 | if (!m_refData) | |
262 | { | |
263 | m_refData = new wxRegionRefData(); | |
264 | M_REGIONDATA->m_region = gdk_region_new(); | |
265 | return TRUE; | |
266 | } | |
267 | ||
b7c2d6ff OK |
268 | #ifdef __WXGTK20__ |
269 | gdk_region_intersect( M_REGIONDATA->m_region, region.GetRegion() ); | |
270 | #else | |
bbe0af5b RR |
271 | GdkRegion *reg = gdk_regions_intersect( M_REGIONDATA->m_region, region.GetRegion() ); |
272 | gdk_region_destroy( M_REGIONDATA->m_region ); | |
273 | M_REGIONDATA->m_region = reg; | |
b7c2d6ff | 274 | #endif |
bbe0af5b | 275 | return TRUE; |
ff7b1510 | 276 | } |
c801d85f | 277 | |
5fc7ede9 | 278 | bool wxRegion::Subtract( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 279 | { |
e1208c31 RR |
280 | if (!m_refData) |
281 | { | |
282 | m_refData = new wxRegionRefData(); | |
283 | M_REGIONDATA->m_region = gdk_region_new(); | |
284 | } | |
285 | ||
bbe0af5b RR |
286 | wxRegion reg( x, y, width, height ); |
287 | Subtract( reg ); | |
288 | return TRUE; | |
ff7b1510 | 289 | } |
c801d85f KB |
290 | |
291 | bool wxRegion::Subtract( const wxRect& rect ) | |
292 | { | |
e1208c31 RR |
293 | if (!m_refData) |
294 | { | |
295 | m_refData = new wxRegionRefData(); | |
296 | M_REGIONDATA->m_region = gdk_region_new(); | |
297 | } | |
298 | ||
bbe0af5b RR |
299 | wxRegion reg( rect ); |
300 | Subtract( reg ); | |
301 | return TRUE; | |
ff7b1510 | 302 | } |
c801d85f KB |
303 | |
304 | bool wxRegion::Subtract( const wxRegion& region ) | |
305 | { | |
e1208c31 RR |
306 | if (region.IsNull()) |
307 | return FALSE; | |
308 | ||
309 | if (!m_refData) | |
310 | { | |
311 | m_refData = new wxRegionRefData(); | |
312 | M_REGIONDATA->m_region = gdk_region_new(); | |
313 | } | |
314 | ||
b7c2d6ff OK |
315 | #ifdef __WXGTK20__ |
316 | gdk_region_subtract( M_REGIONDATA->m_region, region.GetRegion() ); | |
317 | #else | |
bbe0af5b RR |
318 | GdkRegion *reg = gdk_regions_subtract( M_REGIONDATA->m_region, region.GetRegion() ); |
319 | gdk_region_destroy( M_REGIONDATA->m_region ); | |
320 | M_REGIONDATA->m_region = reg; | |
b7c2d6ff | 321 | #endif |
bbe0af5b | 322 | return TRUE; |
ff7b1510 | 323 | } |
c801d85f | 324 | |
5fc7ede9 | 325 | bool wxRegion::Xor( wxCoord x, wxCoord y, wxCoord width, wxCoord height ) |
c801d85f | 326 | { |
e1208c31 RR |
327 | if (!m_refData) |
328 | { | |
329 | m_refData = new wxRegionRefData(); | |
330 | M_REGIONDATA->m_region = gdk_region_new(); | |
331 | } | |
332 | ||
bbe0af5b RR |
333 | wxRegion reg( x, y, width, height ); |
334 | Xor( reg ); | |
335 | return TRUE; | |
ff7b1510 | 336 | } |
c801d85f KB |
337 | |
338 | bool wxRegion::Xor( const wxRect& rect ) | |
339 | { | |
e1208c31 RR |
340 | if (!m_refData) |
341 | { | |
342 | m_refData = new wxRegionRefData(); | |
343 | M_REGIONDATA->m_region = gdk_region_new(); | |
344 | } | |
345 | ||
bbe0af5b RR |
346 | wxRegion reg( rect ); |
347 | Xor( reg ); | |
348 | return TRUE; | |
ff7b1510 | 349 | } |
c801d85f KB |
350 | |
351 | bool wxRegion::Xor( const wxRegion& region ) | |
352 | { | |
e1208c31 | 353 | if (region.IsNull()) |
05a11043 | 354 | return FALSE; |
e1208c31 RR |
355 | |
356 | if (!m_refData) | |
357 | { | |
358 | m_refData = new wxRegionRefData(); | |
359 | M_REGIONDATA->m_region = gdk_region_new(); | |
360 | } | |
361 | ||
b7c2d6ff OK |
362 | #ifdef __WXGTK20__ |
363 | gdk_region_xor( M_REGIONDATA->m_region, region.GetRegion() ); | |
364 | #else | |
bbe0af5b RR |
365 | GdkRegion *reg = gdk_regions_xor( M_REGIONDATA->m_region, region.GetRegion() ); |
366 | gdk_region_destroy( M_REGIONDATA->m_region ); | |
367 | M_REGIONDATA->m_region = reg; | |
b7c2d6ff | 368 | #endif |
5fc7ede9 | 369 | |
3d0c4d2e | 370 | #if OLDCODE |
bbe0af5b RR |
371 | wxNode *node = region.GetRectList()->First(); |
372 | while (node) | |
373 | { | |
374 | wxRect *r = (wxRect*)node->Data(); | |
375 | M_REGIONDATA->m_rects.Append( (wxObject*) new wxRect(r->x,r->y,r->width,r->height) ); | |
376 | node = node->Next(); | |
377 | } | |
3d0c4d2e | 378 | #endif |
5fc7ede9 | 379 | |
bbe0af5b | 380 | return TRUE; |
ff7b1510 | 381 | } |
c801d85f | 382 | |
e1208c31 | 383 | void wxRegion::GetBox( wxCoord &x, wxCoord &y, wxCoord &w, wxCoord &h ) const |
c801d85f | 384 | { |
bbe0af5b RR |
385 | x = 0; |
386 | y = 0; | |
387 | w = -1; | |
388 | h = -1; | |
05a11043 | 389 | if (!m_refData) |
e1208c31 RR |
390 | return; |
391 | ||
864e8bd0 RR |
392 | GdkRectangle rect; |
393 | gdk_region_get_clipbox( M_REGIONDATA->m_region, &rect ); | |
394 | x = rect.x; | |
395 | y = rect.y; | |
396 | w = rect.width; | |
397 | h = rect.height; | |
ff7b1510 | 398 | } |
c801d85f | 399 | |
bf57d1ad | 400 | wxRect wxRegion::GetBox() const |
c801d85f | 401 | { |
5fc7ede9 VZ |
402 | wxCoord x = 0; |
403 | wxCoord y = 0; | |
404 | wxCoord w = -1; | |
405 | wxCoord h = -1; | |
bbe0af5b RR |
406 | GetBox( x, y, w, h ); |
407 | return wxRect( x, y, w, h ); | |
ff7b1510 | 408 | } |
c801d85f | 409 | |
bf57d1ad | 410 | bool wxRegion::Empty() const |
c801d85f | 411 | { |
e1208c31 RR |
412 | if (!m_refData) |
413 | return TRUE; | |
414 | ||
bbe0af5b | 415 | return gdk_region_empty( M_REGIONDATA->m_region ); |
ff7b1510 | 416 | } |
c801d85f | 417 | |
5fc7ede9 | 418 | wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y ) const |
c801d85f | 419 | { |
e1208c31 RR |
420 | if (!m_refData) |
421 | return wxOutRegion; | |
422 | ||
bbe0af5b RR |
423 | if (gdk_region_point_in( M_REGIONDATA->m_region, x, y )) |
424 | return wxInRegion; | |
425 | else | |
426 | return wxOutRegion; | |
ff7b1510 | 427 | } |
c801d85f | 428 | |
5fc7ede9 | 429 | wxRegionContain wxRegion::Contains( wxCoord x, wxCoord y, wxCoord w, wxCoord h ) const |
c801d85f | 430 | { |
e1208c31 RR |
431 | if (!m_refData) |
432 | return wxOutRegion; | |
433 | ||
bbe0af5b RR |
434 | GdkRectangle rect; |
435 | rect.x = x; | |
436 | rect.y = y; | |
437 | rect.width = w; | |
438 | rect.height = h; | |
439 | GdkOverlapType res = gdk_region_rect_in( M_REGIONDATA->m_region, &rect ); | |
440 | switch (res) | |
441 | { | |
442 | case GDK_OVERLAP_RECTANGLE_IN: return wxInRegion; | |
443 | case GDK_OVERLAP_RECTANGLE_OUT: return wxOutRegion; | |
444 | case GDK_OVERLAP_RECTANGLE_PART: return wxPartRegion; | |
445 | } | |
446 | return wxOutRegion; | |
ff7b1510 | 447 | } |
c801d85f | 448 | |
8429bec1 RR |
449 | wxRegionContain wxRegion::Contains(const wxPoint& pt) const |
450 | { | |
bbe0af5b | 451 | return Contains( pt.x, pt.y ); |
8429bec1 RR |
452 | } |
453 | ||
454 | wxRegionContain wxRegion::Contains(const wxRect& rect) const | |
455 | { | |
bbe0af5b | 456 | return Contains( rect.x, rect.y, rect.width, rect.height ); |
8429bec1 RR |
457 | } |
458 | ||
bf57d1ad | 459 | GdkRegion *wxRegion::GetRegion() const |
c801d85f | 460 | { |
e1208c31 RR |
461 | if (!m_refData) |
462 | return (GdkRegion*) NULL; | |
463 | ||
bbe0af5b | 464 | return M_REGIONDATA->m_region; |
ff7b1510 | 465 | } |
c801d85f | 466 | |
8429bec1 RR |
467 | wxList *wxRegion::GetRectList() const |
468 | { | |
3d0c4d2e | 469 | #if OLDCODE |
e1208c31 RR |
470 | if (!m_refData) |
471 | return (wxList*) NULL; | |
472 | ||
bbe0af5b | 473 | return &(M_REGIONDATA->m_rects); |
3d0c4d2e RR |
474 | #else |
475 | return (wxList*) NULL; | |
476 | #endif | |
8429bec1 RR |
477 | } |
478 | ||
479 | //----------------------------------------------------------------------------- | |
3d0c4d2e | 480 | // wxRegionIterator |
8429bec1 RR |
481 | //----------------------------------------------------------------------------- |
482 | ||
3d0c4d2e RR |
483 | #if OLDCODE |
484 | ||
8429bec1 | 485 | IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject); |
5fc7ede9 | 486 | |
bf57d1ad | 487 | wxRegionIterator::wxRegionIterator() |
8429bec1 | 488 | { |
6f2a55e3 | 489 | Reset(); |
8429bec1 RR |
490 | } |
491 | ||
492 | wxRegionIterator::wxRegionIterator( const wxRegion& region ) | |
493 | { | |
6f2a55e3 | 494 | Reset(region); |
8429bec1 RR |
495 | } |
496 | ||
497 | void wxRegionIterator::Reset( const wxRegion& region ) | |
498 | { | |
bbe0af5b | 499 | m_region = region; |
6f2a55e3 | 500 | Reset(); |
8429bec1 RR |
501 | } |
502 | ||
5fc7ede9 VZ |
503 | wxRegionIterator::operator bool () const |
504 | { | |
3d0c4d2e | 505 | return m_region.GetRectList() && m_current < (size_t)m_region.GetRectList()->Number(); |
8429bec1 RR |
506 | } |
507 | ||
5fc7ede9 VZ |
508 | bool wxRegionIterator::HaveRects() const |
509 | { | |
3d0c4d2e | 510 | return m_region.GetRectList() && m_current < (size_t)m_region.GetRectList()->Number(); |
8429bec1 RR |
511 | } |
512 | ||
bf57d1ad | 513 | void wxRegionIterator::operator ++ () |
8429bec1 | 514 | { |
3d0c4d2e | 515 | if (HaveRects()) ++m_current; |
8429bec1 RR |
516 | } |
517 | ||
518 | void wxRegionIterator::operator ++ (int) | |
519 | { | |
3d0c4d2e | 520 | if (HaveRects()) ++m_current; |
8429bec1 RR |
521 | } |
522 | ||
bf57d1ad | 523 | wxCoord wxRegionIterator::GetX() const |
8429bec1 | 524 | { |
bbe0af5b RR |
525 | wxNode *node = m_region.GetRectList()->Nth( m_current ); |
526 | if (!node) return 0; | |
527 | wxRect *r = (wxRect*)node->Data(); | |
528 | return r->x; | |
8429bec1 RR |
529 | } |
530 | ||
bf57d1ad | 531 | wxCoord wxRegionIterator::GetY() const |
8429bec1 | 532 | { |
bbe0af5b RR |
533 | wxNode *node = m_region.GetRectList()->Nth( m_current ); |
534 | if (!node) return 0; | |
535 | wxRect *r = (wxRect*)node->Data(); | |
536 | return r->y; | |
8429bec1 RR |
537 | } |
538 | ||
bf57d1ad | 539 | wxCoord wxRegionIterator::GetW() const |
8429bec1 | 540 | { |
bbe0af5b RR |
541 | wxNode *node = m_region.GetRectList()->Nth( m_current ); |
542 | if (!node) return 0; | |
543 | wxRect *r = (wxRect*)node->Data(); | |
544 | return r->width; | |
8429bec1 RR |
545 | } |
546 | ||
bf57d1ad | 547 | wxCoord wxRegionIterator::GetH() const |
8429bec1 | 548 | { |
bbe0af5b RR |
549 | wxNode *node = m_region.GetRectList()->Nth( m_current ); |
550 | if (!node) return 0; | |
551 | wxRect *r = (wxRect*)node->Data(); | |
552 | return r->height; | |
8429bec1 RR |
553 | } |
554 | ||
3d0c4d2e RR |
555 | #else |
556 | ||
557 | // the following structures must match the private structures | |
558 | // in X11 region code ( xc/lib/X11/region.h ) | |
559 | ||
560 | // this makes the Region type transparent | |
561 | // and we have access to the region rectangles | |
562 | ||
563 | struct _XBox { | |
564 | short x1, x2, y1, y2; | |
565 | }; | |
566 | ||
567 | struct _XRegion { | |
568 | long size , numRects; | |
569 | _XBox *rects, extents; | |
570 | }; | |
571 | ||
572 | class wxRIRefData: public wxObjectRefData | |
573 | { | |
574 | public: | |
575 | ||
576 | wxRIRefData() : m_rects(0), m_numRects(0){} | |
577 | ~wxRIRefData(); | |
578 | ||
579 | wxRect *m_rects; | |
580 | size_t m_numRects; | |
581 | ||
582 | void CreateRects( const wxRegion& r ); | |
583 | }; | |
584 | ||
585 | wxRIRefData::~wxRIRefData() | |
586 | { | |
587 | delete m_rects; | |
588 | } | |
589 | ||
590 | #include <gdk/gdkprivate.h> | |
591 | ||
592 | void wxRIRefData::CreateRects( const wxRegion& region ) | |
593 | { | |
594 | if( m_rects ) | |
595 | delete m_rects; | |
596 | m_rects = 0; | |
597 | m_numRects= 0; | |
598 | GdkRegion *gdkregion= region.GetRegion(); | |
599 | if( gdkregion ){ | |
600 | Region r= ((GdkRegionPrivate *)gdkregion)->xregion; | |
601 | if( r ){ | |
602 | m_numRects= r->numRects; | |
603 | if( m_numRects ) | |
604 | { | |
605 | m_rects= new wxRect[m_numRects]; | |
606 | for( size_t i=0; i<m_numRects; ++i ) | |
607 | { | |
608 | _XBox &xr= r->rects[i]; | |
609 | wxRect&wr= m_rects[i]; | |
610 | wr.x = xr.x1; | |
611 | wr.y = xr.y1; | |
612 | wr.width = xr.x2-xr.x1; | |
613 | wr.height= xr.y2-xr.y1; | |
614 | } | |
615 | } | |
616 | } | |
617 | } | |
618 | } | |
619 | ||
620 | IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator,wxObject); | |
621 | ||
622 | wxRegionIterator::wxRegionIterator() | |
623 | { | |
624 | m_refData = new wxRIRefData(); | |
625 | Reset(); | |
626 | } | |
627 | ||
628 | wxRegionIterator::wxRegionIterator( const wxRegion& region ) | |
629 | { | |
630 | m_refData = new wxRIRefData(); | |
631 | Reset(region); | |
632 | } | |
633 | ||
634 | void wxRegionIterator::Reset( const wxRegion& region ) | |
635 | { | |
636 | m_region = region; | |
637 | ((wxRIRefData*)m_refData)->CreateRects(region); | |
638 | Reset(); | |
639 | } | |
640 | ||
641 | bool wxRegionIterator::HaveRects() const | |
642 | { | |
643 | return m_current < ((wxRIRefData*)m_refData)->m_numRects; | |
644 | } | |
645 | ||
646 | wxRegionIterator::operator bool () const | |
647 | { | |
648 | return HaveRects(); | |
649 | } | |
650 | ||
651 | void wxRegionIterator::operator ++ () | |
652 | { | |
653 | if (HaveRects()) ++m_current; | |
654 | } | |
655 | ||
656 | void wxRegionIterator::operator ++ (int) | |
657 | { | |
658 | if (HaveRects()) ++m_current; | |
659 | } | |
660 | ||
661 | wxCoord wxRegionIterator::GetX() const | |
662 | { | |
663 | if( !HaveRects() ) return 0; | |
664 | return ((wxRIRefData*)m_refData)->m_rects[m_current].x; | |
665 | } | |
666 | ||
667 | wxCoord wxRegionIterator::GetY() const | |
668 | { | |
669 | if( !HaveRects() ) return 0; | |
670 | return ((wxRIRefData*)m_refData)->m_rects[m_current].y; | |
671 | } | |
672 | ||
673 | wxCoord wxRegionIterator::GetW() const | |
674 | { | |
675 | if( !HaveRects() ) return -1; | |
676 | return ((wxRIRefData*)m_refData)->m_rects[m_current].width; | |
677 | } | |
678 | ||
679 | wxCoord wxRegionIterator::GetH() const | |
680 | { | |
681 | if( !HaveRects() ) return -1; | |
682 | return ((wxRIRefData*)m_refData)->m_rects[m_current].height; | |
683 | } | |
684 | ||
685 | #endif | |
8429bec1 | 686 |