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