Added wxRICHTEXT_SETSTYLE_RESET SetStyleEx() flag to allow for clearing attributes before setting new ones

SetStyle() now looks up and applies named paragraph or character style
Fixed a bug in text entry (taking previous paragraph's style)


git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@43459 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Julian Smart
2006-11-17 08:33:34 +00:00
parent 380a5dd803
commit 523d2f145e
5 changed files with 53 additions and 20 deletions

View File

@@ -1599,11 +1599,29 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
bool applyMinimal = ((flags & wxRICHTEXT_SETSTYLE_OPTIMIZE) != 0);
bool parasOnly = ((flags & wxRICHTEXT_SETSTYLE_PARAGRAPHS_ONLY) != 0);
bool charactersOnly = ((flags & wxRICHTEXT_SETSTYLE_CHARACTERS_ONLY) != 0);
bool resetExistingStyle = ((flags & wxRICHTEXT_SETSTYLE_RESET) != 0);
// Apply paragraph style first, if any
wxRichTextAttr wholeStyle(style);
if (wholeStyle.HasParagraphStyleName() && GetStyleSheet())
{
wxRichTextParagraphStyleDefinition* def = GetStyleSheet()->FindParagraphStyle(wholeStyle.GetParagraphStyleName());
if (def)
wxRichTextApplyStyle(wholeStyle, def->GetStyle());
}
// Limit the attributes to be set to the content to only character attributes.
wxRichTextAttr characterAttributes(style);
wxRichTextAttr characterAttributes(wholeStyle);
characterAttributes.SetFlags(characterAttributes.GetFlags() & (wxTEXT_ATTR_CHARACTER));
if (characterAttributes.HasCharacterStyleName() && GetStyleSheet())
{
wxRichTextCharacterStyleDefinition* def = GetStyleSheet()->FindCharacterStyle(characterAttributes.GetCharacterStyleName());
if (def)
wxRichTextApplyStyle(characterAttributes, def->GetStyle());
}
// If we are associated with a control, make undoable; otherwise, apply immediately
// to the data.
@@ -1651,15 +1669,20 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
// to be included in the paragraph style
if ((paragraphStyle || parasOnly) && !charactersOnly)
{
if (applyMinimal)
{
// Only apply attributes that will make a difference to the combined
// style as seen on the display
wxRichTextAttr combinedAttr(para->GetCombinedAttributes());
wxRichTextApplyStyle(newPara->GetAttributes(), style, & combinedAttr);
}
if (resetExistingStyle)
newPara->GetAttributes() = wholeStyle;
else
wxRichTextApplyStyle(newPara->GetAttributes(), style);
{
if (applyMinimal)
{
// Only apply attributes that will make a difference to the combined
// style as seen on the display
wxRichTextAttr combinedAttr(para->GetCombinedAttributes());
wxRichTextApplyStyle(newPara->GetAttributes(), wholeStyle, & combinedAttr);
}
else
wxRichTextApplyStyle(newPara->GetAttributes(), wholeStyle);
}
}
#if wxRICHTEXT_USE_DYNAMIC_STYLES
@@ -1725,15 +1748,20 @@ bool wxRichTextParagraphLayoutBox::SetStyle(const wxRichTextRange& range, const
{
wxRichTextObject* child = node2->GetData();
if (applyMinimal)
{
// Only apply attributes that will make a difference to the combined
// style as seen on the display
wxRichTextAttr combinedAttr(newPara->GetCombinedAttributes(child->GetAttributes()));
wxRichTextApplyStyle(child->GetAttributes(), characterAttributes, & combinedAttr);
}
if (resetExistingStyle)
child->GetAttributes() = characterAttributes;
else
wxRichTextApplyStyle(child->GetAttributes(), characterAttributes);
{
if (applyMinimal)
{
// Only apply attributes that will make a difference to the combined
// style as seen on the display
wxRichTextAttr combinedAttr(newPara->GetCombinedAttributes(child->GetAttributes()));
wxRichTextApplyStyle(child->GetAttributes(), characterAttributes, & combinedAttr);
}
else
wxRichTextApplyStyle(child->GetAttributes(), characterAttributes);
}
if (node2 == lastNode)
break;