]> git.saurik.com Git - wxWidgets.git/blob - src/gtk1/region.cpp
wxDocManager gets the only view if none other specified as the current view;
[wxWidgets.git] / src / gtk1 / region.cpp
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
22 class wxRegionRefData: public wxObjectRefData
23 {
24 public:
25
26 wxRegionRefData(void);
27 ~wxRegionRefData(void);
28
29 public:
30
31 GdkRegion *m_region;
32 };
33
34 wxRegionRefData::wxRegionRefData(void)
35 {
36 m_region = NULL;
37 };
38
39 wxRegionRefData::~wxRegionRefData(void)
40 {
41 if (m_region) gdk_region_destroy( m_region );
42 };
43
44 //-----------------------------------------------------------------------------
45
46 #define M_REGIONDATA ((wxRegionRefData *)m_refData)
47
48 IMPLEMENT_DYNAMIC_CLASS(wxRegion,wxGDIObject);
49
50 wxRegion::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 );
61 };
62
63 wxRegion::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 );
74 };
75
76 wxRegion::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 );
87 };
88
89 wxRegion::wxRegion(void)
90 {
91 m_refData = new wxRegionRefData();
92 M_REGIONDATA->m_region = gdk_region_new();
93 };
94
95 wxRegion::~wxRegion(void)
96 {
97 };
98
99 void wxRegion::Clear(void)
100 {
101 UnRef();
102 m_refData = new wxRegionRefData();
103 M_REGIONDATA->m_region = gdk_region_new();
104 };
105
106 bool 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;
117 };
118
119 bool 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;
130 };
131
132 bool 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;
138 };
139
140 bool wxRegion::Intersect( long x, long y, long width, long height )
141 {
142 wxRegion reg( x, y, width, height );
143 Intersect( reg );
144 return TRUE;
145 };
146
147 bool wxRegion::Intersect( const wxRect& rect )
148 {
149 wxRegion reg( rect );
150 Intersect( reg );
151 return TRUE;
152 };
153
154 bool 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;
160 };
161
162 bool wxRegion::Subtract( long x, long y, long width, long height )
163 {
164 wxRegion reg( x, y, width, height );
165 Subtract( reg );
166 return TRUE;
167 };
168
169 bool wxRegion::Subtract( const wxRect& rect )
170 {
171 wxRegion reg( rect );
172 Subtract( reg );
173 return TRUE;
174 };
175
176 bool 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;
182 };
183
184 bool wxRegion::Xor( long x, long y, long width, long height )
185 {
186 wxRegion reg( x, y, width, height );
187 Xor( reg );
188 return TRUE;
189 };
190
191 bool wxRegion::Xor( const wxRect& rect )
192 {
193 wxRegion reg( rect );
194 Xor( reg );
195 return TRUE;
196 };
197
198 bool 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;
204 };
205
206 void wxRegion::GetBox( long& x, long& y, long&w, long &h ) const
207 {
208 x = 0;
209 y = 0;
210 w = -1;
211 h = -1;
212 };
213
214 wxRect wxRegion::GetBox(void) const
215 {
216 return wxRect( 0, 0, -1, -1 );
217 };
218
219 bool wxRegion::Empty(void) const
220 {
221 return gdk_region_empty( M_REGIONDATA->m_region );
222 };
223
224 wxRegionContain 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;
230 };
231
232 wxRegionContain 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;
245 };
246 return wxOutRegion;
247 };
248
249 GdkRegion *wxRegion::GetRegion(void) const
250 {
251 return M_REGIONDATA->m_region;
252 };
253