Many more corrections and clarifications to virtual index list model use
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@61078 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -274,11 +274,11 @@ public:
|
||||
|
||||
// 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;
|
||||
unsigned int m_lastIndex;
|
||||
unsigned int m_nextFreeID;
|
||||
bool m_ordered;
|
||||
};
|
||||
|
||||
@@ -339,11 +339,10 @@ public:
|
||||
|
||||
// internal
|
||||
virtual bool IsVirtualListModel() const { return true; }
|
||||
unsigned int GetLastIndex() const { return m_lastIndex; }
|
||||
unsigned int GetCount() const { return m_size; }
|
||||
|
||||
private:
|
||||
wxDataViewItemArray m_hash;
|
||||
unsigned int m_lastIndex;
|
||||
unsigned int m_size;
|
||||
bool m_ordered;
|
||||
};
|
||||
#endif
|
||||
|
@@ -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) );
|
||||
m_lastIndex = initial_size + 1;
|
||||
m_nextFreeID = initial_size + 1;
|
||||
}
|
||||
|
||||
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) );
|
||||
m_lastIndex = new_size + 1;
|
||||
|
||||
m_nextFreeID = new_size + 1;
|
||||
|
||||
wxDataViewModel::Cleared();
|
||||
}
|
||||
@@ -336,17 +337,22 @@ void wxDataViewIndexListModel::RowPrepended()
|
||||
{
|
||||
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 );
|
||||
|
||||
}
|
||||
|
||||
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 );
|
||||
@@ -354,7 +360,9 @@ void wxDataViewIndexListModel::RowInserted( unsigned int before )
|
||||
|
||||
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 );
|
||||
@@ -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 pos = wxPtrToUInt( item.GetID() );
|
||||
return pos-1;
|
||||
}
|
||||
return wxPtrToUInt(item.GetID())-1;
|
||||
|
||||
// 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)
|
||||
{
|
||||
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;
|
||||
@@ -493,7 +498,7 @@ unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item,
|
||||
|
||||
wxDataViewVirtualListModel::wxDataViewVirtualListModel( unsigned int initial_size )
|
||||
{
|
||||
m_lastIndex = initial_size-1;
|
||||
m_size = initial_size;
|
||||
}
|
||||
|
||||
wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
||||
@@ -502,29 +507,29 @@ wxDataViewVirtualListModel::~wxDataViewVirtualListModel()
|
||||
|
||||
void wxDataViewVirtualListModel::Reset( unsigned int new_size )
|
||||
{
|
||||
m_lastIndex = new_size-1;
|
||||
m_size = new_size;
|
||||
|
||||
wxDataViewModel::Cleared();
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowPrepended()
|
||||
{
|
||||
m_lastIndex++;
|
||||
m_size++;
|
||||
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()
|
||||
{
|
||||
m_lastIndex++;
|
||||
wxDataViewItem item( wxUIntToPtr(m_lastIndex+1) );
|
||||
m_size++;
|
||||
wxDataViewItem item( wxUIntToPtr(m_size) );
|
||||
ItemAdded( wxDataViewItem(0), item );
|
||||
}
|
||||
|
||||
@@ -532,7 +537,7 @@ void wxDataViewVirtualListModel::RowDeleted( unsigned int row )
|
||||
{
|
||||
wxDataViewItem item( wxUIntToPtr(row+1) );
|
||||
wxDataViewModel::ItemDeleted( wxDataViewItem(0), item );
|
||||
m_lastIndex++;
|
||||
m_size--;
|
||||
}
|
||||
|
||||
void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
||||
@@ -549,7 +554,7 @@ void wxDataViewVirtualListModel::RowsDeleted( const wxArrayInt &rows )
|
||||
}
|
||||
wxDataViewModel::ItemsDeleted( wxDataViewItem(0), array );
|
||||
|
||||
m_lastIndex -= rows.GetCount();
|
||||
m_size -= rows.GetCount();
|
||||
}
|
||||
|
||||
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 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;
|
||||
|
@@ -3204,13 +3204,9 @@ int wxDataViewMainWindow::RecalculateCount()
|
||||
{
|
||||
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
|
||||
{
|
||||
|
@@ -3407,13 +3407,14 @@ GtkTreeModelFlags wxDataViewCtrlInternal::get_flags()
|
||||
|
||||
gboolean wxDataViewCtrlInternal::get_iter( GtkTreeIter *iter, GtkTreePath *path )
|
||||
{
|
||||
|
||||
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];
|
||||
|
||||
if (i >= wx_model->GetLastIndex() + 1)
|
||||
if (i >= wx_model->GetCount())
|
||||
return FALSE;
|
||||
|
||||
iter->stamp = m_gtk_model->stamp;
|
||||
@@ -3496,7 +3497,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
||||
{
|
||||
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;
|
||||
@@ -3504,7 +3505,7 @@ gboolean wxDataViewCtrlInternal::iter_next( GtkTreeIter *iter )
|
||||
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)
|
||||
@@ -3537,7 +3538,7 @@ gboolean wxDataViewCtrlInternal::iter_children( GtkTreeIter *iter, GtkTreeIter *
|
||||
return FALSE;
|
||||
|
||||
iter->stamp = m_gtk_model->stamp;
|
||||
iter->user_data = (gpointer) 0;
|
||||
iter->user_data = (gpointer) 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
@@ -3568,6 +3569,11 @@ gboolean wxDataViewCtrlInternal::iter_has_child( GtkTreeIter *iter )
|
||||
{
|
||||
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;
|
||||
}
|
||||
@@ -3594,10 +3600,10 @@ gint wxDataViewCtrlInternal::iter_n_children( GtkTreeIter *iter )
|
||||
{
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||
|
||||
if (iter == NULL)
|
||||
return (gint) wx_model->GetLastIndex() + 1;
|
||||
return (gint) wx_model->GetCount();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -3627,7 +3633,7 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
||||
{
|
||||
if (m_wx_model->IsVirtualListModel())
|
||||
{
|
||||
wxDataViewIndexListModel *wx_model = (wxDataViewIndexListModel*) m_wx_model;
|
||||
wxDataViewVirtualListModel *wx_model = (wxDataViewVirtualListModel*) m_wx_model;
|
||||
|
||||
if (parent)
|
||||
return FALSE;
|
||||
@@ -3635,12 +3641,12 @@ gboolean wxDataViewCtrlInternal::iter_nth_child( GtkTreeIter *iter, GtkTreeIter
|
||||
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
|
||||
iter->user_data = (gpointer) (n-1);
|
||||
iter->user_data = (gpointer) (n+1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
Reference in New Issue
Block a user