X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/999d9a9f795cfc745681989ae0f30e531cde059f..9f9eb285d722c6d9cc48d9c57e815f9a763770b6:/contrib/include/wx/xrc/xml.h diff --git a/contrib/include/wx/xrc/xml.h b/contrib/include/wx/xrc/xml.h index de3b3fe7ed..7d5f4e05a6 100644 --- a/contrib/include/wx/xrc/xml.h +++ b/contrib/include/wx/xrc/xml.h @@ -54,18 +54,6 @@ enum wxXmlNodeType }; -// Types of XML files: - -enum wxXmlIOType -{ - wxXML_IO_AUTO = 0, // detect it automatically - wxXML_IO_EXPAT, // use Expat to load from text/xml document - wxXML_IO_TEXT_OUTPUT, // generic saver into text/xml - wxXML_IO_BIN, // save in binary uncompressed proprietary format - wxXML_IO_BINZ // svae in binary zlib-compressed proprietary format -}; - - // Represents node property(ies). // Example: in "src" is property with value // "hello.gif" and "id" is prop. with value "3". @@ -77,7 +65,6 @@ public: wxXmlProperty(const wxString& name, const wxString& value, wxXmlProperty *next) : m_name(name), m_value(value), m_next(next) {} - ~wxXmlProperty() { delete m_next; } wxString GetName() const { return m_name; } wxString GetValue() const { return m_value; } @@ -101,12 +88,8 @@ private: // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE // with content="hi"). // -// If wxUSE_UNICODE is 0, all strings are encoded in UTF-8 encoding (same as -// ASCII for characters 0-127). You can use wxMBConvUTF8 to convert then to -// desired encoding: -// -// wxCSConv myConv("iso8859-2"); -// wxString s(cMB2WC(node->GetContent().c_str()), myConv); +// If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load +// (default is UTF-8). class WXXMLDLLEXPORT wxXmlNode { @@ -116,7 +99,7 @@ public: wxXmlNode(wxXmlNode *parent,wxXmlNodeType type, const wxString& name, const wxString& content, wxXmlProperty *props, wxXmlNode *next); - ~wxXmlNode() { delete m_properties; delete m_next; delete m_children; } + ~wxXmlNode(); // copy ctor & operator=. Note that this does NOT copy syblings // and parent pointer, i.e. m_parent and m_next will be NULL @@ -176,18 +159,16 @@ private: -// This class holds XML data/document as parsed by libxml. Note that -// internal representation is independant on libxml and you can use -// it without libxml (see Load/SaveBinary). +// This class holds XML data/document as parsed by XML parser. class WXXMLDLLEXPORT wxXmlDocument : public wxObject { public: wxXmlDocument() : wxObject(), m_version(wxT("1.0")), m_root(NULL) {} wxXmlDocument(const wxString& filename, - wxXmlIOType io_type = wxXML_IO_AUTO); + const wxString& encoding = wxT("UTF-8")); wxXmlDocument(wxInputStream& stream, - wxXmlIOType io_type = wxXML_IO_AUTO); + const wxString& encoding = wxT("UTF-8")); ~wxXmlDocument() { delete m_root; } wxXmlDocument(const wxXmlDocument& doc); @@ -195,16 +176,14 @@ public: // Parses .xml file and loads data. Returns TRUE on success, FALSE // otherwise. - // NOTE: Any call to this method will result into linking against libxml - // and app's binary size will grow by ca. 250kB - bool Load(const wxString& filename, wxXmlIOType io_type = wxXML_IO_AUTO); - bool Load(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO); + bool Load(const wxString& filename, + const wxString& encoding = wxT("UTF-8")); + bool Load(wxInputStream& stream, + const wxString& encoding = wxT("UTF-8")); // Saves document as .xml file. - bool Save(const wxString& filename, - wxXmlIOType io_type = wxXML_IO_TEXT_OUTPUT) const; - bool Save(wxOutputStream& stream, - wxXmlIOType io_type = wxXML_IO_TEXT_OUTPUT) const; + bool Save(const wxString& filename) const; + bool Save(wxOutputStream& stream) const; bool IsOk() const { return m_root != NULL; } @@ -215,50 +194,30 @@ public: wxString GetVersion() const { return m_version; } // Returns encoding of document (may be empty). // Note: this is the encoding original fail was saved in, *not* the - // encoding of in-memory representation! Data in wxXmlNode are always - // stored in wchar_t (in Unicode build) or UTF-8 encoded - // (if wxUSE_UNICODE is 0). - wxString GetEncoding() const { return m_encoding; } + // encoding of in-memory representation! + wxString GetFileEncoding() const { return m_fileEncoding; } // Write-access methods: void SetRoot(wxXmlNode *node) { delete m_root ; m_root = node; } void SetVersion(const wxString& version) { m_version = version; } - void SetEncoding(const wxString& encoding) { m_encoding = encoding; } - - static void AddHandler(wxXmlIOHandler *handler); - static void CleanUpHandlers(); - static void InitStandardHandlers(); + void SetFileEncoding(const wxString& encoding) { m_fileEncoding = encoding; } -protected: - static wxList *sm_handlers; +#if !wxUSE_UNICODE + // Returns encoding of in-memory representation of the document + // (same as passed to Load or ctor, defaults to UTF-8). + // NB: this is meaningless in Unicode build where data are stored as wchar_t* + wxString GetEncoding() const { return m_encoding; } +#endif private: - wxString m_version, m_encoding; + wxString m_version; + wxString m_fileEncoding; +#if !wxUSE_UNICODE + wxString m_encoding; +#endif wxXmlNode *m_root; void DoCopy(const wxXmlDocument& doc); }; - - -// wxXmlIOHandler takes care of loading and/or saving XML data. -// see xmlio.h for available handlers - -class WXXMLDLLEXPORT wxXmlIOHandler : public wxObject -{ - public: - wxXmlIOHandler() {} - - virtual wxXmlIOType GetType() = 0; - virtual bool CanLoad(wxInputStream& stream) = 0; - virtual bool CanSave() = 0; - - virtual bool Load(wxInputStream& stream, wxXmlDocument& doc) = 0; - virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc) = 0; -}; - - - -void wxXmlInitXmlModule(); - #endif // _WX_XML_H_