]>
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 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(text), 
  20     LoadPage(filename) or wxHtmlWindow::LoadFile. 
  23     wxHtmlWindow uses the wxImage class for displaying images. 
  24     Don't forget to initialize all image formats you need before loading any 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     @beginEventTable{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 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. 
 123         (each page displayed using LoadPage() is 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. HistoryBack() won't fail). 
 137     bool HistoryCanForward(); 
 145         Moves to next page in history. 
 147     bool HistoryForward(); 
 150         Loads HTML page from file and displays it. 
 152         @return @false if an error occurred, @true otherwise 
 156     bool LoadFile(const wxFileName
& filename
); 
 159         Unlike SetPage() this function first loads HTML page from @a location 
 160         and then displays it. See example: 
 163             The address of document. 
 164             See wxFileSystem for details on address format and behaviour of "opener". 
 166         @return @false if an error occurred, @true otherwise 
 170     virtual bool LoadPage(const wxString
& location
); 
 173         Called when user clicks on hypertext link. 
 174         Default behaviour is to emit a wxHtmlLinkEvent and, if the event was not 
 175         processed or skipped, call LoadPage() and do nothing else. 
 177         Overloading this method is deprecated; intercept the event instead. 
 179         Also see wxHtmlLinkInfo. 
 181     virtual void OnLinkClicked(const wxHtmlLinkInfo
& link
); 
 184         Called when an URL is being opened (either when the user clicks on a link or 
 185         an image is loaded). The URL will be opened only if OnOpeningURL() returns 
 186         @c wxHTML_OPEN. This method is called by wxHtmlParser::OpenURL. 
 188         You can override OnOpeningURL() to selectively block some URLs 
 189         (e.g. for security reasons) or to redirect them elsewhere. 
 190         Default behaviour is to always return @c wxHTML_OPEN. 
 193             Indicates type of the resource. Is one of 
 194             - wxHTML_URL_PAGE: Opening a HTML page. 
 195             - wxHTML_URL_IMAGE: Opening an image. 
 196             - wxHTML_URL_OTHER: Opening a resource that doesn't fall into 
 201             Pointer to wxString variable that must be filled with an 
 202             URL if OnOpeningURL() returns @c wxHTML_REDIRECT. 
 205         - wxHTML_OPEN: Open the URL. 
 206         - wxHTML_BLOCK: Deny access to the URL, wxHtmlParser::OpenURL will return @NULL. 
 207         - wxHTML_REDIRECT: Don't open url, redirect to another URL. 
 208           OnOpeningURL() must fill *redirect with the new URL. 
 209           OnOpeningURL() will be called again on returned URL. 
 211     virtual wxHtmlOpeningStatus 
OnOpeningURL(wxHtmlURLType type
, 
 213                                              wxString
* redirect
) const; 
 216         Called on parsing \<TITLE\> tag. 
 218     virtual void OnSetTitle(const wxString
& title
); 
 221         This reads custom settings from wxConfig. It uses the path 'path' 
 222         if given, otherwise it saves info into currently selected path. 
 223         The values are stored in sub-path @c wxHtmlWindow. 
 224         Read values: all things set by SetFonts(), SetBorders(). 
 227             wxConfig from which you want to read the configuration. 
 229             Optional path in config tree. If not given current path is used. 
 231     virtual void ReadCustomization(wxConfigBase
* cfg
, 
 232                                    wxString path 
= wxEmptyString
); 
 235         Selects all text in the window. 
 237         @see SelectLine(), SelectWord() 
 242         Selects the line of text that @a pos points at. Note that @e pos 
 243         is relative to the top of displayed page, not to window's origin, use 
 244         wxScrolled::CalcUnscrolledPosition() 
 245         to convert physical coordinate. 
 247         @see SelectAll(), SelectWord() 
 249     void SelectLine(const wxPoint
& pos
); 
 252         Selects the word at position @a pos. 
 253         Note that @a pos is relative to the top of displayed page, not to window's 
 254         origin, use wxScrolled::CalcUnscrolledPosition() to convert physical coordinate. 
 256         @see SelectAll(), SelectLine() 
 258     void SelectWord(const wxPoint
& pos
); 
 261         Returns current selection as plain text. 
 262         Returns empty string if no text is currently selected. 
 264     wxString 
SelectionToText(); 
 267         This function sets the space between border of window and HTML contents. 
 269         @image html border.png 
 272             indentation from borders in pixels 
 274     void SetBorders(int b
); 
 277         This function sets font sizes and faces. 
 280             This is face name for normal (i.e. non-fixed) font. 
 281             It can be either empty string (then the default face is chosen) or 
 282             platform-specific face name. Examples are "helvetica" under Unix or 
 283             "Times New Roman" under Windows. 
 285             The same thing for fixed face ( \<TT\>..\</TT\> ) 
 287             This is an array of 7 items of int type. 
 288             The values represent size of font with HTML size from -2 to +4 
 289             ( \<FONT SIZE=-2\> to \<FONT SIZE=+4\> ). 
 290             Default sizes are used if sizes is @NULL. 
 292         Default font sizes are defined by constants wxHTML_FONT_SIZE_1, 
 293         wxHTML_FONT_SIZE_2, ..., wxHTML_FONT_SIZE_7. 
 294         Note that they differ among platforms. Default face names are empty strings. 
 296     void SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, 
 297                   const int* sizes 
= NULL
); 
 300         Sets HTML page and display it. This won't @b load the page!! 
 301         It will display the @e source. See example: 
 303         htmlwin -> SetPage("<html><body>Hello, world!</body></html>"); 
 306         If you want to load a document from some location use LoadPage() instead. 
 309             The HTML document source to be displayed. 
 311         @return @false if an error occurred, @true otherwise. 
 313     virtual bool SetPage(const wxString
& source
); 
 316         Sets the frame in which page title will be displayed. 
 317         @a format is the format of the frame title, e.g. "HtmlHelp : %s". 
 318         It must contain exactly one %s. 
 319         This %s is substituted with HTML page title. 
 321     void SetRelatedFrame(wxFrame
* frame
, const wxString
& format
); 
 324         @b After calling SetRelatedFrame(), this sets statusbar slot where messages 
 325         will be displayed. (Default is -1 = no messages.) 
 328             Statusbar slot number (0..n) 
 330     void SetRelatedStatusBar(int index
); 
 333         @b Sets the associated statusbar where messages will be displayed. 
 334         Call this instead of SetRelatedFrame() if you want statusbar updates only, 
 335         no changing of the frame title. 
 340             Statusbar slot number (0..n) 
 344     void SetRelatedStatusBar(wxStatusBar
* statusbar
, int index 
= 0); 
 347         Returns content of currently displayed page as plain text. 
 352         Saves custom settings into wxConfig. 
 353         It uses the path 'path' if given, otherwise it saves info into currently 
 355         Regardless of whether the path is given or not, the function creates 
 356         sub-path @c wxHtmlWindow. 
 358         Saved values: all things set by SetFonts(), SetBorders(). 
 361             wxConfig to which you want to save the configuration. 
 363             Optional path in config tree. If not given, the current path is used. 
 365     virtual void WriteCustomization(wxConfigBase
* cfg
, 
 366                                     wxString path 
= wxEmptyString
); 
 371         This method is called when a mouse button is clicked inside wxHtmlWindow. 
 372         The default behaviour is to emit a wxHtmlCellEvent and, if the event was 
 373         not processed or skipped, call OnLinkClicked() if the cell contains an 
 376         Overloading this method is deprecated; intercept the event instead. 
 379             The cell inside which the mouse was clicked, always a simple 
 380             (i.e. non-container) cell 
 382             The logical x coordinate of the click point 
 384             The logical y coordinate of the click point 
 386             The mouse event containing other information about the click 
 388         @return @true if a link was clicked, @false otherwise. 
 390     virtual bool OnCellClicked(wxHtmlCell
* cell
, wxCoord x
, wxCoord y
, 
 391                                const wxMouseEvent
& event
); 
 394         This method is called when a mouse moves over an HTML cell. 
 395         Default behaviour is to emit a wxHtmlCellEvent. 
 397         Overloading this method is deprecated; intercept the event instead. 
 400             The cell inside which the mouse is currently, always a simple 
 401             (i.e. non-container) cell 
 403             The logical x coordinate of the click point 
 405             The logical y coordinate 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. 
 417     @beginEventTable{wxHtmlLinkEvent} 
 418     @event{EVT_HTML_LINK_CLICKED(id, func)} 
 419         User clicked on an hyperlink. 
 425 class wxHtmlLinkEvent 
: public wxCommandEvent
 
 429         The constructor is not normally used by the user code. 
 431     wxHyperlinkEvent(int id
, const wxHtmlLinkInfo
& linkinfo
); 
 434         Returns the wxHtmlLinkInfo which contains info about the cell clicked 
 435         and the hyperlink it contains. 
 437     const wxHtmlLinkInfo
& GetLinkInfo() const; 
 443     @class wxHtmlCellEvent 
 445     This event class is used for the events generated by wxHtmlWindow. 
 447     @beginEventTable{wxHtmlCellEvent} 
 448     @event{EVT_HTML_CELL_HOVER(id, func)} 
 449         User moved the mouse over a wxHtmlCell. 
 450     @event{EVT_HTML_CELL_CLICKED(id, func)} 
 451         User clicked on a wxHtmlCell. When handling this event, remember to use 
 452         wxHtmlCell::SetLinkClicked(true) if the cell contains a link. 
 458 class wxHtmlCellEvent 
: public wxCommandEvent
 
 462         The constructor is not normally used by the user code. 
 464     wxHtmlCellEvent(wxEventType commandType
, int id
, 
 466                     const wxPoint
& point
, 
 467                     const wxMouseEvent
& ev
); 
 470         Returns the wxHtmlCellEvent associated with the event. 
 472     wxHtmlCell
* GetCell() const; 
 475         Returns @true if SetLinkClicked(@true) has previously been called; 
 478     bool GetLinkClicked() const; 
 481         Returns the wxPoint associated with the event. 
 483     wxPoint 
GetPoint() const; 
 486         Call this function with @a linkclicked set to @true if the cell which has 
 487         been clicked contained a link or @false otherwise (which is the default). 
 489         With this function the event handler can return info to the wxHtmlWindow 
 490         which sent the event. 
 492     void SetLinkClicked(bool linkclicked
);