[winforms] Style
[mono.git] / mcs / class / System.Drawing / System.Drawing / Region.jvm.cs
1
2 using System;
3 using System.Drawing.Drawing2D;
4 using System.Runtime.InteropServices;
5
6 using awt = java.awt;
7 using geom = java.awt.geom;
8
9 namespace System.Drawing
10 {
11         [ComVisible (false)]
12         public sealed class Region : BasicShape
13         {
14                 #region Member Vars
15                 internal static readonly Region InfiniteRegion = new Region(new Rectangle(-0x400000, -0x400000, 0x800000, 0x800000));
16                 #endregion
17         
18                 #region Internals
19                 internal geom.Area NativeObject
20                 {
21                         get
22                         {
23                                 return (geom.Area)Shape;
24                         }
25                 }
26                 #endregion
27                 
28                 #region Ctors. and Dtor
29
30
31                 public Region ()
32                         : this ((geom.Area) InfiniteRegion.NativeObject.clone ())
33                 {                  
34                 }
35
36         internal Region(geom.Area native) : base(native)
37                 {
38         }
39                 
40                 
41                 public Region (GraphicsPath path) : this(new geom.Area(path.NativeObject))
42                 {       
43                 }
44
45                 public Region (Rectangle rect) : this(new geom.Area(rect.NativeObject))
46                 {
47                 }
48
49                 public Region (RectangleF rect) : this(new geom.Area(rect.NativeObject))
50                 {
51                 }
52
53                 [MonoTODO]
54                 public Region (RegionData region_data) : this((geom.Area)null)
55                 {
56                         throw new NotImplementedException ();
57                 }
58                 #endregion
59                 
60                 #region Union
61                 public void Union (GraphicsPath path)
62                 {
63                         if (path == null)
64                                 throw new ArgumentNullException("path");
65                         NativeObject.add(new geom.Area(path.NativeObject));
66                 }
67
68
69                 public void Union (Rectangle rect)
70                 {                                    
71                         NativeObject.add(new geom.Area(rect.NativeObject));
72                 }
73
74                 public void Union (RectangleF rect)
75                 {
76                         NativeObject.add(new geom.Area(rect.NativeObject));
77                 }
78
79                 public void Union (Region region)
80                 {
81                         if (region == null)
82                                 throw new ArgumentNullException("region");
83                         NativeObject.add(region.NativeObject);
84                 }
85                 #endregion                                                                                 
86
87                 #region Intersect
88                 //
89                 public void Intersect (GraphicsPath path)
90                 {
91                         if (path == null)
92                                 throw new ArgumentNullException("path");
93                         NativeObject.intersect(new geom.Area(path.NativeObject));
94                 }
95
96                 public void Intersect (Rectangle rect)
97                 {
98                         NativeObject.intersect(new geom.Area(rect.NativeObject));
99                 }
100
101                 public void Intersect (RectangleF rect)
102                 {
103                         NativeObject.intersect(new geom.Area(rect.NativeObject));
104                 }
105
106                 public void Intersect (Region region)
107                 {
108                         if (region == null)
109                                 throw new ArgumentNullException("region");
110                         NativeObject.intersect(region.NativeObject);
111                 }
112                 #endregion
113
114                 #region  Complement
115                 //
116                 public void Complement (GraphicsPath path)
117                 {
118                         if (path == null)
119                                 throw new ArgumentNullException("path");
120                         geom.Area a = new geom.Area(path.NativeObject);
121                         a.subtract(NativeObject);
122                         Shape = a;
123                 }
124
125                 public void Complement (Rectangle rect)
126                 {
127                         geom.Area a = new geom.Area(rect.NativeObject);
128                         a.subtract(NativeObject);
129                         Shape = a;
130                 }
131
132                 public void Complement (RectangleF rect)
133                 {
134                         geom.Area a = new geom.Area(rect.NativeObject);
135                         a.subtract(NativeObject);
136                         Shape = a;
137                 }
138
139                 public void Complement (Region region)
140                 {
141                         if (region == null)
142                                 throw new ArgumentNullException("region");
143                         geom.Area a = (geom.Area) region.NativeObject.clone ();
144                         a.subtract(NativeObject);
145                         Shape = a;
146                 }
147                 #endregion
148
149                 #region Exclude
150                 //
151                 public void Exclude (GraphicsPath path)
152                 {
153                         if (path == null)
154                                 throw new ArgumentNullException("path");
155                         NativeObject.subtract(new geom.Area(path.NativeObject));
156                 }
157
158                 public void Exclude (Rectangle rect)
159                 {
160                         NativeObject.subtract(new geom.Area(rect.NativeObject));
161                 }
162
163                 public void Exclude (RectangleF rect)
164                 {
165                         NativeObject.subtract(new geom.Area(rect.NativeObject));
166                 }
167
168                 public void Exclude (Region region)
169                 {
170                         if (region == null)
171                                 throw new ArgumentNullException("region");
172                         NativeObject.subtract(region.NativeObject);
173                 }
174                 #endregion
175
176                 #region  Xor
177                 //
178                 public void Xor (GraphicsPath path)
179                 {
180                         if (path == null)
181                                 throw new ArgumentNullException("path");
182                         NativeObject.exclusiveOr(new geom.Area(path.NativeObject));
183                 }
184
185                 public void Xor (Rectangle rect)
186                 {
187                         NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
188                 }
189
190                 public void Xor (RectangleF rect)
191                 {
192                         NativeObject.exclusiveOr(new geom.Area(rect.NativeObject));
193                 }
194
195                 public void Xor (Region region)
196                 {
197                         if (region == null)
198                                 throw new ArgumentNullException("region");
199                         NativeObject.exclusiveOr(region.NativeObject);
200                 }
201                 #endregion
202
203                 #region GetBounds
204                 //
205                 public RectangleF GetBounds (Graphics graphics)
206                 {
207                         if (graphics == null)
208                                 throw new ArgumentNullException("graphics");
209                         return new RectangleF(NativeObject.getBounds2D());
210                 }
211                 #endregion
212
213                 #region  Translate
214                 //
215                 public void Translate (int dx, int dy)
216                 {
217                         Translate((float)dx, (float)dy);
218                 }
219
220                 public void Translate (float dx, float dy)
221                 {
222                         if (NativeObject.equals(InfiniteRegion.NativeObject))
223                                 return;
224                         NativeObject.transform(geom.AffineTransform.getTranslateInstance(
225                                 dx,
226                                 dy));
227                 }
228                 #endregion
229
230                 #region  IsVisible [TODO]
231                 //
232                 public bool IsVisible (int x, int y, Graphics g)
233                 {
234                         return IsVisible((float)x, (float)y, g);
235                 }
236
237                 public bool IsVisible (int x, int y, int width, int height)
238                 {
239                         return IsVisible((float)x, (float)y, (float)width, (float)height);
240                 }
241
242                 public bool IsVisible (int x, int y, int width, int height, Graphics g)
243                 {
244                         return IsVisible((float)x, (float)y, (float)width, (float)height, g);
245                 }
246
247                 public bool IsVisible (Point point)
248                 {
249                         return IsVisible(point.X, point.Y);
250                 }
251
252                 public bool IsVisible (PointF point)
253                 {
254                         return IsVisible(point.X, point.Y);
255                 }
256
257                 public bool IsVisible (Point point, Graphics g)
258                 {
259                         return IsVisible(point.X, point.Y, g);
260                 }
261
262                 public bool IsVisible (PointF point, Graphics g)
263                 {
264                         return IsVisible(point.X, point.Y, g);
265                 }
266
267                 public bool IsVisible (Rectangle rect)
268                 {
269                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
270                 }
271
272                 public bool IsVisible (RectangleF rect)
273                 {
274                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height);
275                 }
276
277                 public bool IsVisible (Rectangle rect, Graphics g)
278                 {
279                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
280                 }
281
282                 public bool IsVisible (RectangleF rect, Graphics g)
283                 {
284                         return IsVisible(rect.X, rect.Y, rect.Width, rect.Height, g);
285                 }
286
287                 public bool IsVisible (float x, float y)
288                 {
289                         return NativeObject.contains(x,y);
290                 }
291
292                 public bool IsVisible (float x, float y, Graphics g)
293                 {
294                         if (g == null)
295                                 throw new ArgumentNullException("graphics");
296                         return NativeObject.contains(x,y);
297                 }
298
299                 public bool IsVisible (float x, float y, float width, float height)
300                 {
301                         return NativeObject.intersects(x,y,width,height);
302                 }
303
304                 public bool IsVisible (float x, float y, float width, float height, Graphics g) 
305                 {
306                         if (g == null)
307                                 throw new ArgumentNullException("graphics");
308                         return NativeObject.intersects(x,y,width,height);
309                 }
310                 #endregion
311
312                 #region IsEmpty
313                 public bool IsEmpty(Graphics g)
314                 {
315                         if (g == null)
316                                 throw new ArgumentNullException("graphics");
317                         return NativeObject.isEmpty();
318                 }
319                 #endregion
320
321                 #region IsInfinite
322                 public bool IsInfinite(Graphics g)
323                 {
324                         if (g == null)
325                                 throw new ArgumentNullException("graphics");
326                         //probably too naive.
327                         return NativeObject.equals(InfiniteRegion.NativeObject);
328                 }
329                 #endregion
330
331                 #region MakeEmpty
332                 public void MakeEmpty()
333                 {
334                         NativeObject.reset();
335                 }
336                 #endregion
337
338                 #region MakeInfinite
339                 public void MakeInfinite()
340                 {
341                         Shape = (geom.Area) InfiniteRegion.NativeObject.clone ();
342                 }
343                 #endregion 
344
345                 #region Equals
346                 public bool Equals(Region region, Graphics g)
347                 {
348                         if (g == null)
349                                 throw new ArgumentNullException("graphics");
350                         return NativeObject.equals(region.NativeObject);
351                 }
352                 #endregion
353                                 
354                 [MonoTODO]
355                 public RegionData GetRegionData()
356                 {
357                         throw new NotImplementedException();
358                 }
359
360                 [MonoTODO]
361                 public IntPtr GetHrgn(Graphics g) {
362                         throw new NotImplementedException();
363                 }
364                 
365                 
366                 public RectangleF[] GetRegionScans(Matrix matrix)
367                 {
368                         throw new NotImplementedException();
369                 }
370                 
371                 #region Transform 
372                 public void Transform(Matrix matrix)
373                 {
374                         if (matrix == null)
375                                 throw new ArgumentNullException("matrix");
376                         if (NativeObject.equals(InfiniteRegion.NativeObject))
377                                 return;
378                         NativeObject.transform(matrix.NativeObject);
379                 }               
380                 #endregion
381
382                 #region Clone
383                 public Region Clone()
384                 {
385                         return new Region ((geom.Area) NativeObject.clone ());
386                 }
387                 #endregion
388         }
389 }