wxRichTextCtrl::ApplyStyle now applies a paragraph style at the cursor
without needing a selection, and setting the default style now avoids duplicating character attributes in subsequently typed text when they exist in the paragraph style. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65456 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -3248,9 +3248,12 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def)
|
|||||||
return SetListStyle(range, (wxRichTextListStyleDefinition*) def, flags);
|
return SetListStyle(range, (wxRichTextListStyleDefinition*) def, flags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool isPara = false;
|
||||||
|
|
||||||
// Make sure the attr has the style name
|
// Make sure the attr has the style name
|
||||||
if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition)))
|
if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition)))
|
||||||
{
|
{
|
||||||
|
isPara = true;
|
||||||
attr.SetParagraphStyleName(def->GetName());
|
attr.SetParagraphStyleName(def->GetName());
|
||||||
|
|
||||||
// If applying a paragraph style, we only want the paragraph nodes to adopt these
|
// If applying a paragraph style, we only want the paragraph nodes to adopt these
|
||||||
@@ -3265,9 +3268,28 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def)
|
|||||||
return SetStyleEx(GetSelectionRange(), attr, flags);
|
return SetStyleEx(GetSelectionRange(), attr, flags);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
wxRichTextAttr current = GetDefaultStyleEx();
|
wxTextAttr current = GetDefaultStyleEx();
|
||||||
current.Apply(attr);
|
wxTextAttr defaultStyle(attr);
|
||||||
|
if (isPara)
|
||||||
|
{
|
||||||
|
// Don't apply extra character styles since they are already implied
|
||||||
|
// in the paragraph style
|
||||||
|
defaultStyle.SetFlags(defaultStyle.GetFlags() & ~wxTEXT_ATTR_CHARACTER);
|
||||||
|
}
|
||||||
|
current.Apply(defaultStyle);
|
||||||
SetAndShowDefaultStyle(current);
|
SetAndShowDefaultStyle(current);
|
||||||
|
|
||||||
|
// If it's a paragraph style, we want to apply the style to the
|
||||||
|
// current paragraph even if we didn't select any text.
|
||||||
|
if (isPara)
|
||||||
|
{
|
||||||
|
long pos = GetAdjustedCaretPosition(GetCaretPosition());
|
||||||
|
wxRichTextParagraph* para = GetBuffer().GetParagraphAtPosition(pos);
|
||||||
|
if (para)
|
||||||
|
{
|
||||||
|
return SetStyleEx(para->GetRange().FromInternal(), attr, flags);
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user