]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/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
16 @see Overview(), wxHtmlTag
18 class wxHtmlTagHandler
: public wxObject
27 Returns list of supported tags. The list is in uppercase and tags
28 are delimited by ','. Example : @c "I,B,FONT,P"
30 virtual wxString
GetSupportedTags() = 0;
33 This is the core method of each handler. It is called each time
34 one of supported tags is detected. @a tag contains all necessary
35 info (see wxHtmlTag for details).
37 @return @true if ParseInner was called, @false otherwise.
39 virtual bool HandleTag(const wxHtmlTag
& tag
) = 0;
42 This method calls parser's wxHtmlParser::DoParsing method
43 for the string between this tag and the paired ending tag:
45 In this example, a call to ParseInner (with @a tag pointing to A tag)
46 will parse 'Hello, world!'.
48 void ParseInner(const wxHtmlTag
& tag
);
51 Assigns @a parser to this handler. Each @b instance of handler
52 is guaranteed to be called only from the parser.
54 virtual void SetParser(wxHtmlParser parser
);
57 @b wxHtmlParser* m_Parser
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.
68 Classes derived from this handle the @b generic parsing of HTML documents: it
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
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).
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).
84 Typically the user calls only the wxHtmlParser::Parse method.
89 @see @ref overview_cells "Cells Overview", @ref overview_handlers "Tag Handlers
101 This may (and may not) be overwritten in derived class.
102 This method is called each time new tag is about to be added.
103 @a tag contains information about the tag. (See wxHtmlTag
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.
109 virtual void AddTag(const wxHtmlTag
& tag
);
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'
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
118 All handlers are deleted on object deletion.
120 virtual void AddTagHandler(wxHtmlTagHandler handler
);
123 Must be overwritten in derived class.
124 This method is called by DoParsing()
125 each time a part of text is parsed. @a txt is NOT only one word, it is
126 substring of input. It is not formatted or preprocessed (so white spaces are
129 virtual void AddWord(const wxString
& txt
);
133 Parses the m_Source from begin_pos to end_pos-1.
134 (in noparams version it parses whole m_Source)
136 void DoParsing(int begin_pos
, int end_pos
);
141 This must be called after DoParsing().
143 virtual void DoneParser();
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
150 wxFileSystem
* GetFS() const;
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!).
156 See wxHtmlWinParser for details.
158 virtual wxObject
* GetProduct() = 0;
161 Returns pointer to the source being parsed.
163 wxString
* GetSource();
166 Setups the parser for parsing the @a source string. (Should be overridden
169 virtual void InitParser(const wxString
& source
);
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.
178 Indicates type of the resource. Is one of:
212 Opening a resource that doesn't fall into
217 virtual wxFSFile
* OpenURL(wxHtmlURLType type
,
218 const wxString
& url
);
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)
223 The method does these things:
224 calls @ref initparser() InitParser(source)
228 returns value returned by GetProduct
229 You shouldn't use InitParser, DoParsing, GetProduct or DoneParser directly.
231 wxObject
* Parse(const wxString
& source
);
234 Restores parser's state before last call to
237 void PopTagHandler();
240 Forces the handler to handle additional tags
241 (not returned by wxHtmlTagHandler::GetSupportedTags).
242 The handler should already be added to this parser.
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).
250 void PushTagHandler(wxHtmlTagHandler
* handler
,
251 const wxString
& tags
);
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
258 void SetFS(wxFileSystem fs
);
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).
266 virtual void StopParsing();