wxWidget mouse processing

  c++, wxwidgets

I use wxWidget-3.1.4 under windows 10
I try to process mouse events from my class.
Header class:

#include "wx/wxprec.h"
#include <wx/wfstream.h>


class MainWindow : public wxFrame
{
public:
   MainWindow(const wxString& title);

   void OnQuit(wxCommandEvent& event);
   void OnOpenImage(wxCommandEvent& WXUNUSED);
   void OnEditImage(wxCommandEvent& WXUNUSED);

   //will redirect mouse event to class ImageDrawing
   void OnMouseWheel(wxMouseEvent& event);
   void OnMouseMove(wxMouseEvent& event);
   void OnMouseDown(wxMouseEvent& event);
   void OnMouseUp(wxMouseEvent& event);
private:
   //wx Panel for drawing image
   wxPanel* m_background;
   wxImage* m_Image;
 ...
}; 

Cpp file:

MainWindow::MainWindow(const wxString& title): wxFrame(NULL, wxID_ANY, title)
{
    m_background = new wxPanel(this, wxID_ANY);
    m_background->Bind(wxEVT_PAINT, &MainWindow::OnPaint, this);
}
void MainWindow::OnQuit(wxCommandEvent& WXUNUSED(event))
{
    Close(true);
}

void MainWindow::OnOpenImage(wxCommandEvent& WXUNUSED(event))
{
    wxString file = OpenFileDialog("Open Image file", "png files (*.png)|*.png");
    openImage(file, true);
}

void MainWindow::OnEditImage(wxCommandEvent& WXUNUSED(event))
{
    wxString file = OpenFileDialog("Open Image file", "png files (*.png)|*.png");
    // some logic
}
void MainWindow::OnMouseWheel(wxMouseEvent& event)
{
    std::cout<<"OnMouseWheel(event)";
}
void MainWindow::OnMouseMove(wxMouseEvent& event)
{
    std::cout<<"OnMouseMove(event)";
}
void MainWindow::OnMouseDown(wxMouseEvent& event)
{
    std::cout<<"OnMouseDown(event)";
}
void MainWindow::OnMouseUp(wxMouseEvent& event)
{
    std::cout<<"OnMouseUp(event)";
}
wxBEGIN_EVENT_TABLE(MainWindow, wxFrame)
EVT_MENU(Minimal_Quit, MainWindow::OnQuit)
EVT_MENU(Open_Image, MainWindow::OnOpenImage)
EVT_MENU(Edit_Image, MainWindow::OnEditImage)

EVT_MOTION(MainWindow::OnMouseMove)
EVT_MOUSEWHEEL(MainWindow::OnMouseWheel)
EVT_LEFT_DOWN(MainWindow::OnMouseDown)
EVT_LEFT_UP(MainWindow::OnMouseUp)
EVT_RIGHT_DOWN(MainWindow::OnMouseDown)
EVT_RIGHT_UP(MainWindow::OnMouseUp)
wxEND_EVENT_TABLE()

the problem is that event menu works fine, also OnMouseWheel works, but all other mouse events are not working. Googling problem shows that a reason for this is because a parent component, in my case wxFrame is included some child, like wxPanel, and this child component could intercept events.
So why OnMouseWheel is working and all other is not. the same behaviour if I change wxFrame to wxPanel in event table and if I didn’t use m_background.

Source: Windows Questions C++

LEAVE A COMMENT