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
This commit is contained in:
Jaakko Salli 2009-12-21 15:20:37 +00:00
parent 163bd4f700
commit 2ec335db78
5 changed files with 57 additions and 29 deletions

View File

@ -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);

View File

@ -86,7 +86,6 @@ protected:
// customization
virtual void OnResize();
virtual wxCoord GetNativeTextIndent() const;
virtual void OnThemeChange();
// event handlers
void OnPaintEvent( wxPaintEvent& event );

View File

@ -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()

View File

@ -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();

View File

@ -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()
{
//