From c2371718586db32092336c06302df6b3fb23e8a2 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Wed, 27 Feb 2013 16:53:49 -0800 Subject: [PATCH 01/21] added 64bit Version of NSRect --- src/Foundation/NSRect.cs | 43 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/Foundation/NSRect.cs diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs new file mode 100644 index 00000000..ca4d5734 --- /dev/null +++ b/src/Foundation/NSRect.cs @@ -0,0 +1,43 @@ +// +// Copyright 2010, Novell, Inc. +// Copyright 2011, 2012 Xamarin Inc +// +// 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; +using System.Runtime.InteropServices; + +namespace MonoMac.Foundation { + [StructLayout(LayoutKind.Sequential)] + public struct NSRect { + public NSRect(System.Drawing.RectangleF rect) + { + Left = rect.Left; + Top = rect.Top; + Width = rect.Width; + Height = rect.Height; + } + + public double Left; + public double Top; + public double Width; + public double Height; + } +} From cac90ff5cf5896134e96cfc63d38d3258c990b0b Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Wed, 27 Feb 2013 17:04:18 -0800 Subject: [PATCH 02/21] using tab style preference for mono files --- src/Foundation/NSRect.cs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs index ca4d5734..06103901 100644 --- a/src/Foundation/NSRect.cs +++ b/src/Foundation/NSRect.cs @@ -25,19 +25,19 @@ using System.Runtime.InteropServices; namespace MonoMac.Foundation { - [StructLayout(LayoutKind.Sequential)] + [StructLayout(LayoutKind.Sequential)] public struct NSRect { - public NSRect(System.Drawing.RectangleF rect) - { - Left = rect.Left; - Top = rect.Top; - Width = rect.Width; - Height = rect.Height; - } + public NSRect(System.Drawing.RectangleF rect) + { + Left = rect.Left; + Top = rect.Top; + Width = rect.Width; + Height = rect.Height; + } - public double Left; - public double Top; - public double Width; - public double Height; + public double Left; + public double Top; + public double Width; + public double Height; } } From d48b33f2e5133529f01f0b926b190302a7018194 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 28 Feb 2013 09:48:05 -0800 Subject: [PATCH 03/21] NSRect, NSPoint, NSSize for 64 bit build --- src/Foundation/NSPoint.cs | 47 ++++++++++++++++++++++++++++++++++++++ src/Foundation/NSRect.cs | 26 ++++++++++++++------- src/Foundation/NSSize.cs | 48 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 8 deletions(-) create mode 100644 src/Foundation/NSPoint.cs create mode 100644 src/Foundation/NSSize.cs diff --git a/src/Foundation/NSPoint.cs b/src/Foundation/NSPoint.cs new file mode 100644 index 00000000..fbd7e544 --- /dev/null +++ b/src/Foundation/NSPoint.cs @@ -0,0 +1,47 @@ +// +// Copyright 2010, Novell, Inc. +// Copyright 2011, 2012 Xamarin Inc +// +// 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; +using System.Runtime.InteropServices; + +// For now, only support MAC64 for NSPoint in order to make sure +// we didn't mess up the 32 bit build +#if MAC64 +namespace MonoMac.Foundation { + [StructLayout(LayoutKind.Sequential)] + public struct NSPoint { + public NSPoint(System.Drawing.PointF point) + { + X = point.X; + Y = point.Y; + } +#if MAC64 + public double X; + public double Y; +#else + public float X; + public float Y; +#endif + } +} +#endif \ No newline at end of file diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs index 06103901..b8349b61 100644 --- a/src/Foundation/NSRect.cs +++ b/src/Foundation/NSRect.cs @@ -24,20 +24,30 @@ using System; using System.Runtime.InteropServices; +// For now, only support MAC64 for NSRect in order to make sure +// we didn't mess up the 32 bit build +#if MAC64 namespace MonoMac.Foundation { [StructLayout(LayoutKind.Sequential)] public struct NSRect { public NSRect(System.Drawing.RectangleF rect) { - Left = rect.Left; - Top = rect.Top; - Width = rect.Width; - Height = rect.Height; + Origin.X = rect.Left; + Origin.Y = rect.Top; + Size.Width = rect.Width; + Size.Height = rect.Height; } - public double Left; - public double Top; - public double Width; - public double Height; + public NSPoint Origin; + public NSSize Size; + +#if MAC64 + public double Width { get { return Size.Width; } } + public double Height { get { return Size.Height; } } +#else + public float Width { get { return Size.Width; } } + public float Height { get { return Size.Height; } } +#endif } } +#endif \ No newline at end of file diff --git a/src/Foundation/NSSize.cs b/src/Foundation/NSSize.cs new file mode 100644 index 00000000..4729de22 --- /dev/null +++ b/src/Foundation/NSSize.cs @@ -0,0 +1,48 @@ +// +// Copyright 2010, Novell, Inc. +// Copyright 2011, 2012 Xamarin Inc +// +// 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; +using System.Runtime.InteropServices; + +// For now, only support MAC64 for NSSize in order to make sure +// we didn't mess up the 32 bit build +#if MAC64 +namespace MonoMac.Foundation { + [StructLayout(LayoutKind.Sequential)] + public struct NSSize { + public NSSize(System.Drawing.SizeF size) + { + Width = size.Width; + Height = size.Height; + } + +#if MAC64 + public double Width; + public double Height; +#else + public float Width; + public float Height; +#endif + } +} +#endif \ No newline at end of file From a99b88e3de7c7b283998e7243ccb70952b42e3bb Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 28 Feb 2013 11:17:10 -0800 Subject: [PATCH 04/21] NSPredicateEditorRowTemplate reviewed for 64 bit --- src/CoreData/Enums.cs | 1 + src/Foundation/Enum.cs | 10 +++++++++- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/CoreData/Enums.cs b/src/CoreData/Enums.cs index d627f768..5b0bd457 100644 --- a/src/CoreData/Enums.cs +++ b/src/CoreData/Enums.cs @@ -32,6 +32,7 @@ public enum NSEntityMappingType : uint { Transform = 0x06 } + //TODO: figure out size for 64 bit public enum NSAttributeType : uint { Undefined = 0, Integer16 = 100, diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index 6713323d..f74d3524 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -316,8 +316,12 @@ public enum NSStreamEvent : uint { ErrorOccurred = 1 << 3, EndEncountered = 1 << 4 } - + +#if MAC64 + public enum NSComparisonPredicateModifier : ulong { +#else public enum NSComparisonPredicateModifier { +#endif Direct, All, Any @@ -341,7 +345,11 @@ public enum NSPredicateOperatorType { } [Flags] +#if MAC64 + public enum NSComparisonPredicateOptions : ulong { +#else public enum NSComparisonPredicateOptions { +#endif CaseInsensitive=0x01, DiacriticInsensitive=0x02 } From 069985ff6ff097912b172e8c97124925e449bb4f Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Wed, 6 Mar 2013 09:38:29 -0800 Subject: [PATCH 05/21] Working on 64bit support for CoreGraphics --- src/CoreGraphics/CGAffineTransform.cs | 89 ++++-- src/CoreGraphics/CGColor.cs | 45 ++- src/CoreGraphics/CGColorSpace.cs | 41 ++- src/CoreGraphics/CGContext.cs | 424 ++++++++++++++++++++------ src/CoreGraphics/CGContextPDF.cs | 43 ++- src/CoreGraphics/CGDataProvider.cs | 8 +- src/CoreGraphics/CGFont.cs | 36 ++- src/CoreGraphics/CGFunction.cs | 35 ++- src/CoreGraphics/CGGeometry.cs | 98 +++++- src/CoreGraphics/CGGradient.cs | 43 ++- src/CoreGraphics/CGImage.cs | 142 +++++++-- src/CoreGraphics/CGLayer.cs | 26 +- src/CoreGraphics/CGPath.cs | 104 ++++++- 13 files changed, 908 insertions(+), 226 deletions(-) diff --git a/src/CoreGraphics/CGAffineTransform.cs b/src/CoreGraphics/CGAffineTransform.cs index 38a706ab..d848a198 100644 --- a/src/CoreGraphics/CGAffineTransform.cs +++ b/src/CoreGraphics/CGAffineTransform.cs @@ -32,28 +32,61 @@ using MonoMac.ObjCRuntime; using MonoMac.Foundation; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + namespace MonoMac.CoreGraphics { [StructLayout(LayoutKind.Sequential)] public struct CGAffineTransform { - public float xx; // a - public float yx; // b - public float xy; // c - public float yy; // d - public float x0; // tx - public float y0; // ty + CGFloat a,b,c,d,tx,ty; + + public float xx { + get { return (float)a; } + set { a = value; } + } + public float yx { + get { return (float)b; } + set { b = value; } + } + public float xy { + get { return (float)c; } + set { c = value; } + } + public float yy { + get { return (float)d; } + set { d = value; } + } + public float x0 { + get { return (float)tx; } + set { tx = value; } + } + public float y0 { + get { return (float)ty; } + set { ty = value; } + } // // Constructors // public CGAffineTransform (float xx, float yx, float xy, float yy, float x0, float y0) { - this.xx = xx; - this.yx = yx; - this.xy = xy; - this.yy = yy; - this.x0 = x0; - this.y0 = y0; + this.a = xx; + this.b = yx; + this.c = xy; + this.d = yy; + this.tx = x0; + this.ty = y0; } // Identity @@ -85,12 +118,12 @@ public static CGAffineTransform MakeTranslation (float tx, float ty) // public static CGAffineTransform Multiply (CGAffineTransform a, CGAffineTransform b) { - return new CGAffineTransform (a.xx * b.xx + a.yx * b.xy, - a.xx * b.yx + a.yx * b.yy, - a.xy * b.xx + a.yy * b.xy, - a.xy * b.yx + a.yy * b.yy, - a.x0 * b.xx + a.y0 * b.xy + b.x0, - a.x0 * b.yx + a.y0 * b.yy + b.y0); + return new CGAffineTransform ((float)(a.xx * b.xx + a.yx * b.xy), + (float)(a.xx * b.yx + a.yx * b.yy), + (float)(a.xy * b.xx + a.yy * b.xy), + (float)(a.xy * b.yx + a.yy * b.yy), + (float)(a.x0 * b.xx + a.y0 * b.xy + b.x0), + (float)(a.x0 * b.yx + a.y0 * b.yy + b.y0)); } public void Multiply (CGAffineTransform b) @@ -145,12 +178,12 @@ public override String ToString () public static CGAffineTransform operator * (CGAffineTransform a, CGAffineTransform b) { - return new CGAffineTransform (a.xx * b.xx + a.yx * b.xy, - a.xx * b.yx + a.yx * b.yy, - a.xy * b.xx + a.yy * b.xy, - a.xy * b.yx + a.yy * b.yy, - a.x0 * b.xx + a.y0 * b.xy + b.x0, - a.x0 * b.yx + a.y0 * b.yy + b.y0); + return new CGAffineTransform ((float)(a.xx * b.xx + a.yx * b.xy), + (float)(a.xx * b.yx + a.yx * b.yy), + (float)(a.xy * b.xx + a.yy * b.xy), + (float)(a.xy * b.yx + a.yy * b.yy), + (float)(a.x0 * b.xx + a.y0 * b.xy + b.x0), + (float)(a.x0 * b.yx + a.y0 * b.yy + b.y0)); } public override bool Equals(object o) @@ -170,14 +203,14 @@ public override int GetHashCode() public PointF TransformPoint (PointF point) { - return new PointF (xx * point.X + xy * point.Y + x0, - yx * point.X + yy * point.Y + y0); + return new PointF ((float)(xx * point.X + xy * point.Y + x0), + (float)(yx * point.X + yy * point.Y + y0)); } [DllImport (Constants.CoreGraphicsLibrary)] - public extern static RectangleF CGRectApplyAffineTransform (RectangleF rect, CGAffineTransform t); + public extern static NSRect CGRectApplyAffineTransform (NSRect rect, CGAffineTransform t); - public RectangleF TransformRect (RectangleF rect) + public NSRect TransformRect (NSRect rect) { return CGRectApplyAffineTransform (rect, this); } diff --git a/src/CoreGraphics/CGColor.cs b/src/CoreGraphics/CGColor.cs index 93405b98..cccb1e45 100644 --- a/src/CoreGraphics/CGColor.cs +++ b/src/CoreGraphics/CGColor.cs @@ -31,6 +31,20 @@ using MonoMac.CoreFoundation; using MonoMac.Foundation; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.CoreGraphics { public class CGColor : INativeObject, IDisposable { @@ -70,7 +84,7 @@ public IntPtr Handle { } [DllImport(Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorCreate(IntPtr space, float [] components); + extern static IntPtr CGColorCreate(IntPtr space, CGFloat [] components); public CGColor (CGColorSpace colorspace, float [] components) { @@ -80,19 +94,20 @@ public CGColor (CGColorSpace colorspace, float [] components) throw new ArgumentNullException ("colorspace"); if (colorspace.handle == IntPtr.Zero) throw new ObjectDisposedException ("colorspace"); - - handle = CGColorCreate (colorspace.handle, components); + CGFloat[] _components = new CGFloat[components.Length]; + Array.Copy (components, _components, components.Length); + handle = CGColorCreate (colorspace.handle, _components); } [DllImport(Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorCreateGenericGray(float gray, float alpha); + extern static IntPtr CGColorCreateGenericGray(CGFloat gray, CGFloat alpha); public CGColor (float gray, float alpha) { handle = CGColorCreateGenericGray (gray, alpha); } [DllImport(Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorCreateGenericRGB (float red, float green, float blue, float alpha); + extern static IntPtr CGColorCreateGenericRGB (CGFloat red, CGFloat green, CGFloat blue, CGFloat alpha); public CGColor (float red, float green, float blue, float alpha) { handle = CGColorCreateGenericRGB (red, green, blue, alpha); @@ -118,7 +133,7 @@ public CGColor (string name) } [DllImport(Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorCreateWithPattern(IntPtr space, IntPtr pattern, float [] components); + extern static IntPtr CGColorCreateWithPattern(IntPtr space, IntPtr pattern, CGFloat [] components); public CGColor (CGColorSpace colorspace, CGPattern pattern, float [] components) { if (colorspace == null) @@ -130,13 +145,15 @@ public CGColor (CGColorSpace colorspace, CGPattern pattern, float [] components) if (components == null) throw new ArgumentNullException ("components"); - handle = CGColorCreateWithPattern (colorspace.handle, pattern.handle, components); + CGFloat[] _components = new CGFloat[components.Length]; + Array.Copy (components, _components, components.Length); + handle = CGColorCreateWithPattern (colorspace.handle, pattern.handle, _components); if (handle == IntPtr.Zero) throw new ArgumentException (); } [DllImport(Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorCreateCopyWithAlpha(IntPtr color, float alpha); + extern static IntPtr CGColorCreateCopyWithAlpha(IntPtr color, CGFloat alpha); public CGColor (CGColor source, float alpha) { if (source == null) @@ -183,16 +200,16 @@ public int NumberOfComponents { } [DllImport(Constants.CoreGraphicsLibrary)] - extern static unsafe float *CGColorGetComponents(IntPtr color); + extern static unsafe CGFloat *CGColorGetComponents(IntPtr color); public float [] Components { get { int n = NumberOfComponents; - float [] result = new float [n]; + float [] result = new float[n]; unsafe { - float *cptr = CGColorGetComponents (handle); + CGFloat *cptr = CGColorGetComponents (handle); for (int i = 0; i < n; i++){ - result [i] = cptr [i]; + result [i] = (float)cptr [i]; } } return result; @@ -200,10 +217,10 @@ public float [] Components { } [DllImport(Constants.CoreGraphicsLibrary)] - extern static float CGColorGetAlpha(IntPtr color); + extern static CGFloat CGColorGetAlpha(IntPtr color); public float Alpha { get { - return CGColorGetAlpha (handle); + return (float)CGColorGetAlpha (handle); } } diff --git a/src/CoreGraphics/CGColorSpace.cs b/src/CoreGraphics/CGColorSpace.cs index 624869cb..9616e29f 100644 --- a/src/CoreGraphics/CGColorSpace.cs +++ b/src/CoreGraphics/CGColorSpace.cs @@ -32,6 +32,20 @@ using MonoMac.ObjCRuntime; using MonoMac.Foundation; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.CoreGraphics { public enum CGColorRenderingIntent { @@ -128,7 +142,7 @@ public static CGColorSpace CreateDeviceCMYK () } [DllImport (Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorSpaceCreateCalibratedGray (float [] whitepoint, float [] blackpoint, float gamma); + extern static IntPtr CGColorSpaceCreateCalibratedGray (CGFloat [] whitepoint, CGFloat [] blackpoint, CGFloat gamma); public static CGColorSpace CreateCalibratedGray (float [] whitepoint, float [] blackpoint, float gamma) { @@ -136,13 +150,16 @@ public static CGColorSpace CreateCalibratedGray (float [] whitepoint, float [] b throw new ArgumentException ("Must have 3 values", "whitepoint"); if (blackpoint.Length != 3) throw new ArgumentException ("Must have 3 values", "blackpoint"); - - return new CGColorSpace (CGColorSpaceCreateCalibratedGray (whitepoint, blackpoint, gamma), true); + CGFloat[] _whitepoint = new CGFloat[3]; + Array.Copy (whitepoint, _whitepoint, 3); + CGFloat[] _blackpoint = new CGFloat[3]; + Array.Copy (blackpoint, _blackpoint, 3); + return new CGColorSpace (CGColorSpaceCreateCalibratedGray (_whitepoint, _blackpoint, gamma), true); } // 3, 3, 3, 9 [DllImport (Constants.CoreGraphicsLibrary)] - extern static IntPtr CGColorSpaceCreateCalibratedRGB (float [] whitePoint, float [] blackPoint, float [] gamma, float [] matrix); + extern static IntPtr CGColorSpaceCreateCalibratedRGB (CGFloat [] whitePoint, CGFloat [] blackPoint, CGFloat [] gamma, CGFloat [] matrix); public static CGColorSpace CreateCalibratedRGB (float [] whitepoint, float [] blackpoint, float [] gamma, float [] matrix) { if (whitepoint.Length != 3) @@ -153,18 +170,26 @@ public static CGColorSpace CreateCalibratedRGB (float [] whitepoint, float [] bl throw new ArgumentException ("Must have 3 values", "gamma"); if (matrix.Length != 9) throw new ArgumentException ("Must have 9 values", "matrix"); - - return new CGColorSpace (CGColorSpaceCreateCalibratedRGB (whitepoint, blackpoint, gamma, matrix), true); + CGFloat[] _whitepoint = new CGFloat[3]; + Array.Copy (whitepoint, _whitepoint, 3); + CGFloat[] _blackpoint = new CGFloat[3]; + Array.Copy (blackpoint, _blackpoint, 3); + CGFloat[] _gamma = new CGFloat[3]; + Array.Copy (gamma, _gamma, 3); + CGFloat[] _matrix = new CGFloat[9]; + Array.Copy (matrix, _matrix, 9); + + return new CGColorSpace (CGColorSpaceCreateCalibratedRGB (_whitepoint, _blackpoint, _gamma, _matrix), true); } [DllImport (Constants.CoreGraphicsLibrary)] extern static IntPtr CGColorSpaceCreateIndexed (IntPtr baseSpace, - int lastIndex, + IntPtr lastIndex, byte[] colorTable); public static CGColorSpace CreateIndexed (CGColorSpace baseSpace, int lastIndex, byte[] colorTable) { - return new CGColorSpace (CGColorSpaceCreateIndexed (baseSpace == null ? IntPtr.Zero : baseSpace.handle, lastIndex, colorTable), true); + return new CGColorSpace (CGColorSpaceCreateIndexed (baseSpace == null ? IntPtr.Zero : baseSpace.handle, new IntPtr(lastIndex), colorTable), true); } diff --git a/src/CoreGraphics/CGContext.cs b/src/CoreGraphics/CGContext.cs index 0241297e..07241daf 100644 --- a/src/CoreGraphics/CGContext.cs +++ b/src/CoreGraphics/CGContext.cs @@ -33,6 +33,20 @@ using MonoMac.ObjCRuntime; using MonoMac.Foundation; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.CoreGraphics { public enum CGLineJoin { @@ -189,21 +203,21 @@ public void RestoreState () // [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextScaleCTM (IntPtr ctx, float sx, float sy); + extern static void CGContextScaleCTM (IntPtr ctx, CGFloat sx, CGFloat sy); public void ScaleCTM (float sx, float sy) { CGContextScaleCTM (handle, sx, sy); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextTranslateCTM (IntPtr ctx, float tx, float ty); + extern static void CGContextTranslateCTM (IntPtr ctx, CGFloat tx, CGFloat ty); public void TranslateCTM (float tx, float ty) { CGContextTranslateCTM (handle, tx, ty); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextRotateCTM (IntPtr ctx, float angle); + extern static void CGContextRotateCTM (IntPtr ctx, CGFloat angle); public void RotateCTM (float angle) { CGContextRotateCTM (handle, angle); @@ -218,7 +232,7 @@ public void ConcatCTM (CGAffineTransform transform) // Settings [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextSetLineWidth(IntPtr c, float width); + extern static void CGContextSetLineWidth(IntPtr c, CGFloat width); public void SetLineWidth (float w) { CGContextSetLineWidth (handle, w); @@ -239,19 +253,17 @@ public void SetLineJoin (CGLineJoin join) } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextSetMiterLimit(IntPtr c, float limit); + extern static void CGContextSetMiterLimit(IntPtr c, CGFloat limit); public void SetMiterLimit (float limit) { CGContextSetMiterLimit (handle, limit); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextSetLineDash(IntPtr c, float phase, float [] lengths, int count); + extern static void CGContextSetLineDash(IntPtr c, CGFloat phase, CGFloat [] lengths, IntPtr count); public void SetLineDash (float phase, float [] lengths) { - if (lengths == null) - throw new ArgumentNullException ("lengths"); - CGContextSetLineDash (handle, phase, lengths, lengths.Length); + SetLineDash (phase, lengths, lengths.Length); } public void SetLineDash (float phase, float [] lengths, int n) @@ -260,18 +272,20 @@ public void SetLineDash (float phase, float [] lengths, int n) throw new ArgumentNullException ("lengths"); if (n > lengths.Length) throw new ArgumentNullException ("n"); - CGContextSetLineDash (handle, phase, lengths, n); + CGFloat[] _lengths = new CGFloat[lengths.Length]; + Array.Copy (lengths, _lengths, lengths.Length); + CGContextSetLineDash (handle, phase, _lengths, new IntPtr(n)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextSetFlatness(IntPtr c, float flatness); + extern static void CGContextSetFlatness(IntPtr c, CGFloat flatness); public void SetFlatness (float flatness) { CGContextSetFlatness (handle, flatness); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextSetAlpha(IntPtr c, float alpha); + extern static void CGContextSetAlpha(IntPtr c, CGFloat alpha); public void SetAlpha (float alpha) { CGContextSetAlpha (handle, alpha); @@ -299,28 +313,28 @@ public void BeginPath () } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextMoveToPoint(IntPtr c, float x, float y); + extern static void CGContextMoveToPoint(IntPtr c, CGFloat x, CGFloat y); public void MoveTo (float x, float y) { CGContextMoveToPoint (handle, x, y); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextAddLineToPoint(IntPtr c, float x, float y); + extern static void CGContextAddLineToPoint(IntPtr c, CGFloat x, CGFloat y); public void AddLineToPoint (float x, float y) { CGContextAddLineToPoint (handle, x, y); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextAddCurveToPoint(IntPtr c, float cp1x, float cp1y, float cp2x, float cp2y, float x, float y); + extern static void CGContextAddCurveToPoint(IntPtr c, CGFloat cp1x, CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y); public void AddCurveToPoint (float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) { CGContextAddCurveToPoint (handle, cp1x, cp1y, cp2x, cp2y, x, y); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextAddQuadCurveToPoint(IntPtr c, float cpx, float cpy, float x, float y); + extern static void CGContextAddQuadCurveToPoint(IntPtr c, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y); public void AddQuadCurveToPoint (float cpx, float cpy, float x, float y) { CGContextAddQuadCurveToPoint (handle, cpx, cpy, x, y); @@ -334,42 +348,64 @@ public void ClosePath () } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextAddRect(IntPtr c, RectangleF rect); + extern static void CGContextAddRect(IntPtr c, NSRect rect); public void AddRect (RectangleF rect) { +#if MAC64 + CGContextAddRect (handle, new NSRect(rect)); +#else CGContextAddRect (handle, rect); +#endif } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextAddRects(IntPtr c, RectangleF [] rects, int size_t_count) ; + extern static void CGContextAddRects(IntPtr c, NSRect [] rects, IntPtr size_t_count) ; public void AddRects (RectangleF [] rects) { - CGContextAddRects (handle, rects, rects.Length); +#if MAC64 + NSRect[] _rects = new NSRect[rects.Length]; + for( int i=0; i str.Length) throw new ArgumentException ("count"); - CGContextShowText (handle, str, count); + CGContextShowText (handle, str, new IntPtr(count)); } public void ShowText (string str) { if (str == null) throw new ArgumentNullException ("str"); - CGContextShowText (handle, str, str.Length); + CGContextShowText (handle, str, new IntPtr(str.Length)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowText(IntPtr c, byte[] bytes, int size_t_length); + extern static void CGContextShowText(IntPtr c, byte[] bytes, IntPtr size_t_length); public void ShowText (byte[] bytes, int count) { if (bytes == null) throw new ArgumentNullException ("bytes"); if (count > bytes.Length) throw new ArgumentException ("count"); - CGContextShowText (handle, bytes, count); + CGContextShowText (handle, bytes, new IntPtr(count)); } public void ShowText (byte[] bytes) { if (bytes == null) throw new ArgumentNullException ("bytes"); - CGContextShowText (handle, bytes, bytes.Length); + CGContextShowText (handle, bytes, new IntPtr(bytes.Length)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowTextAtPoint(IntPtr c, float x, float y, string str, int size_t_length); + extern static void CGContextShowTextAtPoint(IntPtr c, CGFloat x, CGFloat y, string str, IntPtr size_t_length); public void ShowTextAtPoint (float x, float y, string str, int length) { if (str == null) throw new ArgumentNullException ("str"); - CGContextShowTextAtPoint (handle, x, y, str, length); + CGContextShowTextAtPoint (handle, x, y, str, new IntPtr(length)); } public void ShowTextAtPoint (float x, float y, string str) { if (str == null) throw new ArgumentNullException ("str"); - CGContextShowTextAtPoint (handle, x, y, str, str.Length); + CGContextShowTextAtPoint (handle, x, y, str, new IntPtr(str.Length)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowTextAtPoint(IntPtr c, float x, float y, byte[] bytes, int size_t_length); + extern static void CGContextShowTextAtPoint(IntPtr c, CGFloat x, CGFloat y, byte[] bytes, IntPtr size_t_length); public void ShowTextAtPoint (float x, float y, byte[] bytes, int length) { if (bytes == null) throw new ArgumentNullException ("bytes"); - CGContextShowTextAtPoint (handle, x, y, bytes, length); + CGContextShowTextAtPoint (handle, x, y, bytes, new IntPtr(length)); } public void ShowTextAtPoint (float x, float y, byte[] bytes) { if (bytes == null) throw new ArgumentNullException ("bytes"); - CGContextShowTextAtPoint (handle, x, y, bytes, bytes.Length); + CGContextShowTextAtPoint (handle, x, y, bytes, new IntPtr(bytes.Length)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowGlyphs(IntPtr c, ushort [] glyphs, int size_t_count); + extern static void CGContextShowGlyphs(IntPtr c, ushort [] glyphs, IntPtr size_t_count); public void ShowGlyphs (ushort [] glyphs) { if (glyphs == null) throw new ArgumentNullException ("glyphs"); - CGContextShowGlyphs (handle, glyphs, glyphs.Length); + CGContextShowGlyphs (handle, glyphs, new IntPtr(glyphs.Length)); } public void ShowGlyphs (ushort [] glyphs, int count) @@ -938,18 +1110,18 @@ public void ShowGlyphs (ushort [] glyphs, int count) throw new ArgumentNullException ("glyphs"); if (count > glyphs.Length) throw new ArgumentException ("count"); - CGContextShowGlyphs (handle, glyphs, count); + CGContextShowGlyphs (handle, glyphs, new IntPtr(count)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowGlyphsAtPoint(IntPtr context, float x, float y, ushort [] glyphs, int size_t_count); + extern static void CGContextShowGlyphsAtPoint(IntPtr context, CGFloat x, CGFloat y, ushort [] glyphs, IntPtr size_t_count); public void ShowGlyphsAtPoint (float x, float y, ushort [] glyphs, int count) { if (glyphs == null) throw new ArgumentNullException ("glyphs"); if (count > glyphs.Length) throw new ArgumentException ("count"); - CGContextShowGlyphsAtPoint (handle, x, y, glyphs, count); + CGContextShowGlyphsAtPoint (handle, x, y, glyphs, new IntPtr(count)); } public void ShowGlyphsAtPoint (float x, float y, ushort [] glyphs) @@ -957,11 +1129,11 @@ public void ShowGlyphsAtPoint (float x, float y, ushort [] glyphs) if (glyphs == null) throw new ArgumentNullException ("glyphs"); - CGContextShowGlyphsAtPoint (handle, x, y, glyphs, glyphs.Length); + CGContextShowGlyphsAtPoint (handle, x, y, glyphs, new IntPtr(glyphs.Length)); } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGContextShowGlyphsWithAdvances(IntPtr c, ushort [] glyphs, SizeF [] advances, int size_t_count); + extern static void CGContextShowGlyphsWithAdvances(IntPtr c, ushort [] glyphs, NSSize [] advances, IntPtr size_t_count); public void ShowGlyphsWithAdvances (ushort [] glyphs, SizeF [] advances, int count) { if (glyphs == null) @@ -970,7 +1142,14 @@ public void ShowGlyphsWithAdvances (ushort [] glyphs, SizeF [] advances, int cou throw new ArgumentNullException ("advances"); if (count > glyphs.Length || count > advances.Length) throw new ArgumentException ("count"); - CGContextShowGlyphsWithAdvances (handle, glyphs, advances, count); +#if MAC64 + NSSize[] _advances = new NSSize[advances.Length]; + for( int i=0; i Date: Wed, 6 Mar 2013 14:36:22 -0800 Subject: [PATCH 06/21] CoreGraphics 64bit support --- src/CoreGraphics/CGPath.cs | 161 ++++++++++++++++++++++++++-------- src/CoreGraphics/CGPattern.cs | 21 ++++- src/CoreGraphics/CGShading.cs | 27 +++++- 3 files changed, 168 insertions(+), 41 deletions(-) diff --git a/src/CoreGraphics/CGPath.cs b/src/CoreGraphics/CGPath.cs index 5c17066a..8463fea3 100644 --- a/src/CoreGraphics/CGPath.cs +++ b/src/CoreGraphics/CGPath.cs @@ -177,9 +177,9 @@ public override bool Equals (object o) } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathMoveToPoint(IntPtr path, ref CGAffineTransform m, float x, float y); + extern static void CGPathMoveToPoint(IntPtr path, ref CGAffineTransform m, CGFloat x, CGFloat y); [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathMoveToPoint(IntPtr path, IntPtr zero, float x, float y); + extern static void CGPathMoveToPoint(IntPtr path, IntPtr zero, CGFloat x, CGFloat y); public void MoveToPoint (float x, float y) { CGPathMoveToPoint (handle, IntPtr.Zero, x, y); @@ -202,9 +202,9 @@ public void MoveToPoint (CGAffineTransform transform, PointF point) } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddLineToPoint(IntPtr path, ref CGAffineTransform m, float x, float y); + extern static void CGPathAddLineToPoint(IntPtr path, ref CGAffineTransform m, CGFloat x, CGFloat y); [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddLineToPoint(IntPtr path, IntPtr m, float x, float y); + extern static void CGPathAddLineToPoint(IntPtr path, IntPtr m, CGFloat x, CGFloat y); [Advice ("Use AddLineToPoint instead")] // Bad name public void CGPathAddLineToPoint (float x, float y) @@ -239,9 +239,9 @@ public void AddLineToPoint (CGAffineTransform transform, PointF point) } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddQuadCurveToPoint(IntPtr path, ref CGAffineTransform m, float cpx, float cpy, float x, float y); + extern static void CGPathAddQuadCurveToPoint(IntPtr path, ref CGAffineTransform m, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y); [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddQuadCurveToPoint(IntPtr path, IntPtr zero, float cpx, float cpy, float x, float y); + extern static void CGPathAddQuadCurveToPoint(IntPtr path, IntPtr zero, CGFloat cpx, CGFloat cpy, CGFloat x, CGFloat y); public void AddQuadCurveToPoint (float cpx, float cpy, float x, float y) { CGPathAddQuadCurveToPoint (handle, IntPtr.Zero, cpx, cpy, x, y); @@ -253,7 +253,7 @@ public void AddQuadCurveToPoint (CGAffineTransform transform, float cpx, float c } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddCurveToPoint(IntPtr path, ref CGAffineTransform m, float cp1x, float cp1y, float cp2x, float cp2y, float x, float y); + extern static void CGPathAddCurveToPoint(IntPtr path, ref CGAffineTransform m, CGFloat cp1x, CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y); public void AddCurveToPoint (CGAffineTransform transform, float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) { CGPathAddCurveToPoint (handle, ref transform, cp1x, cp1y, cp2x, cp2y, x, y); @@ -265,7 +265,7 @@ public void AddCurveToPoint (CGAffineTransform transform, PointF cp1, PointF cp2 } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddCurveToPoint(IntPtr path, IntPtr zero, float cp1x, float cp1y, float cp2x, float cp2y, float x, float y); + extern static void CGPathAddCurveToPoint(IntPtr path, IntPtr zero, CGFloat cp1x, CGFloat cp1y, CGFloat cp2x, CGFloat cp2y, CGFloat x, CGFloat y); public void AddCurveToPoint (float cp1x, float cp1y, float cp2x, float cp2y, float x, float y) { CGPathAddCurveToPoint (handle, IntPtr.Zero, cp1x, cp1y, cp2x, cp2y, x, y); @@ -284,127 +284,192 @@ public void CloseSubpath () } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddRect(IntPtr path, ref CGAffineTransform m, RectangleF rect); + extern static void CGPathAddRect(IntPtr path, ref CGAffineTransform m, NSRect rect); public void AddRect (CGAffineTransform transform, RectangleF rect) { +#if MAC64 + CGPathAddRect (handle, ref transform, new NSRect(rect)); +#else CGPathAddRect (handle, ref transform, rect); +#endif } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddRect(IntPtr path, IntPtr zero, RectangleF rect); + extern static void CGPathAddRect(IntPtr path, IntPtr zero, NSRect rect); public void AddRect (RectangleF rect) { +#if MAC64 + CGPathAddRect (handle, IntPtr.Zero, new NSRect(rect)); +#else CGPathAddRect (handle, IntPtr.Zero, rect); +#endif } [DllImport (Constants.CoreGraphicsLibrary)] - extern static void CGPathAddRects(IntPtr path, ref CGAffineTransform m, RectangleF [] rects, int size_t_count); + extern static void CGPathAddRects(IntPtr path, ref CGAffineTransform m, NSRect [] rects, IntPtr size_t_count); public void AddRects (CGAffineTransform m, RectangleF [] rects) { - CGPathAddRects (handle, ref m, rects, rects.Length); +#if MAC64 + NSRect[] _rects = new NSRect[rects.Length]; + for( int i=0; i rects.Length) throw new ArgumentException ("counts"); - CGPathAddRects (handle, ref m, rects, count); +#if MAC64 + NSRect[] _rects = new NSRect[rects.Length]; + for( int i=0; i rects.Length) throw new ArgumentException ("count"); - CGPathAddRects (handle, IntPtr.Zero, rects, count); +#if MAC64 + NSRect[] _rects = new NSRect[rects.Length]; + for( int i=0; i points.Length) throw new ArgumentException ("count"); - CGPathAddLines (handle, ref m, points, count); +#if MAC64 + NSPoint[] _points = new NSPoint[points.Length]; + for( int i=0; i points.Length) throw new ArgumentException ("count"); - CGPathAddLines (handle, IntPtr.Zero, points, count); +#if MAC64 + NSPoint[] _points = new NSPoint[points.Length]; + for( int i=0; i Date: Wed, 6 Mar 2013 15:36:01 -0800 Subject: [PATCH 07/21] Removed warning on 32 build of unused variable --- src/CoreGraphics/CGPath.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/CoreGraphics/CGPath.cs b/src/CoreGraphics/CGPath.cs index 8463fea3..d54764ba 100644 --- a/src/CoreGraphics/CGPath.cs +++ b/src/CoreGraphics/CGPath.cs @@ -589,7 +589,9 @@ static void ApplierCallback (IntPtr info, IntPtr element_ptr) CGPathElement element = new CGPathElement (Marshal.ReadInt32 (element_ptr, 0)); ApplierFunction func = (ApplierFunction) gch.Target; +#if MAC64 NSPoint pt; +#endif IntPtr ptr = Marshal.ReadIntPtr (element_ptr, 4); int ptsize = Marshal.SizeOf (typeof (NSPoint)); From 321d1f4b5a432b6bcaee52e4c3d996a8cda0152e Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Sat, 9 Mar 2013 09:15:52 -0800 Subject: [PATCH 08/21] Update ImageIO for 64 bit --- src/ImageIO/CGImageSource.cs | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ImageIO/CGImageSource.cs b/src/ImageIO/CGImageSource.cs index 6e2485e8..a5426079 100644 --- a/src/ImageIO/CGImageSource.cs +++ b/src/ImageIO/CGImageSource.cs @@ -240,11 +240,11 @@ public string TypeIdentifier { } [DllImport (Constants.ImageIOLibrary)] - extern static int CGImageSourceGetCount (IntPtr handle); + extern static IntPtr CGImageSourceGetCount (IntPtr handle); public int ImageCount { get { - return CGImageSourceGetCount (handle); + return CGImageSourceGetCount (handle).ToInt32(); } } @@ -266,12 +266,12 @@ public NSDictionary CopyProperties (CGImageOptions options) } [DllImport (Constants.ImageIOLibrary)] - extern static IntPtr CGImageSourceCopyPropertiesAtIndex (IntPtr handle, int idx, IntPtr dictOptions); + extern static IntPtr CGImageSourceCopyPropertiesAtIndex (IntPtr handle, IntPtr idx, IntPtr dictOptions); [Advice ("Use GetProperties")] public NSDictionary CopyProperties (NSDictionary dict, int imageIndex) { - return new NSDictionary (CGImageSourceCopyPropertiesAtIndex (handle, imageIndex, dict == null ? IntPtr.Zero : dict.Handle)); + return new NSDictionary (CGImageSourceCopyPropertiesAtIndex (handle, new IntPtr(imageIndex), dict == null ? IntPtr.Zero : dict.Handle)); } [Advice ("Use GetProperties")] @@ -293,21 +293,21 @@ public CoreGraphics.CGImageProperties GetProperties (int index, CGImageOptions o } [DllImport (Constants.ImageIOLibrary)] - extern static IntPtr CGImageSourceCreateImageAtIndex(IntPtr isrc, int index, IntPtr options); + extern static IntPtr CGImageSourceCreateImageAtIndex(IntPtr isrc, IntPtr index, IntPtr options); public CGImage CreateImage (int index, CGImageOptions options) { using (var dict = options == null ? null : options.ToDictionary ()) { - var ret = CGImageSourceCreateImageAtIndex (handle, index, dict == null ? IntPtr.Zero : dict.Handle); + var ret = CGImageSourceCreateImageAtIndex (handle, new IntPtr(index), dict == null ? IntPtr.Zero : dict.Handle); return new CGImage (ret, true); } } [DllImport (Constants.ImageIOLibrary)] - extern static IntPtr CGImageSourceCreateThumbnailAtIndex (IntPtr isrc, int index, IntPtr options); + extern static IntPtr CGImageSourceCreateThumbnailAtIndex (IntPtr isrc, IntPtr index, IntPtr options); public CGImage CreateThumbnail (int index, CGImageThumbnailOptions options) { using (var dict = options == null ? null : options.ToDictionary ()) { - var ret = CGImageSourceCreateThumbnailAtIndex (handle, index, dict == null ? IntPtr.Zero : dict.Handle); + var ret = CGImageSourceCreateThumbnailAtIndex (handle, new IntPtr(index), dict == null ? IntPtr.Zero : dict.Handle); return new CGImage (ret, true); } } @@ -349,11 +349,11 @@ public CGImageSourceStatus GetStatus () } [DllImport (Constants.ImageIOLibrary)] - extern static CGImageSourceStatus CGImageSourceGetStatusAtIndex (IntPtr handle, int idx); + extern static CGImageSourceStatus CGImageSourceGetStatusAtIndex (IntPtr handle, IntPtr idx); public CGImageSourceStatus GetStatus (int index) { - return CGImageSourceGetStatusAtIndex (handle, index); + return CGImageSourceGetStatusAtIndex (handle, new IntPtr(index)); } } } From 6778c031d1cb21658994496ed2fa0111e55e2819 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Sat, 9 Mar 2013 09:37:23 -0800 Subject: [PATCH 09/21] NSArray and NSAttributedString made 64bit compatible --- src/CoreImage/CIImage.cs | 18 ++++++++++++-- src/Foundation/NSArray.cs | 18 ++++++++++++-- src/foundation.cs | 50 +++++++++++++++++++++++++-------------- 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/src/CoreImage/CIImage.cs b/src/CoreImage/CIImage.cs index b6715f64..aa56d580 100644 --- a/src/CoreImage/CIImage.cs +++ b/src/CoreImage/CIImage.cs @@ -32,6 +32,20 @@ using MonoMac.CoreGraphics; #endif +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.CoreImage { public class CIAutoAdjustmentFilterOptions { @@ -89,11 +103,11 @@ static CIFilter [] WrapFilters (NSArray filters) if (filters == null) return new CIFilter [0]; - uint count = filters.Count; + NSUInteger count = filters.Count; if (count == 0) return new CIFilter [0]; var ret = new CIFilter [count]; - for (uint i = 0; i < count; i++){ + for (NSUInteger i = 0; i < count; i++){ IntPtr filterHandle = filters.ValueAt (i); string filterName = CIFilter.GetFilterName (filterHandle); diff --git a/src/Foundation/NSArray.cs b/src/Foundation/NSArray.cs index 5d81c92c..69ecceaf 100644 --- a/src/Foundation/NSArray.cs +++ b/src/Foundation/NSArray.cs @@ -29,6 +29,20 @@ using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSArray { @@ -196,9 +210,9 @@ static public T [] FromArray (NSArray weakArray) where T : NSObject if (weakArray == null || weakArray.Handle == IntPtr.Zero) return null; try { - uint n = weakArray.Count; + NSUInteger n = weakArray.Count; T [] ret = new T [n]; - for (uint i = 0; i < n; i++){ + for (NSUInteger i = 0; i < n; i++){ ret [i] = (T) Runtime.GetNSObject (weakArray.ValueAt (i)); } return ret; diff --git a/src/foundation.cs b/src/foundation.cs index 8ea0845a..ce1db2ab 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -47,9 +47,23 @@ using System.Drawing; using System.ComponentModel; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { - public delegate int NSComparator (NSObject obj1, NSObject obj2); + public delegate NSInteger NSComparator (NSObject obj1, NSObject obj2); public delegate void NSAttributedRangeCallback (NSDictionary attrs, NSRange range, ref bool stop); public delegate void NSAttributedStringCallback (NSObject value, NSRange range, ref bool stop); @@ -58,13 +72,13 @@ namespace MonoMac.Foundation [BaseType (typeof (NSObject))] public interface NSArray { [Export ("count")] - uint Count { get; } + NSUInteger Count { get; } [Export ("objectAtIndex:")] - IntPtr ValueAt (uint idx); + IntPtr ValueAt (NSUInteger idx); [Export ("arrayWithObjects:count:")][Static][Internal] - NSArray FromObjects (IntPtr array, int count); + NSArray FromObjects (IntPtr array, NSUInteger count); [Export ("valueForKey:")] NSObject ValueForKey (NSString key); @@ -92,23 +106,23 @@ public partial interface NSAttributedString { string Value { get; } [Export ("attributesAtIndex:effectiveRange:")] - NSDictionary GetAttributes (int location, out NSRange effectiveRange); + NSDictionary GetAttributes (NSUInteger location, out NSRange effectiveRange); [Export ("length")] - int Length { get; } + NSUInteger Length { get; } // TODO: figure out the type, this deserves to be strongly typed if possble [Export ("attribute:atIndex:effectiveRange:")] - NSObject GetAttribute (string attribute, int location, out NSRange effectiveRange); + NSObject GetAttribute (string attribute, NSUInteger location, out NSRange effectiveRange); [Export ("attributedSubstringFromRange:"), Internal] NSAttributedString Substring (NSRange range); [Export ("attributesAtIndex:longestEffectiveRange:inRange:")] - NSDictionary GetAttributes (int location, out NSRange longestEffectiveRange, NSRange rangeLimit); + NSDictionary GetAttributes (NSUInteger location, out NSRange longestEffectiveRange, NSRange rangeLimit); [Export ("attribute:atIndex:longestEffectiveRange:inRange:")] - NSObject GetAttribute (string attribute, int location, out NSRange longestEffectiveRange, NSRange rangeLimit); + NSObject GetAttribute (string attribute, NSUInteger location, out NSRange longestEffectiveRange, NSRange rangeLimit); [Export ("isEqualToAttributedString:")] bool IsEqual (NSAttributedString other); @@ -131,7 +145,7 @@ public partial interface NSAttributedString { #if MONOMAC [Export("size")] - SizeF Size { get; } + NSSize Size { get; } [Field ("NSFontAttributeName", "AppKit")] NSString FontAttributeName { get; } @@ -215,34 +229,34 @@ public partial interface NSAttributedString { IntPtr Constructor (NSData htmlData, NSUrl baseUrl, out NSDictionary docAttributes); [Export ("drawAtPoint:")] - void DrawString (PointF point); + void DrawString (NSPoint point); [Export ("drawInRect:")] - void DrawString (RectangleF rect); + void DrawString (NSRect rect); [Export ("drawWithRect:options:")] - void DrawString (RectangleF rect, NSStringDrawingOptions options); + void DrawString (NSRect rect, NSStringDrawingOptions options); #else [Since (6,0)] [Export ("size")] - SizeF Size { get; } + NSSize Size { get; } [Since (6,0)] [Export ("drawAtPoint:")] - void DrawString (PointF point); + void DrawString (NSPoint point); [Since (6,0)] [Export ("drawInRect:")] - void DrawString (RectangleF rect); + void DrawString (NSRect rect); [Since (6,0)] [Export ("drawWithRect:options:context:")] - void DrawString (RectangleF rect, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context); + void DrawString (NSRect rect, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context); [Since (6,0)] [Export ("boundingRectWithSize:options:context:")] - RectangleF GetBoundingRect (SizeF size, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context); + NSRect GetBoundingRect (NSSize size, NSStringDrawingOptions options, [NullAllowed] NSStringDrawingContext context); #endif } From 6de5e396a80c8f5c712bf70c08144e8cd6990cd9 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Sat, 9 Mar 2013 10:03:59 -0800 Subject: [PATCH 10/21] NSCache, NSCalendarDate, NSData modified for 64 bit build --- src/Foundation/Enum.cs | 20 ++++++++++++++++++++ src/Foundation/NSData.cs | 24 +++++++++++++++++++----- src/Foundation/NSMutableData.cs | 18 ++++++++++++++++-- src/foundation.cs | 28 ++++++++++++++-------------- 4 files changed, 69 insertions(+), 21 deletions(-) diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index 705f2069..b2d9d4d3 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -132,7 +132,11 @@ public enum NSHttpCookieAcceptPolicy { } [Flags] +#if MAC64 + public enum NSCalendarUnit : ulong { +#else public enum NSCalendarUnit { +#endif Era = 2, Year = 4, Month = 8, @@ -159,7 +163,11 @@ public enum NSCalendarUnit { } [Flags] +#if MAC64 + public enum NSDataReadingOptions: ulong { +#else public enum NSDataReadingOptions: uint { +#endif Mapped = 1 << 0, Uncached = 1 << 1, @@ -209,7 +217,11 @@ public enum NSPostingStyle { } [Flags] +#if MAC64 + public enum NSDataSearchOptions : ulong { +#else public enum NSDataSearchOptions { +#endif SearchBackwards = 1, SearchAnchored = 2 } @@ -327,7 +339,11 @@ public enum NSComparisonPredicateModifier { Any } +#if MAC64 + public enum NSPredicateOperatorType : ulong { +#else public enum NSPredicateOperatorType { +#endif LessThan, LessThanOrEqualTo, GreaterThan, @@ -617,7 +633,11 @@ public enum NSLigatureType { None, Default, All } +#if MAC64 + public enum NSDateComponentsWrappingBehavior : ulong { +#else public enum NSDateComponentsWrappingBehavior { +#endif None = 0, WrapCalendarComponents = 1 << 0, } diff --git a/src/Foundation/NSData.cs b/src/Foundation/NSData.cs index e38bf9cc..2ac9b030 100644 --- a/src/Foundation/NSData.cs +++ b/src/Foundation/NSData.cs @@ -33,6 +33,20 @@ using System.Collections; using System.Collections.Generic; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSData : IEnumerable, IEnumerable { @@ -100,7 +114,7 @@ public static NSData FromStream (Stream stream) } catch { len = 8192; } - ret = NSMutableData.FromCapacity ((int)len); + ret = NSMutableData.FromCapacity ((NSUInteger)len); byte [] buffer = new byte [32*1024]; int n; try { @@ -122,7 +136,7 @@ public static NSData FromStream (Stream stream) unsafe class UnmanagedMemoryStreamWithRef : UnmanagedMemoryStream { NSData source; - public UnmanagedMemoryStreamWithRef (NSData source) : base ((byte *)source.Bytes, source.Length) + public UnmanagedMemoryStreamWithRef (NSData source) : base ((byte *)source.Bytes, (long)source.Length) { this.source = source; } @@ -226,7 +240,7 @@ public bool Save (string file, bool auxiliaryFile, out NSError error) IntPtr val; IntPtr val_addr = (IntPtr) ((IntPtr *) &val); - bool ret = _Save (file, auxiliaryFile ? 1 : 0, val_addr); + bool ret = _Save (file, (NSUInteger)(auxiliaryFile ? 1 : 0), val_addr); error = (NSError) Runtime.GetNSObject (val); return ret; @@ -239,7 +253,7 @@ public bool Save (string file, NSDataWritingOptions options, out NSError error) IntPtr val; IntPtr val_addr = (IntPtr) ((IntPtr *) &val); - bool ret = _Save (file, (int) options, val_addr); + bool ret = _Save (file, (NSUInteger) options, val_addr); error = (NSError) Runtime.GetNSObject (val); return ret; @@ -252,7 +266,7 @@ public bool Save (NSUrl url, bool auxiliaryFile, out NSError error) IntPtr val; IntPtr val_addr = (IntPtr) ((IntPtr *) &val); - bool ret = _Save (url, auxiliaryFile ? 1 : 0, val_addr); + bool ret = _Save (url, (NSUInteger)(auxiliaryFile ? 1 : 0), val_addr); error = (NSError) Runtime.GetNSObject (val); return ret; diff --git a/src/Foundation/NSMutableData.cs b/src/Foundation/NSMutableData.cs index dfa42721..6623f367 100644 --- a/src/Foundation/NSMutableData.cs +++ b/src/Foundation/NSMutableData.cs @@ -10,6 +10,20 @@ using System.Collections; using System.Collections.Generic; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSMutableData : IEnumerable, IEnumerable { @@ -56,7 +70,7 @@ IEnumerator IEnumerable.GetEnumerator () int top = (int) Length; for (int i = 0; i < top; i++){ - if (source == Bytes && top == Length) + if (source == Bytes && top == (int)Length) yield return Marshal.ReadByte (source, i); else throw new InvalidOperationException ("The NSMutableData has changed"); @@ -69,7 +83,7 @@ IEnumerator IEnumerable.GetEnumerator () int top = (int) Length; for (int i = 0; i < top; i++){ - if (source == Bytes && top == Length) + if (source == Bytes && top == (int)Length) yield return Marshal.ReadByte (source, i); else throw new InvalidOperationException ("The NSMutableData has changed"); diff --git a/src/foundation.cs b/src/foundation.cs index ce1db2ab..1bb78f33 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -272,7 +272,7 @@ public interface NSCache { void SetObjectforKey (NSObject obj, NSObject key); [Export ("setObject:forKey:cost:")] - void SetCost (NSObject obj, NSObject key, uint cost); + void SetCost (NSObject obj, NSObject key, NSUInteger cost); [Export ("removeObjectForKey:")] void RemoveObjectForKey (NSObject key); @@ -291,10 +291,10 @@ public interface NSCache { NSCacheDelegate Delegate { get; set; } [Export ("totalCostLimit")] - uint TotalCostLimit { get; set; } + NSUInteger TotalCostLimit { get; set; } [Export ("countLimit")] - uint CountLimit { get; set; } + NSUInteger CountLimit { get; set; } [Export ("evictsObjectsWithDiscardedContent")] bool EvictsObjectsWithDiscardedContent { get; set; } @@ -350,10 +350,10 @@ public interface NSCalendar { NSTimeZone TimeZone { get; set; } [Export ("firstWeekday")] - uint FirstWeekDay { get; set; } + NSUInteger FirstWeekDay { get; set; } [Export ("minimumDaysInFirstWeek")] - uint MinimumDaysInFirstWeek { get; set; } + NSUInteger MinimumDaysInFirstWeek { get; set; } //- (NSRange)minimumRangeOfUnit:(NSCalendarUnit)unit; //- (NSRange)maximumRangeOfUnit:(NSCalendarUnit)unit; @@ -646,19 +646,19 @@ public interface NSData { NSData FromData (NSData source); [Export ("dataWithBytes:length:"), Static] - NSData FromBytes (IntPtr bytes, uint size); + NSData FromBytes (IntPtr bytes, NSUInteger size); [Export ("bytes")] IntPtr Bytes { get; } [Export ("length")] - uint Length { get; [NotImplemented] set; } + NSUInteger Length { get; [NotImplemented] set; } [Export ("writeToFile:options:error:")] - bool _Save (string file, int options, IntPtr addr); + bool _Save (string file, NSUInteger options, IntPtr addr); [Export ("writeToURL:options:error:")] - bool _Save (NSUrl url, int options, IntPtr addr); + bool _Save (NSUrl url, NSUInteger options, IntPtr addr); [Export ("rangeOfData:options:range:")] [Since (4,0)] @@ -1460,16 +1460,16 @@ public interface NSMutableAttributedString { [BaseType (typeof (NSData))] public interface NSMutableData { [Static, Export ("dataWithCapacity:")] - NSMutableData FromCapacity (int capacity); + NSMutableData FromCapacity (NSUInteger capacity); [Static, Export ("dataWithLength:")] - NSMutableData FromLength (int length); + NSMutableData FromLength (NSUInteger length); [Static, Export ("data")] NSMutableData Create (); [Export ("setLength:")] - void SetLength (uint len); + void SetLength (NSUInteger len); [Export ("mutableBytes")] IntPtr MutableBytes { get; } @@ -1481,14 +1481,14 @@ public interface NSMutableData { void AppendData (NSData other); [Export ("appendBytes:length:")] - void AppendBytes (IntPtr bytes, uint len); + void AppendBytes (IntPtr bytes, NSUInteger len); [Export ("setData:")] void SetData (NSData data); [Export ("length")] [Override] - uint Length { get; set; } + NSUInteger Length { get; set; } } [BaseType (typeof (NSObject))] From 6ee26b6c82121eae1fc07f5959c838ab70628cbf Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Sat, 9 Mar 2013 10:18:34 -0800 Subject: [PATCH 11/21] 64bit updates to foundation classes --- src/Foundation/Enum.cs | 12 ++++++++++++ src/foundation.cs | 40 ++++++++++++++++++++-------------------- 2 files changed, 32 insertions(+), 20 deletions(-) diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index b2d9d4d3..022e5644 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -73,7 +73,11 @@ public enum NSStreamStatus { Error = 7 } +#if MAC64 + public enum NSPropertyListFormat : ulong { +#else public enum NSPropertyListFormat { +#endif OpenStep = 1, Xml = 100, Binary = 200 @@ -595,7 +599,11 @@ public enum NSWritingDirection { } [Flags] +#if MAC64 + public enum NSByteCountFormatterUnits : ulong { +#else public enum NSByteCountFormatterUnits { +#endif UseDefault = 0, UseBytes = 1 << 0, UseKB = 1 << 1, @@ -609,7 +617,11 @@ public enum NSByteCountFormatterUnits { UseAll = 0x0FFFF } +#if MAC64 + public enum NSByteCountFormatterCountStyle : long { +#else public enum NSByteCountFormatterCountStyle { +#endif File, Memory, Decimal, Binary } diff --git a/src/foundation.cs b/src/foundation.cs index 1bb78f33..30d3d4db 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -677,7 +677,7 @@ public interface NSDateComponents { [Export ("quarter")] [Since (4,0)] - int Quarter { get; set; } + NSInteger Quarter { get; set; } [Export ("date")] [Since (4,0)] @@ -685,46 +685,46 @@ public interface NSDateComponents { //Detected properties [Export ("era")] - int Era { get; set; } + NSInteger Era { get; set; } [Export ("year")] - int Year { get; set; } + NSInteger Year { get; set; } [Export ("month")] - int Month { get; set; } + NSInteger Month { get; set; } [Export ("day")] - int Day { get; set; } + NSInteger Day { get; set; } [Export ("hour")] - int Hour { get; set; } + NSInteger Hour { get; set; } [Export ("minute")] - int Minute { get; set; } + NSInteger Minute { get; set; } [Export ("second")] - int Second { get; set; } + NSInteger Second { get; set; } [Export ("week")] - int Week { get; set; } + NSInteger Week { get; set; } [Export ("weekday")] - int Weekday { get; set; } + NSInteger Weekday { get; set; } [Export ("weekdayOrdinal")] - int WeekdayOrdinal { get; set; } + NSInteger WeekdayOrdinal { get; set; } [Since (5,0)] [Export ("weekOfMonth")] - int WeekOfMonth { get; set; } + NSInteger WeekOfMonth { get; set; } [Since (5,0)] [Export ("weekOfYear")] - int WeekOfYear { get; set; } + NSInteger WeekOfYear { get; set; } [Since (5,0)] [Export ("yearForWeekOfYear")] - int YearForWeekOfYear { get; set; } + NSInteger YearForWeekOfYear { get; set; } [Since (6,0)] [Export ("leapMonth")] @@ -904,7 +904,7 @@ public interface NSFileHandle NSData ReadDataToEndOfFile (); [Export ("readDataOfLength:")] - NSData ReadDataOfLength (uint length); + NSData ReadDataOfLength (NSUInteger length); [Export ("writeData:")] void WriteData (NSData data); @@ -1185,16 +1185,16 @@ public interface NSMetadataQuery { void EnableUpdates (); [Export ("resultCount")] - int ResultCount { get; } + NSUInteger ResultCount { get; } [Export ("resultAtIndex:")] - NSObject ResultAtIndex (int idx); + NSObject ResultAtIndex (NSUInteger idx); [Export ("results")] NSMetadataItem[] Results { get; } [Export ("indexOfResult:")] - int IndexOfResult (NSObject result); + NSUInteger IndexOfResult (NSObject result); [Export ("valueLists")] NSDictionary ValueLists { get; } @@ -1203,7 +1203,7 @@ public interface NSMetadataQuery { NSObject [] GroupedResults { get; } [Export ("valueOfAttribute:forResultAtIndex:")] - NSObject ValueOfAttribute (string attribyteName, int atIndex); + NSObject ValueOfAttribute (string attribyteName, NSUInteger atIndex); [Export ("delegate", ArgumentSemantic.Assign), NullAllowed] NSMetadataQueryDelegate WeakDelegate { get; set; } @@ -1346,7 +1346,7 @@ public interface NSMetadataQueryAttributeValueTuple { NSObject Value { get; } [Export ("count")] - int Count { get; } + NSUInteger Count { get; } } [BaseType (typeof (NSObject))] From ae4676071601babfc40906970281f7883cf0d0c1 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Sat, 9 Mar 2013 10:27:55 -0800 Subject: [PATCH 12/21] 64 bit modifications for foundation classes --- src/Foundation/NSDictionary.cs | 18 ++++++++++++++++-- src/Foundation/NSMutableDictionary.cs | 16 +++++++++++++++- src/foundation.cs | 26 +++++++++++++------------- 3 files changed, 44 insertions(+), 16 deletions(-) diff --git a/src/Foundation/NSDictionary.cs b/src/Foundation/NSDictionary.cs index 50c149be..d6d62cd3 100644 --- a/src/Foundation/NSDictionary.cs +++ b/src/Foundation/NSDictionary.cs @@ -26,6 +26,20 @@ using System.Collections.Generic; using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSDictionary : IDictionary, IDictionary { @@ -156,7 +170,7 @@ void ICollection.CopyTo (Array array, int arrayIndex) throw new ArgumentException ("array is multidimensional"); if ((array.Length > 0) && (arrayIndex >= array.Length)) throw new ArgumentException ("arrayIndex is equal to or greater than array.Length"); - if (arrayIndex + Count > array.Length) + if (arrayIndex + (int)Count > array.Length) throw new ArgumentException ("Not enough room from arrayIndex to end of array for this Hashtable"); IDictionaryEnumerator e = ((IDictionary) this).GetEnumerator (); int i = arrayIndex; @@ -202,7 +216,7 @@ void ICollection>.CopyTo (KeyValuePair array.Length) throw new ArgumentException ("index larger than largest valid index of array"); - if (array.Length - index < Count) + if (array.Length - index < (int)Count) throw new ArgumentException ("Destination array cannot hold the requested elements!"); var e = GetEnumerator (); diff --git a/src/Foundation/NSMutableDictionary.cs b/src/Foundation/NSMutableDictionary.cs index 596dbd82..0ac96695 100644 --- a/src/Foundation/NSMutableDictionary.cs +++ b/src/Foundation/NSMutableDictionary.cs @@ -25,6 +25,20 @@ using System.Collections.Generic; using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSMutableDictionary : IDictionary, IDictionary { @@ -117,7 +131,7 @@ void ICollection>.CopyTo (KeyValuePair array.Length) throw new ArgumentException ("index larger than largest valid index of array"); - if (array.Length - index < Count) + if (array.Length - index < (int)Count) throw new ArgumentException ("Destination array cannot hold the requested elements!"); var e = GetEnumerator (); diff --git a/src/foundation.cs b/src/foundation.cs index 30d3d4db..cc7a130f 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -1361,10 +1361,10 @@ public interface NSMetadataQueryResultGroup { NSObject [] Subgroups { get; } [Export ("resultCount")] - int ResultCount { get; } + NSUInteger ResultCount { get; } [Export ("resultAtIndex:")] - NSObject ResultAtIndex (uint idx); + NSObject ResultAtIndex (NSUInteger idx); [Export ("results")] NSObject [] Results { get; } @@ -1378,22 +1378,22 @@ public interface NSMetadataQueryResultGroup { [BaseType (typeof (NSArray))] public interface NSMutableArray { [Export ("initWithCapacity:")] - IntPtr Constructor (int capacity); + IntPtr Constructor (NSUInteger capacity); [Export ("addObject:")] void Add (NSObject obj); [Export ("insertObject:atIndex:")] - void Insert (NSObject obj, int index); + void Insert (NSObject obj, NSUInteger index); [Export ("removeLastObject")] void RemoveLastObject (); [Export ("removeObjectAtIndex:")] - void RemoveObject (int index); + void RemoveObject (NSUInteger index); [Export ("replaceObjectAtIndex:withObject:")] - void ReplaceObject (int index, NSObject withObject); + void ReplaceObject (NSUInteger index, NSObject withObject); [Export ("removeAllObjects")] void RemoveAllObjects (); @@ -1439,7 +1439,7 @@ public interface NSMutableAttributedString { void Replace (NSRange range, NSAttributedString value); [Export ("insertAttributedString:atIndex:")] - void Insert (NSAttributedString attrString, int location); + void Insert (NSAttributedString attrString, NSUInteger location); [Export ("appendAttributedString:")] void Append (NSAttributedString attrString); @@ -1475,7 +1475,7 @@ public interface NSMutableData { IntPtr MutableBytes { get; } [Export ("initWithCapacity:")] - IntPtr Constructor (uint len); + IntPtr Constructor (NSUInteger len); [Export ("appendData:")] void AppendData (NSData other); @@ -1543,7 +1543,7 @@ public interface NSDictionary { [Export ("dictionaryWithObjects:forKeys:count:")] [Static, Internal] - NSDictionary FromObjectsAndKeysInternal ([NullAllowed] NSArray objects, [NullAllowed] NSArray keys, int count); + NSDictionary FromObjectsAndKeysInternal ([NullAllowed] NSArray objects, [NullAllowed] NSArray keys, NSUInteger count); [Export ("dictionaryWithObjects:forKeys:")] [Static, Internal] @@ -1562,7 +1562,7 @@ public interface NSDictionary { IntPtr Constructor (NSUrl url); [Export ("count")] - uint Count { get; } + NSUInteger Count { get; } [Export ("objectForKey:")] NSObject ObjectForKey (NSObject key); @@ -1611,16 +1611,16 @@ public interface NSEnumerator { [DisableDefaultCtor] public interface NSError { [Static, Export ("errorWithDomain:code:userInfo:")] - NSError FromDomain (NSString domain, int code, [NullAllowed] NSDictionary userInfo); + NSError FromDomain (NSString domain, NSInteger code, [NullAllowed] NSDictionary userInfo); [Export ("initWithDomain:code:userInfo:")] - IntPtr Constructor (NSString domain, int code, [NullAllowed] NSDictionary userInfo); + IntPtr Constructor (NSString domain, NSInteger code, [NullAllowed] NSDictionary userInfo); [Export ("domain")] string Domain { get; } [Export ("code")] - int Code { get; } + NSInteger Code { get; } [Export ("userInfo")] NSDictionary UserInfo { get; } From 5175dabe0afe0b65feb732a682d45f6cea311696 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Tue, 12 Mar 2013 22:03:50 -0700 Subject: [PATCH 13/21] Making foundation generated classes 64bit compatible --- src/Foundation/Enum.cs | 32 ++++++++++ src/Foundation/NSIndexPath.cs | 23 +++++-- src/Foundation/NSIndexSet.cs | 30 ++++++--- src/Foundation/NSInputStream.cs | 31 +++++++-- src/Foundation/NSString2.cs | 15 ++++- src/foundation.cs | 110 ++++++++++++++++---------------- 6 files changed, 165 insertions(+), 76 deletions(-) diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index 022e5644..72756c38 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -40,13 +40,21 @@ public enum NSBundleExecutableArchitecture { PPC64 = 0x01000012 } +#if MAC64 + public enum NSComparisonResult : long { +#else public enum NSComparisonResult { +#endif Ascending = -1, Same, Descending } +#if MAC64 + public enum NSUrlRequestCachePolicy : ulong { +#else public enum NSUrlRequestCachePolicy { +#endif UseProtocolCachePolicy = 0, ReloadIgnoringLocalCacheData = 1, ReloadIgnoringLocalAndRemoteCacheData = 4, // Unimplemented @@ -455,7 +463,11 @@ public enum NSCalculationError { None, PrecisionLoss, Underflow, Overflow, DivideByZero } +#if MAC64 + public enum NSStringDrawingOptions : long { +#else public enum NSStringDrawingOptions : uint { +#endif UsesLineFragmentOrigin = (1 << 0), UsesFontLeading = (1 << 1), DisableScreenFontSubstitution = (1 << 2), @@ -510,7 +522,11 @@ public enum NSFileCoordinatorWritingOptions { } [Flags] +#if MAC64 + public enum NSLinguisticTaggerOptions : ulong { +#else public enum NSLinguisticTaggerOptions { +#endif OmitWords = 1, OmitPunctuation = 2, OmitWhitespace = 4, @@ -523,18 +539,30 @@ public enum NSUbiquitousKeyValueStoreChangeReason { } [Flags] +#if MAC64 + public enum NSJsonReadingOptions : ulong { +#else public enum NSJsonReadingOptions { +#endif MutableContainers = 1, MutableLeaves = 2, AllowFragments = 4 } [Flags] +#if MAC64 + public enum NSJsonWritingOptions : ulong { +#else public enum NSJsonWritingOptions { +#endif PrettyPrinted = 1 } +#if MAC64 + public enum NSLocaleLanguageDirection : ulong { +#else public enum NSLocaleLanguageDirection { +#endif Unknown, LeftToRight, RightToLeft, TopToBottom, BottomToTop, } @@ -654,7 +682,11 @@ public enum NSDateComponentsWrappingBehavior { WrapCalendarComponents = 1 << 0, } +#if MAC64 + public enum NSUrlRequestNetworkServiceType : ulong { +#else public enum NSUrlRequestNetworkServiceType { +#endif Default, VoIP, Video, diff --git a/src/Foundation/NSIndexPath.cs b/src/Foundation/NSIndexPath.cs index fbd8e9d1..501ae387 100644 --- a/src/Foundation/NSIndexPath.cs +++ b/src/Foundation/NSIndexPath.cs @@ -13,6 +13,19 @@ using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + namespace MonoMac.Foundation { public partial class NSIndexPath { @@ -25,7 +38,7 @@ public NSIndexPath FromIndexes (uint [] indexes) IntPtr buf = Marshal.AllocHGlobal (4 * indexes.Length); for (int i = 0; i < indexes.Length; i++) Marshal.WriteInt32 (buf, i * 4, (int) indexes [i]); - NSIndexPath ret = _FromIndex (buf, indexes.Length); + NSIndexPath ret = _FromIndex (buf, (NSUInteger)indexes.Length); Marshal.FreeHGlobal (buf); return ret; } @@ -39,7 +52,7 @@ public static NSIndexPath Create (params int [] indexes) for (int i = 0; i < indexes.Length; i++) Marshal.WriteInt32 (buf, i * 4, indexes [i]); - NSIndexPath ret = _FromIndex (buf, indexes.Length); + NSIndexPath ret = _FromIndex (buf, (NSUInteger)indexes.Length); Marshal.FreeHGlobal (buf); return ret; } @@ -53,14 +66,14 @@ public static NSIndexPath Create (params uint [] indexes) for (int i = 0; i < indexes.Length; i++) Marshal.WriteInt32 (buf, i * 4, (int) indexes [i]); - NSIndexPath ret = _FromIndex (buf, indexes.Length); + NSIndexPath ret = _FromIndex (buf, (NSUInteger)indexes.Length); Marshal.FreeHGlobal (buf); return ret; } public uint [] GetIndexes () { - int n = Length; + int n = (int)Length; IntPtr buf = Marshal.AllocHGlobal (4 * n); uint [] ret = new uint [n]; for (int i = 0; i < n; i++) @@ -85,7 +98,7 @@ public override bool Equals (object obj) public override int GetHashCode () { - return Length; + return (int)Length; } } } diff --git a/src/Foundation/NSIndexSet.cs b/src/Foundation/NSIndexSet.cs index a15a83d0..befae519 100644 --- a/src/Foundation/NSIndexSet.cs +++ b/src/Foundation/NSIndexSet.cs @@ -29,37 +29,51 @@ using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { - public partial class NSIndexSet : IEnumerable, IEnumerable { + public partial class NSIndexSet : IEnumerable, IEnumerable { IEnumerator IEnumerable.GetEnumerator () { - for (uint i = this.FirstIndex; i <= this.LastIndex;) { + for (NSUInteger i = this.FirstIndex; i <= this.LastIndex;) { yield return i; i = this.IndexGreaterThan (i); } } - public IEnumerator GetEnumerator () + public IEnumerator GetEnumerator () { - for (uint i = this.FirstIndex; i <= this.LastIndex;) { + for (NSUInteger i = this.FirstIndex; i <= this.LastIndex;) { yield return i; i = this.IndexGreaterThan (i); } } - public uint[] ToArray () + public NSUInteger[] ToArray () { - uint [] indexes = new uint [Count]; + NSUInteger [] indexes = new NSUInteger [Count]; int j = 0; - for (uint i = this.FirstIndex; i <= this.LastIndex;) { + for (NSUInteger i = this.FirstIndex; i <= this.LastIndex;) { indexes [j++] = i; i = this.IndexGreaterThan (i); } return indexes; } - public static NSIndexSet FromArray (uint[] items) + public static NSIndexSet FromArray (NSUInteger[] items) { if (items == null) return new NSIndexSet (); diff --git a/src/Foundation/NSInputStream.cs b/src/Foundation/NSInputStream.cs index f62b52c4..93a0c90e 100644 --- a/src/Foundation/NSInputStream.cs +++ b/src/Foundation/NSInputStream.cs @@ -25,6 +25,20 @@ using MonoMac.Foundation; using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public partial class NSInputStream : NSStream { const string selReadMaxLength = "read:maxLength:"; @@ -33,26 +47,29 @@ public partial class NSInputStream : NSStream { IntPtr callback; CFStreamClientContext context; - public int Read (byte [] buffer, uint len) { + public NSInteger Read (byte [] buffer, NSUInteger len) { return objc_msgSend (Handle, Selector.GetHandle (selReadMaxLength), buffer, len); } [DllImport ("/usr/lib/libobjc.dylib")] - static extern int objc_msgSend (IntPtr handle, IntPtr sel, [In, Out] byte [] buffer, uint len); + static extern NSInteger objc_msgSend (IntPtr handle, IntPtr sel, [In, Out] byte [] buffer, NSUInteger len); + + [DllImport ("/usr/lib/libobjc.dylib")] + static extern NSInteger objc_msgSend (IntPtr handle, IntPtr sel, IntPtr buffer, NSUInteger len); [Export ("read:maxLength:")] - public virtual int Read (IntPtr buffer, uint len) + public virtual NSInteger Read (IntPtr buffer, NSUInteger len) { if (buffer == IntPtr.Zero) throw new ArgumentNullException ("buffer"); - int ret; + NSInteger ret; if (IsDirectBinding) { - ret = Messaging.int_objc_msgSend_IntPtr_UInt32 (this.Handle, Selector.GetHandle (selReadMaxLength), buffer, len); + ret = objc_msgSend (this.Handle, Selector.GetHandle (selReadMaxLength), buffer, len); } else { - ret = Messaging.int_objc_msgSendSuper_IntPtr_UInt32 (this.SuperHandle, Selector.GetHandle (selReadMaxLength), buffer, len); + ret = objc_msgSend (this.SuperHandle, Selector.GetHandle (selReadMaxLength), buffer, len); } - + return ret; } diff --git a/src/Foundation/NSString2.cs b/src/Foundation/NSString2.cs index 55f0b64e..ce9bb865 100644 --- a/src/Foundation/NSString2.cs +++ b/src/Foundation/NSString2.cs @@ -30,6 +30,19 @@ using MonoMac.ObjCRuntime; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + namespace MonoMac.Foundation { public partial class NSString { @@ -107,7 +120,7 @@ public static NSString FromData (NSData data, NSStringEncoding encoding) public char this [int idx] { get { - return _characterAtIndex (idx); + return _characterAtIndex ((NSUInteger)idx); } } } diff --git a/src/foundation.cs b/src/foundation.cs index cc7a130f..f111e45d 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -1799,10 +1799,10 @@ interface NSLinguisticTagger { void SetOrthographyrange (NSOrthography orthography, NSRange range); [Export ("orthographyAtIndex:effectiveRange:")] - NSOrthography GetOrthography (int charIndex, ref NSRange effectiveRange); + NSOrthography GetOrthography (NSUInteger charIndex, ref NSRange effectiveRange); [Export ("stringEditedInRange:changeInLength:")] - void StringEditedInRange (NSRange newRange, int delta); + void StringEditedInRange (NSRange newRange, NSInteger delta); [Export ("enumerateTagsInRange:scheme:options:usingBlock:")] void EnumerateTagsInRange (NSRange range, NSString tagScheme, NSLinguisticTaggerOptions opts, NSLingusticEnumerator enumerator); @@ -1811,13 +1811,13 @@ interface NSLinguisticTagger { NSRange GetSentenceRangeForRange (NSRange range); [Export ("tagAtIndex:scheme:tokenRange:sentenceRange:")] - string GetTag (int charIndex, NSString tagScheme, ref NSRange tokenRange, ref NSRange sentenceRange); + string GetTag (NSUInteger charIndex, NSString tagScheme, ref NSRange tokenRange, ref NSRange sentenceRange); [Export ("tagsInRange:scheme:options:tokenRanges:"), Internal] NSString [] GetTagsInRange (NSRange range, NSString tagScheme, NSLinguisticTaggerOptions opts, ref NSArray tokenRanges); [Export ("possibleTagsAtIndex:scheme:tokenRange:sentenceRange:scores:"), Internal] - NSString [] GetPossibleTags (int charIndex, NSString tagScheme, ref NSRange tokenRange, ref NSRange sentenceRange, ref NSArray scores); + NSString [] GetPossibleTags (NSUInteger charIndex, NSString tagScheme, ref NSRange tokenRange, ref NSRange sentenceRange, ref NSArray scores); //Detected properties [Export ("string")] @@ -2136,7 +2136,7 @@ public interface NSSet { IntPtr Constructor (NSArray other); [Export ("count")] - uint Count { get; } + NSUInteger Count { get; } [Export ("anyObject")] NSObject AnyObject { get; } @@ -2246,7 +2246,7 @@ public interface NSTimeZone { NSData Data { get; } [Export ("secondsFromGMTForDate:")] - int SecondsFromGMT (NSDate date); + NSInteger SecondsFromGMT (NSDate date); [Export ("abbreviationForDate:")] string Abbreviation (NSDate date); @@ -2270,7 +2270,7 @@ public interface NSTimeZone { NSTimeZone LocalTimeZone { get; } [Export ("secondsFromGMT")] - int GetSecondsFromGMT { get; } + NSInteger GetSecondsFromGMT { get; } [Export ("defaultTimeZone"), Static] NSTimeZone DefaultTimeZone { get; set; } @@ -2953,7 +2953,7 @@ public interface NSUrlCache { NSUrlCache SharedCache { get; set; } [Export ("initWithMemoryCapacity:diskCapacity:diskPath:")] - IntPtr Constructor (uint memoryCapacity, uint diskCapacity, string diskPath); + IntPtr Constructor (NSUInteger memoryCapacity, NSUInteger diskCapacity, string diskPath); [Export ("cachedResponseForRequest:")] NSCachedUrlResponse CachedResponseForRequest (NSUrlRequest request); @@ -2968,16 +2968,16 @@ public interface NSUrlCache { void RemoveAllCachedResponses (); [Export ("memoryCapacity")] - uint MemoryCapacity { get; set; } + NSUInteger MemoryCapacity { get; set; } [Export ("diskCapacity")] - uint DiskCapacity { get; set; } + NSUInteger DiskCapacity { get; set; } [Export ("currentMemoryUsage")] - uint CurrentMemoryUsage { get; } + NSUInteger CurrentMemoryUsage { get; } [Export ("currentDiskUsage")] - uint CurrentDiskUsage { get; } + NSUInteger CurrentDiskUsage { get; } } [BaseType (typeof (NSObject), Name="NSURLAuthenticationChallenge")] @@ -2985,7 +2985,7 @@ public interface NSUrlCache { [DisableDefaultCtor] public interface NSUrlAuthenticationChallenge { [Export ("initWithProtectionSpace:proposedCredential:previousFailureCount:failureResponse:error:sender:")] - IntPtr Constructor (NSUrlProtectionSpace space, NSUrlCredential credential, int previousFailureCount, NSUrlResponse response, [NullAllowed] NSError error, NSUrlConnection sender); + IntPtr Constructor (NSUrlProtectionSpace space, NSUrlCredential credential, NSInteger previousFailureCount, NSUrlResponse response, [NullAllowed] NSError error, NSUrlConnection sender); [Export ("initWithAuthenticationChallenge:sender:")] IntPtr Constructor (NSUrlAuthenticationChallenge challenge, NSUrlConnection sender); @@ -2997,7 +2997,7 @@ public interface NSUrlAuthenticationChallenge { NSUrlCredential ProposedCredential { get; } [Export ("previousFailureCount")] - int PreviousFailureCount { get; } + NSInteger PreviousFailureCount { get; } [Export ("failureResponse")] NSUrlResponse FailureResponse { get; } @@ -3108,7 +3108,7 @@ public interface NSUrlConnectionDelegate { void ReceivedData (NSUrlConnection connection, NSData data); [Export ("connection:didSendBodyData:totalBytesWritten:totalBytesExpectedToWrite:")] - void SentBodyData (NSUrlConnection connection, int bytesWritten, int totalBytesWritten, int totalBytesExpectedToWrite); + void SentBodyData (NSUrlConnection connection, NSInteger bytesWritten, NSInteger totalBytesWritten, NSInteger totalBytesExpectedToWrite); [Export ("connectionDidFinishLoading:")] void FinishedLoading (NSUrlConnection connection); @@ -3222,7 +3222,7 @@ public interface NSUndoManager { void EndUndoGrouping (); [Export ("groupingLevel")] - int GroupingLevel { get; } + NSInteger GroupingLevel { get; } [Export ("disableUndoRegistration")] void DisableUndoRegistration (); @@ -3237,7 +3237,7 @@ public interface NSUndoManager { bool GroupsByEvent { get; set; } [Export ("levelsOfUndo")] - int LevelsOfUndo { get; set; } + NSInteger LevelsOfUndo { get; set; } [Export ("runLoopModes")] string [] RunLoopModes { get; set; } @@ -3350,7 +3350,7 @@ public interface NSUndoManager { public interface NSUrlProtectionSpace { [Export ("initWithHost:port:protocol:realm:authenticationMethod:")] - IntPtr Constructor (string host, int port, string protocol, string realm, string authenticationMethod); + IntPtr Constructor (string host, NSInteger port, string protocol, string realm, string authenticationMethod); //[Export ("initWithProxyHost:port:type:realm:authenticationMethod:")] //IntPtr Constructor (string host, int port, string type, string realm, string authenticationMethod); @@ -3368,7 +3368,7 @@ public interface NSUrlProtectionSpace { string Host { get; } [Export ("port")] - int Port { get; } + NSInteger Port { get; } [Export ("proxyType")] string ProxyType { get; } @@ -3496,7 +3496,7 @@ public interface NSMutableDictionary { [Export ("dictionaryWithObjects:forKeys:count:")] [Static, Internal] - NSMutableDictionary FromObjectsAndKeysInternalCount (NSArray objects, NSArray keys, int count); + NSMutableDictionary FromObjectsAndKeysInternalCount (NSArray objects, NSArray keys, NSUInteger count); [Export ("dictionaryWithObjects:forKeys:")] [Static, Internal, New] @@ -3535,7 +3535,7 @@ public interface NSMutableSet { IntPtr Constructor (NSSet other); [Export ("initWithCapacity:")] - IntPtr Constructor (int capacity); + IntPtr Constructor (NSUInteger capacity); [Export ("addObject:")] void Add (NSObject nso); @@ -3601,7 +3601,7 @@ [New] [Export ("allowsCellularAccess")] [BaseType (typeof (NSObject), Name="NSURLResponse")] public interface NSUrlResponse { [Export ("initWithURL:MIMEType:expectedContentLength:textEncodingName:")] - IntPtr Constructor (NSUrl url, string mimetype, int expectedContentLength, [NullAllowed] string textEncodingName); + IntPtr Constructor (NSUrl url, string mimetype, NSInteger expectedContentLength, [NullAllowed] string textEncodingName); [Export ("URL")] NSUrl Url { get; } @@ -3736,16 +3736,16 @@ public interface NSString2 { SizeF StringSize ([NullAllowed] NSDictionary attributedStringAttributes); [Bind ("boundingRectWithSize:options:attributes:")] - RectangleF BoundingRectWithSize (SizeF size, NSStringDrawingOptions options, NSDictionary attributes); + NSRect BoundingRectWithSize (NSSize size, NSStringDrawingOptions options, NSDictionary attributes); [Bind ("drawAtPoint:withAttributes:")] void DrawString (PointF point, NSDictionary attributes); [Bind ("drawInRect:withAttributes:")] - void DrawString (RectangleF rect, NSDictionary attributes); + void DrawString (NSRect rect, NSDictionary attributes); [Bind ("drawWithRect:options:attributes:")] - void DrawString (RectangleF rect, NSStringDrawingOptions options, NSDictionary attributes); + void DrawString (NSRect rect, NSStringDrawingOptions options, NSDictionary attributes); #else [Bind ("sizeWithFont:")] SizeF StringSize (UIFont font); @@ -3784,13 +3784,13 @@ public interface NSString2 { SizeF DrawString (RectangleF rect, UIFont font, UILineBreakMode mode, UITextAlignment alignment); #endif [Export ("characterAtIndex:")] - char _characterAtIndex (int index); + char _characterAtIndex (NSUInteger index); [Export ("length")] - int Length {get;} + NSUInteger Length {get;} [Export ("hash"), Internal] - int Hash (); + NSUInteger Hash (); [Export ("isEqualToString:"), Internal] bool IsEqualTo (IntPtr handle); @@ -4151,7 +4151,7 @@ public interface NSOperationQueue { NSOperation [] Operations { get; } [Export ("operationCount")] - int OperationCount { get; } + NSUInteger OperationCount { get; } [Export ("name")] string Name { get; set; } @@ -4172,7 +4172,7 @@ public interface NSOperationQueue { //Detected properties [Export ("maxConcurrentOperationCount")] - int MaxConcurrentOperationCount { get; set; } + NSInteger MaxConcurrentOperationCount { get; set; } [Export ("suspended")] bool Suspended { [Bind ("isSuspended")]get; set; } @@ -4255,7 +4255,7 @@ public interface NSHttpCookie { NSDictionary Properties { get; } [Export ("version")] - uint Version { get; } + NSUInteger Version { get; } [Export ("value")] string Value { get; } @@ -4325,16 +4325,16 @@ public interface NSHttpCookieStorage { public interface NSHttpUrlResponse { [Since (5,0)] [Export ("initWithURL:statusCode:HTTPVersion:headerFields:")] - IntPtr Constructor (NSUrl url, int statusCode, string httpVersion, NSDictionary headerFields); + IntPtr Constructor (NSUrl url, NSInteger statusCode, string httpVersion, NSDictionary headerFields); [Export ("statusCode")] - int StatusCode { get; } + NSInteger StatusCode { get; } [Export ("allHeaderFields")] NSDictionary AllHeaderFields { get; } [Export ("localizedStringForStatusCode:")][Static] - string LocalizedStringForStatusCode (int statusCode); + string LocalizedStringForStatusCode (NSInteger statusCode); } [BaseType (typeof (NSObject))] @@ -4502,28 +4502,28 @@ public partial interface NSBundle { [BaseType (typeof (NSObject))] public interface NSIndexPath { [Export ("indexPathWithIndex:")][Static] - NSIndexPath FromIndex (uint index); + NSIndexPath FromIndex (NSUInteger index); [Export ("indexPathWithIndexes:length:")][Internal][Static] - NSIndexPath _FromIndex (IntPtr indexes, int len); + NSIndexPath _FromIndex (IntPtr indexes, NSUInteger len); [Export ("indexPathByAddingIndex:")] - NSIndexPath IndexPathByAddingIndex (uint index); + NSIndexPath IndexPathByAddingIndex (NSUInteger index); [Export ("indexPathByRemovingLastIndex")] NSIndexPath IndexPathByRemovingLastIndex (); [Export ("indexAtPosition:")] - uint IndexAtPosition (int position); + NSUInteger IndexAtPosition (NSUInteger position); [Export ("length")] - int Length { get; } + NSUInteger Length { get; } [Export ("getIndexes:")][Internal] void _GetIndexes (IntPtr target); [Export ("compare:")] - int Compare (NSIndexPath other); + NSInteger Compare (NSIndexPath other); #if !MONOMAC // NSIndexPath UIKit Additions Reference @@ -4555,43 +4555,43 @@ public interface NSIndexPath { [BaseType (typeof (NSObject))] public interface NSIndexSet { [Static, Export ("indexSetWithIndex:")] - NSIndexSet FromIndex (int idx); + NSIndexSet FromIndex (NSUInteger idx); [Static, Export ("indexSetWithIndexesInRange:")] NSIndexSet FromNSRange (NSRange indexRange); [Export ("initWithIndex:")] - IntPtr Constructor (uint index); + IntPtr Constructor (NSUInteger index); [Export ("initWithIndexSet:")] IntPtr Constructor (NSIndexSet other); [Export ("count")] - int Count { get; } + NSUInteger Count { get; } [Export ("isEqualToIndexSet:")] bool IsEqual (NSIndexSet other); [Export ("firstIndex")] - uint FirstIndex { get; } + NSUInteger FirstIndex { get; } [Export ("lastIndex")] - uint LastIndex { get; } + NSUInteger LastIndex { get; } [Export ("indexGreaterThanIndex:")] - uint IndexGreaterThan (uint index); + NSUInteger IndexGreaterThan (NSUInteger index); [Export ("indexLessThanIndex:")] - uint IndexLessThan (uint index); + NSUInteger IndexLessThan (NSUInteger index); [Export ("indexGreaterThanOrEqualToIndex:")] - uint IndexGreaterThanOrEqual (uint index); + NSUInteger IndexGreaterThanOrEqual (NSUInteger index); [Export ("indexLessThanOrEqualToIndex:")] - uint IndexLessThanOrEqual (uint index); + NSUInteger IndexLessThanOrEqual (NSUInteger index); [Export ("containsIndex:")] - bool Contains (uint index); + bool Contains (NSUInteger index); [Export ("containsIndexes:")] bool Contains (NSIndexSet indexes); @@ -4624,7 +4624,7 @@ interface NSJsonSerialization { [Static] [Export ("writeJSONObject:toStream:options:error:")] - int Serialize (NSObject obj, NSOutputStream stream, NSJsonWritingOptions opt, out NSError error); + NSInteger Serialize (NSObject obj, NSOutputStream stream, NSJsonWritingOptions opt, out NSError error); [Static] [Export ("JSONObjectWithStream:options:error:")] @@ -4635,7 +4635,7 @@ interface NSJsonSerialization { [BaseType (typeof (NSIndexSet))] public interface NSMutableIndexSet { [Export ("initWithIndex:")] - IntPtr Constructor (uint index); + IntPtr Constructor (NSUInteger index); [Export ("initWithIndexSet:")] IntPtr Constructor (NSIndexSet other); @@ -4650,13 +4650,13 @@ public interface NSMutableIndexSet { void Clear (); [Export ("addIndex:")] - void Add (uint index); + void Add (NSUInteger index); [Export ("removeIndex:")] - void Remove (uint index); + void Remove (NSUInteger index); [Export ("shiftIndexesStartingAtIndex:by:")] - void ShiftIndexes (uint startIndex, int delta); + void ShiftIndexes (NSUInteger startIndex, NSInteger delta); } [BaseType (typeof (NSObject), Delegates=new string [] { "WeakDelegate" }, Events=new Type [] { typeof (NSNetServiceDelegate)})] From 768f55d6f8101d36a70f4c6e7ecedc4dac6fddeb Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Wed, 13 Mar 2013 09:01:29 -0700 Subject: [PATCH 14/21] foundation.cs updated to be 64bit compatible --- src/Foundation/Enum.cs | 28 +++++++++++++++++++ src/Foundation/NSObject2.cs | 24 +++++++++++++++- src/foundation.cs | 56 +++++++++++++++++++++++++------------ 3 files changed, 89 insertions(+), 19 deletions(-) diff --git a/src/Foundation/Enum.cs b/src/Foundation/Enum.cs index 72756c38..c3082883 100644 --- a/src/Foundation/Enum.cs +++ b/src/Foundation/Enum.cs @@ -326,7 +326,11 @@ public enum NSNotificationSuspensionBehavior { } [Flags] +#if MAC64 + public enum NSNotificationFlags : ulong { +#else public enum NSNotificationFlags { +#endif DeliverImmediately = (1 << 0), PostToAllSessions = (1 << 1), } @@ -476,7 +480,11 @@ public enum NSStringDrawingOptions : uint { TruncatesLastVisibleLine = (1 << 5) } +#if MAC64 + public enum NSNumberFormatterStyle : ulong { +#else public enum NSNumberFormatterStyle { +#endif None = 0, Decimal = 1, Currency = 2, @@ -485,17 +493,29 @@ public enum NSNumberFormatterStyle { SpellOut = 5 } +#if MAC64 + public enum NSNumberFormatterBehavior : ulong { +#else public enum NSNumberFormatterBehavior { +#endif Default = 0, Version_10_0 = 1000, Version_10_4 = 1040 } +#if MAC64 + public enum NSNumberFormatterPadPosition : ulong { +#else public enum NSNumberFormatterPadPosition { +#endif BeforePrefix, AfterPrefix, BeforeSuffix, AfterSuffix } +#if MAC64 + public enum NSNumberFormatterRoundingMode : ulong { +#else public enum NSNumberFormatterRoundingMode { +#endif Ceiling, Floor, Down, Up, HalfEven, HalfDown, HalfUp } @@ -509,12 +529,20 @@ public enum NSFileVersionAddingOptions { } [Flags] +#if MAC64 + public enum NSFileCoordinatorReadingOptions : ulong { +#else public enum NSFileCoordinatorReadingOptions { +#endif WithoutChanges = 1 } [Flags] +#if MAC64 + public enum NSFileCoordinatorWritingOptions : ulong { +#else public enum NSFileCoordinatorWritingOptions { +#endif ForDeleting = 1, ForMoving = 2, ForMerging = 4, diff --git a/src/Foundation/NSObject2.cs b/src/Foundation/NSObject2.cs index d977c11f..46dcb2e5 100644 --- a/src/Foundation/NSObject2.cs +++ b/src/Foundation/NSObject2.cs @@ -32,6 +32,20 @@ #endif using MonoMac.CoreGraphics; +#if MAC64 +using NSInteger = System.Int64; +using NSUInteger = System.UInt64; +using CGFloat = System.Double; +#else +using NSInteger = System.Int32; +using NSUInteger = System.UInt32; +using NSPoint = System.Drawing.PointF; +using NSSize = System.Drawing.SizeF; +using NSRect = System.Drawing.RectangleF; +using CGFloat = System.Single; +#endif + + namespace MonoMac.Foundation { public class NSObjectFlag { public static readonly NSObjectFlag Empty; @@ -411,13 +425,21 @@ public static NSObject FromObject (object obj) default: if (t == typeof (IntPtr)) return NSValue.ValueFromPointer ((IntPtr) obj); - +#if MAC64 + if (t == typeof (NSSize)) + return NSValue.FromSize ((NSSize) obj); + else if (t == typeof (NSRect)) + return NSValue.FromRectangle ((NSRect) obj); + else if (t == typeof (NSPoint)) + return NSValue.FromPoint ((NSPoint) obj); +#else if (t == typeof (SizeF)) return NSValue.FromSizeF ((SizeF) obj); else if (t == typeof (RectangleF)) return NSValue.FromRectangleF ((RectangleF) obj); else if (t == typeof (PointF)) return NSValue.FromPointF ((PointF) obj); +#endif #if !MONOMAC if (t == typeof (CGAffineTransform)) return NSValue.FromCGAffineTransform ((CGAffineTransform) obj); diff --git a/src/foundation.cs b/src/foundation.cs index f111e45d..0b71730c 100644 --- a/src/foundation.cs +++ b/src/foundation.cs @@ -4982,7 +4982,26 @@ public partial interface NSValue { [Export ("CMTimeRangeValue"), Lion] CMTimeRange CMTimeRangeValue { get; } + +#if MAC64 + [Export ("valueWithRect:"), Static] + NSValue FromRectangle (NSRect rect); + + [Export ("valueWithSize:")][Static] + NSValue FromSize (NSSize size); + + [Export ("valueWithPoint:")][Static] + NSValue FromPoint (NSPoint point); + [Export ("rectValue")] + NSRect RectangleValue { get; } + + [Export ("sizeValue")] + NSSize SizeValue { get; } + + [Export ("pointValue")] + NSPoint PointValue { get; } +#else [Export ("valueWithRect:"), Static] NSValue FromRectangleF (System.Drawing.RectangleF rect); @@ -5000,6 +5019,7 @@ public partial interface NSValue { [Export ("pointValue")] System.Drawing.PointF PointFValue { get; } +#endif [Export ("rangeValue")] NSRange RangeValue { get; } @@ -5125,10 +5145,10 @@ public interface NSNumber { bool BoolValue { get; } [Export ("integerValue")] - int IntValue { get; } + NSInteger IntValue { get; } [Export ("unsignedIntegerValue")] - uint UnsignedIntegerValue { get; } + NSUInteger UnsignedIntegerValue { get; } [Export ("stringValue")] string StringValue { get; } @@ -5369,7 +5389,7 @@ interface NSNumberFormatter { NSNumber Multiplier { get; set; } [Export ("formatWidth")] - uint FormatWidth { get; set; } + NSUInteger FormatWidth { get; set; } [Export ("paddingCharacter")] string PaddingCharacter { get; set; } @@ -5384,16 +5404,16 @@ interface NSNumberFormatter { NSNumber RoundingIncrement { get; set; } [Export ("minimumIntegerDigits")] - int MinimumIntegerDigits { get; set; } + NSUInteger MinimumIntegerDigits { get; set; } [Export ("maximumIntegerDigits")] - int MaximumIntegerDigits { get; set; } + NSUInteger MaximumIntegerDigits { get; set; } [Export ("minimumFractionDigits")] - int MinimumFractionDigits { get; set; } + NSUInteger MinimumFractionDigits { get; set; } [Export ("maximumFractionDigits")] - int MaximumFractionDigits { get; set; } + NSUInteger MaximumFractionDigits { get; set; } [Export ("minimum")] NSNumber Minimum { get; set; } @@ -5411,10 +5431,10 @@ interface NSNumberFormatter { bool UsesSignificantDigits { get; set; } [Export ("minimumSignificantDigits")] - uint MinimumSignificantDigits { get; set; } + NSUInteger MinimumSignificantDigits { get; set; } [Export ("maximumSignificantDigits")] - uint MaximumSignificantDigits { get; set; } + NSUInteger MaximumSignificantDigits { get; set; } [Export ("partialStringValidationEnabled")] bool PartialStringValidationEnabled { [Bind ("isPartialStringValidationEnabled")]get; set; } @@ -5484,10 +5504,10 @@ public interface NSDecimalNumber { NSDecimalNumber Divide (NSDecimalNumber d, NSObject Behavior); [Export ("decimalNumberByRaisingToPower:")] - NSDecimalNumber RaiseTo (uint power); + NSDecimalNumber RaiseTo (NSUInteger power); [Export ("decimalNumberByRaisingToPower:withBehavior:")] - NSDecimalNumber RaiseTo (uint power, NSObject Behavior); + NSDecimalNumber RaiseTo (NSUInteger power, NSObject Behavior); [Export ("decimalNumberByMultiplyingByPowerOf10:")] NSDecimalNumber MultiplyPowerOf10 (short power); @@ -5499,7 +5519,7 @@ public interface NSDecimalNumber { NSDecimalNumber Rounding (NSObject behavior); [Export ("compare:")] - int Compare (NSNumber other); + NSInteger Compare (NSNumber other); [Export ("defaultBehavior")][Static] NSObject DefaultBehavior { get; set; } @@ -5541,7 +5561,7 @@ public interface NSThread { string Name { get; set; } [Export ("stackSize")] - uint StackSize { get; set; } + NSUInteger StackSize { get; set; } [Export ("isMainThread")] bool IsMainThread { get; } @@ -5601,7 +5621,7 @@ public interface NSProcessInfo { string HostName { get; } [Export ("operatingSystem")] - int OperatingSystem { get; } + NSUInteger OperatingSystem { get; } [Export ("operatingSystemName")] string OperatingSystemName { get; } @@ -5613,10 +5633,10 @@ public interface NSProcessInfo { ulong PhysicalMemory { get; } [Export ("processorCount")] - int ProcessorCount { get; } + NSUInteger ProcessorCount { get; } [Export ("activeProcessorCount")] - int ActiveProcessorCount { get; } + NSUInteger ActiveProcessorCount { get; } [Export ("systemUptime")] double SystemUptime { get; } @@ -6293,10 +6313,10 @@ public interface NSDirectoryEnumerator { string FileGroupOwnerAccountName ([Target] NSDictionary fileAttributes); [Export ("fileSystemNumber")] - int FileSystemNumber ([Target] NSDictionary fileAttributes); + NSInteger FileSystemNumber ([Target] NSDictionary fileAttributes); [Export ("fileSystemFileNumber")] - uint FileSystemFileNumber ([Target] NSDictionary fileAttributes); + NSUInteger FileSystemFileNumber ([Target] NSDictionary fileAttributes); [Export ("fileExtensionHidden")] bool FileExtensionHidden ([Target] NSDictionary fileAttributes); From a67c2248b03e11d73913e745bdd76188f2f88265 Mon Sep 17 00:00:00 2001 From: sbaer Date: Fri, 5 Apr 2013 10:19:56 -0700 Subject: [PATCH 15/21] Added constructors/functions to point,rect,size to make it easier to build winforms --- src/Foundation/NSPoint.cs | 23 +++++++++++++++++++++++ src/Foundation/NSRect.cs | 35 +++++++++++++++++++++++++++++++++++ src/Foundation/NSSize.cs | 5 +++++ 3 files changed, 63 insertions(+) diff --git a/src/Foundation/NSPoint.cs b/src/Foundation/NSPoint.cs index fbd7e544..d6db7262 100644 --- a/src/Foundation/NSPoint.cs +++ b/src/Foundation/NSPoint.cs @@ -35,10 +35,33 @@ public NSPoint(System.Drawing.PointF point) X = point.X; Y = point.Y; } + + public NSPoint(int x, int y) + { +#if MAC64 + X = (double)x; + Y = (double)y; +#else + X = (float)x; + Y = (float)y; +#endif + } #if MAC64 + public NSPoint(double x, double y) + { + X = x; + Y = y; + } + public double X; public double Y; #else + public NSPoint(float x, float y) + { + X = x; + Y = y; + } + public float X; public float Y; #endif diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs index b8349b61..947f19c1 100644 --- a/src/Foundation/NSRect.cs +++ b/src/Foundation/NSRect.cs @@ -38,13 +38,48 @@ public NSRect(System.Drawing.RectangleF rect) Size.Height = rect.Height; } + public NSRect(NSPoint location, NSSize size) + { + Origin.X = location.X; + Origin.Y = location.Y; + Size.Width = size.Width; + Size.Height = size.Height; + } + + public NSRect(System.Drawing.Point location, System.Drawing.Size size) + { + Origin.X = location.X; + Origin.Y = location.Y; + Size.Width = size.Width; + Size.Height = size.Height; + } + + public NSRect(double x, double y, double width, double height) + { + Origin.X = x; + Origin.Y = y; + Size.Width = width; + Size.Height = height; + } + public NSPoint Origin; public NSSize Size; + public NSPoint Location { + get + { + return Origin; + } + } + #if MAC64 + public double X { get { return Origin.X; } } + public double Y { get { return Origin.Y; } } public double Width { get { return Size.Width; } } public double Height { get { return Size.Height; } } #else + public float X { get { return Origin.X; } } + public float Y { get { return Origin.Y; } } public float Width { get { return Size.Width; } } public float Height { get { return Size.Height; } } #endif diff --git a/src/Foundation/NSSize.cs b/src/Foundation/NSSize.cs index 4729de22..1d538152 100644 --- a/src/Foundation/NSSize.cs +++ b/src/Foundation/NSSize.cs @@ -35,6 +35,11 @@ public NSSize(System.Drawing.SizeF size) Width = size.Width; Height = size.Height; } + public NSSize(float width, float height) + { + Width = width; + Height = height; + } #if MAC64 public double Width; From 4f359d3d910c61f350494bcd9a506ca851062ece Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 11 Apr 2013 11:25:21 -0700 Subject: [PATCH 16/21] added overload of NSArray.FromObjects to 64 bit compile I need to spend some time looking at why the params object[] exists in the overloads --- src/Foundation/NSArray.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Foundation/NSArray.cs b/src/Foundation/NSArray.cs index 69ecceaf..6f5d9d28 100644 --- a/src/Foundation/NSArray.cs +++ b/src/Foundation/NSArray.cs @@ -85,7 +85,15 @@ public static NSArray FromObjects (params object [] items) } return FromNSObjects (nsoa); } - + +#if MAC64 + public static NSArray FromObjects (IntPtr array, int count) + { + NSUInteger ucount = (NSUInteger)count; + return FromObjects (array, ucount); + } +#endif + internal static NSArray FromNSObjects (IList items) { if (items == null) From 91d93233121db8890509e817c662b72f0a3a728f Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 25 Apr 2013 10:55:29 -0700 Subject: [PATCH 17/21] 64bit fix for figuring out which obj_msg... function to call based on size of data --- src/generator.cs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/generator.cs b/src/generator.cs index ea800a7e..38db94ef 100644 --- a/src/generator.cs +++ b/src/generator.cs @@ -1429,7 +1429,11 @@ bool X86NeedStret (MethodInfo mi) if (!t.IsValueType || t.IsEnum || t.Assembly == typeof (object).Assembly) return false; +#if MAC64 + return Marshal.SizeOf (t) > 16; +#else return Marshal.SizeOf (t) > 8; +#endif } bool NeedStret (MethodInfo mi) From fbe54305be160b24f53f08619e2967a808f95d9b Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 25 Apr 2013 10:56:11 -0700 Subject: [PATCH 18/21] added set properties for NSRect --- src/Foundation/NSRect.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs index 947f19c1..234eae11 100644 --- a/src/Foundation/NSRect.cs +++ b/src/Foundation/NSRect.cs @@ -73,15 +73,15 @@ public NSPoint Location { } #if MAC64 - public double X { get { return Origin.X; } } - public double Y { get { return Origin.Y; } } - public double Width { get { return Size.Width; } } - public double Height { get { return Size.Height; } } + public double X { get { return Origin.X; } set { Origin.X=value; } } + public double Y { get { return Origin.Y; } set { Origin.Y=value; } } + public double Width { get { return Size.Width; } set { Size.Width = value; } } + public double Height { get { return Size.Height; } set { Size.Height = value; } } #else - public float X { get { return Origin.X; } } - public float Y { get { return Origin.Y; } } - public float Width { get { return Size.Width; } } - public float Height { get { return Size.Height; } } + public float X { get { return Origin.X; } set { Origin.X=value; } } + public float Y { get { return Origin.Y; } set { Origin.Y=value; } } + public float Width { get { return Size.Width; } set { Size.Width = value; } } + public float Height { get { return Size.Height; } set { Size.Height = value; } } #endif } } From 6542951cb100207ea6d5c7a2a2ae7f4d792a633c Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 25 Apr 2013 10:57:04 -0700 Subject: [PATCH 19/21] Added "debugging" command args for testing --- src/btouch.cs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/btouch.cs b/src/btouch.cs index 0a66a944..2f65cbff 100644 --- a/src/btouch.cs +++ b/src/btouch.cs @@ -65,6 +65,40 @@ static void ShowHelp (OptionSet os) static int Main (string [] args) { + string [] testArgs = new string[]{ + "-a", + "-d=MONOMAC", + "-d=MAC64", + "--core", + "--sourceonly=generated_sources", + "-v", + "-tmpdir=.", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/appkit.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/corewlan.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/foundation-desktop.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/imagekit.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/qtkit.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/pdfkit.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/webkit.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/composer.cs", + "/Users/stevenbaer/dev/github/mcneel/monomac/src/scriptingbridge.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/avfoundation.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/foundation.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/coreanimation.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/coredata.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/coreimage.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/coremidi.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/corelocation.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/imageio.cs", + "/Users/stevenbaer/dev/github/mcneel/maccore/src/quicklook.cs", + "--baselib=/Users/stevenbaer/dev/github/mcneel/monomac/src/core.dll", + "--ns=MonoMac.ObjCRuntime", + "-r=System.Drawing" + }; + //args = testArgs; + + + try { return Main2 (args); } catch (Exception ex) { From 2ead7f778fff17436e32dbcdcec3b0f8c24b9b40 Mon Sep 17 00:00:00 2001 From: Steve Baer Date: Thu, 25 Apr 2013 10:57:46 -0700 Subject: [PATCH 20/21] set up project for working on a 64 bit compile --- src/generator.csproj | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/generator.csproj b/src/generator.csproj index ff982872..6b1dcad2 100644 --- a/src/generator.csproj +++ b/src/generator.csproj @@ -15,7 +15,7 @@ full False bin\Debug - DEBUG;MONOMAC + DEBUG;MONOMAC;NET_2_0;MAC64;MONOMAC_BOOTSTRAP prompt 4 x86 @@ -33,8 +33,8 @@ - - ..\..\monomac\src\MonoMac.dll + + ..\..\monomac\src\core.dll From 22b24555d7ad5bb33fb3648aa1ae1925dc22eb8f Mon Sep 17 00:00:00 2001 From: sbaer Date: Fri, 11 Oct 2013 08:39:28 -0700 Subject: [PATCH 21/21] update to fix compile error with latest mono release --- src/AddressBook/ABAddressBook.cs | 15 +- src/AudioToolbox/AudioBuffers.cs | 39 ++-- src/AudioToolbox/AudioConverter.cs | 34 +-- src/AudioToolbox/AudioFile.cs | 40 ++-- src/AudioToolbox/AudioFileGlobalInfo.cs | 14 +- src/AudioToolbox/AudioFileStream.cs | 89 ++++---- src/AudioToolbox/AudioFormat.cs | 19 +- src/AudioToolbox/AudioFormatAvailability.cs | 11 +- src/AudioToolbox/AudioQueue.cs | 34 ++- src/AudioToolbox/AudioSession.cs | 228 ++++++++++++++------ src/AudioToolbox/AudioType.cs | 80 ++++--- src/ObjCRuntime/AdoptsAttribute.cs | 1 - src/ObjCRuntime/Blocks.cs | 2 +- 13 files changed, 375 insertions(+), 231 deletions(-) diff --git a/src/AddressBook/ABAddressBook.cs b/src/AddressBook/ABAddressBook.cs index c3078c89..0032dd43 100644 --- a/src/AddressBook/ABAddressBook.cs +++ b/src/AddressBook/ABAddressBook.cs @@ -4,7 +4,7 @@ // Authors: Mono Team // // Copyright (C) 2009 Novell, Inc -// Copyright 2011, 2012 Xamarin Inc. +// Copyright 2011-2013 Xamarin Inc. // // Permission is hereby granted, free of charge, to any person obtaining // a copy of this software and associated documentation files (the @@ -69,13 +69,17 @@ public ExternalChangeEventArgs (ABAddressBook addressBook, NSDictionary info) // // Meaning we can't rely on static constructors, as they could be invoked // before those functions have been invoked. :-/ + // + // Note that the above comment was removed from iOS 6.0+ documentation (and were not part of OSX docs AFAIK). + // It make sense since it's not possible to call those functions, from 6.0+ they will return NULL on devices, + // unless the application has been authorized to access the address book. class InitConstants { public static void Init () {} static InitConstants () { - // ensure we can init. - CFObject.CFRelease (ABAddressBook.ABAddressBookCreate ()); + // ensure we can init. This is needed before iOS6 (as per doc). + IntPtr p = ABAddressBook.ABAddressBookCreate (); ABGroupProperty.Init (); ABLabel.Init (); @@ -89,6 +93,11 @@ static InitConstants () ABPersonRelatedNamesLabel.Init (); ABPersonUrlLabel.Init (); ABSourcePropertyId.Init (); + + // From iOS 6.0+ this might return NULL, e.g. if the application is not authorized to access the + // address book, and we would crash if we tried to release a null pointer + if (p != IntPtr.Zero) + CFObject.CFRelease (p); } } diff --git a/src/AudioToolbox/AudioBuffers.cs b/src/AudioToolbox/AudioBuffers.cs index 2469cd1c..1ad17cc4 100644 --- a/src/AudioToolbox/AudioBuffers.cs +++ b/src/AudioToolbox/AudioBuffers.cs @@ -53,18 +53,23 @@ public AudioBuffers (IntPtr address, bool owns) this.owns = owns; } - public AudioBuffers (int count) + public unsafe AudioBuffers (int count) { if (count < 0) throw new ArgumentOutOfRangeException ("count"); - var size = sizeof (int) + count * Marshal.SizeOf (typeof (AudioBuffer)); + var size = sizeof (int) + count * sizeof (AudioBuffer); address = Marshal.AllocHGlobal (size); owns = true; Marshal.WriteInt32 (address, 0, count); - for (int i = sizeof (int); i < size; i++) - Marshal.WriteByte (address, i, 0); + AudioBuffer *ptr = (AudioBuffer *) (((byte *) address) + sizeof (int)); + for (int i = 0; i < count; i++){ + ptr->NumberChannels = 0; + ptr->DataByteSize = 0; + ptr->Data = IntPtr.Zero; + ptr++; + } } ~AudioBuffers () @@ -73,9 +78,9 @@ public AudioBuffers (int count) GC.SuppressFinalize (this); } - public int Count { + public unsafe int Count { get { - return Marshal.ReadInt32 (address); + return *(int *) address; } } @@ -96,8 +101,8 @@ public AudioBuffer this [int index] { unsafe { byte *baddress = (byte *) address; - var ptr = baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)); - return (AudioBuffer) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioBuffer)); + var ptr = baddress + sizeof (int) + index * sizeof (AudioBuffer); + return *(AudioBuffer *) ptr; } } set { @@ -106,10 +111,8 @@ public AudioBuffer this [int index] { unsafe { byte *baddress = (byte *) address; - var ptr = (IntPtr) (baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer))); - Marshal.WriteInt32 (ptr, value.NumberChannels); - Marshal.WriteInt32 (ptr, sizeof (int), value.DataByteSize); - Marshal.WriteIntPtr (ptr, sizeof (int) + sizeof (int), value.Data); + var ptr = (AudioBuffer *) (baddress + sizeof (int) + index * sizeof (AudioBuffer)); + *ptr = value; } } } @@ -126,8 +129,8 @@ public void SetData (int index, IntPtr data) unsafe { byte * baddress = (byte *) address; - var ptr = (IntPtr)(baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)) + sizeof (int) + sizeof (int)); - Marshal.WriteIntPtr (ptr, data); + var ptr = (IntPtr *)(baddress + sizeof (int) + index * sizeof (AudioBuffer) + sizeof (int) + sizeof (int)); + *ptr = data; } } @@ -138,9 +141,11 @@ public void SetData (int index, IntPtr data, int dataByteSize) unsafe { byte *baddress = (byte *) address; - var ptr = (IntPtr)(baddress + sizeof (int) + index * Marshal.SizeOf (typeof (AudioBuffer)) + sizeof (int)); - Marshal.WriteInt32 (ptr, dataByteSize); - Marshal.WriteIntPtr (ptr, sizeof (int), data); + var ptr = (int *)(baddress + sizeof (int) + index * sizeof (AudioBuffer) + sizeof (int)); + *ptr = dataByteSize; + ptr++; + IntPtr *iptr = (IntPtr *) ptr; + *iptr = data; } } diff --git a/src/AudioToolbox/AudioConverter.cs b/src/AudioToolbox/AudioConverter.cs index 7405cc42..b97bea9a 100644 --- a/src/AudioToolbox/AudioConverter.cs +++ b/src/AudioToolbox/AudioConverter.cs @@ -76,6 +76,7 @@ public enum AudioConverterPrimeMethod None = 2 } + [StructLayout (LayoutKind.Sequential)] public struct AudioConverterPrimeInfo { public int LeadingFrames; @@ -185,10 +186,10 @@ public AudioConverterPrimeMethod PrimeMethod { } } - public AudioConverterPrimeInfo PrimeInfo { + public unsafe AudioConverterPrimeInfo PrimeInfo { get { AudioConverterPrimeInfo value; - var size = Marshal.SizeOf (typeof (AudioConverterPrimeInfo)); + var size = sizeof (AudioConverterPrimeInfo); var res = AudioConverterGetProperty (handle, AudioConverterPropertyID.PrimeInfo, ref size, out value); if (res != AudioConverterError.None) throw new ArgumentException (res.ToString ()); @@ -328,7 +329,7 @@ public AudioChannelLayoutTag[] AvailableEncodeChannelLayoutTags { } } - public AudioStreamBasicDescription CurrentOutputStreamDescription { + public unsafe AudioStreamBasicDescription CurrentOutputStreamDescription { get { int size; bool writable; @@ -341,13 +342,13 @@ public AudioStreamBasicDescription CurrentOutputStreamDescription { if (res != AudioConverterError.None) throw new ArgumentException (res.ToString ()); - var asbd = (AudioStreamBasicDescription) Marshal.PtrToStructure (ptr, typeof (AudioStreamBasicDescription)); + var asbd = *(AudioStreamBasicDescription *) ptr; Marshal.FreeHGlobal (ptr); return asbd; } } - public AudioStreamBasicDescription CurrentInputStreamDescription { + public unsafe AudioStreamBasicDescription CurrentInputStreamDescription { get { int size; bool writable; @@ -360,7 +361,7 @@ public AudioStreamBasicDescription CurrentInputStreamDescription { if (res != AudioConverterError.None) throw new ArgumentException (res.ToString ()); - var asbd = (AudioStreamBasicDescription) Marshal.PtrToStructure (ptr, typeof (AudioStreamBasicDescription)); + var asbd = *(AudioStreamBasicDescription*) ptr; Marshal.FreeHGlobal (ptr); return asbd; } @@ -375,9 +376,9 @@ public int BitDepthHint { } } - public AudioFormat[] FormatList { + public unsafe AudioFormat[] FormatList { get { - return GetArray (AudioConverterPropertyID.PropertyFormatList, Marshal.SizeOf (typeof (AudioFormat))); + return GetArray (AudioConverterPropertyID.PropertyFormatList, sizeof (AudioFormat)); } } @@ -568,26 +569,31 @@ double GetDoubleProperty (AudioConverterPropertyID propertyID) return value; } - AudioValueRange[] GetAudioValueRange (AudioConverterPropertyID prop) + unsafe AudioValueRange[] GetAudioValueRange (AudioConverterPropertyID prop) { - return GetArray (prop, Marshal.SizeOf (typeof (AudioValueRange))); + return GetArray (prop, sizeof (AudioValueRange)); } - unsafe T[] GetArray (AudioConverterPropertyID prop, int elementSize) where T : struct + unsafe T[] GetArray (AudioConverterPropertyID prop, int elementSize) { int size; bool writable; if (AudioConverterGetPropertyInfo (handle, prop, out size, out writable) != AudioConverterError.None) return null; - var data = new T[size / elementSize]; - fixed (T* ptr = &data[0]) { - var res = AudioConverterGetProperty (handle, prop, ref size, (IntPtr)ptr); + var data = new T [size / elementSize]; + var array_handle = GCHandle.Alloc (data, GCHandleType.Pinned); + + try { + var ptr = array_handle.AddrOfPinnedObject (); + var res = AudioConverterGetProperty (handle, prop, ref size, ptr); if (res != 0) return null; Array.Resize (ref data, size / elementSize); return data; + } finally { + array_handle.Free (); } } diff --git a/src/AudioToolbox/AudioFile.cs b/src/AudioToolbox/AudioFile.cs index 78785fa9..41ca53e3 100644 --- a/src/AudioToolbox/AudioFile.cs +++ b/src/AudioToolbox/AudioFile.cs @@ -276,8 +276,8 @@ public AudioFileMarker this [int index] { // } // unsafe { - var ptr = (byte *) this.ptr + 2 * sizeof (int) + index * Marshal.SizeOf (typeof (AudioFileMarker)); - return (AudioFileMarker) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioFileMarker)); + var ptr = (AudioFileMarker *) this.ptr + 2 * sizeof (int) + index * sizeof (AudioFileMarker); + return *ptr; } } } @@ -347,15 +347,15 @@ internal IntPtr NameWeak { } } - public AudioFileRegionFlags Flags { + public unsafe AudioFileRegionFlags Flags { get { - return (AudioFileRegionFlags) Marshal.ReadInt32 (ptr, sizeof (uint) + Marshal.SizeOf (typeof (IntPtr))); + return (AudioFileRegionFlags) Marshal.ReadInt32 (ptr, sizeof (uint) + sizeof (IntPtr)); } } - public int Count { + public unsafe int Count { get { - return Marshal.ReadInt32 (ptr, 2 * sizeof (uint) + Marshal.SizeOf (typeof (IntPtr))); + return Marshal.ReadInt32 (ptr, 2 * sizeof (uint) + sizeof (IntPtr)); } } @@ -365,15 +365,15 @@ public AudioFileMarker this [int index] { throw new ArgumentOutOfRangeException ("index"); unsafe { - var ptr = (byte *) this.ptr + 3 * sizeof (int) + Marshal.SizeOf (typeof (IntPtr)) + index * Marshal.SizeOf (typeof (AudioFileMarker)); - return (AudioFileMarker) Marshal.PtrToStructure ((IntPtr) ptr, typeof (AudioFileMarker)); + var ptr = (AudioFileMarker *) this.ptr + 3 * sizeof (int) + sizeof (IntPtr) + index * sizeof (AudioFileMarker); + return *ptr; } } } - internal int TotalSize { + internal unsafe int TotalSize { get { - return Count * Marshal.SizeOf (typeof (AudioFileMarker)); + return Count * sizeof (AudioFileMarker); } } } @@ -991,7 +991,7 @@ public IntPtr GetProperty (AudioFileProperty property, out int size) return IntPtr.Zero; } - T? GetProperty (AudioFileProperty property) where T : struct + unsafe T? GetProperty (AudioFileProperty property) where T : struct { int size, writable; @@ -1002,8 +1002,10 @@ public IntPtr GetProperty (AudioFileProperty property, out int size) return null; try { var r = AudioFileGetProperty (handle, property, ref size, buffer); - if (r == 0) - return (T) Marshal.PtrToStructure (buffer, typeof (T)); + if (r == 0){ + T t = (T) Marshal.PtrToStructure (buffer, typeof (T)); + return t; + } return null; } finally { @@ -1258,7 +1260,7 @@ public AudioFileRegionList RegionList { } } - public AudioFilePacketTableInfo? PacketTableInfo { + public unsafe AudioFilePacketTableInfo? PacketTableInfo { get { return GetProperty (AudioFileProperty.PacketTableInfo); } @@ -1267,7 +1269,7 @@ public AudioFilePacketTableInfo? PacketTableInfo { throw new ArgumentNullException ("value"); AudioFilePacketTableInfo afpti = value.Value; - var res = AudioFileSetProperty (handle, AudioFileProperty.PacketTableInfo, Marshal.SizeOf (typeof (AudioFilePacketTableInfo)), ref afpti); + var res = AudioFileSetProperty (handle, AudioFileProperty.PacketTableInfo, sizeof (AudioFilePacketTableInfo), ref afpti); if (res != 0) throw new ArgumentException (res.ToString ()); } @@ -1326,7 +1328,7 @@ public long PacketToFrame (long packet) unsafe { AudioFramePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); + int size = sizeof (AudioFramePacketTranslation); if (AudioFileGetProperty (handle, AudioFileProperty.PacketToFrame, ref size, (IntPtr) p) == 0) return buffer.Frame; return -1; @@ -1340,7 +1342,7 @@ public long FrameToPacket (long frame, out int frameOffsetInPacket) unsafe { AudioFramePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); + int size = sizeof (AudioFramePacketTranslation); if (AudioFileGetProperty (handle, AudioFileProperty.FrameToPacket, ref size, (IntPtr) p) == 0){ frameOffsetInPacket = buffer.FrameOffsetInPacket; return buffer.Packet; @@ -1357,7 +1359,7 @@ public long PacketToByte (long packet, out bool isEstimate) unsafe { AudioBytePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); + int size = sizeof (AudioBytePacketTranslation); if (AudioFileGetProperty (handle, AudioFileProperty.PacketToByte, ref size, (IntPtr) p) == 0){ isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0; return buffer.Byte; @@ -1374,7 +1376,7 @@ public long ByteToPacket (long byteval, out int byteOffsetInPacket, out bool isE unsafe { AudioBytePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); + int size = sizeof (AudioBytePacketTranslation); if (AudioFileGetProperty (handle, AudioFileProperty.ByteToPacket, ref size, (IntPtr) p) == 0){ isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0; byteOffsetInPacket = buffer.ByteOffsetInPacket; diff --git a/src/AudioToolbox/AudioFileGlobalInfo.cs b/src/AudioToolbox/AudioFileGlobalInfo.cs index 4fa8dbc0..b42aa702 100644 --- a/src/AudioToolbox/AudioFileGlobalInfo.cs +++ b/src/AudioToolbox/AudioFileGlobalInfo.cs @@ -74,7 +74,7 @@ public static AudioFileType[] WritableTypes { public static string GetFileTypeName (AudioFileType fileType) { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.FileTypeName, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0) return null; @@ -120,7 +120,7 @@ public static AudioStreamBasicDescription[] GetAvailableStreamDescriptions (Audi public static string[] AllExtensions { get { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllExtensions, 0, IntPtr.Zero, ref size, out ptr) != 0) return null; @@ -131,7 +131,7 @@ public static string[] AllExtensions { public static string[] AllUTIs { get { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllUTIs, 0, IntPtr.Zero, ref size, out ptr) != 0) return null; @@ -142,7 +142,7 @@ public static string[] AllUTIs { public static string[] AllMIMETypes { get { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.AllMIMETypes, 0, IntPtr.Zero, ref size, out ptr) != 0) return null; @@ -173,7 +173,7 @@ public static HFSTypeCode[] AllHFSTypeCodes { public static string[] GetExtensions (AudioFileType fileType) { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.ExtensionsForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0) return null; @@ -183,7 +183,7 @@ public static string[] GetExtensions (AudioFileType fileType) public static string[] GetUTIs (AudioFileType fileType) { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.UTIsForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0) return null; @@ -193,7 +193,7 @@ public static string[] GetUTIs (AudioFileType fileType) public static string[] GetMIMETypes (AudioFileType fileType) { IntPtr ptr; - var size = (uint) Marshal.SizeOf (typeof (IntPtr)); + var size = (uint) sizeof (IntPtr); if (AudioFileGetGlobalInfo (AudioFileGlobalProperty.MIMETypesForType, sizeof (AudioFileType), ref fileType, ref size, out ptr) != 0) return null; diff --git a/src/AudioToolbox/AudioFileStream.cs b/src/AudioToolbox/AudioFileStream.cs index 0a68ea83..fc6c9dd6 100644 --- a/src/AudioToolbox/AudioFileStream.cs +++ b/src/AudioToolbox/AudioFileStream.cs @@ -166,14 +166,8 @@ extern static OSStatus AudioFileStreamOpen ( AudioFileType fileTypeHint, out IntPtr file_id); - static AudioFileStream_PacketsProc dInPackets; - static AudioFileStream_PropertyListenerProc dPropertyListener; - - static AudioFileStream () - { - dInPackets = InPackets; - dPropertyListener = PropertyListener; - } + static readonly AudioFileStream_PacketsProc dInPackets = InPackets; + static readonly AudioFileStream_PropertyListenerProc dPropertyListener = PropertyListener; [MonoPInvokeCallback(typeof(AudioFileStream_PacketsProc))] static void InPackets (IntPtr clientData, int numberBytes, int numberPackets, IntPtr inputData, IntPtr packetDescriptions) @@ -234,7 +228,7 @@ extern static AudioFileStreamStatus AudioFileStreamParseBytes ( public AudioFileStreamStatus ParseBytes (int size, IntPtr data, bool discontinuity) { - return AudioFileStreamParseBytes (handle, size, data, discontinuity ? (uint) 1 : (uint) 0); + return LastError = AudioFileStreamParseBytes (handle, size, data, discontinuity ? (uint) 1 : (uint) 0); } public AudioFileStreamStatus ParseBytes (byte [] bytes, bool discontinuity) @@ -243,7 +237,7 @@ public AudioFileStreamStatus ParseBytes (byte [] bytes, bool discontinuity) throw new ArgumentNullException ("bytes"); unsafe { fixed (byte *bp = &bytes[0]){ - return AudioFileStreamParseBytes (handle, bytes.Length, (IntPtr) bp, discontinuity ? (uint) 1 : (uint) 0); + return LastError = AudioFileStreamParseBytes (handle, bytes.Length, (IntPtr) bp, discontinuity ? (uint) 1 : (uint) 0); } } } @@ -261,7 +255,7 @@ public AudioFileStreamStatus ParseBytes (byte [] bytes, int offset, int count, b unsafe { fixed (byte *bp = &bytes[0]){ - return AudioFileStreamParseBytes (handle, count, (IntPtr) (bp + offset) , discontinuity ? (uint) 1 : (uint) 0); + return LastError = AudioFileStreamParseBytes (handle, count, (IntPtr) (bp + offset) , discontinuity ? (uint) 1 : (uint) 0); } } } @@ -275,24 +269,25 @@ extern static AudioFileStreamStatus AudioFileStreamSeek(AudioFileStreamID inAudi public AudioFileStreamStatus Seek (long packetOffset, out long dataByteOffset, out bool isEstimate) { int v = 0; - var code = AudioFileStreamSeek (handle, packetOffset, out dataByteOffset, ref v); - if (code != AudioFileStreamStatus.Ok){ + LastError = AudioFileStreamSeek (handle, packetOffset, out dataByteOffset, ref v); + if (LastError != AudioFileStreamStatus.Ok){ isEstimate = false; - return code; + } else { + isEstimate = (v & 1) == 1; } - isEstimate = (v & 1) == 1; - return code; + + return LastError; } [DllImport (Constants.AudioToolboxLibrary)] - extern static OSStatus AudioFileStreamGetPropertyInfo( + extern static AudioFileStreamStatus AudioFileStreamGetPropertyInfo( AudioFileStreamID inAudioFileStream, AudioFileStreamProperty inPropertyID, out int outPropertyDataSize, out int isWritable); [DllImport (Constants.AudioToolboxLibrary)] - extern static OSStatus AudioFileStreamGetProperty( + extern static AudioFileStreamStatus AudioFileStreamGetProperty( AudioFileStreamID inAudioFileStream, AudioFileStreamProperty inPropertyID, ref int ioPropertyDataSize, @@ -307,16 +302,16 @@ public IntPtr GetProperty (AudioFileStreamProperty property, out int size) { int writable; - var r = AudioFileStreamGetPropertyInfo (handle, property, out size, out writable); - if (r != 0) + LastError = AudioFileStreamGetPropertyInfo (handle, property, out size, out writable); + if (LastError != 0) return IntPtr.Zero; var buffer = Marshal.AllocHGlobal (size); if (buffer == IntPtr.Zero) return IntPtr.Zero; - r = AudioFileStreamGetProperty (handle, property, ref size, buffer); - if (r == 0) + LastError = AudioFileStreamGetProperty (handle, property, ref size, buffer); + if (LastError == 0) return buffer; Marshal.FreeHGlobal (buffer); return IntPtr.Zero; @@ -327,7 +322,8 @@ int GetInt (AudioFileStreamProperty property) unsafe { int val = 0; int size = 4; - if (AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)) == 0) + LastError = AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)); + if (LastError == 0) return val; return 0; } @@ -338,7 +334,8 @@ double GetDouble (AudioFileStreamProperty property) unsafe { double val = 0; int size = 8; - if (AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)) == 0) + LastError = AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)); + if (LastError == 0) return val; return 0; } @@ -349,25 +346,28 @@ long GetLong (AudioFileStreamProperty property) unsafe { long val = 0; int size = 8; - if (AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)) == 0) + LastError = AudioFileStreamGetProperty (handle, property, ref size, (IntPtr) (&val)); + if (LastError == 0) return val; return 0; } } - T? GetProperty (AudioFileStreamProperty property) where T : struct + unsafe T? GetProperty (AudioFileStreamProperty property) where T : struct { int size, writable; - if (AudioFileStreamGetPropertyInfo (handle, property, out size, out writable) != 0) + LastError = AudioFileStreamGetPropertyInfo (handle, property, out size, out writable); + if (LastError != 0) return null; var buffer = Marshal.AllocHGlobal (size); if (buffer == IntPtr.Zero) return null; try { - var r = AudioFileStreamGetProperty (handle, property, ref size, buffer); - if (r == 0) + LastError = AudioFileStreamGetProperty (handle, property, ref size, buffer); + if (LastError == 0){ return (T) Marshal.PtrToStructure (buffer, typeof (T)); + } return null; } finally { @@ -376,7 +376,7 @@ long GetLong (AudioFileStreamProperty property) } [DllImport (Constants.AudioToolboxLibrary)] - extern static OSStatus AudioFileStreamSetProperty( + extern static AudioFileStreamStatus AudioFileStreamSetProperty( AudioFileStreamID inAudioFileStream, AudioFileStreamProperty inPropertyID, int inPropertyDataSize, @@ -384,11 +384,12 @@ extern static OSStatus AudioFileStreamSetProperty( public bool SetProperty (AudioFileStreamProperty property, int dataSize, IntPtr propertyData) { - return AudioFileStreamSetProperty (handle, property, dataSize, propertyData) == 0; + LastError = AudioFileStreamSetProperty (handle, property, dataSize, propertyData); + return LastError == 0; } [DllImport (Constants.AudioToolboxLibrary)] - extern static OSStatus AudioFileStreamClose(AudioFileStreamID inAudioFileStream); + extern static AudioFileStreamStatus AudioFileStreamClose(AudioFileStreamID inAudioFileStream); public bool ReadyToProducePackets { get { @@ -419,10 +420,10 @@ public unsafe AudioFormat [] FormatList { get { int size; var r = GetProperty (AudioFileStreamProperty.FormatList, out size); - var records = (AudioFormat *) r; if (r == IntPtr.Zero) return null; + var records = (AudioFormat *) r; int itemSize = sizeof (AudioFormat); int items = size/itemSize; var ret = new AudioFormat [items]; @@ -502,8 +503,9 @@ public long PacketToFrame (long packet) unsafe { AudioFramePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); - if (AudioFileStreamGetProperty (handle, AudioFileStreamProperty.PacketToFrame, ref size, (IntPtr) p) == 0) + int size = sizeof (AudioFramePacketTranslation); + LastError = AudioFileStreamGetProperty (handle, AudioFileStreamProperty.PacketToFrame, ref size, (IntPtr) p); + if (LastError == 0) return buffer.Frame; return -1; } @@ -516,8 +518,9 @@ public long FrameToPacket (long frame, out int frameOffsetInPacket) unsafe { AudioFramePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); - if (AudioFileStreamGetProperty (handle, AudioFileStreamProperty.FrameToPacket, ref size, (IntPtr) p) == 0){ + int size = sizeof (AudioFramePacketTranslation); + LastError = AudioFileStreamGetProperty (handle, AudioFileStreamProperty.FrameToPacket, ref size, (IntPtr) p); + if (LastError == 0){ frameOffsetInPacket = buffer.FrameOffsetInPacket; return buffer.Packet; } @@ -533,8 +536,9 @@ public long PacketToByte (long packet, out bool isEstimate) unsafe { AudioBytePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); - if (AudioFileStreamGetProperty (handle, AudioFileStreamProperty.PacketToByte, ref size, (IntPtr) p) == 0){ + int size = sizeof (AudioBytePacketTranslation); + LastError = AudioFileStreamGetProperty (handle, AudioFileStreamProperty.PacketToByte, ref size, (IntPtr) p); + if (LastError == 0){ isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0; return buffer.Byte; } @@ -550,8 +554,9 @@ public long ByteToPacket (long byteval, out int byteOffsetInPacket, out bool isE unsafe { AudioBytePacketTranslation *p = &buffer; - int size = Marshal.SizeOf (buffer); - if (AudioFileStreamGetProperty (handle, AudioFileStreamProperty.ByteToPacket, ref size, (IntPtr) p) == 0){ + int size = sizeof (AudioBytePacketTranslation); + LastError = AudioFileStreamGetProperty (handle, AudioFileStreamProperty.ByteToPacket, ref size, (IntPtr) p); + if (LastError == 0){ isEstimate = (buffer.Flags & BytePacketTranslationFlags.IsEstimate) != 0; byteOffsetInPacket = buffer.ByteOffsetInPacket; return buffer.Packet; @@ -579,5 +584,7 @@ public double AverageBytesPerPacket { return GetDouble (AudioFileStreamProperty.AverageBytesPerPacket); } } + + public AudioFileStreamStatus LastError { get; private set; } } } diff --git a/src/AudioToolbox/AudioFormat.cs b/src/AudioToolbox/AudioFormat.cs index 3a077192..cf4d3152 100644 --- a/src/AudioToolbox/AudioFormat.cs +++ b/src/AudioToolbox/AudioFormat.cs @@ -55,7 +55,7 @@ public struct AudioFormat fixed (AudioFormat* item = &formatList[0]) { uint index; int size = sizeof (uint); - var ptr_size = Marshal.SizeOf (formatList[0]) * formatList.Length; + var ptr_size = sizeof (AudioFormat) * formatList.Length; if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FirstPlayableFormatFromList, ptr_size, item, ref size, out index) != 0) return null; @@ -122,11 +122,11 @@ public AudioBalanceFade (AudioChannelLayout channelLayout) public unsafe float[] GetBalanceFade () { - var type_size = Marshal.SizeOf (typeof (Layout)); + var type_size = sizeof (Layout); var str = ToStruct (); var ptr = Marshal.AllocHGlobal (type_size); - Marshal.StructureToPtr (str, ptr, false); + (*(Layout *) ptr) = str; int size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.BalanceFade, type_size, ptr, out size) != 0) @@ -170,12 +170,12 @@ public enum PanningMode public class AudioPanningInfo { + [StructLayout (LayoutKind.Sequential)] struct Layout { public PanningMode PanningMode; public AudioChannelFlags CoordinateFlags; - [MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)] - public float[] Coordinates; + public float Coord0, Coord1, Coord2; public float GainScale; public IntPtr OutputChannelMapWeak; } @@ -186,7 +186,6 @@ public AudioPanningInfo (AudioChannelLayout outputChannelMap) throw new ArgumentNullException ("outputChannelMap"); this.OutputChannelMap = outputChannelMap; - Coordinates = new float[3]; } public PanningMode PanningMode { get; set; } @@ -197,11 +196,11 @@ public AudioPanningInfo (AudioChannelLayout outputChannelMap) public unsafe float[] GetPanningMatrix () { - var type_size = Marshal.SizeOf (typeof (Layout)); + var type_size = sizeof (Layout); var str = ToStruct (); var ptr = Marshal.AllocHGlobal (type_size); - Marshal.StructureToPtr (str, ptr, false); + *((Layout *)ptr) = str; int size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.PanningMatrix, type_size, ptr, out size) != 0) @@ -225,7 +224,9 @@ Layout ToStruct () { PanningMode = PanningMode, CoordinateFlags = CoordinateFlags, - Coordinates = Coordinates, + Coord0 = Coordinates [0], + Coord1 = Coordinates [1], + Coord2 = Coordinates [2], GainScale = GainScale }; diff --git a/src/AudioToolbox/AudioFormatAvailability.cs b/src/AudioToolbox/AudioFormatAvailability.cs index effc1910..b5040770 100644 --- a/src/AudioToolbox/AudioFormatAvailability.cs +++ b/src/AudioToolbox/AudioFormatAvailability.cs @@ -55,20 +55,25 @@ public static AudioClassDescription[] GetEncoders (AudioFormatType format) return GetAvailable (AudioFormatProperty.Encoders, format); } - unsafe static T[] GetAvailable (AudioFormatProperty prop, AudioFormatType format) where T : struct + unsafe static T[] GetAvailable (AudioFormatProperty prop, AudioFormatType format) { uint size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (prop, sizeof (AudioFormatType), ref format, out size) != 0) return null; var data = new T[size / Marshal.SizeOf (typeof (T))]; - fixed (T* ptr = data) { - var res = AudioFormatPropertyNative.AudioFormatGetProperty (prop, sizeof (AudioFormatType), ref format, ref size, (IntPtr)ptr); + var array_handle = GCHandle.Alloc (data, GCHandleType.Pinned); + + try { + var ptr = array_handle.AddrOfPinnedObject (); + var res = AudioFormatPropertyNative.AudioFormatGetProperty (prop, sizeof (AudioFormatType), ref format, ref size, ptr); if (res != 0) return null; Array.Resize (ref data, (int) size / Marshal.SizeOf (typeof (T))); return data; + } finally { + array_handle.Free (); } } } diff --git a/src/AudioToolbox/AudioQueue.cs b/src/AudioToolbox/AudioQueue.cs index f50827bb..a139d8c4 100644 --- a/src/AudioToolbox/AudioQueue.cs +++ b/src/AudioToolbox/AudioQueue.cs @@ -817,7 +817,7 @@ public IntPtr GetProperty (AudioQueueProperty property, out int size) } // Should be private - public T GetProperty (AudioQueueProperty property) + public unsafe T GetProperty (AudioQueueProperty property) where T:struct { int size; @@ -830,8 +830,10 @@ public T GetProperty (AudioQueueProperty property) return default(T); try { r = AudioQueueGetProperty (handle, property, buffer, ref size); - if (r == 0) - return (T) Marshal.PtrToStructure (buffer, typeof (T)); + if (r == 0){ + T result = (T) Marshal.PtrToStructure (buffer, typeof (T)); + return result; + } throw new AudioQueueException (r); } finally { @@ -1054,21 +1056,17 @@ public AudioQueueStatus SetChannelAssignments (params AudioQueueChannelAssignmen } } - unsafe static IntPtr MarshalArray (ref T[] array, out int totalSize) where T : struct - { - int elementSize = Marshal.SizeOf (typeof (T)); - totalSize = elementSize * array.Length; - IntPtr array_ptr = Marshal.AllocHGlobal (totalSize); - byte* ptr = (byte*) array_ptr.ToPointer(); - - for (int i = 0; i < array.Length; i++, ptr += elementSize) - { - IntPtr pos = new IntPtr (ptr); - Marshal.StructureToPtr (array [i], pos, false); - } - - return array_ptr; - } + unsafe static IntPtr MarshalArray (ref AudioQueueChannelAssignment[] array, out int totalSize) + { + int elementSize = sizeof (AudioQueueChannelAssignment); + totalSize = elementSize * array.Length; + var array_ptr = (AudioQueueChannelAssignment*) Marshal.AllocHGlobal (totalSize); + + for (int i = 0; i < array.Length; i++) + array_ptr [i] = array [i]; + + return (IntPtr) array_ptr; + } #endif [DllImport (Constants.AudioToolboxLibrary)] diff --git a/src/AudioToolbox/AudioSession.cs b/src/AudioToolbox/AudioSession.cs index fbcf8e7c..c579bd40 100644 --- a/src/AudioToolbox/AudioSession.cs +++ b/src/AudioToolbox/AudioSession.cs @@ -36,6 +36,7 @@ using MonoMac.CoreFoundation; using MonoMac.ObjCRuntime; using MonoMac.Foundation; +using System.Threading; using OSStatus = System.Int32; @@ -92,6 +93,13 @@ internal AccessoryInfo (int id, string description) Description = description; } + // TODO: Should not be just int but int wrapped in struct because it's system-defined identifier + public int ID { get; private set; } + public string Description { get; private set; } + } + + public class InputSourceInfo + { public int ID { get; private set; } public string Description { get; private set; } } @@ -339,6 +347,19 @@ static int GetInt (AudioSessionProperty property) return val; } } + + static IntPtr GetIntPtr (AudioSessionProperty property) + { + unsafe { + IntPtr val; + int size = IntPtr.Size; + int k = AudioSessionGetProperty (property, ref size, (IntPtr) (&val)); + if (k != 0) + throw new AudioSessionException (k); + + return val; + } + } static void SetDouble (AudioSessionProperty property, double val) { @@ -404,43 +425,37 @@ public static AudioSessionInterruptionType InterruptionType { [Obsolete ("Deprecated in iOS 5.0. Use InputRoute or OutputRoute instead")] static public string AudioRoute { get { - return CFString.FetchString ((IntPtr) GetInt (AudioSessionProperty.AudioRoute)); + return CFString.FetchString (GetIntPtr (AudioSessionProperty.AudioRoute)); } } [Since (5,0)] static public AccessoryInfo[] InputSources { get { - using (var array = new CFArray ((IntPtr) GetInt (AudioSessionProperty.InputSources))) { - var res = new AccessoryInfo [array.Count]; - for (int i = 0; i < res.Length; ++i) { - var dict = array.GetValue (i); - var id = new NSNumber (CFDictionary.GetValue (dict, InputSourceKey_ID.Handle)); - var desc = CFString.FetchString (CFDictionary.GetValue (dict, InputSourceKey_Description.Handle)); - - res [i] = new AccessoryInfo ((int) id, desc); - id.Dispose (); - } - return res; - } + return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.InputSources), InputSourceKey_ID, InputSourceKey_Description); } } [Since (5,0)] static public AccessoryInfo[] OutputDestinations { get { - using (var array = new CFArray ((IntPtr) GetInt (AudioSessionProperty.OutputDestinations))) { - var res = new AccessoryInfo [array.Count]; - for (int i = 0; i < res.Length; ++i) { - var dict = array.GetValue (i); - var id = new NSNumber (CFDictionary.GetValue (dict, OutputDestinationKey_ID.Handle)); - var desc = CFString.FetchString (CFDictionary.GetValue (dict, OutputDestinationKey_Description.Handle)); - - res [i] = new AccessoryInfo ((int) id, desc); - id.Dispose (); - } - return res; + return ExtractAccessoryInfo (GetIntPtr (AudioSessionProperty.OutputDestinations), OutputDestinationKey_ID, OutputDestinationKey_Description); + } + } + + static AccessoryInfo[] ExtractAccessoryInfo (IntPtr ptr, NSString id, NSString description) + { + using (var array = new CFArray (ptr)) { + var res = new AccessoryInfo [array.Count]; + for (int i = 0; i < res.Length; ++i) { + var dict = array.GetValue (i); + var n = new NSNumber (CFDictionary.GetValue (dict, id.Handle)); + var desc = CFString.FetchString (CFDictionary.GetValue (dict, description.Handle)); + + res [i] = new AccessoryInfo ((int) n, desc); + id.Dispose (); } + return res; } } @@ -557,7 +572,7 @@ static public AudioSessionOutputRouteKind [] OutputRoutes { static NSDictionary AudioRouteDescription { get { - NSDictionary dict = new NSDictionary ((IntPtr) GetInt (AudioSessionProperty.AudioRouteDescription)); + NSDictionary dict = new NSDictionary (GetIntPtr (AudioSessionProperty.AudioRouteDescription)); dict.Release (); return dict; } @@ -669,8 +684,6 @@ static public AudioSessionMode Mode { } } - // InputSources - [Since (5,0)] static public bool InputGainAvailable { get { @@ -706,12 +719,15 @@ static void Listener (IntPtr userData, AudioSessionProperty prop, int size, IntP } [DllImport (Constants.AudioToolboxLibrary)] - extern static OSStatus AudioSessionAddPropertyListener(AudioSessionProperty id, _PropertyListener inProc, IntPtr userData); + extern static AudioSessionErrors AudioSessionAddPropertyListener(AudioSessionProperty id, _PropertyListener inProc, IntPtr userData); static Hashtable listeners; - public static void AddListener (AudioSessionProperty property, PropertyListener listener) + public static AudioSessionErrors AddListener (AudioSessionProperty property, PropertyListener listener) { + if (property == null) + throw new ArgumentNullException ("property"); + if (listener == null) throw new ArgumentNullException ("listener"); @@ -724,8 +740,11 @@ public static void AddListener (AudioSessionProperty property, PropertyListener a.Add (listener); - if (a.Count == 1) - AudioSessionAddPropertyListener (property, Listener, IntPtr.Zero); + if (a.Count == 1) { + return AudioSessionAddPropertyListener (property, Listener, IntPtr.Zero); + } + + return AudioSessionErrors.None; } public static void RemoveListener (AudioSessionProperty property, PropertyListener listener) @@ -741,40 +760,119 @@ public static void RemoveListener (AudioSessionProperty property, PropertyListen listeners [property] = null; } - class RouteChangeListener { - public EventHandler cback; - - public RouteChangeListener (EventHandler cback) - { - this.cback = cback; - } - - public void Listener (AudioSessionProperty prop, int size, IntPtr data) - { - cback (null, new AudioSessionRouteChangeEventArgs (data)); - } - } - static Hashtable strongListenerHash; - - public static event EventHandler AudioRouteChanged { - add { - if (strongListenerHash == null) - strongListenerHash = new Hashtable (); - var routeChangeListener = new RouteChangeListener (value); - strongListenerHash [value] = routeChangeListener; - AddListener (AudioSessionProperty.AudioRouteChange, routeChangeListener.Listener); - } - - remove { - if (strongListenerHash == null) - return; - var k = strongListenerHash [value] as RouteChangeListener; - if (k != null){ - RemoveListener (AudioSessionProperty.AudioRouteChange, k.Listener); - strongListenerHash.Remove (value); - } - } - } + + static void AddListenerEvent (AudioSessionProperty property, object handler, PropertyListener listener) + { + if (strongListenerHash == null) + Interlocked.CompareExchange (ref strongListenerHash, new Hashtable (), null); + + lock (strongListenerHash) { + strongListenerHash [handler] = listener; + } + + AddListener (property, listener); + } + + static void RemoveListenerEvent (AudioSessionProperty property, object handler) + { + if (strongListenerHash == null) + return; + + PropertyListener listener; + lock (strongListenerHash) { + listener = (PropertyListener) strongListenerHash [handler]; + if (listener == null) + return; + + strongListenerHash.Remove (handler); + } + + RemoveListener (AudioSessionProperty.CurrentHardwareOutputVolume, listener); + } + + public static event EventHandler AudioRouteChanged { + add { + AddListenerEvent (AudioSessionProperty.AudioRouteChange, value, + (prop, size, data) => value (null, new AudioSessionRouteChangeEventArgs (data))); + } + remove { + RemoveListenerEvent (AudioSessionProperty.AudioRouteChange, value); + } + } + + public static event Action CurrentHardwareOutputVolumeChanged { + add { + AddListenerEvent (AudioSessionProperty.CurrentHardwareOutputVolume, value, + (prop, size, data) => value ((float) data)); + } + remove { + RemoveListenerEvent (AudioSessionProperty.CurrentHardwareOutputVolume, value); + } + } + + public static event Action AudioInputBecameAvailable { + add { + AddListenerEvent (AudioSessionProperty.AudioInputAvailable, value, + (prop, size, data) => value (data != IntPtr.Zero)); + } + remove { + RemoveListenerEvent (AudioSessionProperty.AudioInputAvailable, value); + } + } + + public static event Action ServerDied { + add { + AddListenerEvent (AudioSessionProperty.ServerDied, value, + (prop, size, data) => value (data != IntPtr.Zero)); + } + remove { + RemoveListenerEvent (AudioSessionProperty.ServerDied, value); + } + } + + [Since (5,0)] + public static event Action InputGainBecameAvailable { + add { + AddListenerEvent (AudioSessionProperty.InputGainAvailable, value, + (prop, size, data) => value (data != IntPtr.Zero)); + } + remove { + RemoveListenerEvent (AudioSessionProperty.InputGainAvailable, value); + } + } + + [Since (5,0)] + public static event Action InputGainScalarChanged { + add { + AddListenerEvent (AudioSessionProperty.InputGainScalar, value, + (prop, size, data) => value ((float) data)); + } + remove { + RemoveListenerEvent (AudioSessionProperty.InputGainScalar, value); + } + } + + [Since (5,0)] + public static event Action InputSourcesChanged { + add { + AddListenerEvent (AudioSessionProperty.InputSources, value, + (prop, size, data) => value (ExtractAccessoryInfo (data, InputSourceKey_ID, InputSourceKey_Description))); + } + remove { + RemoveListenerEvent (AudioSessionProperty.InputSources, value); + } + } + + [Since (5,0)] + public static event Action OutputDestinationsChanged { + add { + AddListenerEvent (AudioSessionProperty.OutputDestinations, value, + (prop, size, data) => value (ExtractAccessoryInfo (data, OutputDestinationKey_ID, OutputDestinationKey_Description))); + } + remove { + RemoveListenerEvent (AudioSessionProperty.OutputDestinations, value); + } + } } } diff --git a/src/AudioToolbox/AudioType.cs b/src/AudioToolbox/AudioType.cs index e74d0046..63203052 100644 --- a/src/AudioToolbox/AudioType.cs +++ b/src/AudioToolbox/AudioType.cs @@ -160,7 +160,7 @@ public static AudioStreamBasicDescription CreateLinearPCM (double sampleRate = 4 public unsafe static AudioChannelLayoutTag[] GetAvailableEncodeChannelLayoutTags (AudioStreamBasicDescription format) { - var type_size = Marshal.SizeOf (format); + var type_size = sizeof (AudioStreamBasicDescription); uint size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.AvailableEncodeChannelLayoutTags, type_size, ref format, out size) != 0) return null; @@ -178,12 +178,12 @@ public unsafe static AudioChannelLayoutTag[] GetAvailableEncodeChannelLayoutTags public unsafe static int[] GetAvailableEncodeNumberChannels (AudioStreamBasicDescription format) { uint size; - if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.AvailableEncodeNumberChannels, Marshal.SizeOf (format), ref format, out size) != 0) + if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.AvailableEncodeNumberChannels, sizeof (AudioStreamBasicDescription), ref format, out size) != 0) return null; var data = new int[size / sizeof (int)]; fixed (int* ptr = data) { - var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.AvailableEncodeNumberChannels, Marshal.SizeOf (format), ref format, ref size, ptr); + var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.AvailableEncodeNumberChannels, sizeof (AudioStreamBasicDescription), ref format, ref size, ptr); if (res != 0) return null; @@ -196,7 +196,7 @@ public unsafe AudioFormat[] GetOutputFormatList (byte[] magicCookie = null) var afi = new AudioFormatInfo (); afi.AudioStreamBasicDescription = this; - var type_size = Marshal.SizeOf (typeof (AudioFormat)); + var type_size = sizeof (AudioFormat); uint size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.OutputFormatList, type_size, ref afi, out size) != 0) return null; @@ -227,7 +227,7 @@ public unsafe AudioFormat[] GetFormatList (byte[] magicCookie) afi.MagicCookieWeak = b; afi.MagicCookieSize = magicCookie.Length; - var type_size = Marshal.SizeOf (typeof (AudioFormat)); + var type_size = sizeof (AudioFormat); uint size; if (AudioFormatPropertyNative.AudioFormatGetPropertyInfo (AudioFormatProperty.FormatList, type_size, ref afi, out size) != 0) return null; @@ -248,16 +248,18 @@ public unsafe AudioFormat[] GetFormatList (byte[] magicCookie) public static AudioFormatError GetFormatInfo (ref AudioStreamBasicDescription format) { - var size = Marshal.SizeOf (format); - return AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatInfo, 0, IntPtr.Zero, ref size, ref format); + unsafe { + var size = sizeof (AudioStreamBasicDescription); + return AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatInfo, 0, IntPtr.Zero, ref size, ref format); + } } public unsafe string FormatName { get { IntPtr ptr; - var size = Marshal.SizeOf (typeof (IntPtr)); + var size = sizeof (IntPtr); - if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatName, Marshal.SizeOf (this), ref this, ref size, out ptr) != 0) + if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatName, sizeof (AudioStreamBasicDescription), ref this, ref size, out ptr) != 0) return null; return new CFString (ptr, true); @@ -269,7 +271,7 @@ public unsafe bool IsEncrypted { uint data; var size = sizeof (uint); - if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatIsEncrypted, Marshal.SizeOf (this), ref this, ref size, out data) != 0) + if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatIsEncrypted, sizeof (AudioStreamBasicDescription), ref this, ref size, out data) != 0) return false; return data != 0; @@ -281,7 +283,7 @@ public unsafe bool IsExternallyFramed { uint data; var size = sizeof (uint); - if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatIsExternallyFramed, Marshal.SizeOf (this), ref this, ref size, out data) != 0) + if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatIsExternallyFramed, sizeof (AudioStreamBasicDescription), ref this, ref size, out data) != 0) return false; return data != 0; @@ -293,7 +295,7 @@ public unsafe bool IsVariableBitrate { uint data; var size = sizeof (uint); - if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatName, Marshal.SizeOf (this), ref this, ref size, out data) != 0) + if (AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.FormatName, sizeof (AudioStreamBasicDescription), ref this, ref size, out data) != 0) return false; return data != 0; @@ -435,14 +437,26 @@ public struct AudioChannelDescription { public AudioChannelLabel Label; public AudioChannelFlags Flags; - [MarshalAs (UnmanagedType.ByValArray, SizeConst = 3)] - public float[] Coords; // = new float[3]; + float Coord0, Coord1, Coord2; + public float [] Coords { + get { + return new float [3] { Coord0, Coord1, Coord2 }; + } + set { + if (value.Length != 3) + throw new ArgumentException ("Must contain three floats"); + Coord0 = value [0]; + Coord1 = value [1]; + Coord2 = value [2]; + } + } + public unsafe string Name { get { IntPtr sptr; - int size = Marshal.SizeOf (typeof (IntPtr)); - int ptr_size = Marshal.SizeOf (this); + int size = sizeof (IntPtr); + int ptr_size = sizeof (AudioChannelDescription); var ptr = ToPointer (); var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.ChannelName, ptr_size, ptr, ref size, out sptr); @@ -457,8 +471,8 @@ public unsafe string Name { public unsafe string ShortName { get { IntPtr sptr; - int size = Marshal.SizeOf (typeof (IntPtr)); - int ptr_size = Marshal.SizeOf (this); + int size = sizeof (IntPtr); + int ptr_size = sizeof (AudioChannelDescription); var ptr = ToPointer (); var res = AudioFormatPropertyNative.AudioFormatGetProperty (AudioFormatProperty.ChannelShortName, ptr_size, ptr, ref size, out sptr); @@ -470,11 +484,11 @@ public unsafe string ShortName { } } - internal IntPtr ToPointer () + internal unsafe IntPtr ToPointer () { - var ptr = Marshal.AllocHGlobal (sizeof (AudioChannelLabel) + sizeof (AudioChannelFlags) + 3 * sizeof (float)); - Marshal.StructureToPtr (this, ptr, false); - return ptr; + var ptr = (AudioChannelDescription *) Marshal.AllocHGlobal (sizeof (AudioChannelLabel) + sizeof (AudioChannelFlags) + 3 * sizeof (float)); + *ptr = this; + return (IntPtr) ptr; } public override string ToString () @@ -659,9 +673,10 @@ internal unsafe AudioChannelLayout (IntPtr h) ChannelUsage = (AudioChannelBit) Marshal.ReadInt32 (h, 4); Channels = new AudioChannelDescription [Marshal.ReadInt32 (h, 8)]; int p = 12; + int size = sizeof (AudioChannelDescription); for (int i = 0; i < Channels.Length; i++){ - Channels [i] = (AudioChannelDescription) Marshal.PtrToStructure((IntPtr) (unchecked (((byte *) h) + p)), typeof(AudioChannelDescription)); - p += Marshal.SizeOf (typeof (AudioChannelDescription)); + Channels [i] = *(AudioChannelDescription *) (unchecked (((byte *) h) + p)); + p += size; } } @@ -692,7 +707,7 @@ public int Bitmap { public unsafe string Name { get { IntPtr sptr; - int size = Marshal.SizeOf (typeof (IntPtr)); + int size = sizeof (IntPtr); int ptr_size; var ptr = ToBlock (out ptr_size); @@ -708,7 +723,7 @@ public unsafe string Name { public unsafe string SimpleName { get { IntPtr sptr; - int size = Marshal.SizeOf (typeof (IntPtr)); + int size = sizeof (IntPtr); int ptr_size; var ptr = ToBlock (out ptr_size); @@ -766,19 +781,18 @@ internal unsafe IntPtr ToBlock (out int size) if (Channels == null) throw new ArgumentNullException ("Channels"); - var desc_size = Marshal.SizeOf (typeof (AudioChannelDescription)); + var desc_size = sizeof (AudioChannelDescription); size = 12 + Channels.Length * desc_size; IntPtr buffer = Marshal.AllocHGlobal (size); - int p; Marshal.WriteInt32 (buffer, (int) AudioTag); Marshal.WriteInt32 (buffer, 4, (int) ChannelUsage); Marshal.WriteInt32 (buffer, 8, Channels.Length); - p = 12; + AudioChannelDescription *dest = (AudioChannelDescription *) ((byte *) buffer + 12); foreach (var desc in Channels){ - Marshal.StructureToPtr (desc, (IntPtr) (unchecked (((byte *) buffer) + p)), false); - p += desc_size; + *dest = desc; + dest++; } return buffer; @@ -812,7 +826,7 @@ public unsafe static int[] GetChannelMap (AudioChannelLayout inputLayout, AudioC var input_ptr = inputLayout.ToBlock (out ptr_size); var output_ptr = outputLayout.ToBlock (out ptr_size); var array = new IntPtr[] { input_ptr, output_ptr }; - ptr_size = Marshal.SizeOf (typeof (IntPtr)) * array.Length; + ptr_size = sizeof (IntPtr) * array.Length; int[] value; AudioFormatError res; @@ -850,7 +864,7 @@ public unsafe static int[] GetChannelMap (AudioChannelLayout inputLayout, AudioC var input_ptr = inputLayout.ToBlock (out ptr_size); var output_ptr = outputLayout.ToBlock (out ptr_size); var array = new IntPtr[] { input_ptr, output_ptr }; - ptr_size = Marshal.SizeOf (typeof (IntPtr)) * array.Length; + ptr_size = sizeof (IntPtr) * array.Length; float[,] value; AudioFormatError res; diff --git a/src/ObjCRuntime/AdoptsAttribute.cs b/src/ObjCRuntime/AdoptsAttribute.cs index b3c916cb..32e94e8d 100644 --- a/src/ObjCRuntime/AdoptsAttribute.cs +++ b/src/ObjCRuntime/AdoptsAttribute.cs @@ -29,7 +29,6 @@ using System; using System.Runtime.InteropServices; -using MonoMac.Foundation; namespace MonoMac.ObjCRuntime { diff --git a/src/ObjCRuntime/Blocks.cs b/src/ObjCRuntime/Blocks.cs index b6c97fda..9df8bd99 100644 --- a/src/ObjCRuntime/Blocks.cs +++ b/src/ObjCRuntime/Blocks.cs @@ -29,7 +29,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; -using MonoMac.Foundation; +//using MonoMac.Foundation; using MonoMac.ObjCRuntime; namespace MonoMac.ObjCRuntime {