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:
parent
7edb85b724
commit
eb8671f277
@ -24,7 +24,7 @@ class WXDLLEXPORT wxCheckListXmlHandler : public wxXmlResourceHandler
|
||||
virtual wxObject *DoCreateResource();
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
private:
|
||||
bool m_InsideBox;
|
||||
bool m_insideBox;
|
||||
wxArrayString strList;
|
||||
};
|
||||
|
||||
|
@ -24,7 +24,7 @@ class WXDLLEXPORT wxChoiceXmlHandler : public wxXmlResourceHandler
|
||||
virtual wxObject *DoCreateResource();
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
private:
|
||||
bool m_InsideBox;
|
||||
bool m_insideBox;
|
||||
wxArrayString strList;
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ class WXDLLEXPORT wxComboBoxXmlHandler : public wxXmlResourceHandler
|
||||
virtual wxObject *DoCreateResource();
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
private:
|
||||
bool m_InsideBox;
|
||||
bool m_insideBox;
|
||||
wxArrayString strList;
|
||||
};
|
||||
|
||||
|
@ -26,7 +26,7 @@ class WXDLLEXPORT wxListBoxXmlHandler : public wxXmlResourceHandler
|
||||
virtual wxObject *DoCreateResource();
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
private:
|
||||
bool m_InsideBox;
|
||||
bool m_insideBox;
|
||||
wxArrayString strList;
|
||||
};
|
||||
|
||||
|
@ -25,7 +25,7 @@ class WXDLLEXPORT wxMenuXmlHandler : public wxXmlResourceHandler
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
|
||||
private:
|
||||
bool m_InsideMenu;
|
||||
bool m_insideMenu;
|
||||
};
|
||||
|
||||
class WXDLLEXPORT wxMenuBarXmlHandler : public wxXmlResourceHandler
|
||||
|
@ -28,8 +28,8 @@ class WXDLLEXPORT wxNotebookXmlHandler : public wxXmlResourceHandler
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
|
||||
private:
|
||||
bool m_IsInside;
|
||||
wxNotebook *m_Notebook;
|
||||
bool m_isInside;
|
||||
wxNotebook *m_notebook;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -26,7 +26,7 @@ class WXDLLEXPORT wxRadioBoxXmlHandler : public wxXmlResourceHandler
|
||||
virtual wxObject *DoCreateResource();
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
private:
|
||||
bool m_InsideBox;
|
||||
bool m_insideBox;
|
||||
wxArrayString strList;
|
||||
};
|
||||
|
||||
|
@ -28,8 +28,8 @@ class WXDLLEXPORT wxSizerXmlHandler : public wxXmlResourceHandler
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
|
||||
private:
|
||||
bool m_IsInside;
|
||||
wxSizer *m_ParentSizer;
|
||||
bool m_isInside;
|
||||
wxSizer *m_parentSizer;
|
||||
|
||||
bool IsSizerNode(wxXmlNode *node);
|
||||
};
|
||||
|
@ -29,8 +29,8 @@ class WXDLLEXPORT wxToolBarXmlHandler : public wxXmlResourceHandler
|
||||
virtual bool CanHandle(wxXmlNode *node);
|
||||
|
||||
private:
|
||||
bool m_IsInside;
|
||||
wxToolBar *m_Toolbar;
|
||||
bool m_isInside;
|
||||
wxToolBar *m_toolbar;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -54,7 +54,8 @@ enum wxXmlNodeType
|
||||
enum wxXmlIOType
|
||||
{
|
||||
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_BINZ // svae in binary zlib-compressed proprietary format
|
||||
};
|
||||
@ -67,23 +68,24 @@ enum wxXmlIOType
|
||||
class WXDLLEXPORT wxXmlProperty
|
||||
{
|
||||
public:
|
||||
wxXmlProperty() : m_Next(NULL) {}
|
||||
wxXmlProperty(const wxString& name, const wxString& value, wxXmlProperty *next)
|
||||
: m_Name(name), m_Value(value), m_Next(next) {}
|
||||
~wxXmlProperty() { delete m_Next; }
|
||||
wxXmlProperty() : m_next(NULL) {}
|
||||
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; }
|
||||
wxXmlProperty *GetNext() const { return m_Next; }
|
||||
wxString GetName() const { return m_name; }
|
||||
wxString GetValue() const { return m_value; }
|
||||
wxXmlProperty *GetNext() const { return m_next; }
|
||||
|
||||
void SetName(const wxString& name) { m_Name = name; }
|
||||
void SetValue(const wxString& value) { m_Value = value; }
|
||||
void SetNext(wxXmlProperty *next) { m_Next = next; }
|
||||
void SetName(const wxString& name) { m_name = name; }
|
||||
void SetValue(const wxString& value) { m_value = value; }
|
||||
void SetNext(wxXmlProperty *next) { m_next = next; }
|
||||
|
||||
private:
|
||||
wxString m_Name;
|
||||
wxString m_Value;
|
||||
wxXmlProperty *m_Next;
|
||||
wxString m_name;
|
||||
wxString m_value;
|
||||
wxXmlProperty *m_next;
|
||||
};
|
||||
|
||||
|
||||
@ -93,19 +95,26 @@ class WXDLLEXPORT wxXmlProperty
|
||||
// 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
|
||||
// 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
|
||||
{
|
||||
public:
|
||||
wxXmlNode() : m_Properties(NULL), m_Parent(NULL),
|
||||
m_Children(NULL), m_Next(NULL) {}
|
||||
wxXmlNode() : m_properties(NULL), m_parent(NULL),
|
||||
m_children(NULL), m_next(NULL) {}
|
||||
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() { delete m_properties; delete m_next; delete m_children; }
|
||||
|
||||
// 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=.
|
||||
// On the other hand, it DOES copy children and properties.
|
||||
wxXmlNode(const wxXmlNode& node);
|
||||
@ -121,36 +130,37 @@ class WXDLLEXPORT wxXmlNode
|
||||
bool DeleteProperty(const wxString& name);
|
||||
|
||||
// access methods:
|
||||
wxXmlNodeType GetType() const { return m_Type; }
|
||||
wxString GetName() const { return m_Name; }
|
||||
wxString GetContent() const { return m_Content; }
|
||||
wxXmlNodeType GetType() const { return m_type; }
|
||||
wxString GetName() const { return m_name; }
|
||||
wxString GetContent() const { return m_content; }
|
||||
|
||||
wxXmlNode *GetParent() const { return m_Parent; }
|
||||
wxXmlNode *GetNext() const { return m_Next; }
|
||||
wxXmlNode *GetChildren() const { return m_Children; }
|
||||
wxXmlNode *GetParent() const { return m_parent; }
|
||||
wxXmlNode *GetNext() const { return m_next; }
|
||||
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;
|
||||
wxString GetPropVal(const wxString& propName, const wxString& defaultVal) const;
|
||||
wxString GetPropVal(const wxString& propName,
|
||||
const wxString& defaultVal) const;
|
||||
bool HasProp(const wxString& propName) const;
|
||||
|
||||
void SetType(wxXmlNodeType type) { m_Type = type; }
|
||||
void SetName(const wxString& name) { m_Name = name; }
|
||||
void SetContent(const wxString& con) { m_Content = con; }
|
||||
void SetType(wxXmlNodeType type) { m_type = type; }
|
||||
void SetName(const wxString& name) { m_name = name; }
|
||||
void SetContent(const wxString& con) { m_content = con; }
|
||||
|
||||
void SetParent(wxXmlNode *parent) { m_Parent = parent; }
|
||||
void SetNext(wxXmlNode *next) { m_Next = next; }
|
||||
void SetChildren(wxXmlNode *child) { m_Children = child; }
|
||||
void SetParent(wxXmlNode *parent) { m_parent = parent; }
|
||||
void SetNext(wxXmlNode *next) { m_next = next; }
|
||||
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);
|
||||
|
||||
private:
|
||||
wxXmlNodeType m_Type;
|
||||
wxString m_Name;
|
||||
wxString m_Content;
|
||||
wxXmlProperty *m_Properties;
|
||||
wxXmlNode *m_Parent, *m_Children, *m_Next;
|
||||
wxXmlNodeType m_type;
|
||||
wxString m_name;
|
||||
wxString m_content;
|
||||
wxXmlProperty *m_properties;
|
||||
wxXmlNode *m_parent, *m_children, *m_next;
|
||||
|
||||
void DoCopy(const wxXmlNode& node);
|
||||
};
|
||||
@ -168,10 +178,12 @@ class WXDLLEXPORT wxXmlNode
|
||||
class WXDLLEXPORT wxXmlDocument : public wxObject
|
||||
{
|
||||
public:
|
||||
wxXmlDocument() : wxObject(), m_Version(wxT("1.0")), m_Root(NULL) {}
|
||||
wxXmlDocument(const wxString& filename, wxXmlIOType io_type = wxXML_IO_AUTO);
|
||||
wxXmlDocument(wxInputStream& stream, wxXmlIOType io_type = wxXML_IO_AUTO);
|
||||
~wxXmlDocument() { delete m_Root; }
|
||||
wxXmlDocument() : wxObject(), m_version(wxT("1.0")), m_root(NULL) {}
|
||||
wxXmlDocument(const wxString& filename,
|
||||
wxXmlIOType io_type = wxXML_IO_AUTO);
|
||||
wxXmlDocument(wxInputStream& stream,
|
||||
wxXmlIOType io_type = wxXML_IO_AUTO);
|
||||
~wxXmlDocument() { delete m_root; }
|
||||
|
||||
wxXmlDocument(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);
|
||||
|
||||
// Saves document as .xml file.
|
||||
bool Save(const wxString& filename, wxXmlIOType io_type) const;
|
||||
bool Save(wxOutputStream& stream, wxXmlIOType io_type) const;
|
||||
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 IsOk() const { return m_root != NULL; }
|
||||
|
||||
// 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).
|
||||
wxString GetVersion() const { return m_Version; }
|
||||
wxString GetVersion() const { return m_version; }
|
||||
// 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:
|
||||
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; }
|
||||
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();
|
||||
|
||||
protected:
|
||||
static wxList *sm_Handlers;
|
||||
static wxList *sm_handlers;
|
||||
|
||||
private:
|
||||
wxString m_Version, m_Encoding;
|
||||
wxXmlNode *m_Root;
|
||||
wxString m_version, m_encoding;
|
||||
wxXmlNode *m_root;
|
||||
|
||||
void DoCopy(const wxXmlDocument& doc);
|
||||
};
|
||||
|
@ -20,6 +20,30 @@
|
||||
#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
|
||||
{
|
||||
public:
|
||||
@ -56,17 +80,4 @@ class WXDLLEXPORT wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin
|
||||
#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_
|
||||
|
@ -136,15 +136,15 @@ class WXDLLEXPORT wxXmlResource : public wxObject
|
||||
// match current platform
|
||||
void ProcessPlatformProperty(wxXmlNode *node);
|
||||
|
||||
bool GetUseLocale() { return m_UseLocale; }
|
||||
bool GetUseLocale() { return m_useLocale; }
|
||||
|
||||
private:
|
||||
bool m_UseLocale;
|
||||
wxList m_Handlers;
|
||||
wxXmlResourceDataRecords m_Data;
|
||||
bool m_useLocale;
|
||||
wxList m_handlers;
|
||||
wxXmlResourceDataRecords m_data;
|
||||
#if wxUSE_FILESYSTEM
|
||||
wxFileSystem m_CurFileSystem;
|
||||
wxFileSystem& GetCurFileSystem() { return m_CurFileSystem; }
|
||||
wxFileSystem m_curFileSystem;
|
||||
wxFileSystem& GetCurFileSystem() { return m_curFileSystem; }
|
||||
#endif
|
||||
|
||||
friend class wxXmlResourceHandler;
|
||||
@ -194,7 +194,8 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
// that is often neccessary to create resource
|
||||
// if instance != NULL it should not create new instance via 'new' but
|
||||
// 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
|
||||
// were filled
|
||||
@ -204,20 +205,20 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
// resource from it, FALSE otherwise.
|
||||
virtual bool CanHandle(wxXmlNode *node) = 0;
|
||||
|
||||
void SetParentResource(wxXmlResource *res) { m_Resource = res; }
|
||||
void SetParentResource(wxXmlResource *res) { m_resource = res; }
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
wxXmlResource *m_Resource;
|
||||
wxArrayString m_StyleNames;
|
||||
wxArrayInt m_StyleValues;
|
||||
wxXmlResource *m_resource;
|
||||
wxArrayString m_styleNames;
|
||||
wxArrayInt m_styleValues;
|
||||
|
||||
// Variables (filled by CreateResource)
|
||||
wxXmlNode *m_Node;
|
||||
wxString m_Class;
|
||||
wxObject *m_Parent, *m_Instance;
|
||||
wxWindow *m_ParentAsWindow, *m_InstanceAsWindow;
|
||||
wxXmlNode *m_node;
|
||||
wxString m_class;
|
||||
wxObject *m_parent, *m_instance;
|
||||
wxWindow *m_parentAsWindow, *m_instanceAsWindow;
|
||||
|
||||
// --- Handy methods:
|
||||
|
||||
@ -278,8 +279,10 @@ class WXDLLEXPORT wxXmlResourceHandler : public wxObject
|
||||
wxCoord GetDimension(const wxString& param, wxCoord defaultv = 0);
|
||||
|
||||
// Get bitmap:
|
||||
wxBitmap GetBitmap(const wxString& param = wxT("bitmap"), wxSize size = wxDefaultSize);
|
||||
wxIcon GetIcon(const wxString& param = wxT("icon"), wxSize size = wxDefaultSize);
|
||||
wxBitmap GetBitmap(const wxString& param = wxT("bitmap"),
|
||||
wxSize size = wxDefaultSize);
|
||||
wxIcon GetIcon(const wxString& param = wxT("icon"),
|
||||
wxSize size = wxDefaultSize);
|
||||
|
||||
// Get 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 CreateChildrenPrivately(wxObject *parent, wxXmlNode *rootnode = NULL);
|
||||
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL)
|
||||
{ return m_Resource->CreateResFromNode(node, parent, instance); }
|
||||
wxObject *CreateResFromNode(wxXmlNode *node,
|
||||
wxObject *parent, wxObject *instance = NULL)
|
||||
{ return m_resource->CreateResFromNode(node, parent, instance); }
|
||||
|
||||
// helper
|
||||
wxFileSystem& GetCurFileSystem() { return m_Resource->GetCurFileSystem(); }
|
||||
wxFileSystem& GetCurFileSystem() { return m_resource->GetCurFileSystem(); }
|
||||
};
|
||||
|
||||
#define ADD_STYLE(style) AddStyle(wxT(#style), style)
|
||||
|
Loading…
Reference in New Issue
Block a user