Capture mouse events from childwindows

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Capture mouse events from childwindows

Post by sparhawk »

I added an left button event to my frame window, but since it is covered with the child windows, I never receive such an event. Is there some way to get mouse events regardless of the window? Or do I have to bind to all childwindows?
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7477
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Capture mouse events from childwindows

Post by ONEEYEMAN »

Hi,
Mouse events are not propagated up the chain.
You need to catch it at the highest level and send it yourself down the road.

What do you want it to be caught in the window and not the children level?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19158
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Capture mouse events from childwindows

Post by doublemax »

sparhawk wrote: Fri Apr 09, 2021 1:12 pm Or do I have to bind to all childwindows?
That depends on what you want to do. In most cases you probably want wxWindow::CaptureMouse()
https://docs.wxwidgets.org/trunk/classw ... 7ec85fcfef

If that's not sufficient for your task, you have to bind to all descendants, or filter the event at wxApp level.
https://docs.wxwidgets.org/trunk/classw ... ilter.html
Use the source, Luke!
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Capture mouse events from childwindows

Post by sparhawk »

doublemax wrote: Fri Apr 09, 2021 3:57 pm That depends on what you want to do. In most cases you probably want wxWindow::CaptureMouse()
https://docs.wxwidgets.org/trunk/classw ... 7ec85fcfef
I have seen that CaptureMouse method, but I'm not sure if this is the proper way to go. I would have to permanently keep the mouse captured, to receive all the events, but then, are they propagated to the correct windows, if I don't need them?

I'm working on that docking code, and for this I need to monitor mouse events. To find the current window I have to capture the mouse buttons, but according to the docs, the even will only be sent if the mouse is clicked in the client area of that window. So if the childwindow has i.E. a textctrl, then I wont see that mouseclick when it is entered there.
And if I understand that ClientArea constraint right, then I also wouldn't see a mouse click if it happens on the border, right?

I'll also check the AUI code, to see how this is handled there, but I don't want to draw decoration myself or similar. I would like to keep that as small as possible.
doublemax wrote: Fri Apr 09, 2021 3:57 pm If that's not sufficient for your task, you have to bind to all descendants, or filter the event at wxApp level.
https://docs.wxwidgets.org/trunk/classw ... ilter.html
I didn't know I can filter at the app level, I definitely will look into this as well. Thanks for that hint! :-D
sparhawk
Experienced Solver
Experienced Solver
Posts: 81
Joined: Tue May 21, 2013 8:08 am

Re: Capture mouse events from childwindows

Post by sparhawk »

At first I tried to bind to the child, but this becomes quite tedious, because I would have to keep track of all child windows and bind there as well. Attaching to wxApp solved my problem clean and nicely! \:D/
PB
Part Of The Furniture
Part Of The Furniture
Posts: 4204
Joined: Sun Jan 03, 2010 5:45 pm

Re: Capture mouse events from childwindows

Post by PB »

I can't say I understand what are you trying to do but FWIW, binding events from all child windows is pretty easy.

For example, see BindEnterAndLeaveWindow() method here: viewtopic.php?f=1&t=44771#p185127
Post Reply