Fix text colour for items drawn using wxRenderer::DrawItemText()
After the addition and usage of DrawItemText() in
b7a89f8746
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.
This commit is contained in:
committed by
Vadim Zeitlin
parent
44bcc3a723
commit
76a75ddc6a
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user