diff options
author | Marius Ungureanu <teromario@yahoo.com> | 2018-04-10 21:53:50 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-04-10 21:53:50 +0300 |
commit | 0b44a3d876ef4c2e4063579154bd49f7a56e49fd (patch) | |
tree | 4122c980aa45ee3f8465ba54c38ec93fab8efbff | |
parent | 078f7850685f2f69d1188437300395885590ddf6 (diff) |
Registrar fixes (#821)
* [Mac] Ensure Copy(NSZone) is overriden
This ensures that if AppKit clones the native cell we will be able to
create a new C# wrapper for it.
One known cause of this is when calculating the BaselineOffsetFromBottom.
This issue also affected the designers.
This is being added as a preventative as we may not actually be
triggering an API which clones the native object, but it's better to
be safe than sorry!
See https://github.com/mono/monodevelop/pull/4465
* [Mac] Fix build for XamMac 4.4
-rw-r--r-- | TestApps/XamMacTest/Info.plist | 2 | ||||
-rw-r--r-- | Xwt.XamMac/Xwt.Mac/LabelBackend.cs | 24 | ||||
-rw-r--r-- | Xwt.XamMac/Xwt.Mac/TextEntryBackend.cs | 23 |
3 files changed, 48 insertions, 1 deletions
diff --git a/TestApps/XamMacTest/Info.plist b/TestApps/XamMacTest/Info.plist index deb645ae..b305a41c 100644 --- a/TestApps/XamMacTest/Info.plist +++ b/TestApps/XamMacTest/Info.plist @@ -9,7 +9,7 @@ <key>CFBundleVersion</key> <string>1</string> <key>LSMinimumSystemVersion</key> - <string>10.6</string> + <string>10.7</string> <key>NSPrincipalClass</key> <string>NSApplication</string> </dict> diff --git a/Xwt.XamMac/Xwt.Mac/LabelBackend.cs b/Xwt.XamMac/Xwt.Mac/LabelBackend.cs index cab91899..ba87df67 100644 --- a/Xwt.XamMac/Xwt.Mac/LabelBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/LabelBackend.cs @@ -271,6 +271,30 @@ namespace Xwt.Mac { CGColor bgColor; + public CustomTextFieldCell () + { + } + + protected CustomTextFieldCell (IntPtr ptr) : base (ptr) + { + } + + /// <summary> + /// Like what happens for the ios designer, AppKit can sometimes clone the native `NSTextFieldCell` using the Copy (NSZone) + /// method. We *need* to ensure we can create a new managed wrapper for the cloned native object so we need the IntPtr + /// constructor. NOTE: By keeping this override in managed we ensure the new wrapper C# object is created ~immediately, + /// which makes it easier to debug issues. + /// </summary> + /// <returns>The copy.</returns> + /// <param name="zone">Zone.</param> + public override NSObject Copy(NSZone zone) + { + // Don't remove this override because the comment on this explains why we need this! + var newCell = (CustomTextFieldCell)base.Copy(zone); + newCell.bgColor = bgColor; + return newCell; + } + public void SetBackgroundColor (CGColor c) { bgColor = c; diff --git a/Xwt.XamMac/Xwt.Mac/TextEntryBackend.cs b/Xwt.XamMac/Xwt.Mac/TextEntryBackend.cs index e6d81734..fe11c70f 100644 --- a/Xwt.XamMac/Xwt.Mac/TextEntryBackend.cs +++ b/Xwt.XamMac/Xwt.Mac/TextEntryBackend.cs @@ -356,6 +356,29 @@ namespace Xwt.Mac } + protected CustomCell(IntPtr ptr) : base(ptr) + { + } + + /// <summary> + /// Like what happens for the ios designer, AppKit can sometimes clone the native `NSTextFieldCell` using the Copy (NSZone) + /// method. We *need* to ensure we can create a new managed wrapper for the cloned native object so we need the IntPtr + /// constructor. NOTE: By keeping this override in managed we ensure the new wrapper C# object is created ~immediately, + /// which makes it easier to debug issues. + /// </summary> + /// <returns>The copy.</returns> + /// <param name="zone">Zone.</param> + public override NSObject Copy(NSZone zone) + { + // Don't remove this override because the comment on this explains why we need this! + var newCell = (CustomCell)base.Copy(zone); + newCell.editor = editor; + newCell.selChangeObserver = selChangeObserver; + newCell.Context = Context; + newCell.EventSink = EventSink; + return newCell; + } + public override NSTextView FieldEditorForView (NSView aControlView) { if (editor == null) { |