WM_MOUSEWHEEL event goes to wrong window Topic is solved

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
faradayent
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sat Dec 12, 2009 3:13 am

WM_MOUSEWHEEL event goes to wrong window

Post by faradayent » Tue Sep 10, 2013 5:09 am

I'm working on an application that combines the penguin and auidemo sample files. I've taken one of the notebook tabs and put a wxGLCanvas into it.

Works fine with one problem.

The center mouse wheel causes zoom in and zoom out when the application is first started. Great!

But if any window outside of the GLCanvas notebook page is clicked, and I then return by clicking in the GLCanvas page I no longer get the mousewheel event. I still get the opengl object rotation events (via mouse drag) so I can manipulate the object, but I can no longer zoom with the wheel.

I have verified that I'm getting the event in the windows handler wxWindowMSW::MSWWindowProc() in window.cpp. I have also verified that the mouse wheel event winds up going to wxFrame, not wxGLCanvas, even though I've clicked in the GLCanvas window before moving the wheel.

To summarize, after leaving GLCanvas and coming back GLCanvas receives mouse drag events, but mouse wheel events no longer make it.

I'm hoping for some insight on where / why the two different mouse event types are handled differently with respect to focus changes.

(Widgets 2.812 compiled with MinGW in Code::Blocks)

User avatar
doublemax
Moderator
Moderator
Posts: 15174
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WM_MOUSEWHEEL event goes to wrong window

Post by doublemax » Tue Sep 10, 2013 8:59 am

Try explicitly calling SetFocus() on the GLCanvas if you click it.
Use the source, Luke!

faradayent
Earned a small fee
Earned a small fee
Posts: 19
Joined: Sat Dec 12, 2009 3:13 am

Re: WM_MOUSEWHEEL event goes to wrong window

Post by faradayent » Tue Sep 10, 2013 1:47 pm

Thanks!

Yes, adding a SetFocus(); upon entering the GLCanvasA::OnMouse(wxMouseEvent& event) function causes the wheel event to be captured by the GLCanvas once again. Zoom in and out works.

Do you happen to know if this behavior is by design or an oversight? There are (at least) two situations here.

1. The user has gone to another window, then simply moves the mouse over the GLCanvas, not clicking in it. Simply moving the mouse over the GLCanvas causes mouse events (which go to the GLCanvas handler if over that window). I could see in this instance that you may not want to set the focus for mouse wheel back there yet.

2. The user has gone to another window, then comes back to the GLCanvas and clicks in it. I would think we'd want to direct wheel events to the GLCanvas in this case, always without having to do an explicit SetFocus.

What do you think?

(As an aside, it's interesting that zoom in the penguin sample never did work. I just happened to notice that it worked after I combined the apps)

User avatar
doublemax
Moderator
Moderator
Posts: 15174
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WM_MOUSEWHEEL event goes to wrong window

Post by doublemax » Tue Sep 10, 2013 2:00 pm

Under Windows, mouse wheel events always go to the control which has focus. E.g. if you open an Explorer window, move the mouse to another window and use the wheel, it will still scroll the Explorer window.

The problem with the GLCanvas is, that the user doesn't see if it has focus or not. Depending on your application, you could setfocus to the GLCanvas when your application gets activated (-> wxActivateEvent), when the mouse cursor enters the GLCanvas or if the user clicks into the window. That is up to you.
Use the source, Luke!

Post Reply