00001 using System;
00002 using System.Collections.Generic;
00003 using System.Runtime.InteropServices;
00004 using System.Text;
00005
00006 namespace OpenTK.Platform.MacOS.Carbon
00007 {
00008 struct CFArray
00009 {
00010 IntPtr arrayRef;
00011 public IntPtr Ref { get { return arrayRef; } set { arrayRef = value; } }
00012
00013 public CFArray(IntPtr reference)
00014 {
00015 arrayRef = reference;
00016 }
00017
00018 public int Count
00019 {
00020 get { return CF.CFArrayGetCount(arrayRef); }
00021 }
00022 public IntPtr this[int index]
00023 {
00024 get
00025 {
00026 if (index >= Count || index < 0)
00027 throw new IndexOutOfRangeException();
00028
00029 return CF.CFArrayGetValueAtIndex(arrayRef, index);
00030 }
00031 }
00032 }
00033 struct CFDictionary
00034 {
00035 public CFDictionary(IntPtr reference)
00036 {
00037 dictionaryRef = reference;
00038 }
00039
00040 IntPtr dictionaryRef;
00041 public IntPtr Ref { get { return dictionaryRef; } set { dictionaryRef = value; } }
00042
00043 public int Count
00044 {
00045 get
00046 {
00047 return CF.CFDictionaryGetCount(dictionaryRef);
00048 }
00049 }
00050 public double GetNumberValue(string key)
00051 {
00052 unsafe
00053 {
00054 double retval;
00055 IntPtr cfnum = CF.CFDictionaryGetValue(dictionaryRef,
00056 CF.CFSTR(key));
00057
00058 CF.CFNumberGetValue(cfnum, CF.CFNumberType.kCFNumberDoubleType, &retval);
00059
00060 return retval;
00061 }
00062 }
00063 }
00064 class CF
00065 {
00066 const string appServices = "/System/Library/Frameworks/ApplicationServices.framework/Versions/Current/ApplicationServices";
00067
00068 [DllImport(appServices)]
00069 internal static extern int CFArrayGetCount(IntPtr theArray);
00070
00071 [DllImport(appServices)]
00072 internal static extern IntPtr CFArrayGetValueAtIndex(IntPtr theArray, int idx);
00073
00074 [DllImport(appServices)]
00075 internal static extern int CFDictionaryGetCount(IntPtr theDictionary);
00076
00077 [DllImport(appServices)]
00078 internal static extern IntPtr CFDictionaryGetValue(IntPtr theDictionary, IntPtr theKey);
00079
00080
00081
00082
00083 [DllImport(appServices)]
00084 static extern IntPtr __CFStringMakeConstantString(string cStr);
00085 internal static IntPtr CFSTR(string cStr)
00086 {
00087 return __CFStringMakeConstantString(cStr);
00088 }
00089
00090 [DllImport(appServices)]
00091 internal unsafe static extern bool CFNumberGetValue (IntPtr number, CFNumberType theType, int* valuePtr);
00092 [DllImport(appServices)]
00093 internal unsafe static extern bool CFNumberGetValue(IntPtr number, CFNumberType theType, double* valuePtr);
00094
00095 internal enum CFNumberType
00096 {
00097 kCFNumberSInt8Type = 1,
00098 kCFNumberSInt16Type = 2,
00099 kCFNumberSInt32Type = 3,
00100 kCFNumberSInt64Type = 4,
00101 kCFNumberFloat32Type = 5,
00102 kCFNumberFloat64Type = 6,
00103 kCFNumberCharType = 7,
00104 kCFNumberShortType = 8,
00105 kCFNumberIntType = 9,
00106 kCFNumberLongType = 10,
00107 kCFNumberLongLongType = 11,
00108 kCFNumberFloatType = 12,
00109 kCFNumberDoubleType = 13,
00110 kCFNumberCFIndexType = 14,
00111 kCFNumberNSIntegerType = 15,
00112 kCFNumberCGFloatType = 16,
00113 kCFNumberMaxType = 16
00114 };
00115 }
00116 }