{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
- // be combined at display time
- wxTextAttrEx style(GetDefaultStyle());
+ // be combined at display time.
+ // Divide into paragraph and character styles.
+
+ wxTextAttrEx defaultCharStyle;
+ wxTextAttrEx defaultParaStyle;
+ wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
+
+ wxTextAttrEx defaultCharStyle = style;
+ wxTextAttrEx defaultParaStyle = style;
#endif
- wxRichTextParagraph* para = new wxRichTextParagraph(text, this, & style);
- if (paraStyle)
- para->SetAttributes(*paraStyle);
+ wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
+ wxTextAttrEx* cStyle = & defaultCharStyle;
+
+ wxRichTextParagraph* para = new wxRichTextParagraph(text, this, pStyle, cStyle);
AppendChild(para);
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
- // be combined at display time
- wxTextAttrEx style(GetDefaultStyle());
+ // be combined at display time.
+ // Divide into paragraph and character styles.
+
+ wxTextAttrEx defaultCharStyle;
+ wxTextAttrEx defaultParaStyle;
+ wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
- //wxLogDebug("Initial style = %s", style.GetFont().GetFaceName());
- //wxLogDebug("Initial size = %d", style.GetFont().GetPointSize());
-
// Apply default style. If the style has no attributes set,
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
- //wxLogDebug("Style after applying default style = %s", style.GetFont().GetFaceName());
- //wxLogDebug("Size after applying default style = %d", style.GetFont().GetPointSize());
+ wxTextAttrEx defaultCharStyle = style;
+ wxTextAttrEx defaultParaStyle = style;
#endif
+ wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
+ wxTextAttrEx* cStyle = & defaultCharStyle;
+
wxRichTextParagraph* firstPara = NULL;
wxRichTextParagraph* lastPara = NULL;
size_t i = 0;
size_t len = text.length();
wxString line;
- wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, & style);
- if (paraStyle)
- para->SetAttributes(*paraStyle);
+ wxRichTextParagraph* para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle);
AppendChild(para);
wxRichTextPlainText* plainText = (wxRichTextPlainText*) para->GetChildren().GetFirst()->GetData();
plainText->SetText(line);
- para = new wxRichTextParagraph(wxEmptyString, this, & style);
- if (paraStyle)
- para->SetAttributes(*paraStyle);
+ para = new wxRichTextParagraph(wxEmptyString, this, pStyle, cStyle);
AppendChild(para);
- //if (!firstPara)
- // firstPara = para;
-
lastPara = para;
line = wxEmptyString;
}
plainText->SetText(line);
}
-/*
- if (firstPara)
- range.SetStart(firstPara->GetRange().GetStart());
- else if (lastPara)
- range.SetStart(lastPara->GetRange().GetStart());
-
- if (lastPara)
- range.SetEnd(lastPara->GetRange().GetEnd());
- else if (firstPara)
- range.SetEnd(firstPara->GetRange().GetEnd());
-*/
-
UpdateRanges();
SetDirty(false);
{
#if wxRICHTEXT_USE_DYNAMIC_STYLES
// Don't use the base style, just the default style, and the base style will
- // be combined at display time
- wxTextAttrEx style(GetDefaultStyle());
+ // be combined at display time.
+ // Divide into paragraph and character styles.
+
+ wxTextAttrEx defaultCharStyle;
+ wxTextAttrEx defaultParaStyle;
+ wxRichTextSplitParaCharStyles(GetDefaultStyle(), defaultParaStyle, defaultCharStyle);
#else
wxTextAttrEx style(GetAttributes());
// then the attributes will remain the 'basic style' (i.e. the
// layout box's style).
wxRichTextApplyStyle(style, GetDefaultStyle());
+
+ wxTextAttrEx defaultCharStyle = style;
+ wxTextAttrEx defaultParaStyle = style;
#endif
- wxRichTextParagraph* para = new wxRichTextParagraph(this, & style);
- AppendChild(para);
- para->AppendChild(new wxRichTextImage(image, this));
+ wxTextAttrEx* pStyle = paraStyle ? paraStyle : (wxTextAttrEx*) & defaultParaStyle;
+ wxTextAttrEx* cStyle = & defaultCharStyle;
- if (paraStyle)
- para->SetAttributes(*paraStyle);
+ wxRichTextParagraph* para = new wxRichTextParagraph(this, pStyle);
+ AppendChild(para);
+ para->AppendChild(new wxRichTextImage(image, this, cStyle));
UpdateRanges();
SetDirty(true);
/// Insert fragment into this box at the given position. If partialParagraph is true,
/// it is assumed that the last (or only) paragraph is just a piece of data with no paragraph
/// marker.
-/// TODO: if fragment is inserted inside styled fragment, must apply that style to
-/// to the data (if it has a default style, anyway).
bool wxRichTextParagraphLayoutBox::InsertFragment(long position, wxRichTextParagraphLayoutBox& fragment)
{
wxRichTextParagraph* firstPara = wxDynamicCast(firstParaNode->GetData(), wxRichTextParagraph);
wxASSERT (firstPara != NULL);
+ // Apply the new paragraph attributes to the existing paragraph
+ wxTextAttrEx attr(para->GetAttributes());
+ wxRichTextApplyStyle(attr, firstPara->GetAttributes());
+ para->SetAttributes(attr);
+
wxRichTextObjectList::compatibility_iterator objectNode = firstPara->GetChildren().GetFirst();
while (objectNode)
{
if (finalPara->GetChildCount() == 0)
{
wxRichTextPlainText* text = new wxRichTextPlainText(wxEmptyString);
-#if !wxRICHTEXT_USE_DYNAMIC_STYLES
- text->SetAttributes(finalPara->GetAttributes());
-#endif
finalPara->AppendChild(text);
}
/// Set default style
bool wxRichTextParagraphLayoutBox::SetDefaultStyle(const wxTextAttrEx& style)
{
- // I don't think the default style should be combined with the previous
- // default style.
m_defaultAttributes = style;
-
-#if 0
- // keep the old attributes if the new style doesn't specify them unless the
- // new style is empty - then reset m_defaultStyle (as there is no other way
- // to do it)
- if ( style.IsDefault() )
- m_defaultAttributes = style;
- else
- m_defaultAttributes = wxTextAttrEx::CombineEx(style, m_defaultAttributes, NULL);
-#endif
return true;
}
/// position of the paragraph that it had to start looking from.
bool wxRichTextParagraphLayoutBox::FindNextParagraphNumber(wxRichTextParagraph* previousParagraph, wxRichTextAttr& attr) const
{
-#if 0
- wxRichTextObjectList::compatibility_iterator node = m_children.Find(previousParagraph);
-
- if (!node)
- return false;
-#endif
-
if (!previousParagraph->GetAttributes().HasFlag(wxTEXT_ATTR_BULLET_STYLE) || previousParagraph->GetAttributes().GetBulletStyle() == wxTEXT_ATTR_BULLET_STYLE_NONE)
return false;
wxRichTextParagraph::wxRichTextParagraph(wxRichTextObject* parent, wxTextAttrEx* style):
wxRichTextBox(parent)
{
- if (parent && !style)
- SetAttributes(parent->GetAttributes());
if (style)
SetAttributes(*style);
}
-wxRichTextParagraph::wxRichTextParagraph(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* style):
+wxRichTextParagraph::wxRichTextParagraph(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* paraStyle, wxTextAttrEx* charStyle):
wxRichTextBox(parent)
{
- if (parent && !style)
- SetAttributes(parent->GetAttributes());
- if (style)
- SetAttributes(*style);
+ if (paraStyle)
+ SetAttributes(*paraStyle);
- AppendChild(new wxRichTextPlainText(text, this));
+ AppendChild(new wxRichTextPlainText(text, this, charStyle));
}
wxRichTextParagraph::~wxRichTextParagraph()
wxRichTextPlainText::wxRichTextPlainText(const wxString& text, wxRichTextObject* parent, wxTextAttrEx* style):
wxRichTextObject(parent)
{
- if (parent && !style)
- SetAttributes(parent->GetAttributes());
if (style)
SetAttributes(*style);
{
wxRichTextAction* action = new wxRichTextAction(NULL, _("Insert Text"), wxRICHTEXT_INSERT, this, ctrl, false);
+#if wxRICHTEXT_USE_DYNAMIC_STYLES
+ wxTextAttrEx attr(GetDefaultStyle());
+#else
+ wxTextAttrEx attr(GetBasicStyle());
+ wxRichTextApplyStyle(attr, GetDefaultStyle());
+#endif
+
wxTextAttrEx* p = NULL;
wxTextAttrEx paraAttr;
if (flags & wxRICHTEXT_INSERT_WITH_PREVIOUS_PARAGRAPH_STYLE)
if (!paraAttr.IsDefault())
p = & paraAttr;
}
-
-#if wxRICHTEXT_USE_DYNAMIC_STYLES
- wxTextAttrEx attr(GetDefaultStyle());
-#else
- wxTextAttrEx attr(GetBasicStyle());
- wxRichTextApplyStyle(attr, GetDefaultStyle());
-#endif
+ else
+ p = & attr;
action->GetNewParagraphs() = paragraphs;
p = & paraAttr;
}
-#if wxRICHTEXT_USE_DYNAMIC_STYLES
- wxTextAttrEx attr(GetDefaultStyle());
-#else
- wxTextAttrEx attr(GetBasicStyle());
- wxRichTextApplyStyle(attr, GetDefaultStyle());
-#endif
-
action->GetNewParagraphs().AddParagraphs(text, p);
int length = action->GetNewParagraphs().GetRange().GetLength();
IMPLEMENT_DYNAMIC_CLASS(wxRichTextImage, wxRichTextObject)
-wxRichTextImage::wxRichTextImage(const wxImage& image, wxRichTextObject* parent):
+wxRichTextImage::wxRichTextImage(const wxImage& image, wxRichTextObject* parent, wxTextAttrEx* charStyle):
wxRichTextObject(parent)
{
m_image = image;
+ if (charStyle)
+ SetAttributes(*charStyle);
}
-wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent):
+wxRichTextImage::wxRichTextImage(const wxRichTextImageBlock& imageBlock, wxRichTextObject* parent, wxTextAttrEx* charStyle):
wxRichTextObject(parent)
{
m_imageBlock = imageBlock;
m_imageBlock.Load(m_image);
+ if (charStyle)
+ SetAttributes(*charStyle);
}
/// Load wxImage from the block
return true;
}
+/// Split into paragraph and character styles
+bool wxRichTextSplitParaCharStyles(const wxTextAttrEx& style, wxTextAttrEx& parStyle, wxTextAttrEx& charStyle)
+{
+ wxTextAttrEx defaultCharStyle1(style);
+ wxTextAttrEx defaultParaStyle1(style);
+ defaultCharStyle1.SetFlags(defaultCharStyle1.GetFlags()&wxTEXT_ATTR_CHARACTER);
+ defaultParaStyle1.SetFlags(defaultParaStyle1.GetFlags()&wxTEXT_ATTR_PARAGRAPH);
+
+ wxRichTextApplyStyle(charStyle, defaultCharStyle1);
+ wxRichTextApplyStyle(parStyle, defaultParaStyle1);
+
+ return true;
+}
+
void wxSetFontPreservingStyles(wxTextAttr& attr, const wxFont& font)
{
long flags = attr.GetFlags();