Avoid asserts when wxDP_ALLOWNONE is used and the date is set to wxDefaultDateTime

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@53510 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2008-05-09 22:15:55 +00:00
parent 1570d8e9e2
commit aae5ec8bbe

View File

@@ -158,6 +158,7 @@ public:
if ( date.IsValid() ) if ( date.IsValid() )
{ {
m_combo->SetText(date.Format(m_format)); m_combo->SetText(date.Format(m_format));
SetDate(date);
} }
else // invalid date else // invalid date
{ {
@@ -166,8 +167,6 @@ public:
m_combo->SetText(wxEmptyString); m_combo->SetText(wxEmptyString);
} }
SetDate(date);
} }
bool ParseDateTime(const wxString& s, wxDateTime* pDt) bool ParseDateTime(const wxString& s, wxDateTime* pDt)
@@ -238,6 +237,9 @@ private:
m_combo->SetText(GetStringValueFor(dt)); m_combo->SetText(GetStringValueFor(dt));
if ( !dt.IsValid() && HasDPFlag(wxDP_ALLOWNONE) )
return;
// notify that we had to change the date after validation // notify that we had to change the date after validation
if ( (dt.IsValid() && (!dtOld.IsValid() || dt != dtOld)) || if ( (dt.IsValid() && (!dtOld.IsValid() || dt != dtOld)) ||
(!dt.IsValid() && dtOld.IsValid()) ) (!dt.IsValid() && dtOld.IsValid()) )
@@ -322,11 +324,9 @@ private:
virtual void SetStringValue(const wxString& s) virtual void SetStringValue(const wxString& s)
{ {
wxDateTime dt; wxDateTime dt;
if ( ParseDateTime(s, &dt) ) if ( !s.empty() && ParseDateTime(s, &dt) )
SetDate(dt); SetDate(dt);
else if ( HasDPFlag(wxDP_ALLOWNONE) ) //else: keep the old value
SetDate(wxInvalidDateTime);
//else: !wxDP_ALLOWNONE, keep the old value
} }
virtual wxString GetStringValue() const virtual wxString GetStringValue() const