X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/706465df1f0d5b356424cc0aeee6c21ac403999e..fb8d7eb7a880f1f2e32d8830f9c5e12b2536e05f:/src/richtext/richtextxml.cpp diff --git a/src/richtext/richtextxml.cpp b/src/richtext/richtextxml.cpp index a20eb181a0..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("")); } @@ -949,17 +958,17 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT wxString name = def->GetName(); wxString nameProp; if (!name.empty()) - nameProp = wxT(" name=\"") + name + wxT("\""); + nameProp = wxT(" name=\"") + AttributeToXML(name) + wxT("\""); wxString baseStyle = def->GetBaseStyle(); wxString baseStyleProp; if (!baseStyle.empty()) - baseStyleProp = wxT(" basestyle=\"") + baseStyle + wxT("\""); + baseStyleProp = wxT(" basestyle=\"") + AttributeToXML(baseStyle) + wxT("\""); wxString descr = def->GetDescription(); wxString descrProp; if (!descr.empty()) - descrProp = wxT(" description=\"") + descr + wxT("\""); + descrProp = wxT(" description=\"") + AttributeToXML(descr) + wxT("\""); if (charDef) { @@ -986,7 +995,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT OutputIndentation(stream, level); if (!listDef->GetNextStyle().empty()) - baseStyleProp << wxT(" nextstyle=\"") << listDef->GetNextStyle() << wxT("\""); + baseStyleProp << wxT(" nextstyle=\"") << AttributeToXML(listDef->GetNextStyle()) << wxT("\""); OutputString(stream, wxT("")); @@ -1027,7 +1036,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT OutputIndentation(stream, level); if (!paraDef->GetNextStyle().empty()) - baseStyleProp << wxT(" nextstyle=\"") << paraDef->GetNextStyle() << wxT("\""); + baseStyleProp << wxT(" nextstyle=\"") << AttributeToXML(paraDef->GetNextStyle()) << wxT("\""); OutputString(stream, wxT("")); @@ -1068,6 +1077,7 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT OutputString(stream, wxT("")); } + WriteProperties(stream, def->GetProperties(), level); return true; } @@ -1076,14 +1086,16 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxOutputStream& stream, wxRichT wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool isPara) { wxString str; - if (attr.HasTextColour() && attr.GetTextColour().Ok()) + if (attr.HasTextColour() && attr.GetTextColour().IsOk()) AddAttribute(str, wxT("textcolor"), attr.GetTextColour()); - if (attr.HasBackgroundColour() && attr.GetBackgroundColour().Ok()) + 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()); @@ -1098,7 +1110,7 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is AddAttribute(str, wxT("fontunderlined"), (int) attr.GetFontUnderlined()); if (attr.HasFontFaceName()) - AddAttribute(str, wxT("fontface"), attr.GetFontFaceName()); + AddAttribute(str, wxT("fontface"), AttributeToXML(attr.GetFontFaceName())); if (attr.HasTextEffects()) { @@ -1107,7 +1119,7 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is } if (!attr.GetCharacterStyleName().empty()) - AddAttribute(str, wxT("characterstyle"), attr.GetCharacterStyleName()); + AddAttribute(str, wxT("characterstyle"), AttributeToXML(attr.GetCharacterStyleName())); if (attr.HasURL()) AddAttribute(str, wxT("url"), AttributeToXML(attr.GetURL())); @@ -1148,19 +1160,22 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is if (!attr.GetBulletText().empty() && (attr.GetBulletStyle() & wxTEXT_ATTR_BULLET_STYLE_SYMBOL)) AddAttribute(str, wxT("bulletsymbol"), (int) (attr.GetBulletText()[0])); else - AddAttribute(str, wxT("bullettext"), attr.GetBulletText()); + AddAttribute(str, wxT("bullettext"), AttributeToXML(attr.GetBulletText())); AddAttribute(str, wxT("bulletfont"), attr.GetBulletFont()); } if (attr.HasBulletName()) - AddAttribute(str, wxT("bulletname"), attr.GetBulletName()); + AddAttribute(str, wxT("bulletname"), AttributeToXML(attr.GetBulletName())); if (!attr.GetParagraphStyleName().empty()) - AddAttribute(str, wxT("parstyle"), attr.GetParagraphStyleName()); + AddAttribute(str, wxT("parstyle"), AttributeToXML(attr.GetParagraphStyleName())); if (!attr.GetListStyleName().empty()) - AddAttribute(str, wxT("liststyle"), attr.GetListStyleName()); + AddAttribute(str, wxT("liststyle"), AttributeToXML(attr.GetListStyleName())); + + if (!attr.GetTextBoxAttr().GetBoxStyleName().empty()) + AddAttribute(str, wxT("boxstyle"), AttributeToXML(attr.GetTextBoxAttr().GetBoxStyleName())); if (attr.HasTabs()) { @@ -1190,6 +1205,10 @@ wxString wxRichTextXMLHandler::AddAttributes(const wxRichTextAttr& attr, bool is AddAttribute(str, wxT("outline"), attr.GetTextBoxAttr().GetOutline()); AddAttribute(str, wxT("width"), attr.GetTextBoxAttr().GetWidth()); AddAttribute(str, wxT("height"), attr.GetTextBoxAttr().GetHeight()); + AddAttribute(str, wxT("minwidth"), attr.GetTextBoxAttr().GetMinSize().GetWidth()); + AddAttribute(str, wxT("minheight"), attr.GetTextBoxAttr().GetMinSize().GetHeight()); + AddAttribute(str, wxT("maxwidth"), attr.GetTextBoxAttr().GetMaxSize().GetWidth()); + AddAttribute(str, wxT("maxheight"), attr.GetTextBoxAttr().GetMaxSize().GetHeight()); if (attr.GetTextBoxAttr().HasVerticalAlignment()) { @@ -1259,7 +1278,7 @@ bool wxRichTextXMLHandler::WriteProperties(wxOutputStream& stream, const wxRichT level ++; OutputIndentation(stream, level); - OutputString(stream, wxT("")); level ++; @@ -1276,14 +1295,14 @@ bool wxRichTextXMLHandler::WriteProperties(wxOutputStream& stream, const wxRichT OutputString(stream, wxT("\n")); + OutputString(stream, wxT("\"/>")); } } level --; OutputIndentation(stream, level); - OutputString(stream, wxT("\n")); + OutputString(stream, wxT("")); level --; } @@ -1366,18 +1385,22 @@ bool wxRichTextXMLHandler::ExportStyleDefinition(wxXmlNode* parent, wxRichTextSt AddAttributes(styleNode, def->GetStyle(), true); } + WriteProperties(defNode, def->GetProperties()); + return true; } bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, bool isPara) { - if (attr.HasTextColour() && attr.GetTextColour().Ok()) + if (attr.HasTextColour() && attr.GetTextColour().IsOk()) node->AddAttribute(wxT("textcolor"), MakeString(attr.GetTextColour())); - if (attr.HasBackgroundColour() && attr.GetBackgroundColour().Ok()) + 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()) @@ -1451,6 +1474,9 @@ bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, if (!attr.GetListStyleName().empty()) node->AddAttribute(wxT("liststyle"), attr.GetListStyleName()); + if (!attr.GetTextBoxAttr().GetBoxStyleName().empty()) + node->AddAttribute(wxT("boxstyle"), attr.GetTextBoxAttr().GetBoxStyleName()); + if (attr.HasTabs()) { wxString tabs; @@ -1478,6 +1504,10 @@ bool wxRichTextXMLHandler::AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, AddAttribute(node, wxT("outline"), attr.GetTextBoxAttr().GetOutline()); AddAttribute(node, wxT("width"), attr.GetTextBoxAttr().GetWidth()); AddAttribute(node, wxT("height"), attr.GetTextBoxAttr().GetHeight()); + AddAttribute(node, wxT("minwidth"), attr.GetTextBoxAttr().GetMinSize().GetWidth()); + AddAttribute(node, wxT("minheight"), attr.GetTextBoxAttr().GetMinSize().GetHeight()); + AddAttribute(node, wxT("maxwidth"), attr.GetTextBoxAttr().GetMaxSize().GetWidth()); + AddAttribute(node, wxT("maxheight"), attr.GetTextBoxAttr().GetMaxSize().GetHeight()); if (attr.GetTextBoxAttr().HasVerticalAlignment()) { @@ -1657,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.SetFontSize(wxAtoi(value)); + attr.SetFontPointSize(wxAtoi(value)); + } + else if (name == wxT("fontpixelsize")) + { + if (!value.empty()) + attr.SetFontPixelSize(wxAtoi(value)); } else if (name == wxT("fontweight")) { @@ -1804,6 +1839,13 @@ bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bo attr.SetListStyleName(value); } } + else if (name == wxT("boxstyle")) + { + if (!value.empty()) + { + attr.GetTextBoxAttr().SetBoxStyleName(value); + } + } else if (name == wxT("tabs")) { if (!value.empty()) @@ -1850,6 +1892,22 @@ bool wxRichTextXMLHandler::ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bo { 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")) { @@ -2381,7 +2439,7 @@ bool wxRichTextImage::ExportXML(wxOutputStream& stream, int indent, wxRichTextXM ::OutputIndentation(stream, indent); ::OutputString(stream, wxT("GetConvMem(), handler->GetConvFile()); - if (!GetImageBlock().Ok()) + if (!GetImageBlock().IsOk()) { // No data ::OutputString(stream, style + wxT(">"), handler->GetConvMem(), handler->GetConvFile()); @@ -2419,7 +2477,7 @@ bool wxRichTextImage::ExportXML(wxXmlNode* parent, wxRichTextXMLHandler* handler wxXmlNode* elementNode = new wxXmlNode(wxXML_ELEMENT_NODE, wxT("image")); parent->AddChild(elementNode); - if (GetImageBlock().Ok()) + if (GetImageBlock().IsOk()) elementNode->AddAttribute(wxT("imagetype"), MakeString((int) GetImageBlock().GetImageType())); handler->AddAttributes(elementNode, GetAttributes(), false); @@ -2495,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