Bug 23059 - NSControlTextFilter delegate signature is incorrect
Summary: NSControlTextFilter delegate signature is incorrect
Alias: None
Product: Xamarin.Mac
Classification: Desktop
Component: Library (Xamarin.Mac.dll) ()
Version: 1.10.0
Hardware: Macintosh Mac OS
: Normal normal
Target Milestone: ---
Assignee: Chris Hamons
Depends on:
Reported: 2014-09-16 12:38 UTC by Bart King
Modified: 2014-11-13 09:49 UTC (History)
3 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Bart King 2014-09-16 12:38:57 UTC
In Xamarin.Mac (XamMac.dll), there is a delegate method defined that relates to the handling of auto-complete in an NSTextView.

This delegate is MonoMac.AppKit.NSControlTextFilter, which has the following signature:

namespace MonoMac.AppKit
	public delegate string[] NSControlTextFilter(NSControl control, NSTextView textView, string[] words, NSRange charRange, int index);

The problem is that it is incorrect - the index field at the end is defined as "int" - a read-only variable. AppKit defines this as NSInteger* - a read AND write variable:

- (NSArray *)control:(NSControl *)control textView:(NSTextView *)textView completions:(NSArray *)words forPartialWordRange:(NSRange)charRange indexOfSelectedItem:(NSInteger *)index

Without this delegate being correct, it is not possible to offer a list of options in an auto-complete text field that has no pre-selected option.  To quote the Apple documentation for the index property:

On input, an integer variable with the default value of 0. On output, you can set this value to an index in the returned array indicating which item should be selected initially. **Set the value to -1 to indicate there should not be an initial selection.**

To resolve, please change the delegate to use the following signature:

public delegate string[] NSControlTextFilter(NSControl control, NSTextView textView, string[] words, NSRange charRange, out int index);

The workaround at the moment is to create a new NSTextViewDelegate override that has the correct Export and delegate signatures, but this prevents using the delegate provided by the Xamarin.Mac framework, and not able to override functionality of NSTextView (they are properties, not virtual methods).

System info:

=== Xamarin Studio ===

Version 5.4 (build 236)
Installation UUID: 9dd87291-364d-4d2e-8a10-1993eee3b90e
	Mono 3.8.0 ((no/45d0ba1)
	GTK+ 2.24.23 (Raleigh theme)

	Package version: 308000009

=== Apple Developer Tools ===

Xcode 5.1.1 (5085)
Build 5B1008

=== Xamarin.iOS ===

Version: (Business Edition)
Hash: 921d22f
Build date: 2014-09-15 09:22:23-0400

=== Xamarin.Android ===

Version: 4.16.0 (Business Edition)
Android SDK: /Users/demon/Library/Developer/Xamarin/android-sdk-mac_x86
	Supported Android versions:
		2.3   (API level 10)
		4.0   (API level 14)
		4.0.3 (API level 15)
		4.3   (API level 18)
		4.4   (API level 19)
Java SDK: /usr
java version "1.6.0_65"
Java(TM) SE Runtime Environment (build 1.6.0_65-b14-462-11M4609)
Java HotSpot(TM) 64-Bit Server VM (build 20.65-b04-462, mixed mode)

=== Xamarin.Mac ===

Version: (Business Edition)

=== Build Information ===

Release ID: 504000236
Git revision: 7919b7498c2fbd22aa2f8beb7f5df597eceb742b
Build date: 2014-09-15 12:51:03-04
Xamarin addins: 209babcde541bd7445544f0a7bbd1b926e918297

=== Operating System ===

Mac OS X 10.9.4
Darwin tempest.local 13.3.0 Darwin Kernel Version 13.3.0
    Tue Jun  3 21:27:35 PDT 2014
    root:xnu-2422.110.17~1/RELEASE_X86_64 x86_64
Comment 1 Ram Chandra 2014-10-30 06:00:22 UTC
I have checked the definition of "NSControlTextFilter" delegate in assembly browser and observed that the index field declare as integer type.

Definition of "NSControlTextFilter" delegate in "AppKit" namespace:

public delegate string[] NSControlTextFilter(NSControl control, NSTextView textView, string[] words, NSRange charRange, int index);

Screencast: http://www.screencast.com/t/LlumXFlS

I’ll need confirmation from the developer if this is a bug.  Leaving as NEW for now.

Environment Info:

Mac OS X 10.10.0
Xamarin Studio: 5.5.3 (build 6)
Mono 3.10.0 ((detached/e204655)
GTK+ 2.24.23 (Raleigh theme)
Xcode 6.0.1 (6528)
Xamarin.Mac: (Business Edition)

=== Build Information ===

Release ID: 505030006
Git revision: fbe3e9453daf6a3bb9a9709ed22bec35f7c9056b
Build date: 2014-10-23 13:08:38-04
Xamarin addins: e44add2b39de4dd57c0742bb2e620dfad84c64c6
Comment 2 Chris Hamons 2014-11-13 09:49:36 UTC
Fixed in master 87147a57683c73765b747bb15d56dc66b50d254a. Verified by a simple test app which was too hard to automate.

Thanks for the report!