public bool EnsureTextInputImplemented(NSView view = null) { view = view ?? TextInputControl; // determine whether we need to call InterpretKeyEvents ourselves or if it is already handled by the super class (e.g. NSTextView) // for NSTextField (TextBox, etc), we handle the TextInput event via MacFieldEditor TextInputImplemented = !ObjCExtensions.ClassConformsToProtocol(view.GetSuperclass(), MacViewTextInput.NSTextInputClientProtocol_Handle); // if it already conforms to the protocol, add the insertText:replacementRange method only if (view.ConformsToProtocol(MacViewTextInput.NSTextInputClientProtocol_Handle)) { AddMethod(MacView.selInsertTextReplacementRange, MacView.TriggerTextInput_Delegate, EtoEnvironment.Is64BitProcess ? "v@:@{NSRange=QQ}" : "v@:@{NSRange=II}"); return(false); } // Debug.WriteLine($"Adding TextInputClient to {view.GetType()}, Widget: {Widget.GetType()}"); // add the NSTextInputClient protocol to the class var cls = Class.GetHandle(view.GetType()); ObjCExtensions.ClassAddProtocol(cls, MacViewTextInput.NSTextInputClientProtocol_Handle); // add required methods for the NSTextInputClient protocol AddMethod(MacViewTextInput.HasMarkedText_Selector, MacViewTextInput.HasMarkedText_Delegate, "B@:", view); AddMethod(MacViewTextInput.MarkedRange_Selector, MacViewTextInput.MarkedRange_Delegate, "{NSRange=QQ}@:", view); AddMethod(MacViewTextInput.SelectedRange_Selector, MacViewTextInput.SelectedRange_Delegate, "{NSRange=QQ}@:", view); AddMethod(MacViewTextInput.SetMarkedText_Selector, MacViewTextInput.SetMarkedText_Delegate, "v@:@{NSRange=QQ}{NSRange=QQ}", view); AddMethod(MacViewTextInput.UnmarkText_Selector, MacViewTextInput.UnmarkText_Delegate, "v@:", view); AddMethod(MacViewTextInput.ValidAttributesForMarkedText_Selector, MacViewTextInput.ValidAttributesForMarkedText_Delegate, "@@:", view); AddMethod(MacViewTextInput.AttributedStringForProposedRange_Selector, MacViewTextInput.AttributedStringForProposedRange_Delegate, "@@:{NSRange=QQ}^{NSRange=QQ}", view); AddMethod(MacViewTextInput.CharacterIndexForPoint_Selector, MacViewTextInput.CharacterIndexForPoint_Delegate, "Q@:{CGPoint=gg}", view); AddMethod(MacViewTextInput.FirstRectForCharacterRange_Selector, MacViewTextInput.FirstRectForCharacterRange_Delegate, "{CGRect=gggg}@:{NSRange=QQ}^{NSRange=QQ}", view); AddMethod(MacViewTextInput.DoCommandBySelector_Selector, MacViewTextInput.DoCommandBySelector_Delegate, "v@:#", view); AddMethod(MacView.selInsertTextReplacementRange, MacView.TriggerTextInput_Delegate, "v@:@{NSRange=QQ}", view); return(true); }