tag: %d", type);
+ }
+ else
+ {
+ imageType = (wxBitmapType)type;
+ }
+ }
+ wxString data;
-#if wxUSE_STREAMS
-bool wxRichTextHTMLHandler::LoadFile(wxRichTextBuffer *WXUNUSED(buffer), wxInputStream& WXUNUSED(stream))
-{
- return false;
-}
+ 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();
+ }
-/*
- * We need to output only _changes_ in character formatting.
- */
+ }
+ imageChild = imageChild->GetNext();
+ }
-bool wxRichTextHTMLHandler::SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream)
-{
- buffer->Defragment();
+ if (!data.empty())
+ {
+ wxStringInputStream strStream(data);
- wxTextOutputStream str(stream);
+ GetImageBlock().ReadHex(strStream, data.length(), imageType);
- wxTextAttrEx currentParaStyle = buffer->GetAttributes();
- wxTextAttrEx currentCharStyle = buffer->GetAttributes();
+ return true;
+ }
+ else
+ return false;
+}
- str << wxT("\n");
+#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);
- wxRichTextObjectList::compatibility_iterator node = buffer->GetChildren().GetFirst();
- while (node)
+ ::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)
{
- wxRichTextParagraph* para = wxDynamicCast(node->GetData(), wxRichTextParagraph);
- wxASSERT (para != NULL);
+ handler->WriteProperties(stream, GetProperties(), indent);
+ ::OutputIndentation(stream, indent);
+ }
- if (para)
- {
- OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, true);
+ ::OutputIndentation(stream, indent+1);
+ ::OutputString(stream, wxT(""), handler->GetConvMem(), handler->GetConvFile());
- 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);
+ // wxStopWatch stopwatch;
- str << textObj->GetText();
+ GetImageBlock().WriteHex(stream);
- OutputCharacterFormatting(currentCharStyle, obj->GetAttributes(), stream, false);
- }
+ // 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
+
+#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);
- node2 = node2->GetNext();
- }
+ if (GetImageBlock().IsOk())
+ elementNode->AddAttribute(wxT("imagetype"), MakeString((int) GetImageBlock().GetImageType()));
- OutputParagraphFormatting(currentParaStyle, para->GetAttributes(), stream, false);
+ handler->AddAttributes(elementNode, GetAttributes(), false);
+ handler->WriteProperties(elementNode, GetProperties());
- str << wxT("\n");
+ 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;
}
- node = node->GetNext();
}
+#else
+ {
+ wxStringOutputStream strStream(& strData);
+ GetImageBlock().WriteHex(strStream);
+ }
+#endif
- str << wxT("\n");
+ textNode->SetContent(strData);
+ textNode->SetNoConversion(true); // optimize speed
return true;
}
+#endif
+
-/// Output character formatting
-void wxRichTextHTMLHandler::OutputCharacterFormatting(const wxTextAttrEx& WXUNUSED(currentStyle), const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start)
+// Import this object from XML
+bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXmlNode* node, wxRichTextXMLHandler* handler, bool* recurse)
{
- wxTextOutputStream str(stream);
+ wxRichTextObject::ImportFromXML(buffer, node, handler, recurse);
- bool isBold = false;
- bool isItalic = false;
- bool isUnderline = false;
- wxString faceName;
+ *recurse = true;
- if (thisStyle.GetFont().Ok())
+ 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))
{
- if (thisStyle.GetFont().GetWeight() == wxBOLD)
- isBold = true;
- if (thisStyle.GetFont().GetStyle() == wxITALIC)
- isItalic = true;
- if (thisStyle.GetFont().GetUnderlined())
- isUnderline = true;
+ 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();
+ }
- faceName = thisStyle.GetFont().GetFaceName();
+ // 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);
}
- if (start)
+ 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)
{
- if (isBold)
- str << wxT("");
- if (isItalic)
- str << wxT("");
- if (isUnderline)
- str << wxT("");
+ handler->WriteProperties(stream, GetProperties(), indent);
}
- else
+
+ size_t i;
+ for (i = 0; i < GetChildCount(); i++)
{
- if (isUnderline)
- str << wxT("");
- if (isItalic)
- str << wxT("");
- if (isBold)
- str << wxT("");
+ 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 paragraph formatting
-void wxRichTextHTMLHandler::OutputParagraphFormatting(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)
{
- // TODO: lists, indentation (using tables), fonts, right-align, ...
+ wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, GetXMLNodeName());
+ parent->AddChild(elementNode);
+ handler->AddAttributes(elementNode, GetAttributes(), true);
+ handler->WriteProperties(elementNode, GetProperties());
- wxTextOutputStream str(stream);
- bool isCentered = false;
+ if (GetPartialParagraph())
+ elementNode->AddAttribute(wxT("partialparagraph"), wxT("true"));
- if (thisStyle.GetAlignment() == wxTEXT_ALIGNMENT_CENTRE)
+ size_t i;
+ for (i = 0; i < GetChildCount(); i++)
{
- isCentered = true;
+ 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 (isCentered)
- 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++)
+ {
+ 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)
{
- if (isCentered)
- str << wxT("");
+ 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;
}
+#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++)
+ {
+ for (j = 0; j < m_colCount; j ++)
+ {
+ wxRichTextCell* cell = GetCell(i, j);
+ cell->ExportXML(elementNode, handler);
+ }
+ }
+
+ return true;
+}
#endif
+
#endif
- // wxUSE_RICHTEXT
+ // wxUSE_RICHTEXT && wxUSE_XML