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