]> git.saurik.com Git - wxWidgets.git/blame - src/gtk/region.cpp
Fixed event handling for DialogEd
[wxWidgets.git] / src / gtk / region.cpp
CommitLineData
c801d85f
KB
1/////////////////////////////////////////////////////////////////////////////
2// Name: region.cpp
3// Purpose:
4// Author: Robert Roebling
5// Created: 01/02/98
6// Id:
7// Copyright: (c) 1998 Robert Roebling, Julian Smart and Markus Holzem
8// Licence: wxWindows licence
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifdef __GNUG__
13#pragma implementation "region.h"
14#endif
15
16#include "wx/region.h"
17
18//-----------------------------------------------------------------------------
19// wxRegion
20//-----------------------------------------------------------------------------
21
22class wxRegionRefData: public wxObjectRefData
23{
24 public:
25
26 wxRegionRefData(void);
27 ~wxRegionRefData(void);
28
29 public:
30
31 GdkRegion *m_region;
32};
33
34wxRegionRefData::wxRegionRefData(void)
35{
c67daf87 36 m_region = (GdkRegion *) NULL;
ff7b1510 37}
c801d85f
KB
38
39wxRegionRefData::~wxRegionRefData(void)
40{
41 if (m_region) gdk_region_destroy( m_region );
ff7b1510 42}
c801d85f
KB
43
44//-----------------------------------------------------------------------------
45
46#define M_REGIONDATA ((wxRegionRefData *)m_refData)
47
48IMPLEMENT_DYNAMIC_CLASS(wxRegion,wxGDIObject);
49
50wxRegion::wxRegion( long x, long y, long w, long h )
51{
52 m_refData = new wxRegionRefData();
53 GdkRegion *reg = gdk_region_new();
54 GdkRectangle rect;
55 rect.x = x;
56 rect.y = y;
57 rect.width = w;
58 rect.height = h;
59 M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
60 gdk_region_destroy( reg );
ff7b1510 61}
c801d85f
KB
62
63wxRegion::wxRegion( const wxPoint& topLeft, const wxPoint& bottomRight )
64{
65 m_refData = new wxRegionRefData();
66 GdkRegion *reg = gdk_region_new();
67 GdkRectangle rect;
68 rect.x = topLeft.x;
69 rect.y = topLeft.y;
70 rect.width = bottomRight.x - rect.x;
71 rect.height = bottomRight.y - rect.y;
72 M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &rect );
73 gdk_region_destroy( reg );
ff7b1510 74}
c801d85f
KB
75
76wxRegion::wxRegion( const wxRect& rect )
77{
78 m_refData = new wxRegionRefData();
79 GdkRegion *reg = gdk_region_new();
80 GdkRectangle g_rect;
81 g_rect.x = rect.x;
82 g_rect.y = rect.y;
83 g_rect.width = rect.width;
84 g_rect.height = rect.height;
85 M_REGIONDATA->m_region = gdk_region_union_with_rect( reg, &g_rect );
86 gdk_region_destroy( reg );
ff7b1510 87}
c801d85f
KB
88
89wxRegion::wxRegion(void)
90{
91 m_refData = new wxRegionRefData();
92 M_REGIONDATA->m_region = gdk_region_new();
ff7b1510 93}
c801d85f
KB
94
95wxRegion::~wxRegion(void)
96{
ff7b1510 97}
c801d85f
KB
98
99void wxRegion::Clear(void)
100{
101 UnRef();
102 m_refData = new wxRegionRefData();
103 M_REGIONDATA->m_region = gdk_region_new();
ff7b1510 104}
c801d85f
KB
105
106bool wxRegion::Union( long x, long y, long width, long height )
107{
108 GdkRectangle rect;
109 rect.x = x;
110 rect.y = y;
111 rect.width = width;
112 rect.height = height;
113 GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &rect );
114 gdk_region_destroy( M_REGIONDATA->m_region );
115 M_REGIONDATA->m_region = reg;
116 return TRUE;
ff7b1510 117}
c801d85f
KB
118
119bool wxRegion::Union( const wxRect& rect )
120{
121 GdkRectangle g_rect;
122 g_rect.x = rect.x;
123 g_rect.y = rect.y;
124 g_rect.width = rect.width;
125 g_rect.height = rect.height;
126 GdkRegion *reg = gdk_region_union_with_rect( M_REGIONDATA->m_region, &g_rect );
127 gdk_region_destroy( M_REGIONDATA->m_region );
128 M_REGIONDATA->m_region = reg;
129 return TRUE;
ff7b1510 130}
c801d85f
KB
131
132bool wxRegion::Union( const wxRegion& region )
133{
134 GdkRegion *reg = gdk_regions_union( M_REGIONDATA->m_region, region.GetRegion() );
135 gdk_region_destroy( M_REGIONDATA->m_region );
136 M_REGIONDATA->m_region = reg;
137 return TRUE;
ff7b1510 138}
c801d85f
KB
139
140bool wxRegion::Intersect( long x, long y, long width, long height )
141{
142 wxRegion reg( x, y, width, height );
143 Intersect( reg );
144 return TRUE;
ff7b1510 145}
c801d85f
KB
146
147bool wxRegion::Intersect( const wxRect& rect )
148{
149 wxRegion reg( rect );
150 Intersect( reg );
151 return TRUE;
ff7b1510 152}
c801d85f
KB
153
154bool wxRegion::Intersect( const wxRegion& region )
155{
156 GdkRegion *reg = gdk_regions_intersect( M_REGIONDATA->m_region, region.GetRegion() );
157 gdk_region_destroy( M_REGIONDATA->m_region );
158 M_REGIONDATA->m_region = reg;
159 return TRUE;
ff7b1510 160}
c801d85f
KB
161
162bool wxRegion::Subtract( long x, long y, long width, long height )
163{
164 wxRegion reg( x, y, width, height );
165 Subtract( reg );
166 return TRUE;
ff7b1510 167}
c801d85f
KB
168
169bool wxRegion::Subtract( const wxRect& rect )
170{
171 wxRegion reg( rect );
172 Subtract( reg );
173 return TRUE;
ff7b1510 174}
c801d85f
KB
175
176bool wxRegion::Subtract( const wxRegion& region )
177{
178 GdkRegion *reg = gdk_regions_subtract( M_REGIONDATA->m_region, region.GetRegion() );
179 gdk_region_destroy( M_REGIONDATA->m_region );
180 M_REGIONDATA->m_region = reg;
181 return TRUE;
ff7b1510 182}
c801d85f
KB
183
184bool wxRegion::Xor( long x, long y, long width, long height )
185{
186 wxRegion reg( x, y, width, height );
187 Xor( reg );
188 return TRUE;
ff7b1510 189}
c801d85f
KB
190
191bool wxRegion::Xor( const wxRect& rect )
192{
193 wxRegion reg( rect );
194 Xor( reg );
195 return TRUE;
ff7b1510 196}
c801d85f
KB
197
198bool wxRegion::Xor( const wxRegion& region )
199{
200 GdkRegion *reg = gdk_regions_xor( M_REGIONDATA->m_region, region.GetRegion() );
201 gdk_region_destroy( M_REGIONDATA->m_region );
202 M_REGIONDATA->m_region = reg;
203 return TRUE;
ff7b1510 204}
c801d85f
KB
205
206void wxRegion::GetBox( long& x, long& y, long&w, long &h ) const
207{
208 x = 0;
209 y = 0;
210 w = -1;
211 h = -1;
ff7b1510 212}
c801d85f
KB
213
214wxRect wxRegion::GetBox(void) const
215{
216 return wxRect( 0, 0, -1, -1 );
ff7b1510 217}
c801d85f
KB
218
219bool wxRegion::Empty(void) const
220{
221 return gdk_region_empty( M_REGIONDATA->m_region );
ff7b1510 222}
c801d85f
KB
223
224wxRegionContain wxRegion::Contains( long x, long y ) const
225{
226 if (gdk_region_point_in( M_REGIONDATA->m_region, x, y ))
227 return wxInRegion;
228 else
229 return wxOutRegion;
ff7b1510 230}
c801d85f
KB
231
232wxRegionContain wxRegion::Contains( long x, long y, long w, long h ) const
233{
234 GdkRectangle rect;
235 rect.x = x;
236 rect.y = y;
237 rect.width = w;
238 rect.height = h;
239 GdkOverlapType res = gdk_region_rect_in( M_REGIONDATA->m_region, &rect );
240 switch (res)
241 {
242 case GDK_OVERLAP_RECTANGLE_IN: return wxInRegion;
243 case GDK_OVERLAP_RECTANGLE_OUT: return wxOutRegion;
244 case GDK_OVERLAP_RECTANGLE_PART: return wxPartRegion;
ff7b1510 245 }
c801d85f 246 return wxOutRegion;
ff7b1510 247}
c801d85f
KB
248
249GdkRegion *wxRegion::GetRegion(void) const
250{
251 return M_REGIONDATA->m_region;
ff7b1510 252}
c801d85f 253