+ else if (facename == wxT("Courier"))
+ {
+ facename = wxT("Courier New");
+ return true;
+ }
+ else
+ return false;
+#else
+ if (facename == wxT("Times New Roman"))
+ {
+ facename = wxT("Times");
+ return true;
+ }
+ else if (facename == wxT("Arial"))
+ {
+ facename = wxT("Helvetica");
+ return true;
+ }
+ else if (facename == wxT("Courier New"))
+ {
+ facename = wxT("Courier");
+ return true;
+ }
+ else
+ return false;
+#endif
+}
+
+static inline long wxRichTextColourStringToLong(const wxString& colStr)
+{
+ if (!colStr.IsEmpty())
+ {
+ wxColour col(colStr);
+ return col.GetRGB();
+ }
+ else
+ return 0;
+}
+
+static inline wxTextAttrDimension wxRichTextParseDimension(const wxString& dimStr)
+{
+ wxString valuePart = dimStr.BeforeFirst(wxT(','));
+ wxString flagsPart;
+ if (dimStr.Contains(wxT(",")))
+ flagsPart = dimStr.AfterFirst(wxT(','));
+ wxTextAttrDimension dim;
+ dim.SetValue(wxAtoi(valuePart));
+ dim.SetFlags(wxAtoi(flagsPart));
+
+ return dim;
+}
+
+/// Import style parameters
+bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara)
+{
+ wxXmlAttribute* xmlAttr = node->GetAttributes();
+ bool found;
+ while (xmlAttr)
+ {
+ const wxString& name = xmlAttr->GetName();
+ const wxString& value = xmlAttr->GetValue();
+ found = true;
+
+ if (name == wxT("fontface"))
+ {
+ if (!value.empty())
+ {
+ wxString v = value;
+ if (GetFlags() & wxRICHTEXT_HANDLER_CONVERT_FACENAMES)
+ wxRichTextFixFaceName(v);
+ attr.SetFontFaceName(v);
+ }
+ }
+ else if (name == wxT("fontfamily"))
+ {
+ if (!value.empty())
+ attr.SetFontFamily((wxFontFamily)wxAtoi(value));
+ }
+ else if (name == wxT("fontstyle"))
+ {
+ if (!value.empty())
+ attr.SetFontStyle((wxFontStyle)wxAtoi(value));
+ }
+ else if (name == wxT("fontsize") || name == wxT("fontpointsize"))
+ {
+ if (!value.empty())
+ attr.SetFontPointSize(wxAtoi(value));
+ }
+ else if (name == wxT("fontpixelsize"))
+ {
+ if (!value.empty())
+ attr.SetFontPixelSize(wxAtoi(value));
+ }
+ else if (name == wxT("fontweight"))
+ {
+ if (!value.empty())
+ attr.SetFontWeight((wxFontWeight) wxAtoi(value));
+ }
+ else if (name == wxT("fontunderlined"))
+ {
+ if (!value.empty())
+ attr.SetFontUnderlined(wxAtoi(value) != 0);
+ }
+ else if (name == wxT("textcolor"))
+ {
+ if (!value.empty())
+ {
+ if (value[0] == wxT('#'))
+ attr.SetTextColour(HexStringToColour(value.Mid(1)));
+ else
+ attr.SetTextColour(value);
+ }
+ }
+ else if (name == wxT("bgcolor"))
+ {
+ if (!value.empty())
+ {
+ if (value[0] == wxT('#'))
+ attr.SetBackgroundColour(HexStringToColour(value.Mid(1)));
+ else
+ attr.SetBackgroundColour(value);
+ }
+ }
+ else if (name == wxT("characterstyle"))
+ {
+ if (!value.empty())
+ attr.SetCharacterStyleName(value);
+ }
+ else if (name == wxT("texteffects"))
+ {
+ if (!value.empty())
+ attr.SetTextEffects(wxAtoi(value));
+ }
+ else if (name == wxT("texteffectflags"))
+ {
+ if (!value.empty())
+ attr.SetTextEffectFlags(wxAtoi(value));
+ }
+ else if (name == wxT("url"))
+ {
+ if (!value.empty())
+ attr.SetURL(value);
+ }
+ else if (isPara)
+ {
+ if (name == wxT("alignment"))
+ {
+ if (!value.empty())
+ attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
+ }
+ else if (name == wxT("leftindent"))
+ {
+ if (!value.empty())
+ attr.SetLeftIndent(wxAtoi(value), attr.GetLeftSubIndent());
+ }
+ else if (name == wxT("leftsubindent"))
+ {
+ if (!value.empty())
+ attr.SetLeftIndent(attr.GetLeftIndent(), wxAtoi(value));
+ }
+ else if (name == wxT("rightindent"))
+ {
+ if (!value.empty())
+ attr.SetRightIndent(wxAtoi(value));
+ }
+ else if (name == wxT("parspacingbefore"))
+ {
+ if (!value.empty())
+ attr.SetParagraphSpacingBefore(wxAtoi(value));
+ }
+ else if (name == wxT("parspacingafter"))
+ {
+ if (!value.empty())
+ attr.SetParagraphSpacingAfter(wxAtoi(value));
+ }
+ else if (name == wxT("linespacing"))
+ {
+ if (!value.empty())
+ attr.SetLineSpacing(wxAtoi(value));
+ }
+ else if (name == wxT("bulletstyle"))
+ {
+ if (!value.empty())
+ attr.SetBulletStyle(wxAtoi(value));
+ }
+ else if (name == wxT("bulletnumber"))
+ {
+ if (!value.empty())
+ attr.SetBulletNumber(wxAtoi(value));
+ }
+ else if (name == wxT("bulletsymbol"))
+ {
+ if (!value.empty())
+ {
+ wxChar ch = wxAtoi(value);
+ wxString s;
+ s << ch;
+ attr.SetBulletText(s);
+ }
+ }
+ else if (name == wxT("bullettext"))
+ {
+ if (!value.empty())
+ {
+ attr.SetBulletText(value);
+ }
+ }
+ else if (name == wxT("bulletfont"))
+ {
+ if (!value.empty())
+ {
+ attr.SetBulletFont(value);
+ }
+ }
+ else if (name == wxT("bulletname"))
+ {
+ if (!value.empty())
+ {
+ attr.SetBulletName(value);
+ }
+ }
+ else if (name == wxT("parstyle"))
+ {
+ if (!value.empty())
+ {
+ attr.SetParagraphStyleName(value);
+ }
+ }
+ else if (name == wxT("liststyle"))
+ {
+ if (!value.empty())
+ {
+ attr.SetListStyleName(value);
+ }
+ }
+ else if (name == wxT("boxstyle"))
+ {
+ if (!value.empty())
+ {
+ attr.GetTextBoxAttr().SetBoxStyleName(value);
+ }
+ }
+ else if (name == wxT("tabs"))
+ {
+ if (!value.empty())
+ {
+ wxArrayInt tabs;
+ wxStringTokenizer tkz(value, wxT(","));
+ while (tkz.HasMoreTokens())
+ {
+ wxString token = tkz.GetNextToken();
+ tabs.Add(wxAtoi(token));
+ }
+ attr.SetTabs(tabs);
+ }
+ }
+ else if (name == wxT("pagebreak"))
+ {
+ if (!value.empty())
+ {
+ attr.SetPageBreak(wxAtoi(value) != 0);
+ }
+ }
+ else if (name == wxT("outlinelevel"))
+ {
+ if (!value.empty())
+ {
+ attr.SetOutlineLevel(wxAtoi(value));
+ }
+ }
+ else
+ found = false;
+ }
+ else
+ found = false;
+
+ if (!found)
+ {
+ // Box attributes
+
+ if (name == wxT("width"))
+ {
+ attr.GetTextBoxAttr().GetWidth().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name == wxT("height"))
+ {
+ attr.GetTextBoxAttr().GetHeight().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name == wxT("minwidth"))
+ {
+ attr.GetTextBoxAttr().GetMinSize().GetWidth().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name == wxT("minheight"))
+ {
+ attr.GetTextBoxAttr().GetMinSize().GetHeight().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name == wxT("maxwidth"))
+ {
+ attr.GetTextBoxAttr().GetMaxSize().GetWidth().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name == wxT("maxheight"))
+ {
+ attr.GetTextBoxAttr().GetMaxSize().GetHeight().SetValue(wxRichTextParseDimension(value));
+ }
+
+ else if (name == wxT("verticalalignment"))
+ {
+ if (value == wxT("top"))
+ attr.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_TOP);
+ else if (value == wxT("centre"))
+ attr.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_CENTRE);
+ else if (value == wxT("bottom"))
+ attr.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_BOTTOM);
+ else if (value == wxT("none"))
+ attr.GetTextBoxAttr().SetVerticalAlignment(wxTEXT_BOX_ATTR_VERTICAL_ALIGNMENT_NONE);
+ }
+ else if (name == wxT("float"))
+ {
+ if (value == wxT("left"))
+ attr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_LEFT);
+ else if (value == wxT("right"))
+ attr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_RIGHT);
+ else if (value == wxT("none"))
+ attr.GetTextBoxAttr().SetFloatMode(wxTEXT_BOX_ATTR_FLOAT_NONE);
+ }
+ else if (name == wxT("clear"))
+ {
+ if (value == wxT("left"))
+ attr.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_LEFT);
+ else if (value == wxT("right"))
+ attr.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_RIGHT);
+ else if (value == wxT("both"))
+ attr.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_BOTH);
+ else if (value == wxT("none"))
+ attr.GetTextBoxAttr().SetClearMode(wxTEXT_BOX_ATTR_CLEAR_NONE);
+ }
+ else if (name == wxT("collapse-borders"))
+ attr.GetTextBoxAttr().SetCollapseBorders((wxTextBoxAttrCollapseMode) wxAtoi(value));
+
+ else if (name.Contains(wxT("border-")))
+ {
+ if (name == wxT("border-left-style"))
+ attr.GetTextBoxAttr().GetBorder().GetLeft().SetStyle(wxAtoi(value));
+ else if (name == wxT("border-right-style"))
+ attr.GetTextBoxAttr().GetBorder().GetRight().SetStyle(wxAtoi(value));
+ else if (name == wxT("border-top-style"))
+ attr.GetTextBoxAttr().GetBorder().GetTop().SetStyle(wxAtoi(value));
+ else if (name == wxT("border-bottom-style"))
+ attr.GetTextBoxAttr().GetBorder().GetBottom().SetStyle(wxAtoi(value));
+
+ else if (name == wxT("border-left-colour"))
+ attr.GetTextBoxAttr().GetBorder().GetLeft().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("border-right-colour"))
+ attr.GetTextBoxAttr().GetBorder().GetRight().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("border-top-colour"))
+ attr.GetTextBoxAttr().GetBorder().GetTop().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("border-bottom-colour"))
+ attr.GetTextBoxAttr().GetBorder().GetBottom().SetColour(wxRichTextColourStringToLong(value));
+
+ else if (name == wxT("border-left-width"))
+ attr.GetTextBoxAttr().GetBorder().GetLeft().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("border-right-width"))
+ attr.GetTextBoxAttr().GetBorder().GetRight().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("border-top-width"))
+ attr.GetTextBoxAttr().GetBorder().GetTop().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("border-bottom-width"))
+ attr.GetTextBoxAttr().GetBorder().GetBottom().SetWidth(wxRichTextParseDimension(value));
+ }
+ else if (name.Contains(wxT("outline-")))
+ {
+ if (name == wxT("outline-left-style"))
+ attr.GetTextBoxAttr().GetOutline().GetLeft().SetStyle(wxAtoi(value));
+ else if (name == wxT("outline-right-style"))
+ attr.GetTextBoxAttr().GetOutline().GetRight().SetStyle(wxAtoi(value));
+ else if (name == wxT("outline-top-style"))
+ attr.GetTextBoxAttr().GetOutline().GetTop().SetStyle(wxAtoi(value));
+ else if (name == wxT("outline-bottom-style"))
+ attr.GetTextBoxAttr().GetOutline().GetBottom().SetStyle(wxAtoi(value));
+
+ else if (name == wxT("outline-left-colour"))
+ attr.GetTextBoxAttr().GetOutline().GetLeft().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("outline-right-colour"))
+ attr.GetTextBoxAttr().GetOutline().GetRight().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("outline-top-colour"))
+ attr.GetTextBoxAttr().GetOutline().GetTop().SetColour(wxRichTextColourStringToLong(value));
+ else if (name == wxT("outline-bottom-colour"))
+ attr.GetTextBoxAttr().GetOutline().GetBottom().SetColour(wxRichTextColourStringToLong(value));
+
+ else if (name == wxT("outline-left-width"))
+ attr.GetTextBoxAttr().GetOutline().GetLeft().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("outline-right-width"))
+ attr.GetTextBoxAttr().GetOutline().GetRight().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("outline-top-width"))
+ attr.GetTextBoxAttr().GetOutline().GetTop().SetWidth(wxRichTextParseDimension(value));
+ else if (name == wxT("outline-bottom-width"))
+ attr.GetTextBoxAttr().GetOutline().GetBottom().SetWidth(wxRichTextParseDimension(value));
+ }
+ else if (name.Contains(wxT("margin-")))
+ {
+ if (name == wxT("margin-left"))
+ attr.GetTextBoxAttr().GetMargins().GetLeft().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("margin-right"))
+ attr.GetTextBoxAttr().GetMargins().GetRight().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("margin-top"))
+ attr.GetTextBoxAttr().GetMargins().GetTop().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("margin-bottom"))
+ attr.GetTextBoxAttr().GetMargins().GetBottom().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name.Contains(wxT("padding-")))
+ {
+ if (name == wxT("padding-left"))
+ attr.GetTextBoxAttr().GetPadding().GetLeft().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("padding-right"))
+ attr.GetTextBoxAttr().GetPadding().GetRight().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("padding-top"))
+ attr.GetTextBoxAttr().GetPadding().GetTop().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("padding-bottom"))
+ attr.GetTextBoxAttr().GetPadding().GetBottom().SetValue(wxRichTextParseDimension(value));
+ }
+ else if (name.Contains(wxT("position-")))
+ {
+ if (name == wxT("position-left"))
+ attr.GetTextBoxAttr().GetPosition().GetLeft().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("position-right"))
+ attr.GetTextBoxAttr().GetPosition().GetRight().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("position-top"))
+ attr.GetTextBoxAttr().GetPosition().GetTop().SetValue(wxRichTextParseDimension(value));
+ else if (name == wxT("position-bottom"))
+ attr.GetTextBoxAttr().GetPosition().GetBottom().SetValue(wxRichTextParseDimension(value));
+ }
+ }
+
+ xmlAttr = xmlAttr->GetNext();
+ }
+
+ return true;
+}
+
+#endif
+ // wxUSE_STREAMS
+
+// Import this object from XML
+bool wxRichTextObject::ImportFromXML(wxRichTextBuffer* WXUNUSED(buffer), wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
+{
+ handler->ImportProperties(this, node);
+ handler->ImportStyle(GetAttributes(), node, UsesParagraphAttributes());
+
+ *recurse = true;
+
+ return true;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextObject::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
+{
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<") + GetXMLNodeName(), handler->GetConvMem(), handler->GetConvFile());
+
+ wxString style = handler->AddAttributes(GetAttributes(), true);
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ }
+
+ wxRichTextCompositeObject* composite = wxDynamicCast(this, wxRichTextCompositeObject);
+ if (composite)
+ {
+ size_t i;
+ for (i = 0; i < composite->GetChildCount(); i++)
+ {
+ wxRichTextObject* child = composite->GetChild(i);
+ child->ExportXML(stream, indent+1, handler);
+ }
+ }
+
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("</") + GetXMLNodeName() + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ return true;
+}
+#endif
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
+// Export this object to the given parent node, usually creating at least one child node.
+bool wxRichTextObject::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler)
+{
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, GetXMLNodeName());
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), true);
+ handler->WriteProperties(elementNode, GetProperties());
+
+ wxRichTextCompositeObject* composite = wxDynamicCast(this, wxRichTextCompositeObject);
+ if (composite)
+ {
+ size_t i;
+ for (i = 0; i < composite->GetChildCount(); i++)
+ {
+ wxRichTextObject* child = composite->GetChild(i);
+ child->ExportXML(elementNode, handler);
+ }
+ }
+ return true;
+}
+#endif
+
+
+// Import this object from XML
+bool wxRichTextPlainText::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
+{
+ wxRichTextObject::ImportFromXML(buffer, node, handler, recurse);
+
+ if (node->GetName() == wxT("text"))
+ {
+ wxString text;
+ wxXmlNode* textChild = node->GetChildren();
+ while (textChild)
+ {
+ if (textChild->GetType() == wxXML_TEXT_NODE ||
+ textChild->GetType() == wxXML_CDATA_SECTION_NODE)
+ {
+ wxString text2 = textChild->GetContent();
+
+ // Strip whitespace from end
+ if (!text2.empty() && text2[text2.length()-1] == wxT('\n'))
+ text2 = text2.Mid(0, text2.length()-1);
+
+ if (!text2.empty() && text2[0] == wxT('"'))
+ text2 = text2.Mid(1);
+ if (!text2.empty() && text2[text2.length()-1] == wxT('"'))
+ text2 = text2.Mid(0, text2.length() - 1);
+
+ text += text2;
+ }
+ textChild = textChild->GetNext();
+ }
+
+ SetText(text);
+ }
+ else if (node->GetName() == wxT("symbol"))
+ {
+ // This is a symbol that XML can't read in the normal way
+ wxString text;
+ wxXmlNode* textChild = node->GetChildren();
+ while (textChild)
+ {
+ if (textChild->GetType() == wxXML_TEXT_NODE ||
+ textChild->GetType() == wxXML_CDATA_SECTION_NODE)
+ {
+ wxString text2 = textChild->GetContent();
+ text += text2;
+ }
+ textChild = textChild->GetNext();
+ }
+
+ wxString actualText;
+ actualText << (wxChar) wxAtoi(text);
+ SetText(actualText);
+ }
+ else
+ return false;
+
+ return true;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextPlainText::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
+{
+ wxString style = handler->AddAttributes(GetAttributes(), false);
+
+ int i;
+ int last = 0;
+ const wxString& text = GetText();
+ int len = (int) text.Length();
+
+ if (len == 0)
+ {
+ i = 0;
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<text"), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
+ ::OutputString(stream, wxT("</text>"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ else for (i = 0; i < len; i++)
+ {
+#if wxUSE_UNICODE
+ int c = (int) text[i];
+#else
+ int c = (int) wxUChar(text[i]);
+#endif
+ if ((c < 32 || c == 34) && /* c != 9 && */ c != 10 && c != 13)
+ {
+ if (i > 0)
+ {
+ wxString fragment(text.Mid(last, i-last));
+ if (!fragment.empty())
+ {
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<text"), handler->GetConvMem(), handler->GetConvFile());
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
+ {
+ ::OutputString(stream, wxT("\""), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputStringEnt(stream, fragment, handler->GetConvMem(), handler->GetConvFile());
+ ::OutputString(stream, wxT("\""), handler->GetConvMem(), handler->GetConvFile());
+ }
+ else
+ ::OutputStringEnt(stream, fragment, handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
+ ::OutputString(stream, wxT("</text>"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ }
+
+
+ // Output this character as a number in a separate tag, because XML can't cope
+ // with entities below 32 except for 10 and 13
+ last = i + 1;
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<symbol"), handler->GetConvMem(), handler->GetConvFile());
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputString(stream, wxString::Format(wxT("%d"), c), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
+ ::OutputString(stream, wxT("</symbol>"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ }
+
+ wxString fragment;
+ if (last == 0)
+ fragment = text;
+ else
+ fragment = text.Mid(last, i-last);
+
+ if (last < len)
+ {
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<text"), handler->GetConvMem(), handler->GetConvFile());
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
+
+ if (!fragment.empty() && (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' ')))
+ {
+ ::OutputString(stream, wxT("\""), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputStringEnt(stream, fragment, handler->GetConvMem(), handler->GetConvFile());
+ ::OutputString(stream, wxT("\""), handler->GetConvMem(), handler->GetConvFile());
+ }
+ else
+ ::OutputStringEnt(stream, fragment, handler->GetConvMem(), handler->GetConvFile());
+
+ ::OutputString(stream, wxT("</text>"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ return true;
+}
+#endif
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
+// Export this object to the given parent node, usually creating at least one child node.
+bool wxRichTextPlainText::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler)
+{
+ int i;
+ int last = 0;
+ const wxString& text = GetText();
+ int len = (int) text.Length();
+
+ if (len == 0)
+ {
+ i = 0;
+
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("text"));
+ parent->AddChild(elementNode);
+
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
+ }
+ else for (i = 0; i < len; i++)
+ {
+#if wxUSE_UNICODE
+ int c = (int) text[i];
+#else
+ int c = (int) wxUChar(text[i]);
+#endif
+ if ((c < 32 || c == 34) && c != 10 && c != 13)
+ {
+ if (i > 0)
+ {
+ wxString fragment(text.Mid(last, i-last));
+ if (!fragment.empty())
+ {
+ // TODO: I'm assuming wxXmlDocument will output quotes if necessary
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("text"));
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
+
+ wxXmlNode* textNode = new wxXmlNode(wxXML_TEXT_NODE, wxT("text"));
+ elementNode->AddChild(textNode);
+
+ if (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' '))
+ fragment = wxT("\"") + fragment + wxT("\"");
+
+ textNode->SetContent(fragment);
+ }
+ }
+
+
+ // Output this character as a number in a separate tag, because XML can't cope
+ // with entities below 32 except for 10 and 13
+
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("symbol"));
+ parent->AddChild(elementNode);
+
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
+
+ wxXmlNode* textNode = new wxXmlNode(wxXML_TEXT_NODE, wxT("text"));
+ elementNode->AddChild(textNode);
+ textNode->SetContent(wxString::Format(wxT("%d"), c));
+
+ last = i + 1;
+ }
+ }
+
+ wxString fragment;
+ if (last == 0)
+ fragment = text;
+ else
+ fragment = text.Mid(last, i-last);
+
+ if (last < len)
+ {
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("text"));
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+
+ wxXmlNode* textNode = new wxXmlNode(wxXML_TEXT_NODE, wxT("text"));
+ elementNode->AddChild(textNode);
+
+ if (fragment[0] == wxT(' ') || fragment[fragment.length()-1] == wxT(' '))
+ fragment = wxT("\"") + fragment + wxT("\"");
+
+ textNode->SetContent(fragment);
+ }
+ return true;
+}
+#endif
+
+
+// Import this object from XML
+bool wxRichTextImage::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
+{
+ wxRichTextObject::ImportFromXML(buffer, node, handler, recurse);
+
+ wxBitmapType imageType = wxBITMAP_TYPE_PNG;
+ wxString value = node->GetAttribute(wxT("imagetype"), wxEmptyString);
+ if (!value.empty())
+ {
+ int type = wxAtoi(value);
+
+ // note: 0 == wxBITMAP_TYPE_INVALID
+ if (type <= 0 || type >= wxBITMAP_TYPE_MAX)
+ {
+ wxLogWarning("Invalid bitmap type specified for <image> tag: %d", type);
+ }
+ else
+ {
+ imageType = (wxBitmapType)type;
+ }
+ }
+
+ wxString data;
+
+ wxXmlNode* imageChild = node->GetChildren();
+ while (imageChild)
+ {
+ wxString childName = imageChild->GetName();
+ if (childName == wxT("data"))
+ {
+ wxXmlNode* dataChild = imageChild->GetChildren();
+ while (dataChild)
+ {
+ data = dataChild->GetContent();
+ // wxLogDebug(data);
+ dataChild = dataChild->GetNext();
+ }
+
+ }
+ imageChild = imageChild->GetNext();
+ }
+
+ if (!data.empty())
+ {
+ wxStringInputStream strStream(data);
+
+ GetImageBlock().ReadHex(strStream, data.length(), imageType);
+
+ return true;
+ }
+ else
+ return false;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextImage::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
+{
+ wxString style = handler->AddAttributes(GetAttributes(), false);
+
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("<image"), handler->GetConvMem(), handler->GetConvFile());
+ if (!GetImageBlock().IsOk())
+ {
+ // No data
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ else
+ {
+ ::OutputString(stream, wxString::Format(wxT(" imagetype=\"%d\""), (int) GetImageBlock().GetImageType()) + style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ }
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
+
+ ::OutputIndentation(stream, indent+1);
+ ::OutputString(stream, wxT("<data>"), handler->GetConvMem(), handler->GetConvFile());
+
+ // wxStopWatch stopwatch;
+
+ GetImageBlock().WriteHex(stream);
+
+ // wxLogDebug(wxT("Image conversion to hex took %ldms"), stopwatch.Time());
+
+ ::OutputString(stream, wxT("</data>\n"), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("</image>"), handler->GetConvMem(), handler->GetConvFile());
+ return true;
+}
+#endif
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
+// Export this object to the given parent node, usually creating at least one child node.
+bool wxRichTextImage::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler)
+{
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("image"));
+ parent->AddChild(elementNode);
+
+ if (GetImageBlock().IsOk())
+ elementNode->AddAttribute(wxT("imagetype"), MakeString((int) GetImageBlock().GetImageType()));
+
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
+
+ wxXmlNode* dataNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("data"));
+ elementNode->AddChild(dataNode);
+ wxXmlNode* textNode = new wxXmlNode(wxXML_TEXT_NODE, wxT("text"));
+ dataNode->AddChild(textNode);
+
+ wxString strData;
+#if 1
+ {
+ wxMemoryOutputStream stream;
+ if (GetImageBlock().WriteHex(stream))
+ {
+ if (stream.GetSize() > 0)
+ {
+ int size = stream.GetSize();
+#ifdef __WXDEBUG__
+ int size2 = stream.GetOutputStreamBuffer()->GetIntPosition();
+ wxASSERT(size == size2);
+#endif
+ unsigned char* data = new unsigned char[size];
+ stream.CopyTo(data, size);
+ strData = wxString((const char*) data, wxConvUTF8, size);
+ delete[] data;
+ }
+ else
+ strData = wxEmptyString;
+ }
+
+ }
+#else
+ {
+ wxStringOutputStream strStream(& strData);
+ GetImageBlock().WriteHex(strStream);
+ }
+#endif
+
+ textNode->SetContent(strData);
+ textNode->SetNoConversion(true); // optimize speed
+
+ return true;
+}
+#endif
+
+
+// Import this object from XML
+bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
+{
+ wxRichTextObject::ImportFromXML(buffer, node, handler, recurse);
+
+ *recurse = true;
+
+ wxString partial = node->GetAttribute(wxT("partialparagraph"), wxEmptyString);
+ if (partial == wxT("true"))
+ SetPartialParagraph(true);
+
+ wxXmlNode* child = wxRichTextXMLHandler::FindNode(node, wxT("stylesheet"));
+ if (child && (handler->GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
+ {
+ wxRichTextStyleSheet* sheet = new wxRichTextStyleSheet;
+ wxString sheetName = child->GetAttribute(wxT("name"), wxEmptyString);
+ wxString sheetDescription = child->GetAttribute(wxT("description"), wxEmptyString);
+ sheet->SetName(sheetName);
+ sheet->SetDescription(sheetDescription);
+
+ wxXmlNode* child2 = child->GetChildren();
+ while (child2)
+ {
+ handler->ImportStyleDefinition(sheet, child2);
+
+ child2 = child2->GetNext();
+ }
+ handler->ImportProperties(sheet->GetProperties(), child);
+
+ // Notify that styles have changed. If this is vetoed by the app,
+ // the new sheet will be deleted. If it is not vetoed, the
+ // old sheet will be deleted and replaced with the new one.
+ buffer->SetStyleSheetAndNotify(sheet);
+ }
+
+ return true;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextParagraphLayoutBox::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
+{
+ ::OutputIndentation(stream, indent);
+ wxString nodeName = GetXMLNodeName();
+ ::OutputString(stream, wxT("<") + nodeName, handler->GetConvMem(), handler->GetConvFile());
+
+ wxString style = handler->AddAttributes(GetAttributes(), true);
+
+ if (GetPartialParagraph())
+ style << wxT(" partialparagraph=\"true\"");
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ }
+
+ size_t i;
+ for (i = 0; i < GetChildCount(); i++)
+ {
+ wxRichTextObject* child = GetChild(i);
+ child->ExportXML(stream, indent+1, handler);
+ }
+
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("</") + nodeName + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+ return true;
+}
+#endif
+
+#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT
+// Export this object to the given parent node, usually creating at least one child node.
+bool wxRichTextParagraphLayoutBox::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler)
+{
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, GetXMLNodeName());
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), true);
+ handler->WriteProperties(elementNode, GetProperties());
+
+ if (GetPartialParagraph())
+ elementNode->AddAttribute(wxT("partialparagraph"), wxT("true"));
+
+ size_t i;
+ for (i = 0; i < GetChildCount(); i++)
+ {
+ wxRichTextObject* child = GetChild(i);
+ child->ExportXML(elementNode, handler);
+ }
+
+ return true;
+}
+#endif
+
+// Import this object from XML
+bool wxRichTextTable::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
+{
+ wxRichTextBox::ImportFromXML(buffer, node, handler, recurse);
+
+ *recurse = false;
+
+ m_rowCount = wxAtoi(node->GetAttribute(wxT("rows"), wxEmptyString));
+ m_colCount = wxAtoi(node->GetAttribute(wxT("cols"), wxEmptyString));
+
+ wxXmlNode* child = node->GetChildren();
+ while (child)
+ {
+ wxRichTextObject* childObj = handler->CreateObjectForXMLName(this, child->GetName());
+ if (childObj)
+ {
+ AppendChild(childObj);
+ handler->ImportXML(buffer, childObj, child);
+ }
+ child = child->GetNext();
+ }
+
+ m_cells.Add(wxRichTextObjectPtrArray(), m_rowCount);
+ int i, j;
+ for (i = 0; i < m_rowCount; i++)
+ {
+ wxRichTextObjectPtrArray& colArray = m_cells[i];
+ for (j = 0; j < m_colCount; j++)
+ {
+ int idx = i * m_colCount + j;
+ if (idx < (int) GetChildren().GetCount())
+ {
+ wxRichTextCell* cell = wxDynamicCast(GetChildren().Item(idx)->GetData(), wxRichTextCell);
+ if (cell)
+ colArray.Add(cell);
+ }
+ }
+ }
+
+ return true;
+}
+
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextTable::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
+{
+ ::OutputIndentation(stream, indent);
+ wxString nodeName = GetXMLNodeName();
+ ::OutputString(stream, wxT("<") + nodeName, handler->GetConvMem(), handler->GetConvFile());
+
+ wxString style = handler->AddAttributes(GetAttributes(), true);
+
+ style << wxT(" rows=\"") << m_rowCount << wxT("\"");
+ style << wxT(" cols=\"") << m_colCount << wxT("\"");
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
+ }
+
+ int i, j;
+ for (i = 0; i < m_rowCount; i++)
+ {
+ for (j = 0; j < m_colCount; j ++)
+ {
+ wxRichTextCell* cell = GetCell(i, j);
+ cell->ExportXML(stream, indent+1, handler);
+ }
+ }
+
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("</") + nodeName + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ return true;
+}