tag: %d", type);
+ }
else
- attr.SetBackgroundColour(value);
+ {
+ imageType = (wxBitmapType)type;
+ }
}
- value = node->GetPropVal(wxT("characterstyle"), wxEmptyString);
- if (!value.empty())
- attr.SetCharacterStyleName(value);
+ wxString data;
- // Set paragraph attributes
- if (isPara)
+ wxXmlNode* imageChild = node->GetChildren();
+ while (imageChild)
{
- value = node->GetPropVal(wxT("alignment"), wxEmptyString);
- if (!value.empty())
- attr.SetAlignment((wxTextAttrAlignment) wxAtoi(value));
+ wxString childName = imageChild->GetName();
+ if (childName == wxT("data"))
+ {
+ wxXmlNode* dataChild = imageChild->GetChildren();
+ while (dataChild)
+ {
+ data = dataChild->GetContent();
+ // wxLogDebug(data);
+ dataChild = dataChild->GetNext();
+ }
- int leftSubIndent = 0;
- int leftIndent = 0;
- value = node->GetPropVal(wxT("leftindent"), wxEmptyString);
- if (!value.empty())
- leftIndent = wxAtoi(value);
- value = node->GetPropVal(wxT("leftsubindent"), wxEmptyString);
- if (!value.empty())
- leftSubIndent = wxAtoi(value);
- attr.SetLeftIndent(leftIndent, leftSubIndent);
+ }
+ imageChild = imageChild->GetNext();
+ }
- value = node->GetPropVal(wxT("rightindent"), wxEmptyString);
- if (!value.empty())
- attr.SetRightIndent(wxAtoi(value));
+ if (!data.empty())
+ {
+ wxStringInputStream strStream(data);
- value = node->GetPropVal(wxT("parspacingbefore"), wxEmptyString);
- if (!value.empty())
- attr.SetParagraphSpacingBefore(wxAtoi(value));
+ GetImageBlock().ReadHex(strStream, data.length(), imageType);
- value = node->GetPropVal(wxT("parspacingafter"), wxEmptyString);
- if (!value.empty())
- attr.SetParagraphSpacingAfter(wxAtoi(value));
+ return true;
+ }
+ else
+ return false;
+}
- value = node->GetPropVal(wxT("linespacing"), wxEmptyString);
- if (!value.empty())
- attr.SetLineSpacing(wxAtoi(value));
+#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);
- value = node->GetPropVal(wxT("bulletstyle"), wxEmptyString);
- if (!value.empty())
- attr.SetBulletStyle(wxAtoi(value));
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT("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);
+ }
- value = node->GetPropVal(wxT("bulletnumber"), wxEmptyString);
- if (!value.empty())
- attr.SetBulletNumber(wxAtoi(value));
+ ::OutputIndentation(stream, indent+1);
+ ::OutputString(stream, wxT(""), handler->GetConvMem(), handler->GetConvFile());
- value = node->GetPropVal(wxT("bulletsymbol"), wxEmptyString);
- if (!value.empty())
- attr.SetBulletSymbol(value[0]);
+ // wxStopWatch stopwatch;
- value = node->GetPropVal(wxT("parstyle"), wxEmptyString);
- if (!value.empty())
- attr.SetParagraphStyleName(value);
- }
+ GetImageBlock().WriteHex(stream);
+ // wxLogDebug(wxT("Image conversion to hex took %ldms"), stopwatch.Time());
+
+ ::OutputString(stream, wxT("\n"), handler->GetConvMem(), handler->GetConvFile());
+ ::OutputIndentation(stream, indent);
+ ::OutputString(stream, wxT(""), handler->GetConvMem(), handler->GetConvFile());
return true;
}
-
#endif
-IMPLEMENT_DYNAMIC_CLASS(wxRichTextHTMLHandler, wxRichTextFileHandler)
-
-/// Can we handle this filename (if using files)? By default, checks the extension.
-bool wxRichTextHTMLHandler::CanHandle(const wxString& filename) const
+#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)
{
- wxString path, file, ext;
- wxSplitPath(filename, & path, & file, & ext);
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("image"));
+ parent->AddChild(elementNode);
- return (ext.Lower() == wxT("html") || ext.Lower() == wxT("htm"));
-}
+ if (GetImageBlock().IsOk())
+ elementNode->AddAttribute(wxT("imagetype"), MakeString((int) GetImageBlock().GetImageType()));
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
-#if wxUSE_STREAMS
-bool wxRichTextHTMLHandler::DoLoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
-{
- return false;
+ 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
-/*
- * We need to output only _changes_ in character formatting.
- */
-bool wxRichTextHTMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
+// Import this object from XML
+bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
{
- buffer->Defragment();
-
- wxTextOutputStream str(stream);
+ wxRichTextObject::ImportFromXML(buffer, node, handler, recurse);
- wxTextAttrEx currentParaStyle = buffer->GetAttributes();
- wxTextAttrEx currentCharStyle = buffer->GetAttributes();
+ *recurse = true;
- str << wxT("\n");
+ wxString partial = node->GetAttribute(wxT("partialparagraph"), wxEmptyString);
+ if (partial == wxT("true"))
+ SetPartialParagraph(true);
- wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst();
- while (node)
+ wxXmlNode* child = wxRichTextXMLHandler::FindNode(node, wxT("stylesheet"));
+ if (child && (handler->GetFlags() & wxRICHTEXT_HANDLER_INCLUDE_STYLESHEET))
{
- wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
- wxASSERT (para != NULL);
-
- if (para)
+ 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)
{
- OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, true);
+ handler->ImportStyleDefinition(sheet, child2);
- wxRichTextObjectList::compatibility_iterator node2 = para->GetChildren().GetFirst();
- while (node2)
- {
- wxRichTextObject* obj = node2->GetData();
- wxRichTextPlainText* textObj = wxDynamicCast(obj, wxRichTextPlainText);
- if (textObj && !textObj->IsEmpty())
- {
- OutputCharacterFormatting(currentCharStyle, obj->GetAttributes(), stream, true);
+ child2 = child2->GetNext();
+ }
- str << textObj->GetText();
+ // 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);
+ }
- OutputCharacterFormatting(currentCharStyle, obj->GetAttributes(), stream, false);
- }
+ return true;
+}
- node2 = node2->GetNext();
- }
+#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());
- OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, false);
+ wxString style = handler->AddAttributes(GetAttributes(), true);
- str << wxT("\n");
- }
+ if (GetPartialParagraph())
+ style << wxT(" partialparagraph=\"true\"");
+
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
- node = node->GetNext();
+ if (GetProperties().GetCount() > 0)
+ {
+ handler->WriteProperties(stream, GetProperties(), indent);
}
- str << wxT("\n");
+ 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
-/// Output character formatting
-void wxRichTextHTMLHandler::OutputCharacterFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start)
+#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)
{
- wxTextOutputStream str(stream);
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, GetXMLNodeName());
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), true);
+ handler->WriteProperties(elementNode, GetProperties());
- bool isBold = false;
- bool isItalic = false;
- bool isUnderline = false;
- wxString faceName;
+ if (GetPartialParagraph())
+ elementNode->AddAttribute(wxT("partialparagraph"), wxT("true"));
- if (thisStyle.GetFont().Ok())
+ size_t i;
+ for (i = 0; i < GetChildCount(); i++)
{
- if (thisStyle.GetFont().GetWeight() == wxBOLD)
- isBold = true;
- if (thisStyle.GetFont().GetStyle() == wxITALIC)
- isItalic = true;
- if (thisStyle.GetFont().GetUnderlined())
- isUnderline = true;
-
- faceName = thisStyle.GetFont().GetFaceName();
+ wxRichTextObject* child = GetChild(i);
+ child->ExportXML(elementNode, handler);
}
- if (start)
+ 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)
{
- if (isBold)
- str << wxT("");
- if (isItalic)
- str << wxT("");
- if (isUnderline)
- str << wxT("");
+ wxRichTextObject* childObj = handler->CreateObjectForXMLName(this, child->GetName());
+ if (childObj)
+ {
+ AppendChild(childObj);
+ handler->ImportXML(buffer, childObj, child);
+ }
+ child = child->GetNext();
}
- else
+
+ m_cells.Add(wxRichTextObjectPtrArray(), m_rowCount);
+ int i, j;
+ for (i = 0; i < m_rowCount; i++)
{
- if (isUnderline)
- str << wxT("");
- if (isItalic)
- str << wxT("");
- if (isBold)
- str << wxT("");
+ 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;
}
-/// Output paragraph formatting
-void wxRichTextHTMLHandler::OutputParagraphFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start)
+#if wxRICHTEXT_HAVE_DIRECT_OUTPUT
+// Export this object directly to the given stream.
+bool wxRichTextTable::ExportXML(wxOutputStream& stream, int indent, wxRichTextXMLHandler* handler)
{
- // TODO: lists, indentation (using tables), fonts, right-align, ...
+ ::OutputIndentation(stream, indent);
+ wxString nodeName = GetXMLNodeName();
+ ::OutputString(stream, wxT("<") + nodeName, handler->GetConvMem(), handler->GetConvFile());
+
+ wxString style = handler->AddAttributes(GetAttributes(), true);
- wxTextOutputStream str(stream);
- bool isCentered = false;
+ style << wxT(" rows=\"") << m_rowCount << wxT("\"");
+ style << wxT(" cols=\"") << m_colCount << wxT("\"");
- if (thisStyle.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+ ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile());
+
+ if (GetProperties().GetCount() > 0)
{
- isCentered = true;
+ handler->WriteProperties(stream, GetProperties(), indent);
}
- if (start)
+ int i, j;
+ for (i = 0; i < m_rowCount; i++)
{
- if (isCentered)
- str << wxT("
");
+ for (j = 0; j < m_colCount; j ++)
+ {
+ wxRichTextCell* cell = GetCell(i, j);
+ cell->ExportXML(stream, indent+1, handler);
+ }
}
- else
+
+ ::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 wxRichTextTable::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());
+
+ elementNode->AddAttribute(wxT("rows"), wxString::Format(wxT("%d"), m_rowCount));
+ elementNode->AddAttribute(wxT("cols"), wxString::Format(wxT("%d"), m_colCount));
+
+ int i, j;
+ for (i = 0; i < m_rowCount; i++)
{
- if (isCentered)
- str << wxT("");
+ for (j = 0; j < m_colCount; j ++)
+ {
+ wxRichTextCell* cell = GetCell(i, j);
+ cell->ExportXML(elementNode, handler);
+ }
}
-}
+ return true;
+}
#endif
+
#endif
// wxUSE_RICHTEXT && wxUSE_XML
+