X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7e2cf464253746db359b2692a252e830a8ac48c6..739c5499fcab1c165b8dd0591c9fd9e2329b3cf9:/src/richtext/richtextxml.cpp diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp index f78883c8be..4157ec5505 100644 --- a/src/richtext/richtextxml.cpp +++ b/src/richtext/richtextxml.cpp @@ -89,6 +89,8 @@ static inline void AddString(wxString& str, const wxColour& col) { str << wxT("# IMPLEMENT_DYNAMIC_CLASS(wxRichTextXMLHandler, wxRichTextFileHandler) +wxStringToStringHashMap wxRichTextXMLHandler::sm_nodeNameToClassMap; + void wxRichTextXMLHandler::Init() { #if wxRICHTEXT_HAVE_DIRECT_OUTPUT @@ -158,22 +160,12 @@ bool wxRichTextXMLHandler::DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& s /// Creates an object given an XML element name wxRichTextObject* wxRichTextXMLHandler::CreateObjectForXMLName(wxRichTextObject* WXUNUSED(parent), const wxString& name) const { - if (name == wxT("text") || name == wxT("symbol")) - return new wxRichTextPlainText; - else if (name == wxT("image")) - return new wxRichTextImage; - else if (name == wxT("paragraph")) - return new wxRichTextParagraph; - else if (name == wxT("paragraphlayout")) - return new wxRichTextParagraphLayoutBox; - else if (name == wxT("textbox")) - return new wxRichTextBox; - else if (name == wxT("cell")) - return new wxRichTextCell; - else if (name == wxT("table")) - return new wxRichTextTable; - else + // The standard node to class mappings are added in wxRichTextModule::OnInit in richtextbuffer.cpp + wxStringToStringHashMap::const_iterator it = sm_nodeNameToClassMap.find(name); + if (it == sm_nodeNameToClassMap.end()) return NULL; + else + return wxDynamicCast(wxCreateDynamicObject(it->second), wxRichTextObject); } /// Recursively import an object @@ -207,6 +199,11 @@ bool wxRichTextXMLHandler::ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* } bool wxRichTextXMLHandler::ImportProperties(wxRichTextObject* obj, wxXmlNode* node) +{ + return ImportProperties(obj->GetProperties(), node); +} + +bool wxRichTextXMLHandler::ImportProperties(wxRichTextProperties& properties, wxXmlNode* node) { wxXmlNode* child = node->GetChildren(); while (child) @@ -225,7 +222,7 @@ bool wxRichTextXMLHandler::ImportProperties(wxRichTextObject* obj, wxXmlNode* no wxVariant var = MakePropertyFromString(name, value, type); if (!var.IsNull()) { - obj->GetProperties().SetProperty(var); + properties.SetProperty(var); } } propertyChild = propertyChild->GetNext(); @@ -262,6 +259,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddCharacterStyle(def); } else if (styleType == wxT("paragraphstyle")) @@ -284,6 +283,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddParagraphStyle(def); } else if (styleType == wxT("boxstyle")) @@ -304,6 +305,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddBoxStyle(def); } else if (styleType == wxT("liststyle")) @@ -339,6 +342,8 @@ bool wxRichTextXMLHandler::ImportStyleDefinition(wxRichTextStyleSheet* sheet, wx child = child->GetNext(); } + ImportProperties(def->GetProperties(), node); + sheet->AddListStyle(def); } @@ -835,6 +840,8 @@ bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& wxRichTextBoxStyleDefinition* def = buffer->GetStyleSheet()->GetBoxStyle(i); ExportStyleDefinition(styleSheetNode, def); } + + WriteProperties(styleSheetNode, buffer->GetStyleSheet()->GetProperties()); } bool success = ExportXML(rootNode, *buffer); #if wxRICHTEXT_USE_OUTPUT_TIMINGS @@ -910,6 +917,8 @@ bool wxRichTextXMLHandler::DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& ExportStyleDefinition(stream, def, level + 1); } + WriteProperties(stream, buffer->GetStyleSheet()->GetProperties(), level); + OutputIndentation(stream, level); OutputString(stream, wxT("")); } @@ -1068,6 +1077,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT OutputString(stream, wxT("")); } + WriteProperties(stream, def->GetProperties(), level); return true; } @@ -1082,8 +1092,10 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is if (attr.HasBackgroundColour() && attr.GetBackgroundColour().IsOk()) AddAttribute(str, wxT("bgcolor"), attr.GetBackgroundColour()); - if (attr.HasFontSize()) - AddAttribute(str, wxT("fontsize"), attr.GetFontSize()); + if (attr.HasFontPointSize()) + AddAttribute(str, wxT("fontpointsize"), attr.GetFontSize()); + else if (attr.HasFontPixelSize()) + AddAttribute(str, wxT("fontpixelsize"), attr.GetFontSize()); if (attr.HasFontFamily()) AddAttribute(str, wxT("fontfamily"), attr.GetFontFamily()); @@ -1373,6 +1385,8 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxXmlNode* parent, wxRichTextSt AddAttributes(styleNode, def->GetStyle(), true); } + WriteProperties(defNode, def->GetProperties()); + return true; } @@ -1383,8 +1397,10 @@ bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, 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.HasFontPointSize()) + node->AddAttribute(wxT("fontpointsize"), MakeString(attr.GetFontSize())); + else if (attr.HasFontPixelSize()) + node->AddAttribute(wxT("fontpixelsize"), MakeString(attr.GetFontSize())); if (attr.HasFontFamily()) node->AddAttribute(wxT("fontfamily"), MakeString(attr.GetFontFamily())); if (attr.HasFontItalic()) @@ -1671,10 +1687,15 @@ bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bo if (!value.empty()) attr.SetFontStyle((wxFontStyle)wxAtoi(value)); } - else if (name == wxT("fontsize")) + else if (name == wxT("fontsize") || name == wxT("fontpointsize")) + { + if (!value.empty()) + attr.SetFontPointSize(wxAtoi(value)); + } + else if (name == wxT("fontpixelsize")) { if (!value.empty()) - attr.SetFontSize(wxAtoi(value)); + attr.SetFontPixelSize(wxAtoi(value)); } else if (name == wxT("fontweight")) { @@ -2532,6 +2553,7 @@ bool wxRichTextParagraphLayoutBox::ImportFromXML(wxRichTextBuffer* buffer, wxXml 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