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:
Jaakko Salli 2009-01-12 17:05:37 +00:00
parent 898a466aef
commit b6fd0b4245
4 changed files with 44 additions and 14 deletions

View File

@ -430,7 +430,8 @@ protected:
<b>Supported special attributes:</b>
- "DateFormat": Determines displayed date format.
- "PickerStyle": Determines window style used with wxDatePickerCtrl.
Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
enables additional support for unspecified property value.
*/
class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
{
@ -442,6 +443,7 @@ public:
const wxDateTime& value = wxDateTime() );
virtual ~wxDateProperty();
virtual void OnSetValue();
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
virtual bool StringToValue(wxVariant& variant,
const wxString& text,

View File

@ -115,7 +115,8 @@
#define wxPG_DATE_FORMAT wxS("DateFormat")
/** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
is wxDP_DEFAULT | wxDP_SHOWCENTURY.
is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE will enable
better unspecified value support in the editor.
*/
#define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
@ -310,6 +311,7 @@
string wxDateTime::Format uses (altough default is recommended as it is
locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
Using wxDP_ALLOWNONE will enable better unspecified value support.
@subsection wxEditEnumProperty

View File

@ -1593,11 +1593,13 @@ void FormMain::PopulateWithExamples ()
#if wxUSE_DATEPICKCTRL
pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE,
(long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY) );
(long)(wxDP_DROPDOWN |
wxDP_SHOWCENTURY |
wxDP_ALLOWNONE) );
pg->SetPropertyHelpString( wxT("DateProperty"),
wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY).")
wxT("Also note that wxPG_ALLOW_WXADV needs to be defined inorder to use wxDatePickerCtrl.") );
wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
#endif
#endif

View File

@ -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
{