public static bool UnregisterGraphicsFont(CGFont font, out NSError error) { if (font == null) { throw new ArgumentNullException("font"); } IntPtr h = IntPtr.Zero; bool ret; try { ret = CTFontManagerUnregisterGraphicsFont(font.Handle, out h); if (ret) { error = null; } else { error = new NSError(h); } } finally { if (h != IntPtr.Zero) { NSObject.DangerousRelease(h); } } return(ret); }
public static NSError RegisterFontsForUrl(NSUrl fontUrl, CTFontManagerScope scope) { if (fontUrl == null) { throw new ArgumentNullException("fontUrl"); } IntPtr error = IntPtr.Zero; try { if (CTFontManagerRegisterFontsForURL(fontUrl.Handle, scope, ref error)) { return(null); } else { return(Runtime.GetNSObject <NSError> (error)); } } finally { if (error != IntPtr.Zero) { NSObject.DangerousRelease(error); } } }
public static NSError [] RegisterFontsForUrl(NSUrl [] fontUrls, CTFontManagerScope scope) { if (fontUrls == null) { throw new ArgumentNullException("fontUrls"); } foreach (var furl in fontUrls) { if (furl == null) { throw new ArgumentException("contains a null entry", "fontUrls"); } } using (var arr = NSArray.FromNSObjects(fontUrls)) { IntPtr error_array = IntPtr.Zero; try { if (CTFontManagerRegisterFontsForURLs(arr.Handle, scope, ref error_array)) { return(null); } else { return(NSArray.ArrayFromHandle <NSError> (error_array)); } } finally { if (error_array != IntPtr.Zero) { NSObject.DangerousRelease(error_array); } } } }
public static IMTLDevice [] GetAllDevices() { var rv = MTLCopyAllDevices(); var devices = NSArray.ArrayFromHandle <IMTLDevice> (rv); NSObject.DangerousRelease(rv); return(devices); }
public static string CreateSharedWebCredentialPassword() { var handle = SecCreateSharedWebCredentialPassword(); var str = NSString.FromHandle(handle); NSObject.DangerousRelease(handle); return(str); }
static public SecStatusCode ImportPkcs12(NSData data, NSDictionary options, out NSDictionary[] array) { if (options == null) { throw new ArgumentNullException("options"); } IntPtr handle; SecStatusCode code = SecPKCS12Import(data.Handle, options.Handle, out handle); array = NSArray.ArrayFromHandle <NSDictionary> (handle); NSObject.DangerousRelease(handle); return(code); }
public static IMTLDevice [] GetAllDevices(MTLDeviceNotificationHandler handler, out NSObject observer) { var block_handler = new BlockLiteral(); block_handler.SetupBlockUnsafe(static_notificationHandler, handler); var rv = MTLCopyAllDevicesWithObserver(out var observer_handle, ref block_handler); var obj = NSArray.ArrayFromHandle <IMTLDevice> (rv); NSObject.DangerousRelease(rv); block_handler.CleanupBlock(); observer = Runtime.GetNSObject(observer_handle); NSObject.DangerousRelease(observer_handle); // Apple's documentation says "The observer out parameter is returned with a +1 retain count [...]." return(obj); }
static CFProxy[] ExecutePacCFRunLoopSourceBlocking(CreatePACCFRunLoopSource factory, out NSError outError) { var runLoop = CFRunLoop.Current; outError = null; // build a struct that will have all the needed info for the callback var pacCbData = new PACProxyCallbackData(); pacCbData.CFRunLoopPtr = runLoop.Handle; var pacDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pacCbData)); try { Marshal.StructureToPtr(pacCbData, pacDataPtr, false); var clientContext = new CFStreamClientContext(); clientContext.Info = pacDataPtr; using (var loopSource = new CFRunLoopSource(factory(ExecutePacCallback, ref clientContext))) using (var mode = new NSString("Xamarin.iOS.Proxy")) { runLoop.AddSource(loopSource, mode); runLoop.RunInMode(mode, double.MaxValue, false); runLoop.RemoveSource(loopSource, mode); } pacCbData = (PACProxyCallbackData)Marshal.PtrToStructure(pacDataPtr, typeof(PACProxyCallbackData)); // get data from the struct outError = pacCbData.Error; return(pacCbData.ProxyList); } finally { if (pacCbData.ProxyListPtr != IntPtr.Zero) { CFObject.CFRelease(pacCbData.ProxyListPtr); } if (pacCbData.ErrorPtr != IntPtr.Zero) { NSObject.DangerousRelease(pacCbData.ErrorPtr); } Marshal.FreeHGlobal(pacDataPtr); } }
static void AddStyles() { Style.Add <Main>(null, ctl => ctl.ClientChanged += (sender, e) => { if (NSProcessInfo.ProcessInfo.RespondsToSelector(Selector.FromHandle(selBeginActivity))) { // ensure we don't go to sleep when the server (or client) is running! (10.9) if (activityToken != null) { void_objc_msgSend_IntPtr(NSProcessInfo.ProcessInfo.Handle, selEndActivity, activityToken.Handle); activityToken.DangerousRelease(); activityToken = null; } bool enabled = ctl.Client != null; if (enabled) { var token = IntPtr_objc_msgSend_Int64_IntPtr(NSProcessInfo.ProcessInfo.Handle, selBeginActivity, (Int64)NSActivityOptions.UserInitiated, ActivityReason.Handle); if (token != IntPtr.Zero) { activityToken = new NSObject(token); activityToken.DangerousRetain(); } } } }); Style.Add <FormHandler>("main", handler => handler.Control.CollectionBehavior |= NSWindowCollectionBehavior.FullScreenPrimary); /*control.WillUseFullScreenPresentationOptions = (window, proposedOptions) => { * return NSApplicationPresentationOptions.FullScreen | NSApplicationPresentationOptions.AutoHideToolbar | NSApplicationPresentationOptions.AutoHideMenuBar | NSApplicationPresentationOptions.AutoHideDock; * };*/ Style.Add <ListBoxHandler>("fileList", handler => { handler.Scroll.BorderType = NSBorderType.NoBorder; handler.Control.SelectionHighlightStyle = NSTableViewSelectionHighlightStyle.SourceList; }); Style.Add <ApplicationHandler>("application", handler => handler.EnableFullScreen()); Style.Add <ScrollableHandler>("viewerPane", handler => { if (handler.Control.RespondsToSelector(new Selector("setScrollerKnobStyle:"))) { handler.Control.ScrollerKnobStyle = NSScrollerKnobStyle.Light; } }); Style.Add <ToolBarHandler>(null, handler => { handler.Control.DisplayMode = NSToolbarDisplayMode.Icon; }); Style.Add <ButtonToolItemHandler>(null, handler => { handler.UseStandardButton(false); }); Style.Add <CheckToolItemHandler>(null, handler => { handler.Control.MaxSize = new CGSize(16, 16); handler.Tint = Colors.Gray; }); }
static async Task <(CFProxy[] proxies, NSError error)> ExecutePacCFRunLoopSourceAsync(CreatePACCFRunLoopSource factory, CancellationToken cancellationToken) { CFProxy[] proxies = null; NSError outError = null; if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException("Operation was cancelled."); } await Task.Run(() => { // we need the runloop of THIS thread, so it is important to get it in the correct context var runLoop = CFRunLoop.Current; // build a struct that will have all the needed info for the callback var pacCbData = new PACProxyCallbackData(); pacCbData.CFRunLoopPtr = runLoop.Handle; var pacDataPtr = Marshal.AllocHGlobal(Marshal.SizeOf(pacCbData)); try { Marshal.StructureToPtr(pacCbData, pacDataPtr, false); var clientContext = new CFStreamClientContext(); clientContext.Info = pacDataPtr; using (var loopSource = new CFRunLoopSource(factory(ExecutePacCallback, ref clientContext))) using (var mode = new NSString("Xamarin.iOS.Proxy")) { if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException("Operation was cancelled."); } cancellationToken.Register(() => { //if user cancels, we invalidte the source, stop the runloop and remove the source loopSource.Invalidate(); runLoop.RemoveSource(loopSource, mode); runLoop.Stop(); }); runLoop.AddSource(loopSource, mode); // blocks until stop is called, will be done in the cb set previously runLoop.RunInMode(mode, double.MaxValue, false); // does not raise an error if source is not longer present, so no need to worry runLoop.RemoveSource(loopSource, mode); } if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException("Operation was cancelled."); } pacCbData = (PACProxyCallbackData)Marshal.PtrToStructure(pacDataPtr, typeof(PACProxyCallbackData)); // get data from the struct proxies = pacCbData.ProxyList; outError = pacCbData.Error; } finally { // clean resources if (pacCbData.ProxyListPtr != IntPtr.Zero) { CFObject.CFRelease(pacCbData.ProxyListPtr); } if (pacCbData.ErrorPtr != IntPtr.Zero) { NSObject.DangerousRelease(pacCbData.ErrorPtr); } Marshal.FreeHGlobal(pacDataPtr); } }, cancellationToken).ConfigureAwait(false); if (cancellationToken.IsCancellationRequested) { throw new OperationCanceledException("Operation was cancelled."); } return(proxies : proxies, error : outError); }
public static void ReleaseNative(IntPtr handle) { NSObject.DangerousRelease(handle); }