Fixed some obvious errors with the event code and added a unit test to illustrate the problem.
Essentially the bug in Widget.sinkEvents(int) caused UiObject.sinkEvents(int) to be called with -1 resulting in listeners being added for every event type.
The other bugs prevented the event listeners and bitmasks from being recorded and retrieved properly.