My project has a significant number of sliders which I would like to have a "right-click" function which will reset the slider back to its default values. I have looked through the wxSlider() class documentation but didn't see a "right-click" event. I have therefore subclassed the wxSlider() class and added a EVT_RIGHT_DOWN event. My code example is as follows and does actually work as designed. I would be grateful if somebody would look at this code and let me know if this is the correct way to subclass a wxWidgets control.
Many thanks
Amanda
Code: Select all
#ifndef UI__ASTROSLIDER_H
#define UI__ASTROSLIDER_H
// WX Headers
#include <wx/slider.h>
#include <wx/frame.h>
#include <wx/panel.h>
// Class Definition
class sub_wxSlider : public wxSlider
{
public:
sub_wxSlider(wxPanel *parent, int id, int value, int min, int max, wxFrame *f);
~sub_wxSlider();
void set_Control_Default(int default_value);
private:
int m_ID;
int m_Default_Value;
wxFrame *m_Event_Path;
DECLARE_EVENT_TABLE()
void on_click(wxMouseEvent& event);
};
#endif /* UI__ASTROSLIDER_H */
Code: Select all
#include "sub_wxSlider.h"
// Event table
BEGIN_EVENT_TABLE(sub_wxSlider, wxSlider)
EVT_RIGHT_DOWN(sub_wxSlider::on_click)
END_EVENT_TABLE()
// Constructor
sub_wxSlider::sub_wxSlider(wxPanel *parent, int id, int value, int min, int max, wxFrame *f)
: wxSlider(parent, id, value, min, max, wxDefaultPosition, wxDefaultSize, wxSL_HORIZONTAL)
{
m_Event_Path = f;
m_ID = id;
}
// Destructor
sub_wxSlider::~sub_wxSlider() { }
// Set default control values
void sub_wxSlider::set_Control_Default(int default_value)
{
m_Default_Value = default_value;
}
// Event Management
void sub_wxSlider::on_click(wxMouseEvent& WXUNUSED(event))
{
this->SetValue(m_Default_Value);
// Send event to the main class
wxCommandEvent e(wxEVT_COMMAND_TEXT_UPDATED, AstroDMx::ID_EVENT_RESET_CONTROL);
e.SetInt(m_ID);
m_Event_Path->GetEventHandler()->AddPendingEvent(e);
}