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

@ -20,18 +20,18 @@
class WXDLLEXPORT wxBitmapXmlHandler : public wxXmlResourceHandler
{
public:
wxBitmapXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxBitmapXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
class WXDLLEXPORT wxIconXmlHandler : public wxXmlResourceHandler
{
public:
wxIconXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxIconXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxBitmapButtonXmlHandler : public wxXmlResourceHandler
{
public:
wxBitmapButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxBitmapButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxButtonXmlHandler : public wxXmlResourceHandler
{
public:
wxButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxCalendarCtrlXmlHandler : public wxXmlResourceHandler
{
public:
wxCalendarCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxCalendarCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -22,10 +22,10 @@
class WXDLLEXPORT wxCheckBoxXmlHandler : public wxXmlResourceHandler
{
public:
wxCheckBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxCheckBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

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

View File

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

View File

@ -21,13 +21,13 @@
class WXDLLEXPORT wxComboBoxXmlHandler : public wxXmlResourceHandler
{
public:
wxComboBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_InsideBox;
wxArrayString strList;
public:
wxComboBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_insideBox;
wxArrayString strList;
};
#endif

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxDialogXmlHandler : public wxXmlResourceHandler
{
public:
wxDialogXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxDialogXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxFrameXmlHandler : public wxXmlResourceHandler
{
public:
wxFrameXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxFrameXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -29,10 +29,10 @@ class WXDLLEXPORT wxGaugeXmlHandler : public wxXmlResourceHandler
wxGAUGE_DEFAULT_RANGE = 100
};
public:
wxGaugeXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxGaugeXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -23,10 +23,10 @@
class WXDLLEXPORT wxHtmlWindowXmlHandler : public wxXmlResourceHandler
{
public:
wxHtmlWindowXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxHtmlWindowXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -21,13 +21,13 @@
class WXDLLEXPORT wxListBoxXmlHandler : public wxXmlResourceHandler
{
public:
wxListBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_InsideBox;
wxArrayString strList;
public:
wxListBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_insideBox;
wxArrayString strList;
};
#endif

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxListCtrlXmlHandler : public wxXmlResourceHandler
{
public:
wxListCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxListCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -19,13 +19,13 @@
class WXDLLEXPORT wxMenuXmlHandler : public wxXmlResourceHandler
{
public:
wxMenuXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_InsideMenu;
public:
wxMenuXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_insideMenu;
};
class WXDLLEXPORT wxMenuBarXmlHandler : public wxXmlResourceHandler

View File

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

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxPanelXmlHandler : public wxXmlResourceHandler
{
public:
wxPanelXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxPanelXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -22,10 +22,10 @@
class WXDLLEXPORT wxRadioButtonXmlHandler : public wxXmlResourceHandler
{
public:
wxRadioButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxRadioButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -21,13 +21,13 @@
class WXDLLEXPORT wxRadioBoxXmlHandler : public wxXmlResourceHandler
{
public:
wxRadioBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_InsideBox;
wxArrayString strList;
public:
wxRadioBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_insideBox;
wxArrayString strList;
};
#endif

View File

@ -29,10 +29,10 @@ class WXDLLEXPORT wxScrollBarXmlHandler : public wxXmlResourceHandler
wxSL_DEFAULT_MAX = 100
};
public:
wxScrollBarXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxScrollBarXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -22,16 +22,16 @@ class WXDLLEXPORT wxSizer;
class WXDLLEXPORT wxSizerXmlHandler : public wxXmlResourceHandler
{
public:
wxSizerXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxSizerXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
private:
bool m_isInside;
wxSizer *m_parentSizer;
private:
bool m_IsInside;
wxSizer *m_ParentSizer;
bool IsSizerNode(wxXmlNode *node);
bool IsSizerNode(wxXmlNode *node);
};

View File

@ -29,10 +29,10 @@ class WXDLLEXPORT wxSliderXmlHandler : public wxXmlResourceHandler
wxSL_DEFAULT_MAX = 100
};
public:
wxSliderXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxSliderXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -28,10 +28,10 @@ class WXDLLEXPORT wxSpinButtonXmlHandler : public wxXmlResourceHandler
wxSP_DEFAULT_MAX = 100
};
public:
wxSpinButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxSpinButtonXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif
@ -45,10 +45,10 @@ class WXDLLEXPORT wxSpinCtrlXmlHandler : public wxXmlResourceHandler
wxSP_DEFAULT_MAX = 100
};
public:
wxSpinCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxSpinCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxStaticBitmapXmlHandler : public wxXmlResourceHandler
{
public:
wxStaticBitmapXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxStaticBitmapXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxStaticBoxXmlHandler : public wxXmlResourceHandler
{
public:
wxStaticBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxStaticBoxXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -21,10 +21,10 @@
class WXDLLEXPORT wxStaticLineXmlHandler : public wxXmlResourceHandler
{
public:
wxStaticLineXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxStaticLineXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};
#endif

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxStaticTextXmlHandler : public wxXmlResourceHandler
{
public:
wxStaticTextXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxStaticTextXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxTextCtrlXmlHandler : public wxXmlResourceHandler
{
public:
wxTextCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxTextCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

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

View File

@ -19,10 +19,10 @@
class WXDLLEXPORT wxTreeCtrlXmlHandler : public wxXmlResourceHandler
{
public:
wxTreeCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxTreeCtrlXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -20,10 +20,10 @@
class WXDLLEXPORT wxUnknownWidgetXmlHandler : public wxXmlResourceHandler
{
public:
wxUnknownWidgetXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
public:
wxUnknownWidgetXmlHandler();
virtual wxObject *DoCreateResource();
virtual bool CanHandle(wxXmlNode *node);
};

View File

@ -53,10 +53,11 @@ enum wxXmlNodeType
enum wxXmlIOType
{
wxXML_IO_AUTO = 0, // detect it automatically
wxXML_IO_LIBXML, // use libxml2 to parse/save XML document
wxXML_IO_BIN, // save in binary uncompressed proprietary format
wxXML_IO_BINZ // svae in binary zlib-compressed proprietary format
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
};
@ -66,24 +67,25 @@ 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; }
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; }
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; }
private:
wxString m_Name;
wxString m_Value;
wxXmlProperty *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; }
private:
wxString m_name;
wxString m_value;
wxXmlProperty *m_next;
};
@ -93,66 +95,74 @@ 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(wxXmlNode *parent,wxXmlNodeType type,
const wxString& name, const wxString& content,
wxXmlProperty *props, wxXmlNode *next);
~wxXmlNode() { delete m_Properties; delete m_Next; delete m_Children; }
public:
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; }
// copy ctor & operator=. Note that this does NOT copy syblings
// 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);
wxXmlNode& operator=(const wxXmlNode& node);
// user-friendly creation:
wxXmlNode(wxXmlNodeType type, const wxString& name,
const wxString& content = wxEmptyString);
void AddChild(wxXmlNode *child);
void InsertChild(wxXmlNode *child, wxXmlNode *before_node);
bool RemoveChild(wxXmlNode *child);
void AddProperty(const wxString& name, const wxString& value);
bool DeleteProperty(const wxString& name);
// copy ctor & operator=. Note that this does NOT copy syblings
// 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);
wxXmlNode& operator=(const wxXmlNode& node);
// access methods:
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; }
// user-friendly creation:
wxXmlNode(wxXmlNodeType type, const wxString& name,
const wxString& content = wxEmptyString);
void AddChild(wxXmlNode *child);
void InsertChild(wxXmlNode *child, wxXmlNode *before_node);
bool RemoveChild(wxXmlNode *child);
void AddProperty(const wxString& name, const wxString& value);
bool DeleteProperty(const wxString& name);
wxXmlProperty *GetProperties() const { return m_Properties; }
bool GetPropVal(const wxString& propName, wxString *value) 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 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 AddProperty(wxXmlProperty *prop);
// access methods:
wxXmlNodeType GetType() const { return m_type; }
wxString GetName() const { return m_name; }
wxString GetContent() const { return m_content; }
private:
wxXmlNodeType m_Type;
wxString m_Name;
wxString m_Content;
wxXmlProperty *m_Properties;
wxXmlNode *m_Parent, *m_Children, *m_Next;
wxXmlNode *GetParent() const { return m_parent; }
wxXmlNode *GetNext() const { return m_next; }
wxXmlNode *GetChildren() const { return m_children; }
void DoCopy(const wxXmlNode& node);
wxXmlProperty *GetProperties() const { return m_properties; }
bool GetPropVal(const wxString& propName, wxString *value) 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 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 AddProperty(wxXmlProperty *prop);
private:
wxXmlNodeType m_type;
wxString m_name;
wxString m_content;
wxXmlProperty *m_properties;
wxXmlNode *m_parent, *m_children, *m_next;
void DoCopy(const wxXmlNode& node);
};
@ -167,51 +177,61 @@ 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(const wxXmlDocument& doc);
wxXmlDocument& operator=(const wxXmlDocument& doc);
// 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);
// Saves document as .xml file.
bool Save(const wxString& filename, wxXmlIOType io_type) const;
bool Save(wxOutputStream& stream, wxXmlIOType io_type) const;
// Returns root node of the document.
wxXmlNode *GetRoot() const { return m_Root; }
// Returns version of document (may be empty).
wxString GetVersion() const { return m_Version; }
// Returns encoding of document (may be empty).
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; }
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; }
static void AddHandler(wxXmlIOHandler *handler);
static void CleanUpHandlers();
static void InitStandardHandlers();
wxXmlDocument(const wxXmlDocument& doc);
wxXmlDocument& operator=(const wxXmlDocument& doc);
protected:
static wxList *sm_Handlers;
// 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);
private:
wxString m_Version, m_Encoding;
wxXmlNode *m_Root;
void DoCopy(const wxXmlDocument& doc);
// 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 IsOk() const { return m_root != NULL; }
// Returns root node of the document.
wxXmlNode *GetRoot() const { return m_root; }
// Returns version of document (may be empty).
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; }
// 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();
protected:
static wxList *sm_handlers;
private:
wxString m_version, m_encoding;
wxXmlNode *m_root;
void DoCopy(const wxXmlDocument& doc);
};

View File

@ -20,21 +20,45 @@
#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:
wxXmlIOHandlerBin() {}
public:
wxXmlIOHandlerBin() {}
virtual wxXmlIOType GetType() { return wxXML_IO_BIN; }
virtual bool CanLoad(wxInputStream& stream);
virtual bool CanSave() { return TRUE; }
virtual wxXmlIOType GetType() { return wxXML_IO_BIN; }
virtual bool CanLoad(wxInputStream& stream);
virtual bool CanSave() { return TRUE; }
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
protected:
wxString ReadHeader(wxInputStream& stream);
void WriteHeader(wxOutputStream& stream, const wxString& header);
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
protected:
wxString ReadHeader(wxInputStream& stream);
void WriteHeader(wxOutputStream& stream, const wxString& header);
};
@ -43,30 +67,17 @@ class WXDLLEXPORT wxXmlIOHandlerBin : public wxXmlIOHandler
class WXDLLEXPORT wxXmlIOHandlerBinZ : public wxXmlIOHandlerBin
{
public:
wxXmlIOHandlerBinZ() {}
public:
wxXmlIOHandlerBinZ() {}
virtual wxXmlIOType GetType() { return wxXML_IO_BINZ; }
virtual bool CanLoad(wxInputStream& stream);
virtual wxXmlIOType GetType() { return wxXML_IO_BINZ; }
virtual bool CanLoad(wxInputStream& stream);
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
virtual bool Load(wxInputStream& stream, wxXmlDocument& doc);
virtual bool Save(wxOutputStream& stream, const wxXmlDocument& doc);
};
#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_

View File

@ -40,13 +40,13 @@ class WXDLLEXPORT wxXmlResourceHandler;
class WXDLLEXPORT wxXmlResourceDataRecord
{
public:
wxXmlResourceDataRecord() : Doc(NULL), Time(wxDateTime::Now()) {}
~wxXmlResourceDataRecord() {delete Doc;}
wxString File;
wxXmlDocument *Doc;
wxDateTime Time;
public:
wxXmlResourceDataRecord() : Doc(NULL), Time(wxDateTime::Now()) {}
~wxXmlResourceDataRecord() {delete Doc;}
wxString File;
wxXmlDocument *Doc;
wxDateTime Time;
};
WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
@ -57,97 +57,97 @@ WX_DECLARE_EXPORTED_OBJARRAY(wxXmlResourceDataRecord, wxXmlResourceDataRecords);
class WXDLLEXPORT wxXmlResource : public wxObject
{
public:
// Ctor. If use_locale is TRUE, translatable strings are
// translated via _(). You can disable it by passing use_locale=FALSE
// (for example if you provide resource file for each locale)
wxXmlResource(bool use_locale = TRUE);
wxXmlResource(const wxString& filemask, bool use_locale = TRUE);
~wxXmlResource();
public:
// Ctor. If use_locale is TRUE, translatable strings are
// translated via _(). You can disable it by passing use_locale=FALSE
// (for example if you provide resource file for each locale)
wxXmlResource(bool use_locale = TRUE);
wxXmlResource(const wxString& filemask, bool use_locale = TRUE);
~wxXmlResource();
// Loads resources from XML files that match given filemask.
// This method understands VFS (see filesys.h).
bool Load(const wxString& filemask);
// Initialize handlers for all supported controls/windows. This will
// make the executable quite big because it forces linking against
// most of wxWin library
void InitAllHandlers();
// Initialize only specific handler (or custom handler). Convention says
// that handler name is equal to control's name plus 'XmlHandler', e.g.
// wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
// (xmlres) can create include file that contains initialization code for
// all controls used within the resource.
void AddHandler(wxXmlResourceHandler *handler);
// Removes all handlers
void ClearHandlers();
// Loads menu from resource. Returns NULL on failure.
wxMenu *LoadMenu(const wxString& name);
// Loads resources from XML files that match given filemask.
// This method understands VFS (see filesys.h).
bool Load(const wxString& filemask);
// Loads menubar from resource. Returns NULL on failure.
wxMenuBar *LoadMenuBar(const wxString& name);
// Initialize handlers for all supported controls/windows. This will
// make the executable quite big because it forces linking against
// most of wxWin library
void InitAllHandlers();
// Initialize only specific handler (or custom handler). Convention says
// that handler name is equal to control's name plus 'XmlHandler', e.g.
// wxTextCtrlXmlHandler, wxHtmlWindowXmlHandler. XML resource compiler
// (xmlres) can create include file that contains initialization code for
// all controls used within the resource.
void AddHandler(wxXmlResourceHandler *handler);
// Removes all handlers
void ClearHandlers();
// Loads menu from resource. Returns NULL on failure.
wxMenu *LoadMenu(const wxString& name);
// Loads menubar from resource. Returns NULL on failure.
wxMenuBar *LoadMenuBar(const wxString& name);
#if wxUSE_TOOLBAR
// Loads toolbar
wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
// Loads toolbar
wxToolBar *LoadToolBar(wxWindow *parent, const wxString& name);
#endif
// Loads dialog. dlg points to parent window (if any). Second form
// is used to finish creation of already existing instance (main reason
// for this is that you may want to use derived class with new event table)
// Example (typical usage):
// MyDialog dlg;
// wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
// dlg->ShowModal();
wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
// Loads dialog. dlg points to parent window (if any). Second form
// is used to finish creation of already existing instance (main reason
// for this is that you may want to use derived class with new event table)
// Example (typical usage):
// MyDialog dlg;
// wxTheXmlResource->LoadDialog(&dlg, mainFrame, "my_dialog");
// dlg->ShowModal();
wxDialog *LoadDialog(wxWindow *parent, const wxString& name);
bool LoadDialog(wxDialog *dlg, wxWindow *parent, const wxString& name);
// Loads panel. panel points to parent window (if any). Second form
// is used to finish creation of already existing instance.
wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
// Loads panel. panel points to parent window (if any). Second form
// is used to finish creation of already existing instance.
wxPanel *LoadPanel(wxWindow *parent, const wxString& name);
bool LoadPanel(wxPanel *panel, wxWindow *parent, const wxString& name);
bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
bool LoadFrame(wxFrame* frame, wxWindow *parent, const wxString& name);
// Loads bitmap or icon resource from file:
wxBitmap LoadBitmap(const wxString& name);
wxIcon LoadIcon(const wxString& name);
// Loads bitmap or icon resource from file:
wxBitmap LoadBitmap(const wxString& name);
wxIcon LoadIcon(const wxString& name);
// Returns numeric ID that is equivalent to string id used in XML
// resource. To be used in event tables
// Macro XMLID is provided for convenience
static int GetXMLID(const char *str_id);
// Returns numeric ID that is equivalent to string id used in XML
// resource. To be used in event tables
// Macro XMLID is provided for convenience
static int GetXMLID(const char *str_id);
protected:
// Scans resources list for unloaded files and loads them. Also reloads
// files that have been modified since last loading.
void UpdateResources();
// Finds resource (calls UpdateResources) and returns node containing it
wxXmlNode *FindResource(const wxString& name, const wxString& classname);
// Creates resource from info in given node:
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL);
protected:
// Scans resources list for unloaded files and loads them. Also reloads
// files that have been modified since last loading.
void UpdateResources();
// Remove nodes with property "platform" that does not
// match current platform
void ProcessPlatformProperty(wxXmlNode *node);
bool GetUseLocale() { return m_UseLocale; }
// Finds resource (calls UpdateResources) and returns node containing it
wxXmlNode *FindResource(const wxString& name, const wxString& classname);
private:
bool m_UseLocale;
wxList m_Handlers;
wxXmlResourceDataRecords m_Data;
// Creates resource from info in given node:
wxObject *CreateResFromNode(wxXmlNode *node, wxObject *parent, wxObject *instance = NULL);
// Remove nodes with property "platform" that does not
// match current platform
void ProcessPlatformProperty(wxXmlNode *node);
bool GetUseLocale() { return m_useLocale; }
private:
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;
friend class wxXmlResourceHandler;
};
@ -184,116 +184,120 @@ extern wxXmlResource *wxTheXmlResource;
class WXDLLEXPORT wxXmlResourceHandler : public wxObject
{
public:
wxXmlResourceHandler();
virtual ~wxXmlResourceHandler() {}
public:
wxXmlResourceHandler();
virtual ~wxXmlResourceHandler() {}
// Creates object (menu, dialog, control, ...) from XML node.
// Should check for validity.
// parent is higher-level object (usually window, dialog or panel)
// 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);
// Creates object (menu, dialog, control, ...) from XML node.
// Should check for validity.
// parent is higher-level object (usually window, dialog or panel)
// 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);
// This one is called from CreateResource after variables
// were filled
virtual wxObject *DoCreateResource() = 0;
// Returns TRUE if it understands this node and can create
// resource from it, FALSE otherwise.
virtual bool CanHandle(wxXmlNode *node) = 0;
// This one is called from CreateResource after variables
// were filled
virtual wxObject *DoCreateResource() = 0;
void SetParentResource(wxXmlResource *res) { m_Resource = res; }
// Returns TRUE if it understands this node and can create
// resource from it, FALSE otherwise.
virtual bool CanHandle(wxXmlNode *node) = 0;
void SetParentResource(wxXmlResource *res) { m_resource = res; }
protected:
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;
// --- Handy methods:
// Variables (filled by CreateResource)
wxXmlNode *m_node;
wxString m_class;
wxObject *m_parent, *m_instance;
wxWindow *m_parentAsWindow, *m_instanceAsWindow;
// Returns true if the node has property class equal to classname,
// e.g. <object class="wxDialog">
bool IsOfClass(wxXmlNode *node, const wxString& classname)
{ return node->GetPropVal(wxT("class"), wxEmptyString) == classname; }
// --- Handy methods:
// Gets node content from wxXML_ENTITY_NODE
// (the problem is, <tag>content<tag> is represented as
// wxXML_ENTITY_NODE name="tag", content=""
// |-- wxXML_TEXT_NODE or
// wxXML_CDATA_SECTION_NODE name="" content="content"
wxString GetNodeContent(wxXmlNode *node);
// Returns true if the node has property class equal to classname,
// e.g. <object class="wxDialog">
bool IsOfClass(wxXmlNode *node, const wxString& classname)
{ return node->GetPropVal(wxT("class"), wxEmptyString) == classname; }
// Check to see if a param exists
bool HasParam(const wxString& param);
// Gets node content from wxXML_ENTITY_NODE
// (the problem is, <tag>content<tag> is represented as
// wxXML_ENTITY_NODE name="tag", content=""
// |-- wxXML_TEXT_NODE or
// wxXML_CDATA_SECTION_NODE name="" content="content"
wxString GetNodeContent(wxXmlNode *node);
// Finds the node or returns NULL
wxXmlNode *GetParamNode(const wxString& param);
wxString GetParamValue(const wxString& param);
// Add style flag (e.g. wxMB_DOCKABLE) to list of flags
// understood by this handler
void AddStyle(const wxString& name, int value);
// Add styles common to all wxWindow-derived classes
void AddWindowStyles();
// Gets style flags from text in form "flag | flag2| flag3 |..."
// Only understads flags added with AddStyle
int GetStyle(const wxString& param = wxT("style"), int defaults = 0);
// Gets text from param and does some convertions:
// - replaces \n, \r, \t by respective chars (according to C syntax)
// - replaces $ by & and $$ by $ (needed for $File => &File because of XML)
// - calls wxGetTranslations (unless disabled in wxXmlResource)
wxString GetText(const wxString& param);
// Check to see if a param exists
bool HasParam(const wxString& param);
// Return XMLID
int GetID();
wxString GetName();
// Finds the node or returns NULL
wxXmlNode *GetParamNode(const wxString& param);
wxString GetParamValue(const wxString& param);
// Get bool flag (1,t,yes,on,true are TRUE, everything else is FALSE)
bool GetBool(const wxString& param, bool defaultv = FALSE);
// Add style flag (e.g. wxMB_DOCKABLE) to list of flags
// understood by this handler
void AddStyle(const wxString& name, int value);
// Get integer value from param
long GetLong( const wxString& param, long defaultv = 0 );
// Get colour in HTML syntax (#RRGGBB)
wxColour GetColour(const wxString& param);
// Get size/position (may be in dlg units):
wxSize GetSize(const wxString& param = wxT("size"));
wxPoint GetPosition(const wxString& param = wxT("pos"));
// Add styles common to all wxWindow-derived classes
void AddWindowStyles();
// Get dimension (may be in dlg units):
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);
// Get font:
wxFont GetFont(const wxString& param = wxT("font"));
// Sets common window options:
void SetupWindow(wxWindow *wnd);
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); }
// Gets style flags from text in form "flag | flag2| flag3 |..."
// Only understads flags added with AddStyle
int GetStyle(const wxString& param = wxT("style"), int defaults = 0);
// helper
wxFileSystem& GetCurFileSystem() { return m_Resource->GetCurFileSystem(); }
// Gets text from param and does some convertions:
// - replaces \n, \r, \t by respective chars (according to C syntax)
// - replaces $ by & and $$ by $ (needed for $File => &File because of XML)
// - calls wxGetTranslations (unless disabled in wxXmlResource)
wxString GetText(const wxString& param);
// Return XMLID
int GetID();
wxString GetName();
// Get bool flag (1,t,yes,on,true are TRUE, everything else is FALSE)
bool GetBool(const wxString& param, bool defaultv = FALSE);
// Get integer value from param
long GetLong( const wxString& param, long defaultv = 0 );
// Get colour in HTML syntax (#RRGGBB)
wxColour GetColour(const wxString& param);
// Get size/position (may be in dlg units):
wxSize GetSize(const wxString& param = wxT("size"));
wxPoint GetPosition(const wxString& param = wxT("pos"));
// Get dimension (may be in dlg units):
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);
// Get font:
wxFont GetFont(const wxString& param = wxT("font"));
// Sets common window options:
void SetupWindow(wxWindow *wnd);
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); }
// helper
wxFileSystem& GetCurFileSystem() { return m_resource->GetCurFileSystem(); }
};
#define ADD_STYLE(style) AddStyle(wxT(#style), style)