]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/htmlwin.h
Support for automatic setup.h in OS/2 with OW builds. __WXOS2__ final removal. Source...
[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"
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 26class wxHtmlProcessor;
892aeafc
VS
27class wxHtmlWinModule;
28class wxHtmlHistoryArray;
29class wxHtmlProcessorList;
6acba9a7 30class WXDLLIMPEXP_HTML wxHtmlWinAutoScrollTimer;
5526e819 31
6cc4e6b8
VS
32
33// wxHtmlWindow flags:
34#define wxHW_SCROLLBAR_NEVER 0x0002
35#define wxHW_SCROLLBAR_AUTO 0x0004
f65a786f
VS
36#define wxHW_NO_SELECTION 0x0008
37
38#define wxHW_DEFAULT_STYLE wxHW_SCROLLBAR_AUTO
39
6cc4e6b8
VS
40
41// enums for wxHtmlWindow::OnOpeningURL
42enum wxHtmlOpeningStatus
43{
44 wxHTML_OPEN,
45 wxHTML_BLOCK,
46 wxHTML_REDIRECT
47};
48
f65a786f 49// ----------------------------------------------------------------------------
5526e819 50// wxHtmlWindow
3ef01ce5 51// (This is probably the only class you will directly use.)
5526e819 52// Purpose of this class is to display HTML page (either local
f65a786f
VS
53// file or downloaded via HTTP protocol) in a window. Width of
54// window is constant - given in constructor - virtual height
55// is changed dynamicly depending on page size. Once the
56// window is created you can set it's content by calling
3ef01ce5 57// SetPage(text) or LoadPage(filename).
f65a786f 58// ----------------------------------------------------------------------------
5526e819 59
6acba9a7 60class WXDLLIMPEXP_HTML wxHtmlWindow : public wxScrolledWindow
5526e819
VS
61{
62 DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
66806a0b 63 friend class wxHtmlWinModule;
5526e819 64
97494971 65public:
4f417130 66 wxHtmlWindow() { Init(); }
6953da00 67 wxHtmlWindow(wxWindow *parent, wxWindowID id = wxID_ANY,
bfb9ee96 68 const wxPoint& pos = wxDefaultPosition,
97494971 69 const wxSize& size = wxDefaultSize,
f65a786f 70 long style = wxHW_DEFAULT_STYLE,
4f417130
VS
71 const wxString& name = wxT("htmlWindow"))
72 {
73 Init();
74 Create(parent, id, pos, size, style, name);
75 }
97494971
VS
76 ~wxHtmlWindow();
77
6953da00 78 bool Create(wxWindow *parent, wxWindowID id = wxID_ANY,
4f417130
VS
79 const wxPoint& pos = wxDefaultPosition,
80 const wxSize& size = wxDefaultSize,
81 long style = wxHW_SCROLLBAR_AUTO,
82 const wxString& name = wxT("htmlWindow"));
83
97494971
VS
84 // Set HTML page and display it. !! source is HTML document itself,
85 // it is NOT address/filename of HTML document. If you want to
86 // specify document location, use LoadPage() istead
3103e8a9 87 // Return value : false if an error occurred, true otherwise
97494971 88 bool SetPage(const wxString& source);
574c939e 89
39029898
VS
90 // Append to current page
91 bool AppendToPage(const wxString& source);
97494971
VS
92
93 // Load HTML page from given location. Location can be either
94 // a) /usr/wxGTK2/docs/html/wx.htm
95 // b) http://www.somewhere.uk/document.htm
96 // c) ftp://ftp.somesite.cz/pub/something.htm
97 // In case there is no prefix (http:,ftp:), the method
98 // will try to find it itself (1. local file, then http or ftp)
99 // After the page is loaded, the method calls SetPage() to display it.
100 // Note : you can also use path relative to previously loaded page
101 // Return value : same as SetPage
38caaa61 102 virtual bool LoadPage(const wxString& location);
97494971 103
903972f9
VS
104 // Loads HTML page from file
105 bool LoadFile(const wxFileName& filename);
106
97494971
VS
107 // Returns full location of opened page
108 wxString GetOpenedPage() const {return m_OpenedPage;}
109 // Returns anchor within opened page
110 wxString GetOpenedAnchor() const {return m_OpenedAnchor;}
111 // Returns <TITLE> of opened page or empty string otherwise
112 wxString GetOpenedPageTitle() const {return m_OpenedPageTitle;}
113
114 // Sets frame in which page title will be displayed. Format is format of
115 // frame title, e.g. "HtmlHelp : %s". It must contain exactly one %s
116 void SetRelatedFrame(wxFrame* frame, const wxString& format);
117 wxFrame* GetRelatedFrame() const {return m_RelatedFrame;}
118
67a99992 119#if wxUSE_STATUSBAR
97494971
VS
120 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
121 // will be displayed. Default is -1 = no messages.
122 void SetRelatedStatusBar(int bar);
67a99992 123#endif // wxUSE_STATUSBAR
97494971
VS
124
125 // Sets fonts to be used when displaying HTML page.
fbfb8bcc 126 void SetFonts(const wxString& normal_face, const wxString& fixed_face,
4eecf115 127 const int *sizes = NULL);
97494971 128
10e5c7ea
VS
129 // Sets font sizes to be relative to the given size or the system
130 // default size; use either specified or default font
131 void SetStandardFonts(int size = -1,
132 const wxString& normal_face = wxEmptyString,
133 const wxString& fixed_face = wxEmptyString);
6953da00 134
97494971
VS
135 // Sets space between text and window borders.
136 void SetBorders(int b) {m_Borders = b;}
137
97e490f8
VZ
138 // Sets the bitmap to use for background (currnetly it will be tiled,
139 // when/if we have CSS support we could add other possibilities...)
140 void SetBackgroundImage(const wxBitmap& bmpBg) { m_bmpBg = bmpBg; }
141
97494971
VS
142 // Saves custom settings into cfg config. it will use the path 'path'
143 // if given, otherwise it will save info into currently selected path.
144 // saved values : things set by SetFonts, SetBorders.
145 virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
146 // ...
147 virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
148
149 // Goes to previous/next page (in browsing history)
6953da00 150 // Returns true if successful, false otherwise
97494971
VS
151 bool HistoryBack();
152 bool HistoryForward();
153 bool HistoryCanBack();
154 bool HistoryCanForward();
155 // Resets history
156 void HistoryClear();
157
158 // Returns pointer to conteiners/cells structure.
159 // It should be used ONLY when printing
160 wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
161
162 // Adds input filter
163 static void AddFilter(wxHtmlFilter *filter);
164
6cc4e6b8
VS
165 // Returns a pointer to the parser.
166 wxHtmlWinParser *GetParser() const { return m_Parser; }
167
168 // Adds HTML processor to this instance of wxHtmlWindow:
169 void AddProcessor(wxHtmlProcessor *processor);
170 // Adds HTML processor to wxHtmlWindow class as whole:
171 static void AddGlobalProcessor(wxHtmlProcessor *processor);
172
97e490f8 173
6cc4e6b8
VS
174 // -- Callbacks --
175
176 // Sets the title of the window
177 // (depending on the information passed to SetRelatedFrame() method)
178 virtual void OnSetTitle(const wxString& title);
179
f6010d8f 180 // Called when the mouse hovers over a cell: (x, y) are logical coords
f6010d8f
VZ
181 // Default behaviour is to do nothing at all
182 virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
183
184 // Called when user clicks on a cell. Default behavior is to call
185 // OnLinkClicked() if this cell corresponds to a hypertext link
186 virtual void OnCellClicked(wxHtmlCell *cell,
187 wxCoord x, wxCoord y,
188 const wxMouseEvent& event);
189
190 // Called when user clicked on hypertext link. Default behavior is to
97494971
VS
191 // call LoadPage(loc)
192 virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
574c939e
KB
193
194 // Called when wxHtmlWindow wants to fetch data from an URL (e.g. when
195 // loading a page or loading an image). The data are downloaded if and only if
6953da00 196 // OnOpeningURL returns true. If OnOpeningURL returns wxHTML_REDIRECT,
6cc4e6b8 197 // it must set *redirect to the new URL
574c939e
KB
198 virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
199 const wxString& WXUNUSED(url),
200 wxString *WXUNUSED(redirect)) const
6cc4e6b8 201 { return wxHTML_OPEN; }
6953da00 202
15622068
VZ
203#if wxUSE_CLIPBOARD
204 // Helper functions to select parts of page:
205 void SelectWord(const wxPoint& pos);
206 void SelectLine(const wxPoint& pos);
207 void SelectAll();
6953da00 208
5d3f80be
VS
209 // Convert selection to text:
210 wxString SelectionToText() { return DoSelectionToText(m_selection); }
211
212 // Converts current page to text:
213 wxString ToText();
97e490f8 214#endif // wxUSE_CLIPBOARD
6953da00 215
97494971 216protected:
4f417130
VS
217 void Init();
218
97494971
VS
219 // Scrolls to anchor of this name. (Anchor is #news
220 // or #features etc. it is part of address sometimes:
221 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
6953da00 222 // Return value : true if anchor exists, false otherwise
97494971
VS
223 bool ScrollToAnchor(const wxString& anchor);
224
bfb9ee96 225 // Prepares layout (= fill m_PosX, m_PosY for fragments) based on
97494971
VS
226 // actual size of window. This method also setup scrollbars
227 void CreateLayout();
228
1338c59a
VS
229 void OnEraseBackground(wxEraseEvent& event);
230 void OnPaint(wxPaintEvent& event);
97494971 231 void OnSize(wxSizeEvent& event);
31d8b4ad 232 void OnMouseMove(wxMouseEvent& event);
adf2eb2d
VS
233 void OnMouseDown(wxMouseEvent& event);
234 void OnMouseUp(wxMouseEvent& event);
61233023
VS
235#if wxUSE_CLIPBOARD
236 void OnKeyUp(wxKeyEvent& event);
31eefb99 237 void OnDoubleClick(wxMouseEvent& event);
61233023 238 void OnCopy(wxCommandEvent& event);
1338c59a
VS
239 void OnMouseEnter(wxMouseEvent& event);
240 void OnMouseLeave(wxMouseEvent& event);
d659d703 241#endif // wxUSE_CLIPBOARD
97494971 242
5180055b
JS
243 virtual void OnInternalIdle();
244
97494971
VS
245 // Returns new filter (will be stored into m_DefaultFilter variable)
246 virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
247
892aeafc 248 // cleans static variables
97494971 249 static void CleanUpStatics();
97494971 250
f65a786f
VS
251 // Returns true if text selection is enabled (wxClipboard must be available
252 // and wxHW_NO_SELECTION not used)
253 bool IsSelectionEnabled() const;
254
61233023
VS
255 enum ClipboardType
256 {
257 Primary,
258 Secondary
259 };
d659d703
VZ
260
261 // Copies selection to clipboard if the clipboard support is available
4bdce112
VZ
262 //
263 // returns true if anything was copied to clipboard, false otherwise
5de65c69 264 bool CopySelection(ClipboardType t = Secondary);
0994d968 265
d659d703 266#if wxUSE_CLIPBOARD
0994d968 267 // Automatic scrolling during selection:
1338c59a 268 void StopAutoScrolling();
d659d703 269#endif // wxUSE_CLIPBOARD
61233023 270
97494971 271protected:
977b867e 272 wxString DoSelectionToText(wxHtmlSelection *sel);
6953da00 273
1338c59a
VS
274 // This is pointer to the first cell in parsed data. (Note: the first cell
275 // is usually top one = all other cells are sub-cells of this one)
97494971 276 wxHtmlContainerCell *m_Cell;
892aeafc
VS
277 // parser which is used to parse HTML input.
278 // Each wxHtmlWindow has it's own parser because sharing one global
279 // parser would be problematic (because of reentrancy)
97494971 280 wxHtmlWinParser *m_Parser;
892aeafc 281 // contains name of actualy opened page or empty string if no page opened
97494971 282 wxString m_OpenedPage;
892aeafc 283 // contains name of current anchor within m_OpenedPage
97494971 284 wxString m_OpenedAnchor;
892aeafc 285 // contains title of actualy opened page or empty string if no <TITLE> tag
97494971 286 wxString m_OpenedPageTitle;
892aeafc 287 // class for opening files (file system)
97494971 288 wxFileSystem* m_FS;
97494971
VS
289
290 wxFrame *m_RelatedFrame;
291 wxString m_TitleFormat;
67a99992 292#if wxUSE_STATUSBAR
892aeafc
VS
293 // frame in which page title should be displayed & number of it's statusbar
294 // reserved for usage with this html window
97494971 295 int m_RelatedStatusBar;
67a99992 296#endif // wxUSE_STATUSBAR
97494971 297
892aeafc
VS
298 // borders (free space between text and window borders)
299 // defaults to 10 pixels.
97494971 300 int m_Borders;
97494971
VS
301
302 int m_Style;
303
adf2eb2d
VS
304 // current text selection or NULL
305 wxHtmlSelection *m_selection;
306
307 // true if the user is dragging mouse to select text
308 bool m_makingSelection;
309
1338c59a 310#if wxUSE_CLIPBOARD
0994d968
VS
311 // time of the last doubleclick event, used to detect tripleclicks
312 // (tripleclicks are used to select whole line):
313 wxLongLong m_lastDoubleClick;
314
315 // helper class to automatically scroll the window if the user is selecting
316 // text and the mouse leaves wxHtmlWindow:
1338c59a 317 wxHtmlWinAutoScrollTimer *m_timerAutoScroll;
d659d703 318#endif // wxUSE_CLIPBOARD
1338c59a 319
97494971 320private:
1338c59a
VS
321 // window content for double buffered rendering:
322 wxBitmap *m_backBuffer;
d659d703 323
97e490f8
VZ
324 // background image, may be invalid
325 wxBitmap m_bmpBg;
326
adf2eb2d
VS
327 // variables used when user is selecting text
328 wxPoint m_tmpSelFromPos;
329 wxHtmlCell *m_tmpSelFromCell;
d659d703 330
892aeafc 331 // contains last link name
97494971 332 wxHtmlLinkInfo *m_tmpLastLink;
f6010d8f
VZ
333 // contains the last (terminal) cell which contained the mouse
334 wxHtmlCell *m_tmpLastCell;
892aeafc
VS
335 // if >0 contents of the window is not redrawn
336 // (in order to avoid ugly blinking)
97494971 337 int m_tmpCanDrawLocks;
97494971 338
892aeafc 339 // list of HTML filters
97494971 340 static wxList m_Filters;
892aeafc 341 // this filter is used when no filter is able to read some file
97494971 342 static wxHtmlFilter *m_DefaultFilter;
97494971 343
518ba663
VZ
344 // html processors array:
345 wxHtmlProcessorList *m_Processors;
346 static wxHtmlProcessorList *m_GlobalProcessors;
347
892aeafc 348 // browser history
518ba663 349 wxHtmlHistoryArray *m_History;
97494971 350 int m_HistoryPos;
892aeafc 351 // if this FLAG is false, items are not added to history
97494971 352 bool m_HistoryOn;
bfb9ee96 353
518ba663
VZ
354 // a flag indicated if mouse moved
355 // (if true we will try to change cursor in last call to OnIdle)
356 bool m_tmpMouseMoved;
357
358 // a flag set if we need to erase background in OnPaint() (otherwise this
359 // is supposed to have been done in OnEraseBackground())
360 bool m_eraseBgInOnPaint;
5526e819 361
69941f05 362 DECLARE_EVENT_TABLE()
22f3361e 363 DECLARE_NO_COPY_CLASS(wxHtmlWindow)
69941f05 364};
5526e819
VS
365
366
d659d703 367#endif // wxUSE_HTML
69941f05
VS
368
369#endif // _WX_HTMLWIN_H_
19193a2c 370