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