fixed handling of NULL items

This commit is contained in:
jensgoe 2018-12-10 00:14:15 +01:00 committed by Jens Göpfert
parent 9a91f59399
commit 1f0e32e485

View File

@ -710,6 +710,7 @@ public:
bool Cleared();
void Resort()
{
m_rowHeightCache->Clear();
if (!IsVirtualList())
{
m_root->Resort(this);
@ -822,6 +823,7 @@ public:
int GetLineStart( unsigned int row ) const; // row * m_lineHeight in fixed mode
int GetLineHeight( unsigned int row ) const; // m_lineHeight in fixed mode
int GetLineAt( unsigned int y ) const; // y / m_lineHeight in fixed mode
int QueryAndCacheLineHeight(unsigned int row, wxDataViewItem item) const;
void SetRowHeight( int lineHeight ) { m_lineHeight = lineHeight; }
int GetRowHeight() const { return m_lineHeight; }
@ -3344,8 +3346,6 @@ wxRect wxDataViewMainWindow::GetLinesRect( unsigned int rowFrom, unsigned int ro
int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
{
const wxDataViewModel *model = GetModel();
if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{
int start = 0;
@ -3362,42 +3362,13 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
continue;
}
wxDataViewItem item;
if (IsList())
{
item = GetItemByRow(r);
}
else
{
const wxDataViewTreeNode* node = GetTreeNodeByRow(r);
if (!node) return start;
item = node->GetItem();
}
wxDataViewItem item = GetItemByRow(r);
if ( !item )
break;
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int col;
height = m_lineHeight;
for (col = 0; col < cols; col++)
{
const wxDataViewColumn *column = GetOwner()->GetColumn(col);
if (column->IsHidden())
continue; // skip it!
if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it!
wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->PrepareForItem(model, item, column->GetModelColumn());
height = wxMax( height, renderer->GetSize().y );
}
height = QueryAndCacheLineHeight(r, item);
start += height;
m_rowHeightCache->Put(r, height);
}
return start;
@ -3410,8 +3381,6 @@ int wxDataViewMainWindow::GetLineStart( unsigned int row ) const
int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
{
const wxDataViewModel *model = GetModel();
// check for the easy case first
if ( !GetOwner()->HasFlag(wxDV_VARIABLE_LINE_HEIGHT) )
return y / m_lineHeight;
@ -3429,25 +3398,49 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
{
// row height not in cache -> get it from the renderer...
wxDataViewItem item;
if (IsList())
wxDataViewItem item = GetItemByRow(row);
if ( !item )
return row; // should be the last row
height = QueryAndCacheLineHeight(row, item);
}
yy += height;
if (y < yy)
return row;
row++;
}
}
int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
{
item = GetItemByRow(row);
if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{
int height = 0;
if ( m_rowHeightCache->GetLineHeight(row, height) )
return height;
wxDataViewItem item = GetItemByRow(row);
if ( !item )
return m_lineHeight;
height = QueryAndCacheLineHeight(row, item);
return height;
}
else
{
const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
if (!node)
{
// not really correct...
return row + ((y-yy) / m_lineHeight);
return m_lineHeight;
}
item = node->GetItem();
}
int wxDataViewMainWindow::QueryAndCacheLineHeight(unsigned int row, wxDataViewItem item) const
{
const wxDataViewModel *model = GetModel();
int height = m_lineHeight;
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int col;
height = m_lineHeight;
for (col = 0; col < cols; col++)
{
const wxDataViewColumn *column = GetOwner()->GetColumn(col);
@ -3468,69 +3461,9 @@ int wxDataViewMainWindow::GetLineAt( unsigned int y ) const
// ... and store the height in the cache
m_rowHeightCache->Put(row, height);
}
yy += height;
if (y < yy)
return row;
row++;
}
}
int wxDataViewMainWindow::GetLineHeight( unsigned int row ) const
{
const wxDataViewModel *model = GetModel();
if (GetOwner()->GetWindowStyle() & wxDV_VARIABLE_LINE_HEIGHT)
{
int height = 0;
if (m_rowHeightCache->GetLineHeight(row, height))
return height;
wxDataViewItem item;
if (IsList())
{
item = GetItemByRow(row);
}
else
{
const wxDataViewTreeNode* node = GetTreeNodeByRow(row);
// wxASSERT( node );
if (!node) return m_lineHeight;
item = node->GetItem();
}
height = m_lineHeight;
unsigned int cols = GetOwner()->GetColumnCount();
unsigned int col;
for (col = 0; col < cols; col++)
{
const wxDataViewColumn *column = GetOwner()->GetColumn(col);
if (column->IsHidden())
continue; // skip it!
if ((col != 0) &&
model->IsContainer(item) &&
!model->HasContainerColumns(item))
continue; // skip it!
wxDataViewRenderer *renderer =
const_cast<wxDataViewRenderer*>(column->GetRenderer());
renderer->PrepareForItem(model, item, column->GetModelColumn());
height = wxMax( height, renderer->GetSize().y );
}
m_rowHeightCache->Put(row, height);
return height;
}
else
{
return m_lineHeight;
}
}
class RowToTreeNodeJob: public DoJob