]> git.saurik.com Git - wxWidgets.git/commitdiff
Added wxPGProperty::OnValidationFailure(); needed it and some other tweaks to allow...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Mon, 12 Jan 2009 16:12:15 +0000 (16:12 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Mon, 12 Jan 2009 16:12:15 +0000 (16:12 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58047 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/propgrid/property.h
include/wx/propgrid/propgrid.h
include/wx/propgrid/props.h
interface/wx/propgrid/property.h
src/propgrid/property.cpp
src/propgrid/propgrid.cpp
src/propgrid/props.cpp

index d30565932630d9ace4a3311ff55e825354982763..176db3d61ee0e0c1af93e891659222d32772cbb6 100644 (file)
@@ -1423,6 +1423,15 @@ public:
     */
     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.
     */
     int AddChoice( const wxString& label, int value = wxPG_INVALID_VALUE )
index 9fbb5adaace0b150ded5e297d492117e34872bc7..fefc72e3b350699e78a176bb55fd234fd1245630 100644 (file)
@@ -1294,12 +1294,8 @@ public:
         To add your own validation failure behavior, override
         wxPropertyGrid::DoOnValidationFailure().
     */
-    bool OnValidationFailure( wxPGProperty* property, wxVariant& invalidValue )
-    {
-        bool res = DoOnValidationFailure(property, invalidValue);
-        property->SetFlag(wxPG_PROP_INVALID_VALUE);
-        return res;
-    }
+    bool OnValidationFailure( wxPGProperty* property,
+                              wxVariant& invalidValue );
 
     /** Called to indicate property and editor has valid value now.
     */
index f7247bc81515db318d022b0d8a271529e296f07d..3d9885c04170979569ac6c7c13dec99568e28af8 100644 (file)
@@ -428,6 +428,8 @@ public:
     // this take advantage of it.
     virtual int GetChoiceSelection() const { return m_index; }
 
+    virtual void OnValidationFailure( wxVariant& pendingValue );
+
 protected:
 
     int GetIndex() const;
@@ -447,6 +449,7 @@ private:
 
     // Relies on ValidateValue being called always before OnSetValue
     static int              ms_nextIndex;
+    static int              ms_prevIndex;
 };
 
 // -----------------------------------------------------------------------
index 5cd1d564a1ac8eb40982e55d029bbf8afd040d34..c78af7a8935d561616832d12895535934b720fd9 100644 (file)
@@ -852,6 +852,15 @@ public:
     */
     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.
 
index aea73df3b9fabec5348735356f59428927c97d11..ac6d0d192cf1b01dce98403257808072c54cbc11 100644 (file)
@@ -652,6 +652,10 @@ void wxPGProperty::RefreshChildren ()
 {
 }
 
+void wxPGProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
+{
+}
+
 void wxPGProperty::GetDisplayInfo( unsigned int column,
                                    int choiceIndex,
                                    int flags,
index bf16d22fdf4c7e5e82e1879d0946af92f0d45792..237158f0bbadf7053601b54535d97642b68deea6 100644 (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) )
 {
     int vfb = m_validationInfo.m_failureBehavior;
index df7efa118a6adb652864859a5f6c7b7a7cd2d8cc..336c55fdc5b31d5e51f67ebc46880a8acb9faf5a 100644 (file)
@@ -963,6 +963,7 @@ wxEnumProperty::~wxEnumProperty ()
 }
 
 int wxEnumProperty::ms_nextIndex = -2;
+int wxEnumProperty::ms_prevIndex = -1;
 
 void wxEnumProperty::OnSetValue()
 {
@@ -1113,8 +1114,17 @@ bool wxEnumProperty::ValueFromInt_( wxVariant& variant, int intVal, int argFlags
     return false;
 }
 
+void
+wxEnumProperty::OnValidationFailure( wxVariant& WXUNUSED(pendingValue) )
+{
+    // Revert index
+    m_index = ms_prevIndex;
+    ResetNextIndex();
+}
+
 void wxEnumProperty::SetIndex( int index )
 {
+    ms_prevIndex = m_index;
     ms_nextIndex = -2;
     m_index = index;
 }