From 76a75ddc6a0cf4bb5f78c25ea17ac02373ff362f Mon Sep 17 00:00:00 2001 From: Tobias Taschner Date: Fri, 25 Sep 2015 21:30:01 +0200 Subject: [PATCH] Fix text colour for items drawn using wxRenderer::DrawItemText() After the addition and usage of DrawItemText() in b7a89f8746b8861712b4e066aaeca4f93083afea custom colors in wxDataViewCtrl where ignored, restore the correct behavior (custom color for unselected items) by avoiding changing the colour for the normal items in this function. Closes #17164. --- src/generic/renderg.cpp | 12 +++++------- src/msw/renderer.cpp | 37 +++++++++++++++++++++++-------------- 2 files changed, 28 insertions(+), 21 deletions(-) diff --git a/src/generic/renderg.cpp b/src/generic/renderg.cpp index b078566e17..9cc9eebc32 100644 --- a/src/generic/renderg.cpp +++ b/src/generic/renderg.cpp @@ -884,7 +884,7 @@ void wxRendererGeneric::DrawGauge(wxWindow* win, } void -wxRendererGeneric::DrawItemText(wxWindow* win, +wxRendererGeneric::DrawItemText(wxWindow* WXUNUSED(win), wxDC& dc, const wxString& text, const wxRect& rect, @@ -909,17 +909,15 @@ wxRendererGeneric::DrawItemText(wxWindow* win, { textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); } - else // enabled but not selected - { - textColour = win->GetForegroundColour(); - } const wxString paintText = wxControl::Ellipsize(text, dc, ellipsizeMode, rect.GetWidth()); - // Draw text - dc.SetTextForeground(textColour); + // Draw text taking care not to change its colour if it had been set by the + // caller for a normal item to allow having items in non-default colours. + if ( textColour.IsOk() ) + dc.SetTextForeground(textColour); dc.SetTextBackground(wxTransparentColour); dc.DrawLabel(paintText, rect, align); } diff --git a/src/msw/renderer.cpp b/src/msw/renderer.cpp index b297a7c8e1..f0a81a82e4 100644 --- a/src/msw/renderer.cpp +++ b/src/msw/renderer.cpp @@ -617,6 +617,27 @@ int wxRendererMSW::GetHeaderButtonMargin(wxWindow *WXUNUSED(win)) #if wxUSE_UXTHEME +namespace +{ + +int GetListItemState(int flags) +{ + int itemState = (flags & wxCONTROL_CURRENT) ? LISS_HOT : LISS_NORMAL; + if ( flags & wxCONTROL_SELECTED ) + { + itemState = (flags & wxCONTROL_CURRENT) ? LISS_HOTSELECTED : LISS_SELECTED; + if ( !(flags & wxCONTROL_FOCUSED) ) + itemState = LISS_SELECTEDNOTFOCUS; + } + + if ( flags & wxCONTROL_DISABLED ) + itemState = LISS_DISABLED; + + return itemState; +} + +} // anonymous namespace + /* static */ wxRendererNative& wxRendererXP::Get() { @@ -943,13 +964,7 @@ wxRendererXP::DrawItemSelectionRect(wxWindow *win, { wxUxThemeHandle hTheme(win, L"LISTVIEW"); - int itemState = LISS_NORMAL; - if ( flags & wxCONTROL_SELECTED ) - itemState = LISS_SELECTED; - if ( !(flags & wxCONTROL_FOCUSED) ) - itemState = LISS_SELECTEDNOTFOCUS; - if ( flags & wxCONTROL_DISABLED ) - itemState |= LISS_DISABLED; + const int itemState = GetListItemState(flags); wxUxThemeEngine* const te = wxUxThemeEngine::Get(); if ( te->IsThemePartDefined(hTheme, LVP_LISTITEM, itemState) ) @@ -977,13 +992,7 @@ void wxRendererXP::DrawItemText(wxWindow* win, { wxUxThemeHandle hTheme(win, L"LISTVIEW"); - int itemState = LISS_NORMAL; - if ( flags & wxCONTROL_SELECTED ) - itemState = LISS_SELECTED; - if ( !(flags & wxCONTROL_FOCUSED) ) - itemState = LISS_SELECTEDNOTFOCUS; - if ( flags & wxCONTROL_DISABLED ) - itemState |= LISS_DISABLED; + const int itemState = GetListItemState(flags); wxUxThemeEngine* te = wxUxThemeEngine::Get(); if ( te->DrawThemeTextEx && // Might be not available if we're under XP