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:
@@ -299,7 +299,7 @@ int wxDataViewModel::Compare( const wxDataViewItem &item1, const wxDataViewItem
|
|||||||
|
|
||||||
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
wxDataViewIndexListModel::wxDataViewIndexListModel( unsigned int initial_size )
|
||||||
{
|
{
|
||||||
#ifdef __WXGTK__
|
#ifndef __WXMAC__
|
||||||
m_useHash = false;
|
m_useHash = false;
|
||||||
#else
|
#else
|
||||||
m_useHash = true;
|
m_useHash = true;
|
||||||
|
@@ -425,8 +425,11 @@ public:
|
|||||||
bool Cleared();
|
bool Cleared();
|
||||||
void Resort()
|
void Resort()
|
||||||
{
|
{
|
||||||
SortPrepare();
|
if (m_root)
|
||||||
m_root->Resort();
|
{
|
||||||
|
SortPrepare();
|
||||||
|
m_root->Resort();
|
||||||
|
}
|
||||||
UpdateDisplay();
|
UpdateDisplay();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2408,14 +2411,24 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
{
|
{
|
||||||
// get the cell value and set it into the renderer
|
// get the cell value and set it into the renderer
|
||||||
wxVariant value;
|
wxVariant value;
|
||||||
wxDataViewTreeNode * node = GetTreeNodeByRow(item);
|
wxDataViewTreeNode *node = NULL;
|
||||||
if( node == NULL )
|
wxDataViewItem dataitem;
|
||||||
continue;
|
|
||||||
|
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))
|
if ((i > 0) && model->IsContainer(dataitem) && !model->HasContainerColumns(dataitem))
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dataitem = wxDataViewItem( (void*) item );
|
||||||
|
}
|
||||||
|
|
||||||
model->GetValue( value, dataitem, col->GetModelColumn());
|
model->GetValue( value, dataitem, col->GetModelColumn());
|
||||||
cell->SetValue( value );
|
cell->SetValue( value );
|
||||||
@@ -2433,9 +2446,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
cell_rect.y = item * m_lineHeight;
|
cell_rect.y = item * m_lineHeight;
|
||||||
|
|
||||||
//Draw the expander here.
|
//Draw the expander here.
|
||||||
int indent = node->GetIndentLevel();
|
int indent = 0;
|
||||||
if( col == expander )
|
if ((m_root) && (col == expander))
|
||||||
{
|
{
|
||||||
|
indent = node->GetIndentLevel();
|
||||||
|
|
||||||
//Calculate the indent first
|
//Calculate the indent first
|
||||||
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
|
indent = cell_rect.x + GetOwner()->GetIndent() * indent;
|
||||||
|
|
||||||
@@ -2460,9 +2475,11 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) )
|
|||||||
}
|
}
|
||||||
else
|
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
|
||||||
delete node;
|
if (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
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
//force the expander column to left-center align
|
//force the expander column to left-center align
|
||||||
@@ -2859,9 +2876,16 @@ private:
|
|||||||
|
|
||||||
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
|
wxDataViewItem wxDataViewMainWindow::GetItemByRow(unsigned int row) const
|
||||||
{
|
{
|
||||||
RowToItemJob job( row, -2 );
|
if (!m_root)
|
||||||
Walker( m_root , job );
|
{
|
||||||
return job.GetResult();
|
return wxDataViewItem( (void*) row );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RowToItemJob job( row, -2 );
|
||||||
|
Walker( m_root , job );
|
||||||
|
return job.GetResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class RowToTreeNodeJob: public DoJob
|
class RowToTreeNodeJob: public DoJob
|
||||||
@@ -2934,9 +2958,16 @@ private:
|
|||||||
|
|
||||||
wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row)
|
wxDataViewTreeNode * wxDataViewMainWindow::GetTreeNodeByRow(unsigned int row)
|
||||||
{
|
{
|
||||||
RowToTreeNodeJob job( row , -2, m_root );
|
if (!m_root)
|
||||||
Walker( m_root , job );
|
{
|
||||||
return job.GetResult();
|
return NULL;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
RowToTreeNodeJob job( row , -2, m_root );
|
||||||
|
Walker( m_root , job );
|
||||||
|
return job.GetResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
|
wxDataViewEvent wxDataViewMainWindow::SendExpanderEvent( wxEventType type, const wxDataViewItem & item )
|
||||||
@@ -3123,7 +3154,15 @@ wxRect wxDataViewMainWindow::GetItemRect( const wxDataViewItem & item, const wxD
|
|||||||
|
|
||||||
int wxDataViewMainWindow::RecalculateCount()
|
int wxDataViewMainWindow::RecalculateCount()
|
||||||
{
|
{
|
||||||
return m_root->GetSubTreeCount();
|
if (!m_root)
|
||||||
|
{
|
||||||
|
wxDataViewIndexListModel *list_model = (wxDataViewIndexListModel*) GetOwner()->GetModel();
|
||||||
|
return list_model->GetLastIndex();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return m_root->GetSubTreeCount();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class ItemToRowJob : public DoJob
|
class ItemToRowJob : public DoJob
|
||||||
@@ -3177,26 +3216,33 @@ int wxDataViewMainWindow::GetRowByItem(const wxDataViewItem & item)
|
|||||||
if( model == NULL )
|
if( model == NULL )
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if( !item.IsOk() )
|
if (!m_root)
|
||||||
return -1;
|
|
||||||
|
|
||||||
//Compose the a parent-chain of the finding item
|
|
||||||
ItemList list;
|
|
||||||
wxDataViewItem * pItem = NULL;
|
|
||||||
list.DeleteContents( true );
|
|
||||||
wxDataViewItem it( item );
|
|
||||||
while( it.IsOk() )
|
|
||||||
{
|
{
|
||||||
pItem = new wxDataViewItem( it );
|
return wxPtrToUInt( item.GetID() );
|
||||||
list.Insert( pItem );
|
|
||||||
it = model->GetParent( it );
|
|
||||||
}
|
}
|
||||||
pItem = new wxDataViewItem( );
|
else
|
||||||
list.Insert( pItem );
|
{
|
||||||
|
if( !item.IsOk() )
|
||||||
|
return -1;
|
||||||
|
|
||||||
ItemToRowJob job( item, list.begin() );
|
//Compose the a parent-chain of the finding item
|
||||||
Walker(m_root , job );
|
ItemList list;
|
||||||
return job.GetResult();
|
wxDataViewItem * pItem = NULL;
|
||||||
|
list.DeleteContents( true );
|
||||||
|
wxDataViewItem it( item );
|
||||||
|
while( it.IsOk() )
|
||||||
|
{
|
||||||
|
pItem = new wxDataViewItem( it );
|
||||||
|
list.Insert( pItem );
|
||||||
|
it = model->GetParent( it );
|
||||||
|
}
|
||||||
|
pItem = new wxDataViewItem( );
|
||||||
|
list.Insert( pItem );
|
||||||
|
|
||||||
|
ItemToRowJob job( item, list.begin() );
|
||||||
|
Walker(m_root , job );
|
||||||
|
return job.GetResult();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
|
void BuildTreeHelper( wxDataViewModel * model, wxDataViewItem & item, wxDataViewTreeNode * node)
|
||||||
@@ -3233,6 +3279,12 @@ void wxDataViewMainWindow::BuildTree(wxDataViewModel * model)
|
|||||||
{
|
{
|
||||||
DestroyTree();
|
DestroyTree();
|
||||||
|
|
||||||
|
if (GetOwner()->GetModel()->IsIndexListModel())
|
||||||
|
{
|
||||||
|
m_count = -1 ;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
m_root = new wxDataViewTreeNode( NULL );
|
m_root = new wxDataViewTreeNode( NULL );
|
||||||
m_root->SetHasChildren(true);
|
m_root->SetHasChildren(true);
|
||||||
|
|
||||||
@@ -3405,7 +3457,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
|
|
||||||
//Test whether the mouse is hovered on the tree item button
|
//Test whether the mouse is hovered on the tree item button
|
||||||
bool hover = false;
|
bool hover = false;
|
||||||
if (GetOwner()->GetExpanderColumn() == col)
|
if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
|
||||||
{
|
{
|
||||||
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
||||||
if( node!=NULL && node->HasChildren() )
|
if( node!=NULL && node->HasChildren() )
|
||||||
@@ -3530,7 +3582,7 @@ void wxDataViewMainWindow::OnMouse( wxMouseEvent &event )
|
|||||||
|
|
||||||
//Process the event of user clicking the expander
|
//Process the event of user clicking the expander
|
||||||
bool expander = false;
|
bool expander = false;
|
||||||
if (GetOwner()->GetExpanderColumn() == col)
|
if ((m_root) && (GetOwner()->GetExpanderColumn() == col))
|
||||||
{
|
{
|
||||||
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
wxDataViewTreeNode * node = GetTreeNodeByRow(current);
|
||||||
if( node!=NULL && node->HasChildren() )
|
if( node!=NULL && node->HasChildren() )
|
||||||
|
Reference in New Issue
Block a user