2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
old mode 100755 (executable)
new mode 100644 (file)
index 8038400..42b107c
@@ -8,7 +8,7 @@
 //
 // Copyright (C) 2003 Ximian, Inc. (http://www.ximian.com)
 //
-// Copyright (C) 2004 Novell, Inc. (http://www.novell.com)
+// Copyright (C) 2004-2005 Novell, Inc. (http://www.novell.com)
 //
 // Permission is hereby granted, free of charge, to any person obtaining
 // a copy of this software and associated documentation files (the
 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 //
-using System;
+
 using System.Drawing.Drawing2D;
 using System.Drawing.Imaging;
 using System.Drawing.Text;
 using System.ComponentModel;
 using System.Runtime.InteropServices;
+using System.Security.Permissions;
 using System.Text;
 
 namespace System.Drawing
@@ -1217,7 +1218,7 @@ namespace System.Drawing
                {
                        Status status = GDIPlus.GdipFlush (nativeObject, intention);
                         GDIPlus.CheckStatus (status);                    
-                       if (GDIPlus.UseQuartzDrawable)
+                       if (GDIPlus.UseQuartzDrawable || GDIPlus.UseCocoaDrawable)
                                Carbon.CGContextSynchronize (GDIPlus.Display);
                }
 
@@ -1238,6 +1239,7 @@ namespace System.Drawing
                }
 
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public static Graphics FromHdcInternal (IntPtr hdc)
                {
                        GDIPlus.Display = hdc;
@@ -1249,6 +1251,13 @@ namespace System.Drawing
                {
                        IntPtr graphics;
 
+                       if (GDIPlus.UseCocoaDrawable) {
+                               CarbonContext cgContext = Carbon.GetCGContextForNSView (hwnd);
+                               GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
+                               
+                               GDIPlus.Display = cgContext.ctx;
+                               return new Graphics (graphics);
+                       }
                        if (GDIPlus.UseQuartzDrawable) {
                                CarbonContext cgContext = Carbon.GetCGContextForView (hwnd);
                                GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics);
@@ -1270,19 +1279,20 @@ namespace System.Drawing
 
                        return new Graphics (graphics);
                }
-
-               [MonoTODO]
+               
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public static Graphics FromHwndInternal (IntPtr hwnd)
                {
-                       throw new NotImplementedException ();
+                       return FromHwnd (hwnd);
                }
 
                public static Graphics FromImage (Image image)
                {
                        IntPtr graphics;
 
-                       if (image == null) throw new ArgumentException ();
+                       if (image == null) 
+                               throw new ArgumentNullException ();
 
                        Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
                        GDIPlus.CheckStatus (status);
@@ -1314,11 +1324,12 @@ namespace System.Drawing
                        throw new NotImplementedException ();
                }
 
-               [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
                public IntPtr GetHdc ()
                {
-                       return nativeObject;
+                       IntPtr hdc;
+                       GDIPlus.CheckStatus (GDIPlus.GdipGetDC (this.nativeObject, out hdc));
+                       return hdc;
                }
 
                
@@ -1583,6 +1594,7 @@ namespace System.Drawing
 
                [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public void ReleaseHdcInternal (IntPtr hdc)
                {
                        throw new NotImplementedException ();