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