Add a simple wxSetWindowFont() helper
This function is a just a very thin wrapper for WM_SETFONT, but it's still better to have it rather than write casts to WPARAM and MAKELPARAM() in several different places. Note that this removes the assert for font validity from wxWindow::SetFont() which really doesn't make much sense (and if we wanted to have it, it would be better to have it for all ports in wxWindowBase instead) and was never triggered since more than 20 years of its existence.
This commit is contained in:
committed by
Maarten Bent
parent
8e15849706
commit
b24d7e3ae4
@@ -965,6 +965,12 @@ WXDLLIMPEXP_CORE void wxFillLogFont(LOGFONT *logFont, const wxFont *font);
|
||||
WXDLLIMPEXP_CORE wxFont wxCreateFontFromLogFont(const LOGFONT *logFont);
|
||||
WXDLLIMPEXP_CORE wxFontEncoding wxGetFontEncFromCharSet(int charset);
|
||||
|
||||
inline void wxSetWindowFont(HWND hwnd, const wxFont& font)
|
||||
{
|
||||
::SendMessage(hwnd, WM_SETFONT,
|
||||
(WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0));
|
||||
}
|
||||
|
||||
WXDLLIMPEXP_CORE void wxSliderEvent(WXHWND control, WXWORD wParam, WXWORD pos);
|
||||
WXDLLIMPEXP_CORE void wxScrollBarEvent(WXHWND hbar, WXWORD wParam, WXWORD pos);
|
||||
|
||||
|
@@ -113,14 +113,11 @@ public:
|
||||
// set font for all windows
|
||||
void SetFont(const wxFont& font)
|
||||
{
|
||||
HFONT hfont = GetHfontOf(font);
|
||||
wxCHECK_RET( hfont, wxT("invalid font") );
|
||||
|
||||
for ( size_t n = 0; n < m_count; n++ )
|
||||
{
|
||||
if ( m_hwnds[n] )
|
||||
{
|
||||
::SendMessage(m_hwnds[n], WM_SETFONT, (WPARAM)hfont, 0);
|
||||
wxSetWindowFont(m_hwnds[n], font);
|
||||
|
||||
// otherwise the window might not be redrawn correctly
|
||||
::InvalidateRect(m_hwnds[n], NULL, FALSE /* don't erase bg */);
|
||||
|
@@ -620,8 +620,7 @@ bool wxListCtrl::SetHeaderAttr(const wxItemAttr& attr)
|
||||
|
||||
// We need to tell the header about its new font to let it compute
|
||||
// its new height.
|
||||
::SendMessage(hwndHdr, WM_SETFONT,
|
||||
(WPARAM)GetHfontOf(font), MAKELPARAM(TRUE, 0));
|
||||
wxSetWindowFont(hwndHdr, font);
|
||||
}
|
||||
|
||||
// Refreshing the listview makes it notice the change in height of its
|
||||
|
@@ -552,7 +552,8 @@ int wxRendererMSW::GetHeaderButtonHeight(wxWindow * win)
|
||||
font = win->GetFont();
|
||||
if ( !font.IsOk() )
|
||||
wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
|
||||
::SendMessage(hwndHeader, WM_SETFONT, (WPARAM)GetHfontOf(font), 0);
|
||||
|
||||
wxSetWindowFont(hwndHeader, font);
|
||||
|
||||
// initialize the struct filled with the values by Header_Layout()
|
||||
RECT parentRect = { 0, 0, 100, 100 };
|
||||
|
@@ -564,8 +564,7 @@ bool wxSpinCtrl::SetFont(const wxFont& font)
|
||||
return false;
|
||||
}
|
||||
|
||||
WXHANDLE hFont = GetFont().GetResourceHandle();
|
||||
(void)::SendMessage(GetBuddyHwnd(), WM_SETFONT, (WPARAM)hFont, TRUE);
|
||||
wxSetWindowFont(GetBuddyHwnd(), GetFont());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@@ -827,11 +827,7 @@ bool wxWindowMSW::SetFont(const wxFont& font)
|
||||
// just been reset and in this case we need to change the font used by
|
||||
// the native window to the default for this class, i.e. exactly what
|
||||
// GetFont() returns
|
||||
WXHANDLE hFont = GetFont().GetResourceHandle();
|
||||
|
||||
wxASSERT_MSG( hFont, wxT("should have valid font") );
|
||||
|
||||
::SendMessage(hWnd, WM_SETFONT, (WPARAM)hFont, MAKELPARAM(TRUE, 0));
|
||||
wxSetWindowFont(hWnd, GetFont());
|
||||
}
|
||||
|
||||
return true;
|
||||
|
Reference in New Issue
Block a user