From 9beb1afb739b7fa187c0527f5791b129470e8875 Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Fri, 18 Dec 2009 16:42:13 +0000 Subject: [PATCH] Have wxComboCtrl honour any application-specified foreground and background colour. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@62928 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/common/combocmn.cpp | 40 ++++++++++----- src/msw/combo.cpp | 105 ++++++++++++++++++---------------------- 2 files changed, 75 insertions(+), 70 deletions(-) diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index 625f7bea0a..6597dcea7a 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -858,7 +858,12 @@ void wxComboCtrlBase::OnThemeChange() // be the correct colour and themed brush. Instead we'll use // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed. #ifndef __WXMAC__ - SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + if ( !m_hasBgCol ) + { + wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + SetOwnBackgroundColour(bgCol); + m_hasBgCol = false; + } #endif } @@ -1262,30 +1267,40 @@ void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags selRect.x += wcp + focusSpacingX; selRect.width -= wcp + (focusSpacingX*2); + wxColour fgCol; wxColour bgCol; if ( isEnabled ) { - // If popup is hidden and this control is focused, - // then draw the focus-indicator (selbgcolor background etc.). - if ( isFocused ) - { - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); - bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); - } + if ( m_hasFgCol ) + // Honour the custom foreground colour + fgCol = GetForegroundColour(); + else if ( isFocused ) + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); + else + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); + } + else + { + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); + } + + if ( isEnabled ) + { + if ( m_hasBgCol ) + // Honour the custom background colour + bgCol = GetBackgroundColour(); + else if ( isFocused ) + bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); else - { - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); #ifndef __WXMAC__ // see note in OnThemeChange bgCol = GetBackgroundColour(); #else bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); #endif - } } else { - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) ); #ifndef __WXMAC__ // see note in OnThemeChange bgCol = GetBackgroundColour(); #else @@ -1293,6 +1308,7 @@ void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags #endif } + dc.SetTextForeground( fgCol ); dc.SetBrush( bgCol ); dc.SetPen( bgCol ); dc.DrawRectangle( selRect ); diff --git a/src/msw/combo.cpp b/src/msw/combo.cpp index 5702a01bcd..56955031ab 100644 --- a/src/msw/combo.cpp +++ b/src/msw/combo.cpp @@ -170,7 +170,14 @@ void wxComboCtrl::OnThemeChange() { // there doesn't seem to be any way to get the text colour using themes // API: TMT_TEXTCOLOR doesn't work neither for EDIT nor COMBOBOX - SetForegroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT)); + if ( !m_hasFgCol ) + { + wxColour fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); + SetForegroundColour(fgCol); + m_hasFgCol = false; + } + + wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); #if wxUSE_UXTHEME wxUxThemeEngine * const theme = wxUxThemeEngine::GetIfActive(); @@ -189,17 +196,21 @@ void wxComboCtrl::OnThemeChange() ); if ( SUCCEEDED(hr) ) { - SetBackgroundColour(wxRGBToColour(col)); - - // skip the call below - return; + bgCol = wxRGBToColour(col); + } + else + { + wxLogApiError(_T("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)"), + hr); } - - wxLogApiError(_T("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)"), hr); } #endif - SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); + if ( !m_hasBgCol ) + { + SetBackgroundColour(bgCol); + m_hasBgCol = false; + } } void wxComboCtrl::OnResize() @@ -347,65 +358,43 @@ wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const // theme = wxUxThemeEngine::GetIfActive(); wxColour bgCol; + wxColour fgCol; bool drawDottedEdge = false; + if ( isEnabled && isFocused && HasFlag(wxCB_READONLY) ) + drawDottedEdge = true; + if ( isEnabled ) { - // If popup is hidden and this control is focused, - // then draw the focus-indicator (selbgcolor background etc.). - if ( isFocused ) - { - #if 0 - // TODO: Proper theme color getting (JMS: I don't know which parts/colors to use, - // those below don't work) - if ( hTheme ) - { - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_SELECTED,TMT_TEXTCOLOR,&cref); - dc.SetTextForeground( wxRGBToColour(cref) ); - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_SELECTED,TMT_FILLCOLOR,&cref); - bgCol = wxRGBToColour(cref); - } - else - #endif - { - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); - bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); - if ( m_windowStyle & wxCB_READONLY ) - drawDottedEdge = true; - } - } + if ( m_hasFgCol ) + // Honour the custom foreground colour + fgCol = GetForegroundColour(); + else if ( isFocused ) + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT); else - { - /*if ( hTheme ) - { - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_TEXTCOLOR,&cref); - dc.SetTextForeground( wxRGBToColour(cref) ); - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_NORMAL,TMT_FILLCOLOR,&cref); - bgCol = wxRGBToColour(cref); - } - else - {*/ - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); - bgCol = GetBackgroundColour(); - //} - } + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); } else { - /*if ( hTheme ) - { - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_DISABLED,TMT_TEXTCOLOR,&cref); - dc.SetTextForeground( wxRGBToColour(cref) ); - theme->GetThemeColor(hTheme,EP_EDITTEXT,ETS_DISABLED,TMT_EDGEFILLCOLOR,&cref); - bgCol = wxRGBToColour(cref); - } - else - {*/ - dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) ); - bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); - //} + fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT); } + if ( isEnabled ) + { + if ( m_hasBgCol ) + // Honour the custom background colour + bgCol = GetBackgroundColour(); + else if ( isFocused ) + bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); + else + bgCol = GetBackgroundColour(); + } + else + { + bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); + } + + dc.SetTextForeground(fgCol); dc.SetBrush(bgCol); dc.SetPen(bgCol); dc.DrawRectangle(selRect); @@ -725,7 +714,7 @@ bool wxComboCtrl::IsKeyPopupToggle(const wxKeyEvent& event) const ( !isPopupShown && HasFlag(wxCB_READONLY) #if wxUSE_UXTHEME - && + && !wxUxThemeEngine::GetIfActive() #endif ) )