UI problem

I’m trying to solve a problem related to user interaction but can’t find a good solution:

In an application with multiple documents (same window class) the document window has a field which forces the user to enter a valid value. If invalid value or nothing is entered, the field prevent switching the focus to other elements.
That’s it, in the LostFocus event I force the focus again to the field AND I show red mark near the field.

The problem come when my application opens a new window: the current window deactivate and the field LostFocus event trigger showing the red mark. Which is not appropriate in this case.

Now I tried setting a flag in the Activate/Deactivate events of the window, but this doesn’t work because the Window.Deactivate event fires AFTER the TextField.LostFocus event.
So, my field can only know that it’s loosing the focus, but not WHY.

Ideas?

Thanks in advance for help.

I guess you could set a var when the activate/deactivate happens and check that var when your lostfocus fires.
Or maybe you can use the window function http://documentation.xojo.com/index.php/Window_Method to detect if the window your field is on still is the frontmost window?
That’s just two thoughts. Didn’t try any of this.

Dirk, thank you for trying, but, as I said the LostFocus event fires AFTER the Window.Deactivate. So It won’t work.

Regarding the detection of frontmost window this doesn’t work if I have only one window. I’m alteady doing this and works only when there are two or more.

Maybe I’m misunderstanding, but when you set a var on deactivate for instance mycurrentwindowactive=false
then wouldn’t this var already be set before the lostfocus, since the lostfocus fires after the deactivate as you said.
So then in lostfocus you’d be able to check mycurrentwindowactive to see it it was active?
Maybe I’m misunderstanding.

Reset a Tiimer in Activate/Deactivate events of the window. The ActionEvent of Timer update the UI.

[quote=42214:@Dirk Cleenwerck]Maybe I’m misunderstanding, but when you set a var on deactivate for instance mycurrentwindowactive=false
then wouldn’t this var already be set before the lostfocus, since the lostfocus fires after the deactivate as you said.
So then in lostfocus you’d be able to check mycurrentwindowactive to see it it was active?
Maybe I’m misunderstanding.[/quote]

Sorry, my fault: the Activate/Deactivate fires AFTER the LostFocus. So when I’m in the LostFocus event I don’t know yet if the window will deactivate.

I think this could be a solution. The problem is the field is self contained TextField subclass and doing this I have to implement part of its functionality outside (in the window instance).
But I will try, thanks.

Quick Sample HTH: https://dl.dropboxusercontent.com/u/103694210/UI_Sample.zip

Thanks!