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:
@@ -430,7 +430,8 @@ protected:
|
|||||||
<b>Supported special attributes:</b>
|
<b>Supported special attributes:</b>
|
||||||
- "DateFormat": Determines displayed date format.
|
- "DateFormat": Determines displayed date format.
|
||||||
- "PickerStyle": Determines window style used with wxDatePickerCtrl.
|
- "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
|
class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
|
||||||
{
|
{
|
||||||
@@ -442,6 +443,7 @@ public:
|
|||||||
const wxDateTime& value = wxDateTime() );
|
const wxDateTime& value = wxDateTime() );
|
||||||
virtual ~wxDateProperty();
|
virtual ~wxDateProperty();
|
||||||
|
|
||||||
|
virtual void OnSetValue();
|
||||||
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
|
virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
|
||||||
virtual bool StringToValue(wxVariant& variant,
|
virtual bool StringToValue(wxVariant& variant,
|
||||||
const wxString& text,
|
const wxString& text,
|
||||||
|
@@ -115,7 +115,8 @@
|
|||||||
#define wxPG_DATE_FORMAT wxS("DateFormat")
|
#define wxPG_DATE_FORMAT wxS("DateFormat")
|
||||||
|
|
||||||
/** Sets wxDatePickerCtrl window style used with wxDateProperty. Default
|
/** 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")
|
#define wxPG_DATE_PICKER_STYLE wxS("PickerStyle")
|
||||||
|
|
||||||
@@ -310,6 +311,7 @@
|
|||||||
string wxDateTime::Format uses (altough default is recommended as it is
|
string wxDateTime::Format uses (altough default is recommended as it is
|
||||||
locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
|
locale-dependant), and wxPG_DATE_PICKER_STYLE allows changing window
|
||||||
style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
|
style given to DatePickerCtrl (default is wxDP_DEFAULT|wxDP_SHOWCENTURY).
|
||||||
|
Using wxDP_ALLOWNONE will enable better unspecified value support.
|
||||||
|
|
||||||
@subsection wxEditEnumProperty
|
@subsection wxEditEnumProperty
|
||||||
|
|
||||||
|
@@ -1593,11 +1593,13 @@ void FormMain::PopulateWithExamples ()
|
|||||||
|
|
||||||
#if wxUSE_DATEPICKCTRL
|
#if wxUSE_DATEPICKCTRL
|
||||||
pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE,
|
pg->SetPropertyAttribute( wxT("DateProperty"), wxPG_DATE_PICKER_STYLE,
|
||||||
(long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY) );
|
(long)(wxDP_DROPDOWN |
|
||||||
|
wxDP_SHOWCENTURY |
|
||||||
|
wxDP_ALLOWNONE) );
|
||||||
|
|
||||||
pg->SetPropertyHelpString( wxT("DateProperty"),
|
pg->SetPropertyHelpString( wxT("DateProperty"),
|
||||||
wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)(wxDP_DROPDOWN | wxDP_SHOWCENTURY).")
|
wxT("Attribute wxPG_DATE_PICKER_STYLE has been set to (long)")
|
||||||
wxT("Also note that wxPG_ALLOW_WXADV needs to be defined inorder to use wxDatePickerCtrl.") );
|
wxT("(wxDP_DROPDOWN | wxDP_SHOWCENTURY | wxDP_ALLOWNONE).") );
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@@ -457,7 +457,7 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
|
|||||||
NULL,
|
NULL,
|
||||||
wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
|
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
|
// Use two stage creation to allow cleaner display on wxMSW
|
||||||
wxDatePickerCtrl* ctrl = new wxDatePickerCtrl();
|
wxDatePickerCtrl* ctrl = new wxDatePickerCtrl();
|
||||||
@@ -490,14 +490,18 @@ wxPGWindowList wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid* propgri
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Copies value from property to control
|
// 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;
|
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
|
||||||
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
|
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
|
||||||
|
|
||||||
// We assume that property's data type is 'int' (or something similar),
|
wxDateTime dateValue(wxInvalidDateTime);
|
||||||
// thus allowing us to get raw, unchecked value via DoGetValue.
|
wxVariant v(property->GetValue());
|
||||||
ctrl->SetValue( property->GetValue().GetDateTime() );
|
if ( v.GetType() == wxT("datetime") )
|
||||||
|
dateValue = v.GetDateTime();
|
||||||
|
|
||||||
|
ctrl->SetValue( dateValue );
|
||||||
}
|
}
|
||||||
|
|
||||||
// Control's events are redirected here
|
// Control's events are redirected here
|
||||||
@@ -522,11 +526,20 @@ bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant& variant, wxPGProp
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* WXUNUSED(property), wxWindow* WXUNUSED(wnd) ) const
|
void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty* property,
|
||||||
|
wxWindow* wnd ) const
|
||||||
{
|
{
|
||||||
// TODO?
|
wxDatePickerCtrl* ctrl = (wxDatePickerCtrl*) wnd;
|
||||||
//wxDateProperty* prop = (wxDateProperty*) property;
|
wxASSERT( ctrl && ctrl->IsKindOf(CLASSINFO(wxDatePickerCtrl)) );
|
||||||
//ctrl->SetValue(?);
|
|
||||||
|
wxDateProperty* prop = wxDynamicCast(property, wxDateProperty);
|
||||||
|
|
||||||
|
if ( prop )
|
||||||
|
{
|
||||||
|
int datePickerStyle = prop->GetDatePickerStyle();
|
||||||
|
if ( datePickerStyle & wxDP_ALLOWNONE )
|
||||||
|
ctrl->SetValue(wxInvalidDateTime);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // wxUSE_DATEPICKCTRL
|
#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,
|
bool wxDateProperty::StringToValue( wxVariant& variant, const wxString& text,
|
||||||
int WXUNUSED(argFlags) ) const
|
int WXUNUSED(argFlags) ) const
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user