Really fix setting fonts in RichEdit 4.1 controls.
The fix applied in r64394 wasn't enough and the control could still decide to overwrite the font used by default when non-ASCII characters were inserted into it. To really force it to use the font we want we apparently must send it EM_SETCHARFORMAT with SCF_ALL flag (MSDN also documents SCF_DEFAULT but it's not clear if we should use it instead or together with SCF_ALL, for now it doesn't seem to be necessary). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65565 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2365,16 +2365,15 @@ bool wxTextCtrl::SetFont(const wxFont& font)
|
|||||||
if ( !wxTextCtrlBase::SetFont(font) )
|
if ( !wxTextCtrlBase::SetFont(font) )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( IsRich() )
|
if ( GetRichVersion() >= 4 )
|
||||||
{
|
{
|
||||||
// Using WM_SETFONT doesn't work reliably with rich edit controls: as
|
// Using WM_SETFONT is not enough with RichEdit 4.1: it does work but
|
||||||
// an example, if we set a fixed width font for a richedit 4.1 control,
|
// for ASCII characters only and inserting a non-ASCII one into it
|
||||||
// it's used for the ASCII characters but inserting any non-ASCII ones
|
// later reverts to the default font so use EM_SETCHARFORMAT to change
|
||||||
// switches the font to a proportional one, whether it's done
|
// the default font for it.
|
||||||
// programmatically or not. So just use EM_SETCHARFORMAT for this too.
|
|
||||||
wxTextAttr attr;
|
wxTextAttr attr;
|
||||||
attr.SetFont(font);
|
attr.SetFont(font);
|
||||||
SetDefaultStyle(attr);
|
SetStyle(-1, -1, attr);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@@ -2467,11 +2466,19 @@ bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end)
|
|||||||
}
|
}
|
||||||
#endif // wxUSE_RICHEDIT2
|
#endif // wxUSE_RICHEDIT2
|
||||||
|
|
||||||
// Apply the style to the selection.
|
// Apply the style either to the selection or to the entire control.
|
||||||
DoSetSelection(start, end, SetSel_NoScroll);
|
WPARAM selMode;
|
||||||
|
if ( start != -1 || end != -1 )
|
||||||
|
{
|
||||||
|
DoSetSelection(start, end, SetSel_NoScroll);
|
||||||
|
selMode = SCF_SELECTION;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
selMode = SCF_ALL;
|
||||||
|
}
|
||||||
|
|
||||||
if ( !::SendMessage(GetHwnd(), EM_SETCHARFORMAT,
|
if ( !::SendMessage(GetHwnd(), EM_SETCHARFORMAT, selMode, (LPARAM)&cf) )
|
||||||
SCF_SELECTION, (LPARAM)&cf) )
|
|
||||||
{
|
{
|
||||||
wxLogLastError(wxT("SendMessage(EM_SETCHARFORMAT)"));
|
wxLogLastError(wxT("SendMessage(EM_SETCHARFORMAT)"));
|
||||||
return false;
|
return false;
|
||||||
|
Reference in New Issue
Block a user