-void wxDataViewMainWindow::OnRenameTimer()
-{
- // We have to call this here because changes may just have
- // been made and no screen update taken place.
- if ( m_dirty )
- wxSafeYield();
-
- int xpos = 0;
- unsigned int cols = GetOwner()->GetColumnCount();
- unsigned int i;
- for (i = 0; i < cols; i++)
- {
- wxDataViewColumn *c = GetOwner()->GetColumn( i );
- if (c->IsHidden())
- continue; // skip it!
-
- if (c == m_currentCol)
- break;
- xpos += c->GetWidth();
- }
- wxRect labelRect( xpos, m_currentRow * m_lineHeight,
- m_currentCol->GetWidth(), m_lineHeight );
-
- GetOwner()->CalcScrolledPosition( labelRect.x, labelRect.y,
- &labelRect.x, &labelRect.y);
-
- wxDataViewItem item = GetItemByRow( m_currentRow );
- m_currentCol->GetRenderer()->StartEditing( item, labelRect );
-}
-
-//------------------------------------------------------------------
-// Helper class for do operation on the tree node
-//------------------------------------------------------------------
-class DoJob
-{
-public:
- DoJob(){};
- virtual ~DoJob(){};
-
- //The return value control how the tree-walker tranverse the tree
- // 0: Job done, stop tranverse and return
- // 1: Ignore the current node's subtree and continue
- // 2: Job not done, continue
- enum { OK = 0 , IGR = 1, CONT = 2 };
- virtual int operator() ( wxDataViewTreeNode * node ) = 0 ;
-};
-
-class ItemAddJob: public DoJob
-{
-public:
- ItemAddJob( const wxDataViewItem & parent, const wxDataViewItem & item, int * count )
- { this->parent = parent ; this->item = item ; m_count = count; }
- virtual ~ItemAddJob(){};
-
- virtual int operator() ( wxDataViewTreeNode * node )
- {
- if( node->GetItem() == parent )
- {
- node->SetHasChildren( true );
- wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
- newnode->SetItem(item);
- node->AppendChild( newnode);
- *m_count = -1;
- return OK;
- }
- return CONT;
- }
-
-private:
- int * m_count;
- wxDataViewItem parent, item;
-};
-
-bool Walker( wxDataViewTreeNode * node, DoJob & func )
-{
- if( node==NULL || !node->HasChildren())
- return false;
-
- wxDataViewTreeNodes nodes = node->GetChildren();
- int len = node->GetChildrenNumber();
- int i = 0 ;
- for( ; i < len ; i ++ )
- {
- wxDataViewTreeNode * n = nodes[i];
- switch( func( n ) )
- {
- case DoJob::OK :
- return true ;
- case DoJob::IGR:
- continue;
- case DoJob::CONT:
- default:
- ;
- }
-
- if( Walker( n , func ) )
- return true;
- }
- return false;
-}
-
-bool wxDataViewMainWindow::ItemAdded(const wxDataViewItem & parent, const wxDataViewItem & item)
-{
- ItemAddJob job( parent, item, &m_count);
- Walker( m_root , job);
- UpdateDisplay();
- return true;
-}
-
-class ItemDeleteJob: public DoJob
-{
-public:
- ItemDeleteJob( const wxDataViewItem & item, int * count ) { m_item = item; m_count = count; }
- virtual ~ItemDeleteJob(){}
- virtual int operator() ( wxDataViewTreeNode * node )
- {
- if( node->GetItem() == m_item )
- {
- node->GetParent()->GetChildren().Remove( node );
- delete node;
- *m_count = -1;
- return DoJob::OK;
- }
- return DoJob::CONT;
- }
-
-private:
- int * m_count;
- wxDataViewItem m_item;
-};
-
-bool wxDataViewMainWindow::ItemDeleted(const wxDataViewItem & item)
-{
- ItemDeleteJob job( item, &m_count);
- Walker( m_root, job);
- UpdateDisplay();
- return true;
-}
-
-bool wxDataViewMainWindow::ItemChanged(const wxDataViewItem & item)
-{
- unsigned int row = GetRowByItem(item);
- RefreshRow( row );
- return true;
-}
-
-bool wxDataViewMainWindow::ValueChanged( const wxDataViewItem & item, unsigned int WXUNUSED(col) )
-{
- // NOTE: to be valid, we cannot use e.g. INT_MAX - 1
-/*#define MAX_VIRTUAL_WIDTH 100000
-
- wxRect rect( 0, row*m_lineHeight, MAX_VIRTUAL_WIDTH, m_lineHeight );
- m_owner->CalcScrolledPosition( rect.x, rect.y, &rect.x, &rect.y );
- Refresh( true, &rect );
-
- return true;
-*/
- unsigned int row = GetRowByItem(item);
- RefreshRow( row );
- return true;
-}
-
-bool wxDataViewMainWindow::Cleared()
-{
- DestroyTree();
- UpdateDisplay();
- return true;
-}
-
-void wxDataViewMainWindow::UpdateDisplay()
-{
- m_dirty = true;
-}
-
-void wxDataViewMainWindow::OnInternalIdle()
-{
- wxWindow::OnInternalIdle();
-
- if (m_dirty)
- {
- RecalculateDisplay();
- m_dirty = false;
- }
-}
-
-void wxDataViewMainWindow::RecalculateDisplay()
-{
- wxDataViewModel *model = GetOwner()->GetModel();
- if (!model)
- {
- Refresh();
- return;
- }
-
- int width = GetEndOfLastCol();
- int height = GetRowCount() * m_lineHeight;
-
- SetVirtualSize( width, height );
- GetOwner()->SetScrollRate( 10, m_lineHeight );
-
- Refresh();
-}
-
-void wxDataViewMainWindow::ScrollWindow( int dx, int dy, const wxRect *rect )
-{
- wxWindow::ScrollWindow( dx, dy, rect );
-
- if (GetOwner()->m_headerArea)
- GetOwner()->m_headerArea->ScrollWindow( dx, 0 );
-}
-