mirror of
https://github.com/Ryujinx/Opentk.git
synced 2025-07-08 07:00:33 +00:00
[Mac] Implemented necessary CFString methods
This commit is contained in:
parent
32653d2c64
commit
6dadbd3570
|
@ -32,7 +32,10 @@ using System.Text;
|
||||||
|
|
||||||
namespace OpenTK.Platform.MacOS.Carbon
|
namespace OpenTK.Platform.MacOS.Carbon
|
||||||
{
|
{
|
||||||
|
using CFIndex = System.IntPtr;
|
||||||
using CFRunLoop = System.IntPtr;
|
using CFRunLoop = System.IntPtr;
|
||||||
|
using CFStringRef = System.IntPtr;
|
||||||
|
using CFTypeRef = System.IntPtr;
|
||||||
|
|
||||||
struct CFArray
|
struct CFArray
|
||||||
{
|
{
|
||||||
|
@ -106,6 +109,9 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
[DllImport(appServices)]
|
[DllImport(appServices)]
|
||||||
internal static extern IntPtr CFDictionaryGetValue(IntPtr theDictionary, IntPtr theKey);
|
internal static extern IntPtr CFDictionaryGetValue(IntPtr theDictionary, IntPtr theKey);
|
||||||
|
|
||||||
|
[DllImport(appServices)]
|
||||||
|
internal static extern void CFRelease(CFTypeRef cf);
|
||||||
|
|
||||||
// this mirrors the definition in CFString.h.
|
// this mirrors the definition in CFString.h.
|
||||||
// I don't know why, but __CFStringMakeConstantString is marked as "private and should not be used directly"
|
// I don't know why, but __CFStringMakeConstantString is marked as "private and should not be used directly"
|
||||||
// even though the CFSTR macro just calls it.
|
// even though the CFSTR macro just calls it.
|
||||||
|
@ -116,6 +122,33 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
return __CFStringMakeConstantString(cStr);
|
return __CFStringMakeConstantString(cStr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[DllImport(appServices)]
|
||||||
|
internal static extern Boolean CFStringGetCString(
|
||||||
|
CFStringRef theString,
|
||||||
|
byte[] buffer,
|
||||||
|
CFIndex bufferSize,
|
||||||
|
CFStringEncoding encoding
|
||||||
|
);
|
||||||
|
|
||||||
|
internal static string CFStringGetCString(IntPtr cfstr)
|
||||||
|
{
|
||||||
|
CFIndex length = CFStringGetLength(cfstr);
|
||||||
|
if (length != IntPtr.Zero)
|
||||||
|
{
|
||||||
|
byte[] utf8_chars = new byte[length.ToInt32() + 1];
|
||||||
|
if (CFStringGetCString(cfstr, utf8_chars, new IntPtr(utf8_chars.Length), CFStringEncoding.UTF8))
|
||||||
|
{
|
||||||
|
return Encoding.UTF8.GetString(utf8_chars);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return String.Empty;
|
||||||
|
}
|
||||||
|
|
||||||
|
[DllImport(appServices)]
|
||||||
|
internal static extern CFIndex CFStringGetLength(
|
||||||
|
CFStringRef theString
|
||||||
|
);
|
||||||
|
|
||||||
[DllImport(appServices)]
|
[DllImport(appServices)]
|
||||||
internal unsafe static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, int* valuePtr);
|
internal unsafe static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, int* valuePtr);
|
||||||
[DllImport(appServices)]
|
[DllImport(appServices)]
|
||||||
|
@ -150,6 +183,25 @@ namespace OpenTK.Platform.MacOS.Carbon
|
||||||
HandledSource = 4
|
HandledSource = 4
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum CFStringEncoding
|
||||||
|
{
|
||||||
|
MacRoman = 0,
|
||||||
|
WindowsLatin1 = 0x0500,
|
||||||
|
ISOLatin1 = 0x0201,
|
||||||
|
NextStepLatin = 0x0B01,
|
||||||
|
ASCII = 0x0600,
|
||||||
|
Unicode = 0x0100,
|
||||||
|
UTF8 = 0x08000100,
|
||||||
|
NonLossyASCII = 0x0BFF,
|
||||||
|
|
||||||
|
UTF16 = 0x0100,
|
||||||
|
UTF16BE = 0x10000100,
|
||||||
|
UTF16LE = 0x14000100,
|
||||||
|
UTF32 = 0x0c000100,
|
||||||
|
UTF32BE = 0x18000100,
|
||||||
|
UTF32LE = 0x1c000100
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly IntPtr RunLoopModeDefault = CF.CFSTR("kCFRunLoopDefaultMode");
|
public static readonly IntPtr RunLoopModeDefault = CF.CFSTR("kCFRunLoopDefaultMode");
|
||||||
|
|
||||||
[DllImport(appServices)]
|
[DllImport(appServices)]
|
||||||
|
|
Loading…
Reference in a new issue