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