]>
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 licence 
   7 ///////////////////////////////////////////////////////////////////////////// 
  12     wxHtmlWindow is probably the only class you will directly use unless you want 
  13     to do something special (like adding new tag handlers or MIME filters). 
  15     The purpose of this class is to display HTML pages (either local file or 
  16     downloaded via HTTP protocol) in a window. 
  17     The width of the window is constant - given in the constructor - and virtual height 
  18     is changed dynamically depending on page size. 
  19     Once the window is created you can set its content by calling SetPage() with raw HTML, 
  20     LoadPage() with a wxFileSystem location or LoadFile() with a filename. 
  23     wxHtmlWindow uses the wxImage class for displaying images, as such you need to 
  24     initialize the handlers for any image formats you use before loading a page. 
  25     See ::wxInitAllImageHandlers and wxImage::AddHandler. 
  28     @style{wxHW_SCROLLBAR_NEVER} 
  29            Never display scrollbars, not even when the page is larger than the 
  31     @style{wxHW_SCROLLBAR_AUTO} 
  32            Display scrollbars only if page's size exceeds window's size. 
  33     @style{wxHW_NO_SELECTION} 
  34            Don't allow the user to select text. 
  38     @beginEventEmissionTable{wxHtmlCellEvent, wxHtmlLinkEvent} 
  39     @event{EVT_HTML_CELL_CLICKED(id, func)} 
  40         A wxHtmlCell was clicked. 
  41     @event{EVT_HTML_CELL_HOVER(id, func)} 
  42         The mouse passed over a wxHtmlCell. 
  43     @event{EVT_HTML_LINK_CLICKED(id, func)} 
  44         A wxHtmlCell which contains an hyperlink was clicked. 
  50     @see wxHtmlLinkEvent, wxHtmlCellEvent 
  52 class wxHtmlWindow 
: public wxScrolledWindow
 
  62         The parameters are the same as wxScrolled::wxScrolled() constructor. 
  64     wxHtmlWindow(wxWindow 
*parent
, wxWindowID id 
= wxID_ANY
, 
  65                  const wxPoint
& pos 
= wxDefaultPosition
, 
  66                  const wxSize
& size 
= wxDefaultSize
, 
  67                  long style 
= wxHW_DEFAULT_STYLE
, 
  68                  const wxString
& name 
= "htmlWindow"); 
  71         Adds @ref overview_html_filters "input filter" to the static list of available 
  72         filters. These filters are present by default: 
  73         - @c text/html MIME type 
  74         - @c image/* MIME types 
  75         - Plain Text filter (this filter is used if no other filter matches) 
  77     static void AddFilter(wxHtmlFilter
* filter
); 
  80         Appends HTML fragment to currently displayed text and refreshes the window. 
  85         @return @false if an error occurred, @true otherwise. 
  87     bool AppendToPage(const wxString
& source
); 
  90         Returns pointer to the top-level container. 
  92         @see @ref overview_html_cells, @ref overview_printing 
  94     wxHtmlContainerCell
* GetInternalRepresentation() const; 
  97         Returns anchor within currently opened page (see wxHtmlWindow::GetOpenedPage). 
  98         If no page is opened or if the displayed page wasn't produced by call to 
  99         LoadPage(), empty string is returned. 
 101     wxString 
GetOpenedAnchor() const; 
 104         Returns full location of the opened page. 
 105         If no page is opened or if the displayed page wasn't produced by call to 
 106         LoadPage(), empty string is returned. 
 108     wxString 
GetOpenedPage() const; 
 111         Returns title of the opened page or wxEmptyString if the current page does not 
 112         contain \<TITLE\> tag. 
 114     wxString 
GetOpenedPageTitle() const; 
 117         Returns the related frame. 
 119     wxFrame
* GetRelatedFrame() const; 
 122         Moves back to the previous page. Only pages displayed using LoadPage() 
 123         are stored in history list. 
 128         Returns @true if it is possible to go back in the history 
 129         i.e. HistoryBack() won't fail. 
 131     bool HistoryCanBack(); 
 134         Returns @true if it is possible to go forward in the history 
 135         i.e. HistoryForward() won't fail. 
 137     bool HistoryCanForward(); 
 145         Moves to next page in history. Only pages displayed using LoadPage() 
 146         are stored in history list. 
 148     bool HistoryForward(); 
 151         Loads an HTML page from a file and displays it. 
 153         @return @false if an error occurred, @true otherwise 
 157     bool LoadFile(const wxFileName
& filename
); 
 160         Unlike SetPage() this function first loads the HTML page from @a location 
 161         and then displays it. 
 164             The address of the document. 
 165             See the @ref overview_fs for details on the address format 
 166             and wxFileSystem for a description of how the file is opened. 
 168         @return @false if an error occurred, @true otherwise 
 172     virtual bool LoadPage(const wxString
& location
); 
 175         Called when user clicks on hypertext link. 
 176         Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not 
 177         processed or skipped, call LoadPage() and do nothing else. 
 179         Overloading this method is deprecated; intercept the event instead. 
 181         Also see wxHtmlLinkInfo. 
 183     virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
); 
 186         Called when an URL is being opened (either when the user clicks on a link or 
 187         an image is loaded). The URL will be opened only if OnOpeningURL() returns 
 188         @c wxHTML_OPEN. This method is called by wxHtmlParser::OpenURL. 
 190         You can override OnOpeningURL() to selectively block some URLs 
 191         (e.g. for security reasons) or to redirect them elsewhere. 
 192         Default behaviour is to always return @c wxHTML_OPEN. 
 195             Indicates type of the resource. Is one of 
 196             - wxHTML_URL_PAGE: Opening a HTML page. 
 197             - wxHTML_URL_IMAGE: Opening an image. 
 198             - wxHTML_URL_OTHER: Opening a resource that doesn't fall into 
 203             Pointer to wxString variable that must be filled with an 
 204             URL if OnOpeningURL() returns @c wxHTML_REDIRECT. 
 207         - wxHTML_OPEN: Open the URL. 
 208         - wxHTML_BLOCK: Deny access to the URL, wxHtmlParser::OpenURL will return @NULL. 
 209         - wxHTML_REDIRECT: Don't open url, redirect to another URL. 
 210           OnOpeningURL() must fill *redirect with the new URL. 
 211           OnOpeningURL() will be called again on returned URL. 
 213     virtual wxHtmlOpeningStatus 
OnOpeningURL(wxHtmlURLType type
, 
 215                                              wxString
* redirect
) const; 
 218         Called on parsing \<TITLE\> tag. 
 220     virtual void OnSetTitle(const wxString
& title
); 
 223         This reads custom settings from wxConfig. It uses the path 'path' 
 224         if given, otherwise it saves info into currently selected path. 
 225         The values are stored in sub-path @c wxHtmlWindow. 
 226         Read values: all things set by SetFonts(), SetBorders(). 
 229             wxConfig from which you want to read the configuration. 
 231             Optional path in config tree. If not given current path is used. 
 233     virtual void ReadCustomization(wxConfigBase
* cfg
, 
 234                                    wxString path 
= wxEmptyString
); 
 237         Selects all text in the window. 
 239         @see SelectLine(), SelectWord() 
 244         Selects the line of text that @a pos points at. Note that @e pos 
 245         is relative to the top of displayed page, not to window's origin, use 
 246         wxScrolled::CalcUnscrolledPosition() 
 247         to convert physical coordinate. 
 249         @see SelectAll(), SelectWord() 
 251     void SelectLine(const wxPoint
& pos
); 
 254         Selects the word at position @a pos. 
 255         Note that @a pos is relative to the top of displayed page, not to window's 
 256         origin, use wxScrolled::CalcUnscrolledPosition() to convert physical coordinate. 
 258         @see SelectAll(), SelectLine() 
 260     void SelectWord(const wxPoint
& pos
); 
 263         Returns the current selection as plain text. 
 264         Returns an empty string if no text is currently selected. 
 266     wxString 
SelectionToText(); 
 269         This function sets the space between border of window and HTML contents. 
 271         @image html htmlwin_border.png 
 274             indentation from borders in pixels 
 276     void SetBorders(int b
); 
 279         This function sets font sizes and faces. See wxHtmlDCRenderer::SetFonts 
 280         for detailed description. 
 284     void SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, 
 285                   const int* sizes 
= NULL
); 
 288         Sets default font sizes and/or default font size.  
 289         See wxHtmlDCRenderer::SetStandardFonts for detailed description. 
 292     void SetStandardFonts(int size 
= -1, 
 293                           const wxString
& normal_face 
= wxEmptyString
, 
 294                           const wxString
& fixed_face 
= wxEmptyString
); 
 297         Sets the source of a page and displays it, for example: 
 299         htmlwin -> SetPage("<html><body>Hello, world!</body></html>"); 
 302         If you want to load a document from some location use LoadPage() instead. 
 305             The HTML to be displayed. 
 307         @return @false if an error occurred, @true otherwise. 
 309     virtual bool SetPage(const wxString
& source
); 
 312         Sets the frame in which page title will be displayed. 
 313         @a format is the format of the frame title, e.g. "HtmlHelp : %s". 
 314         It must contain exactly one %s. 
 315         This %s is substituted with HTML page title. 
 317     void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
); 
 320         @b After calling SetRelatedFrame(), this sets statusbar slot where messages 
 321         will be displayed. (Default is -1 = no messages.) 
 324             Statusbar slot number (0..n) 
 326     void SetRelatedStatusBar(int index
); 
 329         @b Sets the associated statusbar where messages will be displayed. 
 330         Call this instead of SetRelatedFrame() if you want statusbar updates only, 
 331         no changing of the frame title. 
 336             Statusbar slot number (0..n) 
 340     void SetRelatedStatusBar(wxStatusBar
* statusbar
, int index 
= 0); 
 343         Returns content of currently displayed page as plain text. 
 348         Saves custom settings into wxConfig. 
 349         It uses the path 'path' if given, otherwise it saves info into currently 
 351         Regardless of whether the path is given or not, the function creates 
 352         sub-path @c wxHtmlWindow. 
 354         Saved values: all things set by SetFonts(), SetBorders(). 
 357             wxConfig to which you want to save the configuration. 
 359             Optional path in config tree. If not given, the current path is used. 
 361     virtual void WriteCustomization(wxConfigBase
* cfg
, 
 362                                     wxString path 
= wxEmptyString
); 
 367         This method is called when a mouse button is clicked inside wxHtmlWindow. 
 368         The default behaviour is to emit a wxHtmlCellEvent and, if the event was 
 369         not processed or skipped, call OnLinkClicked() if the cell contains an 
 372         Overloading this method is deprecated; intercept the event instead. 
 375             The cell inside which the mouse was clicked, always a simple 
 376             (i.e. non-container) cell 
 378             The logical x coordinate of the click point 
 380             The logical y coordinate of the click point 
 382             The mouse event containing other information about the click 
 384         @return @true if a link was clicked, @false otherwise. 
 386     virtual bool OnCellClicked(wxHtmlCell
* cell
, wxCoord x
, wxCoord y
, 
 387                                const wxMouseEvent
& event
); 
 390         This method is called when a mouse moves over an HTML cell. 
 391         Default behaviour is to emit a wxHtmlCellEvent. 
 393         Overloading this method is deprecated; intercept the event instead. 
 396             The cell inside which the mouse is currently, always a simple 
 397             (i.e. non-container) cell 
 399             The logical x coordinate of the click point 
 401             The logical y coordinate of the click point 
 403     virtual void OnCellMouseHover(wxHtmlCell
* cell
, wxCoord x
, wxCoord y
); 
 409     @class wxHtmlLinkEvent 
 411     This event class is used for the events generated by wxHtmlWindow. 
 413     @beginEventTable{wxHtmlLinkEvent} 
 414     @event{EVT_HTML_LINK_CLICKED(id, func)} 
 415         User clicked on an hyperlink. 
 421 class wxHtmlLinkEvent 
: public wxCommandEvent
 
 425         The constructor is not normally used by the user code. 
 427     wxHtmlLinkEvent(int id
, const wxHtmlLinkInfo
& linkinfo
); 
 430         Returns the wxHtmlLinkInfo which contains info about the cell clicked 
 431         and the hyperlink it contains. 
 433     const wxHtmlLinkInfo
& GetLinkInfo() const; 
 439     @class wxHtmlCellEvent 
 441     This event class is used for the events generated by wxHtmlWindow. 
 443     @beginEventTable{wxHtmlCellEvent} 
 444     @event{EVT_HTML_CELL_HOVER(id, func)} 
 445         User moved the mouse over a wxHtmlCell. 
 446     @event{EVT_HTML_CELL_CLICKED(id, func)} 
 447         User clicked on a wxHtmlCell. When handling this event, remember to use 
 448         wxHtmlCell::SetLinkClicked(true) if the cell contains a link. 
 454 class wxHtmlCellEvent 
: public wxCommandEvent
 
 458         The constructor is not normally used by the user code. 
 460     wxHtmlCellEvent(wxEventType commandType
, int id
, 
 462                     const wxPoint
& point
, 
 463                     const wxMouseEvent
& ev
); 
 466         Returns the wxHtmlCellEvent associated with the event. 
 468     wxHtmlCell
* GetCell() const; 
 471         Returns @true if SetLinkClicked(@true) has previously been called; 
 474     bool GetLinkClicked() const; 
 477         Returns the wxPoint associated with the event. 
 479     wxPoint 
GetPoint() const; 
 482         Call this function with @a linkclicked set to @true if the cell which has 
 483         been clicked contained a link or @false otherwise (which is the default). 
 485         With this function the event handler can return info to the wxHtmlWindow 
 486         which sent the event. 
 488     void SetLinkClicked(bool linkclicked
);