allow customizing the string values returned by wxGridCellBoolEditor::GetValue() (feature request 1557790)

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@42567 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin 2006-10-28 13:57:38 +00:00
parent a4e73390a6
commit 9c71a1386d
3 changed files with 60 additions and 15 deletions

View File

@ -33,6 +33,25 @@ The editor for boolean data.
Default constructor. Default constructor.
\membersection{wxGridCellBoolEditor::IsTrueValue}\label{wxgridcellbooleditoristruevalue}
\func{static bool}{IsTrueValue}{\param{const wxString\& }{value}}
Returns \true if the given \arg{value} is equal to the string representation of
the truth value we currently use (see
\helpref{UseStringValues}{wxgridcellbooleditorusestringvalues}).
\membersection{wxGridCellBoolEditor::UseStringValues}\label{wxgridcellbooleditorusestringvalues}
\func{static void}{UseStringValues}{\param{const wxString\& }{valueTrue = \_T("1")}, \param{const wxString\& }{valueFalse = \_T("")}}
This method allows to customize the values returned by GetValue() method for
the cell using this editor. By default, the default values of the arguments are
used, i.e. \texttt{"1"} is returned if the cell is checked and an empty string
otherwise, using this method allows to change this.
\section{\class{wxGridCellChoiceEditor}}\label{wxgridcellchoiceeditor} \section{\class{wxGridCellChoiceEditor}}\label{wxgridcellchoiceeditor}
The editor for string data allowing to choose from a list of strings. The editor for string data allowing to choose from a list of strings.

View File

@ -348,7 +348,6 @@ public:
// create a new object which is the copy of this one // create a new object which is the copy of this one
virtual wxGridCellEditor *Clone() const = 0; virtual wxGridCellEditor *Clone() const = 0;
// DJC MAPTEK
// added GetValue so we can get the value which is in the control // added GetValue so we can get the value which is in the control
virtual wxString GetValue() const = 0; virtual wxString GetValue() const = 0;
@ -405,9 +404,9 @@ public:
virtual wxGridCellEditor *Clone() const virtual wxGridCellEditor *Clone() const
{ return new wxGridCellTextEditor; } { return new wxGridCellTextEditor; }
// DJC MAPTEK
// added GetValue so we can get the value which is in the control // added GetValue so we can get the value which is in the control
virtual wxString GetValue() const; virtual wxString GetValue() const;
protected: protected:
wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
@ -446,7 +445,7 @@ public:
virtual wxGridCellEditor *Clone() const virtual wxGridCellEditor *Clone() const
{ return new wxGridCellNumberEditor(m_min, m_max); } { return new wxGridCellNumberEditor(m_min, m_max); }
// DJC MAPTEK
// added GetValue so we can get the value which is in the control // added GetValue so we can get the value which is in the control
virtual wxString GetValue() const; virtual wxString GetValue() const;
@ -528,7 +527,7 @@ public:
wxEvtHandler* evtHandler); wxEvtHandler* evtHandler);
virtual void SetSize(const wxRect& rect); virtual void SetSize(const wxRect& rect);
virtual void Show(bool show, wxGridCellAttr *attr = (wxGridCellAttr *)NULL); virtual void Show(bool show, wxGridCellAttr *attr = NULL);
virtual bool IsAcceptedKey(wxKeyEvent& event); virtual bool IsAcceptedKey(wxKeyEvent& event);
virtual void BeginEdit(int row, int col, wxGrid* grid); virtual void BeginEdit(int row, int col, wxGrid* grid);
@ -540,16 +539,28 @@ public:
virtual wxGridCellEditor *Clone() const virtual wxGridCellEditor *Clone() const
{ return new wxGridCellBoolEditor; } { return new wxGridCellBoolEditor; }
// DJC MAPTEK
// added GetValue so we can get the value which is in the control // added GetValue so we can get the value which is in the control, see
// also UseStringValues()
virtual wxString GetValue() const; virtual wxString GetValue() const;
// set the string values returned by GetValue() for the true and false
// states, respectively
static void UseStringValues(const wxString& valueTrue = _T("1"),
const wxString& valueFalse = wxEmptyString);
// return true if the given string is equal to the string representation of
// true value which we currently use
static bool IsTrueValue(const wxString& value);
protected: protected:
wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
private: private:
bool m_startValue; bool m_startValue;
static wxString ms_stringValues[2];
DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor) DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor)
}; };
@ -583,7 +594,7 @@ public:
virtual void SetParameters(const wxString& params); virtual void SetParameters(const wxString& params);
virtual wxGridCellEditor *Clone() const; virtual wxGridCellEditor *Clone() const;
// DJC MAPTEK
// added GetValue so we can get the value which is in the control // added GetValue so we can get the value which is in the control
virtual wxString GetValue() const; virtual wxString GetValue() const;

View File

@ -1233,6 +1233,9 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event)
// wxGridCellBoolEditor // wxGridCellBoolEditor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// the default values for GetValue()
wxString wxGridCellBoolEditor::ms_stringValues[2] = { _T("1"), _T("") };
void wxGridCellBoolEditor::Create(wxWindow* parent, void wxGridCellBoolEditor::Create(wxWindow* parent,
wxWindowID id, wxWindowID id,
wxEvtHandler* evtHandler) wxEvtHandler* evtHandler)
@ -1358,10 +1361,11 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col,
if ( changed ) if ( changed )
{ {
if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) wxGridTableBase * const table = grid->GetTable();
grid->GetTable()->SetValueAsBool(row, col, value); if ( table->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) )
table->SetValueAsBool(row, col, value);
else else
grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); table->SetValue(row, col, GetValue());
} }
return changed; return changed;
@ -1416,12 +1420,23 @@ void wxGridCellBoolEditor::StartingKey(wxKeyEvent& event)
} }
} }
// return the value as "1" for true and the empty string for false
wxString wxGridCellBoolEditor::GetValue() const wxString wxGridCellBoolEditor::GetValue() const
{ {
bool bSet = CBox()->GetValue(); return ms_stringValues[CBox()->GetValue()];
return bSet ? _T("1") : wxEmptyString; }
/* static */ void
wxGridCellBoolEditor::UseStringValues(const wxString& valueTrue,
const wxString& valueFalse)
{
ms_stringValues[false] = valueFalse;
ms_stringValues[true] = valueTrue;
}
/* static */ bool
wxGridCellBoolEditor::IsTrueValue(const wxString& value)
{
return value == ms_stringValues[true];
} }
#endif // wxUSE_CHECKBOX #endif // wxUSE_CHECKBOX
@ -2217,7 +2232,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid,
else else
{ {
wxString cellval( grid.GetTable()->GetValue(row, col) ); wxString cellval( grid.GetTable()->GetValue(row, col) );
value = !( !cellval || (cellval == wxT("0")) ); value = wxGridCellBoolEditor::IsTrueValue(cellval);
} }
if ( value ) if ( value )