From 9c71a1386d70836180f8e78346d9f38c74980f11 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 28 Oct 2006 13:57:38 +0000 Subject: [PATCH] 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 --- docs/latex/wx/gridedit.tex | 19 +++++++++++++++++++ include/wx/generic/grid.h | 25 ++++++++++++++++++------- src/generic/grid.cpp | 31 +++++++++++++++++++++++-------- 3 files changed, 60 insertions(+), 15 deletions(-) diff --git a/docs/latex/wx/gridedit.tex b/docs/latex/wx/gridedit.tex index 1aa6b7a9c8..7d7826fd16 100644 --- a/docs/latex/wx/gridedit.tex +++ b/docs/latex/wx/gridedit.tex @@ -33,6 +33,25 @@ The editor for boolean data. 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} The editor for string data allowing to choose from a list of strings. diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index e38563df19..a9acd59db1 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -348,7 +348,6 @@ public: // create a new object which is the copy of this one virtual wxGridCellEditor *Clone() const = 0; - // DJC MAPTEK // added GetValue so we can get the value which is in the control virtual wxString GetValue() const = 0; @@ -405,9 +404,9 @@ public: virtual wxGridCellEditor *Clone() const { return new wxGridCellTextEditor; } - // DJC MAPTEK // added GetValue so we can get the value which is in the control virtual wxString GetValue() const; + protected: wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; } @@ -446,7 +445,7 @@ public: virtual wxGridCellEditor *Clone() const { return new wxGridCellNumberEditor(m_min, m_max); } - // DJC MAPTEK + // added GetValue so we can get the value which is in the control virtual wxString GetValue() const; @@ -528,7 +527,7 @@ public: wxEvtHandler* evtHandler); 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 void BeginEdit(int row, int col, wxGrid* grid); @@ -540,16 +539,28 @@ public: virtual wxGridCellEditor *Clone() const { 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; + // 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: wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } private: bool m_startValue; + static wxString ms_stringValues[2]; + DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor) }; @@ -583,7 +594,7 @@ public: virtual void SetParameters(const wxString& params); virtual wxGridCellEditor *Clone() const; - // DJC MAPTEK + // added GetValue so we can get the value which is in the control virtual wxString GetValue() const; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 72284e458c..623586fbe1 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -1233,6 +1233,9 @@ bool wxGridCellFloatEditor::IsAcceptedKey(wxKeyEvent& event) // wxGridCellBoolEditor // ---------------------------------------------------------------------------- +// the default values for GetValue() +wxString wxGridCellBoolEditor::ms_stringValues[2] = { _T("1"), _T("") }; + void wxGridCellBoolEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) @@ -1358,10 +1361,11 @@ bool wxGridCellBoolEditor::EndEdit(int row, int col, if ( changed ) { - if (grid->GetTable()->CanGetValueAs(row, col, wxGRID_VALUE_BOOL)) - grid->GetTable()->SetValueAsBool(row, col, value); + wxGridTableBase * const table = grid->GetTable(); + if ( table->CanGetValueAs(row, col, wxGRID_VALUE_BOOL) ) + table->SetValueAsBool(row, col, value); else - grid->GetTable()->SetValue(row, col, value ? _T("1") : wxEmptyString); + table->SetValue(row, col, GetValue()); } 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 { - bool bSet = CBox()->GetValue(); - return bSet ? _T("1") : wxEmptyString; + return ms_stringValues[CBox()->GetValue()]; +} + +/* 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 @@ -2217,7 +2232,7 @@ void wxGridCellBoolRenderer::Draw(wxGrid& grid, else { wxString cellval( grid.GetTable()->GetValue(row, col) ); - value = !( !cellval || (cellval == wxT("0")) ); + value = wxGridCellBoolEditor::IsTrueValue(cellval); } if ( value ) -- 2.45.2