+/*
+static int tree_walk_current ;
+wxDataViewTreeNode * TreeWalk( unsigned int row , wxDataViewTreeNode * node )
+{
+ wxDataViewTreeNode * ret ;
+ if( tree_walk_current == row )
+ return node;
+
+ if( node->HasChildren() && node->IsOpen())
+ {
+ wxDataViewTreeNodes nodes = node->GetChildren();
+ int len = nodes.GetCount();
+ int i = 0 ;
+ for( ; i < len; i ++)
+ {
+ tree_walk_current ++;
+ ret = TreeWalk( row, nodes[i] );
+ if( ret != NULL )
+ return ret;
+ }
+ }
+ return NULL;
+}
+*/
+
+class RowToItemJob: public DoJob
+{
+public:
+ RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current ;}
+ virtual ~RowToItemJob(){};
+
+ virtual bool operator() ( wxDataViewTreeNode * node )
+ {
+ if( current == row)
+ {
+ ret = node->GetItem() ;
+ return true;
+ }
+ current ++;
+ return false;
+ }
+
+ wxDataViewItem GetResult(){ return ret; }
+private:
+ unsigned int row;
+ int current ;
+ wxDataViewItem ret;
+};
+
+wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row)
+{
+ RowToItemJob job( row, 0 );
+ Walker( m_root , job );
+ return job.GetResult();
+}
+
+class ItemToRowJob : public DoJob
+{
+public:
+ ItemToRowJob(const wxDataViewItem & item){ this->item = item ; }
+ virtual ~ItemToRowJob(){};
+
+ virtual bool operator() ( wxDataViewTreeNode * node)
+ {
+ ret ++;
+ if( node->GetItem() == item )
+ return true;
+
+ return false;
+ }
+
+ int GetResult(){ return ret; }
+private:
+ wxDataViewItem item;
+ int ret;
+};
+
+unsigned int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
+{
+ ItemToRowJob job( item );
+ Walker(m_root , job );
+ return job.GetResult();
+}
+
+unsigned int BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
+{
+ int sum = 0 ;
+ if( !model->HasChildren( item ) )
+ return 0;
+
+ wxDataViewItem i = model->GetFirstChild( item );
+ while( i.IsOk() )
+ {
+ wxDataViewTreeNode * n = new wxDataViewTreeNode( node );
+ n->SetItem(i);
+ node->AppendChild(n);
+ int num = BuildTreeHelper( model, i, n) + 1;
+ sum += num ;
+ i = model->GetNextSibling( i );
+ }
+ return sum;
+}
+
+void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
+{
+ //First we define a invalid item to fetch the top-level elements
+ wxDataViewItem item;
+ m_count = BuildTreeHelper( model, item, m_root);
+}
+
+void DestroyTreeHelper( wxDataViewTreeNode * node )
+{
+ if( node->HasChildren() )
+ {
+ int len = node->GetChildrenNumber();
+ int i = 0 ;
+ wxDataViewTreeNodes nodes = node->GetChildren();
+ for( ; i < len; i ++ )
+ {
+ DestroyTreeHelper(nodes[i]);
+ }
+ }
+ delete node;
+}
+
+void wxDataViewMainWindow::DestroyTree()
+{
+ DestroyTreeHelper(m_root);
+ m_count = 0 ;
+}
+