]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/property.cpp
make sure theme font info is reset if anything is changed
[wxWidgets.git] / src / propgrid / property.cpp
index eed6f76b225e80a9be7d287a37fa7667dfd3d82f..221ebb4f770e5833446f4e0bbc94caadd16f8d20 100644 (file)
@@ -539,10 +539,12 @@ void wxPGProperty::InitAfterAdded( wxPropertyGridPageState* pageState,
     if ( GetChildCount() )
     {
         // Check parental flags
-        wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS),
-                      "Call SetFlag(wxPG_PROP_MISC_PARENT) or"
-                      "SetFlag(wxPG_PROP_AGGREGATE) before calling"
-                      "wxPGProperty::AddChild()." );
+        wxASSERT_MSG( ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                            wxPG_PROP_AGGREGATE) ||
+                      ((m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                            wxPG_PROP_MISC_PARENT),
+                      "wxPGProperty parental flags set incorrectly at "
+                      "this time" );
 
         if ( HasFlag(wxPG_PROP_AGGREGATE) )
         {
@@ -957,14 +959,8 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
 
     int propagatedFlags = argFlags & (wxPG_REPORT_ERROR|wxPG_PROGRAMMATIC_VALUE);
 
-#ifdef __WXDEBUG__
-    bool debug_print = false;
-#endif
-
-#ifdef __WXDEBUG__
-    if ( debug_print )
-        wxLogDebug(wxT(">> %s.StringToValue('%s')"),GetLabel().c_str(),text.c_str());
-#endif
+    wxLogTrace("propgrid",
+               wxT(">> %s.StringToValue('%s')"), GetLabel(), text);
 
     wxString::const_iterator it = text.begin();
     wxUniChar a;
@@ -996,11 +992,9 @@ bool wxPGProperty::StringToValue( wxVariant& variant, const wxString& text, int
                     wxVariant variant(child->GetValue());
                     wxString childName = child->GetBaseName();
 
-                #ifdef __WXDEBUG__
-                    if ( debug_print )
-                        wxLogDebug(wxT("token = '%s', child = %s"),
-                                   token.c_str(), childName.c_str());
-                #endif
+                    wxLogTrace("propgrid",
+                               wxT("token = '%s', child = %s"),
+                               token, childName);
 
                     // Add only if editable or setting programmatically
                     if ( (argFlags & wxPG_PROGRAMMATIC_VALUE) ||
@@ -1359,10 +1353,7 @@ void wxPGProperty::SetValueInEvent( wxVariant value ) const
 
 void wxPGProperty::SetFlagRecursively( FlagType flag, bool set )
 {
-    if ( set )
-        SetFlag(flag);
-    else
-        ClearFlag(flag);
+    ChangeFlag(flag, set);
 
     unsigned int i;
     for ( i = 0; i < GetChildCount(); i++ )
@@ -1381,7 +1372,7 @@ void wxPGProperty::RefreshEditor()
 
 wxVariant wxPGProperty::GetDefaultValue() const
 {
-    wxVariant defVal = GetAttribute(wxS("DefaultValue"));
+    wxVariant defVal = GetAttribute(wxPG_ATTR_DEFAULT_VALUE);
     if ( !defVal.IsNull() )
         return defVal;
 
@@ -1643,18 +1634,20 @@ long wxPGProperty::GetAttributeAsLong( const wxString& name, long defVal ) const
 {
     wxVariant variant = m_attributes.FindValue(name);
 
-    return wxPGVariantToInt(variant, defVal);
+    if ( variant.IsNull() )
+        return defVal;
+
+    return variant.GetLong();
 }
 
 double wxPGProperty::GetAttributeAsDouble( const wxString& name, double defVal ) const
 {
-    double retVal;
     wxVariant variant = m_attributes.FindValue(name);
 
-    if ( wxPGVariantToDouble(variant, &retVal) )
-        return retVal;
+    if ( variant.IsNull() )
+        return defVal;
 
-    return defVal;
+    return variant.GetDouble();
 }
 
 wxVariant wxPGProperty::GetAttributesAsList() const
@@ -2034,7 +2027,8 @@ int wxPGProperty::GetY() const
 }
 
 // This is used by Insert etc.
-void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
+void wxPGProperty::DoAddChild( wxPGProperty* prop, int index,
+                               bool correct_mode )
 {
     if ( index < 0 || (size_t)index >= m_children.size() )
     {
@@ -2050,14 +2044,15 @@ void wxPGProperty::AddChild2( wxPGProperty* prop, int index, bool correct_mode )
     prop->m_parent = this;
 }
 
-// This is used by properties that have fixed sub-properties
-void wxPGProperty::AddChild( wxPGProperty* prop )
+void wxPGProperty::DoPreAddChild( int index, wxPGProperty* prop )
 {
     wxASSERT_MSG( prop->GetBaseName().length(),
-                  "Property's children must have unique, non-empty names within their scope" );
+                  "Property's children must have unique, non-empty "
+                  "names within their scope" );
 
-    prop->m_arrIndex = m_children.size();
-    m_children.push_back( prop );
+    prop->m_arrIndex = index;
+    m_children.insert( m_children.begin()+index,
+                       prop );
 
     int custImgHeight = prop->OnMeasureImage().y;
     if ( custImgHeight < 0 /*|| custImgHeight > 1*/ )
@@ -2066,6 +2061,52 @@ void wxPGProperty::AddChild( wxPGProperty* prop )
     prop->m_parent = this;
 }
 
+void wxPGProperty::AddPrivateChild( wxPGProperty* prop )
+{
+    if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
+        SetParentalType(wxPG_PROP_AGGREGATE);
+
+    wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                    wxPG_PROP_AGGREGATE,
+                  "Do not mix up AddPrivateChild() calls with other "
+                  "property adders." );
+
+    DoPreAddChild( m_children.size(), prop );
+}
+
+#if wxPG_COMPATIBILITY_1_4
+void wxPGProperty::AddChild( wxPGProperty* prop )
+{
+    AddPrivateChild(prop);
+}
+#endif
+
+wxPGProperty* wxPGProperty::InsertChild( int index,
+                                         wxPGProperty* childProperty )
+{
+    if ( index < 0 )
+        index = m_children.size();
+
+    if ( m_parentState )
+    {
+        m_parentState->DoInsert(this, index, childProperty);
+    }
+    else
+    {
+        if ( !(m_flags & wxPG_PROP_PARENTAL_FLAGS) )
+            SetParentalType(wxPG_PROP_MISC_PARENT);
+
+        wxASSERT_MSG( (m_flags & wxPG_PROP_PARENTAL_FLAGS) ==
+                        wxPG_PROP_MISC_PARENT,
+                      "Do not mix up AddPrivateChild() calls with other "
+                      "property adders." );
+
+        DoPreAddChild( index, childProperty );
+    }
+
+    return childProperty;
+}
+
 void wxPGProperty::RemoveChild( wxPGProperty* p )
 {
     wxArrayPGProperty::iterator it;
@@ -2124,7 +2165,10 @@ void wxPGProperty::AdaptListToValue( wxVariant& list, wxVariant* value ) const
             }
 
             if ( allChildrenSpecified )
-                ChildChanged(*value, i, childValue);
+            {
+                *value = ChildChanged(*value, i, childValue);
+            }
+
             n++;
             if ( n == (unsigned int)list.GetCount() )
                 break;
@@ -2235,7 +2279,9 @@ int wxPGProperty::GetChildrenHeight( int lh, int iMax_ ) const
     return h;
 }
 
-wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y, unsigned int lh, unsigned int* nextItemY ) const
+wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y,
+                                        unsigned int lh,
+                                        unsigned int* nextItemY ) const
 {
     wxASSERT( nextItemY );
 
@@ -2307,6 +2353,12 @@ void wxPGProperty::Empty()
     m_children.clear();
 }
 
+wxPGProperty* wxPGProperty::GetItemAtY( unsigned int y ) const
+{
+    unsigned int nextItem;
+    return GetItemAtY( y, GetGrid()->GetRowHeight(), &nextItem);
+}
+
 void wxPGProperty::DeleteChildren()
 {
     wxPropertyGridPageState* state = m_parentState;
@@ -2318,10 +2370,11 @@ void wxPGProperty::DeleteChildren()
     }
 }
 
-void wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
-                                 int WXUNUSED(childIndex),
-                                 wxVariant& WXUNUSED(childValue) ) const
+wxVariant wxPGProperty::ChildChanged( wxVariant& WXUNUSED(thisValue),
+                                      int WXUNUSED(childIndex),
+                                      wxVariant& WXUNUSED(childValue) ) const
 {
+    return wxNullVariant;
 }
 
 bool wxPGProperty::AreAllChildrenSpecified( wxVariant* pendingList ) const
@@ -2455,12 +2508,8 @@ IMPLEMENT_DYNAMIC_CLASS(wxPGRootProperty, wxPGProperty)
 wxPGRootProperty::wxPGRootProperty( const wxString& name )
     : wxPGProperty()
 {
-#ifdef __WXDEBUG__
     m_name = name;
     m_label = m_name;
-#else
-    wxUnusedVar(name);
-#endif
     SetParentalType(0);
     m_depth = 0;
 }
@@ -2635,7 +2684,7 @@ void wxPGChoices::RemoveAt(size_t nIndex, size_t count)
 {
     AllocExclusive();
 
-    wxASSERT( m_data->m_refCount != 0xFFFFFFF );
+    wxASSERT( m_data->GetRefCount() != -1 );
     m_data->m_items.erase(m_data->m_items.begin()+nIndex,
                           m_data->m_items.begin()+nIndex+count);
 }
@@ -2751,7 +2800,7 @@ void wxPGChoices::AllocExclusive()
 {
     EnsureData();
 
-    if ( m_data->m_refCount != 1 )
+    if ( m_data->GetRefCount() != 1 )
     {
         wxPGChoicesData* data = new wxPGChoicesData();
         data->CopyDataFrom(m_data);
@@ -2769,7 +2818,7 @@ void wxPGChoices::AssignData( wxPGChoicesData* data )
     if ( data != wxPGChoicesEmptyData )
     {
         m_data = data;
-        data->m_refCount++;
+        data->IncRef();
     }
 }