Fix confusion with LOGFONT{A,W} parameters to MSW GetTheme[Sys]Font().

Change the signature of GetThemeFont() and GetThemeSysFont() methods of
wxUxThemeEngine to take an artificial wxUxThemeFont::Ptr type instead of
LOGFONT which allows the broken code to compile correctly and even work in
Unicode builds but crashed in ANSI ones under Windows Vista/7 as these
functions expect a LOGFONTW and not LOGFONTA even in non-Unicode build under
these systems.

This generalizes the previous fix/workaround for the same problem in
wxStaticBox so remove it now and use wxUxThemeFont both there and in
wxMenuItem to avoid crashes when using owner-drawn menus in ANSI build.

Closes #12364.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65955 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2010-10-30 23:50:22 +00:00
parent abaa31e7ea
commit 3120eccfe2
3 changed files with 76 additions and 26 deletions

View File

@@ -430,11 +430,7 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
wxUxThemeHandle hTheme(this, L"BUTTON");
if ( hTheme )
{
// GetThemeFont() expects its parameter to be LOGFONTW and not
// LOGFONTA even in ANSI programs and will happily corrupt
// memory after the struct end if we pass a LOGFONTA (which is
// smaller) to it!
LOGFONTW lfw;
wxUxThemeFont themeFont;
if ( wxUxThemeEngine::Get()->GetThemeFont
(
hTheme,
@@ -442,24 +438,10 @@ void wxStaticBox::PaintForeground(wxDC& dc, const RECT& rc)
BP_GROUPBOX,
GBS_NORMAL,
TMT_FONT,
(LOGFONT *)&lfw
themeFont.GetPtr()
) == S_OK )
{
#if wxUSE_UNICODE
// ok, no conversion necessary
const LOGFONT& lf = lfw;
#else // !wxUSE_UNICODE
// most of the fields are the same in LOGFONTA and LOGFONTW
LOGFONT lf;
memcpy(&lf, &lfw, sizeof(lf));
// but the face name must be converted
WideCharToMultiByte(CP_ACP, 0, lfw.lfFaceName, -1,
lf.lfFaceName, sizeof(lf.lfFaceName),
NULL, NULL);
#endif // wxUSE_UNICODE/!wxUSE_UNICODE
font.Init(lf);
font.Init(themeFont.GetLOGFONT());
if ( font )
selFont.Init(hdc, font);
}