Component::focusLost() in the parent Component

Hello. I have two components, A and B, with hundreds of juce widgets. When A or B gains/losts the keyboard focus it gets repainted.

If A is focused, and one of his children components gains the focus A::focusLost() is called (and I’d paint it using Component::hasKeyboardFocus(true)), but then if I swich to B, A::focusLost() won’t be called (just A::childComp::focusLost()) , and A won’t be repainted.

Is it possible to call A::focusLost() when none of A’s children neither A have the focus?

the focus behaviour there looks correct. However, if you need to repaint A when a child loses the focus, can you have the child component signal repaint to the parent.

ie override Component::focusGained and focusLost and make them do that you want.

That means I might redefine all juce widgets overriding their focusGained() and focusLost(), and add a pointer to the parent (or grand-parent) I want to repaint. Too messy.

Must be something simpler and less alike spaghetti code, isn’t it?

See the FocusChangeListener class?

Yes, that did the trick, however I was expecting something like to a function in Component that could deal with that.

Anyway I post the code here, maybe someone can need it:

[code]class A: public Component,
public FocusChangeListener
virtual void globalFocusChanged(Component* focusedComponent);

bool m_bIHaveTheFocus;



void A::globalFocusChanged(Component* focusedComponent)
Component* comp = focusedComponent;

bool IhaveFocus = false;

while (comp != 0)
if (comp == this)
IhaveFocus = true;
comp = 0;
comp = comp->getParentComponent();

if (IhaveFocus != m_bIHaveTheFocus)
m_bIHaveTheFocus = IhaveFocus;