Added wxPGProperty::OnValidationFailure(); needed it and some other tweaks to allow vetoing value changes of ComboBox editors

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58047 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-01-12 16:12:15 +00:00
parent cbc9abd710
commit d8812c6e0e
7 changed files with 60 additions and 6 deletions

View File

@@ -1423,6 +1423,15 @@ public:
*/ */
virtual wxPGEditorDialogAdapter* GetEditorDialog() const; virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
/**
Called whenever validation has failed with given pending value.
@remarks If you implement this in your custom property class, please
remember to call the baser implementation as well, since they
may use it to revert property into pre-change state.
*/
virtual void OnValidationFailure( wxVariant& pendingValue );
/** Append a new choice to property's list of choices. /** Append a new choice to property's list of choices.
*/ */
int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE ) int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )

View File

@@ -1294,12 +1294,8 @@ public:
To add your own validation failure behavior, override To add your own validation failure behavior, override
wxPropertyGrid::DoOnValidationFailure(). wxPropertyGrid::DoOnValidationFailure().
*/ */
bool OnValidationFailure( wxPGProperty* property, wxVariant& invalidValue ) bool OnValidationFailure( wxPGProperty* property,
{ wxVariant& invalidValue );
bool res = DoOnValidationFailure(property, invalidValue);
property->SetFlag(wxPG_PROP_INVALID_VALUE);
return res;
}
/** Called to indicate property and editor has valid value now. /** Called to indicate property and editor has valid value now.
*/ */

View File

@@ -428,6 +428,8 @@ public:
// this take advantage of it. // this take advantage of it.
virtual int GetChoiceSelection() const { return m_index; } virtual int GetChoiceSelection() const { return m_index; }
virtual void OnValidationFailure( wxVariant& pendingValue );
protected: protected:
int GetIndex() const; int GetIndex() const;
@@ -447,6 +449,7 @@ private:
// Relies on ValidateValue being called always before OnSetValue // Relies on ValidateValue being called always before OnSetValue
static int ms_nextIndex; static int ms_nextIndex;
static int ms_prevIndex;
}; };
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------

View File

@@ -852,6 +852,15 @@ public:
*/ */
virtual wxPGEditorDialogAdapter* GetEditorDialog() const; virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
/**
Called whenever validation has failed with given pending value.
@remarks If you implement this in your custom property class, please
remember to call the baser implementation as well, since they
may use it to revert property into pre-change state.
*/
virtual void OnValidationFailure( wxVariant& pendingValue );
/** /**
Append a new choice to property's list of choices. Append a new choice to property's list of choices.

View File

@@ -652,6 +652,10 @@ void wxPGProperty::RefreshChildren ()
{ {
} }
void wxPGProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
{
}
void wxPGProperty::GetDisplayInfo( unsigned int column, void wxPGProperty::GetDisplayInfo( unsigned int column,
int choiceIndex, int choiceIndex,
int flags, int flags,

View File

@@ -2602,6 +2602,29 @@ void wxPropertyGrid::DoShowPropertyError( wxPGProperty* WXUNUSED(property), cons
// ----------------------------------------------------------------------- // -----------------------------------------------------------------------
bool wxPropertyGrid::OnValidationFailure( wxPGProperty* property,
wxVariant& invalidValue )
{
wxWindow* editor = GetEditorControl();
// First call property's handler
property->OnValidationFailure(invalidValue);
bool res = DoOnValidationFailure(property, invalidValue);
//
// For non-wxTextCtrl editors, we do need to revert the value
if ( !editor->IsKindOf(CLASSINFO(wxTextCtrl)) &&
property == m_selected )
{
property->GetEditorClass()->UpdateControl(property, editor);
}
property->SetFlag(wxPG_PROP_INVALID_VALUE);
return res;
}
bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) ) bool wxPropertyGrid::DoOnValidationFailure( wxPGProperty* property, wxVariant& WXUNUSED(invalidValue) )
{ {
int vfb = m_validationInfo.m_failureBehavior; int vfb = m_validationInfo.m_failureBehavior;

View File

@@ -963,6 +963,7 @@ wxEnumProperty::~wxEnumProperty ()
} }
int wxEnumProperty::ms_nextIndex = -2; int wxEnumProperty::ms_nextIndex = -2;
int wxEnumProperty::ms_prevIndex = -1;
void wxEnumProperty::OnSetValue() void wxEnumProperty::OnSetValue()
{ {
@@ -1113,8 +1114,17 @@ bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags
return false; return false;
} }
void
wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
{
// Revert index
m_index = ms_prevIndex;
ResetNextIndex();
}
void wxEnumProperty::SetIndex( int index ) void wxEnumProperty::SetIndex( int index )
{ {
ms_prevIndex = m_index;
ms_nextIndex = -2; ms_nextIndex = -2;
m_index = index; m_index = index;
} }