]>
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 This method is called when a mouse button is clicked inside wxHtmlWindow.
164 The default behaviour is to emit a wxHtmlCellEvent
165 and, if the event was not processed or skipped, call
166 OnLinkClicked() if the cell contains an
168 Overloading this method is deprecated; intercept the event instead.
171 The cell inside which the mouse was clicked, always a simple
172 (i.e. non-container) cell
174 The logical coordinates of the click point
176 The mouse event containing other information about the click
178 @return @true if a link was clicked, @false otherwise.
180 virtual bool OnCellClicked(wxHtmlCell cell
, wxCoord x
, wxCoord y
,
181 const wxMouseEvent
& event
);
184 This method is called when a mouse moves over an HTML cell.
185 Default behaviour is to emit a wxHtmlCellEvent.
186 Overloading this method is deprecated; intercept the event instead.
189 The cell inside which the mouse is currently, always a simple
190 (i.e. non-container) cell
192 The logical coordinates of the click point
194 virtual void OnCellMouseHover(wxHtmlCell cell
, wxCoord x
,
198 Called when user clicks on hypertext link. Default behaviour is to emit a
199 wxHtmlLinkEvent and, if the event was not processed
200 or skipped, call LoadPage() and do nothing else.
201 Overloading this method is deprecated; intercept the event instead.
202 Also see wxHtmlLinkInfo.
204 virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
);
207 Called when an URL is being opened (either when the user clicks on a link or
208 an image is loaded). The URL will be opened only if OnOpeningURL returns
209 @c wxHTML_OPEN. This method is called by
210 wxHtmlParser::OpenURL.
211 You can override OnOpeningURL to selectively block some
212 URLs (e.g. for security reasons) or to redirect them elsewhere. Default
213 behaviour is to always return @c wxHTML_OPEN.
216 Indicates type of the resource. Is one of
250 Opening a resource that doesn't fall into
255 Pointer to wxString variable that must be filled with an
256 URL if OnOpeningURL returns wxHTML_REDIRECT.
258 virtual wxHtmlOpeningStatus
OnOpeningURL(wxHtmlURLType type
,
260 wxString
* redirect
) const;
263 Called on parsing @c TITLE tag.
265 virtual void OnSetTitle(const wxString
& title
);
268 This reads custom settings from wxConfig. It uses the path 'path'
269 if given, otherwise it saves info into currently selected path.
270 The values are stored in sub-path @c wxHtmlWindow
271 Read values: all things set by SetFonts, SetBorders.
274 wxConfig from which you want to read the configuration.
276 Optional path in config tree. If not given current path is used.
278 virtual void ReadCustomization(wxConfigBase cfg
,
279 wxString path
= wxEmptyString
);
282 Selects all text in the window.
284 @see SelectLine(), SelectWord()
289 Selects the line of text that @a pos points at. Note that @e pos
290 is relative to the top of displayed page, not to window's origin, use
291 wxScrolled::CalcUnscrolledPosition()
292 to convert physical coordinate.
294 @see SelectAll(), SelectWord()
296 void SelectLine(const wxPoint
& pos
);
299 Selects the word at position @e pos. Note that @e pos
300 is relative to the top of displayed page, not to window's origin, use
301 wxScrolled::CalcUnscrolledPosition()
302 to convert physical coordinate.
304 @see SelectAll(), SelectLine()
306 void SelectWord(const wxPoint
& pos
);
309 Returns current selection as plain text. Returns empty string if no text
310 is currently selected.
312 wxString
SelectionToText();
315 This function sets the space between border of window and HTML contents. See
319 indentation from borders in pixels
321 void SetBorders(int b
);
324 This function sets font sizes and faces.
327 This is face name for normal (i.e. non-fixed) font.
328 It can be either empty string (then the default face is chosen) or
329 platform-specific face name. Examples are "helvetica" under Unix or
330 "Times New Roman" under Windows.
332 The same thing for fixed face ( TT../TT )
334 This is an array of 7 items of int type.
335 The values represent size of font with HTML size from -2 to +4
336 ( FONT SIZE=-2 to FONT SIZE=+4 ). Default sizes are used if sizes
339 void SetFonts(const wxString
& normal_face
,
340 const wxString
& fixed_face
,
341 const int sizes
= NULL
);
344 Sets HTML page and display it. This won't @b load the page!!
345 It will display the @e source. See example:
347 If you want to load a document from some location use
351 The HTML document source to be displayed.
353 @return @false if an error occurred, @true otherwise.
355 virtual bool SetPage(const wxString
& source
);
358 Sets the frame in which page title will be displayed. @a format is format of
359 frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s. This
360 %s is substituted with HTML page title.
362 void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
);
365 @b After calling SetRelatedFrame(),
366 this sets statusbar slot where messages will be displayed.
367 (Default is -1 = no messages.)
370 Statusbar slot number (0..n)
372 void SetRelatedStatusBar(int index
);
375 @b Sets the associated statusbar where messages will be displayed.
376 Call this instead of SetRelatedFrame() if you want statusbar updates only,
377 no changing of the frame title.
382 Statusbar slot number (0..n)
386 void SetRelatedStatusBar(wxStatusBar
* statusbar
, int index
= 0);
389 Returns content of currently displayed page as plain text.
394 Saves custom settings into wxConfig. It uses the path 'path'
395 if given, otherwise it saves info into currently selected path.
396 Regardless of whether the path is given or not, the function creates sub-path
398 Saved values: all things set by SetFonts, SetBorders.
401 wxConfig to which you want to save the configuration.
403 Optional path in config tree. If not given, the current path is used.
405 virtual void WriteCustomization(wxConfigBase cfg
,
406 wxString path
= wxEmptyString
);
412 @class wxHtmlLinkEvent
414 This event class is used for the events generated by wxHtmlWindow.
419 class wxHtmlLinkEvent
: public wxCommandEvent
423 The constructor is not normally used by the user code.
425 wxHyperlinkEvent(int id
, const wxHtmlLinkInfo
& linkinfo
);
428 Returns the wxHtmlLinkInfo which contains info about the cell clicked and the
429 hyperlink it contains.
431 const wxHtmlLinkInfo
GetLinkInfo() const;
437 @class wxHtmlCellEvent
439 This event class is used for the events generated by wxHtmlWindow.
444 class wxHtmlCellEvent
: public wxCommandEvent
448 The constructor is not normally used by the user code.
450 wxHtmlCellEvent(wxEventType commandType
, int id
,
452 const wxPoint
& point
);
455 Returns the wxHtmlCellEvent associated with the event.
457 wxHtmlCell
* GetCell() const;
460 Returns @true if @ref setlinkclicked() SetLinkClicked(@true) has previously
464 bool GetLinkClicked() const;
467 Returns the wxPoint associated with the event.
469 wxPoint
GetPoint() const;
472 Call this function with @c linkclicked set to @true if the cell which has
473 been clicked contained a link or
474 @false otherwise (which is the default). With this function the event handler
475 can return info to the
476 wxHtmlWindow which sent the event.
478 bool SetLinkClicked(bool linkclicked
);