2007-05-30 Sebastien Pouliot <sebastien@ximian.com>
authorSebastien Pouliot <sebastien@ximian.com>
Thu, 31 May 2007 01:15:22 +0000 (01:15 -0000)
committerSebastien Pouliot <sebastien@ximian.com>
Thu, 31 May 2007 01:15:22 +0000 (01:15 -0000)
* Graphics.cs: Refactor [Get|Release]Hdc to get ReleaseHdcInternal
working (as long as the HDC comes from GetHdc).

svn path=/trunk/mcs/; revision=78286

mcs/class/System.Drawing/System.Drawing/ChangeLog
mcs/class/System.Drawing/System.Drawing/Graphics.cs

index bd05bd3c61e57ca8456caa64208d678abe6f4e11..daba5436c9ab906a669617f4b36af6c6f4f58261 100644 (file)
@@ -1,3 +1,8 @@
+2007-05-30  Sebastien Pouliot  <sebastien@ximian.com>
+
+       * Graphics.cs: Refactor [Get|Release]Hdc to get ReleaseHdcInternal
+       working (as long as the HDC comes from GetHdc).
+
 2007-05-21  Adar Wesley <adarw@mainsoft.com>
 
        * Graphics.jvm.cs
index 19821fbb28d817e6dd5d53562644f22f024051f9..5b64367a4484a4b1858bea030a5a86d3d8e00c75 100644 (file)
@@ -52,9 +52,7 @@ 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)]
@@ -1771,14 +1769,9 @@ namespace System.Drawing
 #endif
                public IntPtr GetHdc ()
                {
-                       IntPtr hdc;
-                       GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
-#if NET_2_0
-                       deviceContextHdc = hdc;
-#endif
-                       return hdc;
+                       GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out deviceContextHdc));
+                       return deviceContextHdc;
                }
-
                
                public Color GetNearestColor (Color color)
                {
@@ -2040,27 +2033,21 @@ namespace System.Drawing
                }
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.Demand, UnmanagedCode = true)]
                public void ReleaseHdc (IntPtr hdc)
                {
-                       Status status = GDIPlus.GdipReleaseDC (nativeObject, hdc);
-                       GDIPlus.CheckStatus (status);
-#if NET_2_0
-                       if (hdc == deviceContextHdc)
-                               deviceContextHdc = IntPtr.Zero;
-#endif
+                       ReleaseHdcInternal (hdc);
                }
 
 #if NET_2_0
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public void ReleaseHdc ()
                {
-                       if (deviceContextHdc == IntPtr.Zero)
-                               throw new ArgumentException ("Invalid Handle");
-
-                       ReleaseHdc (deviceContextHdc);
+                       ReleaseHdcInternal (deviceContextHdc);
                }
 #endif
 
-               [MonoTODO ("Parameter hdc doesn't map well into libgdiplus")]
+               [MonoLimitation ("Can only be used when hdc was provided by Graphics.GetHdc() method")]
 #if NET_2_0
                [EditorBrowsable (EditorBrowsableState.Never)]
 #else
@@ -2069,9 +2056,13 @@ namespace System.Drawing
                [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public void ReleaseHdcInternal (IntPtr hdc)
                {
-                       throw new NotImplementedException ();
+                       Status status = Status.InvalidParameter;
+                       if (hdc == deviceContextHdc) {
+                               status = GDIPlus.GdipReleaseDC (nativeObject, deviceContextHdc);
+                               deviceContextHdc = IntPtr.Zero;
+                       }
+                       GDIPlus.CheckStatus (status);
                }
-
                
                public void ResetClip ()
                {
@@ -2482,6 +2473,7 @@ namespace System.Drawing
                [EditorBrowsable (EditorBrowsableState.Never)]
                public object GetContextInfo ()
                {
+                       // only known source of information @ http://blogs.wdevs.com/jdunlap/Default.aspx
                        throw new NotImplementedException ();
                }
 #endif