X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/a76c2f3715f6a1d343f0716f7924db33077843e1..850df2d78866c3edcf848103b5dbc7e7fa1ee5fa:/src/common/datavcmn.cpp diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 9fa5635c20..09353943d8 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -20,12 +20,13 @@ #include "wx/dataview.h" #include "wx/spinctrl.h" -#include "wx/dc.h" -#include "wx/settings.h" #ifndef WX_PRECOMP + #include "wx/dc.h" + #include "wx/settings.h" #include "wx/log.h" #include "wx/icon.h" + #include "wx/crt.h" #endif const wxChar wxDataViewCtrlNameStr[] = wxT("dataviewCtrl"); @@ -36,6 +37,12 @@ bool operator == (const wxDataViewItem &left, const wxDataViewItem &right) return (left.GetID() == right.GetID() ); } +#ifdef __WXDEBUG__ +void wxDataViewItem::Print(const wxString& text) const +{ + wxPrintf("item %s: %l\n", text, (long)m_id); +} +#endif // --------------------------------------------------------- // wxDataViewModelNotifier @@ -292,11 +299,27 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size ) { - // build initial index - unsigned int i; - for (i = 1; i < initial_size+1; i++) - m_hash.Add( (void*) i ); - m_lastIndex = initial_size + 1; +#ifndef __WXMAC__ + m_useHash = false; +#else + m_useHash = true; +#endif + + if (m_useHash) + { + // IDs are ordered until an item gets deleted or inserted + m_ordered = true; + + // build initial index + unsigned int i; + for (i = 1; i < initial_size+1; i++) + m_hash.Add( (void*) i ); + m_lastIndex = initial_size + 1; + } + else + { + m_lastIndex = initial_size-1; + } } wxDataViewIndexListModel::~wxDataViewIndexListModel() @@ -305,33 +328,73 @@ wxDataViewIndexListModel::~wxDataViewIndexListModel() void wxDataViewIndexListModel::RowPrepended() { - unsigned int id = m_lastIndex++; - m_hash.Insert( (void*) id, 0 ); - wxDataViewItem item( (void*) id ); - ItemAdded( wxDataViewItem(0), item ); + if (m_useHash) + { + m_ordered = false; + + unsigned int id = m_lastIndex++; + m_hash.Insert( (void*) id, 0 ); + wxDataViewItem item( (void*) id ); + ItemAdded( wxDataViewItem(0), item ); + } + else + { + m_lastIndex++; + wxDataViewItem item( (void*) 0 ); + ItemAdded( wxDataViewItem(0), item ); + } } void wxDataViewIndexListModel::RowInserted( unsigned int before ) { - unsigned int id = m_lastIndex++; - m_hash.Insert( (void*) id, before ); - wxDataViewItem item( (void*) id ); - ItemAdded( wxDataViewItem(0), item ); + if (m_useHash) + { + m_ordered = false; + + unsigned int id = m_lastIndex++; + m_hash.Insert( (void*) id, before ); + wxDataViewItem item( (void*) id ); + ItemAdded( wxDataViewItem(0), item ); + } + else + { + m_lastIndex++; + wxDataViewItem item( (void*) before ); + ItemAdded( wxDataViewItem(0), item ); + } } void wxDataViewIndexListModel::RowAppended() { - unsigned int id = m_lastIndex++; - m_hash.Add( (void*) id ); - wxDataViewItem item( (void*) id ); - ItemAdded( wxDataViewItem(0), item ); + if (m_useHash) + { + unsigned int id = m_lastIndex++; + m_hash.Add( (void*) id ); + wxDataViewItem item( (void*) id ); + ItemAdded( wxDataViewItem(0), item ); + } + else + { + m_lastIndex++; + wxDataViewItem item( (void*) m_lastIndex ); + ItemAdded( wxDataViewItem(0), item ); + } } void wxDataViewIndexListModel::RowDeleted( unsigned int row ) { - wxDataViewItem item( m_hash[row] ); - wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); - m_hash.RemoveAt( row ); + if (m_useHash) + { + wxDataViewItem item( m_hash[row] ); + wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); + m_hash.RemoveAt( row ); + } + else + { + wxDataViewItem item( (void*) row ); + wxDataViewModel::ItemDeleted( wxDataViewItem(0), item ); + m_lastIndex++; + } } void wxDataViewIndexListModel::RowChanged( unsigned int row ) @@ -346,14 +409,39 @@ void wxDataViewIndexListModel::RowValueChanged( unsigned int row, unsigned int c unsigned int wxDataViewIndexListModel::GetRow( const wxDataViewItem &item ) const { - // assert for not found - return (unsigned int) m_hash.Index( item.GetID() ); + if (m_useHash) + { + if (m_ordered) + { + unsigned int pos = wxPtrToUInt( item.GetID() ); + return pos-1; + } + + // assert for not found + return (unsigned int) m_hash.Index( item.GetID() ); + } + else + { + return wxPtrToUInt( item.GetID() ); + } } wxDataViewItem wxDataViewIndexListModel::GetItem( unsigned int row ) const { - wxASSERT( row < m_hash.GetCount() ); - return wxDataViewItem( m_hash[row] ); + if (m_useHash) + { + wxASSERT( row < m_hash.GetCount() ); + return wxDataViewItem( m_hash[row] ); + } + else + { + return wxDataViewItem( (void*) row ); + } +} + +bool wxDataViewIndexListModel::HasDefaultCompare() const +{ + return !m_ordered; } int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, @@ -361,6 +449,17 @@ int wxDataViewIndexListModel::Compare(const wxDataViewItem& item1, unsigned int WXUNUSED(column), bool ascending) { + if (m_ordered || !m_useHash) + { + unsigned int pos1 = wxPtrToUInt(item1.GetID()); + unsigned int pos2 = wxPtrToUInt(item2.GetID()); + + if (ascending) + return pos1 - pos2; + else + return pos2 - pos1; + } + if (ascending) return GetRow(item1) - GetRow(item2); @@ -379,6 +478,11 @@ bool wxDataViewIndexListModel::SetValue( const wxVariant &variant, return SetValue( variant, GetRow(item), col ); } +bool wxDataViewIndexListModel::GetAttr( const wxDataViewItem &item, unsigned int col, wxDataViewItemAttr &attr ) +{ + return GetAttr( GetRow(item), col, attr ); +} + wxDataViewItem wxDataViewIndexListModel::GetParent( const wxDataViewItem & WXUNUSED(item) ) const { return wxDataViewItem(0); @@ -395,6 +499,9 @@ bool wxDataViewIndexListModel::IsContainer( const wxDataViewItem &item ) const unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const { + if (!m_useHash) + return 0; // error + if (item.IsOk()) return 0;