#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");
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
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()
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 )
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,
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);
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);
unsigned int wxDataViewIndexListModel::GetChildren( const wxDataViewItem &item, wxDataViewItemArray &children ) const
{
+ if (!m_useHash)
+ return 0; // error
+
if (item.IsOk())
return 0;