Not catching all mouse events with wxWidgets
Posted
by Stef
on Stack Overflow
See other posts from Stack Overflow
or by Stef
Published on 2010-03-24T18:14:15Z
Indexed on
2010/03/24
18:33 UTC
Read the original article
Hit count: 753
Hi I am am trying to catch mouse movements for a MouseOver function in an app created with Code::Blocks using the wxSmith plugin. I have stumbled upon a puzzling problem. EVT_MOUSEWHEEL calling the function in the EventTable works well, but all other macros have no result at all. And the mousewheel is not really want I want (I just used it to test...)
Here is a the basic problem code (mostly generated by the fantastic wxSmith plugin)
MouseMain.h
#include <wx/frame.h>
#include <wx/statusbr.h>
//*)
class MouseFrame: public wxFrame
{
public:
MouseFrame(wxWindow* parent,wxWindowID id = -1);
virtual ~MouseFrame();
private:
//(*Handlers(MouseFrame)
void OnQuit(wxCommandEvent& event);
void OnAbout(wxCommandEvent& event);
void OnButton1Click(wxCommandEvent& event);
void MouseOver(wxMouseEvent& event);
//*)
//(*Identifiers(MouseFrame)
static const long ID_BUTTON1;
static const long ID_STATICBITMAP1;
static const long ID_PANEL1;
static const long idMenuQuit;
static const long idMenuAbout;
static const long ID_STATUSBAR1;
//*)
//(*Declarations(MouseFrame)
wxButton* Button1;
wxStaticBitmap* StaticBitmap1;
wxPanel* Panel1;
wxStatusBar* StatusBar1;
//*)
DECLARE_EVENT_TABLE()
};
#endif // MOUSEMAIN_H
...and MouseMain.cpp
#include "wx_pch.h"
#include "MouseMain.h"
#include <wx/msgdlg.h>
//(*InternalHeaders(MouseFrame)
#include <wx/bitmap.h>
#include <wx/intl.h>
#include <wx/image.h>
#include <wx/string.h>
//*)
//helper functions
enum wxbuildinfoformat {
short_f, long_f };
wxString wxbuildinfo(wxbuildinfoformat format)
{
wxString wxbuild(wxVERSION_STRING);
if (format == long_f )
{
#if defined(__WXMSW__)
wxbuild << _T("-Windows");
#elif defined(__UNIX__)
wxbuild << _T("-Linux");
#endif
#if wxUSE_UNICODE
wxbuild << _T("-Unicode build");
#else
wxbuild << _T("-ANSI build");
#endif // wxUSE_UNICODE
}
return wxbuild;
}
//(*IdInit(MouseFrame)
const long MouseFrame::ID_BUTTON1 = wxNewId();
const long MouseFrame::ID_STATICBITMAP1 = wxNewId();
const long MouseFrame::ID_PANEL1 = wxNewId();
const long MouseFrame::idMenuQuit = wxNewId();
const long MouseFrame::idMenuAbout = wxNewId();
const long MouseFrame::ID_STATUSBAR1 = wxNewId();
//*)
BEGIN_EVENT_TABLE(MouseFrame,wxFrame)
EVT_RIGHT_DCLICK(MouseFrame::MouseOver)
EVT_MOUSEWHEEL(MouseFrame::MouseOver)
EVT_MOTION(MouseFrame::MouseOver)
EVT_RIGHT_DOWN(MouseFrame::MouseOver)
//(*EventTable(MouseFrame)
//*)
END_EVENT_TABLE()
MouseFrame::MouseFrame(wxWindow* parent,wxWindowID id)
{
//(*Initialize(MouseFrame)
wxMenuItem* MenuItem2;
wxMenuItem* MenuItem1;
wxMenu* Menu1;
wxMenuBar* MenuBar1;
wxFlexGridSizer* FlexGridSizer1;
wxMenu* Menu2;
Create(parent, id, wxEmptyString, wxDefaultPosition, wxDefaultSize, wxDEFAULT_FRAME_STYLE, _T("id"));
Panel1 = new wxPanel(this, ID_PANEL1, wxPoint(144,392), wxDefaultSize, wxTAB_TRAVERSAL, _T("ID_PANEL1"));
FlexGridSizer1 = new wxFlexGridSizer(0, 3, 0, 0);
Button1 = new wxButton(Panel1, ID_BUTTON1, _("TheButton"), wxDefaultPosition, wxDefaultSize, 0, wxDefaultValidator, _T("ID_BUTTON1"));
FlexGridSizer1->Add(Button1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
StaticBitmap1 = new wxStaticBitmap(Panel1, ID_STATICBITMAP1, wxNullBitmap, wxDefaultPosition, wxSize(159,189), wxSUNKEN_BORDER, _T("ID_STATICBITMAP1"));
FlexGridSizer1->Add(StaticBitmap1, 1, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5);
Panel1->SetSizer(FlexGridSizer1);
FlexGridSizer1->Fit(Panel1);
FlexGridSizer1->SetSizeHints(Panel1);
MenuBar1 = new wxMenuBar();
Menu1 = new wxMenu();
MenuItem1 = new wxMenuItem(Menu1, idMenuQuit, _("Quit\tAlt-F4"), _("Quit the application"), wxITEM_NORMAL);
Menu1->Append(MenuItem1);
MenuBar1->Append(Menu1, _("&File"));
Menu2 = new wxMenu();
MenuItem2 = new wxMenuItem(Menu2, idMenuAbout, _("About\tF1"), _("Show info about this application"), wxITEM_NORMAL);
Menu2->Append(MenuItem2);
MenuBar1->Append(Menu2, _("Help"));
SetMenuBar(MenuBar1);
StatusBar1 = new wxStatusBar(this, ID_STATUSBAR1, 0, _T("ID_STATUSBAR1"));
int __wxStatusBarWidths_1[1] = { -1 };
int __wxStatusBarStyles_1[1] = { wxSB_NORMAL };
StatusBar1->SetFieldsCount(1,__wxStatusBarWidths_1);
StatusBar1->SetStatusStyles(1,__wxStatusBarStyles_1);
SetStatusBar(StatusBar1);
Connect(ID_BUTTON1,wxEVT_COMMAND_BUTTON_CLICKED,(wxObjectEventFunction)&MouseFrame::OnButton1Click);
Connect(idMenuQuit,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MouseFrame::OnQuit);
Connect(idMenuAbout,wxEVT_COMMAND_MENU_SELECTED,(wxObjectEventFunction)&MouseFrame::OnAbout);
//*)
}
MouseFrame::~MouseFrame()
{
//(*Destroy(MouseFrame)
//*)
}
void MouseFrame::OnQuit(wxCommandEvent& event)
{
Close();
}
void MouseFrame::OnAbout(wxCommandEvent& event)
{
wxString msg = wxbuildinfo(long_f);
wxMessageBox(msg, _("Welcome to..."));
}
void MouseFrame::OnButton1Click(wxCommandEvent& event)
{
}
void MouseFrame::MouseOver(wxMouseEvent& event){
wxMessageBox(_("MouseOver event!"));
}
So my big question: Why are EVT_MOTION, EVT_RIGHT_DOWN or EVT_RIGHT_DCLICK not calling MouseFrame::MouseOver(wxMouseEvent& event) in the way EVT_MOUSEWHEEL does?
© Stack Overflow or respective owner