]> git.saurik.com Git - wxWidgets.git/blame - docs/doxygen/overviews/html.h
Merge in from trunk r67662 to r64801
[wxWidgets.git] / docs / doxygen / overviews / html.h
CommitLineData
15b6757b 1/////////////////////////////////////////////////////////////////////////////
c33e257b 2// Name: html.h
15b6757b
FM
3// Purpose: topic overview
4// Author: wxWidgets team
5// RCS-ID: $Id$
526954c5 6// Licence: wxWindows licence
15b6757b
FM
7/////////////////////////////////////////////////////////////////////////////
8
880efa2a 9/**
36c9828f 10
928f1a07 11@page overview_html wxHTML Overview
36c9828f 12
928f1a07
FM
13The wxHTML library provides classes for parsing and displaying HTML.
14It is not intended to be a high-end HTML browser. If you are looking for
15something like that try <http://www.mozilla.org/>.
c33e257b 16
928f1a07
FM
17wxHTML can be used as a generic rich text viewer - for example to display
18a nice About Box (like those of GNOME apps) or to display the result of
19database searching. There is a wxFileSystem class which allows you to use
20your own virtual file systems.
c33e257b 21
928f1a07
FM
22wxHtmlWindow supports tag handlers. This means that you can easily
23extend wxHtml library with new, unsupported tags. Not only that,
24you can even use your own application-specific tags!
c33e257b 25
928f1a07 26See @c src/html/m_*.cpp files for details.
c33e257b 27
928f1a07 28There is a generic wxHtmlParser class, independent of wxHtmlWindow.
c33e257b 29
928f1a07
FM
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
c33e257b
FM
37
38
928f1a07 39<hr>
c33e257b
FM
40
41
928f1a07 42@section overview_html_quickstart wxHTML quick start
c33e257b 43
928f1a07 44@subsection overview_html_quickstart_disphtml Displaying HTML
c33e257b 45
928f1a07 46First of all, you must include @c wx/wxhtml.h.
c33e257b 47
f09b5681 48Class wxHtmlWindow (derived from ::wxScrolledWindow) is used to display HTML documents.
c33e257b 49
928f1a07
FM
50It has two important methods: wxHtmlWindow::LoadPage and wxHtmlWindow::SetPage.
51LoadPage loads and displays HTML file while SetPage displays directly the
52passed @b string. See the example:
36c9828f 53
928f1a07
FM
54@code
55 mywin -> LoadPage("test.htm");
56 mywin -> SetPage("htmlbody"
57 "h1Error/h1"
58 "Some error occurred :-H)"
59 "/body/hmtl");
60@endcode
36c9828f 61
928f1a07 62@subsection overview_html_quickstart_settingup Setting up wxHtmlWindow
c33e257b 63
f09b5681 64Because wxHtmlWindow is derived from ::wxScrolledWindow and not from
928f1a07
FM
65wxFrame, it doesn't have visible frame. But the user usually wants to see
66the title of HTML page displayed somewhere and the frame's titlebar is
67the ideal place for it.
c33e257b 68
928f1a07
FM
69wxHtmlWindow provides 2 methods in order to handle this:
70wxHtmlWindow::SetRelatedFrame and wxHtmlWindow::SetRelatedStatusBar.
71See the example:
36c9828f 72
928f1a07
FM
73@code
74 html = new wxHtmlWindow(this);
75 html -> SetRelatedFrame(this, "HTML : %%s");
76 html -> SetRelatedStatusBar(0);
77@endcode
36c9828f 78
928f1a07
FM
79The first command associates the HTML object with its parent frame
80(this points to wxFrame object there) and sets the format of the title.
81Page title "Hello, world!" will be displayed as "HTML : Hello, world!"
82in this example.
c33e257b 83
928f1a07
FM
84The second command sets which frame's status bar should be used to display
85browser's messages (such as "Loading..." or "Done" or hypertext links).
36c9828f 86
928f1a07 87@subsection overview_html_quickstart_custom Customizing wxHtmlWindow
36c9828f 88
928f1a07
FM
89You can customize wxHtmlWindow by setting font size, font face and
90borders (space between border of window and displayed HTML). Related functions:
36c9828f 91
928f1a07
FM
92@li wxHtmlWindow::SetFonts
93@li wxHtmlWindow::SetBorders
94@li wxHtmlWindow::ReadCustomization
95@li wxHtmlWindow::WriteCustomization
36c9828f 96
928f1a07
FM
97The last two functions are used to store user customization info wxConfig stuff
98(for example in the registry under Windows, or in a dotfile under Unix).
36c9828f 99
c33e257b
FM
100
101
928f1a07 102@section overview_html_printing HTML Printing
36c9828f 103
928f1a07
FM
104The wxHTML library provides printing facilities with several levels of complexity.
105The easiest way to print an HTML document is to use the wxHtmlEasyPrinting class.
c33e257b 106
928f1a07
FM
107It lets you print HTML documents with only one command and you don't have to worry
108about deriving from the wxPrintout class at all. It is only a simple wrapper around the
109wxHtmlPrintout, normal wxWidgets printout class.
c33e257b 110
928f1a07
FM
111And finally there is the low level class wxHtmlDCRenderer which you can use to
112render HTML into a rectangular area on any DC.
36c9828f 113
928f1a07
FM
114It supports rendering into multiple rectangles with the same
115width. (The most common use of this is placing one rectangle on each page or
116printing into two columns.)
c33e257b
FM
117
118
928f1a07 119@section overview_html_helpformats Help Files Format
36c9828f 120
4726bcc5
FM
121wxHTML library can be used to show an help manual to the user; in fact, it supports
122natively (through wxHtmlHelpController) a reduced version of MS HTML Workshop format.
c33e257b 123
928f1a07
FM
124A @b book consists of three files: the header file, the contents file
125and the index file.
c33e257b 126
928f1a07 127You can make a regular zip archive of these files, plus the HTML and any
4726bcc5
FM
128image files, for wxHTML (or helpview) to read; and the @c ".zip" file can
129optionally be renamed to @c ".htb".
c33e257b 130
928f1a07 131@subsection overview_html_helpformats_hhp Header file (.hhp)
c33e257b 132
928f1a07
FM
133The header file must contain these lines (and may contain additional lines
134which are ignored):
36c9828f 135
928f1a07
FM
136@code
137Contents file=filename.hhc
138Index file=filename.hhk
139Title=title of your book
140Default topic=default page to be displayed.htm
141@endcode
36c9828f 142
928f1a07 143All filenames (including the Default topic) are relative to the
4726bcc5 144location of the @c ".hhp" file.
36c9828f 145
4726bcc5 146@note For localization, in addition the @c ".hhp" file may contain the line
928f1a07 147 @code
c33e257b 148 Charset=rfc_charset
928f1a07
FM
149 @endcode
150 which specifies what charset (e.g. "iso8859_1") was used in contents
151 and index files. Please note that this line is incompatible with
152 MS HTML Help Workshop and it would either silently remove it or complain
153 with some error. See also @ref overview_nonenglish.
36c9828f 154
928f1a07 155@subsection overview_html_helpformats_hhc Contents file (.hhc)
c33e257b 156
928f1a07
FM
157Contents file has HTML syntax and it can be parsed by regular HTML parser.
158It contains exactly one list (@c &lt;ul&gt;....@c &lt;/ul&gt; statement):
36c9828f 159
928f1a07
FM
160@code
161<ul>
c33e257b 162
928f1a07 163<li><object type="text/sitemap">
c33e257b
FM
164 <param name="Name" value="@topic name@">
165 <param name="ID" value=@numeric_id@>
166 <param name="Local" value="@filename.htm@">
167 </object>
928f1a07 168<li><object type="text/sitemap">
c33e257b
FM
169 <param name="Name" value="@topic name@">
170 <param name="ID" value=@numeric_id@>
171 <param name="Local" value="@filename.htm@">
172 </object>
928f1a07
FM
173...
174</ul>
175@endcode
36c9828f 176
928f1a07
FM
177You can modify value attributes of param tags.
178The <em>topic name</em> is name of chapter/topic as is displayed in
4726bcc5 179contents, <em>filename.htm</em> is the HTML page name (relative to the @c ".hhp" file)
928f1a07 180and <em>numeric_id</em> is optional - it is used only when you use wxHtmlHelpController::Display(int).
36c9828f 181
928f1a07 182Items in the list may be nested - one @c &lt;li&gt; statement may contain a @c &lt;ul&gt; sub-statement:
36c9828f 183
928f1a07
FM
184@code
185<ul>
c33e257b 186
928f1a07
FM
187<li><object type="text/sitemap">
188 <param name="Name" value="Top node">
189 <param name="Local" value="top.htm">
190 </object>
191 <ul>
192 <li><object type="text/sitemap">
193 <param name="Name" value="subnode in topnode">
194 <param name="Local" value="subnode1.htm">
195 </object>
196 ...
197 </ul>
c33e257b 198
928f1a07
FM
199<li><object type="text/sitemap">
200 <param name="Name" value="Another Top">
201 <param name="Local" value="top2.htm">
202 </object>
203...
c33e257b 204
928f1a07
FM
205</ul>
206@endcode
36c9828f 207
928f1a07 208@subsection overview_html_helpformats_hhk Index file (.hhk)
3c4f71cc 209
4726bcc5 210Index files have same format as contents files except that ID params are ignored
928f1a07 211and sublists are @b not allowed.
c33e257b 212
36c9828f 213
928f1a07 214@section overview_html_filters Input Filters
36c9828f 215
928f1a07
FM
216The wxHTML library provides a mechanism for reading and displaying
217files of many different file formats.
c33e257b 218
928f1a07
FM
219wxHtmlWindow::LoadPage can load not only HTML files but any known file.
220To make a file type known to wxHtmlWindow you must create a wxHtmlFilter filter and
221register it using wxHtmlWindow::AddFilter.
36c9828f 222
36c9828f 223
928f1a07 224@section overview_html_cells Cells and Containers
c33e257b 225
928f1a07
FM
226This article describes mechanism used by wxHtmlWinParser and
227wxHtmlWindow to parse and display HTML documents.
c33e257b 228
928f1a07 229@subsection overview_html_cells_cells Cells
c33e257b 230
928f1a07
FM
231You can divide any text (or HTML) into small fragments. Let's call these
232fragments @b cells. Cell is for example one word, horizontal line, image
233or any other part of document. Each cell has width and height (except special
234"magic" cells with zero dimensions - e.g. colour changers or font changers).
235See wxHtmlCell.
c33e257b 236
928f1a07 237@subsection overview_html_cells_containers Containers
c33e257b 238
928f1a07
FM
239Container is kind of cell that may contain sub-cells. Its size depends
240on number and sizes of its sub-cells (and also depends on width of window).
241See wxHtmlContainerCell, wxHtmlCell::Layout. This image shows the cells and
242containers:
de2b67e6 243
928f1a07 244@image html overview_html_contbox.png
c33e257b 245
928f1a07 246@subsection overview_html_cells_conttaghandler Using Containers in Tag Handler
c33e257b 247
928f1a07
FM
248wxHtmlWinParser provides a user-friendly way of managing containers.
249It is based on the idea of opening and closing containers.
c33e257b 250
928f1a07
FM
251Use wxHtmlWinParser::OpenContainer to open new a container @e within an already
252opened container.
253This new container is a @e sub-container of the old one. (If you want to create a
254new container with the same depth level you can call @c CloseContainer(); OpenContainer();.)
c33e257b 255
928f1a07
FM
256Use wxHtmlWinParser::CloseContainer to close the container.
257This doesn't create a new container with same depth level but it returns "control"
258to the parent container. See explanation:
de2b67e6 259
928f1a07 260@image html overview_html_cont.png
36c9828f 261
928f1a07
FM
262There clearly must be same number of calls to OpenContainer as to
263CloseContainer.
c33e257b 264
928f1a07 265@subsubsection overview_html_cells_conttaghandler_example Example
c33e257b 266
928f1a07
FM
267This code creates a new paragraph (container at same depth level)
268with "Hello, world!":
36c9828f 269
928f1a07
FM
270@code
271m_WParser -> CloseContainer();
272c = m_WParser -> OpenContainer();
36c9828f 273
928f1a07
FM
274m_WParser -> AddText("Hello, ");
275m_WParser -> AddText("world!");
36c9828f 276
928f1a07
FM
277m_WParser -> CloseContainer();
278m_WParser -> OpenContainer();
279@endcode
36c9828f 280
928f1a07 281and here is image of the situation:
de2b67e6 282
928f1a07 283@image html overview_html_hello.png
36c9828f 284
928f1a07
FM
285You can see that there was an opened container before the code was executed.
286We closed it, created our own container, then closed our container and opened
287new container.
c33e257b 288
928f1a07
FM
289The result was that we had @e same depth level after executing.
290This is general rule that should be followed by tag handlers:
291leave depth level of containers unmodified (in other words, number of
292OpenContainer and CloseContainer calls should be same within
293wxHtmlTagHandler::HandleTag's body).
c33e257b 294
928f1a07
FM
295Notice that it would be usually better to use wxHtmlContainerCell::InsertCell instead
296of adding text to the parser directly.
36c9828f 297
c33e257b 298
928f1a07 299@section overview_html_handlers Tag Handlers
36c9828f 300
928f1a07
FM
301The wxHTML library provides architecture of pluggable @e tag handlers.
302Tag handler is class that understands particular HTML tag (or tags) and is
303able to interpret it.
c33e257b 304
928f1a07
FM
305wxHtmlWinParser has a static table of @b modules.
306Each module contains one or more tag handlers. Each time a new wxHtmlWinParser
307object is constructed all modules are scanned and handlers are added
308to wxHtmlParser's list of available handlers (note: wxHtmlParser's list
309is non-static).
36c9828f 310
928f1a07 311@subsection overview_html_handlers_howworks How it works
c33e257b 312
928f1a07 313Common tag handler's wxHtmlTagHandler::HandleTag method works in four steps:
36c9828f 314
928f1a07
FM
315@li Save state of parent parser into local variables
316@li Change parser state according to tag's params
317@li Parse text between the tag and paired ending tag (if present)
318@li Restore original parser state
36c9828f 319
928f1a07
FM
320See wxHtmlWinParser for methods for modifying parser's state.
321In general you can do things like opening/closing containers, changing colors, fonts etc.
36c9828f 322
928f1a07 323@subsection overview_html_handlers_custom Providing own tag handlers
c33e257b 324
928f1a07 325You should create a new .cpp file and place the following lines into it:
36c9828f 326
928f1a07
FM
327@code
328#include <mod_templ.h>
329#include <forcelink.h>
330FORCE_LINK_ME(yourmodulefilenamewithoutcpp)
331@endcode
36c9828f 332
928f1a07 333Then you must define handlers and one module.
36c9828f 334
928f1a07 335@subsection overview_html_handlers_tag Tag handlers
36c9828f 336
928f1a07 337The handler is derived from wxHtmlWinTagHandler (or directly from wxHtmlTagHandler).
36c9828f 338
928f1a07
FM
339You can use set of macros to define the handler (see src/html/m_*.cpp files
340for details). Handler definition must start with @b TAG_HANDLER_BEGIN macro
341and end with @b TAG_HANDLER_END macro.
36c9828f 342
928f1a07
FM
343I strongly recommend to have a look at @e include/wxhtml/mod_templ.h file.
344Otherwise you won't understand the structure of macros.
36c9828f 345
928f1a07
FM
346See macros reference:
347@li @b TAG_HANDLER_BEGIN(@e name, @e tags):
348 Starts handler definition. @e name is handler identifier (in fact
349 part of class name), @e tags is string containing list of tags
350 supported by this handler (in uppercase). This macro derives new class from
351 wxHtmlWinTagHandler and implements it is wxHtmlTagHandler::GetSupportedTags method.
352 Example: TAG_HANDLER_BEGIN(FONTS, "B,I,U,T")
c33e257b 353
928f1a07
FM
354@li @b TAG_HANDLER_VARS:
355 This macro starts block of variables definitions. (Variables are identical
356 to class attributes.) Example:
3c4f71cc 357
928f1a07
FM
358 @code
359 TAG_HANDLER_BEGIN(VARS_ONLY, "CRAZYTAG")
c33e257b
FM
360 TAG_HANDLER_VARS
361 int my_int_var;
362 wxString something_else;
928f1a07
FM
363 TAG_HANDLER_END(VARS_ONLY)
364 @endcode
3c4f71cc 365
928f1a07 366 This macro is used only in rare cases.
c33e257b 367
928f1a07
FM
368@li @b TAG_HANDLER_CONSTR(@e name):
369 This macro supplies object constructor. @e name is same name as the one
370 from TAG_HANDLER_BEGIN macro. Body of constructor follow after
371 this macro (you must use { and } ). Example:
3c4f71cc 372
928f1a07
FM
373 @code
374 TAG_HANDLER_BEGIN(VARS2, "CRAZYTAG")
c33e257b
FM
375 TAG_HANDLER_VARS
376 int my_int_var;
377 TAG_HANDLER_CONSTR(vars2)
378 { // !!!!!!
928f1a07 379 my_int_var = 666;
c33e257b 380 } // !!!!!!
928f1a07
FM
381 TAG_HANDLER_END(VARS2)
382 @endcode
3c4f71cc 383
928f1a07 384 Never used in wxHTML :-)
c33e257b 385
928f1a07
FM
386@li @b TAG_HANDLER_PROC(@e varib):
387 This is very important macro. It defines wxHtmlTagHandler::HandleTag
388 method. @e varib is name of parameter passed to the method, usually
389 @e tag. Body of method follows after this macro.
390 Note than you must use { and } !
391 Example:
3c4f71cc 392
928f1a07
FM
393 @code
394 TAG_HANDLER_BEGIN(TITLE, "TITLE")
c33e257b
FM
395 TAG_HANDLER_PROC(tag)
396 {
928f1a07 397 printf("TITLE found...\n");
c33e257b 398 }
928f1a07
FM
399 TAG_HANDLER_END(TITLE)
400 @endcode
c33e257b 401
928f1a07
FM
402@li @b TAG_HANDLER_END(@e name):
403 Ends definition of tag handler @e name.
c33e257b 404
928f1a07 405@subsection overview_html_handlers_modules Tags Modules
36c9828f 406
928f1a07
FM
407You can use set of 3 macros TAGS_MODULE_BEGIN, TAGS_MODULE_ADD and
408TAGS_MODULE_END to inherit new module from
409wxHtmlTagsModule and to create instance of it.
36c9828f 410
928f1a07 411See macros reference:
36c9828f 412
928f1a07
FM
413@li @b TAGS_MODULE_BEGIN(@e modname):
414 Begins module definition. @e modname is part of class name and must be unique.
415@li @b TAGS_MODULE_ADD(@e name):
416 Adds the handler to this module. @e name is the identifier from TAG_HANDLER_BEGIN.
417@li @b TAGS_MODULE_END(@e modname):
418 Ends the definition of module.
419 Example:
3c4f71cc 420
928f1a07
FM
421 @code
422 TAGS_MODULE_BEGIN(Examples)
c33e257b
FM
423 TAGS_MODULE_ADD(VARS_ONLY)
424 TAGS_MODULE_ADD(VARS2)
425 TAGS_MODULE_ADD(TITLE)
928f1a07
FM
426 TAGS_MODULE_END(Examples)
427 @endcode
428
429
430@section overview_html_supptags Tags supported by wxHTML
431
432wxHTML is not full implementation of HTML standard. Instead, it supports most
433common tags so that it is possible to display @e simple HTML documents with it.
434(For example it works fine with pages created in Netscape Composer or generated by tex2rtf).
435
436Following tables list all tags known to wxHTML, together with supported parameters.
437
438A tag has general form of @c tagname param_1 param_2 ... param_n where param_i is
439either @c paramname="paramvalue" or @c paramname=paramvalue - these two are equivalent.
440Unless stated otherwise, wxHTML is case-insensitive.
441
442@subsection overview_html_supptags_commonvalues Table of common parameter values
443
444We will use these substitutions in tags descriptions:
445
446@code
447[alignment] CENTER
448 LEFT
449 RIGHT
450 JUSTIFY
451
452[v_alignment] TOP
453 BOTTOM
454 CENTER
455
456[color] HTML 4.0-compliant colour specification
457
458[fontsize] -2
459 -1
460 +0
461 +1
462 +2
463 +3
464 +4
465 1
466 2
467 3
468 4
469 5
470 6
471 7
472
473[pixels] integer value that represents dimension in pixels
474
475[percent] i%
476 where i is integer
477
478[url] an URL
479
480[string] text string
481
482[coords] c(1),c(2),c(3),...,c(n)
483 where c(i) is integer
484@endcode
485
486
487@subsection overview_html_supptags_list List of supported tags
488
489@code
490A NAME=[string]
491 HREF=[url]
492 TARGET=[target window spec]
493ADDRESS
494AREA SHAPE=POLY
495 SHAPE=CIRCLE
496 SHAPE=RECT
497 COORDS=[coords]
498 HREF=[url]
499B
500BIG
501BLOCKQUOTE
502BODY TEXT=[color]
503 LINK=[color]
504 BGCOLOR=[color]
505BR ALIGN=[alignment]
506CENTER
507CITE
508CODE
509DD
510DIV ALIGN=[alignment]
511DL
512DT
513EM
514FONT COLOR=[color]
515 SIZE=[fontsize]
516 FACE=[comma-separated list of facenames]
517HR ALIGN=[alignment]
518 SIZE=[pixels]
519 WIDTH=[percent|pixels]
520 NOSHADE
521H1
522H2
523H3
524H4
525H5
526H6
527I
528IMG SRC=[url]
fa794151 529 WIDTH=[percent|pixels]
928f1a07
FM
530 HEIGHT=[pixels]
531 ALIGN=TEXTTOP
532 ALIGN=CENTER
533 ALIGN=ABSCENTER
534 ALIGN=BOTTOM
535 USEMAP=[url]
536KBD
537LI
538MAP NAME=[string]
539META HTTP-EQUIV="Content-Type"
540 CONTENT=[string]
541OL
542P ALIGN=[alignment]
543PRE
544SAMP
545SMALL
f68e16c5 546SPAN
928f1a07
FM
547STRIKE
548STRONG
549SUB
550SUP
551TABLE ALIGN=[alignment]
552 WIDTH=[percent|pixels]
553 BORDER=[pixels]
554 VALIGN=[v_alignment]
555 BGCOLOR=[color]
556 CELLSPACING=[pixels]
557 CELLPADDING=[pixels]
558TD ALIGN=[alignment]
559 VALIGN=[v_alignment]
560 BGCOLOR=[color]
561 WIDTH=[percent|pixels]
562 COLSPAN=[pixels]
563 ROWSPAN=[pixels]
564 NOWRAP
565TH ALIGN=[alignment]
566 VALIGN=[v_alignment]
567 BGCOLOR=[color]
568 WIDTH=[percent|pixels]
569 COLSPAN=[pixels]
570 ROWSPAN=[pixels]
571TITLE
572TR ALIGN=[alignment]
573 VALIGN=[v_alignment]
574 BGCOLOR=[color]
575TT
576U
577UL
578@endcode
36c9828f 579
f68e16c5
VZ
580@subsection overview_html_suppstyles_list List of supported styles
581
582wxHTML doesn't really have CSS support but it does support a few simple styles:
583you can use @c "text-align", @c "width", @c "vertical-align" and @c
584"background" with all elements and for @c SPAN elements the @c "color", @c
585"font-size" and @c "font-weight" are additionally recognized.
586
c33e257b 587*/
36c9828f 588