switched wxXML to expat parser; some formatting mods

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@9976 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Václav Slavík
2001-05-02 23:01:00 +00:00
parent 7edb85b724
commit eb8671f277
34 changed files with 518 additions and 483 deletions

View File

@@ -24,7 +24,7 @@ class WXDLLEXPORT wxCheckListXmlHandler : public wxXmlResourceHandler
virtual wxObject *DoCreateResource(); virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideBox; bool m_insideBox;
wxArrayString strList; wxArrayString strList;
}; };

View File

@@ -24,7 +24,7 @@ class WXDLLEXPORT wxChoiceXmlHandler : public wxXmlResourceHandler
virtual wxObject *DoCreateResource(); virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideBox; bool m_insideBox;
wxArrayString strList; wxArrayString strList;
}; };

View File

@@ -26,7 +26,7 @@ class WXDLLEXPORT wxComboBoxXmlHandler : public wxXmlResourceHandler
virtual wxObject *DoCreateResource(); virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideBox; bool m_insideBox;
wxArrayString strList; wxArrayString strList;
}; };

View File

@@ -26,7 +26,7 @@ class WXDLLEXPORT wxListBoxXmlHandler : public wxXmlResourceHandler
virtual wxObject *DoCreateResource(); virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideBox; bool m_insideBox;
wxArrayString strList; wxArrayString strList;
}; };

View File

@@ -25,7 +25,7 @@ class WXDLLEXPORT wxMenuXmlHandler : public wxXmlResourceHandler
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideMenu; bool m_insideMenu;
}; };
class WXDLLEXPORT wxMenuBarXmlHandler : public wxXmlResourceHandler class WXDLLEXPORT wxMenuBarXmlHandler : public wxXmlResourceHandler

View File

@@ -28,8 +28,8 @@ class WXDLLEXPORT wxNotebookXmlHandler : public wxXmlResourceHandler
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_IsInside; bool m_isInside;
wxNotebook *m_Notebook; wxNotebook *m_notebook;
}; };
#endif #endif

View File

@@ -26,7 +26,7 @@ class WXDLLEXPORT wxRadioBoxXmlHandler : public wxXmlResourceHandler
virtual wxObject *DoCreateResource(); virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_InsideBox; bool m_insideBox;
wxArrayString strList; wxArrayString strList;
}; };

View File

@@ -28,8 +28,8 @@ class WXDLLEXPORT wxSizerXmlHandler : public wxXmlResourceHandler
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_IsInside; bool m_isInside;
wxSizer *m_ParentSizer; wxSizer *m_parentSizer;
bool IsSizerNode(wxXmlNode *node); bool IsSizerNode(wxXmlNode *node);
}; };

View File

@@ -29,8 +29,8 @@ class WXDLLEXPORT wxToolBarXmlHandler : public wxXmlResourceHandler
virtual bool CanHandle(wxXmlNode *node); virtual bool CanHandle(wxXmlNode *node);
private: private:
bool m_IsInside; bool m_isInside;
wxToolBar *m_Toolbar; wxToolBar *m_toolbar;
}; };
#endif #endif

View File

@@ -54,7 +54,8 @@ enum wxXmlNodeType
enum wxXmlIOType enum wxXmlIOType
{ {
wxXML_IO_AUTO = 0, // detect it automatically wxXML_IO_AUTO = 0, // detect it automatically
wxXML_IO_LIBXML, // use libxml2 to parse/save XML document 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_BIN, // save in binary uncompressed proprietary format
wxXML_IO_BINZ // svae in binary zlib-compressed proprietary format wxXML_IO_BINZ // svae in binary zlib-compressed proprietary format
}; };
@@ -67,23 +68,24 @@ enum wxXmlIOType
class WXDLLEXPORT wxXmlProperty class WXDLLEXPORT wxXmlProperty
{ {
public: public:
wxXmlProperty() : m_Next(NULL) {} wxXmlProperty() : m_next(NULL) {}
wxXmlProperty(const wxString& name, const wxString& value, wxXmlProperty *next) wxXmlProperty(const wxString& name, const wxString& value,
: m_Name(name), m_Value(value), m_Next(next) {} wxXmlProperty *next)
~wxXmlProperty() { delete m_Next; } : m_name(name), m_value(value), m_next(next) {}
~wxXmlProperty() { delete m_next; }
wxString GetName() const { return m_Name; } wxString GetName() const { return m_name; }
wxString GetValue() const { return m_Value; } wxString GetValue() const { return m_value; }
wxXmlProperty *GetNext() const { return m_Next; } wxXmlProperty *GetNext() const { return m_next; }
void SetName(const wxString& name) { m_Name = name; } void SetName(const wxString& name) { m_name = name; }
void SetValue(const wxString& value) { m_Value = value; } void SetValue(const wxString& value) { m_value = value; }
void SetNext(wxXmlProperty *next) { m_Next = next; } void SetNext(wxXmlProperty *next) { m_next = next; }
private: private:
wxString m_Name; wxString m_name;
wxString m_Value; wxString m_value;
wxXmlProperty *m_Next; wxXmlProperty *m_next;
}; };
@@ -93,19 +95,26 @@ class WXDLLEXPORT wxXmlProperty
// are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
// element with name="title", irrelevant content and one child (wxXML_TEXT_NODE // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
// with content="hi"). // 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);
class WXDLLEXPORT wxXmlNode class WXDLLEXPORT wxXmlNode
{ {
public: public:
wxXmlNode() : m_Properties(NULL), m_Parent(NULL), wxXmlNode() : m_properties(NULL), m_parent(NULL),
m_Children(NULL), m_Next(NULL) {} m_children(NULL), m_next(NULL) {}
wxXmlNode(wxXmlNode *parent,wxXmlNodeType type, wxXmlNode(wxXmlNode *parent,wxXmlNodeType type,
const wxString& name, const wxString& content, const wxString& name, const wxString& content,
wxXmlProperty *props, wxXmlNode *next); wxXmlProperty *props, wxXmlNode *next);
~wxXmlNode() { delete m_Properties; delete m_Next; delete m_Children; } ~wxXmlNode() { delete m_properties; delete m_next; delete m_children; }
// copy ctor & operator=. Note that this does NOT copy syblings // copy ctor & operator=. Note that this does NOT copy syblings
// and parent pointer, i.e. m_Parent and m_Next will be NULL // and parent pointer, i.e. m_parent and m_next will be NULL
// after using copy ctor and are never unmodified by operator=. // after using copy ctor and are never unmodified by operator=.
// On the other hand, it DOES copy children and properties. // On the other hand, it DOES copy children and properties.
wxXmlNode(const wxXmlNode& node); wxXmlNode(const wxXmlNode& node);
@@ -121,36 +130,37 @@ class WXDLLEXPORT wxXmlNode
bool DeleteProperty(const wxString& name); bool DeleteProperty(const wxString& name);
// access methods: // access methods:
wxXmlNodeType GetType() const { return m_Type; } wxXmlNodeType GetType() const { return m_type; }
wxString GetName() const { return m_Name; } wxString GetName() const { return m_name; }
wxString GetContent() const { return m_Content; } wxString GetContent() const { return m_content; }
wxXmlNode *GetParent() const { return m_Parent; } wxXmlNode *GetParent() const { return m_parent; }
wxXmlNode *GetNext() const { return m_Next; } wxXmlNode *GetNext() const { return m_next; }
wxXmlNode *GetChildren() const { return m_Children; } wxXmlNode *GetChildren() const { return m_children; }
wxXmlProperty *GetProperties() const { return m_Properties; } wxXmlProperty *GetProperties() const { return m_properties; }
bool GetPropVal(const wxString& propName, wxString *value) const; bool GetPropVal(const wxString& propName, wxString *value) const;
wxString GetPropVal(const wxString& propName, const wxString& defaultVal) const; wxString GetPropVal(const wxString& propName,
const wxString& defaultVal) const;
bool HasProp(const wxString& propName) const; bool HasProp(const wxString& propName) const;
void SetType(wxXmlNodeType type) { m_Type = type; } void SetType(wxXmlNodeType type) { m_type = type; }
void SetName(const wxString& name) { m_Name = name; } void SetName(const wxString& name) { m_name = name; }
void SetContent(const wxString& con) { m_Content = con; } void SetContent(const wxString& con) { m_content = con; }
void SetParent(wxXmlNode *parent) { m_Parent = parent; } void SetParent(wxXmlNode *parent) { m_parent = parent; }
void SetNext(wxXmlNode *next) { m_Next = next; } void SetNext(wxXmlNode *next) { m_next = next; }
void SetChildren(wxXmlNode *child) { m_Children = child; } void SetChildren(wxXmlNode *child) { m_children = child; }
void SetProperties(wxXmlProperty *prop) { m_Properties = prop; } void SetProperties(wxXmlProperty *prop) { m_properties = prop; }
void AddProperty(wxXmlProperty *prop); void AddProperty(wxXmlProperty *prop);
private: private:
wxXmlNodeType m_Type; wxXmlNodeType m_type;
wxString m_Name; wxString m_name;
wxString m_Content; wxString m_content;
wxXmlProperty *m_Properties; wxXmlProperty *m_properties;
wxXmlNode *m_Parent, *m_Children, *m_Next; wxXmlNode *m_parent, *m_children, *m_next;
void DoCopy(const wxXmlNode& node); void DoCopy(const wxXmlNode& node);
}; };
@@ -168,10 +178,12 @@ class WXDLLEXPORT wxXmlNode
class WXDLLEXPORT wxXmlDocument : public wxObject class WXDLLEXPORT wxXmlDocument : public wxObject
{ {
public: public:
wxXmlDocument() : wxObject(), m_Version(wxT("1.0")), m_Root(NULL) {} wxXmlDocument() : wxObject(), m_version(wxT("1.0")), m_root(NULL) {}
wxXmlDocument(const wxString& filename, wxXmlIOType io_type = wxXML_IO_AUTO); wxXmlDocument(const wxString& filename,
wxXmlDocument(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO); wxXmlIOType io_type = wxXML_IO_AUTO);
~wxXmlDocument() { delete m_Root; } wxXmlDocument(wxInputStream& stream,
wxXmlIOType io_type = wxXML_IO_AUTO);
~wxXmlDocument() { delete m_root; }
wxXmlDocument(const wxXmlDocument& doc); wxXmlDocument(const wxXmlDocument& doc);
wxXmlDocument& operator=(const wxXmlDocument& doc); wxXmlDocument& operator=(const wxXmlDocument& doc);
@@ -184,32 +196,40 @@ class WXDLLEXPORT wxXmlDocument : public wxObject
bool Load(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO); bool Load(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO);
// Saves document as .xml file. // Saves document as .xml file.
bool Save(const wxString& filename, wxXmlIOType io_type) const; bool Save(const wxString& filename,
bool Save(wxOutputStream& stream, wxXmlIOType io_type) const; wxXmlIOType io_type = wxXML_IO_TEXT_OUTPUT) const;
bool Save(wxOutputStream& stream,
wxXmlIOType io_type = wxXML_IO_TEXT_OUTPUT) const;
bool IsOk() const { return m_root != NULL; }
// Returns root node of the document. // Returns root node of the document.
wxXmlNode *GetRoot() const { return m_Root; } wxXmlNode *GetRoot() const { return m_root; }
// Returns version of document (may be empty). // Returns version of document (may be empty).
wxString GetVersion() const { return m_Version; } wxString GetVersion() const { return m_version; }
// Returns encoding of document (may be empty). // Returns encoding of document (may be empty).
wxString GetEncoding() const { return m_Encoding; } // 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; }
// Write-access methods: // Write-access methods:
void SetRoot(wxXmlNode *node) { delete m_Root ; m_Root = node; } void SetRoot(wxXmlNode *node) { delete m_root ; m_root = node; }
void SetVersion(const wxString& version) { m_Version = version; } void SetVersion(const wxString& version) { m_version = version; }
void SetEncoding(const wxString& encoding) { m_Encoding = encoding; } void SetEncoding(const wxString& encoding) { m_encoding = encoding; }
static void AddHandler(wxXmlIOHandler *handler); static void AddHandler(wxXmlIOHandler *handler);
static void CleanUpHandlers(); static void CleanUpHandlers();
static void InitStandardHandlers(); static void InitStandardHandlers();
protected: protected:
static wxList *sm_Handlers; static wxList *sm_handlers;
private: private:
wxString m_Version, m_Encoding; wxString m_version, m_encoding;
wxXmlNode *m_Root; wxXmlNode *m_root;
void DoCopy(const wxXmlDocument& doc); void DoCopy(const wxXmlDocument& doc);
}; };

View File

@@ -20,6 +20,30 @@
#include "wx/xml/xml.h" #include "wx/xml/xml.h"
class WXDLLEXPORT wxXmlIOHandlerExpat : public wxXmlIOHandler
{
public:
virtual wxXmlIOType GetType() { return wxXML_IO_EXPAT; }
virtual bool CanLoad(wxInputStream& stream);
virtual bool CanSave() { return FALSE; }
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc) { return FALSE; }
};
class WXDLLEXPORT wxXmlIOHandlerWriter : public wxXmlIOHandler
{
public:
virtual wxXmlIOType GetType() { return wxXML_IO_TEXT_OUTPUT; }
virtual bool CanLoad(wxInputStream& stream) { return FALSE; }
virtual bool CanSave() { return TRUE; }
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc) { return FALSE; }
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
};
class WXDLLEXPORT wxXmlIOHandlerBin : public wxXmlIOHandler class WXDLLEXPORT wxXmlIOHandlerBin : public wxXmlIOHandler
{ {
public: public:
@@ -56,17 +80,4 @@ class WXDLLEXPORT wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin
#endif #endif
class WXDLLEXPORT wxXmlIOHandlerLibxml : public wxXmlIOHandler
{
public:
virtual wxXmlIOType GetType() { return wxXML_IO_LIBXML; }
virtual bool CanLoad(wxInputStream& stream);
virtual bool CanSave();
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
};
#endif // _WX_XMLIO_H_ #endif // _WX_XMLIO_H_

View File

@@ -136,15 +136,15 @@ class WXDLLEXPORT wxXmlResource : public wxObject
// match current platform // match current platform
void ProcessPlatformProperty(wxXmlNode *node); void ProcessPlatformProperty(wxXmlNode *node);
bool GetUseLocale() { return m_UseLocale; } bool GetUseLocale() { return m_useLocale; }
private: private:
bool m_UseLocale; bool m_useLocale;
wxList m_Handlers; wxList m_handlers;
wxXmlResourceDataRecords m_Data; wxXmlResourceDataRecords m_data;
#if wxUSE_FILESYSTEM #if wxUSE_FILESYSTEM
wxFileSystem m_CurFileSystem; wxFileSystem m_curFileSystem;
wxFileSystem& GetCurFileSystem() { return m_CurFileSystem; } wxFileSystem& GetCurFileSystem() { return m_curFileSystem; }
#endif #endif
friend class wxXmlResourceHandler; friend class wxXmlResourceHandler;
@@ -194,7 +194,8 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
// that is often neccessary to create resource // that is often neccessary to create resource
// if instance != NULL it should not create new instance via 'new' but // if instance != NULL it should not create new instance via 'new' but
// rather use this one and call its Create method // rather use this one and call its Create method
wxObject *CreateResource(wxXmlNode *node, wxObject *parent, wxObject *instance); wxObject *CreateResource(wxXmlNode *node, wxObject *parent,
wxObject *instance);
// This one is called from CreateResource after variables // This one is called from CreateResource after variables
// were filled // were filled
@@ -204,20 +205,20 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
// resource from it, FALSE otherwise. // resource from it, FALSE otherwise.
virtual bool CanHandle(wxXmlNode *node) = 0; virtual bool CanHandle(wxXmlNode *node) = 0;
void SetParentResource(wxXmlResource *res) { m_Resource = res; } void SetParentResource(wxXmlResource *res) { m_resource = res; }
protected: protected:
wxXmlResource *m_Resource; wxXmlResource *m_resource;
wxArrayString m_StyleNames; wxArrayString m_styleNames;
wxArrayInt m_StyleValues; wxArrayInt m_styleValues;
// Variables (filled by CreateResource) // Variables (filled by CreateResource)
wxXmlNode *m_Node; wxXmlNode *m_node;
wxString m_Class; wxString m_class;
wxObject *m_Parent, *m_Instance; wxObject *m_parent, *m_instance;
wxWindow *m_ParentAsWindow, *m_InstanceAsWindow; wxWindow *m_parentAsWindow, *m_instanceAsWindow;
// --- Handy methods: // --- Handy methods:
@@ -278,8 +279,10 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0); wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0);
// Get bitmap: // Get bitmap:
wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), wxSize size = wxDefaultSize); wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
wxIcon GetIcon(const wxString& param = wxT("icon"), wxSize size = wxDefaultSize); wxSize size = wxDefaultSize);
wxIcon GetIcon(const wxString& param = wxT("icon"),
wxSize size = wxDefaultSize);
// Get font: // Get font:
wxFont GetFont(const wxString& param = wxT("font")); wxFont GetFont(const wxString& param = wxT("font"));
@@ -289,11 +292,12 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE); void CreateChildren(wxObject *parent, bool this_hnd_only = FALSE);
void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL); void CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL);
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL) wxObject *CreateResFromNode(wxXmlNode *node,
{ return m_Resource->CreateResFromNode(node, parent, instance); } wxObject *parent, wxObject *instance = NULL)
{ return m_resource->CreateResFromNode(node, parent, instance); }
// helper // helper
wxFileSystem& GetCurFileSystem() { return m_Resource->GetCurFileSystem(); } wxFileSystem& GetCurFileSystem() { return m_resource->GetCurFileSystem(); }
}; };
#define ADD_STYLE(style) AddStyle(wxT(#style), style) #define ADD_STYLE(style) AddStyle(wxT(#style), style)