I have a component that holds a child component.
This child component could have any internal component layout of its own.
I want my outer component to be able to respond to mouse clicks on the child component by selecting it. I’ve added the outer component as a mouseListener, and it gets clicks upon it fine. If i set it to want clicks on child components, then my callback does indeed get called when any children happen to be clicked on.
However, my problem is: I want to test that the click happened within the main child component. I can’t just say if (e.eventComponent == child), because it might be one of its children.
How can I perform this test? I could test it against the eventComponent’s parent too, but there may be many levels of depth in the child component.
I’ve tried this:
MouseEvent e2 (e.getEventRelativeTo (child));
if (child->contains(e2.x,e2.y))
{
jassertfalse;
}
but for some reason it doesn’t always work. It’s got an odd behaviour - it will respond if the click is at least child->getX() across the child, but not if it’s less. Weirder still, if i set a breakpoint on the ‘jassertfalse’ line, then it stops at the breakpoint when you would expect it to (if the click is indeed anywhere within the child). That sort of debugging conundrum is ridiculously headscratching [i can’t test to see if the values should be right there, because when i test - they are! and when i don’t test, they’re definitely not!]