+ bool deleteConvFile = false;
+ wxString fileEncoding;
+ //wxMBConv* convFile = NULL;
+
+#if wxUSE_UNICODE
+ fileEncoding = wxT("UTF-8");
+ m_convFile = & wxConvUTF8;
+#else
+ fileEncoding = wxT("ISO-8859-1");
+ m_convFile = & wxConvISO8859_1;
+#endif
+
+ // If SetEncoding has been called, change the output encoding.
+ if (!m_encoding.empty() && m_encoding.Lower() != fileEncoding.Lower())
+ {
+ if (m_encoding == wxT("<System>"))
+ {
+#if wxUSE_INTL
+ fileEncoding = wxLocale::GetSystemEncodingName();
+ // if !wxUSE_INTL, we fall back to UTF-8 or ISO-8859-1 below
+#endif
+ }
+ else
+ {
+ fileEncoding = m_encoding;
+ }
+
+ // GetSystemEncodingName may not have returned a name
+ if (fileEncoding.empty())
+#if wxUSE_UNICODE
+ fileEncoding = wxT("UTF-8");
+#else
+ fileEncoding = wxT("ISO-8859-1");
+#endif
+ m_convFile = new wxCSConv(fileEncoding);
+ deleteConvFile = true;
+ }
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT && wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT
+#if wxRICHTEXT_USE_OUTPUT_TIMINGS
+ wxStopWatch stopwatch;
+#endif
+ wxXmlDocument* doc = new wxXmlDocument;
+ doc->SetFileEncoding(fileEncoding);
+
+ wxXmlNode* rootNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("richtext"));
+ doc->SetRoot(rootNode);
+ rootNode->AddAttribute(wxT("version"), wxT("1.0.0.0"));
+ rootNode->AddAttribute(wxT("xmlns"), wxT("http://www.wxwidgets.org"));
+
+ if (buffer->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
+ {
+ wxXmlNode* styleSheetNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("stylesheet"));
+ rootNode->AddChild(styleSheetNode);
+
+ wxString nameAndDescr;
+
+ if (!buffer->GetStyleSheet()->GetName().empty())
+ styleSheetNode->AddAttribute(wxT("name"), buffer->GetStyleSheet()->GetName());
+
+ if (!buffer->GetStyleSheet()->GetDescription().empty())
+ styleSheetNode->AddAttribute(wxT("description"), buffer->GetStyleSheet()->GetDescription());
+
+ int i;
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetCharacterStyleCount(); i++)
+ {
+ wxRichTextCharacterStyleDefinition* def = buffer->GetStyleSheet()->GetCharacterStyle(i);
+ ExportStyleDefinition(styleSheetNode, def);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetParagraphStyleCount(); i++)
+ {
+ wxRichTextParagraphStyleDefinition* def = buffer->GetStyleSheet()->GetParagraphStyle(i);
+ ExportStyleDefinition(styleSheetNode, def);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetListStyleCount(); i++)
+ {
+ wxRichTextListStyleDefinition* def = buffer->GetStyleSheet()->GetListStyle(i);
+ ExportStyleDefinition(styleSheetNode, def);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetBoxStyleCount(); i++)
+ {
+ wxRichTextBoxStyleDefinition* def = buffer->GetStyleSheet()->GetBoxStyle(i);
+ ExportStyleDefinition(styleSheetNode, def);
+ }
+ }
+ bool success = ExportXML(rootNode, *buffer);
+#if wxRICHTEXT_USE_OUTPUT_TIMINGS
+ long t = stopwatch.Time();
+ wxLogDebug(wxT("Creating the document took %ldms"), t);
+ wxMessageBox(wxString::Format(wxT("Creating the document took %ldms"), t));
+#endif
+ if (success)
+ {
+#if wxRICHTEXT_USE_OUTPUT_TIMINGS
+ wxStopWatch s2;
+#endif
+ success = doc->Save(stream);
+#if wxRICHTEXT_USE_OUTPUT_TIMINGS
+ long t2 = s2.Time();
+ wxLogDebug(wxT("Save() took %ldms"), t2);
+ wxMessageBox(wxString::Format(wxT("Save() took %ldms"), t2));
+#endif
+ }
+ delete doc;
+ doc = NULL;
+
+#else
+ // !(wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT && wxRICHTEXT_USE_XMLDOCUMENT_OUTPUT)
+
+#if !wxUSE_UNICODE
+ m_convMem = wxConvCurrent;
+#else
+ m_convMem = NULL;
+#endif
+
+ wxString s ;
+ s.Printf(wxT("<?xml version=\"%s\" encoding=\"%s\"?>\n"),
+ version, fileEncoding);
+ OutputString(stream, s);
+ OutputString(stream, wxT("<richtext version=\"1.0.0.0\" xmlns=\"http://www.wxwidgets.org\">"));
+
+ int level = 1;
+
+ if (buffer->GetStyleSheet() && (GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
+ {
+ OutputIndentation(stream, level);
+ wxString nameAndDescr;
+ if (!buffer->GetStyleSheet()->GetName().empty())
+ nameAndDescr << wxT(" name=\"") << buffer->GetStyleSheet()->GetName() << wxT("\"");
+ if (!buffer->GetStyleSheet()->GetDescription().empty())
+ nameAndDescr << wxT(" description=\"") << buffer->GetStyleSheet()->GetDescription() << wxT("\"");
+ OutputString(stream, wxString(wxT("<stylesheet")) + nameAndDescr + wxT(">"));
+
+ int i;
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetCharacterStyleCount(); i++)
+ {
+ wxRichTextCharacterStyleDefinition* def = buffer->GetStyleSheet()->GetCharacterStyle(i);
+ ExportStyleDefinition(stream, def, level + 1);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetParagraphStyleCount(); i++)
+ {
+ wxRichTextParagraphStyleDefinition* def = buffer->GetStyleSheet()->GetParagraphStyle(i);
+ ExportStyleDefinition(stream, def, level + 1);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetListStyleCount(); i++)
+ {
+ wxRichTextListStyleDefinition* def = buffer->GetStyleSheet()->GetListStyle(i);
+ ExportStyleDefinition(stream, def, level + 1);
+ }
+
+ for (i = 0; i < (int) buffer->GetStyleSheet()->GetBoxStyleCount(); i++)
+ {
+ wxRichTextBoxStyleDefinition* def = buffer->GetStyleSheet()->GetBoxStyle(i);
+ ExportStyleDefinition(stream, def, level + 1);
+ }
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</stylesheet>"));
+ }
+
+
+ bool success = ExportXML(stream, *buffer, level);
+
+ OutputString(stream, wxT("\n</richtext>"));
+ OutputString(stream, wxT("\n"));
+
+ if (deleteConvFile)
+ delete m_convFile;
+ m_convFile = NULL;
+ m_convMem = NULL;
+#endif
+
+ return success;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+
+/// Recursively export an object
+bool wxRichTextXMLHandler::ExportXML(wxOutputStream& stream, wxRichTextObject& obj, int indent)
+{
+ obj.ExportXML(stream, indent, this);
+
+ return true;
+}
+
+bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichTextStyleDefinition* def, int level)
+{
+ wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
+ wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
+ wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
+ wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition);
+
+ wxString name = def->GetName();
+ wxString nameProp;
+ if (!name.empty())
+ nameProp = wxT(" name=\"") + AttributeToXML(name) + wxT("\"");
+
+ wxString baseStyle = def->GetBaseStyle();
+ wxString baseStyleProp;
+ if (!baseStyle.empty())
+ baseStyleProp = wxT(" basestyle=\"") + AttributeToXML(baseStyle) + wxT("\"");
+
+ wxString descr = def->GetDescription();
+ wxString descrProp;
+ if (!descr.empty())
+ descrProp = wxT(" description=\"") + AttributeToXML(descr) + wxT("\"");
+
+ if (charDef)
+ {
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<characterstyle") + nameProp + baseStyleProp + descrProp + wxT(">"));
+
+ level ++;
+
+ wxString style = AddAttributes(def->GetStyle(), false);
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<style ") + style + wxT(">"));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</style>"));
+
+ level --;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</characterstyle>"));
+ }
+ else if (listDef)
+ {
+ OutputIndentation(stream, level);
+
+ if (!listDef->GetNextStyle().empty())
+ baseStyleProp << wxT(" nextstyle=\"") << AttributeToXML(listDef->GetNextStyle()) << wxT("\"");
+
+ OutputString(stream, wxT("<liststyle") + nameProp + baseStyleProp + descrProp + wxT(">"));
+
+ level ++;
+
+ wxString style = AddAttributes(def->GetStyle(), true);
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<style ") + style + wxT(">"));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</style>"));
+
+ int i;
+ for (i = 0; i < 10; i ++)
+ {
+ wxRichTextAttr* levelAttr = listDef->GetLevelAttributes(i);
+ if (levelAttr)
+ {
+ wxString style = AddAttributes(def->GetStyle(), true);
+ wxString levelStr = wxString::Format(wxT(" level=\"%d\" "), (i+1));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<style ") + levelStr + style + wxT(">"));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</style>"));
+ }
+ }
+
+ level --;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</liststyle>"));
+ }
+ else if (paraDef)
+ {
+ OutputIndentation(stream, level);
+
+ if (!paraDef->GetNextStyle().empty())
+ baseStyleProp << wxT(" nextstyle=\"") << AttributeToXML(paraDef->GetNextStyle()) << wxT("\"");
+
+ OutputString(stream, wxT("<paragraphstyle") + nameProp + baseStyleProp + descrProp + wxT(">"));
+
+ level ++;
+
+ wxString style = AddAttributes(def->GetStyle(), true);
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<style ") + style + wxT(">"));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</style>"));
+
+ level --;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</paragraphstyle>"));
+ }
+ else if (boxDef)
+ {
+ OutputIndentation(stream, level);
+
+ OutputString(stream, wxT("<boxstyle") + nameProp + baseStyleProp + descrProp + wxT(">"));
+
+ level ++;
+
+ wxString style = AddAttributes(def->GetStyle(), true);
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<style ") + style + wxT(">"));
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</style>"));
+
+ level --;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</boxstyle>"));
+ }
+
+
+ return true;
+}
+
+/// Create a string containing style attributes
+wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool isPara)
+{
+ wxString str;
+ if (attr.HasTextColour() && attr.GetTextColour().IsOk())
+ AddAttribute(str, wxT("textcolor"), attr.GetTextColour());
+
+ if (attr.HasBackgroundColour() && attr.GetBackgroundColour().IsOk())
+ AddAttribute(str, wxT("bgcolor"), attr.GetBackgroundColour());
+
+ if (attr.HasFontSize())
+ AddAttribute(str, wxT("fontsize"), attr.GetFontSize());
+
+ if (attr.HasFontFamily())
+ AddAttribute(str, wxT("fontfamily"), attr.GetFontFamily());
+
+ if (attr.HasFontItalic())
+ AddAttribute(str, wxT("fontstyle"), attr.GetFontStyle());
+
+ if (attr.HasFontWeight())
+ AddAttribute(str, wxT("fontweight"), attr.GetFontWeight());
+
+ if (attr.HasFontUnderlined())
+ AddAttribute(str, wxT("fontunderlined"), (int) attr.GetFontUnderlined());
+
+ if (attr.HasFontFaceName())
+ AddAttribute(str, wxT("fontface"), AttributeToXML(attr.GetFontFaceName()));
+
+ if (attr.HasTextEffects())
+ {
+ AddAttribute(str, wxT("texteffects"), attr.GetTextEffects());
+ AddAttribute(str, wxT("texteffectflags"), attr.GetTextEffectFlags());
+ }
+
+ if (!attr.GetCharacterStyleName().empty())
+ AddAttribute(str, wxT("characterstyle"), AttributeToXML(attr.GetCharacterStyleName()));
+
+ if (attr.HasURL())
+ AddAttribute(str, wxT("url"), AttributeToXML(attr.GetURL()));
+
+ if (isPara)
+ {
+ if (attr.HasAlignment())
+ AddAttribute(str, wxT("alignment"), (int) attr.GetAlignment());
+
+ if (attr.HasLeftIndent())
+ {
+ AddAttribute(str, wxT("leftindent"), (int) attr.GetLeftIndent());
+ AddAttribute(str, wxT("leftsubindent"), (int) attr.GetLeftSubIndent());
+ }
+
+ if (attr.HasRightIndent())
+ AddAttribute(str, wxT("rightindent"), (int) attr.GetRightIndent());
+
+ if (attr.HasParagraphSpacingAfter())
+ AddAttribute(str, wxT("parspacingafter"), (int) attr.GetParagraphSpacingAfter());
+
+ if (attr.HasParagraphSpacingBefore())
+ AddAttribute(str, wxT("parspacingbefore"), (int) attr.GetParagraphSpacingBefore());
+
+ if (attr.HasLineSpacing())
+ AddAttribute(str, wxT("linespacing"), (int) attr.GetLineSpacing());
+
+ if (attr.HasBulletStyle())
+ AddAttribute(str, wxT("bulletstyle"), (int) attr.GetBulletStyle());
+
+ if (attr.HasBulletNumber())
+ AddAttribute(str, wxT("bulletnumber"), (int) attr.GetBulletNumber());
+
+ if (attr.HasBulletText())
+ {
+ // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
+ // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
+ if (!attr.GetBulletText().empty() && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL))
+ AddAttribute(str, wxT("bulletsymbol"), (int) (attr.GetBulletText()[0]));
+ else
+ AddAttribute(str, wxT("bullettext"), AttributeToXML(attr.GetBulletText()));
+
+ AddAttribute(str, wxT("bulletfont"), attr.GetBulletFont());
+ }
+
+ if (attr.HasBulletName())
+ AddAttribute(str, wxT("bulletname"), AttributeToXML(attr.GetBulletName()));
+
+ if (!attr.GetParagraphStyleName().empty())
+ AddAttribute(str, wxT("parstyle"), AttributeToXML(attr.GetParagraphStyleName()));
+
+ if (!attr.GetListStyleName().empty())
+ AddAttribute(str, wxT("liststyle"), AttributeToXML(attr.GetListStyleName()));
+
+ if (attr.HasTabs())
+ {
+ wxString strTabs;
+ size_t i;
+ for (i = 0; i < attr.GetTabs().GetCount(); i++)
+ {
+ if (i > 0) strTabs << wxT(",");
+ strTabs << attr.GetTabs()[i];
+ }
+ AddAttribute(str, wxT("tabs"), strTabs);
+ }
+
+ if (attr.HasPageBreak())
+ {
+ AddAttribute(str, wxT("pagebreak"), 1);
+ }
+
+ if (attr.HasOutlineLevel())
+ AddAttribute(str, wxT("outlinelevel"), (int) attr.GetOutlineLevel());
+ }
+
+ AddAttribute(str, wxT("margin"), attr.GetTextBoxAttr().GetMargins());
+ AddAttribute(str, wxT("padding"), attr.GetTextBoxAttr().GetPadding());
+ AddAttribute(str, wxT("position"), attr.GetTextBoxAttr().GetPosition());
+ AddAttribute(str, wxT("border"), attr.GetTextBoxAttr().GetBorder());
+ AddAttribute(str, wxT("outline"), attr.GetTextBoxAttr().GetOutline());
+ AddAttribute(str, wxT("width"), attr.GetTextBoxAttr().GetWidth());
+ AddAttribute(str, wxT("height"), attr.GetTextBoxAttr().GetHeight());
+
+ if (attr.GetTextBoxAttr().HasVerticalAlignment())
+ {
+ wxString value;
+ if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP)
+ value = wxT("top");
+ else if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE)
+ value = wxT("centre");
+ else if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM)
+ value = wxT("bottom");
+ else
+ value = wxT("none");
+ AddAttribute(str, wxT("verticalalignment"), value);
+ }
+
+ if (attr.GetTextBoxAttr().HasFloatMode())
+ {
+ wxString value;
+ if (attr.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_LEFT)
+ value = wxT("left");
+ else if (attr.GetTextBoxAttr().GetFloatMode() == wxTEXT_BOX_ATTR_FLOAT_RIGHT)
+ value = wxT("right");
+ else
+ value = wxT("none");
+ AddAttribute(str, wxT("float"), value);
+ }
+
+ if (attr.GetTextBoxAttr().HasClearMode())
+ {
+ wxString value;
+ if (attr.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_LEFT)
+ value = wxT("left");
+ else if (attr.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_RIGHT)
+ value = wxT("right");
+ else if (attr.GetTextBoxAttr().GetClearMode() == wxTEXT_BOX_ATTR_CLEAR_BOTH)
+ value = wxT("both");
+ else
+ value = wxT("none");
+ AddAttribute(str, wxT("clear"), value);
+ }
+
+ if (attr.GetTextBoxAttr().HasCollapseBorders())
+ AddAttribute(str, wxT("collapse-borders"), (int) attr.GetTextBoxAttr().GetCollapseBorders());
+
+ return str;
+}
+
+// Make a string from the given property. This can be overridden for custom variants.
+wxString wxRichTextXMLHandler::MakeStringFromProperty(const wxVariant& var)
+{
+ return var.MakeString();
+}
+
+// Create a proprty from the string read from the XML file.
+wxVariant wxRichTextXMLHandler::MakePropertyFromString(const wxString& name, const wxString& value, const wxString& WXUNUSED(type))
+{
+ wxVariant var(value, name);
+ // TODO: use type to create using common types
+ return var;
+}
+
+// Write the properties
+bool wxRichTextXMLHandler::WriteProperties(wxOutputStream& stream, const wxRichTextProperties& properties, int level)
+{
+ if (properties.GetCount() > 0)
+ {
+ level ++;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<properties"));
+
+ level ++;
+
+ size_t i;
+ for (i = 0; i < properties.GetCount(); i++)
+ {
+ const wxVariant& var = properties[i];
+ if (!var.IsNull())
+ {
+ const wxString& name = var.GetName();
+ wxString value = MakeStringFromProperty(var);
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("<property name=\"") + name +
+ wxT("\" type=\"") + var.GetType() + wxT("\" value=\""));
+ OutputStringEnt(stream, value);
+ OutputString(stream, wxT("\"/>\n"));
+ }
+ }
+
+ level --;
+
+ OutputIndentation(stream, level);
+ OutputString(stream, wxT("</properties>\n"));
+
+ level --;
+ }
+
+ return true;
+}
+
+
+#endif
+ // wxRICHTEXT_HAVE_DIRECT_OUTPUT
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
+bool wxRichTextXMLHandler::ExportXML(wxXmlNode* parent, wxRichTextObject& obj)
+{
+ obj.ExportXML(parent, this);
+
+ return true;
+}
+
+bool wxRichTextXMLHandler::ExportStyleDefinition(wxXmlNode* parent, wxRichTextStyleDefinition* def)
+{
+ wxRichTextCharacterStyleDefinition* charDef = wxDynamicCast(def, wxRichTextCharacterStyleDefinition);
+ wxRichTextParagraphStyleDefinition* paraDef = wxDynamicCast(def, wxRichTextParagraphStyleDefinition);
+ wxRichTextBoxStyleDefinition* boxDef = wxDynamicCast(def, wxRichTextBoxStyleDefinition);
+ wxRichTextListStyleDefinition* listDef = wxDynamicCast(def, wxRichTextListStyleDefinition);
+
+ wxString baseStyle = def->GetBaseStyle();
+ wxString descr = def->GetDescription();
+
+ wxXmlNode* defNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxEmptyString);
+ parent->AddChild(defNode);
+ if (!baseStyle.empty())
+ defNode->AddAttribute(wxT("basestyle"), baseStyle);
+ if (!descr.empty())
+ defNode->AddAttribute(wxT("description"), descr);
+
+ wxXmlNode* styleNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("style"));
+ defNode->AddChild(styleNode);
+
+ if (charDef)
+ {
+ defNode->SetName(wxT("characterstyle"));
+ AddAttributes(styleNode, def->GetStyle(), false);
+ }
+ else if (listDef)
+ {
+ defNode->SetName(wxT("liststyle"));
+
+ if (!listDef->GetNextStyle().empty())
+ defNode->AddAttribute(wxT("nextstyle"), listDef->GetNextStyle());
+
+ AddAttributes(styleNode, def->GetStyle(), true);
+
+ int i;
+ for (i = 0; i < 10; i ++)
+ {
+ wxRichTextAttr* levelAttr = listDef->GetLevelAttributes(i);
+ if (levelAttr)
+ {
+ wxXmlNode* levelNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("style"));
+ defNode->AddChild(levelNode);
+ levelNode->AddAttribute(wxT("level"), MakeString(i+1));
+ AddAttributes(levelNode, * levelAttr, true);
+ }
+ }
+ }
+ else if (boxDef)
+ {
+ defNode->SetName(wxT("boxstyle"));
+
+ AddAttributes(styleNode, def->GetStyle(), true);
+ }
+ else if (paraDef)
+ {
+ defNode->SetName(wxT("paragraphstyle"));
+
+ if (!paraDef->GetNextStyle().empty())
+ defNode->AddAttribute(wxT("nextstyle"), paraDef->GetNextStyle());
+
+ AddAttributes(styleNode, def->GetStyle(), true);
+ }
+
+ return true;
+}
+
+bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, bool isPara)
+{
+ if (attr.HasTextColour() && attr.GetTextColour().IsOk())
+ node->AddAttribute(wxT("textcolor"), MakeString(attr.GetTextColour()));
+ if (attr.HasBackgroundColour() && attr.GetBackgroundColour().IsOk())
+ node->AddAttribute(wxT("bgcolor"), MakeString(attr.GetBackgroundColour()));
+
+ if (attr.HasFontSize())
+ node->AddAttribute(wxT("fontsize"), MakeString(attr.GetFontSize()));
+ if (attr.HasFontFamily())
+ node->AddAttribute(wxT("fontfamily"), MakeString(attr.GetFontFamily()));
+ if (attr.HasFontItalic())
+ node->AddAttribute(wxT("fontstyle"), MakeString(attr.GetFontStyle()));
+ if (attr.HasFontWeight())
+ node->AddAttribute(wxT("fontweight"), MakeString(attr.GetFontWeight()));
+ if (attr.HasFontUnderlined())
+ node->AddAttribute(wxT("fontunderlined"), MakeString((int) attr.GetFontUnderlined()));
+ if (attr.HasFontFaceName())
+ node->AddAttribute(wxT("fontface"), attr.GetFontFaceName());
+
+ if (attr.HasTextEffects())
+ {
+ node->AddAttribute(wxT("texteffects"), MakeString(attr.GetTextEffects()));
+ node->AddAttribute(wxT("texteffectflags"), MakeString(attr.GetTextEffectFlags()));
+ }
+ if (attr.HasCharacterStyleName() && !attr.GetCharacterStyleName().empty())
+ node->AddAttribute(wxT("characterstyle"), attr.GetCharacterStyleName());
+
+ if (attr.HasURL())
+ node->AddAttribute(wxT("url"), attr.GetURL()); // TODO: do we need to wrap this in AttributeToXML?
+
+ if (isPara)
+ {
+ if (attr.HasAlignment())
+ node->AddAttribute(wxT("alignment"), MakeString((int) attr.GetAlignment()));
+
+ if (attr.HasLeftIndent())
+ {
+ node->AddAttribute(wxT("leftindent"), MakeString((int) attr.GetLeftIndent()));
+ node->AddAttribute(wxT("leftsubindent"), MakeString((int) attr.GetLeftSubIndent()));
+ }
+
+ if (attr.HasRightIndent())
+ node->AddAttribute(wxT("rightindent"), MakeString((int) attr.GetRightIndent()));
+
+ if (attr.HasParagraphSpacingAfter())
+ node->AddAttribute(wxT("parspacingafter"), MakeString((int) attr.GetParagraphSpacingAfter()));
+
+ if (attr.HasParagraphSpacingBefore())
+ node->AddAttribute(wxT("parspacingbefore"), MakeString((int) attr.GetParagraphSpacingBefore()));
+
+ if (attr.HasLineSpacing())
+ node->AddAttribute(wxT("linespacing"), MakeString((int) attr.GetLineSpacing()));
+
+ if (attr.HasBulletStyle())
+ node->AddAttribute(wxT("bulletstyle"), MakeString((int) attr.GetBulletStyle()));
+
+ if (attr.HasBulletNumber())
+ node->AddAttribute(wxT("bulletnumber"), MakeString((int) attr.GetBulletNumber()));
+
+ if (attr.HasBulletText())
+ {
+ // If using a bullet symbol, convert to integer in case it's a non-XML-friendly character.
+ // Otherwise, assume it's XML-friendly text such as outline numbering, e.g. 1.2.3.1
+ if (!attr.GetBulletText().empty() && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL))
+ node->AddAttribute(wxT("bulletsymbol"), MakeString((int) (attr.GetBulletText()[0])));
+ else
+ node->AddAttribute(wxT("bullettext"), attr.GetBulletText());
+
+ if (!attr.GetBulletFont().empty())
+ node->AddAttribute(wxT("bulletfont"), attr.GetBulletFont());
+ }
+
+ if (attr.HasBulletName())
+ node->AddAttribute(wxT("bulletname"), attr.GetBulletName());
+
+ if (!attr.GetParagraphStyleName().empty())
+ node->AddAttribute(wxT("parstyle"), attr.GetParagraphStyleName());
+
+ if (!attr.GetListStyleName().empty())
+ node->AddAttribute(wxT("liststyle"), attr.GetListStyleName());
+
+ if (attr.HasTabs())
+ {
+ wxString tabs;
+ size_t i;
+ for (i = 0; i < attr.GetTabs().GetCount(); i++)
+ {
+ if (i > 0)
+ tabs << wxT(",");
+ tabs << attr.GetTabs()[i];
+ }
+ node->AddAttribute(wxT("tabs"), tabs);
+ }
+
+ if (attr.HasPageBreak())
+ node->AddAttribute(wxT("pagebreak"), wxT("1"));
+
+ if (attr.HasOutlineLevel())
+ node->AddAttribute(wxT("outlinelevel"), MakeString((int) attr.GetOutlineLevel()));
+ }
+
+ AddAttribute(node, wxT("margin"), attr.GetTextBoxAttr().GetMargins());
+ AddAttribute(node, wxT("padding"), attr.GetTextBoxAttr().GetPadding());
+ AddAttribute(node, wxT("position"), attr.GetTextBoxAttr().GetPosition());
+ AddAttribute(node, wxT("border"), attr.GetTextBoxAttr().GetBorder());
+ AddAttribute(node, wxT("outline"), attr.GetTextBoxAttr().GetOutline());
+ AddAttribute(node, wxT("width"), attr.GetTextBoxAttr().GetWidth());
+ AddAttribute(node, wxT("height"), attr.GetTextBoxAttr().GetHeight());
+
+ if (attr.GetTextBoxAttr().HasVerticalAlignment())
+ {
+ wxString value;
+ if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP)
+ value = wxT("top");
+ else if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE)
+ value = wxT("centre");
+ else if (attr.GetTextBoxAttr().GetVerticalAlignment() == wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM)
+ value = wxT("bottom");