htmlwin.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/html/htmlwin.h
  3. // Purpose: wxHtmlWindow class for parsing & displaying HTML
  4. // Author: Vaclav Slavik
  5. // Copyright: (c) 1999 Vaclav Slavik
  6. // Licence: wxWindows licence
  7. /////////////////////////////////////////////////////////////////////////////
  8. #ifndef _WX_HTMLWIN_H_
  9. #define _WX_HTMLWIN_H_
  10. #include "wx/defs.h"
  11. #if wxUSE_HTML
  12. #include "wx/window.h"
  13. #include "wx/scrolwin.h"
  14. #include "wx/config.h"
  15. #include "wx/stopwatch.h"
  16. #include "wx/html/winpars.h"
  17. #include "wx/html/htmlcell.h"
  18. #include "wx/filesys.h"
  19. #include "wx/html/htmlfilt.h"
  20. #include "wx/filename.h"
  21. #include "wx/bitmap.h"
  22. class wxHtmlProcessor;
  23. class wxHtmlWinModule;
  24. class wxHtmlHistoryArray;
  25. class wxHtmlProcessorList;
  26. class WXDLLIMPEXP_FWD_HTML wxHtmlWinAutoScrollTimer;
  27. class WXDLLIMPEXP_FWD_HTML wxHtmlCellEvent;
  28. class WXDLLIMPEXP_FWD_HTML wxHtmlLinkEvent;
  29. class WXDLLIMPEXP_FWD_CORE wxStatusBar;
  30. // wxHtmlWindow flags:
  31. #define wxHW_SCROLLBAR_NEVER 0x0002
  32. #define wxHW_SCROLLBAR_AUTO 0x0004
  33. #define wxHW_NO_SELECTION 0x0008
  34. #define wxHW_DEFAULT_STYLE wxHW_SCROLLBAR_AUTO
  35. /// Enum for wxHtmlWindow::OnOpeningURL and wxHtmlWindowInterface::OnOpeningURL
  36. enum wxHtmlOpeningStatus
  37. {
  38. /// Open the requested URL
  39. wxHTML_OPEN,
  40. /// Do not open the URL
  41. wxHTML_BLOCK,
  42. /// Redirect to another URL (returned from OnOpeningURL)
  43. wxHTML_REDIRECT
  44. };
  45. /**
  46. Abstract interface to a HTML rendering window (such as wxHtmlWindow or
  47. wxHtmlListBox) that is passed to wxHtmlWinParser. It encapsulates all
  48. communication from the parser to the window.
  49. */
  50. class WXDLLIMPEXP_HTML wxHtmlWindowInterface
  51. {
  52. public:
  53. /// Ctor
  54. wxHtmlWindowInterface() {}
  55. virtual ~wxHtmlWindowInterface() {}
  56. /**
  57. Called by the parser to set window's title to given text.
  58. */
  59. virtual void SetHTMLWindowTitle(const wxString& title) = 0;
  60. /**
  61. Called when a link is clicked.
  62. @param link information about the clicked link
  63. */
  64. virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link) = 0;
  65. /**
  66. Called when the parser needs to open another URL (e.g. an image).
  67. @param type Type of the URL request (e.g. image)
  68. @param url URL the parser wants to open
  69. @param redirect If the return value is wxHTML_REDIRECT, then the
  70. URL to redirect to will be stored in this variable
  71. (the pointer must never be NULL)
  72. @return indicator of how to treat the request
  73. */
  74. virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
  75. const wxString& url,
  76. wxString *redirect) const = 0;
  77. /**
  78. Converts coordinates @a pos relative to given @a cell to
  79. physical coordinates in the window.
  80. */
  81. virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
  82. const wxPoint& pos) const = 0;
  83. /// Returns the window used for rendering (may be NULL).
  84. virtual wxWindow* GetHTMLWindow() = 0;
  85. /// Returns background colour to use by default.
  86. virtual wxColour GetHTMLBackgroundColour() const = 0;
  87. /// Sets window's background to colour @a clr.
  88. virtual void SetHTMLBackgroundColour(const wxColour& clr) = 0;
  89. /// Sets window's background to given bitmap.
  90. virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg) = 0;
  91. /// Sets status bar text.
  92. virtual void SetHTMLStatusText(const wxString& text) = 0;
  93. /// Type of mouse cursor
  94. enum HTMLCursor
  95. {
  96. /// Standard mouse cursor (typically an arrow)
  97. HTMLCursor_Default,
  98. /// Cursor shown over links
  99. HTMLCursor_Link,
  100. /// Cursor shown over selectable text
  101. HTMLCursor_Text
  102. };
  103. /**
  104. Returns mouse cursor of given @a type.
  105. */
  106. virtual wxCursor GetHTMLCursor(HTMLCursor type) const = 0;
  107. };
  108. /**
  109. Helper class that implements part of mouse handling for wxHtmlWindow and
  110. wxHtmlListBox. Cursor changes and clicking on links are handled, text
  111. selection is not.
  112. */
  113. class WXDLLIMPEXP_HTML wxHtmlWindowMouseHelper
  114. {
  115. protected:
  116. /**
  117. Ctor.
  118. @param iface Interface to the owner window.
  119. */
  120. wxHtmlWindowMouseHelper(wxHtmlWindowInterface *iface);
  121. /**
  122. Virtual dtor.
  123. It is not really needed in this case but at leats it prevents gcc from
  124. complaining about its absence.
  125. */
  126. virtual ~wxHtmlWindowMouseHelper() { }
  127. /// Returns true if the mouse moved since the last call to HandleIdle
  128. bool DidMouseMove() const { return m_tmpMouseMoved; }
  129. /// Call this from EVT_MOTION event handler
  130. void HandleMouseMoved();
  131. /**
  132. Call this from EVT_LEFT_UP handler (or, alternatively, EVT_LEFT_DOWN).
  133. @param rootCell HTML cell inside which the click occured. This doesn't
  134. have to be the leaf cell, it can be e.g. toplevel
  135. container, but the mouse must be inside the container's
  136. area, otherwise the event would be ignored.
  137. @param pos Mouse position in coordinates relative to @a cell
  138. @param event The event that triggered the call
  139. */
  140. bool HandleMouseClick(wxHtmlCell *rootCell,
  141. const wxPoint& pos, const wxMouseEvent& event);
  142. /**
  143. Call this from OnInternalIdle of the HTML displaying window. Handles
  144. mouse movements and must be used together with HandleMouseMoved.
  145. @param rootCell HTML cell inside which the click occured. This doesn't
  146. have to be the leaf cell, it can be e.g. toplevel
  147. container, but the mouse must be inside the container's
  148. area, otherwise the event would be ignored.
  149. @param pos Current mouse position in coordinates relative to
  150. @a cell
  151. */
  152. void HandleIdle(wxHtmlCell *rootCell, const wxPoint& pos);
  153. /**
  154. Called by HandleIdle when the mouse hovers over a cell. Default
  155. behaviour is to do nothing.
  156. @param cell the cell the mouse is over
  157. @param x, y coordinates of mouse relative to the cell
  158. */
  159. virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
  160. /**
  161. Called by HandleMouseClick when the user clicks on a cell.
  162. Default behaviour is to call wxHtmlWindowInterface::OnLinkClicked()
  163. if this cell corresponds to a hypertext link.
  164. @param cell the cell the mouse is over
  165. @param x, y coordinates of mouse relative to the cell
  166. @param event The event that triggered the call
  167. @return true if a link was clicked, false otherwise.
  168. */
  169. virtual bool OnCellClicked(wxHtmlCell *cell,
  170. wxCoord x, wxCoord y,
  171. const wxMouseEvent& event);
  172. protected:
  173. // this flag indicates if the mouse moved (used by HandleIdle)
  174. bool m_tmpMouseMoved;
  175. // contains last link name
  176. wxHtmlLinkInfo *m_tmpLastLink;
  177. // contains the last (terminal) cell which contained the mouse
  178. wxHtmlCell *m_tmpLastCell;
  179. private:
  180. wxHtmlWindowInterface *m_interface;
  181. };
  182. // ----------------------------------------------------------------------------
  183. // wxHtmlWindow
  184. // (This is probably the only class you will directly use.)
  185. // Purpose of this class is to display HTML page (either local
  186. // file or downloaded via HTTP protocol) in a window. Width of
  187. // window is constant - given in constructor - virtual height
  188. // is changed dynamically depending on page size. Once the
  189. // window is created you can set its content by calling
  190. // SetPage(text) or LoadPage(filename).
  191. // ----------------------------------------------------------------------------
  192. class WXDLLIMPEXP_HTML wxHtmlWindow : public wxScrolledWindow,
  193. public wxHtmlWindowInterface,
  194. public wxHtmlWindowMouseHelper
  195. {
  196. DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
  197. friend class wxHtmlWinModule;
  198. public:
  199. wxHtmlWindow() : wxHtmlWindowMouseHelper(this) { Init(); }
  200. wxHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
  201. const wxPoint& pos = wxDefaultPosition,
  202. const wxSize& size = wxDefaultSize,
  203. long style = wxHW_DEFAULT_STYLE,
  204. const wxString& name = wxT("htmlWindow"))
  205. : wxHtmlWindowMouseHelper(this)
  206. {
  207. Init();
  208. Create(parent, id, pos, size, style, name);
  209. }
  210. virtual ~wxHtmlWindow();
  211. bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
  212. const wxPoint& pos = wxDefaultPosition,
  213. const wxSize& size = wxDefaultSize,
  214. long style = wxHW_SCROLLBAR_AUTO,
  215. const wxString& name = wxT("htmlWindow"));
  216. // Set HTML page and display it. !! source is HTML document itself,
  217. // it is NOT address/filename of HTML document. If you want to
  218. // specify document location, use LoadPage() istead
  219. // Return value : false if an error occurred, true otherwise
  220. virtual bool SetPage(const wxString& source);
  221. // Append to current page
  222. bool AppendToPage(const wxString& source);
  223. // Load HTML page from given location. Location can be either
  224. // a) /usr/wxGTK2/docs/html/wx.htm
  225. // b) http://www.somewhere.uk/document.htm
  226. // c) ftp://ftp.somesite.cz/pub/something.htm
  227. // In case there is no prefix (http:,ftp:), the method
  228. // will try to find it itself (1. local file, then http or ftp)
  229. // After the page is loaded, the method calls SetPage() to display it.
  230. // Note : you can also use path relative to previously loaded page
  231. // Return value : same as SetPage
  232. virtual bool LoadPage(const wxString& location);
  233. // Loads HTML page from file
  234. bool LoadFile(const wxFileName& filename);
  235. // Returns full location of opened page
  236. wxString GetOpenedPage() const {return m_OpenedPage;}
  237. // Returns anchor within opened page
  238. wxString GetOpenedAnchor() const {return m_OpenedAnchor;}
  239. // Returns <TITLE> of opened page or empty string otherwise
  240. wxString GetOpenedPageTitle() const {return m_OpenedPageTitle;}
  241. // Sets frame in which page title will be displayed. Format is format of
  242. // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
  243. void SetRelatedFrame(wxFrame* frame, const wxString& format);
  244. wxFrame* GetRelatedFrame() const {return m_RelatedFrame;}
  245. #if wxUSE_STATUSBAR
  246. // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
  247. // will be displayed. Default is -1 = no messages.
  248. void SetRelatedStatusBar(int index);
  249. void SetRelatedStatusBar(wxStatusBar*, int index = 0);
  250. #endif // wxUSE_STATUSBAR
  251. // Sets fonts to be used when displaying HTML page.
  252. void SetFonts(const wxString& normal_face, const wxString& fixed_face,
  253. const int *sizes = NULL);
  254. // Sets font sizes to be relative to the given size or the system
  255. // default size; use either specified or default font
  256. void SetStandardFonts(int size = -1,
  257. const wxString& normal_face = wxEmptyString,
  258. const wxString& fixed_face = wxEmptyString);
  259. // Sets space between text and window borders.
  260. void SetBorders(int b) {m_Borders = b;}
  261. // Sets the bitmap to use for background (currnetly it will be tiled,
  262. // when/if we have CSS support we could add other possibilities...)
  263. void SetBackgroundImage(const wxBitmap& bmpBg) { m_bmpBg = bmpBg; }
  264. #if wxUSE_CONFIG
  265. // Saves custom settings into cfg config. it will use the path 'path'
  266. // if given, otherwise it will save info into currently selected path.
  267. // saved values : things set by SetFonts, SetBorders.
  268. virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
  269. // ...
  270. virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
  271. #endif // wxUSE_CONFIG
  272. // Goes to previous/next page (in browsing history)
  273. // Returns true if successful, false otherwise
  274. bool HistoryBack();
  275. bool HistoryForward();
  276. bool HistoryCanBack();
  277. bool HistoryCanForward();
  278. // Resets history
  279. void HistoryClear();
  280. // Returns pointer to conteiners/cells structure.
  281. // It should be used ONLY when printing
  282. wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
  283. // Adds input filter
  284. static void AddFilter(wxHtmlFilter *filter);
  285. // Returns a pointer to the parser.
  286. wxHtmlWinParser *GetParser() const { return m_Parser; }
  287. // Adds HTML processor to this instance of wxHtmlWindow:
  288. void AddProcessor(wxHtmlProcessor *processor);
  289. // Adds HTML processor to wxHtmlWindow class as whole:
  290. static void AddGlobalProcessor(wxHtmlProcessor *processor);
  291. // -- Callbacks --
  292. // Sets the title of the window
  293. // (depending on the information passed to SetRelatedFrame() method)
  294. virtual void OnSetTitle(const wxString& title);
  295. // Called when user clicked on hypertext link. Default behaviour is to
  296. // call LoadPage(loc)
  297. virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
  298. // Called when wxHtmlWindow wants to fetch data from an URL (e.g. when
  299. // loading a page or loading an image). The data are downloaded if and only if
  300. // OnOpeningURL returns true. If OnOpeningURL returns wxHTML_REDIRECT,
  301. // it must set *redirect to the new URL
  302. virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
  303. const wxString& WXUNUSED(url),
  304. wxString *WXUNUSED(redirect)) const
  305. { return wxHTML_OPEN; }
  306. #if wxUSE_CLIPBOARD
  307. // Helper functions to select parts of page:
  308. void SelectWord(const wxPoint& pos);
  309. void SelectLine(const wxPoint& pos);
  310. void SelectAll();
  311. // Convert selection to text:
  312. wxString SelectionToText() { return DoSelectionToText(m_selection); }
  313. // Converts current page to text:
  314. wxString ToText();
  315. #endif // wxUSE_CLIPBOARD
  316. virtual void OnInternalIdle();
  317. /// Returns standard HTML cursor as used by wxHtmlWindow
  318. static wxCursor GetDefaultHTMLCursor(HTMLCursor type);
  319. protected:
  320. void Init();
  321. // Scrolls to anchor of this name. (Anchor is #news
  322. // or #features etc. it is part of address sometimes:
  323. // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
  324. // Return value : true if anchor exists, false otherwise
  325. bool ScrollToAnchor(const wxString& anchor);
  326. // Prepares layout (= fill m_PosX, m_PosY for fragments) based on
  327. // actual size of window. This method also setup scrollbars
  328. void CreateLayout();
  329. void OnPaint(wxPaintEvent& event);
  330. void OnEraseBackground(wxEraseEvent& event);
  331. void OnSize(wxSizeEvent& event);
  332. void OnMouseMove(wxMouseEvent& event);
  333. void OnMouseDown(wxMouseEvent& event);
  334. void OnMouseUp(wxMouseEvent& event);
  335. #if wxUSE_CLIPBOARD
  336. void OnKeyUp(wxKeyEvent& event);
  337. void OnDoubleClick(wxMouseEvent& event);
  338. void OnCopy(wxCommandEvent& event);
  339. void OnClipboardEvent(wxClipboardTextEvent& event);
  340. void OnMouseEnter(wxMouseEvent& event);
  341. void OnMouseLeave(wxMouseEvent& event);
  342. void OnMouseCaptureLost(wxMouseCaptureLostEvent& event);
  343. #endif // wxUSE_CLIPBOARD
  344. // Returns new filter (will be stored into m_DefaultFilter variable)
  345. virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
  346. // cleans static variables
  347. static void CleanUpStatics();
  348. // Returns true if text selection is enabled (wxClipboard must be available
  349. // and wxHW_NO_SELECTION not used)
  350. bool IsSelectionEnabled() const;
  351. enum ClipboardType
  352. {
  353. Primary,
  354. Secondary
  355. };
  356. // Copies selection to clipboard if the clipboard support is available
  357. //
  358. // returns true if anything was copied to clipboard, false otherwise
  359. bool CopySelection(ClipboardType t = Secondary);
  360. #if wxUSE_CLIPBOARD
  361. // Automatic scrolling during selection:
  362. void StopAutoScrolling();
  363. #endif // wxUSE_CLIPBOARD
  364. wxString DoSelectionToText(wxHtmlSelection *sel);
  365. public:
  366. // wxHtmlWindowInterface methods:
  367. virtual void SetHTMLWindowTitle(const wxString& title);
  368. virtual void OnHTMLLinkClicked(const wxHtmlLinkInfo& link);
  369. virtual wxHtmlOpeningStatus OnHTMLOpeningURL(wxHtmlURLType type,
  370. const wxString& url,
  371. wxString *redirect) const;
  372. virtual wxPoint HTMLCoordsToWindow(wxHtmlCell *cell,
  373. const wxPoint& pos) const;
  374. virtual wxWindow* GetHTMLWindow();
  375. virtual wxColour GetHTMLBackgroundColour() const;
  376. virtual void SetHTMLBackgroundColour(const wxColour& clr);
  377. virtual void SetHTMLBackgroundImage(const wxBitmap& bmpBg);
  378. virtual void SetHTMLStatusText(const wxString& text);
  379. virtual wxCursor GetHTMLCursor(HTMLCursor type) const;
  380. // implementation of SetPage()
  381. bool DoSetPage(const wxString& source);
  382. protected:
  383. // This is pointer to the first cell in parsed data. (Note: the first cell
  384. // is usually top one = all other cells are sub-cells of this one)
  385. wxHtmlContainerCell *m_Cell;
  386. // parser which is used to parse HTML input.
  387. // Each wxHtmlWindow has its own parser because sharing one global
  388. // parser would be problematic (because of reentrancy)
  389. wxHtmlWinParser *m_Parser;
  390. // contains name of actually opened page or empty string if no page opened
  391. wxString m_OpenedPage;
  392. // contains name of current anchor within m_OpenedPage
  393. wxString m_OpenedAnchor;
  394. // contains title of actually opened page or empty string if no <TITLE> tag
  395. wxString m_OpenedPageTitle;
  396. // class for opening files (file system)
  397. wxFileSystem* m_FS;
  398. // frame in which page title should be displayed & number of its statusbar
  399. // reserved for usage with this html window
  400. wxFrame *m_RelatedFrame;
  401. #if wxUSE_STATUSBAR
  402. int m_RelatedStatusBarIndex;
  403. wxStatusBar* m_RelatedStatusBar;
  404. #endif // wxUSE_STATUSBAR
  405. wxString m_TitleFormat;
  406. // borders (free space between text and window borders)
  407. // defaults to 10 pixels.
  408. int m_Borders;
  409. // current text selection or NULL
  410. wxHtmlSelection *m_selection;
  411. // true if the user is dragging mouse to select text
  412. bool m_makingSelection;
  413. #if wxUSE_CLIPBOARD
  414. // time of the last doubleclick event, used to detect tripleclicks
  415. // (tripleclicks are used to select whole line):
  416. wxMilliClock_t m_lastDoubleClick;
  417. // helper class to automatically scroll the window if the user is selecting
  418. // text and the mouse leaves wxHtmlWindow:
  419. wxHtmlWinAutoScrollTimer *m_timerAutoScroll;
  420. #endif // wxUSE_CLIPBOARD
  421. private:
  422. // erase the window background using m_bmpBg or just solid colour if we
  423. // don't have any background image
  424. void DoEraseBackground(wxDC& dc);
  425. // window content for double buffered rendering, may be invalid until it is
  426. // really initialized in OnPaint()
  427. wxBitmap m_backBuffer;
  428. // background image, may be invalid
  429. wxBitmap m_bmpBg;
  430. // variables used when user is selecting text
  431. wxPoint m_tmpSelFromPos;
  432. wxHtmlCell *m_tmpSelFromCell;
  433. // if >0 contents of the window is not redrawn
  434. // (in order to avoid ugly blinking)
  435. int m_tmpCanDrawLocks;
  436. // list of HTML filters
  437. static wxList m_Filters;
  438. // this filter is used when no filter is able to read some file
  439. static wxHtmlFilter *m_DefaultFilter;
  440. // html processors array:
  441. wxHtmlProcessorList *m_Processors;
  442. static wxHtmlProcessorList *m_GlobalProcessors;
  443. // browser history
  444. wxHtmlHistoryArray *m_History;
  445. int m_HistoryPos;
  446. // if this FLAG is false, items are not added to history
  447. bool m_HistoryOn;
  448. // Flag used to communicate between OnPaint() and OnEraseBackground(), see
  449. // the comments near its use.
  450. bool m_isBgReallyErased;
  451. // standard mouse cursors
  452. static wxCursor *ms_cursorLink;
  453. static wxCursor *ms_cursorText;
  454. DECLARE_EVENT_TABLE()
  455. wxDECLARE_NO_COPY_CLASS(wxHtmlWindow);
  456. };
  457. class WXDLLIMPEXP_FWD_HTML wxHtmlCellEvent;
  458. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_HTML, wxEVT_HTML_CELL_CLICKED, wxHtmlCellEvent );
  459. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_HTML, wxEVT_HTML_CELL_HOVER, wxHtmlCellEvent );
  460. wxDECLARE_EXPORTED_EVENT( WXDLLIMPEXP_HTML, wxEVT_HTML_LINK_CLICKED, wxHtmlLinkEvent );
  461. /*!
  462. * Html cell window event
  463. */
  464. class WXDLLIMPEXP_HTML wxHtmlCellEvent : public wxCommandEvent
  465. {
  466. public:
  467. wxHtmlCellEvent() {}
  468. wxHtmlCellEvent(wxEventType commandType, int id,
  469. wxHtmlCell *cell, const wxPoint &pt,
  470. const wxMouseEvent &ev)
  471. : wxCommandEvent(commandType, id)
  472. {
  473. m_cell = cell;
  474. m_pt = pt;
  475. m_mouseEvent = ev;
  476. m_bLinkWasClicked = false;
  477. }
  478. wxHtmlCell* GetCell() const { return m_cell; }
  479. wxPoint GetPoint() const { return m_pt; }
  480. wxMouseEvent GetMouseEvent() const { return m_mouseEvent; }
  481. void SetLinkClicked(bool linkclicked) { m_bLinkWasClicked=linkclicked; }
  482. bool GetLinkClicked() const { return m_bLinkWasClicked; }
  483. // default copy ctor, assignment operator and dtor are ok
  484. virtual wxEvent *Clone() const { return new wxHtmlCellEvent(*this); }
  485. private:
  486. wxHtmlCell *m_cell;
  487. wxMouseEvent m_mouseEvent;
  488. wxPoint m_pt;
  489. bool m_bLinkWasClicked;
  490. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHtmlCellEvent)
  491. };
  492. /*!
  493. * Html link event
  494. */
  495. class WXDLLIMPEXP_HTML wxHtmlLinkEvent : public wxCommandEvent
  496. {
  497. public:
  498. wxHtmlLinkEvent() {}
  499. wxHtmlLinkEvent(int id, const wxHtmlLinkInfo &linkinfo)
  500. : wxCommandEvent(wxEVT_HTML_LINK_CLICKED, id)
  501. {
  502. m_linkInfo = linkinfo;
  503. }
  504. const wxHtmlLinkInfo &GetLinkInfo() const { return m_linkInfo; }
  505. // default copy ctor, assignment operator and dtor are ok
  506. virtual wxEvent *Clone() const { return new wxHtmlLinkEvent(*this); }
  507. private:
  508. wxHtmlLinkInfo m_linkInfo;
  509. DECLARE_DYNAMIC_CLASS_NO_ASSIGN(wxHtmlLinkEvent)
  510. };
  511. typedef void (wxEvtHandler::*wxHtmlCellEventFunction)(wxHtmlCellEvent&);
  512. typedef void (wxEvtHandler::*wxHtmlLinkEventFunction)(wxHtmlLinkEvent&);
  513. #define wxHtmlCellEventHandler(func) \
  514. wxEVENT_HANDLER_CAST(wxHtmlCellEventFunction, func)
  515. #define wxHtmlLinkEventHandler(func) \
  516. wxEVENT_HANDLER_CAST(wxHtmlLinkEventFunction, func)
  517. #define EVT_HTML_CELL_CLICKED(id, fn) \
  518. wx__DECLARE_EVT1(wxEVT_HTML_CELL_CLICKED, id, wxHtmlCellEventHandler(fn))
  519. #define EVT_HTML_CELL_HOVER(id, fn) \
  520. wx__DECLARE_EVT1(wxEVT_HTML_CELL_HOVER, id, wxHtmlCellEventHandler(fn))
  521. #define EVT_HTML_LINK_CLICKED(id, fn) \
  522. wx__DECLARE_EVT1(wxEVT_HTML_LINK_CLICKED, id, wxHtmlLinkEventHandler(fn))
  523. // old wxEVT_COMMAND_* constants
  524. #define wxEVT_COMMAND_HTML_CELL_CLICKED wxEVT_HTML_CELL_CLICKED
  525. #define wxEVT_COMMAND_HTML_CELL_HOVER wxEVT_HTML_CELL_HOVER
  526. #define wxEVT_COMMAND_HTML_LINK_CLICKED wxEVT_HTML_LINK_CLICKED
  527. #endif // wxUSE_HTML
  528. #endif // _WX_HTMLWIN_H_