Add support for date format to wxGridCellDateEditor too
This is needed to allow editing the cells using wxGridCellDateRenderer with a custom format, otherwise the editor might parse the contents of the cell differently from what is actually shown. In particular, this ensures that using "date:%d.%m.%y" (or any other custom format) as "cell type" works correctly, which wasn't the case before.
This commit is contained in:
@@ -390,7 +390,9 @@ public:
|
||||
class WXDLLIMPEXP_ADV wxGridCellDateEditor : public wxGridCellEditor
|
||||
{
|
||||
public:
|
||||
wxGridCellDateEditor() { }
|
||||
explicit wxGridCellDateEditor(const wxString& format = wxString());
|
||||
|
||||
virtual void SetParameters(const wxString& params) wxOVERRIDE;
|
||||
|
||||
virtual void Create(wxWindow* parent,
|
||||
wxWindowID id,
|
||||
@@ -414,6 +416,7 @@ protected:
|
||||
|
||||
private:
|
||||
wxDateTime m_value;
|
||||
wxString m_format;
|
||||
|
||||
wxDECLARE_NO_COPY_CLASS(wxGridCellDateEditor);
|
||||
};
|
||||
|
@@ -1092,8 +1092,14 @@ class wxGridCellDateEditor : public wxGridCellEditor
|
||||
public:
|
||||
/**
|
||||
Date editor constructor.
|
||||
|
||||
@param format Optional format for the date displayed in the associated
|
||||
cell. By default, the locale-specific date format ("%x") is assumed.
|
||||
You would typically want to specify the same format as the one
|
||||
used with the cell renderer, if a non-default one is used.
|
||||
Note that this parameter is only available since wxWidgets 3.1.5.
|
||||
*/
|
||||
wxGridCellDateEditor();
|
||||
explicit wxGridCellDateEditor(const wxString& format = wxString());
|
||||
};
|
||||
|
||||
|
||||
|
@@ -1861,6 +1861,19 @@ struct wxGridCellDateEditorKeyHandler
|
||||
};
|
||||
#endif // __WXGTK__
|
||||
|
||||
wxGridCellDateEditor::wxGridCellDateEditor(const wxString& format)
|
||||
{
|
||||
SetParameters(format);
|
||||
}
|
||||
|
||||
void wxGridCellDateEditor::SetParameters(const wxString& params)
|
||||
{
|
||||
if ( params.empty() )
|
||||
m_format = "%x";
|
||||
else
|
||||
m_format = params;
|
||||
}
|
||||
|
||||
void wxGridCellDateEditor::Create(wxWindow* parent, wxWindowID id,
|
||||
wxEvtHandler* evtHandler)
|
||||
{
|
||||
@@ -1908,7 +1921,7 @@ void wxGridCellDateEditor::BeginEdit(int row, int col, wxGrid* grid)
|
||||
wxASSERT_MSG(m_control, "The wxGridCellDateEditor must be created first!");
|
||||
|
||||
const wxString dateStr = grid->GetTable()->GetValue(row, col);
|
||||
if ( !m_value.ParseDate(dateStr) )
|
||||
if ( !wxGridPrivate::TryParseDate(m_value, dateStr, m_format) )
|
||||
{
|
||||
// Invalidate m_value, so that it always compares different
|
||||
// to any value returned from DatePicker()->GetValue().
|
||||
@@ -1960,7 +1973,7 @@ void wxGridCellDateEditor::Reset()
|
||||
|
||||
wxGridCellEditor *wxGridCellDateEditor::Clone() const
|
||||
{
|
||||
return new wxGridCellDateEditor();
|
||||
return new wxGridCellDateEditor(m_format);
|
||||
}
|
||||
|
||||
wxString wxGridCellDateEditor::GetValue() const
|
||||
|
Reference in New Issue
Block a user