focusGained() and focusLost() problem

Hi, I have a VST which has inside a component that can have lots of ResizableWindow (RW). Those RW have a content component inside. I need to keyboard-focus those RW, like any multiple window enviroment, and repaint the customized tittlebar (and more) depending if they have the focus or not. So I implemented something as simple as this:

[code]void DockWindow::focusGained(FocusChangeType /cause/)
{
repaint();
}

void DockWindow::focusLost(FocusChangeType /cause/)
{
repaint();
}
[/code]

However the windows dont work as expected. When you click on one of them, they call focusGained() on the clicked windows, and just right after that, focusLost() ON THE SAME WINDOWS (so the old window that has the focus isn’t repainted). Am I doing something wrong?

Thanks!

Note: I cannot use MultiDocumentPanel or DocumentWindow due to the high customization degree I need. And… I’m still using juce 1.52, I’ll upgrade soon.

Well, it’d make no sense for me to look into a problem like this unless you’re on the very latest version.

Done, i’ve updated with Introjucer, and i’ve done the pertinents changes in my code, discarding all obsololete Juce code I had.

The problem persist: when I click on any ResizableWindow, it calls to its FocusGained() and then its FocusLost(), instead calling the FocusLost() of the window that has the keyboard focus and then the FocusGained on the clicked window. Please, what am I missing?

Did you read my warning in the comment for ResizableWindow::resized() ?

Yes, but i didn’t reimplement it (if you’re talking about the call to ResizableWindow::resized). The content component hasn’t a setWantsKeyboardFocus(true) either. What i noticed is that when i click on the RW’s resizable border there is a call to focusGained() but there isnt any call to any focusLost() from any RW

(Sorry, I was talking crap… trying to do several things at once and misread your post…)

In fact, what you probably really want to use is TopLevelWindow::activeWindowStatusChanged ?

I also thought on activeWindows, however i cannot:

I have an enviroment like Visual Studio, where you can add all the ResizableWindow you want, arrange and dock them. Some of these ResizableWindow are toolbars, and others are just windows (i.e.: piano roll editors). A toolbar shouldn’t be focused if I use any control of them (editors would be unfocused then, and that’s is weird).

There isn’t any way to prevent that a ResizableWindow takes the activewindow flag so I cannot prevent that toolbars be the activewindow. Then, I think that keyboard focus is the answer, however I have this problem with focusLost() function, that isn’t called for the Component that lose the focus.

The enviroment has setFocusContainer(true) in his constructor, and all ResizableWindow that act like a toolbar has setWantsKeyboardFocus(false). I’m sure i’m missing something, because i implemented a normal TextButton on RW’s custom tittlebar and it DOES lose the focus (it’s repainted, but not the rest of the titlebar or window). I think this little gif could give some light:

Uploaded with ImageShack.us

The window is repainted when focusGained() or focusLost() are called. In its paint method it just detect if it has the keyboard focus and just fillall with the proper color.

I’ve no idea. Why not use a global FocusChangeListener to monitor which comps are getting focused, and that might show you what’s going on.

I know what’s happening: native Juce TextButton and other child Buttons are stealing the focus. So when I click on any RW window it doesnt keep the focus.

How should I prevent this? Is dangerous to avoid that Button cannot have the focus?

Edit: The idea is that my TopLevelWindows must know when one of its childs components has the focus, and when no one of them has the focus (ie: another TopLevelWindows was clicked) it repaints itself. How should I achieve this?

Just use Component::hasKeyboardFocus (true)

Thanks you, i think that’s enough for my purpose :wink: