In .:
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
1 //
2 // System.Drawing.Graphics.cs
3 //
4 // Authors:
5 //      Gonzalo Paniagua Javier (gonzalo@ximian.com) (stubbed out)
6 //      Alexandre Pigolkine(pigolkine@gmx.de)
7 //      Jordi Mas i Hernandez (jordi@ximian.com)
8 //      Sebastien Pouliot  <sebastien@ximian.com>
9 //
10 // Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
11 // Copyright (C) 2004-2006 Novell, Inc. (http://www.novell.com)
12 //
13 // Permission is hereby granted, free of charge, to any person obtaining
14 // a copy of this software and associated documentation files (the
15 // "Software"), to deal in the Software without restriction, including
16 // without limitation the rights to use, copy, modify, merge, publish,
17 // distribute, sublicense, and/or sell copies of the Software, and to
18 // permit persons to whom the Software is furnished to do so, subject to
19 // the following conditions:
20 // 
21 // The above copyright notice and this permission notice shall be
22 // included in all copies or substantial portions of the Software.
23 // 
24 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
25 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
27 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
28 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
29 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
30 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31 //
32
33 using System.Drawing.Drawing2D;
34 using System.Drawing.Imaging;
35 using System.Drawing.Text;
36 using System.ComponentModel;
37 using System.Runtime.InteropServices;
38 using System.Security.Permissions;
39 using System.Text;
40
41 namespace System.Drawing
42 {
43 #if !NET_2_0
44         [ComVisible(false)]  
45 #endif
46         public sealed class Graphics : MarshalByRefObject, IDisposable
47 #if NET_2_0
48         , IDeviceContext
49 #endif
50         {
51                 internal IntPtr nativeObject = IntPtr.Zero;
52                 internal CarbonContext context;
53                 private bool disposed = false;
54                 private static float defDpiX = 0;
55                 private static float defDpiY = 0;
56                 private IntPtr deviceContextHdc;
57
58 #if !NET_2_0
59                 [ComVisible(false)]
60 #endif
61                 public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
62                                                             int flags,
63                                                             int dataSize,
64                                                             IntPtr data,
65                                                             PlayRecordCallback callbackData);
66                 
67 #if !NET_2_0
68                 [ComVisible (false)]
69 #endif
70                 public delegate bool DrawImageAbort (IntPtr callbackData);
71
72                 internal Graphics (IntPtr nativeGraphics)
73                 {
74                         nativeObject = nativeGraphics;
75                 }
76
77                 ~Graphics ()
78                 {
79                         Dispose ();                     
80                 }               
81
82                 static internal float systemDpiX {
83                         get {
84                                 if (defDpiX == 0) {
85                                         Bitmap bmp = new Bitmap (1, 1);
86                                         Graphics g = Graphics.FromImage (bmp);
87                                         defDpiX = g.DpiX;
88                                         defDpiY = g.DpiY;
89                                 }
90                                 return defDpiX;
91                         }
92                 }
93
94                 static internal float systemDpiY {
95                         get {
96                                 if (defDpiY == 0) {
97                                         Bitmap bmp = new Bitmap (1, 1);
98                                         Graphics g = Graphics.FromImage (bmp);
99                                         defDpiX = g.DpiX;
100                                         defDpiY = g.DpiY;
101                                 }
102                                 return defDpiY;
103                         }
104                 }
105
106                 internal IntPtr NativeObject {
107                         get {
108                                 return nativeObject;
109                         }
110
111                         set {
112                                 nativeObject = value;
113                         }
114                 }
115                 
116                 [MonoTODO ("Metafiles, both WMF and EMF formats, aren't supported.")]
117                 public void AddMetafileComment (byte [] data)
118                 {
119                         throw new NotImplementedException ();
120                 }
121
122                 public GraphicsContainer BeginContainer ()
123                 {
124                         uint state;
125                         Status status;
126                         status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
127                         GDIPlus.CheckStatus (status);
128
129                         return new GraphicsContainer(state);
130                 }
131
132                 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]                
133                 public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
134                 {
135                         uint state;
136                         Status status;
137                         status = GDIPlus.GdipBeginContainerI (nativeObject, ref dstrect, ref srcrect, unit, out state);
138                         GDIPlus.CheckStatus (status);
139
140                         return new GraphicsContainer (state);
141                 }
142
143                 [MonoTODO ("The rectangles and unit parameters aren't supported in libgdiplus")]                
144                 public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
145                 {
146                         uint state;
147                         Status status;
148                         status = GDIPlus.GdipBeginContainer (nativeObject, ref dstrect, ref srcrect, unit, out state);
149                         GDIPlus.CheckStatus (status);
150
151                         return new GraphicsContainer (state);
152                 }
153
154                 
155                 public void Clear (Color color)
156                 {
157                         Status status;
158                         status = GDIPlus.GdipGraphicsClear (nativeObject, color.ToArgb ());
159                         GDIPlus.CheckStatus (status);
160                 }
161 #if NET_2_0             
162                 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
163                 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize)
164                 {
165                         CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
166                                 blockRegionSize, CopyPixelOperation.SourceCopy);                                
167                 }
168
169                 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
170                 public void CopyFromScreen (Point upperLeftSource, Point upperLeftDestination, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
171                 {
172                         CopyFromScreen (upperLeftSource.X, upperLeftSource.Y, upperLeftDestination.X, upperLeftDestination.Y,
173                                 blockRegionSize, copyPixelOperation);
174                 }
175                 
176                 [MonoLimitation ("Works on Win32 and on X11 (but not on Cocoa and Quartz)")]
177                 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize)
178                 {
179                         CopyFromScreen (sourceX, sourceY, destinationX, destinationY, blockRegionSize,
180                                 CopyPixelOperation.SourceCopy);
181                 }
182
183                 [MonoLimitation ("Works on Win32 and (for CopyPixelOperation.SourceCopy only) on X11 but not on Cocoa and Quartz")]
184                 public void CopyFromScreen (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
185                 {
186                         if (!Enum.IsDefined (typeof (CopyPixelOperation), copyPixelOperation))
187                                 throw new InvalidEnumArgumentException (Locale.GetText ("Enum argument value '{0}' is not valid for CopyPixelOperation", copyPixelOperation));
188
189                         if (GDIPlus.UseX11Drawable) {
190                                 CopyFromScreenX11 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
191                         } else if (GDIPlus.UseCocoaDrawable || GDIPlus.UseQuartzDrawable) {
192                                 CopyFromScreenMac (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
193                         } else {
194                                 CopyFromScreenWin32 (sourceX, sourceY, destinationX, destinationY, blockRegionSize, copyPixelOperation);
195                         }
196                 }
197
198                 private void CopyFromScreenWin32 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
199                 {
200                         IntPtr window = GDIPlus.GetDesktopWindow ();
201                         IntPtr srcDC = GDIPlus.GetDC (window);
202                         IntPtr dstDC = GetHdc ();
203                         GDIPlus.BitBlt (dstDC, destinationX, destinationY, blockRegionSize.Width,
204                                 blockRegionSize.Height, srcDC, sourceX, sourceY, (int) copyPixelOperation);
205
206                         GDIPlus.ReleaseDC (IntPtr.Zero, srcDC);
207                         ReleaseHdc (dstDC);                     
208                 }
209                 
210                 private void CopyFromScreenMac (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
211                 {
212                         throw new NotImplementedException ();
213                 }
214
215                 private void CopyFromScreenX11 (int sourceX, int sourceY, int destinationX, int destinationY, Size blockRegionSize, CopyPixelOperation copyPixelOperation)
216                 {
217                         IntPtr window, image, defvisual, vPtr;
218                         int AllPlanes = ~0, nitems = 0, pixel;
219
220                         if (copyPixelOperation != CopyPixelOperation.SourceCopy)
221                                 throw new NotImplementedException ("Operation not implemented under X11");
222                 
223                         if (GDIPlus.Display == IntPtr.Zero) {
224                                 GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);                                   
225                         }
226
227                         window = GDIPlus.XRootWindow (GDIPlus.Display, 0);
228                         defvisual = GDIPlus.XDefaultVisual (GDIPlus.Display, 0);                                
229                         XVisualInfo visual = new XVisualInfo ();
230
231                         /* Get XVisualInfo for this visual */
232                         visual.visualid = GDIPlus.XVisualIDFromVisual(defvisual);
233                         vPtr = GDIPlus.XGetVisualInfo (GDIPlus.Display, 0x1 /* VisualIDMask */, ref visual, ref nitems);
234                         visual = (XVisualInfo) Marshal.PtrToStructure(vPtr, typeof (XVisualInfo));
235
236                         /* Sorry I do not have access to a computer with > deepth. Fell free to add more pixel formats */       
237                         image = GDIPlus.XGetImage (GDIPlus.Display, window, sourceX, sourceY, blockRegionSize.Width,
238                                 blockRegionSize.Height, AllPlanes, 2 /* ZPixmap*/);
239                                 
240                         Bitmap bmp = new Bitmap (blockRegionSize.Width, blockRegionSize.Height);
241                         int red, blue, green;
242                         for (int y = sourceY; y <  sourceY + blockRegionSize.Height; y++) {
243                                 for (int x = sourceX; x <  sourceX + blockRegionSize.Width; x++) {
244                                         pixel = GDIPlus.XGetPixel (image, x, y);                        
245
246                                         switch (visual.depth) {
247                                                 case 16: /* 16bbp pixel transformation */
248                                                         red = (int) ((pixel & visual.red_mask ) >> 8) & 0xff;
249                                                         green = (int) (((pixel & visual.green_mask ) >> 3 )) & 0xff;
250                                                         blue = (int) ((pixel & visual.blue_mask ) << 3 ) & 0xff;
251                                                         break;
252                                                 case 24:
253                                                 case 32:
254                                                         red = (int) ((pixel & visual.red_mask ) >> 16) & 0xff;
255                                                         green = (int) (((pixel & visual.green_mask ) >> 8 )) & 0xff;
256                                                         blue = (int) ((pixel & visual.blue_mask )) & 0xff;
257                                                         break;
258                                                 default:
259                                                         throw new NotImplementedException ("Deepth not supported right now");
260                                         }
261                                                 
262                                         bmp.SetPixel (x, y, Color.FromArgb (255, red, green, blue));                                                     
263                                 }
264                         }
265
266                         DrawImage (bmp, 0, 0);
267                         bmp.Dispose ();
268                         GDIPlus.XDestroyImage (image);
269                         GDIPlus.XFree (vPtr);
270                 }
271 #endif
272
273                 public void Dispose ()
274                 {
275                         Status status;
276                         if (! disposed) {
277                                 if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero) {
278                                         Flush ();
279                                         Carbon.CGContextSynchronize (context.ctx);
280                                         Carbon.ReleaseContext (context.port, context.ctx);
281                                 }
282                                 status = GDIPlus.GdipDeleteGraphics (nativeObject);
283                                 nativeObject = IntPtr.Zero;
284                                 GDIPlus.CheckStatus (status);
285                                 disposed = true;                                
286                         }
287
288                         GC.SuppressFinalize(this);
289                 }
290
291                 
292                 public void DrawArc (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
293                 {
294                         DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
295                 }
296
297                 
298                 public void DrawArc (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
299                 {
300                         DrawArc (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
301                 }
302
303                 
304                 public void DrawArc (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
305                 {
306                         Status status;
307                         if (pen == null)
308                                 throw new ArgumentNullException ("pen");
309                         
310                         status = GDIPlus.GdipDrawArc (nativeObject, pen.nativeObject,
311                                         x, y, width, height, startAngle, sweepAngle);
312                         GDIPlus.CheckStatus (status);
313                 }
314
315                 // Microsoft documentation states that the signature for this member should be
316                 // public void DrawArc( Pen pen,  int x,  int y,  int width,  int height,   int startAngle,
317                 // int sweepAngle. However, GdipDrawArcI uses also float for the startAngle and sweepAngle params
318                 public void DrawArc (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
319                 {
320                         Status status;
321                         if (pen == null)
322                                 throw new ArgumentNullException ("pen");
323                         status = GDIPlus.GdipDrawArcI (nativeObject, pen.nativeObject,
324                                                 x, y, width, height, startAngle, sweepAngle);
325                         GDIPlus.CheckStatus (status);
326                 }
327
328                 public void DrawBezier (Pen pen, PointF pt1, PointF pt2, PointF pt3, PointF pt4)
329                 {
330                         Status status;
331                         if (pen == null)
332                                 throw new ArgumentNullException ("pen");
333                         status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject,
334                                                         pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
335                                                         pt3.Y, pt4.X, pt4.Y);
336                         GDIPlus.CheckStatus (status);
337                 }
338
339                 public void DrawBezier (Pen pen, Point pt1, Point pt2, Point pt3, Point pt4)
340                 {
341                         Status status;
342                         if (pen == null)
343                                 throw new ArgumentNullException ("pen");
344                         status = GDIPlus.GdipDrawBezierI (nativeObject, pen.nativeObject,
345                                                         pt1.X, pt1.Y, pt2.X, pt2.Y, pt3.X,
346                                                         pt3.Y, pt4.X, pt4.Y);
347                         GDIPlus.CheckStatus (status);
348                 }
349
350                 public void DrawBezier (Pen pen, float x1, float y1, float x2, float y2, float x3, float y3, float x4, float y4)
351                 {
352                         Status status;
353                         if (pen == null)
354                                 throw new ArgumentNullException ("pen");
355                         status = GDIPlus.GdipDrawBezier (nativeObject, pen.nativeObject, x1,
356                                                         y1, x2, y2, x3, y3, x4, y4);
357                         GDIPlus.CheckStatus (status);
358                 }
359
360                 public void DrawBeziers (Pen pen, Point [] points)
361                 {
362                         if (pen == null)
363                                 throw new ArgumentNullException ("pen");
364                         if (points == null)
365                                 throw new ArgumentNullException ("points");
366                         
367                         int length = points.Length;
368                         Status status;
369
370                         if (length < 4)
371                                 return;
372
373                         for (int i = 0; i < length - 1; i += 3) {
374                                 Point p1 = points [i];
375                                 Point p2 = points [i + 1];
376                                 Point p3 = points [i + 2];
377                                 Point p4 = points [i + 3];
378
379                                 status = GDIPlus.GdipDrawBezier (nativeObject, 
380                                                         pen.nativeObject,
381                                                         p1.X, p1.Y, p2.X, p2.Y, 
382                                                         p3.X, p3.Y, p4.X, p4.Y);
383                                 GDIPlus.CheckStatus (status);
384                         }
385                 }
386
387                 public void DrawBeziers (Pen pen, PointF [] points)
388                 {
389                         if (pen == null)
390                                 throw new ArgumentNullException ("pen");
391                         if (points == null)
392                                 throw new ArgumentNullException ("points");
393                         
394                         int length = points.Length;
395                         Status status;
396
397                         if (length < 4)
398                                 return;
399
400                         for (int i = 0; i < length - 1; i += 3) {
401                                 PointF p1 = points [i];
402                                 PointF p2 = points [i + 1];
403                                 PointF p3 = points [i + 2];
404                                 PointF p4 = points [i + 3];
405
406                                 status = GDIPlus.GdipDrawBezier (nativeObject, 
407                                                         pen.nativeObject,
408                                                         p1.X, p1.Y, p2.X, p2.Y, 
409                                                         p3.X, p3.Y, p4.X, p4.Y);
410                                 GDIPlus.CheckStatus (status);
411                         }
412                 }
413
414                 
415                 public void DrawClosedCurve (Pen pen, PointF [] points)
416                 {
417                         if (pen == null)
418                                 throw new ArgumentNullException ("pen");
419                         if (points == null)
420                                 throw new ArgumentNullException ("points");
421                         
422                         Status status;
423                         status = GDIPlus.GdipDrawClosedCurve (nativeObject, pen.nativeObject, points, points.Length);
424                         GDIPlus.CheckStatus (status);
425                 }
426                 
427                 public void DrawClosedCurve (Pen pen, Point [] points)
428                 {
429                         if (pen == null)
430                                 throw new ArgumentNullException ("pen");
431                         if (points == null)
432                                 throw new ArgumentNullException ("points");
433                         
434                         Status status;
435                         status = GDIPlus.GdipDrawClosedCurveI (nativeObject, pen.nativeObject, points, points.Length);
436                         GDIPlus.CheckStatus (status);
437                 }
438                         
439                 public void DrawClosedCurve (Pen pen, Point [] points, float tension, FillMode fillmode)
440                 {
441                         if (pen == null)
442                                 throw new ArgumentNullException ("pen");
443                         if (points == null)
444                                 throw new ArgumentNullException ("points");
445                         
446                         Status status;
447                         status = GDIPlus.GdipDrawClosedCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);
448                         GDIPlus.CheckStatus (status);
449                 }
450                 
451                 public void DrawClosedCurve (Pen pen, PointF [] points, float tension, FillMode fillmode)
452                 {
453                         if (pen == null)
454                                 throw new ArgumentNullException ("pen");
455                         if (points == null)
456                                 throw new ArgumentNullException ("points");
457                         
458                         Status status;
459                         status = GDIPlus.GdipDrawClosedCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
460                         GDIPlus.CheckStatus (status);
461                 }
462                 
463                 public void DrawCurve (Pen pen, Point [] points)
464                 {
465                         if (pen == null)
466                                 throw new ArgumentNullException ("pen");
467                         if (points == null)
468                                 throw new ArgumentNullException ("points");
469                         
470                         Status status;
471                         status = GDIPlus.GdipDrawCurveI (nativeObject, pen.nativeObject, points, points.Length);
472                         GDIPlus.CheckStatus (status);
473                 }
474                 
475                 public void DrawCurve (Pen pen, PointF [] points)
476                 {
477                         if (pen == null)
478                                 throw new ArgumentNullException ("pen");
479                         if (points == null)
480                                 throw new ArgumentNullException ("points");
481                         
482                         Status status;
483                         status = GDIPlus.GdipDrawCurve (nativeObject, pen.nativeObject, points, points.Length);
484                         GDIPlus.CheckStatus (status);
485                 }
486                 
487                 public void DrawCurve (Pen pen, PointF [] points, float tension)
488                 {
489                         if (pen == null)
490                                 throw new ArgumentNullException ("pen");
491                         if (points == null)
492                                 throw new ArgumentNullException ("points");
493                         
494                         Status status;
495                         status = GDIPlus.GdipDrawCurve2 (nativeObject, pen.nativeObject, points, points.Length, tension);
496                         GDIPlus.CheckStatus (status);
497                 }
498                 
499                 public void DrawCurve (Pen pen, Point [] points, float tension)
500                 {
501                         if (pen == null)
502                                 throw new ArgumentNullException ("pen");
503                         if (points == null)
504                                 throw new ArgumentNullException ("points");
505                         
506                         Status status;
507                         status = GDIPlus.GdipDrawCurve2I (nativeObject, pen.nativeObject, points, points.Length, tension);              
508                         GDIPlus.CheckStatus (status);
509                 }
510                 
511                 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
512                 {
513                         if (pen == null)
514                                 throw new ArgumentNullException ("pen");
515                         if (points == null)
516                                 throw new ArgumentNullException ("points");
517                         
518                         Status status;
519                         status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
520                                                         points, points.Length, offset,
521                                                         numberOfSegments, 0.5f);
522                         GDIPlus.CheckStatus (status);
523                 }
524
525                 public void DrawCurve (Pen pen, Point [] points, int offset, int numberOfSegments, float tension)
526                 {
527                         if (pen == null)
528                                 throw new ArgumentNullException ("pen");
529                         if (points == null)
530                                 throw new ArgumentNullException ("points");
531                         
532                         Status status;
533                         status = GDIPlus.GdipDrawCurve3I (nativeObject, pen.nativeObject,
534                                                         points, points.Length, offset,
535                                                         numberOfSegments, tension);
536                         GDIPlus.CheckStatus (status);
537                 }
538
539                 public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
540                 {
541                         if (pen == null)
542                                 throw new ArgumentNullException ("pen");
543                         if (points == null)
544                                 throw new ArgumentNullException ("points");
545                         
546                         Status status;
547                         status = GDIPlus.GdipDrawCurve3 (nativeObject, pen.nativeObject,
548                                                         points, points.Length, offset,
549                                                         numberOfSegments, tension);
550                         GDIPlus.CheckStatus (status);
551                 }
552
553                 public void DrawEllipse (Pen pen, Rectangle rect)
554                 {
555                         if (pen == null)
556                                 throw new ArgumentNullException ("pen");
557                         
558                         DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
559                 }
560
561                 public void DrawEllipse (Pen pen, RectangleF rect)
562                 {
563                         if (pen == null)
564                                 throw new ArgumentNullException ("pen");
565                         DrawEllipse (pen, rect.X, rect.Y, rect.Width, rect.Height);
566                 }
567
568                 public void DrawEllipse (Pen pen, int x, int y, int width, int height)
569                 {
570                         if (pen == null)
571                                 throw new ArgumentNullException ("pen");
572                         Status status;
573                         status = GDIPlus.GdipDrawEllipseI (nativeObject, pen.nativeObject, x, y, width, height);
574                         GDIPlus.CheckStatus (status);
575                 }
576
577                 public void DrawEllipse (Pen pen, float x, float y, float width, float height)
578                 {
579                         if (pen == null)
580                                 throw new ArgumentNullException ("pen");
581                         Status status = GDIPlus.GdipDrawEllipse (nativeObject, pen.nativeObject, x, y, width, height);
582                         GDIPlus.CheckStatus (status);
583                 }
584
585                 public void DrawIcon (Icon icon, Rectangle targetRect)
586                 {
587                         if (icon == null)
588                                 throw new ArgumentNullException ("icon");
589
590                         DrawImage (icon.GetInternalBitmap (), targetRect);
591                 }
592
593                 public void DrawIcon (Icon icon, int x, int y)
594                 {
595                         if (icon == null)
596                                 throw new ArgumentNullException ("icon");
597
598                         DrawImage (icon.GetInternalBitmap (), x, y);
599                 }
600
601                 public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
602                 {
603                         if (icon == null)
604                                 throw new ArgumentNullException ("icon");
605
606                         DrawImageUnscaled (icon.GetInternalBitmap (), targetRect);
607                 }
608                 
609                 public void DrawImage (Image image, RectangleF rect)
610                 {
611                         if (image == null)
612                                 throw new ArgumentNullException ("image");
613                         
614                         Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, rect.X, rect.Y, rect.Width, rect.Height);
615                         GDIPlus.CheckStatus (status);
616                 }
617
618                 public void DrawImage (Image image, PointF point)
619                 {
620                         if (image == null)
621                                 throw new ArgumentNullException ("image");
622                         
623                         Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, point.X, point.Y);
624                         GDIPlus.CheckStatus (status);
625                 }
626
627                 public void DrawImage (Image image, Point [] destPoints)
628                 {
629                         if (image == null)
630                                 throw new ArgumentNullException ("image");
631                         if (destPoints == null)
632                                 throw new ArgumentNullException ("destPoints");
633                         
634                         Status status = GDIPlus.GdipDrawImagePointsI (nativeObject, image.NativeObject, destPoints, destPoints.Length);
635                         GDIPlus.CheckStatus (status);
636                 }
637
638                 public void DrawImage (Image image, Point point)
639                 {
640                         if (image == null)
641                                 throw new ArgumentNullException ("image");
642                         DrawImage (image, point.X, point.Y);
643                 }
644
645                 public void DrawImage (Image image, Rectangle rect)
646                 {
647                         if (image == null)
648                                 throw new ArgumentNullException ("image");
649                         DrawImage (image, rect.X, rect.Y, rect.Width, rect.Height);
650                 }
651
652                 public void DrawImage (Image image, PointF [] destPoints)
653                 {
654                         if (image == null)
655                                 throw new ArgumentNullException ("image");
656                         if (destPoints == null)
657                                 throw new ArgumentNullException ("destPoints");
658                         Status status = GDIPlus.GdipDrawImagePoints (nativeObject, image.NativeObject, destPoints, destPoints.Length);
659                         GDIPlus.CheckStatus (status);
660                 }
661
662                 public void DrawImage (Image image, int x, int y)
663                 {
664                         if (image == null)
665                                 throw new ArgumentNullException ("image");
666                         Status status = GDIPlus.GdipDrawImageI (nativeObject, image.NativeObject, x, y);
667                         GDIPlus.CheckStatus (status);
668                 }
669
670                 public void DrawImage (Image image, float x, float y)
671                 {
672                         if (image == null)
673                                 throw new ArgumentNullException ("image");
674                         Status status = GDIPlus.GdipDrawImage (nativeObject, image.NativeObject, x, y);
675                         GDIPlus.CheckStatus (status);
676                 }
677
678                 public void DrawImage (Image image, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit)
679                 {
680                         if (image == null)
681                                 throw new ArgumentNullException ("image");
682                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
683                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
684                                 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
685                                 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
686                         GDIPlus.CheckStatus (status);
687                 }
688                 
689                 public void DrawImage (Image image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit)
690                 {                       
691                         if (image == null)
692                                 throw new ArgumentNullException ("image");
693                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
694                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
695                                 srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height,
696                                 srcUnit, IntPtr.Zero, null, IntPtr.Zero);
697                         GDIPlus.CheckStatus (status);
698                 }
699
700                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit)
701                 {
702                         if (image == null)
703                                 throw new ArgumentNullException ("image");
704                         if (destPoints == null)
705                                 throw new ArgumentNullException ("destPoints");
706                         
707                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
708                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
709                                 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
710                                 null, IntPtr.Zero);
711                         GDIPlus.CheckStatus (status);
712                 }
713
714                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit)
715                 {
716                         if (image == null)
717                                 throw new ArgumentNullException ("image");
718                         if (destPoints == null)
719                                 throw new ArgumentNullException ("destPoints");
720                         
721                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
722                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
723                                 srcRect.Width, srcRect.Height, srcUnit, IntPtr.Zero, 
724                                 null, IntPtr.Zero);
725                         GDIPlus.CheckStatus (status);
726                 }
727
728                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, 
729                                 ImageAttributes imageAttr)
730                 {
731                         if (image == null)
732                                 throw new ArgumentNullException ("image");
733                         if (destPoints == null)
734                                 throw new ArgumentNullException ("destPoints");
735                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
736                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
737                                 srcRect.Width, srcRect.Height, srcUnit,
738                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
739                         GDIPlus.CheckStatus (status);
740                 }
741                 
742                 public void DrawImage (Image image, float x, float y, float width, float height)
743                 {
744                         if (image == null)
745                                 throw new ArgumentNullException ("image");
746                         Status status = GDIPlus.GdipDrawImageRect(nativeObject, image.NativeObject, x, y,
747                            width, height);
748                         GDIPlus.CheckStatus (status);
749                 }
750
751                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, 
752                                 ImageAttributes imageAttr)
753                 {
754                         if (image == null)
755                                 throw new ArgumentNullException ("image");
756                         if (destPoints == null)
757                                 throw new ArgumentNullException ("destPoints");
758                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
759                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
760                                 srcRect.Width, srcRect.Height, srcUnit, 
761                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
762                         GDIPlus.CheckStatus (status);
763                 }
764
765                 public void DrawImage (Image image, int x, int y, Rectangle srcRect, GraphicsUnit srcUnit)
766                 {                       
767                         if (image == null)
768                                 throw new ArgumentNullException ("image");
769                         Status status = GDIPlus.GdipDrawImagePointRectI(nativeObject, image.NativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
770                         GDIPlus.CheckStatus (status);
771                 }
772                 
773                 public void DrawImage (Image image, int x, int y, int width, int height)
774                 {
775                         if (image == null)
776                                 throw new ArgumentNullException ("image");
777                         Status status = GDIPlus.GdipDrawImageRectI (nativeObject, image.nativeObject, x, y, width, height);
778                         GDIPlus.CheckStatus (status);
779                 }
780
781                 public void DrawImage (Image image, float x, float y, RectangleF srcRect, GraphicsUnit srcUnit)
782                 {                       
783                         if (image == null)
784                                 throw new ArgumentNullException ("image");
785                         Status status = GDIPlus.GdipDrawImagePointRect (nativeObject, image.nativeObject, x, y, srcRect.X, srcRect.Y, srcRect.Width, srcRect.Height, srcUnit);
786                         GDIPlus.CheckStatus (status);
787                 }
788
789                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
790                 {
791                         if (image == null)
792                                 throw new ArgumentNullException ("image");
793                         if (destPoints == null)
794                                 throw new ArgumentNullException ("destPoints");
795                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
796                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
797                                 srcRect.Width, srcRect.Height, srcUnit, 
798                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
799                         GDIPlus.CheckStatus (status);
800                 }
801
802                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
803                 {
804                         if (image == null)
805                                 throw new ArgumentNullException ("image");
806                         if (destPoints == null)
807                                 throw new ArgumentNullException ("destPoints");
808                         
809                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
810                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
811                                 srcRect.Width, srcRect.Height, srcUnit, 
812                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, IntPtr.Zero);
813                         GDIPlus.CheckStatus (status);
814                 }
815
816                 public void DrawImage (Image image, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
817                 {
818                         if (image == null)
819                                 throw new ArgumentNullException ("image");
820                         if (destPoints == null)
821                                 throw new ArgumentNullException ("destPoints");
822
823                         Status status = GDIPlus.GdipDrawImagePointsRectI (nativeObject, image.NativeObject,
824                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y, 
825                                 srcRect.Width, srcRect.Height, srcUnit, 
826                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
827                         GDIPlus.CheckStatus (status);
828                 }
829
830                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit)
831                 {
832                         if (image == null)
833                                 throw new ArgumentNullException ("image");
834                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
835                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
836                                 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
837                                 null, IntPtr.Zero);
838                         GDIPlus.CheckStatus (status);                                   
839                 }
840                 
841                 public void DrawImage (Image image, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, int callbackData)
842                 {
843                         Status status = GDIPlus.GdipDrawImagePointsRect (nativeObject, image.NativeObject,
844                                 destPoints, destPoints.Length , srcRect.X, srcRect.Y,
845                                 srcRect.Width, srcRect.Height, srcUnit, 
846                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, (IntPtr) callbackData);
847                         GDIPlus.CheckStatus (status);
848                 }
849
850                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit)
851                 {
852                         if (image == null)
853                                 throw new ArgumentNullException ("image");
854                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject,
855                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
856                                 srcX, srcY, srcWidth, srcHeight, srcUnit, IntPtr.Zero, 
857                                 null, IntPtr.Zero);
858                         GDIPlus.CheckStatus (status);
859                 }
860
861                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttrs)
862                 {
863                         if (image == null)
864                                 throw new ArgumentNullException ("image");
865                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject,
866                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
867                                 srcX, srcY, srcWidth, srcHeight, srcUnit,
868                                 imageAttrs != null ? imageAttrs.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
869                         GDIPlus.CheckStatus (status);
870                 }
871                 
872                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr)
873                 {                       
874                         if (image == null)
875                                 throw new ArgumentNullException ("image");
876                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
877                                         destRect.X, destRect.Y, destRect.Width, 
878                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
879                                         srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, null, IntPtr.Zero);
880                         GDIPlus.CheckStatus (status);
881                 }
882                 
883                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
884                 {
885                         if (image == null)
886                                 throw new ArgumentNullException ("image");
887                         Status status = GDIPlus.GdipDrawImageRectRectI (nativeObject, image.NativeObject, 
888                                         destRect.X, destRect.Y, destRect.Width, 
889                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
890                                         srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback,
891                                         IntPtr.Zero);
892                         GDIPlus.CheckStatus (status);
893                 }
894                 
895                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback)
896                 {
897                         if (image == null)
898                                 throw new ArgumentNullException ("image");
899                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
900                                         destRect.X, destRect.Y, destRect.Width, 
901                                         destRect.Height, srcX, srcY, srcWidth, srcHeight,
902                                         srcUnit, imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, 
903                                         callback, IntPtr.Zero);
904                         GDIPlus.CheckStatus (status);
905                 }
906
907                 public void DrawImage (Image image, Rectangle destRect, float srcX, float srcY, float srcWidth, float srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
908                 {
909                         if (image == null)
910                                 throw new ArgumentNullException ("image");
911                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
912                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
913                                 srcX, srcY, srcWidth, srcHeight, srcUnit, 
914                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
915                         GDIPlus.CheckStatus (status);
916                 }
917
918                 public void DrawImage (Image image, Rectangle destRect, int srcX, int srcY, int srcWidth, int srcHeight, GraphicsUnit srcUnit, ImageAttributes imageAttr, DrawImageAbort callback, IntPtr callbackData)
919                 {
920                         if (image == null)
921                                 throw new ArgumentNullException ("image");
922                         Status status = GDIPlus.GdipDrawImageRectRect (nativeObject, image.NativeObject, 
923                                 destRect.X, destRect.Y, destRect.Width, destRect.Height,
924                                 srcX, srcY, srcWidth, srcHeight, srcUnit,
925                                 imageAttr != null ? imageAttr.NativeObject : IntPtr.Zero, callback, callbackData);
926                         GDIPlus.CheckStatus (status);
927                 }               
928                 
929                 public void DrawImageUnscaled (Image image, Point point)
930                 {
931                         DrawImageUnscaled (image, point.X, point.Y);
932                 }
933                 
934                 public void DrawImageUnscaled (Image image, Rectangle rect)
935                 {
936                         DrawImageUnscaled (image, rect.X, rect.Y, rect.Width, rect.Height);
937                 }
938                 
939                 public void DrawImageUnscaled (Image image, int x, int y)
940                 {
941                         if (image == null)
942                                 throw new ArgumentNullException ("image");
943                         DrawImage (image, x, y, image.Width, image.Height);
944                 }
945
946                 public void DrawImageUnscaled (Image image, int x, int y, int width, int height)
947                 {
948                         if (image == null)
949                                 throw new ArgumentNullException ("image");
950
951                         // avoid creating an empty, or negative w/h, bitmap...
952                         if ((width <= 0) || (height <= 0))
953                                 return;
954
955                         using (Image tmpImg = new Bitmap (width, height)) {
956                                 using (Graphics g = FromImage (tmpImg)) {
957                                         g.DrawImage (image, 0, 0, image.Width, image.Height);
958                                         DrawImage (tmpImg, x, y, width, height);
959                                 }
960                         }
961                 }
962
963 #if NET_2_0
964                 public void DrawImageUnscaledAndClipped (Image image, Rectangle rect)
965                 {
966                         if (image == null)
967                                 throw new ArgumentNullException ("image");
968
969                         int width = (image.Width > rect.Width) ? rect.Width : image.Width;
970                         int height = (image.Height > rect.Height) ? rect.Height : image.Height;
971
972                         DrawImageUnscaled (image, rect.X, rect.Y, width, height);                       
973                 }
974 #endif
975
976                 public void DrawLine (Pen pen, PointF pt1, PointF pt2)
977                 {
978                         if (pen == null)
979                                 throw new ArgumentNullException ("pen");
980                         Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject,
981                                                 pt1.X, pt1.Y, pt2.X, pt2.Y);
982                         GDIPlus.CheckStatus (status);
983                 }
984
985                 public void DrawLine (Pen pen, Point pt1, Point pt2)
986                 {
987                         if (pen == null)
988                                 throw new ArgumentNullException ("pen");
989                         Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject,
990                                                 pt1.X, pt1.Y, pt2.X, pt2.Y);
991                         GDIPlus.CheckStatus (status);
992                 }
993
994                 public void DrawLine (Pen pen, int x1, int y1, int x2, int y2)
995                 {
996                         if (pen == null)
997                                 throw new ArgumentNullException ("pen");
998                         Status status = GDIPlus.GdipDrawLineI (nativeObject, pen.nativeObject, x1, y1, x2, y2);
999                         GDIPlus.CheckStatus (status);
1000                 }
1001
1002                 public void DrawLine (Pen pen, float x1, float y1, float x2, float y2)
1003                 {
1004                         if (pen == null)
1005                                 throw new ArgumentNullException ("pen");
1006                         Status status = GDIPlus.GdipDrawLine (nativeObject, pen.nativeObject, x1, y1, x2, y2);
1007                         GDIPlus.CheckStatus (status);
1008                 }
1009
1010                 public void DrawLines (Pen pen, PointF [] points)
1011                 {
1012                         if (pen == null)
1013                                 throw new ArgumentNullException ("pen");
1014                         if (points == null)
1015                                 throw new ArgumentNullException ("points");
1016                         Status status = GDIPlus.GdipDrawLines (nativeObject, pen.nativeObject, points, points.Length);
1017                         GDIPlus.CheckStatus (status);
1018                 }
1019
1020                 public void DrawLines (Pen pen, Point [] points)
1021                 {
1022                         if (pen == null)
1023                                 throw new ArgumentNullException ("pen");
1024                         if (points == null)
1025                                 throw new ArgumentNullException ("points");
1026                         Status status = GDIPlus.GdipDrawLinesI (nativeObject, pen.nativeObject, points, points.Length);
1027                         GDIPlus.CheckStatus (status);
1028                 }
1029
1030                 public void DrawPath (Pen pen, GraphicsPath path)
1031                 {
1032                         if (pen == null)
1033                                 throw new ArgumentNullException ("pen");
1034                         if (path == null)
1035                                 throw new ArgumentNullException ("path");
1036                         Status status = GDIPlus.GdipDrawPath (nativeObject, pen.nativeObject, path.nativePath);
1037                         GDIPlus.CheckStatus (status);
1038                 }
1039                 
1040                 public void DrawPie (Pen pen, Rectangle rect, float startAngle, float sweepAngle)
1041                 {
1042                         if (pen == null)
1043                                 throw new ArgumentNullException ("pen");
1044                         DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1045                 }
1046                 
1047                 public void DrawPie (Pen pen, RectangleF rect, float startAngle, float sweepAngle)
1048                 {
1049                         if (pen == null)
1050                                 throw new ArgumentNullException ("pen");
1051                         DrawPie (pen, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1052                 }
1053                 
1054                 public void DrawPie (Pen pen, float x, float y, float width, float height, float startAngle, float sweepAngle)
1055                 {
1056                         if (pen == null)
1057                                 throw new ArgumentNullException ("pen");
1058                         Status status = GDIPlus.GdipDrawPie (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1059                         GDIPlus.CheckStatus (status);
1060                 }
1061                 
1062                 // Microsoft documentation states that the signature for this member should be
1063                 // public void DrawPie(Pen pen, int x,  int y,  int width,   int height,   int startAngle
1064                 // int sweepAngle. However, GdipDrawPieI uses also float for the startAngle and sweepAngle params
1065                 public void DrawPie (Pen pen, int x, int y, int width, int height, int startAngle, int sweepAngle)
1066                 {
1067                         if (pen == null)
1068                                 throw new ArgumentNullException ("pen");
1069                         Status status = GDIPlus.GdipDrawPieI (nativeObject, pen.nativeObject, x, y, width, height, startAngle, sweepAngle);
1070                         GDIPlus.CheckStatus (status);
1071                 }
1072
1073                 public void DrawPolygon (Pen pen, Point [] points)
1074                 {
1075                         if (pen == null)
1076                                 throw new ArgumentNullException ("pen");
1077                         if (points == null)
1078                                 throw new ArgumentNullException ("points");
1079                         Status status = GDIPlus.GdipDrawPolygonI (nativeObject, pen.nativeObject, points, points.Length);
1080                         GDIPlus.CheckStatus (status);
1081                 }
1082
1083                 public void DrawPolygon (Pen pen, PointF [] points)
1084                 {
1085                         if (pen == null)
1086                                 throw new ArgumentNullException ("pen");
1087                         if (points == null)
1088                                 throw new ArgumentNullException ("points");
1089                         Status status = GDIPlus.GdipDrawPolygon (nativeObject, pen.nativeObject, points, points.Length);
1090                         GDIPlus.CheckStatus (status);
1091                 }
1092
1093                 internal void DrawRectangle (Pen pen, RectangleF rect)
1094                 {
1095                         if (pen == null)
1096                                 throw new ArgumentNullException ("pen");
1097                         DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1098                 }
1099
1100                 public void DrawRectangle (Pen pen, Rectangle rect)
1101                 {
1102                         if (pen == null)
1103                                 throw new ArgumentNullException ("pen");
1104                         DrawRectangle (pen, rect.Left, rect.Top, rect.Width, rect.Height);
1105                 }
1106
1107                 public void DrawRectangle (Pen pen, float x, float y, float width, float height)
1108                 {
1109                         if (pen == null)
1110                                 throw new ArgumentNullException ("pen");
1111                         Status status = GDIPlus.GdipDrawRectangle (nativeObject, pen.nativeObject, x, y, width, height);
1112                         GDIPlus.CheckStatus (status);
1113                 }
1114
1115                 public void DrawRectangle (Pen pen, int x, int y, int width, int height)
1116                 {
1117                         if (pen == null)
1118                                 throw new ArgumentNullException ("pen");
1119                         Status status = GDIPlus.GdipDrawRectangleI (nativeObject, pen.nativeObject, x, y, width, height);
1120                         GDIPlus.CheckStatus (status);
1121                 }
1122
1123                 public void DrawRectangles (Pen pen, RectangleF [] rects)
1124                 {
1125                         if (pen == null)
1126                                 throw new ArgumentNullException ("image");
1127                         if (rects == null)
1128                                 throw new ArgumentNullException ("rects");
1129                         Status status = GDIPlus.GdipDrawRectangles (nativeObject, pen.nativeObject, rects, rects.Length);
1130                         GDIPlus.CheckStatus (status);
1131                 }
1132
1133                 public void DrawRectangles (Pen pen, Rectangle [] rects)
1134                 {
1135                         if (pen == null)
1136                                 throw new ArgumentNullException ("image");
1137                         if (rects == null)
1138                                 throw new ArgumentNullException ("rects");
1139                         Status status = GDIPlus.GdipDrawRectanglesI (nativeObject, pen.nativeObject, rects, rects.Length);
1140                         GDIPlus.CheckStatus (status);
1141                 }
1142
1143                 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle)
1144                 {
1145                         DrawString (s, font, brush, layoutRectangle, null);
1146                 }
1147
1148                 public void DrawString (string s, Font font, Brush brush, PointF point)
1149                 {
1150                         DrawString (s, font, brush, new RectangleF (point.X, point.Y, 0, 0), null);
1151                 }
1152
1153                 public void DrawString (string s, Font font, Brush brush, PointF point, StringFormat format)
1154                 {
1155                         DrawString(s, font, brush, new RectangleF(point.X, point.Y, 0, 0), format);
1156                 }
1157
1158                 public void DrawString (string s, Font font, Brush brush, float x, float y)
1159                 {
1160                         DrawString (s, font, brush, new RectangleF (x, y, 0, 0), null);
1161                 }
1162
1163                 public void DrawString (string s, Font font, Brush brush, float x, float y, StringFormat format)
1164                 {
1165                         DrawString (s, font, brush, new RectangleF(x, y, 0, 0), format);
1166                 }
1167
1168                 public void DrawString (string s, Font font, Brush brush, RectangleF layoutRectangle, StringFormat format)
1169                 {
1170                         if (font == null)
1171                                 throw new ArgumentNullException ("font");
1172                         if (brush == null)
1173                                 throw new ArgumentNullException ("brush");
1174                         if (s == null || s.Length == 0)
1175                                 return;
1176
1177                         Status status = GDIPlus.GdipDrawString (nativeObject, s, s.Length, font.NativeObject, ref layoutRectangle, format != null ? format.NativeObject : IntPtr.Zero, brush.nativeObject);
1178                         GDIPlus.CheckStatus (status);
1179                 }
1180
1181                 public void EndContainer (GraphicsContainer container)
1182                 {
1183 #if NET_2_0
1184                         if (container == null)
1185                                 throw new ArgumentNullException ("container");
1186 #endif
1187                         Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
1188                         GDIPlus.CheckStatus (status);
1189                 }
1190
1191                 private const string MetafileEnumeration = "Metafiles enumeration, for both WMF and EMF formats, isn't supported.";
1192
1193                 [MonoTODO (MetafileEnumeration)]
1194                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback)
1195                 {
1196                         throw new NotImplementedException ();
1197                 }
1198
1199                 [MonoTODO (MetafileEnumeration)]
1200                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback)
1201                 {
1202                         throw new NotImplementedException ();
1203                 }
1204
1205                 [MonoTODO (MetafileEnumeration)]
1206                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback)
1207                 {
1208                         throw new NotImplementedException ();
1209                 }
1210
1211                 [MonoTODO (MetafileEnumeration)]
1212                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback)
1213                 {
1214                         throw new NotImplementedException ();
1215                 }
1216
1217                 [MonoTODO (MetafileEnumeration)]
1218                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback)
1219                 {
1220                         throw new NotImplementedException ();
1221                 }
1222
1223                 [MonoTODO (MetafileEnumeration)]
1224                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback)
1225                 {
1226                         throw new NotImplementedException ();
1227                 }
1228
1229                 [MonoTODO (MetafileEnumeration)]
1230                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1231                 {
1232                         throw new NotImplementedException ();
1233                 }
1234
1235                 [MonoTODO (MetafileEnumeration)]
1236                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1237                 {
1238                         throw new NotImplementedException ();
1239                 }
1240
1241                 [MonoTODO (MetafileEnumeration)]
1242                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1243                 {
1244                         throw new NotImplementedException ();
1245                 }
1246
1247                 [MonoTODO (MetafileEnumeration)]
1248                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData)
1249                 {
1250                         throw new NotImplementedException ();
1251                 }
1252
1253                 [MonoTODO (MetafileEnumeration)]
1254                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData)
1255                 {
1256                         throw new NotImplementedException ();
1257                 }
1258
1259                 [MonoTODO (MetafileEnumeration)]
1260                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData)
1261                 {
1262                         throw new NotImplementedException ();
1263                 }
1264
1265                 [MonoTODO (MetafileEnumeration)]
1266                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1267                 {
1268                         throw new NotImplementedException ();
1269                 }
1270
1271                 [MonoTODO (MetafileEnumeration)]
1272                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1273                 {
1274                         throw new NotImplementedException ();
1275                 }
1276
1277                 [MonoTODO (MetafileEnumeration)]
1278                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1279                 {
1280                         throw new NotImplementedException ();
1281                 }
1282
1283                 [MonoTODO (MetafileEnumeration)]
1284                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1285                 {
1286                         throw new NotImplementedException ();
1287                 }
1288
1289                 [MonoTODO (MetafileEnumeration)]
1290                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1291                 {
1292                         throw new NotImplementedException ();
1293                 }
1294
1295                 [MonoTODO (MetafileEnumeration)]
1296                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback)
1297                 {
1298                         throw new NotImplementedException ();
1299                 }
1300
1301                 [MonoTODO (MetafileEnumeration)]
1302                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1303                 {
1304                         throw new NotImplementedException ();
1305                 }
1306
1307                 [MonoTODO (MetafileEnumeration)]
1308                 public void EnumerateMetafile (Metafile metafile, Point destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1309                 {
1310                         throw new NotImplementedException ();
1311                 }
1312
1313                 [MonoTODO (MetafileEnumeration)]
1314                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1315                 {
1316                         throw new NotImplementedException ();
1317                 }
1318
1319                 [MonoTODO (MetafileEnumeration)]
1320                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1321                 {
1322                         throw new NotImplementedException ();
1323                 }
1324
1325                 [MonoTODO (MetafileEnumeration)]
1326                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1327                 {
1328                         throw new NotImplementedException ();
1329                 }
1330
1331                 [MonoTODO (MetafileEnumeration)]
1332                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1333                 {
1334                         throw new NotImplementedException ();
1335                 }
1336
1337                 [MonoTODO (MetafileEnumeration)]
1338                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1339                 {
1340                         throw new NotImplementedException ();
1341                 }
1342
1343                 [MonoTODO (MetafileEnumeration)]
1344                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1345                 {
1346                         throw new NotImplementedException ();
1347                 }
1348
1349                 [MonoTODO (MetafileEnumeration)]
1350                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1351                 {
1352                         throw new NotImplementedException ();
1353                 }
1354
1355                 [MonoTODO (MetafileEnumeration)]
1356                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1357                 {
1358                         throw new NotImplementedException ();
1359                 }
1360
1361                 [MonoTODO (MetafileEnumeration)]
1362                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1363                 {
1364                         throw new NotImplementedException ();
1365                 }
1366
1367                 [MonoTODO (MetafileEnumeration)]
1368                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit srcUnit, EnumerateMetafileProc callback, IntPtr callbackData)
1369                 {
1370                         throw new NotImplementedException ();
1371                 }
1372
1373                 [MonoTODO (MetafileEnumeration)]
1374                 public void EnumerateMetafile (Metafile metafile, Point [] destPoints, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1375                 {
1376                         throw new NotImplementedException ();
1377                 }
1378
1379                 [MonoTODO (MetafileEnumeration)]
1380                 public void EnumerateMetafile (Metafile metafile, Rectangle destRect, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1381                 {
1382                         throw new NotImplementedException ();
1383                 }
1384
1385                 [MonoTODO (MetafileEnumeration)]
1386                 public void EnumerateMetafile (Metafile metafile, Point destPoint, Rectangle srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1387                 {
1388                         throw new NotImplementedException ();
1389                 }
1390
1391                 [MonoTODO (MetafileEnumeration)]
1392                 public void EnumerateMetafile (Metafile metafile, RectangleF destRect, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1393                 {
1394                         throw new NotImplementedException ();
1395                 }
1396
1397                 [MonoTODO (MetafileEnumeration)]
1398                 public void EnumerateMetafile (Metafile metafile, PointF [] destPoints, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1399                 {
1400                         throw new NotImplementedException ();
1401                 }
1402
1403                 [MonoTODO (MetafileEnumeration)]
1404                 public void EnumerateMetafile (Metafile metafile, PointF destPoint, RectangleF srcRect, GraphicsUnit unit, EnumerateMetafileProc callback, IntPtr callbackData, ImageAttributes imageAttr)
1405                 {
1406                         throw new NotImplementedException ();
1407                 }
1408         
1409                 public void ExcludeClip (Rectangle rect)
1410                 {
1411                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Exclude);
1412                         GDIPlus.CheckStatus (status);
1413                 }
1414
1415                 public void ExcludeClip (Region region)
1416                 {
1417                         if (region == null)
1418                                 throw new ArgumentNullException ("region");
1419                         Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Exclude);
1420                         GDIPlus.CheckStatus (status);
1421                 }
1422
1423                 
1424                 public void FillClosedCurve (Brush brush, PointF [] points)
1425                 {
1426                         if (brush == null)
1427                                 throw new ArgumentNullException ("brush");
1428                         if (points == null)
1429                                 throw new ArgumentNullException ("points");
1430                         Status status = GDIPlus.GdipFillClosedCurve (nativeObject, brush.NativeObject, points, points.Length);
1431                         GDIPlus.CheckStatus (status);
1432                 }
1433                 
1434                 public void FillClosedCurve (Brush brush, Point [] points)
1435                 {
1436                         if (brush == null)
1437                                 throw new ArgumentNullException ("brush");
1438                         if (points == null)
1439                                 throw new ArgumentNullException ("points");
1440                         Status status = GDIPlus.GdipFillClosedCurveI (nativeObject, brush.NativeObject, points, points.Length);
1441                         GDIPlus.CheckStatus (status);
1442                 }
1443
1444                 
1445                 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode)
1446                 {
1447                         if (brush == null)
1448                                 throw new ArgumentNullException ("brush");
1449                         if (points == null)
1450                                 throw new ArgumentNullException ("points");
1451                         FillClosedCurve (brush, points, fillmode, 0.5f);
1452                 }
1453                 
1454                 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode)
1455                 {
1456                         if (brush == null)
1457                                 throw new ArgumentNullException ("brush");
1458                         if (points == null)
1459                                 throw new ArgumentNullException ("points");
1460                         FillClosedCurve (brush, points, fillmode, 0.5f);
1461                 }
1462
1463                 public void FillClosedCurve (Brush brush, PointF [] points, FillMode fillmode, float tension)
1464                 {
1465                         if (brush == null)
1466                                 throw new ArgumentNullException ("brush");
1467                         if (points == null)
1468                                 throw new ArgumentNullException ("points");
1469                         Status status = GDIPlus.GdipFillClosedCurve2 (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1470                         GDIPlus.CheckStatus (status);
1471                 }
1472
1473                 public void FillClosedCurve (Brush brush, Point [] points, FillMode fillmode, float tension)
1474                 {
1475                         if (brush == null)
1476                                 throw new ArgumentNullException ("brush");
1477                         if (points == null)
1478                                 throw new ArgumentNullException ("points");
1479                         Status status = GDIPlus.GdipFillClosedCurve2I (nativeObject, brush.NativeObject, points, points.Length, tension, fillmode);
1480                         GDIPlus.CheckStatus (status);
1481                 }
1482
1483                 public void FillEllipse (Brush brush, Rectangle rect)
1484                 {
1485                         if (brush == null)
1486                                 throw new ArgumentNullException ("brush");
1487                         FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1488                 }
1489
1490                 public void FillEllipse (Brush brush, RectangleF rect)
1491                 {
1492                         if (brush == null)
1493                                 throw new ArgumentNullException ("brush");
1494                         FillEllipse (brush, rect.X, rect.Y, rect.Width, rect.Height);
1495                 }
1496
1497                 public void FillEllipse (Brush brush, float x, float y, float width, float height)
1498                 {
1499                         if (brush == null)
1500                                 throw new ArgumentNullException ("brush");
1501                         Status status = GDIPlus.GdipFillEllipse (nativeObject, brush.nativeObject, x, y, width, height);
1502                         GDIPlus.CheckStatus (status);
1503                 }
1504
1505                 public void FillEllipse (Brush brush, int x, int y, int width, int height)
1506                 {
1507                         if (brush == null)
1508                                 throw new ArgumentNullException ("brush");
1509                         Status status = GDIPlus.GdipFillEllipseI (nativeObject, brush.nativeObject, x, y, width, height);
1510                         GDIPlus.CheckStatus (status);
1511                 }
1512
1513                 public void FillPath (Brush brush, GraphicsPath path)
1514                 {
1515                         if (brush == null)
1516                                 throw new ArgumentNullException ("brush");
1517                         if (path == null)
1518                                 throw new ArgumentNullException ("path");
1519                         Status status = GDIPlus.GdipFillPath (nativeObject, brush.NativeObject,  path.NativeObject);
1520                         GDIPlus.CheckStatus (status);
1521                 }
1522
1523                 public void FillPie (Brush brush, Rectangle rect, float startAngle, float sweepAngle)
1524                 {
1525                         if (brush == null)
1526                                 throw new ArgumentNullException ("brush");
1527                         Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, rect.X, rect.Y, rect.Width, rect.Height, startAngle, sweepAngle);
1528                         GDIPlus.CheckStatus (status);
1529                 }
1530
1531                 public void FillPie (Brush brush, int x, int y, int width, int height, int startAngle, int sweepAngle)
1532                 {
1533                         if (brush == null)
1534                                 throw new ArgumentNullException ("brush");
1535                         Status status = GDIPlus.GdipFillPieI (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1536                         GDIPlus.CheckStatus (status);
1537                 }
1538
1539                 public void FillPie (Brush brush, float x, float y, float width, float height, float startAngle, float sweepAngle)
1540                 {
1541                         if (brush == null)
1542                                 throw new ArgumentNullException ("brush");
1543                         Status status = GDIPlus.GdipFillPie (nativeObject, brush.NativeObject, x, y, width, height, startAngle, sweepAngle);
1544                         GDIPlus.CheckStatus (status);
1545                 }
1546
1547                 public void FillPolygon (Brush brush, PointF [] points)
1548                 {
1549                         if (brush == null)
1550                                 throw new ArgumentNullException ("brush");
1551                         if (points == null)
1552                                 throw new ArgumentNullException ("points");
1553                         Status status = GDIPlus.GdipFillPolygon2 (nativeObject, brush.nativeObject, points, points.Length);
1554                         GDIPlus.CheckStatus (status);
1555                 }
1556
1557                 public void FillPolygon (Brush brush, Point [] points)
1558                 {
1559                         if (brush == null)
1560                                 throw new ArgumentNullException ("brush");
1561                         if (points == null)
1562                                 throw new ArgumentNullException ("points");
1563                         Status status = GDIPlus.GdipFillPolygon2I (nativeObject, brush.nativeObject, points, points.Length);
1564                         GDIPlus.CheckStatus (status);
1565                 }
1566
1567                 public void FillPolygon (Brush brush, Point [] points, FillMode fillMode)
1568                 {
1569                         if (brush == null)
1570                                 throw new ArgumentNullException ("brush");
1571                         if (points == null)
1572                                 throw new ArgumentNullException ("points");
1573                         Status status = GDIPlus.GdipFillPolygonI (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1574                         GDIPlus.CheckStatus (status);
1575                 }
1576
1577                 public void FillPolygon (Brush brush, PointF [] points, FillMode fillMode)
1578                 {
1579                         if (brush == null)
1580                                 throw new ArgumentNullException ("brush");
1581                         if (points == null)
1582                                 throw new ArgumentNullException ("points");
1583                         Status status = GDIPlus.GdipFillPolygon (nativeObject, brush.nativeObject, points, points.Length, fillMode);
1584                         GDIPlus.CheckStatus (status);
1585                 }
1586
1587                 public void FillRectangle (Brush brush, RectangleF rect)
1588                 {
1589                         if (brush == null)
1590                                 throw new ArgumentNullException ("brush");
1591                         FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1592                 }
1593
1594                 public void FillRectangle (Brush brush, Rectangle rect)
1595                 {
1596                         if (brush == null)
1597                                 throw new ArgumentNullException ("brush");
1598                         FillRectangle (brush, rect.Left, rect.Top, rect.Width, rect.Height);
1599                 }
1600
1601                 public void FillRectangle (Brush brush, int x, int y, int width, int height)
1602                 {
1603                         if (brush == null)
1604                                 throw new ArgumentNullException ("brush");
1605                         
1606                         Status status = GDIPlus.GdipFillRectangleI (nativeObject, brush.nativeObject, x, y, width, height);
1607                         GDIPlus.CheckStatus (status);
1608                 }
1609
1610                 public void FillRectangle (Brush brush, float x, float y, float width, float height)
1611                 {
1612                         if (brush == null)
1613                                 throw new ArgumentNullException ("brush");
1614                         
1615                         Status status = GDIPlus.GdipFillRectangle (nativeObject, brush.nativeObject, x, y, width, height);
1616                         GDIPlus.CheckStatus (status);
1617                 }
1618
1619                 public void FillRectangles (Brush brush, Rectangle [] rects)
1620                 {
1621                         if (brush == null)
1622                                 throw new ArgumentNullException ("brush");
1623                         if (rects == null)
1624                                 throw new ArgumentNullException ("rects");
1625
1626                         Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
1627                         GDIPlus.CheckStatus (status);
1628                 }
1629
1630                 public void FillRectangles (Brush brush, RectangleF [] rects)
1631                 {
1632                         if (brush == null)
1633                                 throw new ArgumentNullException ("brush");
1634                         if (rects == null)
1635                                 throw new ArgumentNullException ("rects");
1636
1637                         Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
1638                         GDIPlus.CheckStatus (status);
1639                 }
1640
1641                 
1642                 public void FillRegion (Brush brush, Region region)
1643                 {
1644                         if (brush == null)
1645                                 throw new ArgumentNullException ("brush");
1646                         if (region == null)
1647                                 throw new ArgumentNullException ("region");
1648                         
1649                         Status status = GDIPlus.GdipFillRegion (nativeObject, brush.NativeObject, region.NativeObject);                  
1650                         GDIPlus.CheckStatus(status);
1651                 }
1652
1653                 
1654                 public void Flush ()
1655                 {
1656                         Flush (FlushIntention.Flush);
1657                 }
1658
1659                 
1660                 public void Flush (FlushIntention intention)
1661                 {
1662                         if (nativeObject == IntPtr.Zero) {
1663                                 return;
1664                         }
1665
1666                         Status status = GDIPlus.GdipFlush (nativeObject, intention);
1667                         GDIPlus.CheckStatus (status);                    
1668                         if ((GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable) && context.ctx != IntPtr.Zero)
1669                                 Carbon.CGContextSynchronize (context.ctx);
1670                 }
1671
1672                 [EditorBrowsable (EditorBrowsableState.Advanced)]               
1673                 public static Graphics FromHdc (IntPtr hdc)
1674                 {
1675                         IntPtr graphics;
1676                         Status status = GDIPlus.GdipCreateFromHDC (hdc, out graphics);
1677                         GDIPlus.CheckStatus (status);
1678                         return new Graphics (graphics);
1679                 }
1680
1681                 [MonoTODO]
1682                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1683                 public static Graphics FromHdc (IntPtr hdc, IntPtr hdevice)
1684                 {
1685                         throw new NotImplementedException ();
1686                 }
1687
1688                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1689                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1690                 public static Graphics FromHdcInternal (IntPtr hdc)
1691                 {
1692                         GDIPlus.Display = hdc;
1693                         return null;
1694                 }
1695
1696                 [EditorBrowsable (EditorBrowsableState.Advanced)]               
1697                 public static Graphics FromHwnd (IntPtr hwnd)
1698                 {
1699                         IntPtr graphics;
1700
1701                         if (GDIPlus.UseCocoaDrawable) {
1702                                 throw new NotImplementedException ();
1703 /* TODO: Fix this code to handle the new libgdiplus
1704                                 CarbonContext context = Carbon.GetCGContextForNSView (hwnd);
1705                                 GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
1706                                 
1707                                 Graphics g = new Graphics (graphics);
1708                                 g.context = context;
1709                                 
1710                                 return g;
1711 */
1712                         }
1713                         if (GDIPlus.UseQuartzDrawable) {
1714                                 CarbonContext context = Carbon.GetCGContextForView (hwnd);
1715                                 GDIPlus.GdipCreateFromQuartz_macosx (context.ctx, context.width, context.height, out graphics);
1716                                 
1717                                 Graphics g = new Graphics (graphics);
1718                                 g.context = context;
1719                                 
1720                                 return g;
1721                         }
1722                         if (GDIPlus.UseX11Drawable) {
1723                                 if (GDIPlus.Display == IntPtr.Zero) {
1724                                         GDIPlus.Display = GDIPlus.XOpenDisplay (IntPtr.Zero);
1725                                 }
1726                                 if (hwnd == IntPtr.Zero) {
1727                                         hwnd = GDIPlus.XRootWindow (GDIPlus.Display, GDIPlus.XDefaultScreen (GDIPlus.Display));
1728                                 }
1729
1730                                 return FromXDrawable (hwnd, GDIPlus.Display);
1731
1732                         }
1733
1734                         Status status = GDIPlus.GdipCreateFromHWND (hwnd, out graphics);
1735                         GDIPlus.CheckStatus (status);
1736
1737                         return new Graphics (graphics);
1738                 }
1739                 
1740                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1741                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
1742                 public static Graphics FromHwndInternal (IntPtr hwnd)
1743                 {
1744                         return FromHwnd (hwnd);
1745                 }
1746
1747                 public static Graphics FromImage (Image image)
1748                 {
1749                         IntPtr graphics;
1750
1751                         if (image == null) 
1752                                 throw new ArgumentNullException ("image");
1753
1754                         if ((image.PixelFormat & PixelFormat.Indexed) != 0)
1755                                 throw new Exception (Locale.GetText ("Cannot create Graphics from an indexed bitmap."));
1756
1757                         Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
1758                         GDIPlus.CheckStatus (status);
1759                         Graphics result = new Graphics (graphics);
1760                                 
1761                         if (GDIPlus.RunningOnUnix ()) {
1762                                 Rectangle rect  = new Rectangle (0,0, image.Width, image.Height);
1763                                 GDIPlus.GdipSetVisibleClip_linux (result.NativeObject, ref rect);
1764                         }
1765                                 
1766                         return result;
1767                 }
1768
1769                 internal static Graphics FromXDrawable (IntPtr drawable, IntPtr display)
1770                 {
1771                         IntPtr graphics;
1772
1773                         Status s = GDIPlus.GdipCreateFromXDrawable_linux (drawable, display, out graphics);
1774                         GDIPlus.CheckStatus (s);
1775                         return new Graphics (graphics);
1776                 }
1777
1778                 [MonoTODO]
1779                 public static IntPtr GetHalftonePalette ()
1780                 {
1781                         throw new NotImplementedException ();
1782                 }
1783
1784 #if !NET_2_0
1785                 [EditorBrowsable (EditorBrowsableState.Advanced)]
1786 #endif
1787                 public IntPtr GetHdc ()
1788                 {
1789                         GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out deviceContextHdc));
1790                         return deviceContextHdc;
1791                 }
1792                 
1793                 public Color GetNearestColor (Color color)
1794                 {
1795                         int argb;
1796                         
1797                         Status status = GDIPlus.GdipGetNearestColor (nativeObject, out argb);
1798                         GDIPlus.CheckStatus (status);
1799
1800                         return Color.FromArgb (argb);
1801                 }
1802
1803                 
1804                 public void IntersectClip (Region region)
1805                 {
1806                         if (region == null)
1807                                 throw new ArgumentNullException ("region");
1808                         Status status = GDIPlus.GdipSetClipRegion (nativeObject, region.NativeObject, CombineMode.Intersect);
1809                         GDIPlus.CheckStatus (status);
1810                 }
1811                 
1812                 public void IntersectClip (RectangleF rect)
1813                 {
1814                         Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1815                         GDIPlus.CheckStatus (status);
1816                 }
1817
1818                 public void IntersectClip (Rectangle rect)
1819                 {                       
1820                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, CombineMode.Intersect);
1821                         GDIPlus.CheckStatus (status);
1822                 }
1823
1824                 public bool IsVisible (Point point)
1825                 {
1826                         bool isVisible = false;
1827
1828                         Status status = GDIPlus.GdipIsVisiblePointI (nativeObject, point.X, point.Y, out isVisible);
1829                         GDIPlus.CheckStatus (status);
1830
1831                         return isVisible;
1832                 }
1833
1834                 
1835                 public bool IsVisible (RectangleF rect)
1836                 {
1837                         bool isVisible = false;
1838
1839                         Status status = GDIPlus.GdipIsVisibleRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1840                         GDIPlus.CheckStatus (status);
1841
1842                         return isVisible;
1843                 }
1844
1845                 public bool IsVisible (PointF point)
1846                 {
1847                         bool isVisible = false;
1848
1849                         Status status = GDIPlus.GdipIsVisiblePoint (nativeObject, point.X, point.Y, out isVisible);
1850                         GDIPlus.CheckStatus (status);
1851
1852                         return isVisible;
1853                 }
1854                 
1855                 public bool IsVisible (Rectangle rect)
1856                 {
1857                         bool isVisible = false;
1858
1859                         Status status = GDIPlus.GdipIsVisibleRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, out isVisible);
1860                         GDIPlus.CheckStatus (status);
1861
1862                         return isVisible;
1863                 }
1864                 
1865                 public bool IsVisible (float x, float y)
1866                 {
1867                         return IsVisible (new PointF (x, y));
1868                 }
1869                 
1870                 public bool IsVisible (int x, int y)
1871                 {
1872                         return IsVisible (new Point (x, y));
1873                 }
1874                 
1875                 public bool IsVisible (float x, float y, float width, float height)
1876                 {
1877                         return IsVisible (new RectangleF (x, y, width, height));
1878                 }
1879
1880                 
1881                 public bool IsVisible (int x, int y, int width, int height)
1882                 {
1883                         return IsVisible (new Rectangle (x, y, width, height));
1884                 }
1885
1886                 
1887                 public Region[] MeasureCharacterRanges (string text, Font font, RectangleF layoutRect, StringFormat stringFormat)
1888                 {
1889                         if ((text == null) || (text.Length == 0))
1890                                 return new Region [0];
1891
1892                         if (font == null)
1893                                 throw new ArgumentNullException ("font");
1894
1895                         if (stringFormat == null)
1896                                 throw new ArgumentException ("stringFormat");
1897
1898                         int regcount = stringFormat.GetMeasurableCharacterRangeCount ();
1899                         if (regcount == 0)
1900                                 return new Region[0];
1901
1902                         IntPtr[] native_regions = new IntPtr [regcount];
1903                         Region[] regions = new Region [regcount];
1904                         
1905                         for (int i = 0; i < regcount; i++) {
1906                                 regions[i] = new Region ();
1907                                 native_regions[i] = regions[i].NativeObject;
1908                         }
1909                         
1910                         Status status = GDIPlus.GdipMeasureCharacterRanges (nativeObject, text, text.Length,
1911                                 font.NativeObject, ref layoutRect, stringFormat.NativeObject, regcount, out native_regions[0]); 
1912                         GDIPlus.CheckStatus (status);                           
1913
1914                         return regions;                                                 
1915                 }
1916
1917                 private unsafe SizeF GdipMeasureString (IntPtr graphics, string text, Font font, ref RectangleF layoutRect,
1918                         IntPtr stringFormat)
1919                 {
1920                         if ((text == null) || (text.Length == 0))
1921                                 return SizeF.Empty;
1922
1923                         if (font == null)
1924                                 throw new ArgumentNullException ("font");
1925
1926                         RectangleF boundingBox = new RectangleF ();
1927
1928                         Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, font.NativeObject, 
1929                                 ref layoutRect, stringFormat, out boundingBox, null, null);
1930                         GDIPlus.CheckStatus (status);
1931
1932                         return new SizeF (boundingBox.Width, boundingBox.Height);
1933                 }
1934
1935                 public SizeF MeasureString (string text, Font font)
1936                 {
1937                         return MeasureString (text, font, SizeF.Empty);
1938                 }
1939
1940                 public SizeF MeasureString (string text, Font font, SizeF layoutArea)
1941                 {
1942                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1943                         return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1944                 }
1945
1946                 public SizeF MeasureString (string text, Font font, int width)
1947                 {                               
1948                         RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1949                         return GdipMeasureString (nativeObject, text, font, ref rect, IntPtr.Zero);
1950                 }
1951
1952                 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat)
1953                 {
1954                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1955                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1956                         return GdipMeasureString (nativeObject, text, font, ref rect, format);
1957                 }
1958
1959                 public SizeF MeasureString (string text, Font font, int width, StringFormat format)
1960                 {
1961                         RectangleF rect = new RectangleF (0, 0, width, Int32.MaxValue);
1962                         IntPtr stringFormat = (format == null) ? IntPtr.Zero : format.NativeObject;
1963                         return GdipMeasureString (nativeObject, text, font, ref rect, stringFormat);
1964                 }
1965
1966                 public SizeF MeasureString (string text, Font font, PointF origin, StringFormat stringFormat)
1967                 {
1968                         RectangleF rect = new RectangleF (origin.X, origin.Y, 0, 0);
1969                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1970                         return GdipMeasureString (nativeObject, text, font, ref rect, format);
1971                 }
1972
1973                 public SizeF MeasureString (string text, Font font, SizeF layoutArea, StringFormat stringFormat, 
1974                         out int charactersFitted, out int linesFilled)
1975                 {       
1976                         charactersFitted = 0;
1977                         linesFilled = 0;
1978
1979                         if ((text == null) || (text.Length == 0))
1980                                 return SizeF.Empty;
1981
1982                         if (font == null)
1983                                 throw new ArgumentNullException ("font");
1984
1985                         RectangleF boundingBox = new RectangleF ();
1986                         RectangleF rect = new RectangleF (0, 0, layoutArea.Width, layoutArea.Height);
1987
1988                         IntPtr format = (stringFormat == null) ? IntPtr.Zero : stringFormat.NativeObject;
1989
1990                         unsafe {
1991                                 fixed (int* pc = &charactersFitted, pl = &linesFilled) {
1992                                         Status status = GDIPlus.GdipMeasureString (nativeObject, text, text.Length, 
1993                                         font.NativeObject, ref rect, format, out boundingBox, pc, pl);
1994                                         GDIPlus.CheckStatus (status);
1995                                 }
1996                         }
1997                         return new SizeF (boundingBox.Width, boundingBox.Height);
1998                 }
1999
2000                 public void MultiplyTransform (Matrix matrix)
2001                 {
2002                         MultiplyTransform (matrix, MatrixOrder.Prepend);
2003                 }
2004
2005                 public void MultiplyTransform (Matrix matrix, MatrixOrder order)
2006                 {
2007                         if (matrix == null)
2008                                 throw new ArgumentNullException ("matrix");
2009
2010                         Status status = GDIPlus.GdipMultiplyWorldTransform (nativeObject, matrix.nativeMatrix, order);
2011                         GDIPlus.CheckStatus (status);
2012                 }
2013
2014                 [EditorBrowsable (EditorBrowsableState.Advanced)]
2015                 [SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
2016                 public void ReleaseHdc (IntPtr hdc)
2017                 {
2018                         ReleaseHdcInternal (hdc);
2019                 }
2020
2021 #if NET_2_0
2022                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2023                 public void ReleaseHdc ()
2024                 {
2025                         ReleaseHdcInternal (deviceContextHdc);
2026                 }
2027 #endif
2028
2029                 [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
2030 #if NET_2_0
2031                 [EditorBrowsable (EditorBrowsableState.Never)]
2032 #else
2033                 [EditorBrowsable (EditorBrowsableState.Advanced)]
2034 #endif
2035                 [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
2036                 public void ReleaseHdcInternal (IntPtr hdc)
2037                 {
2038                         Status status = Status.InvalidParameter;
2039                         if (hdc == deviceContextHdc) {
2040                                 status = GDIPlus.GdipReleaseDC (nativeObject, deviceContextHdc);
2041                                 deviceContextHdc = IntPtr.Zero;
2042                         }
2043                         GDIPlus.CheckStatus (status);
2044                 }
2045                 
2046                 public void ResetClip ()
2047                 {
2048                         Status status = GDIPlus.GdipResetClip (nativeObject);
2049                         GDIPlus.CheckStatus (status);
2050                 }
2051
2052                 public void ResetTransform ()
2053                 {
2054                         Status status = GDIPlus.GdipResetWorldTransform (nativeObject);
2055                         GDIPlus.CheckStatus (status);
2056                 }
2057
2058                 public void Restore (GraphicsState gstate)
2059                 {                       
2060                         // the possible NRE thrown by gstate.nativeState match MS behaviour
2061                         Status status = GDIPlus.GdipRestoreGraphics (nativeObject, gstate.nativeState);
2062                         GDIPlus.CheckStatus (status);
2063                 }
2064
2065                 public void RotateTransform (float angle)
2066                 {
2067                         RotateTransform (angle, MatrixOrder.Prepend);
2068                 }
2069
2070                 public void RotateTransform (float angle, MatrixOrder order)
2071                 {
2072                         Status status = GDIPlus.GdipRotateWorldTransform (nativeObject, angle, order);
2073                         GDIPlus.CheckStatus (status);
2074                 }
2075
2076                 public GraphicsState Save ()
2077                 {                                               
2078                         uint saveState;
2079                         Status status = GDIPlus.GdipSaveGraphics (nativeObject, out saveState);
2080                         GDIPlus.CheckStatus (status);
2081
2082                         GraphicsState state = new GraphicsState ();
2083                         state.nativeState = saveState;
2084                         return state;
2085                 }
2086
2087                 public void ScaleTransform (float sx, float sy)
2088                 {
2089                         ScaleTransform (sx, sy, MatrixOrder.Prepend);
2090                 }
2091
2092                 public void ScaleTransform (float sx, float sy, MatrixOrder order)
2093                 {
2094                         Status status = GDIPlus.GdipScaleWorldTransform (nativeObject, sx, sy, order);
2095                         GDIPlus.CheckStatus (status);
2096                 }
2097
2098                 
2099                 public void SetClip (RectangleF rect)
2100                 {
2101                         SetClip (rect, CombineMode.Replace);
2102                 }
2103
2104                 
2105                 public void SetClip (GraphicsPath path)
2106                 {
2107                         SetClip (path, CombineMode.Replace);
2108                 }
2109
2110                 
2111                 public void SetClip (Rectangle rect)
2112                 {
2113                         SetClip (rect, CombineMode.Replace);
2114                 }
2115
2116                 
2117                 public void SetClip (Graphics g)
2118                 {
2119                         SetClip (g, CombineMode.Replace);
2120                 }
2121
2122                 
2123                 public void SetClip (Graphics g, CombineMode combineMode)
2124                 {
2125                         if (g == null)
2126                                 throw new ArgumentNullException ("g");
2127                         
2128                         Status status = GDIPlus.GdipSetClipGraphics (nativeObject, g.NativeObject, combineMode);
2129                         GDIPlus.CheckStatus (status);
2130                 }
2131
2132                 
2133                 public void SetClip (Rectangle rect, CombineMode combineMode)
2134                 {
2135                         Status status = GDIPlus.GdipSetClipRectI (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2136                         GDIPlus.CheckStatus (status);
2137                 }
2138
2139                 
2140                 public void SetClip (RectangleF rect, CombineMode combineMode)
2141                 {
2142                         Status status = GDIPlus.GdipSetClipRect (nativeObject, rect.X, rect.Y, rect.Width, rect.Height, combineMode);
2143                         GDIPlus.CheckStatus (status);
2144                 }
2145
2146                 
2147                 public void SetClip (Region region, CombineMode combineMode)
2148                 {
2149                         if (region == null)
2150                                 throw new ArgumentNullException ("region");
2151                         Status status =   GDIPlus.GdipSetClipRegion(nativeObject,  region.NativeObject, combineMode); 
2152                         GDIPlus.CheckStatus (status);
2153                 }
2154
2155                 
2156                 public void SetClip (GraphicsPath path, CombineMode combineMode)
2157                 {
2158                         if (path == null)
2159                                 throw new ArgumentNullException ("path");
2160                         Status status = GDIPlus.GdipSetClipPath (nativeObject, path.NativeObject, combineMode);
2161                         GDIPlus.CheckStatus (status);
2162                 }
2163
2164                 
2165                 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, PointF [] pts)
2166                 {
2167                         if (pts == null)
2168                                 throw new ArgumentNullException ("pts");
2169
2170                         IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemory (pts);
2171             
2172                         Status status = GDIPlus.GdipTransformPoints (nativeObject, destSpace, srcSpace,  ptrPt, pts.Length);
2173                         GDIPlus.CheckStatus (status);
2174                         
2175                         GDIPlus.FromUnManagedMemoryToPoint (ptrPt, pts);
2176                 }
2177
2178
2179                 public void TransformPoints (CoordinateSpace destSpace, CoordinateSpace srcSpace, Point [] pts)
2180                 {                                               
2181                         if (pts == null)
2182                                 throw new ArgumentNullException ("pts");
2183                         IntPtr ptrPt =  GDIPlus.FromPointToUnManagedMemoryI (pts);
2184             
2185                         Status status = GDIPlus.GdipTransformPointsI (nativeObject, destSpace, srcSpace, ptrPt, pts.Length);
2186                         GDIPlus.CheckStatus (status);
2187                         
2188                         GDIPlus.FromUnManagedMemoryToPointI (ptrPt, pts);
2189                 }
2190
2191                 
2192                 public void TranslateClip (int dx, int dy)
2193                 {
2194                         Status status = GDIPlus.GdipTranslateClipI (nativeObject, dx, dy);
2195                         GDIPlus.CheckStatus (status);
2196                 }
2197
2198                 
2199                 public void TranslateClip (float dx, float dy)
2200                 {
2201                         Status status = GDIPlus.GdipTranslateClip (nativeObject, dx, dy);
2202                         GDIPlus.CheckStatus (status);
2203                 }
2204
2205                 public void TranslateTransform (float dx, float dy)
2206                 {
2207                         TranslateTransform (dx, dy, MatrixOrder.Prepend);
2208                 }
2209
2210                 
2211                 public void TranslateTransform (float dx, float dy, MatrixOrder order)
2212                 {                       
2213                         Status status = GDIPlus.GdipTranslateWorldTransform (nativeObject, dx, dy, order);
2214                         GDIPlus.CheckStatus (status);
2215                 }
2216
2217                 public Region Clip {
2218                         get {
2219                                 Region reg = new Region();
2220                                 Status status = GDIPlus.GdipGetClip (nativeObject, reg.NativeObject);
2221                                 GDIPlus.CheckStatus (status);
2222                                 return reg;                             
2223                         }
2224                         set {
2225                                 SetClip (value, CombineMode.Replace);
2226                         }
2227                 }
2228
2229                 public RectangleF ClipBounds {
2230                         get {
2231                                 RectangleF rect = new RectangleF ();
2232                                 Status status = GDIPlus.GdipGetClipBounds (nativeObject, out rect);
2233                                 GDIPlus.CheckStatus (status);
2234                                 return rect;
2235                         }
2236                 }
2237
2238                 public CompositingMode CompositingMode {
2239                         get {
2240                                 CompositingMode mode;
2241                                 Status status = GDIPlus.GdipGetCompositingMode (nativeObject, out mode);
2242                                 GDIPlus.CheckStatus (status);
2243
2244                                 return mode;
2245                         }
2246                         set {
2247                                 Status status = GDIPlus.GdipSetCompositingMode (nativeObject, value);
2248                                 GDIPlus.CheckStatus (status);
2249                         }
2250
2251                 }
2252
2253                 public CompositingQuality CompositingQuality {
2254                         get {
2255                                 CompositingQuality quality;
2256
2257                                 Status status = GDIPlus.GdipGetCompositingQuality (nativeObject, out quality);
2258                                 GDIPlus.CheckStatus (status);
2259                                 return quality;
2260                         }
2261                         set {
2262                                 Status status = GDIPlus.GdipSetCompositingQuality (nativeObject, value);
2263                                 GDIPlus.CheckStatus (status);
2264                         }
2265                 }
2266
2267                 public float DpiX {
2268                         get {
2269                                 float x;
2270
2271                                 Status status = GDIPlus.GdipGetDpiX (nativeObject, out x);
2272                                 GDIPlus.CheckStatus (status);
2273                                 return x;
2274                         }
2275                 }
2276
2277                 public float DpiY {
2278                         get {
2279                                 float y;
2280
2281                                 Status status = GDIPlus.GdipGetDpiY (nativeObject, out y);
2282                                 GDIPlus.CheckStatus (status);
2283                                 return y;
2284                         }
2285                 }
2286
2287                 public InterpolationMode InterpolationMode {
2288                         get {                           
2289                                 InterpolationMode imode = InterpolationMode.Invalid;
2290                                 Status status = GDIPlus.GdipGetInterpolationMode (nativeObject, out imode);
2291                                 GDIPlus.CheckStatus (status);
2292                                 return imode;
2293                         }
2294                         set {
2295                                 Status status = GDIPlus.GdipSetInterpolationMode (nativeObject, value);
2296                                 GDIPlus.CheckStatus (status);
2297                         }
2298                 }
2299
2300                 public bool IsClipEmpty {
2301                         get {
2302                                 bool isEmpty = false;
2303
2304                                 Status status = GDIPlus.GdipIsClipEmpty (nativeObject, out isEmpty);
2305                                 GDIPlus.CheckStatus (status);
2306                                 return isEmpty;
2307                         }
2308                 }
2309
2310                 public bool IsVisibleClipEmpty {
2311                         get {
2312                                 bool isEmpty = false;
2313
2314                                 Status status = GDIPlus.GdipIsVisibleClipEmpty (nativeObject, out isEmpty);
2315                                 GDIPlus.CheckStatus (status);
2316                                 return isEmpty;
2317                         }
2318                 }
2319
2320                 public float PageScale {
2321                         get {
2322                                 float scale;
2323
2324                                 Status status = GDIPlus.GdipGetPageScale (nativeObject, out scale);
2325                                 GDIPlus.CheckStatus (status);
2326                                 return scale;
2327                         }
2328                         set {
2329                                 Status status = GDIPlus.GdipSetPageScale (nativeObject, value);
2330                                 GDIPlus.CheckStatus (status);
2331                         }
2332                 }
2333
2334                 public GraphicsUnit PageUnit {
2335                         get {
2336                                 GraphicsUnit unit;
2337                                 
2338                                 Status status = GDIPlus.GdipGetPageUnit (nativeObject, out unit);
2339                                 GDIPlus.CheckStatus (status);
2340                                 return unit;
2341                         }
2342                         set {
2343                                 Status status = GDIPlus.GdipSetPageUnit (nativeObject, value);
2344                                 GDIPlus.CheckStatus (status);
2345                         }
2346                 }
2347
2348                 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2349                 public PixelOffsetMode PixelOffsetMode {
2350                         get {
2351                                 PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
2352                                 
2353                                 Status status = GDIPlus.GdipGetPixelOffsetMode (nativeObject, out pixelOffset);
2354                                 GDIPlus.CheckStatus (status);
2355                                 return pixelOffset;
2356                         }
2357                         set {
2358                                 Status status = GDIPlus.GdipSetPixelOffsetMode (nativeObject, value); 
2359                                 GDIPlus.CheckStatus (status);
2360                         }
2361                 }
2362
2363                 public Point RenderingOrigin {
2364                         get {
2365                                 int x, y;
2366                                 Status status = GDIPlus.GdipGetRenderingOrigin (nativeObject, out x, out y);
2367                                 GDIPlus.CheckStatus (status);
2368                                 return new Point (x, y);
2369                         }
2370
2371                         set {
2372                                 Status status = GDIPlus.GdipSetRenderingOrigin (nativeObject, value.X, value.Y);
2373                                 GDIPlus.CheckStatus (status);
2374                         }
2375                 }
2376
2377                 public SmoothingMode SmoothingMode {
2378                         get {
2379                                 SmoothingMode mode = SmoothingMode.Invalid;
2380
2381                                 Status status = GDIPlus.GdipGetSmoothingMode (nativeObject, out mode);
2382                                 GDIPlus.CheckStatus (status);
2383                                 return mode;
2384                         }
2385
2386                         set {
2387                                 Status status = GDIPlus.GdipSetSmoothingMode (nativeObject, value);
2388                                 GDIPlus.CheckStatus (status);
2389                         }
2390                 }
2391
2392                 [MonoTODO ("This property does not do anything when used with libgdiplus.")]
2393                 public int TextContrast {
2394                         get {   
2395                                 int contrast;
2396                                         
2397                                 Status status = GDIPlus.GdipGetTextContrast (nativeObject, out contrast);
2398                                 GDIPlus.CheckStatus (status);
2399                                 return contrast;
2400                         }
2401
2402                         set {
2403                                 Status status = GDIPlus.GdipSetTextContrast (nativeObject, value);
2404                                 GDIPlus.CheckStatus (status);
2405                         }
2406                 }
2407
2408                 public TextRenderingHint TextRenderingHint {
2409                         get {
2410                                 TextRenderingHint hint;
2411
2412                                 Status status = GDIPlus.GdipGetTextRenderingHint (nativeObject, out hint);
2413                                 GDIPlus.CheckStatus (status);
2414                                 return hint;        
2415                         }
2416
2417                         set {
2418                                 Status status = GDIPlus.GdipSetTextRenderingHint (nativeObject, value);
2419                                 GDIPlus.CheckStatus (status);
2420                         }
2421                 }
2422
2423                 public Matrix Transform {
2424                         get {
2425                                 Matrix matrix = new Matrix ();
2426                                 Status status = GDIPlus.GdipGetWorldTransform (nativeObject, matrix.nativeMatrix);
2427                                 GDIPlus.CheckStatus (status);
2428                                 return matrix;
2429                         }
2430                         set {
2431                                 if (value == null)
2432                                         throw new ArgumentNullException ("value");
2433                                 
2434                                 Status status = GDIPlus.GdipSetWorldTransform (nativeObject, value.nativeMatrix);
2435                                 GDIPlus.CheckStatus (status);
2436                         }
2437                 }
2438
2439                 public RectangleF VisibleClipBounds {
2440                         get {
2441                                 RectangleF rect;
2442                                         
2443                                 Status status = GDIPlus.GdipGetVisibleClipBounds (nativeObject, out rect);
2444                                 GDIPlus.CheckStatus (status);
2445                                 return rect;
2446                         }
2447                 }
2448
2449 #if NET_2_0
2450                 [MonoTODO]
2451                 [EditorBrowsable (EditorBrowsableState.Never)]
2452                 public object GetContextInfo ()
2453                 {
2454                         // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
2455                         throw new NotImplementedException ();
2456                 }
2457 #endif
2458         }
2459 }