Change the data in generic wxDatePickerCtrl immediately
Accept the new date typed into the text control immediately if it's valid. This is more consistent with the native MSW control behaviour and avoids semi-duplicated events on text change and then on focus loss that occurred before.
This commit is contained in:
parent
d406f23e67
commit
d7351536c1
@ -121,6 +121,34 @@ public:
|
|||||||
return m_combo->GetTextCtrl()->IsEmpty();
|
return m_combo->GetTextCtrl()->IsEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is public because it is used by wxDatePickerCtrlGeneric itself to
|
||||||
|
// change the date when the text control field changes. The reason it's
|
||||||
|
// done there and not in this class itself is mostly historic.
|
||||||
|
void ChangeDateAndNotifyIfValid()
|
||||||
|
{
|
||||||
|
wxDateTime dt;
|
||||||
|
if ( !ParseDateTime(m_combo->GetValue(), &dt) )
|
||||||
|
{
|
||||||
|
// The user must be in the process of updating the date, don't do
|
||||||
|
// anything -- we'll take care of ensuring it's valid on focus loss
|
||||||
|
// later.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( dt == GetDate() )
|
||||||
|
{
|
||||||
|
// No need to send event if the date hasn't changed.
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We change the date immediately, as it's more consistent with the
|
||||||
|
// native MSW version and avoids another event on focus loss.
|
||||||
|
SetDate(dt);
|
||||||
|
|
||||||
|
SendDateEvent(dt);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
bool ParseDateTime(const wxString& s, wxDateTime* pDt)
|
bool ParseDateTime(const wxString& s, wxDateTime* pDt)
|
||||||
{
|
{
|
||||||
wxASSERT(pDt);
|
wxASSERT(pDt);
|
||||||
@ -144,8 +172,6 @@ public:
|
|||||||
datePicker->GetEventHandler()->ProcessEvent(event);
|
datePicker->GetEventHandler()->ProcessEvent(event);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
|
||||||
|
|
||||||
void OnCalKey(wxKeyEvent & ev)
|
void OnCalKey(wxKeyEvent & ev)
|
||||||
{
|
{
|
||||||
if (ev.GetKeyCode() == WXK_ESCAPE && !ev.HasModifiers())
|
if (ev.GetKeyCode() == WXK_ESCAPE && !ev.HasModifiers())
|
||||||
@ -488,13 +514,8 @@ void wxDatePickerCtrlGeneric::OnText(wxCommandEvent &ev)
|
|||||||
ev.SetId(GetId());
|
ev.SetId(GetId());
|
||||||
GetParent()->GetEventHandler()->ProcessEvent(ev);
|
GetParent()->GetEventHandler()->ProcessEvent(ev);
|
||||||
|
|
||||||
// We'll create an additional event if the date is valid.
|
if ( m_popup )
|
||||||
// If the date isn't valid, the user's probably in the middle of typing
|
m_popup->ChangeDateAndNotifyIfValid();
|
||||||
wxDateTime dt;
|
|
||||||
if ( !m_popup || !m_popup->ParseDateTime(m_combo->GetValue(), &dt) )
|
|
||||||
return;
|
|
||||||
|
|
||||||
m_popup->SendDateEvent(dt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_DATEPICKCTRL
|
#endif // wxUSE_DATEPICKCTRL
|
||||||
|
Loading…
Reference in New Issue
Block a user