]> git.saurik.com Git - wxWidgets.git/blob - wxPython/src/_xml.i
new wxRect and wxPlatformInformation methods
[wxWidgets.git] / wxPython / src / _xml.i
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: _xml.i
3 // Purpose: SWIG interface for other wxXml classes
4 //
5 // Author: Robin Dunn
6 //
7 // Created: 4-June-2001
8 // RCS-ID: $Id$
9 // Copyright: (c) 2003 by Total Control Software
10 // Licence: wxWindows license
11 /////////////////////////////////////////////////////////////////////////////
12
13 // Not a %module
14
15
16 //---------------------------------------------------------------------------
17 %newgroup
18
19
20 // In order to provide wrappers for wxXmlResourceHandler we need to also
21 // provide the classes for representing and parsing XML.
22
23
24 // Represents XML node type.
25 enum wxXmlNodeType
26 {
27 // note: values are synchronized with xmlElementType from libxml
28 wxXML_ELEMENT_NODE,
29 wxXML_ATTRIBUTE_NODE,
30 wxXML_TEXT_NODE,
31 wxXML_CDATA_SECTION_NODE,
32 wxXML_ENTITY_REF_NODE,
33 wxXML_ENTITY_NODE,
34 wxXML_PI_NODE,
35 wxXML_COMMENT_NODE,
36 wxXML_DOCUMENT_NODE,
37 wxXML_DOCUMENT_TYPE_NODE,
38 wxXML_DOCUMENT_FRAG_NODE,
39 wxXML_NOTATION_NODE,
40 wxXML_HTML_DOCUMENT_NODE
41 };
42
43
44
45 // Represents node property(ies).
46 // Example: in <img src="hello.gif" id="3"/> "src" is property with value
47 // "hello.gif" and "id" is property with value "3".
48 class wxXmlProperty
49 {
50 public:
51 wxXmlProperty(const wxString& name = wxPyEmptyString,
52 const wxString& value = wxPyEmptyString,
53 wxXmlProperty *next = NULL);
54
55 wxString GetName() const;
56 wxString GetValue() const;
57 wxXmlProperty *GetNext() const;
58
59 void SetName(const wxString& name);
60 void SetValue(const wxString& value);
61 void SetNext(wxXmlProperty *next);
62 };
63
64
65
66
67 // Represents node in XML document. Node has name and may have content
68 // and properties. Most common node types are wxXML_TEXT_NODE (name and props
69 // are irrelevant) and wxXML_ELEMENT_NODE (e.g. in <title>hi</title> there is
70 // element with name="title", irrelevant content and one child (wxXML_TEXT_NODE
71 // with content="hi").
72 //
73 // If wxUSE_UNICODE is 0, all strings are encoded in the encoding given to Load
74 // (default is UTF-8).
75 class wxXmlNode
76 {
77 public:
78 wxXmlNode(wxXmlNode *parent = NULL,
79 wxXmlNodeType type = 0,
80 const wxString& name = wxPyEmptyString,
81 const wxString& content = wxPyEmptyString,
82 wxXmlProperty *props = NULL,
83 wxXmlNode *next = NULL);
84 ~wxXmlNode();
85
86
87 // user-friendly creation:
88 %RenameCtor(XmlNodeEasy, wxXmlNode(wxXmlNodeType type, const wxString& name,
89 const wxString& content = wxPyEmptyString));
90
91 void AddChild(wxXmlNode *child);
92 bool InsertChild(wxXmlNode *child, wxXmlNode *before_node);
93 bool RemoveChild(wxXmlNode *child);
94 void AddProperty(wxXmlProperty *prop);
95 %Rename(AddPropertyName, void, AddProperty(const wxString& name, const wxString& value));
96 bool DeleteProperty(const wxString& name);
97
98 // access methods:
99 wxXmlNodeType GetType() const;
100 wxString GetName() const;
101 wxString GetContent() const;
102
103 bool IsWhitespaceOnly() const;
104 int GetDepth(wxXmlNode *grandparent = NULL) const;
105
106 // Gets node content from wxXML_ENTITY_NODE
107 // The problem is, <tag>content<tag> is represented as
108 // wxXML_ENTITY_NODE name="tag", content=""
109 // |-- wxXML_TEXT_NODE or
110 // wxXML_CDATA_SECTION_NODE name="" content="content"
111 wxString GetNodeContent() const;
112
113 wxXmlNode *GetParent() const;
114 wxXmlNode *GetNext() const;
115 wxXmlNode *GetChildren() const;
116
117 wxXmlProperty *GetProperties() const;
118 wxString GetPropVal(const wxString& propName,
119 const wxString& defaultVal) const;
120 bool HasProp(const wxString& propName) const;
121
122 void SetType(wxXmlNodeType type);
123 void SetName(const wxString& name);
124 void SetContent(const wxString& con);
125
126 void SetParent(wxXmlNode *parent);
127 void SetNext(wxXmlNode *next);
128 void SetChildren(wxXmlNode *child);
129
130 void SetProperties(wxXmlProperty *prop);
131 };
132
133
134
135 // special indentation value for wxXmlDocument::Save
136 enum {
137 wxXML_NO_INDENTATION
138 };
139
140 // flags for wxXmlDocument::Load
141 enum wxXmlDocumentLoadFlag
142 {
143 wxXMLDOC_NONE = 0,
144 wxXMLDOC_KEEP_WHITESPACE_NODES = 1
145 };
146
147
148
149 // This class holds XML data/document as parsed by XML parser.
150 class wxXmlDocument : public wxObject
151 {
152 public:
153 wxXmlDocument(const wxString& filename,
154 const wxString& encoding = wxPyUTF8String);
155 %RenameCtor(XmlDocumentFromStream, wxXmlDocument(wxInputStream& stream,
156 const wxString& encoding = wxPyUTF8String));
157 %RenameCtor(EmptyXmlDocument, wxXmlDocument());
158
159 ~wxXmlDocument();
160
161
162 // Parses .xml file and loads data. Returns True on success, False
163 // otherwise.
164 bool Load(const wxString& filename,
165 const wxString& encoding = wxPyUTF8String,
166 int flags = wxXMLDOC_NONE);
167 %Rename(LoadFromStream, bool, Load(wxInputStream& stream,
168 const wxString& encoding = wxPyUTF8String,
169 int flags = wxXMLDOC_NONE));
170
171 // Saves document as .xml file.
172 bool Save(const wxString& filename, int indentstep=1) const;
173 %Rename(SaveToStream, bool, Save(wxOutputStream& stream, int indentstep=1) const);
174
175 bool IsOk() const;
176
177 // Returns root node of the document.
178 wxXmlNode *GetRoot() const;
179
180 // Returns version of document (may be empty).
181 wxString GetVersion() const;
182
183 // Returns encoding of document (may be empty).
184 // Note: this is the encoding original file was saved in, *not* the
185 // encoding of in-memory representation!
186 wxString GetFileEncoding() const;
187
188 // Write-access methods:
189 wxXmlNode *DetachRoot();
190 void SetRoot(wxXmlNode *node);
191 void SetVersion(const wxString& version);
192 void SetFileEncoding(const wxString& encoding);
193
194 // %extend {
195 // // Returns encoding of in-memory representation of the document (same
196 // // as passed to Load or ctor, defaults to UTF-8). NB: this is
197 // // meaningless in Unicode build where data are stored as wchar_t*
198 // wxString GetEncoding() {
199 // %#if wxUSE_UNICODE
200 // return wxPyEmptyString;
201 // %#else
202 // return self->GetEncoding();
203 // %#endif
204 // }
205 // void SetEncoding(const wxString& enc) {
206 // %#if wxUSE_UNICODE
207 // // do nothing
208 // %#else
209 // self->SetEncoding(enc);
210 // %#endif
211 // }
212 // }
213 };
214
215 //---------------------------------------------------------------------------
216 //---------------------------------------------------------------------------