Mouse event help

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
ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Mouse event help

Post by ninja9578 » Fri Feb 06, 2009 5:04 pm

As you might know, I'm working on a picking routine, but I can't see to get the mouse information.

In my event table I have EVT_MOUSE_EVENTS(MyFrame::OnMouse)

Here is the callback

Code: Select all

void MyFrame::OnMouse(wxMouseEvent & event){
     wxMessageBox(_T("hello"),_T("Debug"), wxOK);
}
As far as my understanding goes, this callback should be called anytime I do anything, including moving the mouse and clicking. It never gets called, I've been clicking, dragging, and moving the mouse in my frame for a while. The only time it ever seems to get called is when I use the scroll wheel.

How do I get it to recognize left clicks and motions? I tried using EVT_MOTION and EVT_LEFT_UP, but that didn't work.

There is another wxWindow inside of MyFrame, but that shouldn't matter, should it?

Also, I'm left handed so I have my mouse buttons switched, will wxWidgets automatically detect that and switch the buttons, or is that something that I have to do?

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Re: Mouse event help

Post by Disch » Fri Feb 06, 2009 5:23 pm

ninja9578 wrote: There is another wxWindow inside of MyFrame, but that shouldn't matter, should it?
It does matter. Events will be sent to the topmost visible window. IE: the one being clicked on. If you have another window on your frame, events will be sent to that window instead (or to one of its children if you click on them).
Also, I'm left handed so I have my mouse buttons switched, will wxWidgets automatically detect that and switch the buttons, or is that something that I have to do?
I'm pretty sure this is an OS setting and nothing API related. So yeah this will be automatic.

EDIT:

To furhter clarify -- in your code, use the left button as the "primary" button even though it will be the right button on your mouse. The OS will swap left/right clicks before the events get sent to the program, so when you click on your right button, it will send an Left-button-down message.

ninja9578
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 236
Joined: Thu Jan 29, 2009 3:33 pm

Post by ninja9578 » Fri Feb 06, 2009 5:49 pm

Oh...

Then is there a way to get it to skip that window and come back to the frame? I used a built in wxWindow.

I guess I could create a child class of it and create an event table in it, but that would be some extra work.


I thought that is:

Code: Select all

wxCommandEvents and the objects of the derived classes are forwarded to the parent window and so on recursively by default
meant that if the other window doesn't handle the event, then it would get passed to my frame.

User avatar
Disch
Experienced Solver
Experienced Solver
Posts: 99
Joined: Wed Oct 17, 2007 2:01 am

Post by Disch » Fri Feb 06, 2009 6:09 pm

ninja9578 wrote: I guess I could create a child class of it and create an event table in it, but that would be some extra work.
This is the generally accepted approach. Derive a class from wxWindow and put that in your frame. You'd probably need/want to do this anyway so you can catch paint events and paint to this window.
I thought that is:

Code: Select all

wxCommandEvents and the objects of the derived classes are forwarded to the parent window and so on recursively by default
meant that if the other window doesn't handle the event, then it would get passed to my frame.
That's wxCommandEvent, not wxMouseEvent.

Post Reply