[Mono-dev] GotFocus/LostFocus in WinForms controls

Steven Boswell II ulatekh at yahoo.com
Sun Jul 29 22:24:55 UTC 2012


For a while now, I've noticed large incompatibilities between Mono's use of GetFocus/LostFocus events and .NET's.  I decided to look into it this weekend...and just ended up with more questions.

My test case is the search-form in our application; when the user double-clicks a search-result line, I bring-to-front the application window and then select the control containing the search-result.  It appears that this doesn't lead to a GotFocus event on the TextBox!  (I modified TextBox.cs so that its existing LostFocus event output to the console, and I added a GotFocus event-handler to do the same.)

Digging around, I came up with the enclosed patch as a proposed solution; it modified Control.Select() so that it looks like the Select() method near line 1283.  This led to the GotFocus event-handler getting called...followed by a small explosion of other WmSetFocus/WmKillFocus events that completely obliterated that.

The worst part is...these events seem to be coming from the X server.  In XplatUIX11.cs, around line 7315, I modified XSendEvent() so that it looked like the one near line 6544, i.e. so that I could put a breakpoint in it.  That breakpoint wasn't hit during the explosion of WmSetFocus/WmKillFocus events.  So Mono isn't generating those events; my only guess is that the X server is.

Here's the flow-of-control I managed to unearth with lots of stack-traces being dumped to the console:

1) My text-box gets a GotFocus event, from my call to Control.Select().
2) My text-box gets a LostFocus event, from a WmKillFocus message generated by an X event.
3) My text-box gets a GotFocus event, from a WmSetFocus message generated by an X event.
4) There's a WmActivate event, apparently from an X event, but I don't know what's being activated -- it doesn't hit any of my debug-output code.
5) There's another WmActivate event, apparently from an X event.
   It first deactivates my text-box, and activates "hSplitContainer" in my application's form.
   That leads to my text-box getting a LostFocus event.
   Then it deactivates "vSplitContainer" and activates "vSplitContainer" in container "hSplitContainer"...apparently 3 times in a row.
6) There's a WmActivate event, apparently from an X event, but I don't know what's being activated -- it doesn't hit any of my debug-output code.

I really have no idea how to make heads or tails of this.

Does anyone know how focusing/unfocusing is SUPPOSED to work in Mono under X11?

Steven Boswell
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120729/7e4470a5/attachment.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: mwf-Control-Select.patch
Type: application/octet-stream
Size: 707 bytes
Desc: not available
URL: <http://lists.ximian.com/pipermail/mono-devel-list/attachments/20120729/7e4470a5/attachment.obj>


More information about the Mono-devel-list mailing list