Better support for unspecified property value in wxDateProperty and DatePickerCtrl editor, especially when wxDP_ALLOWNONE is used
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58051 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -457,7 +457,7 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
|
||||
NULL,
|
||||
wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
|
||||
|
||||
wxDateProperty* prop = (wxDateProperty*) property;
|
||||
wxDateProperty* prop = wxDynamicCast(property, wxDateProperty);
|
||||
|
||||
// Use two stage creation to allow cleaner display on wxMSW
|
||||
wxDatePickerCtrl* ctrl = new wxDatePickerCtrl();
|
||||
@@ -490,14 +490,18 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
|
||||
}
|
||||
|
||||
// Copies value from property to control
|
||||
void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty* property, wxWindow* wnd ) const
|
||||
void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty* property,
|
||||
wxWindow* wnd ) const
|
||||
{
|
||||
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
|
||||
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
|
||||
|
||||
// We assume that property's data type is 'int' (or something similar),
|
||||
// thus allowing us to get raw, unchecked value via DoGetValue.
|
||||
ctrl->SetValue( property->GetValue().GetDateTime() );
|
||||
wxDateTime dateValue(wxInvalidDateTime);
|
||||
wxVariant v(property->GetValue());
|
||||
if ( v.GetType() == wxT("datetime") )
|
||||
dateValue = v.GetDateTime();
|
||||
|
||||
ctrl->SetValue( dateValue );
|
||||
}
|
||||
|
||||
// Control's events are redirected here
|
||||
@@ -522,11 +526,20 @@ bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProp
|
||||
return true;
|
||||
}
|
||||
|
||||
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* WXUNUSED(wnd) ) const
|
||||
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* property,
|
||||
wxWindow* wnd ) const
|
||||
{
|
||||
// TODO?
|
||||
//wxDateProperty* prop = (wxDateProperty*) property;
|
||||
//ctrl->SetValue(?);
|
||||
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
|
||||
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
|
||||
|
||||
wxDateProperty* prop = wxDynamicCast(property, wxDateProperty);
|
||||
|
||||
if ( prop )
|
||||
{
|
||||
int datePickerStyle = prop->GetDatePickerStyle();
|
||||
if ( datePickerStyle & wxDP_ALLOWNONE )
|
||||
ctrl->SetValue(wxInvalidDateTime);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // wxUSE_DATEPICKCTRL
|
||||
@@ -2066,6 +2079,17 @@ wxDateProperty::~wxDateProperty()
|
||||
{
|
||||
}
|
||||
|
||||
void wxDateProperty::OnSetValue()
|
||||
{
|
||||
//
|
||||
// Convert invalid dates to unspecified value
|
||||
if ( m_value.GetType() == wxT("datetime") )
|
||||
{
|
||||
if ( !m_value.GetDateTime().IsValid() )
|
||||
m_value.MakeNull();
|
||||
}
|
||||
}
|
||||
|
||||
bool wxDateProperty::StringToValue( wxVariant& variant, const wxString& text,
|
||||
int WXUNUSED(argFlags) ) const
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user