From 0bd879bad6f35bd7f5abd6845e9850b89a444e93 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 18 May 2000 12:29:02 +0000 Subject: [PATCH] (re?)added support for params to wxGridCellFloatEditor git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_2_BRANCH@7419 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/generic/grid.h | 10 +++++-- src/generic/grid.cpp | 55 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+), 2 deletions(-) diff --git a/include/wx/generic/grid.h b/include/wx/generic/grid.h index 60373fe49e..c34e94afec 100644 --- a/include/wx/generic/grid.h +++ b/include/wx/generic/grid.h @@ -449,6 +449,8 @@ private: class WXDLLEXPORT wxGridCellFloatEditor : public wxGridCellTextEditor { public: + wxGridCellFloatEditor(int width = -1, int precision = -1); + virtual void Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler); @@ -462,12 +464,16 @@ public: virtual wxGridCellEditor *Clone() const { return new wxGridCellFloatEditor; } + // parameters string format is "width,precision" + virtual void SetParameters(const wxString& params); + protected: // string representation of m_valueOld - wxString GetString() const - { return wxString::Format(_T("%g"), m_valueOld); } + wxString GetString() const; private: + int m_width, + m_precision; double m_valueOld; }; diff --git a/src/generic/grid.cpp b/src/generic/grid.cpp index 7e87947585..b05825ec99 100644 --- a/src/generic/grid.cpp +++ b/src/generic/grid.cpp @@ -813,6 +813,12 @@ void wxGridCellNumberEditor::SetParameters(const wxString& params) // wxGridCellFloatEditor // ---------------------------------------------------------------------------- +wxGridCellFloatEditor::wxGridCellFloatEditor(int width, int precision) +{ + m_width = width; + m_precision = precision; +} + void wxGridCellFloatEditor::Create(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler) @@ -884,6 +890,55 @@ void wxGridCellFloatEditor::StartingKey(wxKeyEvent& event) event.Skip(); } +void wxGridCellFloatEditor::SetParameters(const wxString& params) +{ + if ( !params ) + { + // reset to default + m_width = + m_precision = -1; + } + else + { + long tmp; + if ( params.BeforeFirst(_T(',')).ToLong(&tmp) ) + { + m_width = (int)tmp; + + if ( params.AfterFirst(_T(',')).ToLong(&tmp) ) + { + m_precision = (int)tmp; + + // skip the error message below + return; + } + } + + wxLogDebug(_T("Invalid wxGridCellFloatEditor parameter string '%s' ignored"), params.c_str()); + } +} + +wxString wxGridCellFloatEditor::GetString() const +{ + wxString fmt; + if ( m_width == -1 ) + { + // default width/precision + fmt = _T("%g"); + } + else if ( m_precision == -1 ) + { + // default precision + fmt.Printf(_T("%%%d.g"), m_width); + } + else + { + fmt.Printf(_T("%%%d.%dg"), m_width, m_precision); + } + + return wxString::Format(fmt, m_valueOld); +} + // ---------------------------------------------------------------------------- // wxGridCellBoolEditor // ----------------------------------------------------------------------------