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