From 14d7c8b52c897641ca241f39357983d846811be6 Mon Sep 17 00:00:00 2001 From: Geoff Norton Date: Thu, 9 Dec 2004 22:20:46 +0000 Subject: [PATCH] 2004-12-09 Geoff Norton * carbonFunctions.cs: New carbon functions/structures * Graphics.cs: Update FromHwnd to work without being in the carbon eventing loop svn path=/trunk/mcs/; revision=37528 --- mcs/class/System.Drawing/ChangeLog | 4 + .../System.Drawing/System.Drawing.dll.sources | 1 + mcs/class/System.Drawing/System.Drawing/ChangeLog | 5 + .../System.Drawing/System.Drawing/Graphics.cs | 16 +-- .../System.Drawing/carbonFunctions.cs | 123 +++++++++++++++++++++ 5 files changed, 139 insertions(+), 10 deletions(-) create mode 100644 mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs diff --git a/mcs/class/System.Drawing/ChangeLog b/mcs/class/System.Drawing/ChangeLog index e0c73582cc2..fe162d5c57a 100644 --- a/mcs/class/System.Drawing/ChangeLog +++ b/mcs/class/System.Drawing/ChangeLog @@ -1,3 +1,7 @@ +2004-12-09 Geoff Norton + + * System.Drawing.dll.sources: Add System.Drawing/carbonFunctions.cs to the build + 2004-11-22 Ravindra * SD.csproj: Removed a wrong entry from files list. diff --git a/mcs/class/System.Drawing/System.Drawing.dll.sources b/mcs/class/System.Drawing/System.Drawing.dll.sources index 3bb52b11583..bc46443ebf9 100755 --- a/mcs/class/System.Drawing/System.Drawing.dll.sources +++ b/mcs/class/System.Drawing/System.Drawing.dll.sources @@ -5,6 +5,7 @@ System.Drawing/Bitmap.cs 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 diff --git a/mcs/class/System.Drawing/System.Drawing/ChangeLog b/mcs/class/System.Drawing/System.Drawing/ChangeLog index 57f01376d93..14ca6333fc6 100644 --- a/mcs/class/System.Drawing/System.Drawing/ChangeLog +++ b/mcs/class/System.Drawing/System.Drawing/ChangeLog @@ -1,3 +1,8 @@ +2004-12-09 Geoff Norton + + * carbonFunctions.cs: New carbon functions/structures + * Graphics.cs: Update FromHwnd to work without being in the carbon eventing loop + 2004-12-08 Geoff Norton * Graphics.cs: Drop FromHwndWithSize; we can't change the public API diff --git a/mcs/class/System.Drawing/System.Drawing/Graphics.cs b/mcs/class/System.Drawing/System.Drawing/Graphics.cs index b470ecdcdf8..3d9fd97e554 100755 --- a/mcs/class/System.Drawing/System.Drawing/Graphics.cs +++ b/mcs/class/System.Drawing/System.Drawing/Graphics.cs @@ -1228,7 +1228,9 @@ namespace System.Drawing 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,10 @@ namespace System.Drawing 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); + CarbonContext cgContext = Carbon.GetCGContextForView (hwnd); + GDIPlus.GdipCreateFromQuartz_macosx (cgContext.ctx, cgContext.width, cgContext.height, out graphics); + display = cgContext.ctx; return new Graphics (graphics); } if (use_x_drawable) { @@ -1985,13 +1988,6 @@ namespace System.Drawing return rect; } } - - internal struct QuartzContext - { - public IntPtr cgContext; - public int width; - public int height; - } } } diff --git a/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs b/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs new file mode 100644 index 00000000000..58ccb6fdbb5 --- /dev/null +++ b/mcs/class/System.Drawing/System.Drawing/carbonFunctions.cs @@ -0,0 +1,123 @@ +// +// 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 { + + internal static CarbonContext GetCGContextForView (IntPtr hwnd) { + 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); + return new CarbonContext (cgContext, (int)vBounds.size.width, (int)vBounds.size.height); + } + [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; + } + + internal struct CarbonContext + { + public IntPtr ctx; + public int width; + public int height; + + public CarbonContext (IntPtr ctx, int width, int height) + { + this.ctx = ctx; + this.width = width; + this.height = height; + } + } +} -- 2.11.4.GIT