X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/5d7836c47de679f03b1b7e738c77164c11bd3689..835165d576b66441987b78519e6ef1fe74ea795a:/include/wx/richtext/richtextxml.h?ds=sidebyside diff --git a/include/wx/richtext/richtextxml.h b/include/wx/richtext/richtextxml.h index be318f9f3a..d51d2043e5 100644 --- a/include/wx/richtext/richtextxml.h +++ b/include/wx/richtext/richtextxml.h @@ -1,10 +1,10 @@ ///////////////////////////////////////////////////////////////////////////// -// Name: richeditxml.h +// Name: wx/richtext/richtextxml.h // Purpose: XML and HTML I/O for wxRichTextCtrl // Author: Julian Smart -// Modified by: +// Modified by: // Created: 2005-09-30 -// RCS-ID: +// RCS-ID: $Id$ // Copyright: (c) Julian Smart // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -16,49 +16,77 @@ * Includes */ -#include "wx/defs.h" - -#if wxUSE_RICHTEXT - #include "wx/richtext/richtextbuffer.h" +#include "wx/richtext/richtextstyles.h" + +#if wxUSE_RICHTEXT && wxUSE_XML /*! * wxRichTextXMLHandler */ -class WXDLLIMPEXP_XML wxXmlNode; +class WXDLLIMPEXP_FWD_XML wxXmlNode; +class WXDLLIMPEXP_FWD_XML wxXmlDocument; -class WXDLLIMPEXP_ADV wxRichTextXMLHandler: public wxRichTextFileHandler +class WXDLLIMPEXP_RICHTEXT wxRichTextXMLHandler: public wxRichTextFileHandler { - DECLARE_CLASS(wxRichTextXMLHandler) + DECLARE_DYNAMIC_CLASS(wxRichTextXMLHandler) public: wxRichTextXMLHandler(const wxString& name = wxT("XML"), const wxString& ext = wxT("xml"), int type = wxRICHTEXT_TYPE_XML) : wxRichTextFileHandler(name, ext, type) - { } + { Init(); } + + void Init(); #if wxUSE_STREAMS - virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); - virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); +#if wxRICHTEXT_HAVE_DIRECT_OUTPUT /// Recursively export an object - bool ExportXML(wxOutputStream& stream, wxMBConv* convMem, wxMBConv* convFile, wxRichTextObject& obj, int level); + bool ExportXML(wxOutputStream& stream, wxRichTextObject& obj, int level); + bool ExportStyleDefinition(wxOutputStream& stream, wxRichTextStyleDefinition* def, int level); + wxString AddAttributes(const wxRichTextAttr& attr, bool isPara = false); + bool WriteProperties(wxOutputStream& stream, const wxRichTextProperties& properties, int level); + void OutputString(wxOutputStream& stream, const wxString& str); + void OutputStringEnt(wxOutputStream& stream, const wxString& str); + void OutputIndentation(wxOutputStream& stream, int indent); + static wxString AttributeToXML(const wxString& str); +#endif - /// Recursively import an object - bool ImportXML(wxRichTextBuffer* buffer, wxXmlNode* node); +#if wxRICHTEXT_HAVE_XMLDOCUMENT_OUTPUT + bool ExportXML(wxXmlNode* parent, wxRichTextObject& obj); + bool ExportStyleDefinition(wxXmlNode* parent, wxRichTextStyleDefinition* def); + bool AddAttributes(wxXmlNode* node, wxRichTextAttr& attr, bool isPara = false); + bool WriteProperties(wxXmlNode* node, const wxRichTextProperties& properties); +#endif + + /// Make a string from the given property. This can be overridden for custom variants. + virtual wxString MakeStringFromProperty(const wxVariant& var); + + /// Create a proprty from the string read from the XML file. + virtual wxVariant MakePropertyFromString(const wxString& name, const wxString& value, const wxString& type); - /// Create style parameters - wxString CreateStyle(const wxTextAttrEx& attr, bool isPara = false); + /// Recursively import an object + bool ImportXML(wxRichTextBuffer* buffer, wxRichTextObject* obj, wxXmlNode* node); + bool ImportStyleDefinition(wxRichTextStyleSheet* sheet, wxXmlNode* node); + bool ImportProperties(wxRichTextObject* obj, wxXmlNode* node); - /// Get style parameters - bool GetStyle(wxTextAttrEx& attr, wxXmlNode* node, bool isPara = false); + /// Import style parameters + bool ImportStyle(wxRichTextAttr& attr, wxXmlNode* node, bool isPara = false); #endif + /// Creates an object given an XML element name + virtual wxRichTextObject* CreateObjectForXMLName(wxRichTextObject* parent, const wxString& name) const; + /// Can we save using this handler? virtual bool CanSave() const { return true; } /// Can we load using this handler? virtual bool CanLoad() const { return true; } + // Used during saving + wxMBConv* GetConvMem() const { return m_convMem; } + wxMBConv* GetConvFile() const { return m_convFile; } + // Implementation bool HasParam(wxXmlNode* node, const wxString& param); @@ -66,49 +94,23 @@ public: wxString GetNodeContent(wxXmlNode *node); wxString GetParamValue(wxXmlNode *node, const wxString& param); wxString GetText(wxXmlNode *node, const wxString& param = wxEmptyString, bool translate = false); + static wxXmlNode* FindNode(wxXmlNode* node, const wxString& name); protected: - -}; - -/*! - * wxRichTextHTMLHandler - */ - -class WXDLLIMPEXP_ADV wxRichTextHTMLHandler: public wxRichTextFileHandler -{ - DECLARE_CLASS(wxRichTextHTMLHandler) -public: - wxRichTextHTMLHandler(const wxString& name = wxT("HTML"), const wxString& ext = wxT("html"), int type = wxRICHTEXT_TYPE_HTML) - : wxRichTextFileHandler(name, ext, type) - { } - #if wxUSE_STREAMS - virtual bool LoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); - virtual bool SaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); + virtual bool DoLoadFile(wxRichTextBuffer *buffer, wxInputStream& stream); + virtual bool DoSaveFile(wxRichTextBuffer *buffer, wxOutputStream& stream); #endif - /// Can we save using this handler? - virtual bool CanSave() const { return true; } - - /// Can we load using this handler? - virtual bool CanLoad() const { return false; } - - /// Can we handle this filename (if using files)? By default, checks the extension. - virtual bool CanHandle(const wxString& filename) const; - - /// Output character formatting - virtual void OutputCharacterFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start); - - /// Output paragraph formatting - virtual void OutputParagraphFormatting(const wxTextAttrEx& currentStyle, const wxTextAttrEx& thisStyle, wxOutputStream& stream, bool start); - -protected: - +#if wxRICHTEXT_HAVE_DIRECT_OUTPUT + // Used during saving + wxMBConv* m_convMem; + wxMBConv* m_convFile; +#endif }; #endif - // wxUSE_RICHTEXT + // wxUSE_RICHTEXT && wxUSE_XML #endif // _WX_RICHTEXTXML_H_