mono/xwt — pull request #298 by luiscubal (2014-03-08 16:35:56+00:00)
Title: Early support for text input event

This is merely intended to be a starting point.
This approach should be tested by someone with an Asian keyboard before being accepted/merged.

Currently, only the WPF backend supports this event, but a GTK/Mac implementation would be needed as well.

This included only the PreviewTextInput event (not the TextInput event). It seems to be enough for European Portuguese keyboard characters such as ã (`~` + `a`) but it might not be enough for other languages.

The problem this attempts to solve has been discussed in the mailing list ("Proposal for additional text editing features (notably TextInput event)"). Here is the relevant part of my email:

> Currently, XWT already features keydown/keyup events, but these are insufficient for the purposes of text insertion on custom controls.
> Some of the problems with this approach include:
>
> 1. It is cumbersome even for simple tasks (one has to keep a Key.A => 'A' dictionary and check if the shift modifier is pressed and check if caps lock is checked, etc.)
> 2. Since it is complex, it is fragile (different platforms can have subtly different conventions);
> 3. It fails for characters that require multiple key strokes to input - for instance, on a portuguese keyboard typing 'ã' requires first pressing the key '~' then pressing the key 'a'. Note that even if the window is out of focus when I press '~', if I then focus the window and press 'a' the result is 'ã'.
> 4. Probably more (IMEs? Speech recognition?)
>
> As such, key down/up is not an acceptable approach for this particular problem.
>
> On Windows, the standard solution for this problem is the text input event.
> Text input is an event ([WPF documentation](http://msdn.microsoft.com/en-us/library/system.windows.uielement.textinput%28v=vs.110%29.aspx)). The event args include a string containing the inserted text (usually, but not necessarily, containing a single char).
>
> I believe this is the best approach because:
>
> 1. It is incredibly easy. Just register the event and get the strings. Done.
> 2. It seems to be used by SDL as well ([documentation](http://wiki.libsdl.org/Tutorials/TextInput)), which suggests that it should be available on other platforms as well. However, SDL also features the SDL_StartTextInput function. Not sure how important that is on non-Windows platforms.
>
> There seems to be an extra issue - composition. I do not know how composition works, but both WPF and SDL mention it and it seems to require application cooperation, so this is likely important (and see also [SDL_SetTextInputRect](http://wiki.libsdl.org/SDL_SetTextInputRect)). I just don't know what it is for.