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