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