Refactor wxGridCellBoolEditor to make some functions reusable
No real changes, just factor out code for getting and setting the grid cell value as bool from {Begin,Apply}Edit() to {Get,Set}GridValue() to make it possible to reuse these functions in the upcoming commits. This commit is best viewed with the --color-moved option.
This commit is contained in:
@@ -275,6 +275,15 @@ protected:
|
|||||||
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
|
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
// These functions modify or use m_value.
|
||||||
|
void SetValueFromGrid(int row, int col, wxGrid* grid);
|
||||||
|
void SetGridFromValue(int row, int col, wxGrid* grid) const;
|
||||||
|
|
||||||
|
wxString GetStringValue() const { return GetStringValue(m_value); }
|
||||||
|
|
||||||
|
static
|
||||||
|
wxString GetStringValue(bool value) { return ms_stringValues[value]; }
|
||||||
|
|
||||||
bool m_value;
|
bool m_value;
|
||||||
|
|
||||||
static wxString ms_stringValues[2];
|
static wxString ms_stringValues[2];
|
||||||
|
@@ -1312,27 +1312,7 @@ void wxGridCellBoolEditor::BeginEdit(int row, int col, wxGrid* grid)
|
|||||||
wxASSERT_MSG(m_control,
|
wxASSERT_MSG(m_control,
|
||||||
wxT("The wxGridCellEditor must be created first!"));
|
wxT("The wxGridCellEditor must be created first!"));
|
||||||
|
|
||||||
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
|
SetValueFromGrid(row, col, grid);
|
||||||
{
|
|
||||||
m_value = grid->GetTable()->GetValueAsBool(row, col);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
wxString cellval( grid->GetTable()->GetValue(row, col) );
|
|
||||||
|
|
||||||
if ( cellval == ms_stringValues[false] )
|
|
||||||
m_value = false;
|
|
||||||
else if ( cellval == ms_stringValues[true] )
|
|
||||||
m_value = true;
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// do not try to be smart here and convert it to true or false
|
|
||||||
// because we'll still overwrite it with something different and
|
|
||||||
// this risks to be very surprising for the user code, let them
|
|
||||||
// know about it
|
|
||||||
wxFAIL_MSG( wxT("invalid value for a cell with bool editor!") );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
CBox()->SetValue(m_value);
|
CBox()->SetValue(m_value);
|
||||||
CBox()->SetFocus();
|
CBox()->SetFocus();
|
||||||
@@ -1358,11 +1338,7 @@ bool wxGridCellBoolEditor::EndEdit(int WXUNUSED(row),
|
|||||||
|
|
||||||
void wxGridCellBoolEditor::ApplyEdit(int row, int col, wxGrid* grid)
|
void wxGridCellBoolEditor::ApplyEdit(int row, int col, wxGrid* grid)
|
||||||
{
|
{
|
||||||
wxGridTableBase * const table = grid->GetTable();
|
SetGridFromValue(row, col, grid);
|
||||||
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
|
|
||||||
table->SetValueAsBool(row, col, m_value);
|
|
||||||
else
|
|
||||||
table->SetValue(row, col, GetValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellBoolEditor::Reset()
|
void wxGridCellBoolEditor::Reset()
|
||||||
@@ -1416,7 +1392,7 @@ void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
|
|||||||
|
|
||||||
wxString wxGridCellBoolEditor::GetValue() const
|
wxString wxGridCellBoolEditor::GetValue() const
|
||||||
{
|
{
|
||||||
return ms_stringValues[CBox()->GetValue()];
|
return GetStringValue(CBox()->GetValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
/* static */ void
|
/* static */ void
|
||||||
@@ -1433,6 +1409,40 @@ wxGridCellBoolEditor::IsTrueValue(const wxString& value)
|
|||||||
return value == ms_stringValues[true];
|
return value == ms_stringValues[true];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void wxGridCellBoolEditor::SetValueFromGrid(int row, int col, wxGrid* grid)
|
||||||
|
{
|
||||||
|
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL))
|
||||||
|
{
|
||||||
|
m_value = grid->GetTable()->GetValueAsBool(row, col);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
wxString cellval( grid->GetTable()->GetValue(row, col) );
|
||||||
|
|
||||||
|
if ( cellval == ms_stringValues[false] )
|
||||||
|
m_value = false;
|
||||||
|
else if ( cellval == ms_stringValues[true] )
|
||||||
|
m_value = true;
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// do not try to be smart here and convert it to true or false
|
||||||
|
// because we'll still overwrite it with something different and
|
||||||
|
// this risks to be very surprising for the user code, let them
|
||||||
|
// know about it
|
||||||
|
wxFAIL_MSG( wxT("invalid value for a cell with bool editor!") );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void wxGridCellBoolEditor::SetGridFromValue(int row, int col, wxGrid* grid) const
|
||||||
|
{
|
||||||
|
wxGridTableBase * const table = grid->GetTable();
|
||||||
|
if ( table->CanSetValueAs(row, col, wxGRID_VALUE_BOOL) )
|
||||||
|
table->SetValueAsBool(row, col, m_value);
|
||||||
|
else
|
||||||
|
table->SetValue(row, col, GetStringValue());
|
||||||
|
}
|
||||||
|
|
||||||
#endif // wxUSE_CHECKBOX
|
#endif // wxUSE_CHECKBOX
|
||||||
|
|
||||||
#if wxUSE_COMBOBOX
|
#if wxUSE_COMBOBOX
|
||||||
|
Reference in New Issue
Block a user