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/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/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 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 items) { if (items == null) @@ -196,9 +218,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/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/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/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/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/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/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/NSPoint.cs b/src/Foundation/NSPoint.cs new file mode 100644 index 00000000..d6db7262 --- /dev/null +++ b/src/Foundation/NSPoint.cs @@ -0,0 +1,70 @@ +// +// 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; + } + + 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 + } +} +#endif \ No newline at end of file diff --git a/src/Foundation/NSRect.cs b/src/Foundation/NSRect.cs new file mode 100644 index 00000000..234eae11 --- /dev/null +++ b/src/Foundation/NSRect.cs @@ -0,0 +1,88 @@ +// +// 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 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) + { + Origin.X = rect.Left; + Origin.Y = rect.Top; + Size.Width = rect.Width; + 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; } 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; } 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 + } +} +#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..1d538152 --- /dev/null +++ b/src/Foundation/NSSize.cs @@ -0,0 +1,53 @@ +// +// 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; + } + public NSSize(float width, float height) + { + Width = width; + Height = height; + } + +#if MAC64 + public double Width; + public double Height; +#else + public float Width; + public float Height; +#endif + } +} +#endif \ No newline at end of file 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/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)); } } } 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 { 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) { diff --git a/src/foundation.cs b/src/foundation.cs index 601b291f..9a376169 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 } @@ -258,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); @@ -277,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; } @@ -337,10 +351,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; @@ -633,19 +647,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)] @@ -664,7 +678,7 @@ public interface NSDateComponents { [Export ("quarter")] [Since (4,0)] - int Quarter { get; set; } + NSInteger Quarter { get; set; } [Export ("date")] [Since (4,0)] @@ -672,46 +686,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")] @@ -891,7 +905,7 @@ public interface NSFileHandle NSData ReadDataToEndOfFile (); [Export ("readDataOfLength:")] - NSData ReadDataOfLength (uint length); + NSData ReadDataOfLength (NSUInteger length); [Export ("writeData:")] void WriteData (NSData data); @@ -1174,16 +1188,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; } @@ -1192,7 +1206,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; } @@ -1336,7 +1350,7 @@ public interface NSMetadataQueryAttributeValueTuple { NSObject Value { get; } [Export ("count")] - int Count { get; } + NSUInteger Count { get; } } [BaseType (typeof (NSObject))] @@ -1351,10 +1365,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; } @@ -1368,22 +1382,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 (); @@ -1429,7 +1443,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); @@ -1450,35 +1464,35 @@ 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; } [Export ("initWithCapacity:")] - IntPtr Constructor (uint len); + IntPtr Constructor (NSUInteger len); [Export ("appendData:")] 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))] @@ -1533,7 +1547,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] @@ -1552,7 +1566,7 @@ public interface NSDictionary { IntPtr Constructor (NSUrl url); [Export ("count")] - uint Count { get; } + NSUInteger Count { get; } [Export ("objectForKey:")] NSObject ObjectForKey (NSObject key); @@ -1601,16 +1615,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; } @@ -1789,10 +1803,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); @@ -1801,13 +1815,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")] @@ -2126,7 +2140,7 @@ public interface NSSet { IntPtr Constructor (NSArray other); [Export ("count")] - uint Count { get; } + NSUInteger Count { get; } [Export ("anyObject")] NSObject AnyObject { get; } @@ -2236,7 +2250,7 @@ public interface NSTimeZone { NSData Data { get; } [Export ("secondsFromGMTForDate:")] - int SecondsFromGMT (NSDate date); + NSInteger SecondsFromGMT (NSDate date); [Export ("abbreviationForDate:")] string Abbreviation (NSDate date); @@ -2260,7 +2274,7 @@ public interface NSTimeZone { NSTimeZone LocalTimeZone { get; } [Export ("secondsFromGMT")] - int GetSecondsFromGMT { get; } + NSInteger GetSecondsFromGMT { get; } [Export ("defaultTimeZone"), Static] NSTimeZone DefaultTimeZone { get; set; } @@ -2943,7 +2957,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); @@ -2958,16 +2972,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")] @@ -2975,7 +2989,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); @@ -2987,7 +3001,7 @@ public interface NSUrlAuthenticationChallenge { NSUrlCredential ProposedCredential { get; } [Export ("previousFailureCount")] - int PreviousFailureCount { get; } + NSInteger PreviousFailureCount { get; } [Export ("failureResponse")] NSUrlResponse FailureResponse { get; } @@ -3099,7 +3113,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); @@ -3214,7 +3228,7 @@ public interface NSUndoManager { void EndUndoGrouping (); [Export ("groupingLevel")] - int GroupingLevel { get; } + NSInteger GroupingLevel { get; } [Export ("disableUndoRegistration")] void DisableUndoRegistration (); @@ -3229,7 +3243,7 @@ public interface NSUndoManager { bool GroupsByEvent { get; set; } [Export ("levelsOfUndo")] - int LevelsOfUndo { get; set; } + NSInteger LevelsOfUndo { get; set; } [Export ("runLoopModes")] string [] RunLoopModes { get; set; } @@ -3342,7 +3356,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); @@ -3360,7 +3374,7 @@ public interface NSUrlProtectionSpace { string Host { get; } [Export ("port")] - int Port { get; } + NSInteger Port { get; } [Export ("proxyType")] string ProxyType { get; } @@ -3488,7 +3502,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] @@ -3527,7 +3541,7 @@ public interface NSMutableSet { IntPtr Constructor (NSSet other); [Export ("initWithCapacity:")] - IntPtr Constructor (int capacity); + IntPtr Constructor (NSUInteger capacity); [Export ("addObject:")] void Add (NSObject nso); @@ -3593,7 +3607,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; } @@ -3729,16 +3743,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); @@ -3777,13 +3791,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); @@ -4144,7 +4158,7 @@ public interface NSOperationQueue { NSOperation [] Operations { get; } [Export ("operationCount")] - int OperationCount { get; } + NSUInteger OperationCount { get; } [Export ("name")] string Name { get; set; } @@ -4165,7 +4179,7 @@ public interface NSOperationQueue { //Detected properties [Export ("maxConcurrentOperationCount")] - int MaxConcurrentOperationCount { get; set; } + NSInteger MaxConcurrentOperationCount { get; set; } [Export ("suspended")] bool Suspended { [Bind ("isSuspended")]get; set; } @@ -4248,7 +4262,7 @@ public interface NSHttpCookie { NSDictionary Properties { get; } [Export ("version")] - uint Version { get; } + NSUInteger Version { get; } [Export ("value")] string Value { get; } @@ -4318,16 +4332,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))] @@ -4495,28 +4509,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 @@ -4548,43 +4562,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); @@ -4617,7 +4631,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:")] @@ -4628,7 +4642,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); @@ -4643,13 +4657,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)})] @@ -4977,7 +4991,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); @@ -4995,6 +5028,7 @@ public partial interface NSValue { [Export ("pointValue")] System.Drawing.PointF PointFValue { get; } +#endif [Export ("rangeValue")] NSRange RangeValue { get; } @@ -5120,10 +5154,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; } @@ -5364,7 +5398,7 @@ interface NSNumberFormatter { NSNumber Multiplier { get; set; } [Export ("formatWidth")] - uint FormatWidth { get; set; } + NSUInteger FormatWidth { get; set; } [Export ("paddingCharacter")] string PaddingCharacter { get; set; } @@ -5379,16 +5413,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; } @@ -5406,10 +5440,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; } @@ -5479,10 +5513,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); @@ -5494,7 +5528,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; } @@ -5536,7 +5570,7 @@ public interface NSThread { string Name { get; set; } [Export ("stackSize")] - uint StackSize { get; set; } + NSUInteger StackSize { get; set; } [Export ("isMainThread")] bool IsMainThread { get; } @@ -5596,7 +5630,7 @@ public interface NSProcessInfo { string HostName { get; } [Export ("operatingSystem")] - int OperatingSystem { get; } + NSUInteger OperatingSystem { get; } [Export ("operatingSystemName")] string OperatingSystemName { get; } @@ -5608,10 +5642,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; } @@ -6290,10 +6324,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); 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) 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