## wxHtmlWindow

wxHtmlWindow is probably the only class you will directly use unless you want to do something special (like adding new tag handlers or MIME filters).

The purpose of this class is to display HTML pages (either local file or downloaded via HTTP protocol) in a window. The width of the window is constant - given in the constructor - and virtual height is changed dynamically depending on page size. Once the window is created you can set its content by calling SetPage(text) or LoadPage(filename).

Note

wxHtmlWindow uses the wxImage class for displaying images. Don't forget to initialize all image formats you need before loading any page! (See wxInitAllImageHandlers and wxImage::AddHandler.)

Derived from

wxScrolledWindow

Include files

<wx/html/htmlwin.h>

wxHtmlWindow::wxHtmlWindow
wxHtmlWindow::AddFilter
wxHtmlWindow::AppendToPage
wxHtmlWindow::GetInternalRepresentation
wxHtmlWindow::GetOpenedAnchor
wxHtmlWindow::GetOpenedPage
wxHtmlWindow::GetOpenedPageTitle
wxHtmlWindow::GetRelatedFrame
wxHtmlWindow::HistoryBack
wxHtmlWindow::HistoryCanBack
wxHtmlWindow::HistoryCanForward
wxHtmlWindow::HistoryClear
wxHtmlWindow::HistoryForward
wxHtmlWindow::LoadPage
wxHtmlWindow::OnCellClicked
wxHtmlWindow::OnCellMouseHover
wxHtmlWindow::OnLinkClicked
wxHtmlWindow::OnOpeningURL
wxHtmlWindow::OnSetTitle
wxHtmlWindow::ReadCustomization
wxHtmlWindow::SetBorders
wxHtmlWindow::SetFonts
wxHtmlWindow::SetPage
wxHtmlWindow::SetRelatedFrame
wxHtmlWindow::SetRelatedStatusBar
wxHtmlWindow::WriteCustomization

### wxHtmlWindow::wxHtmlWindow

wxHtmlWindow()

Default constructor.

wxHtmlWindow(wxWindow *parent, wxWindowID id = -1, const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize, long style = wxHW_SCROLLBAR_AUTO, const wxString& name = "htmlWindow")

Constructor. The parameters are the same as for the wxScrolledWindow constructor.

Parameters

style

wxHW_SCROLLBAR_NEVER, or wxHW_SCROLLBAR_AUTO. Affects the appearance of vertical scrollbar in the window.

### wxHtmlWindow::AddFilter

static void AddFilter(wxHtmlFilter *filter)

Adds input filter to the static list of available filters. These filters are present by default:

- `text/html` MIME type
- `image/*` MIME types
- Plain Text filter (this filter is used if no other filter matches)

### wxHtmlWindow::AppendToPage

bool AppendToPage(const wxString& source)

Appends HTML fragment to currently displayed text and refreshes the window.

Parameters

source

HTML code fragment

Return value

FALSE if an error occurred, TRUE otherwise.

### wxHtmlWindow::GetInternalRepresentation

wxHtmlContainerCell* GetInternalRepresentation() const

Returns pointer to the top-level container.

See also: Cells Overview, Printing Overview

### wxHtmlWindow::GetOpenedAnchor

wxString GetOpenedAnchor()

Returns anchor within currently opened page (see GetOpenedPage). If no page is opened or if the displayed page wasn't produced by call to LoadPage, empty string is returned.

### wxHtmlWindow::GetOpenedPage

wxString GetOpenedPage()

Returns full location of the opened page. If no page is opened or if the displayed page wasn't produced by call to LoadPage, empty string is returned.

### wxHtmlWindow::GetOpenedPageTitle

wxString GetOpenedPageTitle()

Returns title of the opened page or wxEmptyString if current page does not contain `<TITLE>` tag.

### wxHtmlWindow::GetRelatedFrame

wxFrame* GetRelatedFrame() const

Returns the related frame.

### wxHtmlWindow::HistoryBack

bool HistoryBack()

Moves back to the previous page. (each page displayed using LoadPage is stored in history list.)

### wxHtmlWindow::HistoryCanBack

bool HistoryCanBack()

Returns true if it is possible to go back in the history (i.e. HistoryBack() won't fail).

### wxHtmlWindow::HistoryCanForward

bool HistoryCanForward()

Returns true if it is possible to go forward in the history (i.e. HistoryBack() won't fail).

### wxHtmlWindow::HistoryClear

void HistoryClear()

Clears history.

### wxHtmlWindow::HistoryForward

bool HistoryForward()

Moves to next page in history.

### wxHtmlWindow::LoadPage

virtual bool LoadPage(const wxString& location)

Unlike SetPage this function first loads HTML page from location and then displays it. See example:

    htmlwin -> SetPage("help/myproject/index.htm");

Parameters

location

The address of document. See wxFileSystem for details on address format and behaviour of "opener".

Return value

FALSE if an error occurred, TRUE otherwise

### wxHtmlWindow::OnCellClicked

virtual void OnCellClicked(wxHtmlCell *cell, wxCoord x, wxCoord y, const wxMouseEvent& event)

This method is called when a mouse button is clicked inside wxHtmlWindow. The default behaviour is to call OnLinkClicked if the cell contains a hypertext link.

Parameters

cell

The cell inside which the mouse was clicked, always a simple (i.e. non container) cell

x, y

The logical coordinates of the click point

event

The mouse event containing other information about the click

### wxHtmlWindow::OnCellMouseHover

virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y)

This method is called when a mouse moves over an HTML cell.

Parameters

cell

The cell inside which the mouse is currently, always a simple (i.e. non container) cell

x, y

The logical coordinates of the click point

### wxHtmlWindow::OnLinkClicked

virtual void OnLinkClicked(const wxHtmlLinkInfo& link)

Called when user clicks on hypertext link. Default behaviour is to call LoadPage and do nothing else.

Also see wxHtmlLinkInfo.

### wxHtmlWindow::OnOpeningURL

virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType type,const wxString& url, wxString *redirect)

Called when an URL is being opened (either when the user clicks on a link or an image is loaded). The URL will be opened only if OnOpeningURL returns `wxHTML_OPEN`. This method is called by wxHtmlParser::OpenURL. You can override OnOpeningURL to selectively block some URLs (e.g. for security reasons) or to redirect them elsewhere. Default behaviour is to always return `wxHTML_OPEN`.

Parameters

type

Indicates type of the resource. Is one of

wxHTML_URL_PAGE | Opening a HTML page.
wxHTML_URL_IMAGE | Opening an image.
wxHTML_URL_OTHER | Opening a resource that doesn't fall into any other category.

url

URL being opened.

redirect

Pointer to wxString variable that must be filled with an URL if OnOpeningURL returns `wxHTML_REDIRECT`.

Return value

wxHTML_OPEN | Open the URL.
wxHTML_BLOCK | Deny access to the URL, wxHtmlParser::OpenURL will return NULL.
wxHTML_REDIRECT | Don't open url, redirect to another URL. OnOpeningURL must fill *redirect with the new URL. OnOpeningURL will be called again on returned URL.

### wxHtmlWindow::OnSetTitle

virtual void OnSetTitle(const wxString& title)

Called on parsing `<TITLE>` tag.

### wxHtmlWindow::ReadCustomization

virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString)

This reads custom settings from wxConfig. It uses the path 'path' if given, otherwise it saves info into currently selected path. The values are stored in sub-path `wxHtmlWindow`

Read values: all things set by SetFonts, SetBorders.

Parameters

cfg

wxConfig from which you want to read the configuration.

path

Optional path in config tree. If not given current path is used.

### wxHtmlWindow::SetBorders

void SetBorders(int b)

This function sets the space between border of window and HTML contents. See image:

Parameters

b

indentation from borders in pixels

### wxHtmlWindow::SetFonts

void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes)

This function sets font sizes and faces.

Parameters

normal_face

This is face name for normal (i.e. non-fixed) font. It can be either empty string (then the default face is chosen) or platform-specific face name. Examples are "helvetica" under Unix or "Times New Roman" under Windows.

fixed_face

The same thing for fixed face ( <TT>..</TT> )

sizes

This is an array of 7 items of int type. The values represent size of font with HTML size from -2 to +4 ( <FONT SIZE=-2> to <FONT SIZE=+4> )

Defaults

Under wxGTK:

        SetFonts("", "", {10, 12, 14, 16, 19, 24, 32});

Under Windows:

        SetFonts("", "", {7, 8, 10, 12, 16, 22, 30});

Although it seems different the fact is that the fonts are of approximately same size under both platforms (due to wxMSW / wxGTK inconsistency)

### wxHtmlWindow::SetPage

bool SetPage(const wxString& source)

Sets HTML page and display it. This won't load the page!! It will display the source. See example:

    htmlwin -> SetPage("<html><body>Hello, world!</body></html>");

If you want to load a document from some location use LoadPage instead.

Parameters

source

The HTML document source to be displayed.

Return value

FALSE if an error occurred, TRUE otherwise.

### wxHtmlWindow::SetRelatedFrame

void SetRelatedFrame(wxFrame* frame, const wxString& format)

Sets the frame in which page title will be displayed. format is format of frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s. This %s is substituted with HTML page title.

### wxHtmlWindow::SetRelatedStatusBar

void SetRelatedStatusBar(int bar)

After calling SetRelatedFrame, this sets statusbar slot where messages will be displayed. (Default is -1 = no messages.)

Parameters

bar

statusbar slot number (0..n)

### wxHtmlWindow::WriteCustomization

virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString)

Saves custom settings into wxConfig. It uses the path 'path' if given, otherwise it saves info into currently selected path. Regardless of whether the path is given or not, the function creates sub-path `wxHtmlWindow`.

Saved values: all things set by SetFonts, SetBorders.

Parameters

cfg

wxConfig to which you want to save the configuration.

path

Optional path in config tree. If not given, the current path is used.