]>
git.saurik.com Git - wxWidgets.git/blob - interface/html/htmlpars.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: html/htmlpars.h
3 // Purpose: interface of wxHtmlTagHandler
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
10 @class wxHtmlTagHandler
11 @headerfile htmlpars.h wx/html/htmlpars.h
17 @see Overview(), wxHtmlTag
19 class wxHtmlTagHandler
: public wxObject
28 Returns list of supported tags. The list is in uppercase and tags
29 are delimited by ','. Example : @c "I,B,FONT,P"
31 virtual wxString
GetSupportedTags();
34 This is the core method of each handler. It is called each time
35 one of supported tags is detected. @a tag contains all necessary
36 info (see wxHtmlTag for details).
38 @returns @true if ParseInner was called, @false otherwise.
40 virtual bool HandleTag(const wxHtmlTag
& tag
);
43 This method calls parser's wxHtmlParser::DoParsing method
44 for the string between this tag and the paired ending tag:
46 In this example, a call to ParseInner (with @a tag pointing to A tag)
47 will parse 'Hello, world!'.
49 void ParseInner(const wxHtmlTag
& tag
);
52 Assigns @a parser to this handler. Each @b instance of handler
53 is guaranteed to be called only from the parser.
55 virtual void SetParser(wxHtmlParser parser
);
58 @b wxHtmlParser* m_Parser
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.
68 @headerfile htmlpars.h wx/html/htmlpars.h
70 Classes derived from this handle the @b generic parsing of HTML documents: it
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
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).
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).
86 Typically the user calls only the wxHtmlParser::Parse method.
91 @see @ref overview_cells "Cells Overview", @ref overview_handlers "Tag Handlers
103 This may (and may not) be overwritten in derived class.
104 This method is called each time new tag is about to be added.
105 @a tag contains information about the tag. (See wxHtmlTag
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.
111 void AddTag(const wxHtmlTag
& tag
);
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'
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
120 All handlers are deleted on object deletion.
122 virtual void AddTagHandler(wxHtmlTagHandler handler
);
125 Must be overwritten in derived class.
126 This method is called by DoParsing()
127 each time a part of text is parsed. @a txt is NOT only one word, it is
128 substring of input. It is not formatted or preprocessed (so white spaces are
131 virtual void AddWord(const wxString
& txt
);
135 Parses the m_Source from begin_pos to end_pos-1.
136 (in noparams version it parses whole m_Source)
138 void DoParsing(int begin_pos
, int end_pos
);
143 This must be called after DoParsing().
145 virtual void DoneParser();
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
152 wxFileSystem
* GetFS() const;
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!).
158 See wxHtmlWinParser for details.
160 virtual wxObject
* GetProduct();
163 Returns pointer to the source being parsed.
165 wxString
* GetSource();
168 Setups the parser for parsing the @a source string. (Should be overridden
171 virtual void InitParser(const wxString
& source
);
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.
180 Indicates type of the resource. Is one of:
214 Opening a resource that doesn't fall into
219 virtual wxFSFile
* OpenURL(wxHtmlURLType type
,
220 const wxString
& url
);
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)
225 The method does these things:
226 calls @ref initparser() InitParser(source)
230 returns value returned by GetProduct
231 You shouldn't use InitParser, DoParsing, GetProduct or DoneParser directly.
233 wxObject
* Parse(const wxString
& source
);
236 Restores parser's state before last call to
239 void PopTagHandler();
242 Forces the handler to handle additional tags
243 (not returned by wxHtmlTagHandler::GetSupportedTags).
244 The handler should already be added to this parser.
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).
252 void PushTagHandler(wxHtmlTagHandler
* handler
,
253 const wxString
& tags
);
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
260 void SetFS(wxFileSystem fs
);
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).