]>
git.saurik.com Git - wxWidgets.git/blob - docs/doxygen/overviews/html.h
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: topic overview
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
11 @page html_overview wxHTML overview
13 The wxHTML library provides classes for parsing and displaying HTML.
14 It is not intended to be a high-end HTML browser. If you are looking for
15 something like that try #http://www.mozilla.org.
16 wxHTML can be used as a generic rich text viewer - for example to display
17 a nice About Box (like those of GNOME apps) or to display the result of
18 database searching. There is a #wxFileSystem
19 class which allows you to use your own virtual file systems.
20 wxHtmlWindow supports tag handlers. This means that you can easily
21 extend wxHtml library with new, unsupported tags. Not only that,
22 you can even use your own application-specific tags!
23 See @c src/html/m_*.cpp files for details.
24 There is a generic wxHtmlParser class,
25 independent of wxHtmlWindow.
26 @ref htmlquickstart_overview
27 @ref printing_overview
28 @ref helpformat_overview
31 @ref handlers_overview
32 @ref htmltagssupported_overview
35 @section wxhtmlquickstart wxHTML quick start
38 First of all, you must include wx/wxhtml.h.
39 Class #wxHtmlWindow (derived from wxScrolledWindow)
40 is used to display HTML documents.
41 It has two important methods: #LoadPage
43 LoadPage loads and displays HTML file while SetPage displays directly the
44 passed @b string. See the example:
47 mywin - LoadPage("test.htm");
48 mywin - SetPage("htmlbody"
50 "Some error occurred :-H)"
55 See #wxHtmlHelpController.
56 @b Setting up wxHtmlWindow
57 Because wxHtmlWindow is derived from wxScrolledWindow and not from
58 wxFrame, it doesn't have visible frame. But the user usually wants to see
59 the title of HTML page displayed somewhere and the frame's titlebar is
60 the ideal place for it.
61 wxHtmlWindow provides 2 methods in order to handle this:
67 html = new wxHtmlWindow(this);
68 html - SetRelatedFrame(this, "HTML : %%s");
69 html - SetRelatedStatusBar(0);
72 The first command associates the HTML object with its parent frame
73 (this points to wxFrame object there) and sets the format of the title.
74 Page title "Hello, world!" will be displayed as "HTML : Hello, world!"
76 The second command sets which frame's status bar should be used to display
77 browser's messages (such as "Loading..." or "Done" or hypertext links).
78 @b Customizing wxHtmlWindow
79 You can customize wxHtmlWindow by setting font size, font face and
80 borders (space between border of window and displayed HTML). Related functions:
89 The last two functions are used to store user customization info wxConfig stuff
90 (for example in the registry under Windows, or in a dotfile under Unix).
92 @section printing HTML Printing
94 The wxHTML library provides printing facilities with several levels of complexity.
95 The easiest way to print an HTML document is to use
96 @ref htmleasyprinting_overview. It lets you print HTML documents with only one
97 command and you don't have to worry about deriving from the wxPrintout class at all. It is only a simple wrapper around the
98 #wxHtmlPrintout, normal wxWidgets printout class.
99 And finally there is the low level class #wxHtmlDCRenderer which you can use to
100 render HTML into a rectangular area on any DC. It supports rendering into multiple rectangles with the same
101 width. (The most common use of this is placing one rectangle on each page or printing into two columns.)
103 @section helpformat Help Files Format
105 wxHTML library uses a reduced version of MS HTML Workshop format.
106 Tex2RTF can produce these files when generating HTML, if you set @b htmlWorkshopFiles to @b @true in
107 your tex2rtf.ini file.
108 (See #wxHtmlHelpController for help controller description.)
109 A @b book consists of three files: header file, contents file and index file.
110 You can make a regular zip archive of these files, plus the HTML and any image files,
111 for wxHTML (or helpview) to read; and the .zip file can optionally be renamed to .htb.
112 @b Header file (.hhp)
113 Header file must contain these lines (and may contain additional lines which are ignored) :
116 Contents file=filename.hhc
117 Index file=filename.hhk
118 Title=title of your book
119 Default topic=default page to be displayed.htm
122 All filenames (including the Default topic) are relative to the
123 location of .hhp file.
124 @b Localization note: In addition, .hhp file may contain line
130 which specifies what charset (e.g. "iso8859_1") was used in contents
131 and index files. Please note that this line is incompatible with
132 MS HTML Help Workshop and it would either silently remove it or complain
133 with some error. See also
134 @ref nonenglish_overview.
135 @b Contents file (.hhc)
136 Contents file has HTML syntax and it can be parsed by regular HTML parser. It contains exactly one list
137 (@c ul....@c /ul statement):
142 li object type="text/sitemap"
143 param name="Name" value="@topic name@"
144 param name="ID" value=@numeric_id@
145 param name="Local" value="@filename.htm@"
147 li object type="text/sitemap"
148 param name="Name" value="@topic name@"
149 param name="ID" value=@numeric_id@
150 param name="Local" value="@filename.htm@"
157 You can modify value attributes of param tags. @e topic name is name of chapter/topic as is displayed in
158 contents, @e filename.htm is HTML page name (relative to .hhp file) and @e numeric_id is optional
159 - it is used only when you use wxHtmlHelpController::Display(int)
160 Items in the list may be nested - one @c li statement may contain a @c ul sub-statement:
165 li object type="text/sitemap"
166 param name="Name" value="Top node"
167 param name="Local" value="top.htm"
170 li object type="text/sitemap"
171 param name="Name" value="subnode in topnode"
172 param name="Local" value="subnode1.htm"
177 li object type="text/sitemap"
178 param name="Name" value="Another Top"
179 param name="Local" value="top2.htm"
187 Index files have same format as contents file except that ID params are ignored and sublists are @b not
190 @section filters Input Filters
192 The wxHTML library provides a mechanism for reading and displaying
193 files of many different file formats.
194 wxHtmlWindow::LoadPage can load not
195 only HTML files but any known file. To make a file type known to wxHtmlWindow
196 you must create a #wxHtmlFilter filter and
197 register it using wxHtmlWindow::AddFilter.
199 @section cells Cells and Containers
201 This article describes mechanism used by
203 #wxHtmlWindow to parse and display HTML documents.
205 You can divide any text (or HTML) into small fragments. Let's call these
206 fragments @b cells. Cell is for example one word, horizontal line, image
207 or any other part of document. Each cell has width and height (except special
208 "magic" cells with zero dimensions - e.g. colour changers or font changers).
211 Container is kind of cell that may contain sub-cells. Its size depends
212 on number and sizes of its sub-cells (and also depends on width of window).
213 See #wxHtmlContainerCell,
215 This image shows the cells and containers:
217 @b Using Containers in Tag Handler
218 #wxHtmlWinParser provides a user-friendly way
219 of managing containers. It is based on the idea of opening and closing containers.
220 Use #OpenContainer to open new
221 a container @e within an already opened container. This new container is a
222 @e sub-container of the old one. (If you want to create a new container with
223 the same depth level you can call @c CloseContainer(); OpenContainer();.)
224 Use #CloseContainer to close the
225 container. This doesn't create a new container with same depth level but
226 it returns "control" to the parent container.
229 There clearly must be same number of calls to OpenContainer as to
232 This code creates a new paragraph (container at same depth level)
233 with "Hello, world!":
236 m_WParser - CloseContainer();
237 c = m_WParser - OpenContainer();
239 m_WParser - AddText("Hello, ");
240 m_WParser - AddText("world!");
242 m_WParser - CloseContainer();
243 m_WParser - OpenContainer();
246 and here is image of the situation:
248 You can see that there was an opened container before the code was executed.
249 We closed it, created our own container, then closed our container and opened
250 new container. The result was that we had @e same depth level after
251 executing. This is general rule that should be followed by tag handlers:
252 leave depth level of containers unmodified (in other words, number of
253 OpenContainer and CloseContainer calls should be same within #HandleTag's body).
254 Notice that it would be usually better to use
255 wxHtmlContainerCell::InsertCell instead
256 of adding text to the parser directly.
258 @section handlers Tag Handlers
260 The wxHTML library provides architecture of pluggable @e tag handlers.
261 Tag handler is class that understands particular HTML tag (or tags) and is
262 able to interpret it.
263 #wxHtmlWinParser has static table of @b modules.
264 Each module contains one or more tag handlers. Each time a new wxHtmlWinParser
265 object is constructed all modules are scanned and handlers are added
266 to wxHtmlParser's list of available handlers (note: wxHtmlParser's list
269 Common tag handler's #HandleTag method
273 Save state of parent parser into local variables
274 Change parser state according to tag's params
275 Parse text between the tag and paired ending tag (if present)
276 Restore original parser state
279 See #wxHtmlWinParser for methods for modifying
280 parser's state. In general you can do things like opening/closing containers,
281 changing colors, fonts etc.
282 @b Providing own tag handlers
283 You should create new .cpp file and place following lines into it:
288 FORCE_LINK_ME(yourmodulefilenamewithoutcpp)
291 Then you must define handlers and one module.
293 The handler is derived from #wxHtmlWinTagHandler
294 (or directly from #wxHtmlTagHandler)
295 You can use set of macros to define the handler (see src/html/m_*.cpp files
296 for details). Handler definition must start with @b TAG_HANDLER_BEGIN macro
297 and end with @b TAG_HANDLER_END macro. I strongly recommend to have a look
298 at @e include/wxhtml/mod_templ.h file. Otherwise you won't understand
299 the structure of macros. See macros reference:
300 @b TAG_HANDLER_BEGIN(@e name, @e tags)
301 Starts handler definition. @e name is handler identifier (in fact
302 part of class name), @e tags is string containing list of tags
303 supported by this handler (in uppercase). This macro derives new class from
304 wxHtmlWinTagHandler and implements it is
305 #GetSupportedTags method.
306 Example: TAG_HANDLER_BEGIN(FONTS, "B,I,U,T")
308 This macro starts block of variables definitions. (Variables are identical
309 to class attributes.) Example:
312 TAG_HANDLER_BEGIN(VARS_ONLY, "CRAZYTAG")
315 wxString something_else;
316 TAG_HANDLER_END(VARS_ONLY)
319 This macro is used only in rare cases.
320 @b TAG_HANDLER_CONSTR(@e name)
321 This macro supplies object constructor. @e name is same name as the one
322 from TAG_HANDLER_BEGIN macro. Body of constructor follow after
323 this macro (you must use and ). Example:
326 TAG_HANDLER_BEGIN(VARS2, "CRAZYTAG")
329 TAG_HANDLER_CONSTR(vars2)
333 TAG_HANDLER_END(VARS2)
336 Never used in wxHTML :-)
337 @b TAG_HANDLER_PROC(@e varib)
338 This is very important macro. It defines #HandleTag
339 method. @e varib is name of parameter passed to the method, usually
340 @e tag. Body of method follows after this macro.
341 Note than you must use and ! Example:
344 TAG_HANDLER_BEGIN(TITLE, "TITLE")
345 TAG_HANDLER_PROC(tag)
347 printf("TITLE found...\n");
349 TAG_HANDLER_END(TITLE)
352 @b TAG_HANDLER_END(@e name)
353 Ends definition of tag handler @e name.
355 You can use set of 3 macros TAGS_MODULE_BEGIN, TAGS_MODULE_ADD and
356 TAGS_MODULE_END to inherit new module from
357 #wxHtmlTagsModule and to create instance of it.
358 See macros reference:
359 @b TAGS_MODULE_BEGIN(@e modname)
360 Begins module definition. @e modname is part of class name and must
362 @b TAGS_MODULE_ADD(@e name)
363 Adds the handler to this module. @e name is the identifier from
365 @b TAGS_MODULE_END(@e modname)
366 Ends the definition of module.
370 TAGS_MODULE_BEGIN(Examples)
371 TAGS_MODULE_ADD(VARS_ONLY)
372 TAGS_MODULE_ADD(VARS2)
373 TAGS_MODULE_ADD(TITLE)
374 TAGS_MODULE_END(Examples)
378 @section htmltagssupported Tags supported by wxHTML
380 wxHTML is not full implementation of HTML standard. Instead, it supports most common tags so that it
381 is possible to display @e simple HTML documents with it. (For example it works fine with pages created
382 in Netscape Composer or generated by tex2rtf).
383 Following tables list all tags known to wxHTML, together with supported parameters.
384 A tag has general form of @c tagname param_1 param_2 ... param_n where param_i is
385 either @c paramname="paramvalue" or @c paramname=paramvalue - these two are equivalent. Unless stated
386 otherwise, wxHTML is case-insensitive.
387 @b Table of common parameter values
388 We will use these substitutions in tags descriptions:
400 [color] HTML 4.0-compliant colour specification
417 [pixels] integer value that represents dimension in pixels
426 [coords] c(1),c(2),c(3),...,c(n)
427 where c(i) is integer
431 @b List of supported tags
436 TARGET=[target window spec]
454 DIV ALIGN=[alignment]
460 FACE=[comma-separated list of facenames]
463 WIDTH=[percent|pixels]
483 META HTTP-EQUIV="Content-Type"
494 TABLE ALIGN=[alignment]
495 WIDTH=[percent|pixels]
504 WIDTH=[percent|pixels]
511 WIDTH=[percent|pixels]