Refactor wxGridCellDateRenderer::Parse() to make it reusable
No real changes, just create TryParseDate() helper in order to allow reusing it from wxGridCellDateEditor too in the upcoming commit.
This commit is contained in:
@@ -1084,5 +1084,20 @@ wxGetContentRect(wxSize contentSize,
|
|||||||
int hAlign,
|
int hAlign,
|
||||||
int vAlign);
|
int vAlign);
|
||||||
|
|
||||||
|
namespace wxGridPrivate
|
||||||
|
{
|
||||||
|
|
||||||
|
#if wxUSE_DATETIME
|
||||||
|
|
||||||
|
// Helper function trying to parse the given string using the specified date
|
||||||
|
// format and then using ParseDate() as a fallback if it failed. If this still
|
||||||
|
// fails, returns false.
|
||||||
|
bool
|
||||||
|
TryParseDate(wxDateTime& result, const wxString& text, const wxString& format);
|
||||||
|
|
||||||
|
#endif // wxUSE_DATETIME
|
||||||
|
|
||||||
|
} // namespace wxGridPrivate
|
||||||
|
|
||||||
#endif // wxUSE_GRID
|
#endif // wxUSE_GRID
|
||||||
#endif // _WX_GENERIC_GRID_PRIVATE_H_
|
#endif // _WX_GENERIC_GRID_PRIVATE_H_
|
||||||
|
@@ -76,6 +76,23 @@ void wxGridCellRenderer::Draw(wxGrid& grid,
|
|||||||
|
|
||||||
#if wxUSE_DATETIME
|
#if wxUSE_DATETIME
|
||||||
|
|
||||||
|
bool
|
||||||
|
wxGridPrivate::TryParseDate(wxDateTime& result,
|
||||||
|
const wxString& text,
|
||||||
|
const wxString& format)
|
||||||
|
{
|
||||||
|
wxString::const_iterator end;
|
||||||
|
|
||||||
|
// Try parsing using the same format we use for output first.
|
||||||
|
if ( result.ParseFormat(text, format, &end) && end == text.end() )
|
||||||
|
return true;
|
||||||
|
|
||||||
|
// But fall back to free-form parsing, which notably allows us to parse
|
||||||
|
// strings such as "today" or "tomorrow" which would be never accepted by
|
||||||
|
// ParseFormat().
|
||||||
|
return result.ParseDate(text, &end) && end == text.end();
|
||||||
|
}
|
||||||
|
|
||||||
// Enables a grid cell to display a formatted date
|
// Enables a grid cell to display a formatted date
|
||||||
|
|
||||||
wxGridCellDateRenderer::wxGridCellDateRenderer(const wxString& outformat)
|
wxGridCellDateRenderer::wxGridCellDateRenderer(const wxString& outformat)
|
||||||
@@ -131,16 +148,7 @@ wxString wxGridCellDateRenderer::GetString(const wxGrid& grid, int row, int col)
|
|||||||
|
|
||||||
bool wxGridCellDateRenderer::Parse(const wxString& text, wxDateTime& result)
|
bool wxGridCellDateRenderer::Parse(const wxString& text, wxDateTime& result)
|
||||||
{
|
{
|
||||||
wxString::const_iterator end;
|
return wxGridPrivate::TryParseDate(result, text, m_oformat);
|
||||||
|
|
||||||
// Try parsing using the same format we use for output first.
|
|
||||||
if ( result.ParseFormat(text, m_oformat, &end) && end == text.end() )
|
|
||||||
return true;
|
|
||||||
|
|
||||||
// But fall back to free-form parsing, which notably allows us to parse
|
|
||||||
// strings such as "today" or "tomorrow" which would be never accepted by
|
|
||||||
// ParseFormat().
|
|
||||||
return result.ParseDate(text, &end) && end == text.end();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxGridCellDateRenderer::Draw(wxGrid& grid,
|
void wxGridCellDateRenderer::Draw(wxGrid& grid,
|
||||||
|
Reference in New Issue
Block a user