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