\item wxRICHTEXT\_SETSTYLE\_WITH\_UNDO: specifies that this operation should be undoable.
\item wxRICHTEXT\_SETSTYLE\_OPTIMIZE: specifies that the style should not be applied if the
combined style at this point is already the style in question.
-\item define wxRICHTEXT\_SETSTYLE\_PARAGRAPHS\_ONLY: specifies that the style should only be applied to paragraphs,
+\item wxRICHTEXT\_SETSTYLE\_PARAGRAPHS\_ONLY: specifies that the style should only be applied to paragraphs,
and not the content. This allows content styling to be preserved independently from that of e.g. a named paragraph style.
\item wxRICHTEXT\_SETSTYLE\_CHARACTERS\_ONLY: specifies that the style should only be applied to characters,
and not the paragraph. This allows content styling to be preserved independently from that of e.g. a named paragraph style.
+\item wxRICHTEXT\_SETSTYLE\_RESET: resets (clears) the existing style before applying the new style.
\end{itemize}
\membersection{wxRichTextBuffer::SetStyleSheet}\label{wxrichtextbuffersetstylesheet}
\item wxRICHTEXT\_SETSTYLE\_WITH\_UNDO: specifies that this operation should be undoable.
\item wxRICHTEXT\_SETSTYLE\_OPTIMIZE: specifies that the style should not be applied if the
combined style at this point is already the style in question.
-\item define wxRICHTEXT\_SETSTYLE\_PARAGRAPHS\_ONLY: specifies that the style should only be applied to paragraphs,
+\item wxRICHTEXT\_SETSTYLE\_PARAGRAPHS\_ONLY: specifies that the style should only be applied to paragraphs,
and not the content. This allows content styling to be preserved independently from that of e.g. a named paragraph style.
\item wxRICHTEXT\_SETSTYLE\_CHARACTERS\_ONLY: specifies that the style should only be applied to characters,
and not the paragraph. This allows content styling to be preserved independently from that of e.g. a named paragraph style.
+\item wxRICHTEXT\_SETSTYLE\_RESET: resets (clears) the existing style before applying the new style.
\end{itemize}
\membersection{wxRichTextCtrl::SetStyleSheet}\label{wxrichtextctrlsetstylesheet}
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.
// to be included in the paragraph style
if ((paragraphStyle || parasOnly) && !charactersOnly)
{
- if (applyMinimal)
+ if (resetExistingStyle)
+ newPara->GetAttributes() = wholeStyle;
+ else
{
- // 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 (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);
}
- else
- wxRichTextApplyStyle(newPara->GetAttributes(), style);
}
#if wxRICHTEXT_USE_DYNAMIC_STYLES
{
wxRichTextObject* child = node2->GetData();
- if (applyMinimal)
+ if (resetExistingStyle)
+ child->GetAttributes() = characterAttributes;
+ else
{
- // 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 (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);
}
- else
- wxRichTextApplyStyle(child->GetAttributes(), characterAttributes);
if (node2 == lastNode)
break;