Replace dynamic cast with a virtual GTKValueChanged() function

No real changes, but using a virtual function is simpler and safer than
using wxIsKindOf().
This commit is contained in:
Vadim Zeitlin
2021-04-20 00:53:50 +02:00
parent 3ac3763705
commit e73a0c23ef
2 changed files with 24 additions and 17 deletions

View File

@@ -71,6 +71,8 @@ public:
virtual GTKInputResult GTKInput(double* value) const = 0;
virtual bool GTKOutput(wxString* text) const = 0;
virtual void GTKValueChanged() = 0;
protected:
double DoGetValue() const;
double DoGetMin() const;
@@ -153,6 +155,7 @@ public:
virtual GTKInputResult GTKInput(double* value) const wxOVERRIDE;
virtual bool GTKOutput(wxString* text) const wxOVERRIDE;
virtual void GTKValueChanged() wxOVERRIDE;
protected:
virtual void GtkSetEntryWidth() wxOVERRIDE;
@@ -224,6 +227,7 @@ public:
virtual GTKInputResult GTKInput(double* value) const wxOVERRIDE;
virtual bool GTKOutput(wxString* text) const wxOVERRIDE;
virtual void GTKValueChanged() wxOVERRIDE;
protected:
virtual void GtkSetEntryWidth() wxOVERRIDE;

View File

@@ -37,27 +37,12 @@ extern bool g_blockEventsOnDrag;
extern "C" {
static void
gtk_value_changed(GtkSpinButton* spinbutton, wxSpinCtrlGTKBase* win)
gtk_value_changed(GtkSpinButton*, wxSpinCtrlGTKBase* win)
{
if (g_blockEventsOnDrag)
return;
if (wxIsKindOf(win, wxSpinCtrl))
{
wxSpinEvent event(wxEVT_SPINCTRL, win->GetId());
event.SetEventObject( win );
event.SetPosition(static_cast<wxSpinCtrl*>(win)->GetValue());
event.SetString(gtk_entry_get_text(GTK_ENTRY(spinbutton)));
win->HandleWindowEvent( event );
}
else // wxIsKindOf(win, wxSpinCtrlDouble)
{
wxSpinDoubleEvent event( wxEVT_SPINCTRLDOUBLE, win->GetId());
event.SetEventObject( win );
event.SetValue(static_cast<wxSpinCtrlDouble*>(win)->GetValue());
event.SetString(gtk_entry_get_text(GTK_ENTRY(spinbutton)));
win->HandleWindowEvent( event );
}
win->GTKValueChanged();
}
}
@@ -523,6 +508,15 @@ bool wxSpinCtrl::GTKOutput(wxString* text) const
return true;
}
void wxSpinCtrl::GTKValueChanged()
{
wxSpinEvent event(wxEVT_SPINCTRL, GetId());
event.SetEventObject( this );
event.SetPosition(GetValue());
event.SetString(GetTextValue());
HandleWindowEvent( event );
}
//-----------------------------------------------------------------------------
// wxSpinCtrlDouble
//-----------------------------------------------------------------------------
@@ -568,4 +562,13 @@ bool wxSpinCtrlDouble::GTKOutput(wxString* WXUNUSED(text)) const
return false;
}
void wxSpinCtrlDouble::GTKValueChanged()
{
wxSpinDoubleEvent event( wxEVT_SPINCTRLDOUBLE, GetId());
event.SetEventObject( this );
event.SetValue(GetValue());
event.SetString(GetTextValue());
HandleWindowEvent( event );
}
#endif // wxUSE_SPINCTRL