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