]> git.saurik.com Git - wxWidgets.git/blobdiff - src/propgrid/propgridpagestate.cpp
State fix
[wxWidgets.git] / src / propgrid / propgridpagestate.cpp
index 59c3a88a39d4bb15afc8698bde6d7c0aa1455fe6..1861b67ef65685281d2061c1bd8f2999f90eca2f 100644 (file)
@@ -255,7 +255,7 @@ void wxPropertyGridPageState::InitNonCatMode()
             wxPGProperty* parent = p->GetParent();
             if ( parent->IsCategory() || parent->IsRoot() )
             {
-                m_abcArray->AddChild2(p);
+                m_abcArray->DoAddChild(p);
                 p->m_parent = &m_regularArray;
             }
         }
@@ -268,6 +268,15 @@ void wxPropertyGridPageState::InitNonCatMode()
 
 void wxPropertyGridPageState::DoClear()
 {
+    if ( m_pPropGrid && m_pPropGrid->GetState() == this  )
+    {
+        m_pPropGrid->ClearSelection(false);
+    }
+    else
+    {
+        m_selected = NULL;
+    }
+
     m_regularArray.Empty();
     if ( m_abcArray )
         m_abcArray->Empty();
@@ -280,8 +289,6 @@ void wxPropertyGridPageState::DoClear()
 
     m_virtualHeight = 0;
     m_vhCalcPending = 0;
-
-    m_selected = NULL;
 }
 
 // -----------------------------------------------------------------------
@@ -346,9 +353,9 @@ void wxPropertyGridPageState::OnClientWidthChange( int newWidth, int widthChange
             long timeSinceCreation = (::wxGetLocalTimeMillis() - GetGrid()->m_timeCreated).ToLong();
 
             // If too long, don't set splitter
-            if ( timeSinceCreation < 3000 )
+            if ( timeSinceCreation < 250 )
             {
-                if ( m_properties->GetChildCount() || timeSinceCreation > 750 )
+                if ( m_properties->GetChildCount() )
                 {
                     SetSplitterLeft( false );
                 }
@@ -863,7 +870,7 @@ void wxPropertyGridPageState::SetSplitterLeft( bool subProps )
 {
     wxPropertyGrid* pg = GetGrid();
     wxClientDC dc(pg);
-    dc.SetFont(pg->m_font);
+    dc.SetFont(pg->GetFont());
 
     int maxW = GetColumnFitWidth(dc, m_properties, 0, subProps);
 
@@ -880,7 +887,7 @@ wxSize wxPropertyGridPageState::DoFitColumns( bool WXUNUSED(allowGridResize) )
 {
     wxPropertyGrid* pg = GetGrid();
     wxClientDC dc(pg);
-    dc.SetFont(pg->m_font);
+    dc.SetFont(pg->GetFont());
 
     int marginWidth = pg->m_marginWidth;
     int accWid = marginWidth;
@@ -929,10 +936,6 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
 
     wxPropertyGrid* pg = GetGrid();
 
-#ifdef __WXDEBUG__
-    const bool debug = false;
-#endif
-
     unsigned int i;
     unsigned int lastColumn = m_colWidths.size() - 1;
     int width = m_width;
@@ -940,14 +943,11 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
 
     //
     // Column to reduce, if needed. Take last one that exceeds minimum width.
-    // Except if auto splitter centering is used, in which case use widest.
     int reduceCol = -1;
-    int highestColWidth = 0;
 
-#ifdef __WXDEBUG__
-    if ( debug )
-        wxLogDebug(wxT("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"), width, clientWidth);
-#endif
+    wxLogTrace("propgrid",
+               wxS("ColumnWidthCheck (virtualWidth: %i, clientWidth: %i)"),
+               width, clientWidth);
 
     //
     // Check min sizes
@@ -960,18 +960,9 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
         }
         else
         {
-            if ( pg->HasFlag(wxPG_SPLITTER_AUTO_CENTER) )
-            {
-                if ( m_colWidths[i] >= highestColWidth )
-                {
-                    highestColWidth = m_colWidths[i];
-                    reduceCol = i;
-                }
-            }
-            else
-            {
-                reduceCol = i;
-            }
+            // Always reduce the last column that is larger than minimum size
+            // (looks nicer, even with auto-centering enabled).
+            reduceCol = i;
         }
     }
 
@@ -979,10 +970,9 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
     for ( i=0; i<m_colWidths.size(); i++ )
         colsWidth += m_colWidths[i];
 
-#ifdef __WXDEBUG__
-    if ( debug )
-        wxLogDebug(wxT("  HasVirtualWidth: %i  colsWidth: %i"),(int)pg->HasVirtualWidth(),colsWidth);
-#endif
+    wxLogTrace("propgrid",
+               wxS("  HasVirtualWidth: %i  colsWidth: %i"),
+               (int)pg->HasVirtualWidth(), colsWidth);
 
     // Then mode-based requirement
     if ( !pg->HasVirtualWidth() )
@@ -993,10 +983,9 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
         if ( colsWidth < width )
         {
             // Increase column
-#ifdef __WXDEBUG__
-            if ( debug )
-                wxLogDebug(wxT("  Adjust last column to %i"), m_colWidths[lastColumn] + widthHigher);
-#endif
+            wxLogTrace("propgrid",
+                       wxS("  Adjust last column to %i"),
+                       m_colWidths[lastColumn] + widthHigher);
             m_colWidths[lastColumn] = m_colWidths[lastColumn] + widthHigher;
         }
         else if ( colsWidth > width )
@@ -1004,10 +993,10 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
             // Reduce column
             if ( reduceCol != -1 )
             {
-            #ifdef __WXDEBUG__
-                if ( debug )
-                    wxLogDebug(wxT("  Reduce column %i (by %i)"), reduceCol, -widthHigher);
-            #endif
+                wxLogTrace("propgrid",
+                           wxT("  Reduce column %i (by %i)"),
+                           reduceCol, -widthHigher);
+
                 // Reduce widest column, and recheck
                 m_colWidths[reduceCol] = m_colWidths[reduceCol] + widthHigher;
                 CheckColumnWidths();
@@ -1029,11 +1018,10 @@ void wxPropertyGridPageState::CheckColumnWidths( int widthChange )
             pg->RecalculateVirtualSize();
     }
 
-#ifdef __WXDEBUG__
-    if ( debug )
-        for ( i=0; i<m_colWidths.size(); i++ )
-            wxLogDebug(wxT("col%i: %i"),i,m_colWidths[i]);
-#endif
+    for ( i=0; i<m_colWidths.size(); i++ )
+    {
+        wxLogTrace("propgrid", wxS("col%i: %i"), i, m_colWidths[i]);
+    }
 
     // Auto center splitter
     if ( !(pg->GetInternalFlags() & wxPG_FL_DONT_CENTER_SPLITTER) &&
@@ -1428,13 +1416,12 @@ void wxPropertyGridPageState::DoSetPropertyValues( const wxVariantList& list, wx
                     }
                     else
                     {
-                #ifdef __WXDEBUG__
-                        if ( wxStrcmp(current->GetType(), p->GetValue().GetType()) != 0)
-                        {
-                            wxLogDebug(wxT("wxPropertyGridPageState::DoSetPropertyValues Warning: Setting value of property \"%s\" from variant"),
-                                p->GetName().c_str());
-                        }
-                #endif
+                        wxASSERT_LEVEL_2_MSG(
+                            wxStrcmp(current->GetType(), p->GetValue().GetType()) == 0,
+                            wxString::Format(
+                                wxS("setting value of property \"%s\" from variant"),
+                                p->GetName().c_str())
+                        );
 
                         p->SetValue(*current);
                     }
@@ -1570,16 +1557,18 @@ bool wxPropertyGridPageState::PrepareToAddItem( wxPGProperty* property,
         }
     }
 
-#ifdef __WXDEBUG__
+#if wxDEBUG_LEVEL
     // Warn for identical names in debug mode.
     if ( BaseGetPropertyByName(property->GetName()) &&
          (!scheduledParent || scheduledParent->IsCategory()) )
     {
-        wxLogError(wxT("wxPropertyGrid: Warning - item with name \"%s\" already exists."),
-            property->GetName().c_str());
+        wxFAIL_MSG(wxString::Format(
+            "wxPropertyGrid item with name \"%s\" already exists",
+            property->GetName()));
+
         wxPGGlobalVars->m_warnings++;
     }
-#endif
+#endif // wxDEBUG_LEVEL
 
     // Make sure nothing is selected.
     if ( propGrid )
@@ -1659,11 +1648,11 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
         if ( m_abcArray && !property->IsCategory() &&
              (parentIsCategory || parentIsRoot) )
         {
-            m_abcArray->AddChild2( property, -1, false );
+            m_abcArray->DoAddChild( property, -1, false );
         }
 
         // Add to current mode.
-        parent->AddChild2( property, index, true );
+        parent->DoAddChild( property, index, true );
     }
     else
     {
@@ -1671,14 +1660,14 @@ wxPGProperty* wxPropertyGridPageState::DoInsert( wxPGProperty* parent, int index
 
         if ( parentIsCategory )
             // Parent is category.
-            parent->AddChild2( property, index, false );
+            parent->DoAddChild( property, index, false );
         else if ( parentIsRoot )
             // Parent is root.
-            m_regularArray.AddChild2( property, -1, false );
+            m_regularArray.DoAddChild( property, -1, false );
 
         // Add to current mode
         if ( !property->IsCategory() )
-            m_abcArray->AddChild2( property, index, true );
+            m_abcArray->DoAddChild( property, index, true );
     }
 
     // category stuff