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