-static int my_sort_reverse( int *v1, int *v2 )
-{
- return *v2-*v1;
-}
-
-static int my_sort( int *v1, int *v2 )
-{
- return *v1-*v2;
-}
-
-class MyListModel: public wxDataViewVirtualListModel
-{
-public:
- MyListModel() :
-#ifdef __WXMAC__
- wxDataViewVirtualListModel( 1000 + 100 )
-#else
- wxDataViewVirtualListModel( 100000 + 100 )
-#endif
- {
-#ifdef __WXMAC__
- m_virtualItems = 1000;
-#else
- m_virtualItems = 100000;
-#endif
-
- unsigned int i;
- for (i = 0; i < 100; i++)
- {
- wxString str;
- str.Printf( wxT("row number %d"), i );
- m_array.Add( str );
- }
-
- m_icon = wxIcon( null_xpm );
- }
-
- // helper methods to change the model
-
- void Prepend( const wxString &text )
- {
- m_array.Insert( text, 0 );
- RowPrepended();
- }
-
- void DeleteItem( const wxDataViewItem &item )
- {
- unsigned int row = GetRow( item );
- if (row >= m_array.GetCount())
- return;
-
- m_array.RemoveAt( row );
- RowDeleted( row );
- }
-
- void DeleteItems( const wxDataViewItemArray &items )
- {
- wxArrayInt rows;
- unsigned int i;
- for (i = 0; i < items.GetCount(); i++)
- {
- unsigned int row = GetRow( items[i] );
- if (row < m_array.GetCount())
- rows.Add( row );
- }
-
- // Sort in descending order so that the last
- // row will be deleted first. Otherwise the
- // remaining indeces would all be wrong.
- rows.Sort( my_sort_reverse );
- for (i = 0; i < rows.GetCount(); i++)
- m_array.RemoveAt( rows[i] );
-
- // This is just to test if wxDataViewCtrl can
- // cope with removing rows not sorted in
- // descending order
- rows.Sort( my_sort );
- RowsDeleted( rows );
- }
-
- void AddMany()
- {
- m_virtualItems += 1000;
- Reset( m_array.GetCount() + m_virtualItems );
- }
-
- // implementation of base class virtuals to define model
-
- virtual unsigned int GetColumnCount() const
- {
- return 3;
- }
-
- virtual wxString GetColumnType( unsigned int col ) const
- {
- if (col == 1)
- return wxT("wxDataViewIconText");
-
- return wxT("string");
- }
-
- virtual unsigned int GetRowCount()
- {
- return m_array.GetCount();
- }
-
- virtual void GetValue( wxVariant &variant,
- unsigned int row, unsigned int col ) const
- {
- if (col==0)
- {
- if (row >= m_array.GetCount())
- {
- wxString str;
- str.Printf(wxT("row %d"), row - m_array.GetCount() );
- variant = str;
- }
- else
- {
- variant = m_array[ row ];
- }
- } else
- if (col==1)
- {
- wxDataViewIconText data( wxT("test"), m_icon );
- variant << data;
- } else
- if (col==2)
- {
- if (row >= m_array.GetCount())
- variant = wxT("plain");
- else
- variant = wxT("blue");
- }
- }
-
- virtual bool GetAttr( unsigned int row, unsigned int col, wxDataViewItemAttr &attr )
- {
- if (col != 2)
- return false;
-
- if (row < m_array.GetCount())
- {
- attr.SetColour( *wxBLUE );
- attr.SetItalic( true );
- }
-
- return true;
- }
-
- virtual bool SetValue( const wxVariant &variant,
- unsigned int row, unsigned int col )
- {
- if (col == 0)
- {
- if (row >= m_array.GetCount())
- return false;
-
- m_array[row] = variant.GetString();
- return true;
- }
-
- return false;
- }
-
- wxArrayString m_array;
- wxIcon m_icon;
- int m_virtualItems;
-};
-
-// -------------------------------------