Custom Control message event handler not being called

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
Nefarious
Knows some wx things
Knows some wx things
Posts: 28
Joined: Fri Feb 24, 2017 8:23 pm

Custom Control message event handler not being called

Post by Nefarious »

I am just trying to figure this out so I can build a real control. I have a class that sub classes wxPanel.

at the end of the class definition for this class I added

Code: Select all

	wxDECLARE_EVENT_TABLE();
}
The event table for the class is simple and has one entry and and si_CONTROL_FREQUENCY_SLIDER is an enum at the top of the header file.

Code: Select all

wxBEGIN_EVENT_TABLE(siFrequencyControl, wxPanel)
EVT_SLIDER(siCONTROL_FREQUENCY_SLIDER, siFrequencyControl::OnFrequencySlider)
wxEND_EVENT_TABLE()
the constructor looks like this

Code: Select all

siFrequencyControl::siFrequencyControl(wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint &pos, const wxSize &size, long style, const wxString &name)
: wxPanel(parent, id, pos, size, style, name)
{
	wxSizer* pVSizer = new wxBoxSizer(wxVERTICAL);
		int mVal = 41;
	int mMin = 1;
	int mMax = 512;
	int flags = 0;
	mFrequencySlider = new wxSlider(this, siCONTROL_FREQUENCY_SLIDER, mVal, mMin, mMax, wxDefaultPosition, wxDefaultSize, flags);
	mFrequencySlider->SetMinClientSize(wxSize(300, 50));
	mFrequencySlider->SetMaxClientSize(wxSize(300, 50));

	pVSizer->Add(mFrequencySlider, 0, wxRIGHT, 0);

	SetSizer(pVSizer);
}
The event handler only looks at a constant and I set a break point on it and it seems to never get called.

Code: Select all

void siFrequencyControl::OnFrequencySlider(wxCommandEvent& event)
{
	int foo = 1;
}
Is there a way to look at the event tables at runtime to try to understand what might be going wrong.
ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 7458
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: Custom Control message event handler not being called

Post by ONEEYEMAN »

Hi,
Usual things apply:
1. wx version
2. OS/toolkit and their versions.
3. any specific (non-standard) configuration options.

and also
4. did you try to build and run widgets sample to reproduce?

Thank you.
User avatar
doublemax
Moderator
Moderator
Posts: 19114
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Custom Control message event handler not being called

Post by doublemax »

Worked for me, so the problem must lie somewhere else.

Code: Select all

#define siCONTROL_FREQUENCY_SLIDER 10001

class siFrequencyControl : public wxPanel
{
public:
  siFrequencyControl(wxWindow *parent, wxWindowID id, const wxString &label, const wxPoint &pos, const wxSize &size, long style, const wxString &name)
  : wxPanel(parent, id, pos, size, style, name)
  {
     wxSizer* pVSizer = new wxBoxSizer(wxVERTICAL);
     int mVal = 41;
     int mMin = 1;
     int mMax = 512;
     int flags = 0;
     mFrequencySlider = new wxSlider(this, siCONTROL_FREQUENCY_SLIDER, mVal, mMin, mMax, wxDefaultPosition, wxDefaultSize, flags);
     mFrequencySlider->SetMinClientSize(wxSize(300, 50));
     mFrequencySlider->SetMaxClientSize(wxSize(300, 50));

     pVSizer->Add(mFrequencySlider, 0, wxRIGHT, 0);

     SetSizer(pVSizer);
  };

  void OnFrequencySlider(wxCommandEvent& event)
  {
     wxLogDebug("slider event");
     event.Skip();
  };

protected:
  wxSlider *mFrequencySlider;

  wxDECLARE_EVENT_TABLE();
};

wxBEGIN_EVENT_TABLE(siFrequencyControl, wxPanel)
  EVT_SLIDER(siCONTROL_FREQUENCY_SLIDER, siFrequencyControl::OnFrequencySlider)
wxEND_EVENT_TABLE()
And BTW: This is how you should have prepared your code, so that it can be tested with a minimal amount of effort by just pasting it into the "minimal" sample.
Use the source, Luke!
Nefarious
Knows some wx things
Knows some wx things
Posts: 28
Joined: Fri Feb 24, 2017 8:23 pm

Re: Custom Control message event handler not being called

Post by Nefarious »

Thank you for the help.

I somehow got it to work, not sure what I did. The real questions is, is there a way to look at the event handler list and see what is defined for a wxWindow. If something is wrong, I haven't found a way to systematically look at the right things to get my app to execute properly.

If I have a code functioning problem in the future, I will use your technique for submitting.
Post Reply