No changes, just refactor wxTextCtrl::SetStyle() in wxMSW.
Split this overly long function into MSWSetCharFormat() and MSWSetParaFormat(). No real changes otherwise except for the use of PARAFORMAT instead of PARAFORMAT2 if wxUSE_RICHEDIT2 is not set as it was certainly intended (but the fact that nobody complained about this problem means that nobody must be compiling without wxUSE_RICHEDIT2 by now so arguably we should just remove it completely). git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65564 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -2384,46 +2384,8 @@ bool wxTextCtrl::SetFont(const wxFont& font)
|
||||
// styling support for rich edit controls
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
||||
bool wxTextCtrl::MSWSetCharFormat(const wxTextAttr& style, long start, long end)
|
||||
{
|
||||
if ( !IsRich() )
|
||||
{
|
||||
// can't do it with normal text control
|
||||
return false;
|
||||
}
|
||||
|
||||
// the richedit 1.0 doesn't handle setting background colour, so don't
|
||||
// even try to do anything if it's the only thing we want to change
|
||||
if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() &&
|
||||
!style.HasLeftIndent() && !style.HasRightIndent() && !style.HasAlignment() &&
|
||||
!style.HasTabs() )
|
||||
{
|
||||
// nothing to do: return true if there was really nothing to do and
|
||||
// false if we failed to set bg colour
|
||||
return !style.HasBackgroundColour();
|
||||
}
|
||||
|
||||
// order the range if needed
|
||||
if ( start > end )
|
||||
{
|
||||
long tmp = start;
|
||||
start = end;
|
||||
end = tmp;
|
||||
}
|
||||
|
||||
// we can only change the format of the selection, so select the range we
|
||||
// want and restore the old selection later
|
||||
long startOld, endOld;
|
||||
GetSelection(&startOld, &endOld);
|
||||
|
||||
// but do we really have to change the selection?
|
||||
bool changeSel = start != startOld || end != endOld;
|
||||
|
||||
if ( changeSel )
|
||||
{
|
||||
DoSetSelection(start, end, SetSel_NoScroll);
|
||||
}
|
||||
|
||||
// initialize CHARFORMAT struct
|
||||
#if wxUSE_RICHEDIT2
|
||||
CHARFORMAT2 cf;
|
||||
@@ -2505,17 +2467,29 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
||||
}
|
||||
#endif // wxUSE_RICHEDIT2
|
||||
|
||||
// do format the selection
|
||||
bool ok = ::SendMessage(GetHwnd(), EM_SETCHARFORMAT,
|
||||
SCF_SELECTION, (LPARAM)&cf) != 0;
|
||||
if ( !ok )
|
||||
// Apply the style to the selection.
|
||||
DoSetSelection(start, end, SetSel_NoScroll);
|
||||
|
||||
if ( !::SendMessage(GetHwnd(), EM_SETCHARFORMAT,
|
||||
SCF_SELECTION, (LPARAM)&cf) )
|
||||
{
|
||||
wxLogDebug(wxT("SendMessage(EM_SETCHARFORMAT, SCF_SELECTION) failed"));
|
||||
wxLogLastError(wxT("SendMessage(EM_SETCHARFORMAT)"));
|
||||
return false;
|
||||
}
|
||||
|
||||
// now do the paragraph formatting
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxTextCtrl::MSWSetParaFormat(const wxTextAttr& style, long start, long end)
|
||||
{
|
||||
#if wxUSE_RICHEDIT2
|
||||
PARAFORMAT2 pf;
|
||||
#else
|
||||
PARAFORMAT pf;
|
||||
#endif
|
||||
|
||||
wxZeroMemory(pf);
|
||||
|
||||
// we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
|
||||
// PARAFORMAT in that case
|
||||
#if wxUSE_RICHEDIT2
|
||||
@@ -2590,16 +2564,54 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
||||
|
||||
if ( pf.dwMask )
|
||||
{
|
||||
// do format the selection
|
||||
bool ok = ::SendMessage(GetHwnd(), EM_SETPARAFORMAT,
|
||||
0, (LPARAM) &pf) != 0;
|
||||
if ( !ok )
|
||||
// Do format the selection.
|
||||
DoSetSelection(start, end, SetSel_NoScroll);
|
||||
|
||||
if ( !::SendMessage(GetHwnd(), EM_SETPARAFORMAT, 0, (LPARAM) &pf) )
|
||||
{
|
||||
wxLogDebug(wxT("SendMessage(EM_SETPARAFORMAT, 0) failed"));
|
||||
wxLogLastError(wxT("SendMessage(EM_SETPARAFORMAT)"));
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( changeSel )
|
||||
return true;
|
||||
}
|
||||
|
||||
bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
||||
{
|
||||
if ( !IsRich() )
|
||||
{
|
||||
// can't do it with normal text control
|
||||
return false;
|
||||
}
|
||||
|
||||
// the richedit 1.0 doesn't handle setting background colour, so don't
|
||||
// even try to do anything if it's the only thing we want to change
|
||||
if ( m_verRichEdit == 1 && !style.HasFont() && !style.HasTextColour() &&
|
||||
!style.HasLeftIndent() && !style.HasRightIndent() && !style.HasAlignment() &&
|
||||
!style.HasTabs() )
|
||||
{
|
||||
// nothing to do: return true if there was really nothing to do and
|
||||
// false if we failed to set bg colour
|
||||
return !style.HasBackgroundColour();
|
||||
}
|
||||
|
||||
// order the range if needed
|
||||
if ( start > end )
|
||||
wxSwap(start, end);
|
||||
|
||||
// we can only change the format of the selection, so select the range we
|
||||
// want and restore the old selection later, after MSWSetXXXFormat()
|
||||
// functions (possibly) change it.
|
||||
long startOld, endOld;
|
||||
GetSelection(&startOld, &endOld);
|
||||
|
||||
bool ok = MSWSetCharFormat(style, start, end);
|
||||
if ( !MSWSetParaFormat(style, start, end) )
|
||||
ok = false;
|
||||
|
||||
if ( start != startOld || end != endOld )
|
||||
{
|
||||
// restore the original selection
|
||||
DoSetSelection(startOld, endOld, SetSel_NoScroll);
|
||||
|
Reference in New Issue
Block a user