]> git.saurik.com Git - wxWidgets.git/blame - include/wx/html/htmlwin.h
Applied patch [ 736322 ] Remove TWINE support, merge it in Wine.
[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
40
41// enums for wxHtmlWindow::OnOpeningURL
42enum wxHtmlOpeningStatus
43{
44 wxHTML_OPEN,
45 wxHTML_BLOCK,
46 wxHTML_REDIRECT
47};
48
5526e819
VS
49//--------------------------------------------------------------------------------
50// wxHtmlWindow
3ef01ce5 51// (This is probably the only class you will directly use.)
5526e819
VS
52// Purpose of this class is to display HTML page (either local
53// file or downloaded via HTTP protocol) in a window. Width
54// of window is constant - given in constructor - virtual height
55// is changed dynamicly depending on page size.
56// Once the window is created you can set it's content by calling
3ef01ce5 57// SetPage(text) or LoadPage(filename).
5526e819
VS
58//--------------------------------------------------------------------------------
59
5526e819
VS
60class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow
61{
62 DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
66806a0b 63 friend class wxHtmlWinModule;
5526e819 64
97494971 65public:
4f417130 66 wxHtmlWindow() { Init(); }
97494971 67 wxHtmlWindow(wxWindow *parent, wxWindowID id = -1,
bfb9ee96 68 const wxPoint& pos = wxDefaultPosition,
97494971
VS
69 const wxSize& size = wxDefaultSize,
70 long style = wxHW_SCROLLBAR_AUTO,
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
4f417130
VS
78 bool Create(wxWindow *parent, wxWindowID id = -1,
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
87 // Return value : FALSE if an error occured, TRUE otherwise
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
119 // After(!) calling SetRelatedFrame, this sets statusbar slot where messages
120 // will be displayed. Default is -1 = no messages.
121 void SetRelatedStatusBar(int bar);
122
123 // Sets fonts to be used when displaying HTML page.
4eecf115
VS
124 void SetFonts(wxString normal_face, wxString fixed_face,
125 const int *sizes = NULL);
97494971 126
97494971
VS
127 // Sets space between text and window borders.
128 void SetBorders(int b) {m_Borders = b;}
129
130 // Saves custom settings into cfg config. it will use the path 'path'
131 // if given, otherwise it will save info into currently selected path.
132 // saved values : things set by SetFonts, SetBorders.
133 virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
134 // ...
135 virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
136
137 // Goes to previous/next page (in browsing history)
138 // Returns TRUE if successful, FALSE otherwise
139 bool HistoryBack();
140 bool HistoryForward();
141 bool HistoryCanBack();
142 bool HistoryCanForward();
143 // Resets history
144 void HistoryClear();
145
146 // Returns pointer to conteiners/cells structure.
147 // It should be used ONLY when printing
148 wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
149
150 // Adds input filter
151 static void AddFilter(wxHtmlFilter *filter);
152
6cc4e6b8
VS
153 // Returns a pointer to the parser.
154 wxHtmlWinParser *GetParser() const { return m_Parser; }
155
156 // Adds HTML processor to this instance of wxHtmlWindow:
157 void AddProcessor(wxHtmlProcessor *processor);
158 // Adds HTML processor to wxHtmlWindow class as whole:
159 static void AddGlobalProcessor(wxHtmlProcessor *processor);
160
161 // what would we do with it?
162 virtual bool AcceptsFocusFromKeyboard() const { return FALSE; }
163
164 // -- Callbacks --
165
166 // Sets the title of the window
167 // (depending on the information passed to SetRelatedFrame() method)
168 virtual void OnSetTitle(const wxString& title);
169
f6010d8f 170 // Called when the mouse hovers over a cell: (x, y) are logical coords
f6010d8f
VZ
171 // Default behaviour is to do nothing at all
172 virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
173
174 // Called when user clicks on a cell. Default behavior is to call
175 // OnLinkClicked() if this cell corresponds to a hypertext link
176 virtual void OnCellClicked(wxHtmlCell *cell,
177 wxCoord x, wxCoord y,
178 const wxMouseEvent& event);
179
180 // Called when user clicked on hypertext link. Default behavior is to
97494971
VS
181 // call LoadPage(loc)
182 virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
574c939e
KB
183
184 // Called when wxHtmlWindow wants to fetch data from an URL (e.g. when
185 // loading a page or loading an image). The data are downloaded if and only if
6cc4e6b8
VS
186 // OnOpeningURL returns TRUE. If OnOpeningURL returns wxHTML_REDIRECT,
187 // it must set *redirect to the new URL
574c939e
KB
188 virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
189 const wxString& WXUNUSED(url),
190 wxString *WXUNUSED(redirect)) const
6cc4e6b8 191 { return wxHTML_OPEN; }
42f96a88 192
97494971 193protected:
4f417130
VS
194 void Init();
195
97494971
VS
196 // Scrolls to anchor of this name. (Anchor is #news
197 // or #features etc. it is part of address sometimes:
198 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
199 // Return value : TRUE if anchor exists, FALSE otherwise
200 bool ScrollToAnchor(const wxString& anchor);
201
bfb9ee96 202 // Prepares layout (= fill m_PosX, m_PosY for fragments) based on
97494971
VS
203 // actual size of window. This method also setup scrollbars
204 void CreateLayout();
205
206 void OnDraw(wxDC& dc);
207 void OnSize(wxSizeEvent& event);
208 void OnMouseEvent(wxMouseEvent& event);
209 void OnIdle(wxIdleEvent& event);
210
211 // Returns new filter (will be stored into m_DefaultFilter variable)
212 virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
213
892aeafc 214 // cleans static variables
97494971 215 static void CleanUpStatics();
97494971
VS
216
217protected:
892aeafc
VS
218 // This is pointer to the first cell in parsed data.
219 // (Note: the first cell is usually top one = all other cells are sub-cells of this one)
97494971 220 wxHtmlContainerCell *m_Cell;
892aeafc
VS
221 // parser which is used to parse HTML input.
222 // Each wxHtmlWindow has it's own parser because sharing one global
223 // parser would be problematic (because of reentrancy)
97494971 224 wxHtmlWinParser *m_Parser;
892aeafc 225 // contains name of actualy opened page or empty string if no page opened
97494971 226 wxString m_OpenedPage;
892aeafc 227 // contains name of current anchor within m_OpenedPage
97494971 228 wxString m_OpenedAnchor;
892aeafc 229 // contains title of actualy opened page or empty string if no <TITLE> tag
97494971 230 wxString m_OpenedPageTitle;
892aeafc 231 // class for opening files (file system)
97494971 232 wxFileSystem* m_FS;
97494971
VS
233
234 wxFrame *m_RelatedFrame;
235 wxString m_TitleFormat;
892aeafc
VS
236 // frame in which page title should be displayed & number of it's statusbar
237 // reserved for usage with this html window
97494971 238 int m_RelatedStatusBar;
97494971 239
892aeafc
VS
240 // borders (free space between text and window borders)
241 // defaults to 10 pixels.
97494971 242 int m_Borders;
97494971
VS
243
244 int m_Style;
245
246private:
892aeafc
VS
247 // a flag indicated if mouse moved
248 // (if TRUE we will try to change cursor in last call to OnIdle)
97494971 249 bool m_tmpMouseMoved;
892aeafc 250 // contains last link name
97494971 251 wxHtmlLinkInfo *m_tmpLastLink;
f6010d8f
VZ
252 // contains the last (terminal) cell which contained the mouse
253 wxHtmlCell *m_tmpLastCell;
892aeafc
VS
254 // if >0 contents of the window is not redrawn
255 // (in order to avoid ugly blinking)
97494971 256 int m_tmpCanDrawLocks;
97494971 257
892aeafc 258 // list of HTML filters
97494971 259 static wxList m_Filters;
892aeafc 260 // this filter is used when no filter is able to read some file
97494971 261 static wxHtmlFilter *m_DefaultFilter;
97494971
VS
262
263 static wxCursor *s_cur_hand;
264 static wxCursor *s_cur_arrow;
265
892aeafc
VS
266 wxHtmlHistoryArray *m_History;
267 // browser history
97494971 268 int m_HistoryPos;
892aeafc 269 // if this FLAG is false, items are not added to history
97494971 270 bool m_HistoryOn;
bfb9ee96 271
892aeafc
VS
272 // html processors array:
273 wxHtmlProcessorList *m_Processors;
42f96a88 274 static wxHtmlProcessorList *m_GlobalProcessors;
5526e819 275
69941f05 276 DECLARE_EVENT_TABLE()
22f3361e 277 DECLARE_NO_COPY_CLASS(wxHtmlWindow)
69941f05 278};
5526e819
VS
279
280
69941f05
VS
281#endif
282
283#endif // _WX_HTMLWIN_H_
19193a2c 284