From 741c337588b7b32ec0ca1b5f2c3aa7f1a444082f Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 1 Sep 2010 14:48:43 +0000 Subject: [PATCH] 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/branches/WX_2_8_BRANCH@65455 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +++ src/richtext/richtextctrl.cpp | 24 +++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/docs/changes.txt b/docs/changes.txt index 129d2be5a6..d83f2fe829 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -97,6 +97,9 @@ All (GUI): - wxRTC: can now edit line spacing in .1 increments from 1 to 2. - wxRTC: fixed wrong line spacing and space after paragraph calculations. - wxRTC: GetStyleMergedWithBase now detects loops. +- wxRTC: 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. wxMSW: diff --git a/src/richtext/richtextctrl.cpp b/src/richtext/richtextctrl.cpp index 4d14b28ab6..a336ef4da8 100644 --- a/src/richtext/richtextctrl.cpp +++ b/src/richtext/richtextctrl.cpp @@ -3321,9 +3321,12 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) return SetListStyle(range, (wxRichTextListStyleDefinition*) def, flags); } + bool isPara = false; + // Make sure the attr has the style name if (def->IsKindOf(CLASSINFO(wxRichTextParagraphStyleDefinition))) { + isPara = true; attr.SetParagraphStyleName(def->GetName()); // If applying a paragraph style, we only want the paragraph nodes to adopt these @@ -3339,8 +3342,27 @@ bool wxRichTextCtrl::ApplyStyle(wxRichTextStyleDefinition* def) else { wxRichTextAttr current = GetDefaultStyleEx(); - current.Apply(attr); + wxRichTextAttr 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); + + // 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; } }