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