Event won't propagate on 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
beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Event won't propagate on Window

Post by beneficii » Mon Apr 30, 2018 1:09 am

I am using wxWigets 3.1.1 on Windows 10, with Visual Studio Community 2017. On the window in the bottom-left corner of the screen, when you press down on the left mouse key, it's supposed to trigger an event that calls MyFrame::OnLeftDown(). But the function never gets called.
Attachments
sfcTileMapEditor.zip
(14.63 KiB) Downloaded 11 times

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

Re: Event won't propagate on Window

Post by doublemax » Mon Apr 30, 2018 5:18 am

Mouse events don't propagate upwards in the window hierarchy. Only wxCommandEvents do.

You have to catch them in the control where they occur.
Use the source, Luke!

beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Re: Event won't propagate on Window

Post by beneficii » Mon Apr 30, 2018 8:23 am

EditWindowEvent inherits from wxCommandEvent. In addition, I just tried Bind() instead of the event table, and the event handler function MyFrame::OnLeftDown() still isn't called!

Is there something wrong in the way I've set up the events?

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

Re: Event won't propagate on Window

Post by doublemax » Mon Apr 30, 2018 11:31 am

For a test, try wxID_ANY for the ID in the event table. If it works then, you know that the ID is wrong.
Use the source, Luke!

beneficii
Earned some good credits
Earned some good credits
Posts: 111
Joined: Fri Nov 27, 2009 2:49 am

Re: Event won't propagate on Window

Post by beneficii » Mon Apr 30, 2018 11:38 am

Even using wxID_ANY in the event table, it does not work. I tried Bind() with it, too, and it still did not work.

I guess something's wrong with the way the events are declared or defined? The event-type is declared in EditWindow.h, and defined in EditWindowEvent.cpp.

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

Re: Event won't propagate on Window

Post by doublemax » Mon Apr 30, 2018 12:35 pm

Code: Select all

void EditWindow::OnMouseDown(wxMouseEvent& event) {
	EditWindowEvent ev(GetId(), myEVT_TILELEFTDOWN);
Order of wxEventType and ID is reversed here.
Use the source, Luke!

Post Reply