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