From 2ec335db7806c058a02d022d2f75b4144ce69d2a Mon Sep 17 00:00:00 2001 From: Jaakko Salli Date: Mon, 21 Dec 2009 15:20:37 +0000 Subject: [PATCH] Added wxMSW wxChoice::GetClassDefaultAttributes(), initially used in wxComboCtrl git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62960 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/choice.h | 8 ++++++++ include/wx/msw/combo.h | 1 - src/common/combocmn.cpp | 20 +++++++++++++++++--- src/msw/choice.cpp | 32 ++++++++++++++++++++++++++++++++ src/msw/combo.cpp | 25 ------------------------- 5 files changed, 57 insertions(+), 29 deletions(-) diff --git a/include/wx/msw/choice.h b/include/wx/msw/choice.h index 5ddb312b11..c5cf8125be 100644 --- a/include/wx/msw/choice.h +++ b/include/wx/msw/choice.h @@ -77,6 +77,14 @@ public: virtual wxString GetString(unsigned int n) const; virtual void SetString(unsigned int n, const wxString& s); + virtual wxVisualAttributes GetDefaultAttributes() const + { + return GetClassDefaultAttributes(GetWindowVariant()); + } + + static wxVisualAttributes + GetClassDefaultAttributes(wxWindowVariant variant = wxWINDOW_VARIANT_NORMAL); + // MSW only virtual bool MSWCommand(WXUINT param, WXWORD id); WXLRESULT MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam); diff --git a/include/wx/msw/combo.h b/include/wx/msw/combo.h index 78ef4f59ef..be85dbcf41 100644 --- a/include/wx/msw/combo.h +++ b/include/wx/msw/combo.h @@ -86,7 +86,6 @@ protected: // customization virtual void OnResize(); virtual wxCoord GetNativeTextIndent() const; - virtual void OnThemeChange(); // event handlers void OnPaintEvent( wxPaintEvent& event ); diff --git a/src/common/combocmn.cpp b/src/common/combocmn.cpp index fe54d24019..71b6075086 100644 --- a/src/common/combocmn.cpp +++ b/src/common/combocmn.cpp @@ -913,13 +913,27 @@ 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__ + #if defined(__WXMSW__) || defined(__WXGTK__) + wxVisualAttributes vattrs = wxComboBox::GetClassDefaultAttributes(); + #else + wxVisualAttributes vattrs; + vattrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); + vattrs.colBg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); + #endif + + // Only change the colours if application has not specified + // custom ones. + if ( !m_hasFgCol ) + { + SetOwnForegroundColour(vattrs.colFg); + m_hasFgCol = false; + } if ( !m_hasBgCol ) { - wxColour bgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW); - SetOwnBackgroundColour(bgCol); + SetOwnBackgroundColour(vattrs.colBg); m_hasBgCol = false; } -#endif +#endif // !__WXMAC__ } wxComboCtrlBase::~wxComboCtrlBase() diff --git a/src/msw/choice.cpp b/src/msw/choice.cpp index b6cdd7b9c9..85eb015339 100644 --- a/src/msw/choice.cpp +++ b/src/msw/choice.cpp @@ -30,6 +30,7 @@ #ifndef WX_PRECOMP #include "wx/utils.h" + #include "wx/app.h" #include "wx/log.h" #include "wx/brush.h" #include "wx/settings.h" @@ -220,6 +221,37 @@ WXDWORD wxChoice::MSWGetStyle(long style, WXDWORD *exstyle) const return msStyle; } +#ifndef EP_EDITTEXT + #define EP_EDITTEXT 1 + #define ETS_NORMAL 1 +#endif + +wxVisualAttributes +wxChoice::GetClassDefaultAttributes(wxWindowVariant WXUNUSED(variant)) +{ + // it is important to return valid values for all attributes from here, + // GetXXX() below rely on this + wxVisualAttributes attrs; + + // FIXME: Use better dummy window? + wxWindow* wnd = wxTheApp->GetTopWindow(); + + attrs.font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); + + // 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 + attrs.colFg = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); + + // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista) + attrs.colBg = wnd->MSWGetThemeColour(L"EDIT", + EP_EDITTEXT, + ETS_NORMAL, + ThemeColourBackground, + wxSYS_COLOUR_WINDOW); + + return attrs; +} + wxChoice::~wxChoice() { Clear(); diff --git a/src/msw/combo.cpp b/src/msw/combo.cpp index 733e068430..3cbae3b335 100644 --- a/src/msw/combo.cpp +++ b/src/msw/combo.cpp @@ -221,31 +221,6 @@ wxComboCtrl::~wxComboCtrl() { } -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 - if ( !m_hasFgCol ) - { - wxColour fgCol = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); - SetForegroundColour(fgCol); - m_hasFgCol = false; - } - - // NB: use EDIT, not COMBOBOX (the latter works in XP but not Vista) - wxColour bgCol = MSWGetThemeColour(L"EDIT", - EP_EDITTEXT, - ETS_NORMAL, - ThemeColourBackground, - wxSYS_COLOUR_WINDOW); - - if ( !m_hasBgCol ) - { - SetBackgroundColour(bgCol); - m_hasBgCol = false; - } -} - void wxComboCtrl::OnResize() { // -- 2.45.2