Add short-cut for wxDataViewListIndexModel for generic code

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@50084 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robert Roebling
2007-11-19 14:21:08 +00:00
parent 51bdecff6f
commit a3cc79d902
2 changed files with 92 additions and 40 deletions

View File

@@ -299,7 +299,7 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
{
#ifdef __WXGTK__
#ifndef __WXMAC__
m_useHash = false;
#else
m_useHash = true;

View File

@@ -424,9 +424,12 @@ public:
bool ValueChanged( const wxDataViewItem &item, unsigned int col );
bool Cleared();
void Resort()
{
if (m_root)
{
SortPrepare();
m_root->Resort();
}
UpdateDisplay();
}
@@ -2408,14 +2411,24 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
{
// get the cell value and set it into the renderer
wxVariant value;
wxDataViewTreeNode * node = GetTreeNodeByRow(item);
wxDataViewTreeNode *node = NULL;
wxDataViewItem dataitem;
if (m_root)
{
node = GetTreeNodeByRow(item);
if( node == NULL )
continue;
wxDataViewItem dataitem = node->GetItem();
dataitem = node->GetItem();
if ((i > 0) && model->IsContainer(dataitem) && !model->HasContainerColumns(dataitem))
continue;
}
else
{
dataitem = wxDataViewItem( (void*) item );
}
model->GetValue( value, dataitem, col->GetModelColumn());
cell->SetValue( value );
@@ -2433,9 +2446,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
cell_rect.y = item * m_lineHeight;
//Draw the expander here.
int indent = node->GetIndentLevel();
if( col == expander )
int indent = 0;
if ((m_root) && (col == expander))
{
indent = node->GetIndentLevel();
//Calculate the indent first
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
@@ -2460,9 +2475,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
}
else
{
// I am wandering whether we should draw dot lines between tree nodes
// I am wondering whether we should draw dot lines between tree nodes
if (node)
delete node;
//Yes, if the node does not have any child, it must be a leaf which mean that it is a temporarily created by GetTreeNodeByRow
// Yes, if the node does not have any child, it must be a leaf which
// mean that it is a temporarily created by GetTreeNodeByRow
}
//force the expander column to left-center align
@@ -2858,11 +2875,18 @@ private:
};
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
{
if (!m_root)
{
return wxDataViewItem( (void*) row );
}
else
{
RowToItemJob job( row, -2 );
Walker( m_root , job );
return job.GetResult();
}
}
class RowToTreeNodeJob: public DoJob
{
@@ -2933,11 +2957,18 @@ private:
wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row)
{
if (!m_root)
{
return NULL;
}
else
{
RowToTreeNodeJob job( row , -2, m_root );
Walker( m_root , job );
return job.GetResult();
}
}
wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
{
@@ -3122,9 +3153,17 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxD
}
int wxDataViewMainWindow::RecalculateCount()
{
if (!m_root)
{
wxDataViewIndexListModel *list_model = (wxDataViewIndexListModel*) GetOwner()->GetModel();
return list_model->GetLastIndex();
}
else
{
return m_root->GetSubTreeCount();
}
}
class ItemToRowJob : public DoJob
{
@@ -3177,6 +3216,12 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
if( model == NULL )
return -1;
if (!m_root)
{
return wxPtrToUInt( item.GetID() );
}
else
{
if( !item.IsOk() )
return -1;
@@ -3198,6 +3243,7 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
Walker(m_root , job );
return job.GetResult();
}
}
void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
{
@@ -3233,6 +3279,12 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
{
DestroyTree();
if (GetOwner()->GetModel()->IsIndexListModel())
{
m_count = -1 ;
return;
}
m_root = new wxDataViewTreeNode( NULL );
m_root->SetHasChildren(true);
@@ -3405,7 +3457,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
//Test whether the mouse is hovered on the tree item button
bool hover = false;
if (GetOwner()->GetExpanderColumn() == col)
if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
if( node!=NULL && node->HasChildren() )
@@ -3530,7 +3582,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
//Process the event of user clicking the expander
bool expander = false;
if (GetOwner()->GetExpanderColumn() == col)
if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
{
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
if( node!=NULL && node->HasChildren() )