]> git.saurik.com Git - wxWidgets.git/blame - interface/wx/html/htmlwin.h
Implement setFont on the iOS port of wxStaticText.
[wxWidgets.git] / interface / wx / html / htmlwin.h
CommitLineData
23324ae1
FM
1/////////////////////////////////////////////////////////////////////////////
2// Name: html/htmlwin.h
e54c96f1 3// Purpose: interface of wxHtmlWindow
23324ae1 4// Author: wxWidgets team
526954c5 5// Licence: wxWindows licence
23324ae1
FM
6/////////////////////////////////////////////////////////////////////////////
7
90f011dc
RD
8// wxHtmlWindow flags:
9#define wxHW_SCROLLBAR_NEVER 0x0002
10#define wxHW_SCROLLBAR_AUTO 0x0004
11#define wxHW_NO_SELECTION 0x0008
12
13#define wxHW_DEFAULT_STYLE wxHW_SCROLLBAR_AUTO
14
15
16/// Enum for wxHtmlWindow::OnOpeningURL and wxHtmlWindowInterface::OnOpeningURL
17enum wxHtmlOpeningStatus
18{
19 /// Open the requested URL
20 wxHTML_OPEN,
21 /// Do not open the URL
22 wxHTML_BLOCK,
23 /// Redirect to another URL (returned from OnOpeningURL)
24 wxHTML_REDIRECT
25};
26
27
28/**
29 @class wxHtmlWindowInterface
30
31 Abstract interface to a HTML rendering window (such as wxHtmlWindow or
32 wxHtmlListBox) that is passed to wxHtmlWinParser. It encapsulates all
33 communication from the parser to the window.
34 */
35class wxHtmlWindowInterface
36{
37public:
38 /// Ctor
39 wxHtmlWindowInterface();
40 virtual ~wxHtmlWindowInterface();
41
42 /**
43 Called by the parser to set window's title to given text.
44 */
45 virtual void SetHTMLWindowTitle(const wxString& title) = 0;
46
47 /**
48 Called when a link is clicked.
49
50 @param link information about the clicked link
51 */
52 virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link) = 0;
53
54 /**
55 Called when the parser needs to open another URL (e.g. an image).
56
57 @param type Type of the URL request (e.g. image)
58 @param url URL the parser wants to open
59 @param redirect If the return value is wxHTML_REDIRECT, then the
60 URL to redirect to will be stored in this variable
61 (the pointer must never be NULL)
62
63 @return indicator of how to treat the request
64 */
65 virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
66 const wxString& url,
67 wxString *redirect) const = 0;
68
69 /**
70 Converts coordinates @a pos relative to given @a cell to
71 physical coordinates in the window.
72 */
73 virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
74 const wxPoint& pos) const = 0;
75
76 /// Returns the window used for rendering (may be NULL).
77 virtual wxWindow* GetHTMLWindow() = 0;
78
79 /// Returns background colour to use by default.
80 virtual wxColour GetHTMLBackgroundColour() const = 0;
81
82 /// Sets window's background to colour @a clr.
83 virtual void SetHTMLBackgroundColour(const wxColour& clr) = 0;
84
85 /// Sets window's background to given bitmap.
86 virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg) = 0;
87
88 /// Sets status bar text.
89 virtual void SetHTMLStatusText(const wxString& text) = 0;
90
91 /// Type of mouse cursor
92 enum HTMLCursor
93 {
94 /// Standard mouse cursor (typically an arrow)
95 HTMLCursor_Default,
96 /// Cursor shown over links
97 HTMLCursor_Link,
98 /// Cursor shown over selectable text
99 HTMLCursor_Text
100 };
101
102 /**
103 Returns mouse cursor of given @a type.
104 */
105 virtual wxCursor GetHTMLCursor(wxHtmlWindowInterface::HTMLCursor type) const = 0;
106};
107
108
109
23324ae1
FM
110/**
111 @class wxHtmlWindow
7c913512 112
5bddd46d
FM
113 wxHtmlWindow is probably the only class you will directly use unless you want
114 to do something special (like adding new tag handlers or MIME filters).
7c913512 115
538f284a
SL
116 The purpose of this class is to display rich content pages (either local file or
117 downloaded via HTTP protocol) in a window based on a subset of the HTML standard.
5bddd46d 118 The width of the window is constant - given in the constructor - and virtual height
23324ae1 119 is changed dynamically depending on page size.
232fdc63
VZ
120 Once the window is created you can set its content by calling SetPage() with raw HTML,
121 LoadPage() with a wxFileSystem location or LoadFile() with a filename.
5bddd46d 122
538f284a
SL
123 @note
124 If you want complete HTML/CSS support as well as a Javascript engine, see instead
125 wxWebView.
126
5bddd46d 127 @note
232fdc63
VZ
128 wxHtmlWindow uses the wxImage class for displaying images, as such you need to
129 initialize the handlers for any image formats you use before loading a page.
130 See ::wxInitAllImageHandlers and wxImage::AddHandler.
7c913512 131
23324ae1 132 @beginStyleTable
8c6791e4 133 @style{wxHW_SCROLLBAR_NEVER}
23324ae1
FM
134 Never display scrollbars, not even when the page is larger than the
135 window.
8c6791e4 136 @style{wxHW_SCROLLBAR_AUTO}
23324ae1 137 Display scrollbars only if page's size exceeds window's size.
8c6791e4 138 @style{wxHW_NO_SELECTION}
23324ae1
FM
139 Don't allow the user to select text.
140 @endStyleTable
7c913512 141
5bddd46d 142
3051a44a 143 @beginEventEmissionTable{wxHtmlCellEvent, wxHtmlLinkEvent}
5bddd46d
FM
144 @event{EVT_HTML_CELL_CLICKED(id, func)}
145 A wxHtmlCell was clicked.
146 @event{EVT_HTML_CELL_HOVER(id, func)}
147 The mouse passed over a wxHtmlCell.
148 @event{EVT_HTML_LINK_CLICKED(id, func)}
149 A wxHtmlCell which contains an hyperlink was clicked.
150 @endEventTable
151
23324ae1
FM
152 @library{wxhtml}
153 @category{html}
7c913512 154
e54c96f1 155 @see wxHtmlLinkEvent, wxHtmlCellEvent
23324ae1 156*/
90f011dc 157class wxHtmlWindow : public wxScrolledWindow, public wxHtmlWindowInterface
23324ae1
FM
158{
159public:
23324ae1 160 /**
5bddd46d 161 Default ctor.
23324ae1
FM
162 */
163 wxHtmlWindow();
5bddd46d
FM
164
165 /**
166 Constructor.
167 The parameters are the same as wxScrolled::wxScrolled() constructor.
168 */
a44f3b5a 169 wxHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
7c913512
FM
170 const wxPoint& pos = wxDefaultPosition,
171 const wxSize& size = wxDefaultSize,
172 long style = wxHW_DEFAULT_STYLE,
173 const wxString& name = "htmlWindow");
23324ae1
FM
174
175 /**
5bddd46d 176 Adds @ref overview_html_filters "input filter" to the static list of available
23324ae1 177 filters. These filters are present by default:
5bddd46d
FM
178 - @c text/html MIME type
179 - @c image/* MIME types
180 - Plain Text filter (this filter is used if no other filter matches)
23324ae1 181 */
382f12e4 182 static void AddFilter(wxHtmlFilter* filter);
23324ae1
FM
183
184 /**
7c913512 185 Appends HTML fragment to currently displayed text and refreshes the window.
551266a9 186
7c913512 187 @param source
4cc4bfaf 188 HTML code fragment
551266a9 189
d29a9a8a 190 @return @false if an error occurred, @true otherwise.
23324ae1
FM
191 */
192 bool AppendToPage(const wxString& source);
193
194 /**
195 Returns pointer to the top-level container.
5bddd46d
FM
196
197 @see @ref overview_html_cells, @ref overview_printing
23324ae1 198 */
328f5751 199 wxHtmlContainerCell* GetInternalRepresentation() const;
23324ae1
FM
200
201 /**
5bddd46d
FM
202 Returns anchor within currently opened page (see wxHtmlWindow::GetOpenedPage).
203 If no page is opened or if the displayed page wasn't produced by call to
204 LoadPage(), empty string is returned.
23324ae1 205 */
adaaa686 206 wxString GetOpenedAnchor() const;
23324ae1
FM
207
208 /**
5bddd46d
FM
209 Returns full location of the opened page.
210 If no page is opened or if the displayed page wasn't produced by call to
211 LoadPage(), empty string is returned.
23324ae1 212 */
adaaa686 213 wxString GetOpenedPage() const;
23324ae1
FM
214
215 /**
232fdc63 216 Returns title of the opened page or wxEmptyString if the current page does not
5bddd46d 217 contain \<TITLE\> tag.
23324ae1 218 */
adaaa686 219 wxString GetOpenedPageTitle() const;
23324ae1
FM
220
221 /**
222 Returns the related frame.
223 */
328f5751 224 wxFrame* GetRelatedFrame() const;
23324ae1
FM
225
226 /**
232fdc63
VZ
227 Moves back to the previous page. Only pages displayed using LoadPage()
228 are stored in history list.
23324ae1
FM
229 */
230 bool HistoryBack();
231
232 /**
5bddd46d 233 Returns @true if it is possible to go back in the history
232fdc63 234 i.e. HistoryBack() won't fail.
23324ae1
FM
235 */
236 bool HistoryCanBack();
237
238 /**
5bddd46d 239 Returns @true if it is possible to go forward in the history
232fdc63 240 i.e. HistoryForward() won't fail.
23324ae1
FM
241 */
242 bool HistoryCanForward();
243
244 /**
245 Clears history.
246 */
247 void HistoryClear();
248
249 /**
232fdc63
VZ
250 Moves to next page in history. Only pages displayed using LoadPage()
251 are stored in history list.
23324ae1
FM
252 */
253 bool HistoryForward();
254
255 /**
232fdc63 256 Loads an HTML page from a file and displays it.
551266a9 257
d29a9a8a 258 @return @false if an error occurred, @true otherwise
551266a9 259
4cc4bfaf 260 @see LoadPage()
23324ae1 261 */
adaaa686 262 bool LoadFile(const wxFileName& filename);
23324ae1
FM
263
264 /**
232fdc63
VZ
265 Unlike SetPage() this function first loads the HTML page from @a location
266 and then displays it.
551266a9 267
7c913512 268 @param location
232fdc63
VZ
269 The address of the document.
270 See the @ref overview_fs for details on the address format
271 and wxFileSystem for a description of how the file is opened.
551266a9 272
d29a9a8a 273 @return @false if an error occurred, @true otherwise
551266a9 274
4cc4bfaf 275 @see LoadFile()
23324ae1
FM
276 */
277 virtual bool LoadPage(const wxString& location);
278
23324ae1 279 /**
5bddd46d
FM
280 Called when user clicks on hypertext link.
281 Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not
282 processed or skipped, call LoadPage() and do nothing else.
283
23324ae1 284 Overloading this method is deprecated; intercept the event instead.
5bddd46d 285
23324ae1
FM
286 Also see wxHtmlLinkInfo.
287 */
288 virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
289
290 /**
291 Called when an URL is being opened (either when the user clicks on a link or
5bddd46d
FM
292 an image is loaded). The URL will be opened only if OnOpeningURL() returns
293 @c wxHTML_OPEN. This method is called by wxHtmlParser::OpenURL.
294
295 You can override OnOpeningURL() to selectively block some URLs
296 (e.g. for security reasons) or to redirect them elsewhere.
297 Default behaviour is to always return @c wxHTML_OPEN.
551266a9 298
7c913512 299 @param type
4cc4bfaf 300 Indicates type of the resource. Is one of
5bddd46d
FM
301 - wxHTML_URL_PAGE: Opening a HTML page.
302 - wxHTML_URL_IMAGE: Opening an image.
303 - wxHTML_URL_OTHER: Opening a resource that doesn't fall into
304 any other category.
4cc4bfaf
FM
305 @param url
306 URL being opened.
7c913512 307 @param redirect
4cc4bfaf 308 Pointer to wxString variable that must be filled with an
5bddd46d
FM
309 URL if OnOpeningURL() returns @c wxHTML_REDIRECT.
310
311 The return value is:
312 - wxHTML_OPEN: Open the URL.
313 - wxHTML_BLOCK: Deny access to the URL, wxHtmlParser::OpenURL will return @NULL.
314 - wxHTML_REDIRECT: Don't open url, redirect to another URL.
315 OnOpeningURL() must fill *redirect with the new URL.
316 OnOpeningURL() will be called again on returned URL.
23324ae1
FM
317 */
318 virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,
adaaa686
FM
319 const wxString& url,
320 wxString* redirect) const;
23324ae1
FM
321
322 /**
5bddd46d 323 Called on parsing \<TITLE\> tag.
23324ae1
FM
324 */
325 virtual void OnSetTitle(const wxString& title);
326
327 /**
328 This reads custom settings from wxConfig. It uses the path 'path'
329 if given, otherwise it saves info into currently selected path.
5bddd46d
FM
330 The values are stored in sub-path @c wxHtmlWindow.
331 Read values: all things set by SetFonts(), SetBorders().
551266a9 332
7c913512 333 @param cfg
4cc4bfaf 334 wxConfig from which you want to read the configuration.
7c913512 335 @param path
4cc4bfaf 336 Optional path in config tree. If not given current path is used.
23324ae1 337 */
5267aefd 338 virtual void ReadCustomization(wxConfigBase* cfg,
23324ae1
FM
339 wxString path = wxEmptyString);
340
341 /**
342 Selects all text in the window.
551266a9 343
4cc4bfaf 344 @see SelectLine(), SelectWord()
23324ae1
FM
345 */
346 void SelectAll();
347
348 /**
4cc4bfaf 349 Selects the line of text that @a pos points at. Note that @e pos
23324ae1 350 is relative to the top of displayed page, not to window's origin, use
f09b5681 351 wxScrolled::CalcUnscrolledPosition()
23324ae1 352 to convert physical coordinate.
551266a9 353
4cc4bfaf 354 @see SelectAll(), SelectWord()
23324ae1
FM
355 */
356 void SelectLine(const wxPoint& pos);
357
358 /**
5bddd46d
FM
359 Selects the word at position @a pos.
360 Note that @a pos is relative to the top of displayed page, not to window's
361 origin, use wxScrolled::CalcUnscrolledPosition() to convert physical coordinate.
551266a9 362
4cc4bfaf 363 @see SelectAll(), SelectLine()
23324ae1
FM
364 */
365 void SelectWord(const wxPoint& pos);
366
367 /**
232fdc63
VZ
368 Returns the current selection as plain text.
369 Returns an empty string if no text is currently selected.
23324ae1
FM
370 */
371 wxString SelectionToText();
372
373 /**
5bddd46d
FM
374 This function sets the space between border of window and HTML contents.
375 See image:
fd779edb 376 @image html htmlwin_border.png
551266a9 377
7c913512 378 @param b
4cc4bfaf 379 indentation from borders in pixels
23324ae1
FM
380 */
381 void SetBorders(int b);
382
383 /**
e37870dd
VZ
384 This function sets font sizes and faces. See wxHtmlDCRenderer::SetFonts
385 for detailed description.
386
387 @see SetSize()
23324ae1 388 */
5267aefd
FM
389 void SetFonts(const wxString& normal_face, const wxString& fixed_face,
390 const int* sizes = NULL);
23324ae1 391
e37870dd
VZ
392 /**
393 Sets default font sizes and/or default font size.
394 See wxHtmlDCRenderer::SetStandardFonts for detailed description.
395 @see SetFonts()
396 */
397 void SetStandardFonts(int size = -1,
398 const wxString& normal_face = wxEmptyString,
399 const wxString& fixed_face = wxEmptyString);
400
23324ae1 401 /**
232fdc63 402 Sets the source of a page and displays it, for example:
5bddd46d
FM
403 @code
404 htmlwin -> SetPage("<html><body>Hello, world!</body></html>");
405 @endcode
551266a9 406
5bddd46d 407 If you want to load a document from some location use LoadPage() instead.
551266a9 408
7c913512 409 @param source
232fdc63 410 The HTML to be displayed.
551266a9 411
d29a9a8a 412 @return @false if an error occurred, @true otherwise.
23324ae1 413 */
adaaa686 414 virtual bool SetPage(const wxString& source);
23324ae1
FM
415
416 /**
5bddd46d
FM
417 Sets the frame in which page title will be displayed.
418 @a format is the format of the frame title, e.g. "HtmlHelp : %s".
419 It must contain exactly one %s.
420 This %s is substituted with HTML page title.
23324ae1
FM
421 */
422 void SetRelatedFrame(wxFrame* frame, const wxString& format);
423
424 /**
5bddd46d
FM
425 @b After calling SetRelatedFrame(), this sets statusbar slot where messages
426 will be displayed. (Default is -1 = no messages.)
37146d33
VS
427
428 @param index
429 Statusbar slot number (0..n)
430 */
431 void SetRelatedStatusBar(int index);
432
433 /**
434 @b Sets the associated statusbar where messages will be displayed.
435 Call this instead of SetRelatedFrame() if you want statusbar updates only,
436 no changing of the frame title.
437
438 @param statusbar
439 Statusbar pointer
440 @param index
441 Statusbar slot number (0..n)
442
443 @since 2.9.0
23324ae1 444 */
37146d33 445 void SetRelatedStatusBar(wxStatusBar* statusbar, int index = 0);
23324ae1
FM
446
447 /**
448 Returns content of currently displayed page as plain text.
449 */
450 wxString ToText();
451
452 /**
5bddd46d
FM
453 Saves custom settings into wxConfig.
454 It uses the path 'path' if given, otherwise it saves info into currently
455 selected path.
456 Regardless of whether the path is given or not, the function creates
457 sub-path @c wxHtmlWindow.
458
459 Saved values: all things set by SetFonts(), SetBorders().
551266a9 460
7c913512 461 @param cfg
4cc4bfaf 462 wxConfig to which you want to save the configuration.
7c913512 463 @param path
4cc4bfaf 464 Optional path in config tree. If not given, the current path is used.
23324ae1 465 */
5267aefd 466 virtual void WriteCustomization(wxConfigBase* cfg,
23324ae1 467 wxString path = wxEmptyString);
90f011dc 468
551266a9
FM
469protected:
470
471 /**
472 This method is called when a mouse button is clicked inside wxHtmlWindow.
5bddd46d
FM
473 The default behaviour is to emit a wxHtmlCellEvent and, if the event was
474 not processed or skipped, call OnLinkClicked() if the cell contains an
551266a9 475 hypertext link.
5bddd46d 476
551266a9
FM
477 Overloading this method is deprecated; intercept the event instead.
478
479 @param cell
480 The cell inside which the mouse was clicked, always a simple
481 (i.e. non-container) cell
5bddd46d
FM
482 @param x
483 The logical x coordinate of the click point
484 @param y
485 The logical y coordinate of the click point
551266a9
FM
486 @param event
487 The mouse event containing other information about the click
488
489 @return @true if a link was clicked, @false otherwise.
490 */
5267aefd 491 virtual bool OnCellClicked(wxHtmlCell* cell, wxCoord x, wxCoord y,
551266a9
FM
492 const wxMouseEvent& event);
493
494 /**
495 This method is called when a mouse moves over an HTML cell.
496 Default behaviour is to emit a wxHtmlCellEvent.
5bddd46d 497
551266a9
FM
498 Overloading this method is deprecated; intercept the event instead.
499
500 @param cell
501 The cell inside which the mouse is currently, always a simple
502 (i.e. non-container) cell
5bddd46d
FM
503 @param x
504 The logical x coordinate of the click point
505 @param y
506 The logical y coordinate of the click point
551266a9 507 */
5267aefd 508 virtual void OnCellMouseHover(wxHtmlCell* cell, wxCoord x, wxCoord y);
23324ae1
FM
509};
510
511
e54c96f1 512
ce7fe42e
VZ
513wxEventType wxEVT_HTML_CELL_CLICKED;
514wxEventType wxEVT_HTML_CELL_HOVER;
515wxEventType wxEVT_HTML_LINK_CLICKED;
90f011dc
RD
516
517
23324ae1
FM
518/**
519 @class wxHtmlLinkEvent
7c913512 520
23324ae1 521 This event class is used for the events generated by wxHtmlWindow.
7c913512 522
5bddd46d
FM
523 @beginEventTable{wxHtmlLinkEvent}
524 @event{EVT_HTML_LINK_CLICKED(id, func)}
525 User clicked on an hyperlink.
526 @endEventTable
527
23324ae1 528 @library{wxhtml}
5bddd46d 529 @category{html}
23324ae1
FM
530*/
531class wxHtmlLinkEvent : public wxCommandEvent
532{
533public:
534 /**
535 The constructor is not normally used by the user code.
536 */
ccf39540 537 wxHtmlLinkEvent(int id, const wxHtmlLinkInfo& linkinfo);
23324ae1
FM
538
539 /**
5bddd46d
FM
540 Returns the wxHtmlLinkInfo which contains info about the cell clicked
541 and the hyperlink it contains.
23324ae1 542 */
5bddd46d 543 const wxHtmlLinkInfo& GetLinkInfo() const;
23324ae1
FM
544};
545
546
e54c96f1 547
23324ae1
FM
548/**
549 @class wxHtmlCellEvent
7c913512 550
23324ae1 551 This event class is used for the events generated by wxHtmlWindow.
7c913512 552
5bddd46d
FM
553 @beginEventTable{wxHtmlCellEvent}
554 @event{EVT_HTML_CELL_HOVER(id, func)}
555 User moved the mouse over a wxHtmlCell.
556 @event{EVT_HTML_CELL_CLICKED(id, func)}
557 User clicked on a wxHtmlCell. When handling this event, remember to use
558 wxHtmlCell::SetLinkClicked(true) if the cell contains a link.
559 @endEventTable
560
23324ae1 561 @library{wxhtml}
5bddd46d 562 @category{html}
23324ae1
FM
563*/
564class wxHtmlCellEvent : public wxCommandEvent
565{
566public:
567 /**
568 The constructor is not normally used by the user code.
569 */
570 wxHtmlCellEvent(wxEventType commandType, int id,
4cc4bfaf 571 wxHtmlCell* cell,
a44f3b5a
FM
572 const wxPoint& point,
573 const wxMouseEvent& ev);
23324ae1
FM
574
575 /**
576 Returns the wxHtmlCellEvent associated with the event.
577 */
328f5751 578 wxHtmlCell* GetCell() const;
23324ae1
FM
579
580 /**
5bddd46d 581 Returns @true if SetLinkClicked(@true) has previously been called;
23324ae1
FM
582 @false otherwise.
583 */
328f5751 584 bool GetLinkClicked() const;
23324ae1
FM
585
586 /**
587 Returns the wxPoint associated with the event.
588 */
328f5751 589 wxPoint GetPoint() const;
23324ae1
FM
590
591 /**
5bddd46d
FM
592 Call this function with @a linkclicked set to @true if the cell which has
593 been clicked contained a link or @false otherwise (which is the default).
594
595 With this function the event handler can return info to the wxHtmlWindow
596 which sent the event.
23324ae1 597 */
5267aefd 598 void SetLinkClicked(bool linkclicked);
23324ae1 599};
e54c96f1 600