More patches from Bo, reduced wxDataViewModel, more sorting preps
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@47410 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -60,11 +60,6 @@ static const int PADDING_TOPBOTTOM = 1;
|
||||
// the expander space margin
|
||||
static const int EXPANDER_MARGIN = 4;
|
||||
|
||||
bool operator == ( const wxDataViewItem & left, const wxDataViewItem & right )
|
||||
{
|
||||
return left.GetID() == right.GetID();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxDataViewHeaderWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
@@ -393,7 +388,7 @@ public:
|
||||
void DestroyTree();
|
||||
private:
|
||||
wxDataViewTreeNode * GetTreeNodeByRow( unsigned int row );
|
||||
wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item ) { return NULL; }
|
||||
wxDataViewTreeNode * GetTreeNodeByItem( const wxDataViewItem & item ){};
|
||||
|
||||
int RecalculateCount() ;
|
||||
|
||||
@@ -1690,34 +1685,41 @@ void wxDataViewMainWindow::OnRenameTimer()
|
||||
m_currentCol->GetRenderer()->StartEditing( m_currentRow, labelRect );
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------
|
||||
// Helper class for do operation on the tree node
|
||||
//------------------------------------------------------------------
|
||||
class DoJob
|
||||
{
|
||||
public:
|
||||
DoJob(){};
|
||||
virtual ~DoJob() { }
|
||||
virtual ~DoJob(){};
|
||||
|
||||
virtual bool operator() ( wxDataViewTreeNode * node ) = 0 ;
|
||||
//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 )
|
||||
{ this->parent = parent ; this->item = item; }
|
||||
virtual ~ItemAddJob() { }
|
||||
{ this->parent = parent ; this->item = item ; }
|
||||
virtual ~ItemAddJob(){};
|
||||
|
||||
virtual bool operator() ( wxDataViewTreeNode * node )
|
||||
virtual int operator() ( wxDataViewTreeNode * node )
|
||||
{
|
||||
if( node->GetItem() == parent )
|
||||
{
|
||||
wxDataViewTreeNode * newnode = new wxDataViewTreeNode( node );
|
||||
newnode->SetItem(item);
|
||||
node->AppendChild( newnode);
|
||||
return true;
|
||||
return OK;
|
||||
}
|
||||
return false;
|
||||
return CONT;
|
||||
}
|
||||
|
||||
private:
|
||||
wxDataViewItem parent, item;
|
||||
};
|
||||
@@ -1733,15 +1735,25 @@ bool Walker( wxDataViewTreeNode * node, DoJob & func )
|
||||
for( ; i < len ; i ++ )
|
||||
{
|
||||
wxDataViewTreeNode * n = nodes[i];
|
||||
if( func( n ) )
|
||||
return true;
|
||||
if( Walker( n , func ) )
|
||||
return true;
|
||||
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);
|
||||
@@ -1971,35 +1983,37 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
||||
if( col->GetModelColumn() == GetOwner()->GetExpanderColumn() )
|
||||
{
|
||||
//Calculate the indent first
|
||||
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
|
||||
|
||||
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
|
||||
|
||||
int expander_width = m_lineHeight - 2*EXPANDER_MARGIN;
|
||||
// change the cell_rect.x to the appropriate pos
|
||||
int expander_x = indent + EXPANDER_MARGIN , expander_y = cell_rect.y + EXPANDER_MARGIN ;
|
||||
// change the cell_rect.x to the appropriate pos
|
||||
int expander_x = indent + EXPANDER_MARGIN , expander_y = cell_rect.y + EXPANDER_MARGIN ;
|
||||
indent = indent + m_lineHeight ; //try to use the m_lineHeight as the expander space
|
||||
dc.SetPen( m_penExpander );
|
||||
dc.SetBrush( wxNullBrush );
|
||||
if( node->HasChildren() )
|
||||
{
|
||||
dc.DrawRoundedRectangle( expander_x,expander_y,expander_width,expander_width, 1.0);
|
||||
dc.DrawLine( expander_x + 2 , expander_y + expander_width/2, expander_x + expander_width - 2, expander_y + expander_width/2 );
|
||||
dc.SetBrush( wxNullBrush );
|
||||
if( node->HasChildren() )
|
||||
{
|
||||
//dc.DrawRoundedRectangle( expander_x,expander_y,expander_width,expander_width, 1.0);
|
||||
//dc.DrawLine( expander_x + 2 , expander_y + expander_width/2, expander_x + expander_width - 2, expander_y + expander_width/2 );
|
||||
wxRect rect( expander_x , expander_y, expander_width, expander_width);
|
||||
if( node->IsOpen() )
|
||||
wxRendererNative::Get().DrawTreeItemButton( this, dc, rect, wxCONTROL_EXPANDED );
|
||||
else
|
||||
wxRendererNative::Get().DrawTreeItemButton( this, dc, rect );
|
||||
}
|
||||
else
|
||||
{
|
||||
// I am wandering whether we should draw dot lines between tree nodes
|
||||
}
|
||||
|
||||
if( !node->IsOpen() )
|
||||
dc.DrawLine( expander_x + expander_width/2, expander_y + 2, expander_x + expander_width/2, expander_y + expander_width -2 );
|
||||
}
|
||||
else
|
||||
{
|
||||
// I am wandering whether we should draw dot lines between tree nodes
|
||||
}
|
||||
|
||||
//force the expander column to left-center align
|
||||
cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
|
||||
//force the expander column to left-center align
|
||||
cell->SetAlignment( wxALIGN_CENTER_VERTICAL );
|
||||
}
|
||||
|
||||
|
||||
// cannot be bigger than allocated space
|
||||
wxSize size = cell->GetSize();
|
||||
// Because of the tree structure indent, here we should minus the width of the cell for drawing
|
||||
// Because of the tree structure indent, here we should minus the width of the cell for drawing
|
||||
size.x = wxMin( size.x + 2*PADDING_RIGHTLEFT, cell_rect.width - indent );
|
||||
size.y = wxMin( size.y + 2*PADDING_TOPBOTTOM, cell_rect.height );
|
||||
|
||||
@@ -2095,8 +2109,8 @@ unsigned int wxDataViewMainWindow::GetRowCount()
|
||||
if ( m_count == -1 )
|
||||
{
|
||||
m_count = RecalculateCount();
|
||||
int width, height;
|
||||
GetVirtualSize( &width, &height );
|
||||
int width, height;
|
||||
GetVirtualSize( &width, &height );
|
||||
height = m_count * m_lineHeight;
|
||||
|
||||
SetVirtualSize( width, height );
|
||||
@@ -2320,19 +2334,21 @@ public:
|
||||
RowToItemJob( unsigned int row , int current ) { this->row = row; this->current = current ;}
|
||||
virtual ~RowToItemJob(){};
|
||||
|
||||
virtual bool operator() ( wxDataViewTreeNode * node )
|
||||
virtual int operator() ( wxDataViewTreeNode * node )
|
||||
{
|
||||
if ( current == row)
|
||||
{
|
||||
ret = node->GetItem() ;
|
||||
return true;
|
||||
}
|
||||
current ++;
|
||||
return false;
|
||||
}
|
||||
if( current == row)
|
||||
{
|
||||
ret = node->GetItem() ;
|
||||
return DoJob::OK;
|
||||
}
|
||||
current ++;
|
||||
if ( node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
}
|
||||
|
||||
wxDataViewItem GetResult() { return ret; }
|
||||
|
||||
wxDataViewItem GetResult(){ return ret; }
|
||||
private:
|
||||
unsigned int row;
|
||||
int current ;
|
||||
@@ -2349,23 +2365,22 @@ wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row)
|
||||
class RowToTreeNodeJob: public DoJob
|
||||
{
|
||||
public:
|
||||
RowToTreeNodeJob( unsigned int row , int current )
|
||||
{ this->row = row; this->current = current ; ret = NULL ; }
|
||||
virtual ~RowToTreeNodeJob() { }
|
||||
RowToTreeNodeJob( unsigned int row , int current ) { this->row = row; this->current = current ; ret = NULL ; }
|
||||
virtual ~RowToTreeNodeJob(){};
|
||||
|
||||
virtual int operator() ( wxDataViewTreeNode * node )
|
||||
{
|
||||
if( current == row)
|
||||
{
|
||||
ret = node ;
|
||||
return DoJob::OK;
|
||||
}
|
||||
current ++;
|
||||
if ( node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
{
|
||||
if( current == row)
|
||||
{
|
||||
ret = node ;
|
||||
return DoJob::OK;
|
||||
}
|
||||
current ++;
|
||||
if ( node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
}
|
||||
|
||||
wxDataViewTreeNode * GetResult(){ return ret; }
|
||||
private:
|
||||
@@ -2386,15 +2401,15 @@ class CountJob : public DoJob
|
||||
{
|
||||
public:
|
||||
CountJob(){ count = 0 ; }
|
||||
virtual ~CountJob() { }
|
||||
virtual ~CountJob(){};
|
||||
|
||||
virtual int operator () ( wxDataViewTreeNode * node )
|
||||
{
|
||||
count ++;
|
||||
if (node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
count ++;
|
||||
if ( node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
}
|
||||
|
||||
unsigned int GetResult()
|
||||
@@ -2410,13 +2425,13 @@ void wxDataViewMainWindow::OnExpanding( unsigned int row )
|
||||
wxDataViewTreeNode * node = GetTreeNodeByRow(row);
|
||||
if( node != NULL )
|
||||
{
|
||||
if (node->HasChildren())
|
||||
if (!node->IsOpen())
|
||||
if( node->HasChildren())
|
||||
if( !node->IsOpen())
|
||||
{
|
||||
node->ToggleOpen();
|
||||
m_count = -1;
|
||||
Refresh();
|
||||
// RefreshRows(row,GetLastVisibleRow());
|
||||
node->ToggleOpen();
|
||||
m_count = -1;
|
||||
Refresh();
|
||||
//RefreshRows(row,GetLastVisibleRow());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2424,7 +2439,7 @@ void wxDataViewMainWindow::OnExpanding( unsigned int row )
|
||||
void wxDataViewMainWindow::OnCollapsing(unsigned int row)
|
||||
{
|
||||
wxDataViewTreeNode * node = GetTreeNodeByRow(row);
|
||||
if (node != NULL)
|
||||
if( node != NULL )
|
||||
{
|
||||
if( node->HasChildren() && node->IsOpen() )
|
||||
{
|
||||
@@ -2432,18 +2447,18 @@ void wxDataViewMainWindow::OnCollapsing(unsigned int row)
|
||||
m_count = -1;
|
||||
Refresh();
|
||||
//RefreshRows(row,GetLastVisibleRow());
|
||||
}
|
||||
else
|
||||
{
|
||||
node = node->GetParent();
|
||||
if( node != NULL )
|
||||
{
|
||||
int parent = GetRowByItem( node->GetItem()) ;
|
||||
SelectRow( row, false);
|
||||
SelectRow(parent , true );
|
||||
ChangeCurrentRow( parent );
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
node = node->GetParent();
|
||||
if( node != NULL )
|
||||
{
|
||||
int parent = GetRowByItem( node->GetItem()) ;
|
||||
SelectRow( row, false);
|
||||
SelectRow(parent , true );
|
||||
ChangeCurrentRow( parent );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2460,13 +2475,17 @@ public:
|
||||
ItemToRowJob(const wxDataViewItem & item){ this->item = item ; ret = 0 ; }
|
||||
virtual ~ItemToRowJob(){};
|
||||
|
||||
virtual bool operator() ( wxDataViewTreeNode * node)
|
||||
{
|
||||
ret ++;
|
||||
if( node->GetItem() == item )
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
virtual int operator() ( wxDataViewTreeNode * node)
|
||||
{
|
||||
ret ++;
|
||||
if( node->GetItem() == item )
|
||||
return DoJob::OK;
|
||||
|
||||
if( node->IsOpen())
|
||||
return DoJob::CONT;
|
||||
else
|
||||
return DoJob::IGR;
|
||||
}
|
||||
|
||||
//the row number is begin from zero
|
||||
int GetResult(){ return ret -1 ; }
|
||||
@@ -2723,24 +2742,24 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
||||
}
|
||||
|
||||
//Process the event of user clicking the expander
|
||||
bool expander = false;
|
||||
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
||||
if( node!=NULL && node->HasChildren() )
|
||||
{
|
||||
int indent = node->GetIndentLevel();
|
||||
indent = GetOwner()->GetIndent()*indent;
|
||||
wxRect rect( xpos + indent + EXPANDER_MARGIN, current * m_lineHeight + EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN,m_lineHeight-2*EXPANDER_MARGIN);
|
||||
if( rect.Contains( x, y) )
|
||||
{
|
||||
expander = true;
|
||||
node->ToggleOpen();
|
||||
m_count = -1; //make the current row number fail
|
||||
bool expander = false;
|
||||
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
||||
if( node!=NULL && node->HasChildren() )
|
||||
{
|
||||
int indent = node->GetIndentLevel();
|
||||
indent = GetOwner()->GetIndent()*indent;
|
||||
wxRect rect( xpos + indent + EXPANDER_MARGIN, current * m_lineHeight + EXPANDER_MARGIN, m_lineHeight-2*EXPANDER_MARGIN,m_lineHeight-2*EXPANDER_MARGIN);
|
||||
if( rect.Contains( x, y) )
|
||||
{
|
||||
expander = true;
|
||||
node->ToggleOpen();
|
||||
m_count = -1; //make the current row number fail
|
||||
|
||||
Refresh();
|
||||
//int last_row = GetLastVisibleRow();
|
||||
//RefreshRows( current, last_row );
|
||||
}
|
||||
}
|
||||
Refresh();
|
||||
//int last_row = GetLastVisibleRow();
|
||||
//RefreshRows( current, last_row );
|
||||
}
|
||||
}
|
||||
|
||||
//If the user click the expander, we do not do editing even if the column with expander are editable
|
||||
if (m_lastOnSame && !expander )
|
||||
|
Reference in New Issue
Block a user