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:
@@ -236,6 +236,19 @@ protected:
|
|||||||
virtual wxSize DoGetBestSize() const;
|
virtual wxSize DoGetBestSize() const;
|
||||||
|
|
||||||
#if wxUSE_RICHEDIT
|
#if wxUSE_RICHEDIT
|
||||||
|
// Apply the character-related parts of wxTextAttr to the given selection
|
||||||
|
// or the entire control if start == end == -1.
|
||||||
|
//
|
||||||
|
// This function is private and should only be called for rich edit
|
||||||
|
// controls and with (from, to) already in correct order, i.e. from <= to.
|
||||||
|
bool MSWSetCharFormat(const wxTextAttr& attr, long from = -1, long to = -1);
|
||||||
|
|
||||||
|
// Same as above for paragraph-related parts of wxTextAttr. Note that this
|
||||||
|
// can only be applied to the selection as RichEdit doesn't support setting
|
||||||
|
// the paragraph styles globally.
|
||||||
|
bool MSWSetParaFormat(const wxTextAttr& attr, long from, long to);
|
||||||
|
|
||||||
|
|
||||||
// we're using RICHEDIT (and not simple EDIT) control if this field is not
|
// we're using RICHEDIT (and not simple EDIT) control if this field is not
|
||||||
// 0, it also gives the version of the RICHEDIT control being used
|
// 0, it also gives the version of the RICHEDIT control being used
|
||||||
// (although not directly: 1 is for 1.0, 2 is for either 2.0 or 3.0 as we
|
// (although not directly: 1 is for 1.0, 2 is for either 2.0 or 3.0 as we
|
||||||
|
@@ -2384,46 +2384,8 @@ bool wxTextCtrl::SetFont(const wxFont& font)
|
|||||||
// styling support for rich edit controls
|
// 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
|
// initialize CHARFORMAT struct
|
||||||
#if wxUSE_RICHEDIT2
|
#if wxUSE_RICHEDIT2
|
||||||
CHARFORMAT2 cf;
|
CHARFORMAT2 cf;
|
||||||
@@ -2505,17 +2467,29 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
|||||||
}
|
}
|
||||||
#endif // wxUSE_RICHEDIT2
|
#endif // wxUSE_RICHEDIT2
|
||||||
|
|
||||||
// do format the selection
|
// Apply the style to the selection.
|
||||||
bool ok = ::SendMessage(GetHwnd(), EM_SETCHARFORMAT,
|
DoSetSelection(start, end, SetSel_NoScroll);
|
||||||
SCF_SELECTION, (LPARAM)&cf) != 0;
|
|
||||||
if ( !ok )
|
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;
|
PARAFORMAT2 pf;
|
||||||
|
#else
|
||||||
|
PARAFORMAT pf;
|
||||||
|
#endif
|
||||||
|
|
||||||
wxZeroMemory(pf);
|
wxZeroMemory(pf);
|
||||||
|
|
||||||
// we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
|
// we can't use PARAFORMAT2 with RichEdit 1.0, so pretend it is a simple
|
||||||
// PARAFORMAT in that case
|
// PARAFORMAT in that case
|
||||||
#if wxUSE_RICHEDIT2
|
#if wxUSE_RICHEDIT2
|
||||||
@@ -2590,16 +2564,54 @@ bool wxTextCtrl::SetStyle(long start, long end, const wxTextAttr& style)
|
|||||||
|
|
||||||
if ( pf.dwMask )
|
if ( pf.dwMask )
|
||||||
{
|
{
|
||||||
// do format the selection
|
// Do format the selection.
|
||||||
bool ok = ::SendMessage(GetHwnd(), EM_SETPARAFORMAT,
|
DoSetSelection(start, end, SetSel_NoScroll);
|
||||||
0, (LPARAM) &pf) != 0;
|
|
||||||
if ( !ok )
|
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
|
// restore the original selection
|
||||||
DoSetSelection(startOld, endOld, SetSel_NoScroll);
|
DoSetSelection(startOld, endOld, SetSel_NoScroll);
|
||||||
|
Reference in New Issue
Block a user