]>
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 overview_html 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.
17 wxHTML can be used as a generic rich text viewer - for example to display
18 a nice About Box (like those of GNOME apps) or to display the result of
19 database searching. There is a #wxFileSystem class which allows you to use
20 your own virtual file systems.
22 wxHtmlWindow supports tag handlers. This means that you can easily
23 extend wxHtml library with new, unsupported tags. Not only that,
24 you can even use your own application-specific tags!
26 See @c src/html/m_*.cpp files for details.
28 There is a generic wxHtmlParser class, independent of wxHtmlWindow.
30 @li @ref overview_html_quickstart
31 @li @ref overview_html_printing
32 @li @ref overview_html_helpformats
33 @li @ref overview_html_filters
34 @li @ref overview_html_cells
35 @li @ref overview_html_handlers
36 @li @ref overview_html_supptags
42 @section overview_html_quickstart wxHTML quick start
44 @subsection overview_html_quickstart_disphtml Displaying HTML
46 First of all, you must include @c wx/wxhtml.h.
48 Class #wxHtmlWindow (derived from wxScrolledWindow) is used to display HTML documents.
50 It has two important methods: wxHtmlWindow::LoadPage and wxHtmlWindow::SetPage.
51 LoadPage loads and displays HTML file while SetPage displays directly the
52 passed @b string. See the example:
55 mywin - LoadPage("test.htm");
56 mywin - SetPage("htmlbody"
58 "Some error occurred :-H)"
62 @subsection overview_html_quickstart_disphelp Displaying Help
64 See #wxHtmlHelpController.
66 @subsection overview_html_quickstart_settingup Setting up wxHtmlWindow
68 Because wxHtmlWindow is derived from wxScrolledWindow and not from
69 wxFrame, it doesn't have visible frame. But the user usually wants to see
70 the title of HTML page displayed somewhere and the frame's titlebar is
71 the ideal place for it.
73 wxHtmlWindow provides 2 methods in order to handle this:
74 wxHtmlWindow::SetRelatedFrame and wxHtmlWindow::SetRelatedStatusBar.
78 html = new wxHtmlWindow(this);
79 html - SetRelatedFrame(this, "HTML : %%s");
80 html - SetRelatedStatusBar(0);
83 The first command associates the HTML object with its parent frame
84 (this points to wxFrame object there) and sets the format of the title.
85 Page title "Hello, world!" will be displayed as "HTML : Hello, world!"
88 The second command sets which frame's status bar should be used to display
89 browser's messages (such as "Loading..." or "Done" or hypertext links).
91 @subsection overview_html_quickstart_custom Customizing wxHtmlWindow
93 You can customize wxHtmlWindow by setting font size, font face and
94 borders (space between border of window and displayed HTML). Related functions:
96 @li wxHtmlWindow::SetFonts
97 @li wxHtmlWindow::SetBorders
98 @li wxHtmlWindow::ReadCustomization
99 @li wxHtmlWindow::WriteCustomization
101 The last two functions are used to store user customization info wxConfig stuff
102 (for example in the registry under Windows, or in a dotfile under Unix).
106 @section overview_html_printing HTML Printing
108 The wxHTML library provides printing facilities with several levels of complexity.
109 The easiest way to print an HTML document is to use @ref htmleasyprinting_overview.
111 It lets you print HTML documents with only one command and you don't have to worry
112 about deriving from the wxPrintout class at all. It is only a simple wrapper around the
113 #wxHtmlPrintout, normal wxWidgets printout class.
115 And finally there is the low level class #wxHtmlDCRenderer which you can use to
116 render HTML into a rectangular area on any DC.
118 It supports rendering into multiple rectangles with the same
119 width. (The most common use of this is placing one rectangle on each page or
120 printing into two columns.)
123 @section overview_html_helpformats Help Files Format
125 wxHTML library uses a reduced version of MS HTML Workshop format.
126 Tex2RTF can produce these files when generating HTML, if you set
127 @b htmlWorkshopFiles to @true in your tex2rtf.ini file.
128 (See #wxHtmlHelpController for help controller description.)
130 A @b book consists of three files: the header file, the contents file
133 You can make a regular zip archive of these files, plus the HTML and any
134 image files, for wxHTML (or helpview) to read; and the @c .zip file can
135 optionally be renamed to @c .htb.
137 @subsection overview_html_helpformats_hhp Header file (.hhp)
139 The header file must contain these lines (and may contain additional lines
143 Contents file=filename.hhc
144 Index file=filename.hhk
145 Title=title of your book
146 Default topic=default page to be displayed.htm
149 All filenames (including the Default topic) are relative to the
150 location of the @c .hhp file.
152 @note For localization, in addition the @c .hhp file may contain the line
156 which specifies what charset (e.g. "iso8859_1") was used in contents
157 and index files. Please note that this line is incompatible with
158 MS HTML Help Workshop and it would either silently remove it or complain
159 with some error. See also @ref overview_nonenglish.
161 @subsection overview_html_helpformats_hhc Contents file (.hhc)
163 Contents file has HTML syntax and it can be parsed by regular HTML parser.
164 It contains exactly one list (@c <ul>....@c </ul> statement):
169 <li><object type="text/sitemap">
170 <param name="Name" value="@topic name@">
171 <param name="ID" value=@numeric_id@>
172 <param name="Local" value="@filename.htm@">
174 <li><object type="text/sitemap">
175 <param name="Name" value="@topic name@">
176 <param name="ID" value=@numeric_id@>
177 <param name="Local" value="@filename.htm@">
183 You can modify value attributes of param tags.
184 The <em>topic name</em> is name of chapter/topic as is displayed in
185 contents, <em>filename.htm</em> is the HTML page name (relative to the @c .hhp file)
186 and <em>numeric_id</em> is optional - it is used only when you use wxHtmlHelpController::Display(int).
188 Items in the list may be nested - one @c <li> statement may contain a @c <ul> sub-statement:
193 <li><object type="text/sitemap">
194 <param name="Name" value="Top node">
195 <param name="Local" value="top.htm">
198 <li><object type="text/sitemap">
199 <param name="Name" value="subnode in topnode">
200 <param name="Local" value="subnode1.htm">
205 <li><object type="text/sitemap">
206 <param name="Name" value="Another Top">
207 <param name="Local" value="top2.htm">
214 @subsection overview_html_helpformats_hhk Index file (.hhk)
216 Index files have same format as contents file except that ID params are ignored
217 and sublists are @b not allowed.
220 @section overview_html_filters Input Filters
222 The wxHTML library provides a mechanism for reading and displaying
223 files of many different file formats.
225 wxHtmlWindow::LoadPage can load not only HTML files but any known file.
226 To make a file type known to wxHtmlWindow you must create a #wxHtmlFilter filter and
227 register it using wxHtmlWindow::AddFilter.
230 @section overview_html_cells Cells and Containers
232 This article describes mechanism used by #wxHtmlWinParser and
233 #wxHtmlWindow to parse and display HTML documents.
235 @subsection overview_html_cells_cells Cells
237 You can divide any text (or HTML) into small fragments. Let's call these
238 fragments @b cells. Cell is for example one word, horizontal line, image
239 or any other part of document. Each cell has width and height (except special
240 "magic" cells with zero dimensions - e.g. colour changers or font changers).
243 @subsection overview_html_cells_containers Containers
245 Container is kind of cell that may contain sub-cells. Its size depends
246 on number and sizes of its sub-cells (and also depends on width of window).
247 See #wxHtmlContainerCell, wxHtmlCell::Layout.
248 This image shows the cells and containers: @image html contbox.bmp
250 @subsection overview_html_cells_conttaghandler Using Containers in Tag Handler
252 #wxHtmlWinParser provides a user-friendly way of managing containers.
253 It is based on the idea of opening and closing containers.
255 Use #OpenContainer to open new a container @e within an already opened container.
256 This new container is a @e sub-container of the old one. (If you want to create a
257 new container with the same depth level you can call @c CloseContainer(); OpenContainer();.)
259 Use #CloseContainer to close the container. This doesn't create a new container
260 with same depth level but it returns "control" to the parent container.
261 See explanation: @image html cont.bmp
263 There clearly must be same number of calls to OpenContainer as to
266 @subsubsection overview_html_cells_conttaghandler_example Example
268 This code creates a new paragraph (container at same depth level)
269 with "Hello, world!":
272 m_WParser -> CloseContainer();
273 c = m_WParser -> OpenContainer();
275 m_WParser -> AddText("Hello, ");
276 m_WParser -> AddText("world!");
278 m_WParser -> CloseContainer();
279 m_WParser -> OpenContainer();
282 and here is image of the situation: @image html hello.bmp
284 You can see that there was an opened container before the code was executed.
285 We closed it, created our own container, then closed our container and opened
288 The result was that we had @e same depth level after executing.
289 This is general rule that should be followed by tag handlers:
290 leave depth level of containers unmodified (in other words, number of
291 OpenContainer and CloseContainer calls should be same within #HandleTag's body).
293 Notice that it would be usually better to use wxHtmlContainerCell::InsertCell instead
294 of adding text to the parser directly.
297 @section overview_html_handlers Tag Handlers
299 The wxHTML library provides architecture of pluggable @e tag handlers.
300 Tag handler is class that understands particular HTML tag (or tags) and is
301 able to interpret it.
303 #wxHtmlWinParser has a static table of @b modules.
304 Each module contains one or more tag handlers. Each time a new wxHtmlWinParser
305 object is constructed all modules are scanned and handlers are added
306 to wxHtmlParser's list of available handlers (note: wxHtmlParser's list
309 @subsection overview_html_handlers_howworks How it works
311 Common tag handler's #HandleTag method works in four steps:
313 @li Save state of parent parser into local variables
314 @li Change parser state according to tag's params
315 @li Parse text between the tag and paired ending tag (if present)
316 @li Restore original parser state
318 See #wxHtmlWinParser for methods for modifying parser's state.
319 In general you can do things like opening/closing containers, changing colors, fonts etc.
321 @subsection overview_html_handlers_custom Providing own tag handlers
323 You should create a new .cpp file and place the following lines into it:
326 #include <mod_templ.h>
327 #include <forcelink.h>
328 FORCE_LINK_ME(yourmodulefilenamewithoutcpp)
331 Then you must define handlers and one module.
333 @subsection overview_html_handlers_tag Tag handlers
335 The handler is derived from #wxHtmlWinTagHandler (or directly from #wxHtmlTagHandler).
337 You can use set of macros to define the handler (see src/html/m_*.cpp files
338 for details). Handler definition must start with @b TAG_HANDLER_BEGIN macro
339 and end with @b TAG_HANDLER_END macro.
341 I strongly recommend to have a look at @e include/wxhtml/mod_templ.h file.
342 Otherwise you won't understand the structure of macros.
344 See macros reference:
345 @li @b TAG_HANDLER_BEGIN(@e name, @e tags):
346 Starts handler definition. @e name is handler identifier (in fact
347 part of class name), @e tags is string containing list of tags
348 supported by this handler (in uppercase). This macro derives new class from
349 wxHtmlWinTagHandler and implements it is #GetSupportedTags method.
350 Example: TAG_HANDLER_BEGIN(FONTS, "B,I,U,T")
352 @li @b TAG_HANDLER_VARS:
353 This macro starts block of variables definitions. (Variables are identical
354 to class attributes.) Example:
357 TAG_HANDLER_BEGIN(VARS_ONLY, "CRAZYTAG")
360 wxString something_else;
361 TAG_HANDLER_END(VARS_ONLY)
364 This macro is used only in rare cases.
366 @li @b TAG_HANDLER_CONSTR(@e name):
367 This macro supplies object constructor. @e name is same name as the one
368 from TAG_HANDLER_BEGIN macro. Body of constructor follow after
369 this macro (you must use { and } ). Example:
372 TAG_HANDLER_BEGIN(VARS2, "CRAZYTAG")
375 TAG_HANDLER_CONSTR(vars2)
379 TAG_HANDLER_END(VARS2)
382 Never used in wxHTML :-)
384 @li @b TAG_HANDLER_PROC(@e varib):
385 This is very important macro. It defines #HandleTag
386 method. @e varib is name of parameter passed to the method, usually
387 @e tag. Body of method follows after this macro.
388 Note than you must use { and } !
392 TAG_HANDLER_BEGIN(TITLE, "TITLE")
393 TAG_HANDLER_PROC(tag)
395 printf("TITLE found...\n");
397 TAG_HANDLER_END(TITLE)
400 @li @b TAG_HANDLER_END(@e name):
401 Ends definition of tag handler @e name.
403 @subsection overview_html_handlers_modules Tags Modules
405 You can use set of 3 macros TAGS_MODULE_BEGIN, TAGS_MODULE_ADD and
406 TAGS_MODULE_END to inherit new module from
407 #wxHtmlTagsModule and to create instance of it.
409 See macros reference:
411 @li @b TAGS_MODULE_BEGIN(@e modname):
412 Begins module definition. @e modname is part of class name and must be unique.
413 @li @b TAGS_MODULE_ADD(@e name):
414 Adds the handler to this module. @e name is the identifier from TAG_HANDLER_BEGIN.
415 @li @b TAGS_MODULE_END(@e modname):
416 Ends the definition of module.
420 TAGS_MODULE_BEGIN(Examples)
421 TAGS_MODULE_ADD(VARS_ONLY)
422 TAGS_MODULE_ADD(VARS2)
423 TAGS_MODULE_ADD(TITLE)
424 TAGS_MODULE_END(Examples)
428 @section overview_html_supptags Tags supported by wxHTML
430 wxHTML is not full implementation of HTML standard. Instead, it supports most
431 common tags so that it is possible to display @e simple HTML documents with it.
432 (For example it works fine with pages created in Netscape Composer or generated by tex2rtf).
434 Following tables list all tags known to wxHTML, together with supported parameters.
436 A tag has general form of @c tagname param_1 param_2 ... param_n where param_i is
437 either @c paramname="paramvalue" or @c paramname=paramvalue - these two are equivalent.
438 Unless stated otherwise, wxHTML is case-insensitive.
440 @subsection overview_html_supptags_commonvalues Table of common parameter values
442 We will use these substitutions in tags descriptions:
454 [color] HTML 4.0-compliant colour specification
471 [pixels] integer value that represents dimension in pixels
480 [coords] c(1),c(2),c(3),...,c(n)
481 where c(i) is integer
485 @subsection overview_html_supptags_list List of supported tags
490 TARGET=[target window spec]
508 DIV ALIGN=[alignment]
514 FACE=[comma-separated list of facenames]
517 WIDTH=[percent|pixels]
537 META HTTP-EQUIV="Content-Type"
548 TABLE ALIGN=[alignment]
549 WIDTH=[percent|pixels]
558 WIDTH=[percent|pixels]
565 WIDTH=[percent|pixels]