Add support for editing dates (without time) to wxGrid

Add wxGridCellDateRenderer and wxGridCellDateRenderer which can be used
for the grid cells containing only dates, without times.

Also add wxGrid::SetColFormatDate() convenience function.

Refactor wxGridCellDateTimeRenderer slightly to reuse its code.

Closes https://github.com/wxWidgets/wxWidgets/pull/1101
This commit is contained in:
Pavel Kalugin
2018-09-06 05:49:58 +03:00
committed by Vadim Zeitlin
parent ee352d79c8
commit 659ab78c6d
10 changed files with 416 additions and 46 deletions

View File

@@ -153,12 +153,17 @@ private:
#include "wx/datetime.h"
// the default renderer for the cells containing times and dates
class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
// renderer for the cells containing dates only, without time component
class WXDLLIMPEXP_ADV wxGridCellDateRenderer : public wxGridCellStringRenderer
{
public:
wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
const wxString& informat = wxDefaultDateTimeFormat);
explicit wxGridCellDateRenderer(const wxString& outformat = wxString());
wxGridCellDateRenderer(const wxGridCellDateRenderer& other)
: m_oformat(other.m_oformat),
m_tz(other.m_tz)
{
}
// draw the string right aligned
virtual void Draw(wxGrid& grid,
@@ -180,11 +185,33 @@ public:
protected:
wxString GetString(const wxGrid& grid, int row, int col);
virtual bool Parse(const wxString& text, wxDateTime& result);
wxString m_oformat;
wxDateTime::TimeZone m_tz;
};
// the default renderer for the cells containing times and dates
class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellDateRenderer
{
public:
wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
const wxString& informat = wxDefaultDateTimeFormat);
wxGridCellDateTimeRenderer(const wxGridCellDateTimeRenderer& other)
: wxGridCellDateRenderer(other),
m_iformat(other.m_iformat),
m_dateDef(other.m_dateDef)
{
}
virtual wxGridCellRenderer *Clone() const wxOVERRIDE;
protected:
virtual bool Parse(const wxString& text, wxDateTime& result) wxOVERRIDE;
wxString m_iformat;
wxString m_oformat;
wxDateTime m_dateDef;
wxDateTime::TimeZone m_tz;
};
#endif // wxUSE_DATETIME