wxSpinButton works ok with negative values
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@1838 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
20e85460c4
commit
6380910c1f
@ -549,7 +549,8 @@ m_text(NULL), m_notebook(NULL)
|
||||
m_spintext = new wxTextCtrl( panel, -1, "0", wxPoint(20,160), wxSize(80,-1) );
|
||||
#ifndef __WIN16__
|
||||
m_spinbutton = new wxSpinButton( panel, ID_SPIN, wxPoint(103,159), wxSize(-1,-1) );
|
||||
m_spinbutton->SetRange(0,100);
|
||||
m_spinbutton->SetRange(-10,30);
|
||||
m_spinbutton->SetValue(-5);
|
||||
#endif
|
||||
m_notebook->AddPage(panel, "wxGauge", FALSE, Image_Gauge);
|
||||
}
|
||||
@ -885,8 +886,14 @@ void MyPanel::OnSliderUpdate( wxCommandEvent &WXUNUSED(event) )
|
||||
void MyPanel::OnSpinUpdate( wxSpinEvent &event )
|
||||
{
|
||||
wxString value;
|
||||
value.sprintf( "%d", (int)event.GetPosition() );
|
||||
value.Printf( "%d", event.GetPosition() );
|
||||
m_spintext->SetValue( value );
|
||||
|
||||
value.Printf("Spin control range: (%d, %d), current = %d\n",
|
||||
m_spinbutton->GetMin(), m_spinbutton->GetMax(),
|
||||
m_spinbutton->GetValue());
|
||||
|
||||
m_text->AppendText(value);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
extern bool g_blockEventsOnDrag;
|
||||
|
||||
static const float sensitivity = 0.2;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// "value_changed"
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -35,7 +37,7 @@ static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *wi
|
||||
if (g_blockEventsOnDrag) return;
|
||||
|
||||
float diff = win->m_adjust->value - win->m_oldPos;
|
||||
if (fabs(diff) < 0.2) return;
|
||||
if (fabs(diff) < sensitivity) return;
|
||||
win->m_oldPos = win->m_adjust->value;
|
||||
|
||||
wxEventType command = wxEVT_NULL;
|
||||
@ -43,13 +45,13 @@ static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *wi
|
||||
float line_step = win->m_adjust->step_increment;
|
||||
float page_step = win->m_adjust->page_increment;
|
||||
|
||||
if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
|
||||
else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
|
||||
else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
|
||||
else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
|
||||
if (fabs(diff-line_step) < sensitivity) command = wxEVT_SCROLL_LINEDOWN;
|
||||
else if (fabs(diff+line_step) < sensitivity) command = wxEVT_SCROLL_LINEUP;
|
||||
else if (fabs(diff-page_step) < sensitivity) command = wxEVT_SCROLL_PAGEDOWN;
|
||||
else if (fabs(diff+page_step) < sensitivity) command = wxEVT_SCROLL_PAGEUP;
|
||||
else command = wxEVT_SCROLL_THUMBTRACK;
|
||||
|
||||
int value = (int)(win->m_adjust->value+0.5);
|
||||
int value = ceil(win->m_adjust->value);
|
||||
|
||||
wxSpinEvent event( command, win->GetId());
|
||||
event.SetPosition( value );
|
||||
@ -80,7 +82,8 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c
|
||||
|
||||
wxSize new_size = size;
|
||||
new_size.x = 16;
|
||||
if (new_size.y == -1) new_size.y = 30;
|
||||
if (new_size.y == -1)
|
||||
new_size.y = 30;
|
||||
|
||||
PreCreation( parent, id, pos, new_size, style, name );
|
||||
|
||||
@ -120,21 +123,21 @@ int wxSpinButton::GetMin() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->lower+0.5);
|
||||
return ceil(m_adjust->lower);
|
||||
}
|
||||
|
||||
int wxSpinButton::GetMax() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->upper+0.5);
|
||||
return ceil(m_adjust->upper);
|
||||
}
|
||||
|
||||
int wxSpinButton::GetValue() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->value+0.5);
|
||||
return ceil(m_adjust->value);
|
||||
}
|
||||
|
||||
void wxSpinButton::SetValue( int value )
|
||||
@ -143,7 +146,7 @@ void wxSpinButton::SetValue( int value )
|
||||
|
||||
float fpos = (float)value;
|
||||
m_oldPos = fpos;
|
||||
if (fabs(fpos-m_adjust->value) < 0.2) return;
|
||||
if (fabs(fpos-m_adjust->value) < sensitivity) return;
|
||||
|
||||
m_adjust->value = fpos;
|
||||
|
||||
@ -157,8 +160,8 @@ void wxSpinButton::SetRange(int minVal, int maxVal)
|
||||
float fmin = (float)minVal;
|
||||
float fmax = (float)maxVal;
|
||||
|
||||
if ((fabs(fmin-m_adjust->lower) < 0.2) &&
|
||||
(fabs(fmax-m_adjust->upper) < 0.2))
|
||||
if ((fabs(fmin-m_adjust->lower) < sensitivity) &&
|
||||
(fabs(fmax-m_adjust->upper) < sensitivity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
@ -25,6 +25,8 @@
|
||||
|
||||
extern bool g_blockEventsOnDrag;
|
||||
|
||||
static const float sensitivity = 0.2;
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// "value_changed"
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -35,7 +37,7 @@ static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *wi
|
||||
if (g_blockEventsOnDrag) return;
|
||||
|
||||
float diff = win->m_adjust->value - win->m_oldPos;
|
||||
if (fabs(diff) < 0.2) return;
|
||||
if (fabs(diff) < sensitivity) return;
|
||||
win->m_oldPos = win->m_adjust->value;
|
||||
|
||||
wxEventType command = wxEVT_NULL;
|
||||
@ -43,13 +45,13 @@ static void gtk_spinbutt_callback( GtkWidget *WXUNUSED(widget), wxSpinButton *wi
|
||||
float line_step = win->m_adjust->step_increment;
|
||||
float page_step = win->m_adjust->page_increment;
|
||||
|
||||
if (fabs(diff-line_step) < 0.2) command = wxEVT_SCROLL_LINEDOWN;
|
||||
else if (fabs(diff+line_step) < 0.2) command = wxEVT_SCROLL_LINEUP;
|
||||
else if (fabs(diff-page_step) < 0.2) command = wxEVT_SCROLL_PAGEDOWN;
|
||||
else if (fabs(diff+page_step) < 0.2) command = wxEVT_SCROLL_PAGEUP;
|
||||
if (fabs(diff-line_step) < sensitivity) command = wxEVT_SCROLL_LINEDOWN;
|
||||
else if (fabs(diff+line_step) < sensitivity) command = wxEVT_SCROLL_LINEUP;
|
||||
else if (fabs(diff-page_step) < sensitivity) command = wxEVT_SCROLL_PAGEDOWN;
|
||||
else if (fabs(diff+page_step) < sensitivity) command = wxEVT_SCROLL_PAGEUP;
|
||||
else command = wxEVT_SCROLL_THUMBTRACK;
|
||||
|
||||
int value = (int)(win->m_adjust->value+0.5);
|
||||
int value = ceil(win->m_adjust->value);
|
||||
|
||||
wxSpinEvent event( command, win->GetId());
|
||||
event.SetPosition( value );
|
||||
@ -80,7 +82,8 @@ bool wxSpinButton::Create(wxWindow *parent, wxWindowID id, const wxPoint& pos, c
|
||||
|
||||
wxSize new_size = size;
|
||||
new_size.x = 16;
|
||||
if (new_size.y == -1) new_size.y = 30;
|
||||
if (new_size.y == -1)
|
||||
new_size.y = 30;
|
||||
|
||||
PreCreation( parent, id, pos, new_size, style, name );
|
||||
|
||||
@ -120,21 +123,21 @@ int wxSpinButton::GetMin() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->lower+0.5);
|
||||
return ceil(m_adjust->lower);
|
||||
}
|
||||
|
||||
int wxSpinButton::GetMax() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->upper+0.5);
|
||||
return ceil(m_adjust->upper);
|
||||
}
|
||||
|
||||
int wxSpinButton::GetValue() const
|
||||
{
|
||||
wxCHECK_MSG( (m_widget != NULL), 0, "invalid spin button" );
|
||||
|
||||
return (int)(m_adjust->value+0.5);
|
||||
return ceil(m_adjust->value);
|
||||
}
|
||||
|
||||
void wxSpinButton::SetValue( int value )
|
||||
@ -143,7 +146,7 @@ void wxSpinButton::SetValue( int value )
|
||||
|
||||
float fpos = (float)value;
|
||||
m_oldPos = fpos;
|
||||
if (fabs(fpos-m_adjust->value) < 0.2) return;
|
||||
if (fabs(fpos-m_adjust->value) < sensitivity) return;
|
||||
|
||||
m_adjust->value = fpos;
|
||||
|
||||
@ -157,8 +160,8 @@ void wxSpinButton::SetRange(int minVal, int maxVal)
|
||||
float fmin = (float)minVal;
|
||||
float fmax = (float)maxVal;
|
||||
|
||||
if ((fabs(fmin-m_adjust->lower) < 0.2) &&
|
||||
(fabs(fmax-m_adjust->upper) < 0.2))
|
||||
if ((fabs(fmin-m_adjust->lower) < sensitivity) &&
|
||||
(fabs(fmax-m_adjust->upper) < sensitivity))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user