Have wxComboCtrl honour any custom foreground and background colour.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Jaakko Salli
2009-12-18 17:28:42 +00:00
parent d5892339a1
commit 3b9ba64cce
2 changed files with 64 additions and 18 deletions

View File

@@ -913,7 +913,12 @@ void wxComboCtrlBase::OnThemeChange()
// be the correct colour and themed brush. Instead we'll use // be the correct colour and themed brush. Instead we'll use
// wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed. // wxSYS_COLOUR_WINDOW in the EVT_PAINT handler as needed.
#ifndef __WXMAC__ #ifndef __WXMAC__
SetOwnBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); if ( !m_hasBgCol )
{
wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW);
SetOwnBackgroundColour(bgCol);
m_hasBgCol = false;
}
#endif #endif
} }
@@ -1353,20 +1358,46 @@ void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags
selRect.width -= wcp + (focusSpacingX*2); selRect.width -= wcp + (focusSpacingX*2);
wxColour bgCol; wxColour bgCol;
wxColour fgCol;
bool doDrawSelRect = true; bool doDrawSelRect = true;
// Determine foreground colour
if ( isEnabled ) if ( isEnabled )
{ {
// If popup is hidden and this control is focused,
// then draw the focus-indicator (selbgcolor background etc.).
if ( doDrawFocusRect ) if ( doDrawFocusRect )
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); }
else if ( m_hasFgCol )
{
// Honour the custom foreground colour
fgCol = GetForegroundColour();
}
else
{
fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT);
}
}
else
{
fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
}
// Determine background colour
if ( isEnabled )
{
if ( doDrawFocusRect )
{
bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
}
else if ( m_hasBgCol )
{
// Honour the custom background colour
bgCol = GetBackgroundColour();
} }
else else
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) );
#ifndef __WXMAC__ // see note in OnThemeChange #ifndef __WXMAC__ // see note in OnThemeChange
doDrawSelRect = false; doDrawSelRect = false;
bgCol = GetBackgroundColour(); bgCol = GetBackgroundColour();
@@ -1377,7 +1408,6 @@ void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags
} }
else else
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) );
#ifndef __WXMAC__ // see note in OnThemeChange #ifndef __WXMAC__ // see note in OnThemeChange
bgCol = GetBackgroundColour(); bgCol = GetBackgroundColour();
#else #else
@@ -1385,6 +1415,7 @@ void wxComboCtrlBase::PrepareBackground( wxDC& dc, const wxRect& rect, int flags
#endif #endif
} }
dc.SetTextForeground( fgCol );
dc.SetBrush( bgCol ); dc.SetBrush( bgCol );
if ( doDrawSelRect ) if ( doDrawSelRect )
{ {

View File

@@ -225,7 +225,14 @@ void wxComboCtrl::OnThemeChange()
{ {
// there doesn't seem to be any way to get the text colour using themes // 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 // 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 #if wxUSE_UXTHEME
wxUxThemeEngine * const theme = wxUxThemeEngine::GetIfActive(); wxUxThemeEngine * const theme = wxUxThemeEngine::GetIfActive();
@@ -244,17 +251,21 @@ void wxComboCtrl::OnThemeChange()
); );
if ( SUCCEEDED(hr) ) if ( SUCCEEDED(hr) )
{ {
SetBackgroundColour(wxRGBToColour(col)); bgCol = wxRGBToColour(col);
}
// skip the call below else
return; {
wxLogApiError("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)",
hr);
} }
wxLogApiError(wxT("GetThemeColor(EDIT, ETS_NORMAL, TMT_FILLCOLOR)"), hr);
} }
#endif #endif
SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW)); if ( !m_hasBgCol )
{
SetBackgroundColour(bgCol);
m_hasBgCol = false;
}
} }
void wxComboCtrl::OnResize() void wxComboCtrl::OnResize()
@@ -397,6 +408,7 @@ wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
//if ( hTheme ) //if ( hTheme )
// theme = wxUxThemeEngine::GetIfActive(); // theme = wxUxThemeEngine::GetIfActive();
wxColour fgCol;
wxColour bgCol; wxColour bgCol;
bool doDrawDottedEdge = false; bool doDrawDottedEdge = false;
bool doDrawSelRect = true; bool doDrawSelRect = true;
@@ -422,28 +434,31 @@ wxComboCtrl::PrepareBackground( wxDC& dc, const wxRect& rect, int flags ) const
if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) ) if ( (m_iFlags & wxCC_FULL_BUTTON) && !(flags & wxCONTROL_ISSUBMENU) )
{ {
// Vista style read-only combo // Vista style read-only combo
fgCol = GetForegroundColour();
bgCol = GetBackgroundColour();
doDrawSelRect = false; doDrawSelRect = false;
doDrawDottedEdge = true; doDrawDottedEdge = true;
} }
else else
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT) ); fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT);
bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT);
} }
} }
else else
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT) ); fgCol = GetForegroundColour();
bgCol = GetBackgroundColour(); bgCol = GetBackgroundColour();
doDrawSelRect = false; doDrawSelRect = false;
} }
} }
else else
{ {
dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT) ); fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT);
bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE); bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE);
} }
dc.SetTextForeground(fgCol);
dc.SetBrush(bgCol); dc.SetBrush(bgCol);
if ( doDrawSelRect ) if ( doDrawSelRect )
{ {