]> git.saurik.com Git - wxWidgets.git/blame - interface/html/htmlpars.h
regenerated headers to remove @seealso in favour of @see; fixed links to global funct...
[wxWidgets.git] / interface / html / htmlpars.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: html/htmlpars.h
e54c96f1 3// Purpose: interface of wxHtmlTagHandler
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxHtmlTagHandler
11 @headerfile htmlpars.h wx/html/htmlpars.h
7c913512
FM
12
13
23324ae1
FM
14 @library{wxhtml}
15 @category{html}
7c913512 16
e54c96f1 17 @see Overview(), wxHtmlTag
23324ae1
FM
18*/
19class wxHtmlTagHandler : public wxObject
20{
21public:
22 /**
23 Constructor.
24 */
25 wxHtmlTagHandler();
26
27 /**
28 Returns list of supported tags. The list is in uppercase and tags
29 are delimited by ','. Example : @c "I,B,FONT,P"
30 */
31 virtual wxString GetSupportedTags();
32
33 /**
34 This is the core method of each handler. It is called each time
4cc4bfaf 35 one of supported tags is detected. @a tag contains all necessary
23324ae1
FM
36 info (see wxHtmlTag for details).
37
38 @returns @true if ParseInner was called, @false otherwise.
39 */
40 virtual bool HandleTag(const wxHtmlTag& tag);
41
42 /**
43 This method calls parser's wxHtmlParser::DoParsing method
44 for the string between this tag and the paired ending tag:
4cc4bfaf
FM
45
46 In this example, a call to ParseInner (with @a tag pointing to A tag)
23324ae1
FM
47 will parse 'Hello, world!'.
48 */
49 void ParseInner(const wxHtmlTag& tag);
50
51 /**
4cc4bfaf 52 Assigns @a parser to this handler. Each @b instance of handler
23324ae1
FM
53 is guaranteed to be called only from the parser.
54 */
55 virtual void SetParser(wxHtmlParser parser);
56
57 /**
58 @b wxHtmlParser* m_Parser
23324ae1
FM
59 This attribute is used to access parent parser. It is protected so that
60 it can't be accessed by user but can be accessed from derived classes.
61 */
62};
63
64
e54c96f1 65
23324ae1
FM
66/**
67 @class wxHtmlParser
68 @headerfile htmlpars.h wx/html/htmlpars.h
7c913512 69
23324ae1
FM
70 Classes derived from this handle the @b generic parsing of HTML documents: it
71 scans
72 the document and divide it into blocks of tags (where one block
73 consists of beginning and ending tag and of text between these
74 two tags).
7c913512 75
23324ae1
FM
76 It is independent from wxHtmlWindow and can be used as stand-alone parser
77 (Julian Smart's idea of speech-only HTML viewer or wget-like utility -
78 see InetGet sample for example).
7c913512 79
23324ae1
FM
80 It uses system of tag handlers to parse the HTML document. Tag handlers
81 are not statically shared by all instances but are created for each
82 wxHtmlParser instance. The reason is that the handler may contain
83 document-specific temporary data used during parsing (e.g. complicated
84 structures like tables).
7c913512 85
23324ae1 86 Typically the user calls only the wxHtmlParser::Parse method.
7c913512 87
23324ae1
FM
88 @library{wxhtml}
89 @category{html}
7c913512 90
e54c96f1 91 @see @ref overview_cells "Cells Overview", @ref overview_handlers "Tag Handlers
23324ae1
FM
92 Overview", wxHtmlTag
93*/
7c913512 94class wxHtmlParser
23324ae1
FM
95{
96public:
97 /**
98 Constructor.
99 */
100 wxHtmlParser();
101
102 /**
103 This may (and may not) be overwritten in derived class.
7c913512 104 This method is called each time new tag is about to be added.
4cc4bfaf 105 @a tag contains information about the tag. (See wxHtmlTag
23324ae1 106 for details.)
23324ae1
FM
107 Default (wxHtmlParser) behaviour is this:
108 First it finds a handler capable of handling this tag and then it calls
109 handler's HandleTag method.
110 */
111 void AddTag(const wxHtmlTag& tag);
112
113 /**
114 Adds handler to the internal list ( hash table) of handlers. This
115 method should not be called directly by user but rather by derived class'
116 constructor.
23324ae1
FM
117 This adds the handler to this @b instance of wxHtmlParser, not to
118 all objects of this class! (Static front-end to AddTagHandler is provided
119 by wxHtmlWinParser).
23324ae1
FM
120 All handlers are deleted on object deletion.
121 */
122 virtual void AddTagHandler(wxHtmlTagHandler handler);
123
124 /**
125 Must be overwritten in derived class.
23324ae1 126 This method is called by DoParsing()
4cc4bfaf 127 each time a part of text is parsed. @a txt is NOT only one word, it is
23324ae1
FM
128 substring of input. It is not formatted or preprocessed (so white spaces are
129 unmodified).
130 */
131 virtual void AddWord(const wxString& txt);
132
133 //@{
134 /**
135 Parses the m_Source from begin_pos to end_pos-1.
136 (in noparams version it parses whole m_Source)
137 */
138 void DoParsing(int begin_pos, int end_pos);
7c913512 139 void DoParsing();
23324ae1
FM
140 //@}
141
142 /**
143 This must be called after DoParsing().
144 */
145 virtual void DoneParser();
146
147 /**
148 Returns pointer to the file system. Because each tag handler has
149 reference to it is parent parser it can easily request the file by
150 calling
151 */
328f5751 152 wxFileSystem* GetFS() const;
23324ae1
FM
153
154 /**
155 Returns product of parsing. Returned value is result of parsing
156 of the document. The type of this result depends on internal
157 representation in derived parser (but it must be derived from wxObject!).
23324ae1
FM
158 See wxHtmlWinParser for details.
159 */
160 virtual wxObject* GetProduct();
161
162 /**
163 Returns pointer to the source being parsed.
164 */
165 wxString* GetSource();
166
167 /**
4cc4bfaf 168 Setups the parser for parsing the @a source string. (Should be overridden
23324ae1
FM
169 in derived class)
170 */
171 virtual void InitParser(const wxString& source);
172
173 /**
174 Opens given URL and returns @c wxFSFile object that can be used to read data
175 from it. This method may return @NULL in one of two cases: either the URL doesn't
176 point to any valid resource or the URL is blocked by overridden implementation
177 of @e OpenURL in derived class.
178
7c913512 179 @param type
4cc4bfaf
FM
180 Indicates type of the resource. Is one of:
181
182
183
184
185
186
187 wxHTML_URL_PAGE
188
23324ae1 189
23324ae1
FM
190
191
4cc4bfaf 192 Opening a HTML page.
23324ae1 193
23324ae1
FM
194
195
23324ae1 196
23324ae1 197
4cc4bfaf 198 wxHTML_URL_IMAGE
23324ae1 199
23324ae1 200
4cc4bfaf
FM
201
202
203 Opening an image.
204
205
206
207
208
209 wxHTML_URL_OTHER
210
211
212
213
214 Opening a resource that doesn't fall into
215 any other category.
7c913512 216 @param url
4cc4bfaf 217 URL being opened.
23324ae1
FM
218 */
219 virtual wxFSFile* OpenURL(wxHtmlURLType type,
220 const wxString& url);
221
222 /**
223 Proceeds parsing of the document. This is end-user method. You can simply
224 call it when you need to obtain parsed output (which is parser-specific)
23324ae1 225 The method does these things:
23324ae1
FM
226 calls @ref initparser() InitParser(source)
227 calls DoParsing()
228 calls GetProduct()
229 calls DoneParser()
230 returns value returned by GetProduct
23324ae1
FM
231 You shouldn't use InitParser, DoParsing, GetProduct or DoneParser directly.
232 */
233 wxObject* Parse(const wxString& source);
234
235 /**
7c913512 236 Restores parser's state before last call to
23324ae1
FM
237 PushTagHandler().
238 */
239 void PopTagHandler();
240
241 /**
7c913512
FM
242 Forces the handler to handle additional tags
243 (not returned by wxHtmlTagHandler::GetSupportedTags).
23324ae1
FM
244 The handler should already be added to this parser.
245
7c913512 246 @param handler
4cc4bfaf 247 the handler
7c913512 248 @param tags
4cc4bfaf
FM
249 List of tags (in same format as GetSupportedTags's return value). The parser
250 will redirect these tags to handler (until call to PopTagHandler).
23324ae1
FM
251 */
252 void PushTagHandler(wxHtmlTagHandler* handler,
253 const wxString& tags);
254
255 /**
256 Sets the virtual file system that will be used to request additional
257 files. (For example @c IMG tag handler requests wxFSFile with the
258 image data.)
259 */
4cc4bfaf 260 void SetFS(wxFileSystem fs);
23324ae1
FM
261
262 /**
263 Call this function to interrupt parsing from a tag handler. No more tags
264 will be parsed afterward. This function may only be called from
265 Parse() or any function called
266 by it (i.e. from tag handlers).
267 */
268 void StopParsing();
269};
e54c96f1 270