don't ignore changes of empty string to 0 or vice versa in float grid cells (#2802)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@54477 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-07-03 15:37:35 +00:00
parent afe442339e
commit 8a3608697f

View File

@@ -953,7 +953,6 @@ void wxGridCellNumberEditor::BeginEdit(int row, int col, wxGrid* grid)
bool wxGridCellNumberEditor::EndEdit(int row, int col, bool wxGridCellNumberEditor::EndEdit(int row, int col,
wxGrid* grid) wxGrid* grid)
{ {
bool changed;
long value = 0; long value = 0;
wxString text; wxString text;
@@ -961,26 +960,40 @@ bool wxGridCellNumberEditor::EndEdit(int row, int col,
if ( HasRange() ) if ( HasRange() )
{ {
value = Spin()->GetValue(); value = Spin()->GetValue();
changed = value != m_valueOld; if ( value == m_valueOld )
if (changed) return false;
text = wxString::Format(wxT("%ld"), value);
text.Printf(wxT("%ld"), value);
} }
else else // using unconstrained input
#endif #endif // wxUSE_SPINCTRL
{ {
const wxString textOld(grid->GetCellValue(row, col));
text = Text()->GetValue(); text = Text()->GetValue();
changed = (text.empty() || text.ToLong(&value)) && (value != m_valueOld); if ( text.empty() )
{
if ( textOld.empty() )
return false;
}
else // non-empty text now (maybe 0)
{
if ( !text.ToLong(&value) )
return false;
// if value == m_valueOld == 0 but old text was "" and new one is
// "0" something still did change
if ( value == m_valueOld && (value || !textOld.empty()) )
return false;
}
} }
if ( changed ) wxGridTableBase * const table = grid->GetTable();
{ if ( table->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER) )
if (grid->GetTable()->CanSetValueAs(row, col, wxGRID_VALUE_NUMBER)) table->SetValueAsLong(row, col, value);
grid->GetTable()->SetValueAsLong(row, col, value); else
else table->SetValue(row, col, text);
grid->GetTable()->SetValue(row, col, text);
}
return changed; return true;
} }
void wxGridCellNumberEditor::Reset() void wxGridCellNumberEditor::Reset()