setInterceptsMouseClicks() question

I’m coding a Piano Roll editor. The notes inside the editor are Components. I want the mouse clicks to pass thru them, so I use setInterceptsMouseClicks(false, false) with the notes.

Problem: when using setInterceptsMouseClicks(false, false) the note components also don’t receive any mouseEnter() mouseExit() anymore…

What can I do to make them let the clicks pass thru, but still react to mouseEnter’s and mouseExit’s, and even possibly mouseMove’s ? Seems tricky to me.

The only possibility that comes to my mind is to “hardwire” mouseDown(), mouseUp(), mouseDrag() of the note component to the parent component’s respective mouseDown(), mouseUp() and mouseDrag() functions (with translation of the mouse coordinates of the MouseEvent, ofcourse).

There’s quite a few ways of approaching this.

My personal two picks would be either to:

  1. just register the parent component as a mouse listener for the child component. I.E. child->addMouseListener(this). That way the parent will get all mouse events that happen over the child, regardless of whether the child attempts to consume them.

  2. modify the child component such that it receives mouse events, but at the end of those it does not wish to consume, call Component::mouseExit(e) or whichever event is applicable. IIRC this’ll cause the events to trickle up the component stack as normal.

I did it as described above in my post, and it works, but there’s one exception:

When I press the right mouse button on a note component, it will be deleted. The problem is that as soon as it is deleted, there’s no receiver for the forthcoming mouse messages.
I would like the parent component to receive them, so the user could let the mouse knob pressed and drag over further notes to delete them. But I don’t see how to do this without starting to hack with a Timer or so…

It’s a fiddly thing to do - I think in the tracktion piano roll I avoided using components for the blobs, and just drew them manually in the parent component.

I searched for the drag problem and found this thread.

One solution, based on information found here might be this: