]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/property.cpp
Update from Brian.
[wxWidgets.git] / src / propgrid / property.cpp
index 4253910e479f9ead69903dce7e09a0e7f0511e9d..2fc310ebdd55706605574d6dc2d183a0b875cb68 100644 (file)
@@ -16,6 +16,8 @@
     #pragma hdrstop
 #endif
 
+#if wxUSE_PROPGRID
+
 #ifndef WX_PRECOMP
     #include "wx/defs.h"
     #include "wx/object.h"
     #include "wx/panel.h"
     #include "wx/dc.h"
     #include "wx/dcmemory.h"
-    #include "wx/button.h"
     #include "wx/pen.h"
     #include "wx/brush.h"
-    #include "wx/cursor.h"
-    #include "wx/dialog.h"
     #include "wx/settings.h"
-    #include "wx/msgdlg.h"
-    #include "wx/choice.h"
-    #include "wx/stattext.h"
-    #include "wx/scrolwin.h"
-    #include "wx/dirdlg.h"
-    #include "wx/layout.h"
-    #include "wx/sizer.h"
-    #include "wx/textdlg.h"
-    #include "wx/filedlg.h"
-    #include "wx/statusbr.h"
     #include "wx/intl.h"
-    #include "wx/frame.h"
 #endif
 
 #include <wx/propgrid/propgrid.h>
@@ -206,11 +194,16 @@ void wxPGDefaultRenderer::Render( wxDC& dc, const wxRect& rect,
     // Use choice cell?
     if ( column == 1 && (flags & Control) )
     {
-        const wxPGCell* ccell = property->GetCurrentChoice();
-        if ( ccell &&
-             ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() )
-           )
-            cell = ccell;
+        int selectedIndex = property->GetChoiceSelection();
+        if ( selectedIndex != wxNOT_FOUND )
+        {
+            const wxPGChoices& choices = property->GetChoices();
+            const wxPGCell* ccell = &choices[selectedIndex];
+            if ( ccell &&
+                 ( ccell->GetBitmap().IsOk() || ccell->GetFgCol().IsOk() || ccell->GetBgCol().IsOk() )
+               )
+                cell = ccell;
+        }
     }
 
     if ( cell )
@@ -703,9 +696,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                         wxVariant variant(child->GetValueRef());
                         if ( child->StringToValue(variant, token, propagatedFlags|wxPG_COMPOSITE_FRAGMENT) )
                         {
-                            // Use label instead of name, as name can be empty string, but
-                            // label in practice never is.
-                            variant.SetName(child->GetLabel());
+                            variant.SetName(child->GetBaseName());
 
                             // Clear unspecified flag only if OnSetValue() didn't
                             // affect it.
@@ -724,7 +715,7 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                     {
                         // Empty, becomes unspecified
                         wxVariant variant2;
-                        variant2.SetName(child->GetLabel());
+                        variant2.SetName(child->GetBaseName());
                         list.Append(variant2);
                         changed = true;
                     }
@@ -774,24 +765,24 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
 
                     const wxPGProperty* child = Item(curChild);
 
-                    wxVariant variant(child->GetValueRef());
-                    if ( child->StringToValue( variant, token, propagatedFlags ) )
+                    wxVariant oldChildValue = child->GetValue();
+                    wxVariant variant(oldChildValue);
+                    bool stvRes = child->StringToValue( variant, token, propagatedFlags );
+                    if ( stvRes || (variant != oldChildValue) )
                     {
-                        // Use label instead of name, as name can be empty string, but
-                        // label in practice never is.
-                        variant.SetName(child->GetLabel());
-                        list.Append(variant);
-                        changed = true;
+                        if ( stvRes )
+                            changed = true;
                     }
                     else
                     {
                         // Failed, becomes unspecified
-                        wxVariant variant2;
-                        variant2.SetName(child->GetLabel());
-                        list.Append(variant2);
+                        variant.MakeNull();
                         changed = true;
                     }
 
+                    variant.SetName(child->GetBaseName());
+                    list.Append(variant);
+
                     curChild++;
                     if ( curChild >= iMax )
                         break;
@@ -894,12 +885,22 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
 {
     if ( !value.IsNull() )
     {
+        wxVariant tempListVariant;
+
         SetCommonValue(-1);
         // List variants are reserved a special purpose
         // as intermediate containers for child values
         // of properties with children.
-        if ( wxPGIsVariantType(value, list) )
+        if ( value.GetType() == wxPG_VARIANT_TYPE_LIST )
         {
+            //
+            // However, situation is different for composed string properties
+            if ( HasFlag(wxPG_PROP_COMPOSED_VALUE) )
+            {
+                tempListVariant = value;
+                pList = &tempListVariant;
+            }
+
             wxVariant newValue;
             AdaptListToValue(value, &newValue);
             value = newValue;
@@ -911,7 +912,7 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
 
         if ( pList && !pList->IsNull() )
         {
-            wxASSERT( wxPGIsVariantType(*pList, list) );
+            wxASSERT( pList->GetType() == wxPG_VARIANT_TYPE_LIST );
             wxASSERT( GetChildCount() );
             wxASSERT( !IsCategory() );
 
@@ -922,15 +923,15 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
             //wxLogDebug(wxT(">> %s.SetValue() pList parsing"),GetName().c_str());
 
             // Children in list can be in any order, but we will give hint to
-            // GetPropertyByLabelWH(). This optimizes for full list parsing.
+            // GetPropertyByNameWH(). This optimizes for full list parsing.
             for ( node = list.begin(); node != list.end(); node++ )
             {
                 wxVariant& childValue = *((wxVariant*)*node);
-                wxPGProperty* child = GetPropertyByLabelWH(childValue.GetName(), i);
+                wxPGProperty* child = GetPropertyByNameWH(childValue.GetName(), i);
                 if ( child )
                 {
-                    //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetLabel().c_str(),childValue.GetType().c_str());
-                    if ( wxPGIsVariantType(childValue, list) )
+                    //wxLogDebug(wxT("%i: child = %s, childValue.GetType()=%s"),i,child->GetBaseName().c_str(),childValue.GetType().c_str());
+                    if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
                     {
                         if ( child->HasFlag(wxPG_PROP_AGGREGATE) && !(flags & wxPG_SETVAL_AGGREGATED) )
                         {
@@ -943,16 +944,14 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
                             child->SetValue(oldVal, &childValue, flags|wxPG_SETVAL_FROM_PARENT);
                         }
                     }
-                    else if ( !wxPG_VARIANT_EQ(child->GetValue(), childValue) )
-                        // This flag is not normally set when setting value programmatically.
-                        // However, this loop is usually only executed when called from
-                        // DoPropertyChanged, which should set this flag.
+                    else if ( child->GetValue() != childValue )
                     {
                         // For aggregate properties, we will trust RefreshChildren()
                         // to update child values.
                         if ( !HasFlag(wxPG_PROP_AGGREGATE) )
                             child->SetValue(childValue, NULL, flags|wxPG_SETVAL_FROM_PARENT);
-                        child->SetFlag(wxPG_PROP_MODIFIED);
+                        if ( flags & wxPG_SETVAL_BY_USER )
+                            child->SetFlag(wxPG_PROP_MODIFIED);
                     }
                 }
                 i++;
@@ -961,14 +960,14 @@ void wxPGProperty::SetValue( wxVariant value, wxVariant* pList, int flags )
 
         if ( !value.IsNull() )
         {
-            wxPGVariantAssign(m_value, value);
+            m_value = value;
             OnSetValue();
 
             if ( !(flags & wxPG_SETVAL_FROM_PARENT) )
                 UpdateParentValues();
         }
 
-        if ( pList )
+        if ( flags & wxPG_SETVAL_BY_USER )
             SetFlag(wxPG_PROP_MODIFIED);
 
         if ( HasFlag(wxPG_PROP_AGGREGATE) )
@@ -1047,34 +1046,34 @@ wxVariant wxPGProperty::GetDefaultValue() const
 
     if ( !value.IsNull() )
     {
-        wxPGVariantDataClassInfo classInfo = wxPGVariantDataGetClassInfo(value.GetData());
-        if ( wxPGIsVariantClassInfo(classInfo, long) )
+        wxString valueType(value.GetType());
+
+        if ( valueType == wxPG_VARIANT_TYPE_LONG )
             return wxPGVariant_Zero;
-        if ( wxPGIsVariantClassInfo(classInfo, string) )
+        if ( valueType == wxPG_VARIANT_TYPE_STRING )
             return wxPGVariant_EmptyString;
-        if ( wxPGIsVariantClassInfo(classInfo, bool) )
+        if ( valueType == wxPG_VARIANT_TYPE_BOOL )
             return wxPGVariant_False;
-        if ( wxPGIsVariantClassInfo(classInfo, double) )
+        if ( valueType == wxPG_VARIANT_TYPE_DOUBLE )
             return wxVariant(0.0);
-
-        wxPGVariantData* pgvdata = wxDynamicCastVariantData(m_value.GetData(), wxPGVariantData);
-        if ( pgvdata )
-            return pgvdata->GetDefaultValue();
-
-        if ( wxPGIsVariantClassInfo(classInfo, arrstring) )
+        if ( valueType == wxPG_VARIANT_TYPE_ARRSTRING )
             return wxVariant(wxArrayString());
-        if ( wxPGIsVariantClassInfo(classInfo, wxColour) )
-            return WXVARIANT(*wxRED);
+        if ( valueType == wxS("wxLongLong") )
+            return WXVARIANT(wxLongLong(0));
+        if ( valueType == wxS("wxULongLong") )
+            return WXVARIANT(wxULongLong(0));
+        if ( valueType == wxS("wxColour") )
+            return WXVARIANT(*wxBLACK);
 #if wxUSE_DATETIME
-        if ( wxPGIsVariantClassInfo(classInfo, datetime) )
+        if ( valueType == wxPG_VARIANT_TYPE_DATETIME )
             return wxVariant(wxDateTime::Now());
 #endif
-
-        wxFAIL_MSG(
-            wxString::Format(wxT("Inorder for value to have default value, it must be added to")
-                             wxT("wxPGProperty::GetDefaultValue or it's variantdata must inherit")
-                             wxT("from wxPGVariantData (unrecognized type was '%s')"),m_value.GetType().c_str())
-                  );
+        if ( valueType == wxS("wxFont") )
+            return WXVARIANT(*wxNORMAL_FONT);
+        if ( valueType == wxS("wxPoint") )
+            return WXVARIANT(wxPoint(0, 0));
+        if ( valueType == wxS("wxSize") )
+            return WXVARIANT(wxSize(0, 0));
     }
 
     return wxVariant();
@@ -1089,104 +1088,6 @@ void wxPGProperty::SetCell( int column, wxPGCell* cellObj )
     m_cells[column] = cellObj;
 }
 
-void wxPGProperty::SetChoiceSelection( int newValue, const wxPGChoiceInfo& choiceInfo )
-{
-    // Changes value of a property with choices, but only
-    // works if the value type is long or string.
-    wxString ts = GetValue().GetType();
-
-    wxCHECK_RET( choiceInfo.m_choices, wxT("invalid choiceinfo") );
-
-    if ( ts == wxS("long") )
-    {
-        SetValue( (long) newValue );
-    }
-    else if ( ts == wxS("string") )
-    {
-        SetValue( choiceInfo.m_choices->GetLabel(newValue) );
-    }
-}
-
-
-wxString wxPGProperty::GetChoiceString( unsigned int index )
-{
-    wxPGChoiceInfo ci;
-    GetChoiceInfo(&ci);
-    wxASSERT(ci.m_choices);
-    return ci.m_choices->GetLabel(index);
-}
-
-int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
-{
-    wxPropertyGrid* pg = GetGrid();
-
-    wxPGChoiceInfo ci;
-    ci.m_choices = (wxPGChoices*) NULL;
-    int sel = GetChoiceInfo(&ci);
-
-    if ( ci.m_choices )
-    {
-        int newSel = sel;
-
-        if ( index < 0 )
-            index = ci.m_choices->GetCount();
-
-        if ( index <= sel )
-            newSel++;
-
-        ci.m_choices->Insert(label, index, value);
-
-        if ( sel != newSel )
-            SetChoiceSelection(newSel, ci);
-
-        if ( this == pg->GetSelection() )
-            GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
-
-        return index;
-    }
-
-    return -1;
-}
-
-
-void wxPGProperty::DeleteChoice( int index )
-{
-    wxPropertyGrid* pg = GetGrid();
-
-    wxPGChoiceInfo ci;
-    ci.m_choices = (wxPGChoices*) NULL;
-    int sel = GetChoiceInfo(&ci);
-
-    if ( ci.m_choices )
-    {
-        int newSel = sel;
-
-        // Adjust current value
-        if ( sel == index )
-        {
-            SetValueToUnspecified();
-            newSel = 0;
-        }
-        else if ( index < sel )
-        {
-            newSel--;
-        }
-
-        ci.m_choices->RemoveAt(index);
-
-        if ( sel != newSel )
-            SetChoiceSelection(newSel, ci);
-
-        if ( this == pg->GetSelection() )
-            GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
-    }
-}
-
-int wxPGProperty::GetChoiceInfo( wxPGChoiceInfo* WXUNUSED(info) )
-{
-    return -1;
-}
-
 wxPGEditorDialogAdapter* wxPGProperty::GetEditorDialog() const
 {
     return NULL;
@@ -1339,63 +1240,116 @@ wxValidator* wxPGProperty::DoGetValidator() const
     return (wxValidator*) NULL;
 }
 
-wxPGChoices& wxPGProperty::GetChoices()
+int wxPGProperty::InsertChoice( const wxString& label, int index, int value )
 {
-    wxPGChoiceInfo choiceInfo;
-    choiceInfo.m_choices = NULL;
-    GetChoiceInfo(&choiceInfo);
-    return *choiceInfo.m_choices;
+    wxPropertyGrid* pg = GetGrid();
+    int sel = GetChoiceSelection();
+
+    int newSel = sel;
+
+    if ( index == wxNOT_FOUND )
+        index = m_choices.GetCount();
+
+    if ( index <= sel )
+        newSel++;
+
+    m_choices.Insert(label, index, value);
+
+    if ( sel != newSel )
+        SetChoiceSelection(newSel);
+
+    if ( this == pg->GetSelection() )
+        GetEditorClass()->InsertItem(pg->GetEditorControl(),label,index);
+
+    return index;
 }
 
-const wxPGChoices& wxPGProperty::GetChoices() const
+
+void wxPGProperty::DeleteChoice( int index )
 {
-    return (const wxPGChoices&) ((wxPGProperty*)this)->GetChoices();
+    wxPropertyGrid* pg = GetGrid();
+
+    int sel = GetChoiceSelection();
+    int newSel = sel;
+
+    // Adjust current value
+    if ( sel == index )
+    {
+        SetValueToUnspecified();
+        newSel = 0;
+    }
+    else if ( index < sel )
+    {
+        newSel--;
+    }
+
+    m_choices.RemoveAt(index);
+
+    if ( sel != newSel )
+        SetChoiceSelection(newSel);
+
+    if ( this == pg->GetSelection() )
+        GetEditorClass()->DeleteItem(pg->GetEditorControl(), index);
 }
 
-unsigned int wxPGProperty::GetChoiceCount() const
+int wxPGProperty::GetChoiceSelection() const
 {
-    const wxPGChoices& choices = GetChoices();
-    if ( &choices && choices.IsOk() )
-        return choices.GetCount();
-    return 0;
+    wxVariant value = GetValue();
+    wxString valueType = value.GetType();
+    int index = wxNOT_FOUND;
+
+    if ( IsValueUnspecified() || !m_choices.GetCount() )
+        return wxNOT_FOUND;
+
+    if ( valueType == wxPG_VARIANT_TYPE_LONG )
+    {
+        index = value.GetLong();
+    }
+    else if ( valueType == wxPG_VARIANT_TYPE_STRING )
+    {
+        index = m_choices.Index(value.GetString());
+    }
+    else if ( valueType == wxPG_VARIANT_TYPE_BOOL )
+    {
+        index = value.GetBool()? 1 : 0;
+    }
+
+    return index;
 }
 
-const wxPGChoiceEntry* wxPGProperty::GetCurrentChoice() const
+void wxPGProperty::SetChoiceSelection( int newValue )
 {
-    wxPGChoiceInfo ci;
-    ci.m_choices = (wxPGChoices*) NULL;
-    int index = ((wxPGProperty*)this)->GetChoiceInfo(&ci);
-    if ( index == -1 || !ci.m_choices || index >= (int)ci.m_choices->GetCount() )
-        return NULL;
+    // Changes value of a property with choices, but only
+    // works if the value type is long or string.
+    wxString valueType = GetValue().GetType();
+
+    wxCHECK_RET( m_choices.IsOk(), wxT("invalid choiceinfo") );
 
-    return &(*ci.m_choices)[index];
+    if ( valueType == wxPG_VARIANT_TYPE_STRING )
+    {
+        SetValue( m_choices.GetLabel(newValue) );
+    }
+    else  // if ( valueType == wxPG_VARIANT_TYPE_LONG )
+    {
+        SetValue( (long) newValue );
+    }
 }
 
 bool wxPGProperty::SetChoices( wxPGChoices& choices )
 {
-    wxPGChoiceInfo ci;
-    ci.m_choices = (wxPGChoices*) NULL;
+    m_choices.Assign(choices);
 
-    // Unref existing
-    GetChoiceInfo(&ci);
-    if ( ci.m_choices )
     {
-        ci.m_choices->Assign(choices);
-
-        //if ( m_parent )
-        {
-            // This may be needed to trigger some initialization
-            // (but don't do it if property is somewhat uninitialized)
-            wxVariant defVal = GetDefaultValue();
-            if ( defVal.IsNull() )
-                return false;
-
-            SetValue(defVal);
+        // This may be needed to trigger some initialization
+        // (but don't do it if property is somewhat uninitialized)
+        wxVariant defVal = GetDefaultValue();
+        if ( defVal.IsNull() )
+            return false;
 
-            return true;
-        }
+        SetValue(defVal);
     }
-    return false;
+
+    return true;
 }
 
 
@@ -1426,18 +1380,6 @@ const wxPGEditor* wxPGProperty::GetEditorClass() const
     return editor;
 }
 
-
-// Privatizes set of choices
-void wxPGProperty::SetChoicesExclusive()
-{
-    wxPGChoiceInfo ci;
-    ci.m_choices = (wxPGChoices*) NULL;
-
-    GetChoiceInfo(&ci);
-    if ( ci.m_choices )
-        ci.m_choices->SetExclusive();
-}
-
 bool wxPGProperty::HasVisibleChildren() const
 {
     unsigned int i;
@@ -1597,26 +1539,6 @@ int wxPGProperty::GetY() const
     return GetY2(GetGrid()->GetRowHeight());
 }
 
-
-wxPGProperty* wxPGPropArgCls::GetPtr( wxPropertyGridInterface* methods ) const
-{
-    if ( !m_isName )
-    {
-        wxASSERT_MSG( m_ptr.property, wxT("invalid property ptr") );
-        return m_ptr.property;
-    }
-    else if ( m_isName == 1 )
-        return methods->GetPropertyByNameA(*m_ptr.name);
-    else if ( m_isName == 2 )
-        return methods->GetPropertyByNameA(m_ptr.rawname);
-    // 3 is like 1, but ptr is freed in dtor - only needed by wxPython bindings.
-    else if ( m_isName == 3 )
-        return methods->GetPropertyByNameA(*m_ptr.name);
-
-    wxASSERT( m_isName <= 3 );
-    return NULL;
-}
-
 // This is used by Insert etc.
 void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
 {
@@ -1637,6 +1559,9 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
 // This is used by properties that have fixed sub-properties
 void wxPGProperty::AddChild( wxPGProperty* prop )
 {
+    wxASSERT_MSG( prop->GetBaseName().length(),
+                  "Property's children must have unique, non-empty names within their scope" );
+
     prop->m_arrIndex = m_children.GetCount();
     m_children.Add( prop );
 
@@ -1673,17 +1598,17 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
     unsigned int i;
     unsigned int n = 0;
 
-    //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetLabel().c_str());
+    //wxLogDebug(wxT(">> %s.AdaptListToValue()"),GetBaseName().c_str());
 
     for ( i=0; i<GetChildCount(); i++ )
     {
         const wxPGProperty* child = Item(i);
 
-        if ( childValue.GetName() == child->GetLabel() )
+        if ( childValue.GetName() == child->GetBaseName() )
         {
             //wxLogDebug(wxT("  %s(n=%i), %s"),childValue.GetName().c_str(),n,childValue.GetType().c_str());
 
-            if ( wxPGIsVariantType(childValue, list) )
+            if ( childValue.GetType() == wxPG_VARIANT_TYPE_LIST )
             {
                 wxVariant cv2(child->GetValue());
                 child->AdaptListToValue(childValue, &cv2);
@@ -1734,7 +1659,7 @@ wxPGProperty* wxPGProperty::GetPropertyByName( const wxString& name ) const
     return p->GetPropertyByName(name.substr(pos+1,name.length()-pos-1));
 }
 
-wxPGProperty* wxPGProperty::GetPropertyByLabelWH( const wxString& label, unsigned int hintIndex ) const
+wxPGProperty* wxPGProperty::GetPropertyByNameWH( const wxString& name, unsigned int hintIndex ) const
 {
     unsigned int i = hintIndex;
 
@@ -1749,7 +1674,7 @@ wxPGProperty* wxPGProperty::GetPropertyByLabelWH( const wxString& label, unsigne
     for (;;)
     {
         wxPGProperty* p = Item(i);
-        if ( p->m_label == label )
+        if ( p->m_name == name )
             return p;
 
         if ( i == lastIndex )
@@ -1894,8 +1819,6 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
         node = pList->begin();
     }
 
-    // Children in list can be in any order, but we will give hint to
-    // GetPropertyByLabelWH(). This optimizes for full list parsing.
     for ( i=0; i<GetChildCount(); i++ )
     {
         wxPGProperty* child = Item(i);
@@ -1904,12 +1827,12 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
 
         if ( pendingList )
         {
-            const wxString& childLabel = child->GetLabel();
+            const wxString& childName = child->GetBaseName();
 
             for ( ; node != pList->end(); node++ )
             {
                 const wxVariant& item = *((const wxVariant*)*node);
-                if ( item.GetName() == childLabel )
+                if ( item.GetName() == childName )
                 {
                     listValue = &item;
                     value = item;
@@ -1929,7 +1852,7 @@ bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
         {
             const wxVariant* childList = NULL;
 
-            if ( listValue && wxPGIsVariantType(*listValue, list) )
+            if ( listValue && listValue->GetType() == wxPG_VARIANT_TYPE_LIST )
                 childList = listValue;
 
             if ( !child->AreAllChildrenSpecified((wxVariant*)childList) )
@@ -2030,7 +1953,7 @@ void wxPGProperty::PrepareSubProperties()
 
             depth--;
 
-            i = nparent->GetArrIndex() + 1;
+            i = nparent->GetIndexInParent() + 1;
             nparent = nparent->GetParent();
         }
     }
@@ -2170,11 +2093,23 @@ void wxPGAttributeStorage::Set( const wxString& name, const wxVariant& value )
     // Free old, if any
     wxPGHashMapS2P::iterator it = m_map.find(name);
     if ( it != m_map.end() )
+    {
         ((wxVariantData*)it->second)->DecRef();
 
+        if ( !data )
+        {
+            // If Null variant, just remove from set
+            m_map.erase(it);
+            return;
+        }
+    }
+
     if ( data )
+    {
         data->IncRef();
 
-    m_map[name] = data;
+        m_map[name] = data;
+    }
 }
 
+#endif  // wxUSE_PROPGRID