[Mono-winforms-list] More System.Graphics changes

kangaroo grompf@sublimeintervention.com
Thu, 9 Dec 2004 16:44:12 -0500


--Apple-Mail-17--232598801
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed

updated patch

-kangaroo

--Apple-Mail-17--232598801
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
	x-unix-mode=0644;
	name="graph.diff"
Content-Disposition: attachment;
	filename=graph.diff

Index: System.Drawing.dll.sources
===================================================================
--- System.Drawing.dll.sources	(revision 37438)
+++ System.Drawing.dll.sources	(working copy)
@@ -5,6 +5,7 @@
 System.Drawing/Brush.cs
 System.Drawing/Brushes.cs
 System.Drawing/CharacterRange.cs
+System.Drawing/carbonFunctions.cs
 System.Drawing/ColorConverter.cs
 System.Drawing/Color.cs
 System.Drawing/ColorTranslator.cs
Index: System.Drawing/carbonFunctions.cs
===================================================================
--- System.Drawing/carbonFunctions.cs	(revision 0)
+++ System.Drawing/carbonFunctions.cs	(revision 0)
@@ -0,0 +1,79 @@
+//
+// System.Drawing.carbonFunctions.cs
+//
+// Authors:
+//      Geoff Norton (gnorton@customerdna.com>
+//
+// Copyright (C) 2004 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
+// "Software"), to deal in the Software without restriction, including
+// without limitation the rights to use, copy, modify, merge, publish,
+// distribute, sublicense, and/or sell copies of the Software, and to
+// permit persons to whom the Software is furnished to do so, subject to
+// the following conditions:
+//
+// The above copyright notice and this permission notice shall be
+// included in all copies or substantial portions of the Software.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+// 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.Runtime.InteropServices;
+
+namespace System.Drawing {
+	internal class Carbon {
+		[DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern int HIViewGetBounds (IntPtr vHnd, ref HIRect r);
+                [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern int HIViewConvertRect (ref HIRect r, IntPtr a, IntPtr b);
+
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern IntPtr GetControlOwner (IntPtr aView);
+
+                [DllImport("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern int GetWindowBounds (IntPtr wHnd, uint reg, ref QRect rect);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern IntPtr GetWindowPort (IntPtr hWnd);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern int CGContextClipToRect (IntPtr cgContext, HIRect clip);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern void CreateCGContextForPort (IntPtr port, ref IntPtr cgc);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern void CGContextTranslateCTM (IntPtr cgc, double tx, double ty);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern void CGContextScaleCTM (IntPtr cgc, double x, double y);
+                [DllImport ("/System/Library/Frameworks/Carbon.framework/Versions/Current/Carbon")]
+                internal static extern void CGContextFlush (IntPtr cgc);
+	}
+
+	internal struct CGSize {
+		public float width;
+		public float height;
+	}
+
+	internal struct CGPoint {
+		public float x;
+		public float y;
+	}
+
+	internal struct HIRect {
+		public CGPoint origin;
+		public CGSize size;
+	}
+
+	internal struct QRect
+	{
+		public short top;
+		public short left;
+		public short bottom;
+		public short right;
+	}
+}
Index: System.Drawing/Graphics.cs
===================================================================
--- System.Drawing/Graphics.cs	(revision 37462)
+++ System.Drawing/Graphics.cs	(working copy)
@@ -1228,7 +1228,9 @@
 		public void Flush (FlushIntention intention)
 		{
 			Status status = GDIPlus.GdipFlush (nativeObject, intention);
-                        GDIPlus.CheckStatus (status);                     
+                        GDIPlus.CheckStatus (status);                    
+			if (use_quartz_drawable)
+				Carbon.CGContextFlush (display);
 		}
 
 		[EditorBrowsable (EditorBrowsableState.Advanced)]		
@@ -1260,9 +1262,36 @@
 			IntPtr graphics;
 
 			if (use_quartz_drawable) {
-				QuartzContext qc = (QuartzContext) Marshal.PtrToStructure (hwnd, typeof (QuartzContext));
-				GDIPlus.GdipCreateFromQuartz_macosx (qc.cgContext, qc.width,qc.height, out graphics);
+				IntPtr cgContext = IntPtr.Zero;
 				
+				// Grab the window we're in
+				IntPtr window = Carbon.GetControlOwner (hwnd);
+				// Get the port of the window
+				IntPtr port = Carbon.GetWindowPort (window);
+				// Create a CGContext ref
+				Carbon.CreateCGContextForPort (port, ref cgContext);
+
+				// Get the bounds of the window
+				QRect wBounds = new QRect ();
+				Carbon.GetWindowBounds (window, 32, ref wBounds);
+			
+				// Get the bounds of the view
+				HIRect vBounds = new HIRect ();
+				Carbon.HIViewGetBounds (hwnd, ref vBounds);
+
+				// Convert the view local bounds to window coordinates
+				Carbon.HIViewConvertRect (ref vBounds, hwnd, IntPtr.Zero);
+				Carbon.CGContextTranslateCTM (cgContext, vBounds.origin.x, (wBounds.bottom-wBounds.top)-(vBounds.origin.y+vBounds.size.height));
+				/* FIXME: Do we need this or is it inherintly clipped */
+				HIRect rcClip = new HIRect ();
+				rcClip.origin.x = 0;
+				rcClip.origin.y = 0;
+				rcClip.size.width = vBounds.size.width;
+				rcClip.size.height = vBounds.size.height;
+				Carbon.CGContextClipToRect (cgContext, rcClip);
+				GDIPlus.GdipCreateFromQuartz_macosx (cgContext, (int)vBounds.size.width, (int)vBounds.size.height, out graphics);
+				
+				display = cgContext;
 				return new Graphics (graphics);
 			}
 			if (use_x_drawable) {
@@ -1985,13 +2014,6 @@
                                 return rect;
 			}
 		}
-
-		internal struct QuartzContext
-		{
-			public IntPtr cgContext;
-			public int width;
-			public int height;
-		}
 	}
 }
 

--Apple-Mail-17--232598801
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
	charset=US-ASCII;
	format=flowed


On 9-Dec-04, at 4:18 PM, Peter Dennis Bartok wrote:

> I think it'd be better to have the quartz stuff in a separate file.
> quartzFunctions.cs sounds good. Similar to gdipFunctions.
> It will me much cleaner that way.
>
> Cheers,
>   Peter
>
> -----Original Message-----
> From: "kangaroo" <grompf@sublimeintervention.com>
> To: <mono-winforms-list@lists.ximian.com>
> Date: 09 December, 2004 14:12
> Subject: [Mono-winforms-list] More System.Graphics changes
>
>
>> I've found and implemented a way to support FromHwnd for the Quartz
>> backend; however it involves some apple-only pinvoking in
>> System.Graphics;  my question is; ok to commit as is; or should I 
>> split
>> the internal structs and DllImports off into something like
>> quartzFunctions.cs?
>>
>> -kangaroo
>>
>
> _______________________________________________
> Mono-winforms-list maillist  -  Mono-winforms-list@lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-winforms-list
>
>
> !DSPAM:41b8c048110401055871702!
>

--Apple-Mail-17--232598801--