]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/html/htmlwin.h
add WX_CLEAR_ARRAY test
[wxWidgets.git] / interface / wx / html / htmlwin.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: html/htmlwin.h
e54c96f1 3// Purpose: interface of wxHtmlWindow
23324ae1
FM
4// Author: wxWidgets team
5// RCS-ID: $Id$
6// Licence: wxWindows license
7/////////////////////////////////////////////////////////////////////////////
8
9/**
10 @class wxHtmlWindow
7c913512 11
5bddd46d
FM
12 wxHtmlWindow is probably the only class you will directly use unless you want
13 to do something special (like adding new tag handlers or MIME filters).
7c913512 14
5bddd46d
FM
15 The purpose of this class is to display HTML pages (either local file or
16 downloaded via HTTP protocol) in a window.
17 The width of the window is constant - given in the constructor - and virtual height
23324ae1 18 is changed dynamically depending on page size.
5bddd46d
FM
19 Once the window is created you can set its content by calling SetPage(text),
20 LoadPage(filename) or wxHtmlWindow::LoadFile.
21
22 @note
23 wxHtmlWindow uses the wxImage class for displaying images.
24 Don't forget to initialize all image formats you need before loading any page!
25 (See ::wxInitAllImageHandlers and wxImage::AddHandler.)
7c913512 26
23324ae1 27 @beginStyleTable
8c6791e4 28 @style{wxHW_SCROLLBAR_NEVER}
23324ae1
FM
29 Never display scrollbars, not even when the page is larger than the
30 window.
8c6791e4 31 @style{wxHW_SCROLLBAR_AUTO}
23324ae1 32 Display scrollbars only if page's size exceeds window's size.
8c6791e4 33 @style{wxHW_NO_SELECTION}
23324ae1
FM
34 Don't allow the user to select text.
35 @endStyleTable
7c913512 36
5bddd46d
FM
37
38 @beginEventTable{wxHtmlCellEvent, wxHtmlLinkEvent}
39 @event{EVT_HTML_CELL_CLICKED(id, func)}
40 A wxHtmlCell was clicked.
41 @event{EVT_HTML_CELL_HOVER(id, func)}
42 The mouse passed over a wxHtmlCell.
43 @event{EVT_HTML_LINK_CLICKED(id, func)}
44 A wxHtmlCell which contains an hyperlink was clicked.
45 @endEventTable
46
23324ae1
FM
47 @library{wxhtml}
48 @category{html}
7c913512 49
e54c96f1 50 @see wxHtmlLinkEvent, wxHtmlCellEvent
23324ae1
FM
51*/
52class wxHtmlWindow : public wxScrolledWindow
53{
54public:
23324ae1 55 /**
5bddd46d 56 Default ctor.
23324ae1
FM
57 */
58 wxHtmlWindow();
5bddd46d
FM
59
60 /**
61 Constructor.
62 The parameters are the same as wxScrolled::wxScrolled() constructor.
63 */
7c913512
FM
64 wxHtmlWindow(wxWindow parent, wxWindowID id = -1,
65 const wxPoint& pos = wxDefaultPosition,
66 const wxSize& size = wxDefaultSize,
67 long style = wxHW_DEFAULT_STYLE,
68 const wxString& name = "htmlWindow");
23324ae1
FM
69 //@}
70
71 /**
5bddd46d 72 Adds @ref overview_html_filters "input filter" to the static list of available
23324ae1 73 filters. These filters are present by default:
5bddd46d
FM
74 - @c text/html MIME type
75 - @c image/* MIME types
76 - Plain Text filter (this filter is used if no other filter matches)
23324ae1
FM
77 */
78 static void AddFilter(wxHtmlFilter filter);
79
80 /**
7c913512 81 Appends HTML fragment to currently displayed text and refreshes the window.
551266a9 82
7c913512 83 @param source
4cc4bfaf 84 HTML code fragment
551266a9 85
d29a9a8a 86 @return @false if an error occurred, @true otherwise.
23324ae1
FM
87 */
88 bool AppendToPage(const wxString& source);
89
90 /**
91 Returns pointer to the top-level container.
5bddd46d
FM
92
93 @see @ref overview_html_cells, @ref overview_printing
23324ae1 94 */
328f5751 95 wxHtmlContainerCell* GetInternalRepresentation() const;
23324ae1
FM
96
97 /**
5bddd46d
FM
98 Returns anchor within currently opened page (see wxHtmlWindow::GetOpenedPage).
99 If no page is opened or if the displayed page wasn't produced by call to
100 LoadPage(), empty string is returned.
23324ae1 101 */
adaaa686 102 wxString GetOpenedAnchor() const;
23324ae1
FM
103
104 /**
5bddd46d
FM
105 Returns full location of the opened page.
106 If no page is opened or if the displayed page wasn't produced by call to
107 LoadPage(), empty string is returned.
23324ae1 108 */
adaaa686 109 wxString GetOpenedPage() const;
23324ae1
FM
110
111 /**
112 Returns title of the opened page or wxEmptyString if current page does not
5bddd46d 113 contain \<TITLE\> tag.
23324ae1 114 */
adaaa686 115 wxString GetOpenedPageTitle() const;
23324ae1
FM
116
117 /**
118 Returns the related frame.
119 */
328f5751 120 wxFrame* GetRelatedFrame() const;
23324ae1
FM
121
122 /**
5bddd46d
FM
123 Moves back to the previous page.
124 (each page displayed using LoadPage() is stored in history list.)
23324ae1
FM
125 */
126 bool HistoryBack();
127
128 /**
5bddd46d
FM
129 Returns @true if it is possible to go back in the history
130 (i.e. HistoryBack() won't fail).
23324ae1
FM
131 */
132 bool HistoryCanBack();
133
134 /**
5bddd46d
FM
135 Returns @true if it is possible to go forward in the history
136 (i.e. HistoryBack() won't fail).
23324ae1
FM
137 */
138 bool HistoryCanForward();
139
140 /**
141 Clears history.
142 */
143 void HistoryClear();
144
145 /**
146 Moves to next page in history.
147 */
148 bool HistoryForward();
149
150 /**
151 Loads HTML page from file and displays it.
551266a9 152
d29a9a8a 153 @return @false if an error occurred, @true otherwise
551266a9 154
4cc4bfaf 155 @see LoadPage()
23324ae1 156 */
adaaa686 157 bool LoadFile(const wxFileName& filename);
23324ae1
FM
158
159 /**
5bddd46d 160 Unlike SetPage() this function first loads HTML page from @a location
23324ae1 161 and then displays it. See example:
551266a9 162
7c913512 163 @param location
5bddd46d
FM
164 The address of document.
165 See wxFileSystem for details on address format and behaviour of "opener".
551266a9 166
d29a9a8a 167 @return @false if an error occurred, @true otherwise
551266a9 168
4cc4bfaf 169 @see LoadFile()
23324ae1
FM
170 */
171 virtual bool LoadPage(const wxString& location);
172
23324ae1 173 /**
5bddd46d
FM
174 Called when user clicks on hypertext link.
175 Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not
176 processed or skipped, call LoadPage() and do nothing else.
177
23324ae1 178 Overloading this method is deprecated; intercept the event instead.
5bddd46d 179
23324ae1
FM
180 Also see wxHtmlLinkInfo.
181 */
182 virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
183
184 /**
185 Called when an URL is being opened (either when the user clicks on a link or
5bddd46d
FM
186 an image is loaded). The URL will be opened only if OnOpeningURL() returns
187 @c wxHTML_OPEN. This method is called by wxHtmlParser::OpenURL.
188
189 You can override OnOpeningURL() to selectively block some URLs
190 (e.g. for security reasons) or to redirect them elsewhere.
191 Default behaviour is to always return @c wxHTML_OPEN.
551266a9 192
7c913512 193 @param type
4cc4bfaf 194 Indicates type of the resource. Is one of
5bddd46d
FM
195 - wxHTML_URL_PAGE: Opening a HTML page.
196 - wxHTML_URL_IMAGE: Opening an image.
197 - wxHTML_URL_OTHER: Opening a resource that doesn't fall into
198 any other category.
4cc4bfaf
FM
199 @param url
200 URL being opened.
7c913512 201 @param redirect
4cc4bfaf 202 Pointer to wxString variable that must be filled with an
5bddd46d
FM
203 URL if OnOpeningURL() returns @c wxHTML_REDIRECT.
204
205 The return value is:
206 - wxHTML_OPEN: Open the URL.
207 - wxHTML_BLOCK: Deny access to the URL, wxHtmlParser::OpenURL will return @NULL.
208 - wxHTML_REDIRECT: Don't open url, redirect to another URL.
209 OnOpeningURL() must fill *redirect with the new URL.
210 OnOpeningURL() will be called again on returned URL.
23324ae1
FM
211 */
212 virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
adaaa686
FM
213 const wxString& url,
214 wxString* redirect) const;
23324ae1
FM
215
216 /**
5bddd46d 217 Called on parsing \<TITLE\> tag.
23324ae1
FM
218 */
219 virtual void OnSetTitle(const wxString& title);
220
221 /**
222 This reads custom settings from wxConfig. It uses the path 'path'
223 if given, otherwise it saves info into currently selected path.
5bddd46d
FM
224 The values are stored in sub-path @c wxHtmlWindow.
225 Read values: all things set by SetFonts(), SetBorders().
551266a9 226
7c913512 227 @param cfg
4cc4bfaf 228 wxConfig from which you want to read the configuration.
7c913512 229 @param path
4cc4bfaf 230 Optional path in config tree. If not given current path is used.
23324ae1
FM
231 */
232 virtual void ReadCustomization(wxConfigBase cfg,
233 wxString path = wxEmptyString);
234
235 /**
236 Selects all text in the window.
551266a9 237
4cc4bfaf 238 @see SelectLine(), SelectWord()
23324ae1
FM
239 */
240 void SelectAll();
241
242 /**
4cc4bfaf 243 Selects the line of text that @a pos points at. Note that @e pos
23324ae1 244 is relative to the top of displayed page, not to window's origin, use
f09b5681 245 wxScrolled::CalcUnscrolledPosition()
23324ae1 246 to convert physical coordinate.
551266a9 247
4cc4bfaf 248 @see SelectAll(), SelectWord()
23324ae1
FM
249 */
250 void SelectLine(const wxPoint& pos);
251
252 /**
5bddd46d
FM
253 Selects the word at position @a pos.
254 Note that @a pos is relative to the top of displayed page, not to window's
255 origin, use wxScrolled::CalcUnscrolledPosition() to convert physical coordinate.
551266a9 256
4cc4bfaf 257 @see SelectAll(), SelectLine()
23324ae1
FM
258 */
259 void SelectWord(const wxPoint& pos);
260
261 /**
5bddd46d
FM
262 Returns current selection as plain text.
263 Returns empty string if no text is currently selected.
23324ae1
FM
264 */
265 wxString SelectionToText();
266
267 /**
5bddd46d
FM
268 This function sets the space between border of window and HTML contents.
269 See image:
270 @image html border.png
551266a9 271
7c913512 272 @param b
4cc4bfaf 273 indentation from borders in pixels
23324ae1
FM
274 */
275 void SetBorders(int b);
276
277 /**
278 This function sets font sizes and faces.
551266a9 279
7c913512 280 @param normal_face
4cc4bfaf
FM
281 This is face name for normal (i.e. non-fixed) font.
282 It can be either empty string (then the default face is chosen) or
283 platform-specific face name. Examples are "helvetica" under Unix or
284 "Times New Roman" under Windows.
7c913512 285 @param fixed_face
5bddd46d 286 The same thing for fixed face ( \<TT\>..\</TT\> )
7c913512 287 @param sizes
4cc4bfaf
FM
288 This is an array of 7 items of int type.
289 The values represent size of font with HTML size from -2 to +4
5bddd46d
FM
290 ( \<FONT SIZE=-2\> to \<FONT SIZE=+4\> ).
291 Default sizes are used if sizes is @NULL.
292
293 Default font sizes are defined by constants wxHTML_FONT_SIZE_1,
294 wxHTML_FONT_SIZE_2, ..., wxHTML_FONT_SIZE_7.
295 Note that they differ among platforms. Default face names are empty strings.
23324ae1
FM
296 */
297 void SetFonts(const wxString& normal_face,
298 const wxString& fixed_face,
4cc4bfaf 299 const int sizes = NULL);
23324ae1
FM
300
301 /**
302 Sets HTML page and display it. This won't @b load the page!!
303 It will display the @e source. See example:
5bddd46d
FM
304 @code
305 htmlwin -> SetPage("<html><body>Hello, world!</body></html>");
306 @endcode
551266a9 307
5bddd46d 308 If you want to load a document from some location use LoadPage() instead.
551266a9 309
7c913512 310 @param source
4cc4bfaf 311 The HTML document source to be displayed.
551266a9 312
d29a9a8a 313 @return @false if an error occurred, @true otherwise.
23324ae1 314 */
adaaa686 315 virtual bool SetPage(const wxString& source);
23324ae1
FM
316
317 /**
5bddd46d
FM
318 Sets the frame in which page title will be displayed.
319 @a format is the format of the frame title, e.g. "HtmlHelp : %s".
320 It must contain exactly one %s.
321 This %s is substituted with HTML page title.
23324ae1
FM
322 */
323 void SetRelatedFrame(wxFrame* frame, const wxString& format);
324
325 /**
5bddd46d
FM
326 @b After calling SetRelatedFrame(), this sets statusbar slot where messages
327 will be displayed. (Default is -1 = no messages.)
37146d33
VS
328
329 @param index
330 Statusbar slot number (0..n)
331 */
332 void SetRelatedStatusBar(int index);
333
334 /**
335 @b Sets the associated statusbar where messages will be displayed.
336 Call this instead of SetRelatedFrame() if you want statusbar updates only,
337 no changing of the frame title.
338
339 @param statusbar
340 Statusbar pointer
341 @param index
342 Statusbar slot number (0..n)
343
344 @since 2.9.0
23324ae1 345 */
37146d33 346 void SetRelatedStatusBar(wxStatusBar* statusbar, int index = 0);
23324ae1
FM
347
348 /**
349 Returns content of currently displayed page as plain text.
350 */
351 wxString ToText();
352
353 /**
5bddd46d
FM
354 Saves custom settings into wxConfig.
355 It uses the path 'path' if given, otherwise it saves info into currently
356 selected path.
357 Regardless of whether the path is given or not, the function creates
358 sub-path @c wxHtmlWindow.
359
360 Saved values: all things set by SetFonts(), SetBorders().
551266a9 361
7c913512 362 @param cfg
4cc4bfaf 363 wxConfig to which you want to save the configuration.
7c913512 364 @param path
4cc4bfaf 365 Optional path in config tree. If not given, the current path is used.
23324ae1
FM
366 */
367 virtual void WriteCustomization(wxConfigBase cfg,
368 wxString path = wxEmptyString);
551266a9
FM
369
370protected:
371
372 /**
373 This method is called when a mouse button is clicked inside wxHtmlWindow.
5bddd46d
FM
374 The default behaviour is to emit a wxHtmlCellEvent and, if the event was
375 not processed or skipped, call OnLinkClicked() if the cell contains an
551266a9 376 hypertext link.
5bddd46d 377
551266a9
FM
378 Overloading this method is deprecated; intercept the event instead.
379
380 @param cell
381 The cell inside which the mouse was clicked, always a simple
382 (i.e. non-container) cell
5bddd46d
FM
383 @param x
384 The logical x coordinate of the click point
385 @param y
386 The logical y coordinate of the click point
551266a9
FM
387 @param event
388 The mouse event containing other information about the click
389
390 @return @true if a link was clicked, @false otherwise.
391 */
392 virtual bool OnCellClicked(wxHtmlCell cell, wxCoord x, wxCoord y,
393 const wxMouseEvent& event);
394
395 /**
396 This method is called when a mouse moves over an HTML cell.
397 Default behaviour is to emit a wxHtmlCellEvent.
5bddd46d 398
551266a9
FM
399 Overloading this method is deprecated; intercept the event instead.
400
401 @param cell
402 The cell inside which the mouse is currently, always a simple
403 (i.e. non-container) cell
5bddd46d
FM
404 @param x
405 The logical x coordinate of the click point
406 @param y
407 The logical y coordinate of the click point
551266a9
FM
408 */
409 virtual void OnCellMouseHover(wxHtmlCell cell, wxCoord x, wxCoord y);
23324ae1
FM
410};
411
412
e54c96f1 413
23324ae1
FM
414/**
415 @class wxHtmlLinkEvent
7c913512 416
23324ae1 417 This event class is used for the events generated by wxHtmlWindow.
7c913512 418
5bddd46d
FM
419 @beginEventTable{wxHtmlLinkEvent}
420 @event{EVT_HTML_LINK_CLICKED(id, func)}
421 User clicked on an hyperlink.
422 @endEventTable
423
23324ae1 424 @library{wxhtml}
5bddd46d 425 @category{html}
23324ae1
FM
426*/
427class wxHtmlLinkEvent : public wxCommandEvent
428{
429public:
430 /**
431 The constructor is not normally used by the user code.
432 */
4cc4bfaf 433 wxHyperlinkEvent(int id, const wxHtmlLinkInfo& linkinfo);
23324ae1
FM
434
435 /**
5bddd46d
FM
436 Returns the wxHtmlLinkInfo which contains info about the cell clicked
437 and the hyperlink it contains.
23324ae1 438 */
5bddd46d 439 const wxHtmlLinkInfo& GetLinkInfo() const;
23324ae1
FM
440};
441
442
e54c96f1 443
23324ae1
FM
444/**
445 @class wxHtmlCellEvent
7c913512 446
23324ae1 447 This event class is used for the events generated by wxHtmlWindow.
7c913512 448
5bddd46d
FM
449 @beginEventTable{wxHtmlCellEvent}
450 @event{EVT_HTML_CELL_HOVER(id, func)}
451 User moved the mouse over a wxHtmlCell.
452 @event{EVT_HTML_CELL_CLICKED(id, func)}
453 User clicked on a wxHtmlCell. When handling this event, remember to use
454 wxHtmlCell::SetLinkClicked(true) if the cell contains a link.
455 @endEventTable
456
23324ae1 457 @library{wxhtml}
5bddd46d 458 @category{html}
23324ae1
FM
459*/
460class wxHtmlCellEvent : public wxCommandEvent
461{
462public:
463 /**
464 The constructor is not normally used by the user code.
465 */
466 wxHtmlCellEvent(wxEventType commandType, int id,
4cc4bfaf
FM
467 wxHtmlCell* cell,
468 const wxPoint& point);
23324ae1
FM
469
470 /**
471 Returns the wxHtmlCellEvent associated with the event.
472 */
328f5751 473 wxHtmlCell* GetCell() const;
23324ae1
FM
474
475 /**
5bddd46d 476 Returns @true if SetLinkClicked(@true) has previously been called;
23324ae1
FM
477 @false otherwise.
478 */
328f5751 479 bool GetLinkClicked() const;
23324ae1
FM
480
481 /**
482 Returns the wxPoint associated with the event.
483 */
328f5751 484 wxPoint GetPoint() const;
23324ae1
FM
485
486 /**
5bddd46d
FM
487 Call this function with @a linkclicked set to @true if the cell which has
488 been clicked contained a link or @false otherwise (which is the default).
489
490 With this function the event handler can return info to the wxHtmlWindow
491 which sent the event.
23324ae1
FM
492 */
493 bool SetLinkClicked(bool linkclicked);
494};
e54c96f1 495