From 55420130b5157c14b466be0d5e62c67401853251 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 1 Dec 2021 01:32:22 +0000 Subject: [PATCH] Don't use items without values in generic wxDVC In particular, don't draw them, as this would reuse the value of the previously drawn item, which would be wrong -- just leave them blank if PrepareForItem() returned false, which happens if GetValue() returned a null value or a value of a wrong type. --- src/generic/datavgen.cpp | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/src/generic/datavgen.cpp b/src/generic/datavgen.cpp index 43c9facee3..2712368c6f 100644 --- a/src/generic/datavgen.cpp +++ b/src/generic/datavgen.cpp @@ -2463,14 +2463,15 @@ wxBitmap wxDataViewMainWindow::CreateItemBitmap( unsigned int row, int &indent ) width -= indent; wxDataViewItem item = GetItemByRow( row ); - cell->PrepareForItem(model, item, column->GetModelColumn()); + if ( cell->PrepareForItem(model, item, column->GetModelColumn()) ) + { + wxRect item_rect(x, 0, width, height); + item_rect.Deflate(PADDING_RIGHTLEFT, 0); - wxRect item_rect(x, 0, width, height); - item_rect.Deflate(PADDING_RIGHTLEFT, 0); - - // dc.SetClippingRegion( item_rect ); - cell->WXCallRender(item_rect, &dc, 0); - // dc.DestroyClippingRegion(); + // dc.SetClippingRegion( item_rect ); + cell->WXCallRender(item_rect, &dc, 0); + // dc.DestroyClippingRegion(); + } x += width; } @@ -2836,7 +2837,7 @@ void wxDataViewMainWindow::OnPaint( wxPaintEvent &WXUNUSED(event) ) cell->SetState(state); if (hasValue) - cell->PrepareForItem(model, dataitem, col->GetModelColumn()); + hasValue = cell->PrepareForItem(model, dataitem, col->GetModelColumn()); // draw the background if ( !selected ) @@ -3789,9 +3790,8 @@ int wxDataViewMainWindow::QueryAndCacheLineHeight(unsigned int row, wxDataViewIt wxDataViewRenderer *renderer = const_cast(column->GetRenderer()); - renderer->PrepareForItem(model, item, column->GetModelColumn()); - - height = wxMax(height, renderer->GetSize().y); + if ( renderer->PrepareForItem(model, item, column->GetModelColumn()) ) + height = wxMax(height, renderer->GetSize().y); } // ... and store the height in the cache @@ -5998,8 +5998,8 @@ public: if ( m_model->HasValue(item, GetColumn()) ) { - m_renderer->PrepareForItem(m_model, item, GetColumn()); - width += m_renderer->GetSize().x; + if ( m_renderer->PrepareForItem(m_model, item, GetColumn()) ) + width += m_renderer->GetSize().x; } UpdateWithWidth(width); @@ -6747,7 +6747,9 @@ wxAccStatus wxDataViewCtrlAccessible::GetName(int childId, wxString* name) continue; // Skip non-textual items wxDataViewRenderer* r = dvCol->GetRenderer(); - r->PrepareForItem(model, item, dvCol->GetModelColumn()); + if ( !r->PrepareForItem(model, item, dvCol->GetModelColumn()) ) + continue; + wxString vs = r->GetAccessibleDescription(); if ( !vs.empty() ) { @@ -6905,7 +6907,9 @@ wxAccStatus wxDataViewCtrlAccessible::GetDescription(int childId, wxString* desc model->GetValue(value, item, dvCol->GetModelColumn()); wxDataViewRenderer* r = dvCol->GetRenderer(); - r->PrepareForItem(model, item, dvCol->GetModelColumn()); + if ( !r->PrepareForItem(model, item, dvCol->GetModelColumn()) ) + continue; + wxString valStr = r->GetAccessibleDescription(); // Skip first textual item if ( !firstTextSkipped && !value.IsNull() && !value.IsType(wxS("bool")) && !valStr.empty() )