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