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