Where did the Focus go?

I have a listbox that seems to lose focus at an inappropriate time…
but cannot figure out “who” is getting/stealing it…

Is there an way to determine where the focus goes when one object “loses” it? short of putting logging code in every possible “gotfocus” event

What about Listbox.LostFocus event? Does it fire?

AppKit has the notion of ‘firstResponder’

https://developer.apple.com/library/mac/documentation/Cocoa/Reference/ApplicationKit/Classes/NSWindow_Class/#//apple_ref/occ/instm/NSWindow/firstResponder

Returns the window’s first responder.

Declaration
SWIFT
var firstResponder: NSResponder { get }

I have seen it in MacOSLib.

I know when it gets lost… I need to know who “found” it after listbox lost it

Put a BREAK statement in LostFocus, then got forward step by step in the debugger until your out of LostFocus and then check the Focus property on the window.

just goes to a “loop” in debugger… no way to tell where it went

When does it lose focus ?
Are you editing the content ?

Create a Boolean property flag in the window, set it to True in the Listbox.LostFocus event after the BREAK statement.
In the window’s paint event, put:

If flag Then BREAK // Check the Focus property of the window here End

[quote=162928:@Norman Palardy]When does it lose focus ?
Are you editing the content ?[/quote]

Yes… this stems from a previous issue

I click a cell and call EDITCELL
something steals the focus, causing me to need to click the cell a 2nd time to restore focus

I am trying to find where the focus is going, so I perhaps can alter the code to keep it from going there, or change the timing of when it goes there.

[quote=162931:@Eli Ott]Create a Boolean property flag in the window, set it to True in the Listbox.LostFocus event after the BREAK statement.
In the window’s paint event, put:

If flag Then BREAK // Check the Focus property of the window here End[/quote]

I put that in all the windows that possible could be open… and it never happens

I had this once.
I added self.title = me.name to all the controls Gotfocus events

Another time, I found that the problem was that two controls close together were causing each other to refresh and the cursor never had a chance to appear.