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