* roottypes.cs: Rename from tree.cs.
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
index bde98b2eba2d7667f23a4622469f62543c817e72..a5a7c0984f1445f1c33bcd56794c56956dfd96bb 100644 (file)
@@ -52,15 +52,22 @@ namespace System.Drawing
                private bool disposed = false;
                private static float defDpiX = 0;
                private static float defDpiY = 0;
+#if NET_2_0
+               private IntPtr deviceContextHdc;
+#endif
 
+#if !NET_2_0
                [ComVisible(false)]
+#endif
                public delegate bool EnumerateMetafileProc (EmfPlusRecordType recordType,
                                                            int flags,
                                                            int dataSize,
                                                            IntPtr data,
                                                            PlayRecordCallback callbackData);
                
+#if !NET_2_0
                [ComVisible (false)]
+#endif
                public delegate bool DrawImageAbort (IntPtr callbackData);
 
                internal Graphics (IntPtr nativeGraphics)
@@ -113,33 +120,33 @@ namespace System.Drawing
                        throw new NotImplementedException ();
                }
 
-               
                public GraphicsContainer BeginContainer ()
                {
-                       int state;
+                       uint state;
                        Status status;
                        status = GDIPlus.GdipBeginContainer2 (nativeObject, out state);
                        GDIPlus.CheckStatus (status);
 
                         return new GraphicsContainer(state);
                }
-               
+
+               [MonoTODO ("rectangles and unit aren't supported in libgdiplus")]               
                public GraphicsContainer BeginContainer (Rectangle dstrect, Rectangle srcrect, GraphicsUnit unit)
                {
-                       int state;
+                       uint state;
                        Status status;
-                       status = GDIPlus.GdipBeginContainerI (nativeObject, dstrect, srcrect, unit, out state);
+                       status = GDIPlus.GdipBeginContainerI (nativeObject, ref dstrect, ref srcrect, unit, out state);
                        GDIPlus.CheckStatus (status);
 
                        return new GraphicsContainer (state);
                }
 
-               
+               [MonoTODO ("rectangles and unit aren't supported in libgdiplus")]               
                public GraphicsContainer BeginContainer (RectangleF dstrect, RectangleF srcrect, GraphicsUnit unit)
                {
-                       int state;
+                       uint state;
                        Status status;
-                       status = GDIPlus.GdipBeginContainer (nativeObject, dstrect, srcrect, unit, out state);
+                       status = GDIPlus.GdipBeginContainer (nativeObject, ref dstrect, ref srcrect, unit, out state);
                        GDIPlus.CheckStatus (status);
 
                        return new GraphicsContainer (state);
@@ -235,6 +242,7 @@ namespace System.Drawing
                                DrawImage (bmp, 0, 0);
                                bmp.Dispose ();
                                GDIPlus.XDestroyImage (image);
+                               GDIPlus.XFree (vPtr);
                                return;
                        }                       
 
@@ -341,10 +349,10 @@ namespace System.Drawing
                         int length = points.Length;
                        Status status;
 
-                        if (length < 3)
+                        if (length < 4)
                                 return;
 
-                       for (int i = 0; i < length; i += 3) {
+                       for (int i = 0; i < length - 1; i += 3) {
                                 Point p1 = points [i];
                                 Point p2 = points [i + 1];
                                 Point p3 = points [i + 2];
@@ -368,10 +376,10 @@ namespace System.Drawing
                        int length = points.Length;
                        Status status;
 
-                        if (length < 3)
+                        if (length < 4)
                                 return;
 
-                       for (int i = 0; i < length; i += 3) {
+                       for (int i = 0; i < length - 1; i += 3) {
                                 PointF p1 = points [i];
                                 PointF p2 = points [i + 1];
                                 PointF p3 = points [i + 2];
@@ -482,7 +490,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
                
-               
                public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments)
                {
                        if (pen == null)
@@ -511,7 +518,6 @@ namespace System.Drawing
                        GDIPlus.CheckStatus (status);
                }
 
-               
                public void DrawCurve (Pen pen, PointF [] points, int offset, int numberOfSegments, float tension)
                {
                        if (pen == null)
@@ -560,20 +566,23 @@ namespace System.Drawing
 
                public void DrawIcon (Icon icon, Rectangle targetRect)
                {
-                       Image img = icon.ToBitmap ();
-                       DrawImage (img, targetRect);
+                       using (Image img = icon.ToBitmap ()) {
+                               DrawImage (img, targetRect);
+                       }
                }
 
                public void DrawIcon (Icon icon, int x, int y)
                {
-                       Image img = icon.ToBitmap ();
-                       DrawImage (img, x, y);
+                       using (Image img = icon.ToBitmap ()) {
+                               DrawImage (img, x, y);
+                       }
                }
 
                public void DrawIconUnstretched (Icon icon, Rectangle targetRect)
                {
-                       Image img = icon.ToBitmap ();
-                       DrawImageUnscaled (img, targetRect);
+                       using (Image img = icon.ToBitmap ()) {
+                               DrawImageUnscaled (img, targetRect);
+                       }
                }
                
                public void DrawImage (Image image, RectangleF rect)
@@ -1168,8 +1177,10 @@ namespace System.Drawing
 
                public void EndContainer (GraphicsContainer container)
                {
+#if NET_2_0
                        if (container == null)
                                throw new ArgumentNullException ("container");
+#endif
                        Status status = GDIPlus.GdipEndContainer(nativeObject, container.NativeObject);
                        GDIPlus.CheckStatus (status);
                }
@@ -1605,7 +1616,9 @@ namespace System.Drawing
                {
                        if (brush == null)
                                throw new ArgumentNullException ("brush");
-                       
+                       if (rects == null)
+                               throw new ArgumentNullException ("rects");
+
                        Status status = GDIPlus.GdipFillRectanglesI (nativeObject, brush.nativeObject, rects, rects.Length);
                        GDIPlus.CheckStatus (status);
                }
@@ -1614,7 +1627,9 @@ namespace System.Drawing
                {
                        if (brush == null)
                                throw new ArgumentNullException ("brush");
-                       
+                       if (rects == null)
+                               throw new ArgumentNullException ("rects");
+
                        Status status = GDIPlus.GdipFillRectangles (nativeObject, brush.nativeObject, rects, rects.Length);
                        GDIPlus.CheckStatus (status);
                }
@@ -1759,6 +1774,9 @@ namespace System.Drawing
                {
                        IntPtr hdc;
                        GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
+#if NET_2_0
+                       deviceContextHdc = hdc;
+#endif
                        return hdc;
                }
 
@@ -2022,13 +2040,22 @@ namespace System.Drawing
                {
                        Status status = GDIPlus.GdipReleaseDC (nativeObject, hdc);
                        GDIPlus.CheckStatus (status);
+#if NET_2_0
+                       if (hdc == deviceContextHdc)
+                               deviceContextHdc = IntPtr.Zero;
+#endif
                }
+
 #if NET_2_0
-               public void ReleaseHdc()\r
+               public void ReleaseHdc ()\r
                {\r
-                     \r
+                       if (deviceContextHdc == IntPtr.Zero)
+                               throw new ArgumentException ("Invalid Handle");
+
+                       ReleaseHdc (deviceContextHdc);
                }
 #endif
+
                [MonoTODO]
 #if NET_2_0
                [EditorBrowsable (EditorBrowsableState.Never)]
@@ -2345,6 +2372,7 @@ namespace System.Drawing
                        }
                }
 
+               [MonoTODO ("not supported by libgdiplus")]
                public PixelOffsetMode PixelOffsetMode {
                        get {
                                PixelOffsetMode pixelOffset = PixelOffsetMode.Invalid;
@@ -2388,6 +2416,7 @@ namespace System.Drawing
                        }
                }
 
+               [MonoTODO ("not supported by libgdiplus")]
                public int TextContrast {
                        get {   
                                 int contrast;
@@ -2443,6 +2472,14 @@ namespace System.Drawing
                                 return rect;
                        }
                }
+
+#if NET_2_0
+               [MonoTODO]
+               [EditorBrowsable (EditorBrowsableState.Never)]
+               public object GetContextInfo ()
+               {
+                       throw new NotImplementedException ();
+               }
+#endif
        }
 }
-