Exemplo n.º 1
0
 public static CFBundle[] GetAll()
 {
     using (var cfBundles = new CFArray(CFBundleGetAllBundles())) {
         var managedBundles = new CFBundle [cfBundles.Count];
         for (int index = 0; index < cfBundles.Count; index++)
         {
             // follow the get rule, we do not own the object
             managedBundles [index] = new CFBundle(cfBundles.GetValue(index), false);
         }
         return(managedBundles);
     }
 }
Exemplo n.º 2
0
 public static string[] GetLocalizations(NSUrl bundle)
 {
     if (bundle == null)
     {
         throw new ArgumentNullException("bundle");
     }
     using (var cfArray = new CFArray(CFBundleCopyLocalizationsForURL(bundle.Handle), true)) {
         var cultureInfo = new string [cfArray.Count];
         for (int index = 0; index < cfArray.Count; index++)
         {
             cultureInfo [index] = CFString.FetchString(cfArray.GetValue(index));
         }
         return(cultureInfo);
     }
 }
Exemplo n.º 3
0
        public NSUrl[] GetResourceUrls(string resourceType, string subDirName)
        {
            if (String.IsNullOrEmpty(resourceType))
            {
                throw new ArgumentException("resourceName");
            }

            using (CFString cfResourceType = new CFString(resourceType),
                   cfSubDir = new CFString(subDirName ?? string.Empty))
                using (var cfArray = new CFArray(CFBundleCopyResourceURLsOfType(handle, cfResourceType.Handle,
                                                                                String.IsNullOrEmpty(subDirName) ? IntPtr.Zero : cfSubDir.Handle), true)) {
                    var result = new NSUrl [cfArray.Count];
                    for (int index = 0; index < cfArray.Count; index++)
                    {
                        result [index] = Runtime.GetNSObject <NSUrl> (cfArray.GetValue(index), true);
                    }
                    return(result);
                }
        }
Exemplo n.º 4
0
 public static CFBundle[] GetBundlesFromDirectory(NSUrl directoryUrl, string bundleType)
 {
     if (directoryUrl == null)             // NSUrl cannot be "" by definition
     {
         throw new ArgumentNullException("directoryUrl");
     }
     if (String.IsNullOrEmpty(bundleType))
     {
         throw new ArgumentException("bundleType");
     }
     using (var bundleTypeCFSting = new CFString(bundleType))
         using (var cfBundles = new CFArray(CFBundleCreateBundlesFromDirectory(IntPtr.Zero, directoryUrl.Handle, bundleTypeCFSting.Handle), true)) {
             var managedBundles = new CFBundle [cfBundles.Count];
             for (int index = 0; index < cfBundles.Count; index++)
             {
                 // follow the create rules, therefore we do have ownership of each of the cfbundles
                 managedBundles [index] = new CFBundle(cfBundles.GetValue(index), true);
             }
             return(managedBundles);
         }
 }
Exemplo n.º 5
0
        public static string[] GetPreferredLocalizations(string[] locArray)
        {
            if (locArray == null)
            {
                throw new ArgumentNullException("locArray");
            }

            var cfString = new CFString [locArray.Length];

            for (int index = 0; index < locArray.Length; index++)
            {
                cfString [index] = new CFString(locArray [index]);
            }
            using (var cfLocArray = CFArray.FromNativeObjects(cfString))
                using (var cfArray = new CFArray(CFBundleCopyPreferredLocalizationsFromArray(cfLocArray.Handle), true)) {
                    var cultureInfo = new string [cfArray.Count];
                    for (int index = 0; index < cfArray.Count; index++)
                    {
                        cultureInfo [index] = CFString.FetchString(cfArray.GetValue(index));
                    }
                    return(cultureInfo);
                }
        }
Exemplo n.º 6
0
        public static string[] GetLocalizationsForPreferences(string[] locArray, string[] prefArray)
        {
            if (locArray == null)
            {
                throw new ArgumentNullException("locArray");
            }
            if (prefArray == null)
            {
                throw new ArgumentNullException("prefArray");
            }

            var cfLocal = new CFString [locArray.Length];

            for (int index = 0; index < locArray.Length; index++)
            {
                cfLocal [index] = new CFString(locArray [index]);
            }

            var cfPref = new CFString [prefArray.Length];

            for (int index = 0; index < prefArray.Length; index++)
            {
                cfPref [index] = new CFString(prefArray [index]);
            }

            using (CFArray cfLocalArray = CFArray.FromNativeObjects(cfLocal),
                   cfPrefArray = CFArray.FromNativeObjects(cfPref))
                using (var cfArray = new CFArray(CFBundleCopyLocalizationsForPreferences(cfLocalArray.Handle, cfPrefArray.Handle), true)) {
                    var cultureInfo = new string [cfArray.Count];
                    for (int index = 0; index < cfArray.Count; index++)
                    {
                        cultureInfo [index] = CFString.FetchString(cfArray.GetValue(index));
                    }
                    return(cultureInfo);
                }
        }
Exemplo n.º 7
0
        public static string[] GetLocalizationsForPreferences(string[] locArray, string[] prefArray)
        {
            if (locArray == null)
                throw new ArgumentNullException ("locArray");
            if (prefArray == null)
                throw new ArgumentNullException ("prefArray");

            var cfLocal = new CFString [locArray.Length];
            for (int index = 0; index < locArray.Length; index++) {
                cfLocal [index] = new CFString (locArray [index]);
            }

            var cfPref = new CFString [prefArray.Length];
            for (int index = 0; index < prefArray.Length; index++) {
                cfPref [index] = new CFString (prefArray [index]);
            }

            using (CFArray cfLocalArray = CFArray.FromNativeObjects (cfLocal),
                       cfPrefArray = CFArray.FromNativeObjects (cfPref))
            using (var cfArray = new CFArray (CFBundleCopyLocalizationsForPreferences (cfLocalArray.Handle, cfPrefArray.Handle), true)) {
                var cultureInfo = new string [cfArray.Count];
                for (int index = 0; index < cfArray.Count; index ++) {
                    cultureInfo [index] = CFString.FetchString (cfArray.GetValue (index));
                }
                return cultureInfo;
            }
        }
Exemplo n.º 8
0
 public static string[] GetSelectedLanguages(MACaptionAppearanceDomain domain)
 {
     using (var langs = new CFArray (MACaptionAppearanceCopySelectedLanguages ((int) domain), owns: true)) {
         var languages = new string [langs.Count];
         for (int i = 0; i < langs.Count; i++) {
             languages[i] = CFString.FetchString (langs.GetValue (i));
         }
         return languages;
     }
 }
Exemplo n.º 9
0
 public CGImageMetadataTag[] GetQualifiers()
 {
     IntPtr result = CGImageMetadataTagCopyQualifiers (Handle);
     if (result == IntPtr.Zero)
         return null;
     using (var a = new CFArray (result)) {
         CGImageMetadataTag[] tags = new CGImageMetadataTag [a.Count];
         for (int i = 0; i < a.Count; i++)
             tags [i] = new CGImageMetadataTag (a.GetValue (i), true);
         return tags;
     }
 }
Exemplo n.º 10
0
        void EventsCallback(IntPtr handle, IntPtr userData, nint numEvents,
            IntPtr eventPaths, IntPtr eventFlags, IntPtr eventIds)
        {
            if (numEvents == 0) {
                return;
            }

            var events = new FSEvent[numEvents];
            var pathArray = new CFArray (eventPaths);

            for (int i = 0; i < events.Length; i++) {
                events[i].Flags = (FSEventStreamEventFlags)(uint)Marshal.ReadInt32 (eventFlags, i * 4);
                events[i].Id = (uint)Marshal.ReadInt64 (eventIds, i * 8);
                using (var cfstr = new CFString (pathArray.GetValue (i))) {
                    events[i].Path = cfstr.ToString ();
                }
            }

            OnEvents (events);
        }
Exemplo n.º 11
0
        public NSUrl[] GetResourceUrls(string resourceType, string subDirName, string localizationName)
        {
            if (String.IsNullOrEmpty (resourceType))
                throw new ArgumentException ("resourceType");

            if (String.IsNullOrEmpty (localizationName))
                throw new ArgumentException ("localizationName");

            using (CFString cfType = new CFString (resourceType),
                            cfDirName = new CFString (subDirName ?? string.Empty),
                    cfLocalization = new CFString (localizationName))
            using (var cfArray = new CFArray (CFBundleCopyResourceURLsOfTypeForLocalization (handle, cfType.Handle,
                                                     String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfDirName.Handle,
                                                     cfLocalization.Handle), true)) {
                var urls = new NSUrl [cfArray.Count];
                for (int index = 0; index < cfArray.Count; index++) {
                    urls [index] = Runtime.GetNSObject<NSUrl> (cfArray.GetValue (index), true);
                }
                return urls;
            }
        }
Exemplo n.º 12
0
 public static NSString[] GetPreferredCaptioningMediaCharacteristics(MACaptionAppearanceDomain domain)
 {
     using (var chars = new CFArray (MACaptionAppearanceCopyPreferredCaptioningMediaCharacteristics ((int) domain), owns: true)) {
         NSString [] characteristics = new NSString [chars.Count];
         for (int i = 0; i < chars.Count; i++) {
             characteristics[i] = new NSString (chars.GetValue (i));
         }
         return characteristics;
     }
 }
Exemplo n.º 13
0
 public static string[] GetLocalizations(NSUrl bundle)
 {
     if (bundle == null)
         throw new ArgumentNullException ("bundle");
     using (var cfArray = new CFArray (CFBundleCopyLocalizationsForURL (bundle.Handle), true)) {
         var cultureInfo = new string [cfArray.Count];
         for (int index = 0; index < cfArray.Count; index++) {
             cultureInfo [index] = CFString.FetchString (cfArray.GetValue (index));
         }
         return cultureInfo;
     }
 }
Exemplo n.º 14
0
 public static CFBundle[] GetBundlesFromDirectory(NSUrl directoryUrl, string bundleType)
 {
     if (directoryUrl == null) // NSUrl cannot be "" by definition
         throw new ArgumentNullException ("directoryUrl");
     if (String.IsNullOrEmpty (bundleType))
         throw new ArgumentException ("bundleType");
     using (var bundleTypeCFSting = new CFString (bundleType))
     using (var cfBundles = new CFArray (CFBundleCreateBundlesFromDirectory (IntPtr.Zero, directoryUrl.Handle, bundleTypeCFSting.Handle), true)) {
         var managedBundles = new CFBundle [cfBundles.Count];
         for (int index = 0; index < cfBundles.Count; index++) {
             // follow the create rules, therefore we do have ownership of each of the cfbundles
             managedBundles [index] = new CFBundle (cfBundles.GetValue (index), true);
         }
         return managedBundles;
     }
 }
Exemplo n.º 15
0
 public static CFBundle[] GetAll()
 {
     using (var cfBundles = new CFArray (CFBundleGetAllBundles ())) {
         var managedBundles = new CFBundle [cfBundles.Count];
         for (int index = 0; index < cfBundles.Count; index++) {
             // follow the get rule, we do not own the object
             managedBundles [index] = new CFBundle (cfBundles.GetValue (index), false);
         }
         return managedBundles;
     }
 }
Exemplo n.º 16
0
        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;
            }
        }
Exemplo n.º 17
0
 public override void Dispose(CTParagraphStyleSettingValue[] values, int index)
 {
     values [index].pointer = IntPtr.Zero;
     value.Dispose ();
     value = null;
 }
Exemplo n.º 18
0
 public CTParagraphStyleSpecifierIntPtrsValue(CTParagraphStyleSpecifier spec, IntPtr[] value)
     : base(spec)
 {
     this.value = CFArray.FromIntPtrs (value);
 }
Exemplo n.º 19
0
        public static string[] GetPreferredLocalizations(string[] locArray)
        {
            if (locArray == null)
                throw new ArgumentNullException ("locArray");

            var cfString = new CFString [locArray.Length];
            for (int index = 0; index < locArray.Length; index++) {
                cfString [index] = new CFString (locArray [index]);
            }
            using (var cfLocArray = CFArray.FromNativeObjects (cfString))
            using (var cfArray = new CFArray (CFBundleCopyPreferredLocalizationsFromArray (cfLocArray.Handle), true)) {
                var cultureInfo = new string [cfArray.Count];
                for (int index = 0; index < cfArray.Count; index++) {
                    cultureInfo [index] = CFString.FetchString (cfArray.GetValue (index));
                }
                return cultureInfo;
            }
        }
Exemplo n.º 20
0
        public NSUrl[] GetResourceUrls(string resourceType, string subDirName)
        {
            if (String.IsNullOrEmpty (resourceType))
                throw new ArgumentException ("resourceName");

            using (CFString cfResourceType = new CFString (resourceType),
                    cfSubDir = new CFString (subDirName ?? string.Empty))
            using (var cfArray = new CFArray (CFBundleCopyResourceURLsOfType (handle, cfResourceType.Handle,
                                             String.IsNullOrEmpty (subDirName) ? IntPtr.Zero : cfSubDir.Handle), true)) {
                var result = new NSUrl [cfArray.Count];
                for (int index = 0; index < cfArray.Count; index++) {
                    result [index] = Runtime.GetNSObject<NSUrl> (cfArray.GetValue (index), true);
                }
                return result;
            }
        }
Exemplo n.º 21
0
 public CGPDFStream[] GetStreams()
 {
     using (CFArray a = new CFArray (CGPDFContentStreamGetStreams (Handle))) {
         var streams = new CGPDFStream [a.Count];
         for (int i = 0; i < a.Count; i++)
             streams [i] = new CGPDFStream (a.GetValue (i));
         return streams;
         // note: CGPDFStreamRef is weird because it has no retain/release calls unlike other CGPDF* types
     }
 }
Exemplo n.º 22
0
        public static CTFontDescriptor[] GetFonts(NSUrl url)
        {
            if (url == null)
                throw new ArgumentNullException ("url");

            var arrayPtr = CTFontManagerCreateFontDescriptorsFromURL (url.Handle);
            if (arrayPtr == IntPtr.Zero)
                return new CTFontDescriptor [0];

            using (var unmanageFonts = new CFArray (arrayPtr, true)) {
                var managedFonts = new CTFontDescriptor [unmanageFonts.Count];
                for (int index = 0; index < unmanageFonts.Count; index++) {
                    managedFonts [index] = new CTFontDescriptor (unmanageFonts.GetValue (index), false);
                }
                return managedFonts;
            }
        }