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