From a4cdbdb779a4cc665b7c6cc0697d64762a2c0e54 Mon Sep 17 00:00:00 2001 From: Dimitri Schoolwerth Date: Mon, 26 Jul 2021 19:29:49 +0200 Subject: [PATCH] Fix disappearing wxDVC cell items if cell background is set With both GTK 2 and 3 if a wxDVC cell has a background colour attribute set then wxDataViewCustomRenderer::RenderText() sets the cell's background property. With wxDataViewCheckIconText this results in items drawn prior to the text to be painted over. Reproducible using the dataview sample which on the MyListModel page uses a background cell colour for the first column of odd-indexed rows. Fix by drawing the text first, followed by the checkbox and possible icon as before. There appear to be no other custom renderers in wx which draw multiple items and may have needed fixing as well. This commit is best viewed with git --color-moved option. Closes https://github.com/wxWidgets/wxWidgets/pull/2449 --- src/common/datavcmn.cpp | 56 +++++++++++++++++++++++------------------ 1 file changed, 32 insertions(+), 24 deletions(-) diff --git a/src/common/datavcmn.cpp b/src/common/datavcmn.cpp index 07d4ea214a..2c6fbe11d1 100644 --- a/src/common/datavcmn.cpp +++ b/src/common/datavcmn.cpp @@ -2108,7 +2108,36 @@ wxSize wxDataViewCheckIconTextRenderer::GetSize() const bool wxDataViewCheckIconTextRenderer::Render(wxRect cell, wxDC* dc, int state) { - // Draw the checkbox first. + /* + Draw the text first because if the item has a background colour set + then with wxGTK the entire cell is painted over during RenderText() + when attributes are applied. + */ + + const wxSize sizeCheck = GetCheckSize(); + + int xoffset = sizeCheck.x + MARGIN_CHECK_ICON; + + wxRect rectIcon; + const wxIcon& icon = m_value.GetIcon(); + const bool drawIcon = icon.IsOk(); + if ( drawIcon ) + { +#ifdef __WXGTK3__ + const wxSize sizeIcon = icon.GetScaledSize(); +#else + const wxSize sizeIcon = icon.GetSize(); +#endif + rectIcon = wxRect(cell.GetPosition(), sizeIcon); + rectIcon.x += xoffset; + rectIcon = rectIcon.CentreIn(cell, wxVERTICAL); + + xoffset += sizeIcon.x + MARGIN_ICON_TEXT; + } + + RenderText(m_value.GetText(), xoffset, cell, dc, state); + + // Then draw the checkbox. int renderFlags = 0; switch ( m_value.GetCheckedState() ) { @@ -2127,8 +2156,6 @@ bool wxDataViewCheckIconTextRenderer::Render(wxRect cell, wxDC* dc, int state) if ( state & wxDATAVIEW_CELL_PRELIT ) renderFlags |= wxCONTROL_CURRENT; - const wxSize sizeCheck = GetCheckSize(); - wxRect rectCheck(cell.GetPosition(), sizeCheck); rectCheck = rectCheck.CentreIn(cell, wxVERTICAL); @@ -2137,29 +2164,10 @@ bool wxDataViewCheckIconTextRenderer::Render(wxRect cell, wxDC* dc, int state) GetView(), *dc, rectCheck, renderFlags ); - // Then the icon, if any. - int xoffset = sizeCheck.x + MARGIN_CHECK_ICON; - - const wxIcon& icon = m_value.GetIcon(); - if ( icon.IsOk() ) - { -#ifdef __WXGTK3__ - const wxSize sizeIcon = icon.GetScaledSize(); -#else - const wxSize sizeIcon = icon.GetSize(); -#endif - wxRect rectIcon(cell.GetPosition(), sizeIcon); - rectIcon.x += xoffset; - rectIcon = rectIcon.CentreIn(cell, wxVERTICAL); - + // Finally draw the icon, if any. + if ( drawIcon ) dc->DrawIcon(icon, rectIcon.GetPosition()); - xoffset += sizeIcon.x + MARGIN_ICON_TEXT; - } - - // Finally the text. - RenderText(m_value.GetText(), xoffset, cell, dc, state); - return true; }