]>
git.saurik.com Git - wxWidgets.git/blob - interface/wx/html/htmlwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: html/htmlwin.h
3 // Purpose: interface of wxHtmlWindow
4 // Author: wxWidgets team
6 // Licence: wxWindows license
7 /////////////////////////////////////////////////////////////////////////////
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).
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.
20 Once the window is created you can set its content by calling
21 @ref wxHtmlWindow::setpage SetPage(text),
22 @ref wxHtmlWindow::loadpage LoadPage(filename) or
23 wxHtmlWindow::LoadFile.
26 @style{wxHW_SCROLLBAR_NEVER}
27 Never display scrollbars, not even when the page is larger than the
29 @style{wxHW_SCROLLBAR_AUTO}
30 Display scrollbars only if page's size exceeds window's size.
31 @style{wxHW_NO_SELECTION}
32 Don't allow the user to select text.
38 @see wxHtmlLinkEvent, wxHtmlCellEvent
40 class wxHtmlWindow
: public wxScrolledWindow
45 Constructor. The parameters are the same as wxScrolled::wxScrolled()
49 Window style. See wxHtmlWindow.
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");
60 Adds @ref overview_filters "input filter" to the static list of available
61 filters. These filters are present by default:
62 @c text/html MIME type
64 Plain Text filter (this filter is used if no other filter matches)
66 static void AddFilter(wxHtmlFilter filter
);
69 Appends HTML fragment to currently displayed text and refreshes the window.
74 @return @false if an error occurred, @true otherwise.
76 bool AppendToPage(const wxString
& source
);
79 Returns pointer to the top-level container.
80 See also: @ref overview_cells "Cells Overview",
81 @ref overview_printing
83 wxHtmlContainerCell
* GetInternalRepresentation() const;
86 Returns anchor within currently opened page
87 (see wxHtmlWindow::GetOpenedPage).
88 If no page is opened or if the displayed page wasn't
89 produced by call to LoadPage, empty string is returned.
91 wxString
GetOpenedAnchor() const;
94 Returns full location of the opened page. If no page is opened or if the
96 produced by call to LoadPage, empty string is returned.
98 wxString
GetOpenedPage() const;
101 Returns title of the opened page or wxEmptyString if current page does not
102 contain @c TITLE tag.
104 wxString
GetOpenedPageTitle() const;
107 Returns the related frame.
109 wxFrame
* GetRelatedFrame() const;
112 Moves back to the previous page. (each page displayed using
113 LoadPage() is stored in history list.)
118 Returns @true if it is possible to go back in the history (i.e. HistoryBack()
121 bool HistoryCanBack();
124 Returns @true if it is possible to go forward in the history (i.e. HistoryBack()
127 bool HistoryCanForward();
135 Moves to next page in history.
137 bool HistoryForward();
140 Loads HTML page from file and displays it.
142 @return @false if an error occurred, @true otherwise
146 bool LoadFile(const wxFileName
& filename
);
149 Unlike SetPage this function first loads HTML page from @a location
150 and then displays it. See example:
153 The address of document. See wxFileSystem for details on address format and
154 behaviour of "opener".
156 @return @false if an error occurred, @true otherwise
160 virtual bool LoadPage(const wxString
& location
);
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.
167 Also see wxHtmlLinkInfo.
169 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
);
172 Called when an URL is being opened (either when the user clicks on a link or
173 an image is loaded). The URL will be opened only if OnOpeningURL returns
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.
181 Indicates type of the resource. Is one of
215 Opening a resource that doesn't fall into
220 Pointer to wxString variable that must be filled with an
221 URL if OnOpeningURL returns wxHTML_REDIRECT.
223 virtual wxHtmlOpeningStatus
OnOpeningURL(wxHtmlURLType type
,
225 wxString
* redirect
) const;
228 Called on parsing @c TITLE tag.
230 virtual void OnSetTitle(const wxString
& title
);
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
236 Read values: all things set by SetFonts, SetBorders.
239 wxConfig from which you want to read the configuration.
241 Optional path in config tree. If not given current path is used.
243 virtual void ReadCustomization(wxConfigBase cfg
,
244 wxString path
= wxEmptyString
);
247 Selects all text in the window.
249 @see SelectLine(), SelectWord()
254 Selects the line of text that @a pos points at. Note that @e pos
255 is relative to the top of displayed page, not to window's origin, use
256 wxScrolled::CalcUnscrolledPosition()
257 to convert physical coordinate.
259 @see SelectAll(), SelectWord()
261 void SelectLine(const wxPoint
& pos
);
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
266 wxScrolled::CalcUnscrolledPosition()
267 to convert physical coordinate.
269 @see SelectAll(), SelectLine()
271 void SelectWord(const wxPoint
& pos
);
274 Returns current selection as plain text. Returns empty string if no text
275 is currently selected.
277 wxString
SelectionToText();
280 This function sets the space between border of window and HTML contents. See
284 indentation from borders in pixels
286 void SetBorders(int b
);
289 This function sets font sizes and faces.
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.
297 The same thing for fixed face ( TT../TT )
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
304 void SetFonts(const wxString
& normal_face
,
305 const wxString
& fixed_face
,
306 const int sizes
= NULL
);
309 Sets HTML page and display it. This won't @b load the page!!
310 It will display the @e source. See example:
312 If you want to load a document from some location use
316 The HTML document source to be displayed.
318 @return @false if an error occurred, @true otherwise.
320 virtual bool SetPage(const wxString
& source
);
323 Sets the frame in which page title will be displayed. @a format is format of
324 frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s. This
325 %s is substituted with HTML page title.
327 void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
);
330 @b After calling SetRelatedFrame(),
331 this sets statusbar slot where messages will be displayed.
332 (Default is -1 = no messages.)
335 Statusbar slot number (0..n)
337 void SetRelatedStatusBar(int index
);
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.
347 Statusbar slot number (0..n)
351 void SetRelatedStatusBar(wxStatusBar
* statusbar
, int index
= 0);
354 Returns content of currently displayed page as plain text.
359 Saves custom settings into wxConfig. It uses the path 'path'
360 if given, otherwise it saves info into currently selected path.
361 Regardless of whether the path is given or not, the function creates sub-path
363 Saved values: all things set by SetFonts, SetBorders.
366 wxConfig to which you want to save the configuration.
368 Optional path in config tree. If not given, the current path is used.
370 virtual void WriteCustomization(wxConfigBase cfg
,
371 wxString path
= wxEmptyString
);
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
381 Overloading this method is deprecated; intercept the event instead.
384 The cell inside which the mouse was clicked, always a simple
385 (i.e. non-container) cell
387 The logical coordinates of the click point
389 The mouse event containing other information about the click
391 @return @true if a link was clicked, @false otherwise.
393 virtual bool OnCellClicked(wxHtmlCell cell
, wxCoord x
, wxCoord y
,
394 const wxMouseEvent
& event
);
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.
402 The cell inside which the mouse is currently, always a simple
403 (i.e. non-container) cell
405 The logical coordinates of the click point
407 virtual void OnCellMouseHover(wxHtmlCell cell
, wxCoord x
, wxCoord y
);
413 @class wxHtmlLinkEvent
415 This event class is used for the events generated by wxHtmlWindow.
420 class wxHtmlLinkEvent
: public wxCommandEvent
424 The constructor is not normally used by the user code.
426 wxHyperlinkEvent(int id
, const wxHtmlLinkInfo
& linkinfo
);
429 Returns the wxHtmlLinkInfo which contains info about the cell clicked and the
430 hyperlink it contains.
432 const wxHtmlLinkInfo
GetLinkInfo() const;
438 @class wxHtmlCellEvent
440 This event class is used for the events generated by wxHtmlWindow.
445 class wxHtmlCellEvent
: public wxCommandEvent
449 The constructor is not normally used by the user code.
451 wxHtmlCellEvent(wxEventType commandType
, int id
,
453 const wxPoint
& point
);
456 Returns the wxHtmlCellEvent associated with the event.
458 wxHtmlCell
* GetCell() const;
461 Returns @true if @ref setlinkclicked() SetLinkClicked(@true) has previously
465 bool GetLinkClicked() const;
468 Returns the wxPoint associated with the event.
470 wxPoint
GetPoint() const;
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.
479 bool SetLinkClicked(bool linkclicked
);