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