diff --git a/include/wx/generic/gridctrl.h b/include/wx/generic/gridctrl.h index 0991110ba8..167201132c 100644 --- a/include/wx/generic/gridctrl.h +++ b/include/wx/generic/gridctrl.h @@ -57,6 +57,13 @@ protected: class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer { public: + explicit wxGridCellNumberRenderer(long minValue = LONG_MIN, + long maxValue = LONG_MAX) + : m_minValue(minValue), + m_maxValue(maxValue) + { + } + // draw the string right aligned virtual void Draw(wxGrid& grid, wxGridCellAttr& attr, @@ -70,11 +77,21 @@ public: wxDC& dc, int row, int col) wxOVERRIDE; + virtual wxSize GetMaxBestSize(wxGrid& grid, + wxGridCellAttr& attr, + wxDC& dc) wxOVERRIDE; + + // Optional parameters for this renderer are ",". + virtual void SetParameters(const wxString& params) wxOVERRIDE; + virtual wxGridCellRenderer *Clone() const wxOVERRIDE - { return new wxGridCellNumberRenderer; } + { return new wxGridCellNumberRenderer(m_minValue, m_maxValue); } protected: wxString GetString(const wxGrid& grid, int row, int col); + + long m_minValue, + m_maxValue; }; class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer diff --git a/src/generic/gridctrl.cpp b/src/generic/gridctrl.cpp index 4f2860912c..df2f831205 100644 --- a/src/generic/gridctrl.cpp +++ b/src/generic/gridctrl.cpp @@ -748,6 +748,34 @@ wxSize wxGridCellNumberRenderer::GetBestSize(wxGrid& grid, return DoGetBestSize(attr, dc, GetString(grid, row, col)); } +wxSize wxGridCellNumberRenderer::GetMaxBestSize(wxGrid& WXUNUSED(grid), + wxGridCellAttr& attr, + wxDC& dc) +{ + // In theory, it's possible that there is a value in min..max range which + // is longer than both min and max, e.g. we could conceivably have "88" be + // wider than both "87" and "91" with some fonts, but it seems something + // too exotic to worry about in practice. + wxSize size = DoGetBestSize(attr, dc, wxString::Format("%ld", m_minValue)); + size.IncTo(DoGetBestSize(attr, dc, wxString::Format("%ld", m_maxValue))); + + return size; +} + +void wxGridCellNumberRenderer::SetParameters(const wxString& params) +{ + if ( params.empty() ) + return; + + wxString maxStr; + const wxString minStr = params.BeforeFirst(',', &maxStr); + + if ( !minStr.ToLong(&m_minValue) || !maxStr.ToLong(&m_maxValue) ) + { + wxLogDebug("Invalid wxGridCellNumberRenderer parameters \"%s\"", params); + } +} + // ---------------------------------------------------------------------------- // wxGridCellFloatRenderer // ----------------------------------------------------------------------------