From cebb745116a3a6507e4b5cbc4e64773814381bc2 Mon Sep 17 00:00:00 2001 From: Dominique Louis Date: Wed, 8 May 2019 19:39:55 +0100 Subject: [Mac] Setting the Formatter by default breaks the RatioEditor rendering. --- .../Controls/RatioEditorControl.cs | 9 ++------ Xamarin.PropertyEditing.Mac/Extensions.cs | 24 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 7 deletions(-) create mode 100644 Xamarin.PropertyEditing.Mac/Extensions.cs (limited to 'Xamarin.PropertyEditing.Mac') diff --git a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs index 2fd4404..7591c2b 100644 --- a/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs +++ b/Xamarin.PropertyEditing.Mac/Controls/RatioEditorControl.cs @@ -15,13 +15,8 @@ namespace Xamarin.PropertyEditing.Mac { base.TranslatesAutoresizingMaskIntoConstraints = false; - this.ratioEditor = new RatioEditor (hostResources) { - AllowNegativeValues = false, - AllowRatios = true, - BackgroundColor = NSColor.Clear, - StringValue = string.Empty, - TranslatesAutoresizingMaskIntoConstraints = false, - }; + this.ratioEditor = new RatioEditor (hostResources); + this.ratioEditor.SetFormatter (null); // update the value on keypress this.ratioEditor.ValueChanged += (sender, e) => { diff --git a/Xamarin.PropertyEditing.Mac/Extensions.cs b/Xamarin.PropertyEditing.Mac/Extensions.cs new file mode 100644 index 0000000..de9fdce --- /dev/null +++ b/Xamarin.PropertyEditing.Mac/Extensions.cs @@ -0,0 +1,24 @@ +using System; +using System.Runtime.InteropServices; +using AppKit; +using Foundation; + +namespace Xamarin.PropertyEditing.Mac +{ + internal static class Extensions + { + internal const string LIBOBJC_DYLIB = "/usr/lib/libobjc.dylib"; + + [DllImport (LIBOBJC_DYLIB, EntryPoint = "objc_msgSend")] + public extern static void void_objc_msgSend_intptr (IntPtr receiver, IntPtr selector, IntPtr arg1); + + const string selSetFormatter = "setFormatter:"; + static readonly IntPtr selSetFormatter_Handle = ObjCRuntime.Selector.GetHandle (selSetFormatter); + + internal static void SetFormatter (this NumericSpinEditor control, NSFormatter formatter) + { + IntPtr pointer = formatter != null ? formatter.Handle : IntPtr.Zero; + void_objc_msgSend_intptr (control.NumericEditor.Handle, selSetFormatter_Handle, pointer); + } + } +} -- cgit v1.2.3