Binding wxEVT_LEFT_DOWN doesn't work

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
stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Binding wxEVT_LEFT_DOWN doesn't work

Post by stegemma » Wed Oct 31, 2018 5:42 pm

Years ago, I've write a custom chessboard component, that worked well. After the last update to wxWidgets, the component doesn't see mouse events anymore. I don't use an event table but dynamically bind the events this way:

Code: Select all


class clsWxBoard : public wxControl
{
protected:
	virtual void OnPaint(wxPaintEvent& event);
	virtual void OnLeftDown(wxMouseEvent& event);
	virtual void OnLeftUp(wxMouseEvent& event);
	virtual void OnMouseMove(wxMouseEvent& event);
	virtual void OnClose(wxCloseEvent &event);
public:
	clsWxBoard();
	clsWxBoard(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxValidator &validator=wxDefaultValidator, const wxString &name=wxControlNameStr);
	virtual ~clsWxBoard();
	...other...
};


void clsWxBoard::BindEvents()
{
		Bind(wxEVT_PAINT, &clsWxBoard::OnPaint, this);
		Bind(wxEVT_LEFT_DOWN, &clsWxBoard::OnLeftDown, this);
		Bind(wxEVT_LEFT_UP, &clsWxBoard::OnLeftUp, this);
		Bind(wxEVT_MOTION, &clsWxBoard::OnMouseMove, this);
}

void clsWxBoard::OnLeftDown(wxMouseEvent& event)
{
	...do something...
	event.Skip();
}

This function has been called by the costructor of the class. What is strange to me is that the wxEVT_PAINT event will be called but mouse events doesn't.

The control is created in gui.cpp (from wxFormBuilder):

Code: Select all

	bSizer121 = new wxBoxSizer( wxVERTICAL );
	
	m_board = new lwxBase::clsWxBoard( panBoard, wxID_LIGS_BOARD, wxDefaultPosition, wxSize(740, 740), 0 );
	m_board->Init();
	m_board->SetMinSize( wxSize( 600,600 ) );
	
	bSizer121->Add( m_board, 0, wxALL, 5 );
Really I don't know what to check, to make mouse events to be called.

stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Re: Binding wxEVT_LEFT_DOWN doesn't work - SOLVED

Post by stegemma » Wed Oct 31, 2018 5:55 pm

I've finally solved! The control were in this position of the form:

Code: Select all

wxBoxSizer
	wxSplitterWindow
		wxPanel
			wxBoxSizer
				CustomControl (clsWxBoard)

Moving the control outside the splitter let the mouse events to work:

Code: Select all

wxBoxSizer
	wxSplitterWindow
		wxPanel
			wxBoxSizer
	CustomControl (clsWxBoard)
Still I don't know why the mouse events work if the control is outside and not if inside the wxSplitter. All the controls are enabled... this is a mistery, for me. :?

Natulux
Filthy Rich wx Solver
Filthy Rich wx Solver
Posts: 223
Joined: Thu Aug 03, 2017 12:20 pm

Re: Binding wxEVT_LEFT_DOWN doesn't work

Post by Natulux » Thu Nov 08, 2018 9:14 am

I can't really answer, why exactly the splitter makes a difference, but I think I recognize your problem in general:
The mouse event might not be passed through your elements and therefore doesn't reach your element, which you bound your handler on.

For example: I used to have a frame as a splashOn-message, so there was a panel in that frame and a static text on top of that. I used BIND on the panel to set an event handler for mouse left down. But if I clicked in the space of the text, even though it's on the panel, I didn't get the event. I had to bind it to the static text, too. In my case, the text element caught the event, but had no handler for it and didn't pass it on to the parent (the panel).

Panel and splitter are both derived from wxWindow, the events are basically available. If you really wanted to have that splitter, I guess you would have to check, to which depth you can still receive events. Maybe it is enough, to bind (and skip) the mouse event to the splitter, too?

Best
Natu

Post Reply