]> git.saurik.com Git - wxWidgets.git/commitdiff
Many more corrections and clarifications to virtual index list model use
authorRobert Roebling <robert@roebling.de>
Tue, 16 Jun 2009 17:59:09 +0000 (17:59 +0000)
committerRobert Roebling <robert@roebling.de>
Tue, 16 Jun 2009 17:59:09 +0000 (17:59 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/dataview.h
src/common/datavcmn.cpp
src/generic/datavgen.cpp
src/gtk/dataview.cpp

index 63e2f6460b1f84d1d3eef0a88a1d28c5200fb74f..951653494589319a59565eb0fab3bd684657e549 100644 (file)
@@ -274,11 +274,11 @@ public:
 
     // internal
     virtual bool IsVirtualListModel() const { return false; }
 
     // internal
     virtual bool IsVirtualListModel() const { return false; }
-    unsigned int GetLastIndex() const { return m_lastIndex; }
+    unsigned int GetCount() const { return m_hash.GetCount(); }
 
 private:
     wxDataViewItemArray m_hash;
 
 private:
     wxDataViewItemArray m_hash;
-    unsigned int m_lastIndex;
+    unsigned int m_nextFreeID;
     bool m_ordered;
 };
 
     bool m_ordered;
 };
 
@@ -339,11 +339,10 @@ public:
 
     // internal
     virtual bool IsVirtualListModel() const { return true; }
 
     // internal
     virtual bool IsVirtualListModel() const { return true; }
-    unsigned int GetLastIndex() const { return m_lastIndex; }
+    unsigned int GetCount() const { return m_size; }
 
 private:
 
 private:
-    wxDataViewItemArray m_hash;
-    unsigned int m_lastIndex;
+    unsigned int m_size;
     bool m_ordered;
 };
 #endif
     bool m_ordered;
 };
 #endif
index d7b9b7d7af28694d84cacff5d1a8d68d311073bb..ddfbd8c7e6306a4a28f7611af10944d7c120416c 100644 (file)
@@ -309,7 +309,7 @@ wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
     unsigned int i;
     for (i = 1; i < initial_size+1; i++)
             m_hash.Add( wxUIntToPtr(i) );
     unsigned int i;
     for (i = 1; i < initial_size+1; i++)
             m_hash.Add( wxUIntToPtr(i) );
-    m_lastIndex = initial_size + 1;
+    m_nextFreeID = initial_size + 1;
 }
 
 wxDataViewIndexListModel::~wxDataViewIndexListModel()
 }
 
 wxDataViewIndexListModel::~wxDataViewIndexListModel()
@@ -327,7 +327,8 @@ void wxDataViewIndexListModel::Reset( unsigned int new_size )
     unsigned int i;
     for (i = 1; i < new_size+1; i++)
             m_hash.Add( wxUIntToPtr(i) );
     unsigned int i;
     for (i = 1; i < new_size+1; i++)
             m_hash.Add( wxUIntToPtr(i) );
-    m_lastIndex = new_size + 1;
+            
+    m_nextFreeID = new_size + 1;
 
     wxDataViewModel::Cleared();
 }
 
     wxDataViewModel::Cleared();
 }
@@ -336,17 +337,22 @@ void wxDataViewIndexListModel::RowPrepended()
 {
     m_ordered = false;
 
 {
     m_ordered = false;
 
-    unsigned int id = m_lastIndex++;
+    unsigned int id = m_nextFreeID;
+    m_nextFreeID++;
+    
     m_hash.Insert( wxUIntToPtr(id), 0 );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
     m_hash.Insert( wxUIntToPtr(id), 0 );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
+    
 }
 
 void wxDataViewIndexListModel::RowInserted( unsigned int before )
 {
     m_ordered = false;
 
 }
 
 void wxDataViewIndexListModel::RowInserted( unsigned int before )
 {
     m_ordered = false;
 
-    unsigned int id = m_lastIndex++;
+    unsigned int id = m_nextFreeID;
+    m_nextFreeID++;
+    
     m_hash.Insert( wxUIntToPtr(id), before );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
     m_hash.Insert( wxUIntToPtr(id), before );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
@@ -354,7 +360,9 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before )
 
 void wxDataViewIndexListModel::RowAppended()
 {
 
 void wxDataViewIndexListModel::RowAppended()
 {
-    unsigned int id = m_lastIndex++;
+    unsigned int id = m_nextFreeID;
+    m_nextFreeID++;
+    
     m_hash.Add( wxUIntToPtr(id) );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
     m_hash.Add( wxUIntToPtr(id) );
     wxDataViewItem item( wxUIntToPtr(id) );
     ItemAdded( wxDataViewItem(0), item );
@@ -402,10 +410,7 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c
 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
 {
     if (m_ordered)
 unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const
 {
     if (m_ordered)
-    {
-            unsigned int pos = wxPtrToUInt( item.GetID() );
-            return pos-1;
-    }
+        return wxPtrToUInt(item.GetID())-1;
 
     // assert for not found
     return (unsigned int) m_hash.Index( item.GetID() );
 
     // assert for not found
     return (unsigned int) m_hash.Index( item.GetID() );
@@ -429,8 +434,8 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1,
 {
     if (m_ordered)
     {
 {
     if (m_ordered)
     {
-        unsigned int pos1 = wxPtrToUInt(item1.GetID());
-        unsigned int pos2 = wxPtrToUInt(item2.GetID());
+        unsigned int pos1 = wxPtrToUInt(item1.GetID());  // -1 not needed here
+        unsigned int pos2 = wxPtrToUInt(item2.GetID());  // -1 not needed here
 
         if (ascending)
             return pos1 - pos2;
 
         if (ascending)
             return pos1 - pos2;
@@ -493,7 +498,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item,
 
 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
 {
 
 wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
 {
-    m_lastIndex = initial_size-1;
+    m_size = initial_size;
 }
 
 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
 }
 
 wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
@@ -502,29 +507,29 @@ wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
 
 void wxDataViewVirtualListModel::Reset( unsigned int new_size )
 {
 
 void wxDataViewVirtualListModel::Reset( unsigned int new_size )
 {
-    m_lastIndex = new_size-1;
+    m_size = new_size;
 
     wxDataViewModel::Cleared();
 }
 
 void wxDataViewVirtualListModel::RowPrepended()
 {
 
     wxDataViewModel::Cleared();
 }
 
 void wxDataViewVirtualListModel::RowPrepended()
 {
-    m_lastIndex++;
+    m_size++;
     wxDataViewItem item( wxUIntToPtr(1) );
     ItemAdded( wxDataViewItem(0), item );
 }
 
 void wxDataViewVirtualListModel::RowInserted( unsigned int before )
 {
     wxDataViewItem item( wxUIntToPtr(1) );
     ItemAdded( wxDataViewItem(0), item );
 }
 
 void wxDataViewVirtualListModel::RowInserted( unsigned int before )
 {
-    m_lastIndex++;
+    m_size++;
     wxDataViewItem item( wxUIntToPtr(before+1) );
     ItemAdded( wxDataViewItem(0), item );
 }
 
 void wxDataViewVirtualListModel::RowAppended()
 {
     wxDataViewItem item( wxUIntToPtr(before+1) );
     ItemAdded( wxDataViewItem(0), item );
 }
 
 void wxDataViewVirtualListModel::RowAppended()
 {
-    m_lastIndex++;
-    wxDataViewItem item( wxUIntToPtr(m_lastIndex+1) );
+    m_size++;
+    wxDataViewItem item( wxUIntToPtr(m_size) );
     ItemAdded( wxDataViewItem(0), item );
 }
 
     ItemAdded( wxDataViewItem(0), item );
 }
 
@@ -532,7 +537,7 @@ void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
 {
     wxDataViewItem item( wxUIntToPtr(row+1) );
     wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
 {
     wxDataViewItem item( wxUIntToPtr(row+1) );
     wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
-    m_lastIndex++;
+    m_size--;
 }
 
 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
 }
 
 void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
@@ -549,7 +554,7 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
     }
     wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
 
     }
     wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
 
-    m_lastIndex -= rows.GetCount();
+    m_size -= rows.GetCount();
 }
 
 void wxDataViewVirtualListModel::RowChanged( unsigned int row )
 }
 
 void wxDataViewVirtualListModel::RowChanged( unsigned int row )
@@ -582,8 +587,8 @@ int wxDataViewVirtualListModel::Compare(const wxDataViewItem& item1,
                                       unsigned int WXUNUSED(column),
                                       bool ascending) const
 {
                                       unsigned int WXUNUSED(column),
                                       bool ascending) const
 {
-    unsigned int pos1 = wxPtrToUInt(item1.GetID())-1;
-    unsigned int pos2 = wxPtrToUInt(item2.GetID())-1;
+    unsigned int pos1 = wxPtrToUInt(item1.GetID());  // -1 not needed here
+    unsigned int pos2 = wxPtrToUInt(item2.GetID());  // -1 not needed here
 
     if (ascending)
        return pos1 - pos2;
 
     if (ascending)
        return pos1 - pos2;
index feb59e3a52c2b9db8cfdfe041168333be476d36b..aba7354e03c7c3996e508bc661f67b6bb1517617 100644 (file)
@@ -3204,13 +3204,9 @@ int wxDataViewMainWindow::RecalculateCount()
 {
     if (IsVirtualList())
     {
 {
     if (IsVirtualList())
     {
-        wxDataViewIndexListModel *list_model =
-            (wxDataViewIndexListModel*) GetOwner()->GetModel();
-#ifndef __WXMAC__
-        return list_model->GetLastIndex() + 1;
-#else
-        return list_model->GetLastIndex() - 1;
-#endif
+        wxDataViewVirtualListModel *list_model =
+            (wxDataViewVirtualListModel*) GetOwner()->GetModel();
+        return list_model->GetCount();
     }
     else
     {
     }
     else
     {
index 040ddc6e615d72818978b337bfb6d4fa503be399..0110325a42bd5087cee30c42931515ef791d69a2 100644 (file)
@@ -3407,13 +3407,14 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
 
 gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
 {
 
 gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
 {
+
     if (m_wx_model->IsVirtualListModel())
     {
     if (m_wx_model->IsVirtualListModel())
     {
-        wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
-
+        wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+    
         unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
         unsigned int i = (unsigned int)gtk_tree_path_get_indices (path)[0];
-
-        if (i >= wx_model->GetLastIndex() + 1)
+        
+        if (i >= wx_model->GetCount())
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
@@ -3496,7 +3497,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
 {
     if (m_wx_model->IsVirtualListModel())
     {
 {
     if (m_wx_model->IsVirtualListModel())
     {
-        wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+        wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
 
         // user_data is just the index +1
         int n = ( (wxUIntPtr) iter->user_data ) -1;
 
         // user_data is just the index +1
         int n = ( (wxUIntPtr) iter->user_data ) -1;
@@ -3504,7 +3505,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
         if (n == -1)
             return FALSE;
 
         if (n == -1)
             return FALSE;
 
-        if (n >= (int) wx_model->GetLastIndex())
+        if (n >= (int) wx_model->GetCount())
             return FALSE;
 
         // user_data is just the index +1 (+2 because we need the next)
             return FALSE;
 
         // user_data is just the index +1 (+2 because we need the next)
@@ -3537,7 +3538,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
-        iter->user_data = (gpointer) 0;
+        iter->user_data = (gpointer) 1;
 
         return TRUE;
     }
 
         return TRUE;
     }
@@ -3568,6 +3569,11 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
 {
     if (m_wx_model->IsVirtualListModel())
     {
 {
     if (m_wx_model->IsVirtualListModel())
     {
+        wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
+
+        if (iter == NULL)
+            return (gint) wx_model->GetCount();
+        
         // this is a list, nodes have no children
         return FALSE;
     }
         // this is a list, nodes have no children
         return FALSE;
     }
@@ -3594,10 +3600,10 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
 {
     if (m_wx_model->IsVirtualListModel())
     {
 {
     if (m_wx_model->IsVirtualListModel())
     {
-        wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+        wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
 
         if (iter == NULL)
 
         if (iter == NULL)
-            return (gint) wx_model->GetLastIndex() + 1;
+            return (gint) wx_model->GetCount();
 
         return 0;
     }
 
         return 0;
     }
@@ -3627,7 +3633,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
 {
     if (m_wx_model->IsVirtualListModel())
     {
 {
     if (m_wx_model->IsVirtualListModel())
     {
-        wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
+        wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
 
         if (parent)
             return FALSE;
 
         if (parent)
             return FALSE;
@@ -3635,12 +3641,12 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
         if (n < 0)
             return FALSE;
 
         if (n < 0)
             return FALSE;
 
-        if (n >= (gint) wx_model->GetLastIndex() + 1)
+        if (n >= (gint) wx_model->GetCount())
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
         // user_data is just the index +1
             return FALSE;
 
         iter->stamp = m_gtk_model->stamp;
         // user_data is just the index +1
-        iter->user_data = (gpointer) (n-1);
+        iter->user_data = (gpointer) (n+1);
 
         return TRUE;
     }
 
         return TRUE;
     }