2005-09-26 Sebastien Pouliot <sebastien@ximian.com>
[mono.git] / mcs / class / System.Drawing / System.Drawing / Graphics.cs
index ac0d04ec4474fdac541b18811a95dfef5af71fbc..42b107c18b478a1d556dc7a4a516ee1f83661f0f 100644 (file)
@@ -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);
@@ -1272,6 +1281,7 @@ namespace System.Drawing
                }
                
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public static Graphics FromHwndInternal (IntPtr hwnd)
                {
                        return FromHwnd (hwnd);
@@ -1281,12 +1291,8 @@ namespace System.Drawing
                {
                        IntPtr graphics;
 
-                       if (image == null) throw new ArgumentException ();
-
-                       if ((image.PixelFormat & PixelFormat.Indexed) != PixelFormat.Undefined) {\r
-                               // And MS ignores its own rules again\r
-                               throw new Exception ("A Graphics object cannot be created from an image that has an indexed pixel format");\r
-                       }\r
+                       if (image == null) 
+                               throw new ArgumentNullException ();
 
                        Status status = GDIPlus.GdipGetImageGraphicsContext (image.nativeObject, out graphics);
                        GDIPlus.CheckStatus (status);
@@ -1588,6 +1594,7 @@ namespace System.Drawing
 
                [MonoTODO]
                [EditorBrowsable (EditorBrowsableState.Advanced)]
+               [SecurityPermission (SecurityAction.LinkDemand, UnmanagedCode = true)]
                public void ReleaseHdcInternal (IntPtr hdc)
                {
                        throw new NotImplementedException ();