]> git.saurik.com Git - wxWidgets.git/blob - include/wx/html/htmlwin.h
added wxDynamicLibrary::Detach()
[wxWidgets.git] / include / wx / html / htmlwin.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: htmlwin.h
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifndef _WX_HTMLWIN_H_
12 #define _WX_HTMLWIN_H_
13
14 #if defined(__GNUG__) && !defined(__APPLE__)
15 #pragma interface "htmlwin.h"
16 #endif
17
18 #include "wx/defs.h"
19 #if wxUSE_HTML
20
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"
29 #include "wx/filename.h"
30
31 class wxHtmlProcessor;
32 class wxHtmlWinModule;
33 class wxHtmlHistoryArray;
34 class wxHtmlProcessorList;
35
36
37 // wxHtmlWindow flags:
38 #define wxHW_SCROLLBAR_NEVER 0x0002
39 #define wxHW_SCROLLBAR_AUTO 0x0004
40
41 // enums for wxHtmlWindow::OnOpeningURL
42 enum wxHtmlOpeningStatus
43 {
44 wxHTML_OPEN,
45 wxHTML_BLOCK,
46 wxHTML_REDIRECT
47 };
48
49 //--------------------------------------------------------------------------------
50 // wxHtmlWindow
51 // (This is probably the only class you will directly use.)
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
57 // SetPage(text) or LoadPage(filename).
58 //--------------------------------------------------------------------------------
59
60 class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow
61 {
62 DECLARE_DYNAMIC_CLASS(wxHtmlWindow)
63 friend class wxHtmlWinModule;
64
65 public:
66 wxHtmlWindow() { Init(); }
67 wxHtmlWindow(wxWindow *parent, wxWindowID id = -1,
68 const wxPoint& pos = wxDefaultPosition,
69 const wxSize& size = wxDefaultSize,
70 long style = wxHW_SCROLLBAR_AUTO,
71 const wxString& name = wxT("htmlWindow"))
72 {
73 Init();
74 Create(parent, id, pos, size, style, name);
75 }
76 ~wxHtmlWindow();
77
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
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);
89
90 // Append to current page
91 bool AppendToPage(const wxString& source);
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
102 virtual bool LoadPage(const wxString& location);
103
104 // Loads HTML page from file
105 bool LoadFile(const wxFileName& filename);
106
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.
124 void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes);
125
126 // Sets space between text and window borders.
127 void SetBorders(int b) {m_Borders = b;}
128
129 // Saves custom settings into cfg config. it will use the path 'path'
130 // if given, otherwise it will save info into currently selected path.
131 // saved values : things set by SetFonts, SetBorders.
132 virtual void ReadCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
133 // ...
134 virtual void WriteCustomization(wxConfigBase *cfg, wxString path = wxEmptyString);
135
136 // Goes to previous/next page (in browsing history)
137 // Returns TRUE if successful, FALSE otherwise
138 bool HistoryBack();
139 bool HistoryForward();
140 bool HistoryCanBack();
141 bool HistoryCanForward();
142 // Resets history
143 void HistoryClear();
144
145 // Returns pointer to conteiners/cells structure.
146 // It should be used ONLY when printing
147 wxHtmlContainerCell* GetInternalRepresentation() const {return m_Cell;}
148
149 // Adds input filter
150 static void AddFilter(wxHtmlFilter *filter);
151
152 // Returns a pointer to the parser.
153 wxHtmlWinParser *GetParser() const { return m_Parser; }
154
155 // Adds HTML processor to this instance of wxHtmlWindow:
156 void AddProcessor(wxHtmlProcessor *processor);
157 // Adds HTML processor to wxHtmlWindow class as whole:
158 static void AddGlobalProcessor(wxHtmlProcessor *processor);
159
160 // what would we do with it?
161 virtual bool AcceptsFocusFromKeyboard() const { return FALSE; }
162
163 // -- Callbacks --
164
165 // Sets the title of the window
166 // (depending on the information passed to SetRelatedFrame() method)
167 virtual void OnSetTitle(const wxString& title);
168
169 // Called when the mouse hovers over a cell: (x, y) are logical coords
170 // Default behaviour is to do nothing at all
171 virtual void OnCellMouseHover(wxHtmlCell *cell, wxCoord x, wxCoord y);
172
173 // Called when user clicks on a cell. Default behavior is to call
174 // OnLinkClicked() if this cell corresponds to a hypertext link
175 virtual void OnCellClicked(wxHtmlCell *cell,
176 wxCoord x, wxCoord y,
177 const wxMouseEvent& event);
178
179 // Called when user clicked on hypertext link. Default behavior is to
180 // call LoadPage(loc)
181 virtual void OnLinkClicked(const wxHtmlLinkInfo& link);
182
183 // Called when wxHtmlWindow wants to fetch data from an URL (e.g. when
184 // loading a page or loading an image). The data are downloaded if and only if
185 // OnOpeningURL returns TRUE. If OnOpeningURL returns wxHTML_REDIRECT,
186 // it must set *redirect to the new URL
187 virtual wxHtmlOpeningStatus OnOpeningURL(wxHtmlURLType WXUNUSED(type),
188 const wxString& WXUNUSED(url),
189 wxString *WXUNUSED(redirect)) const
190 { return wxHTML_OPEN; }
191
192 protected:
193 void Init();
194
195 // Scrolls to anchor of this name. (Anchor is #news
196 // or #features etc. it is part of address sometimes:
197 // http://www.ms.mff.cuni.cz/~vsla8348/wxhtml/index.html#news)
198 // Return value : TRUE if anchor exists, FALSE otherwise
199 bool ScrollToAnchor(const wxString& anchor);
200
201 // Prepares layout (= fill m_PosX, m_PosY for fragments) based on
202 // actual size of window. This method also setup scrollbars
203 void CreateLayout();
204
205 void OnDraw(wxDC& dc);
206 void OnSize(wxSizeEvent& event);
207 void OnMouseEvent(wxMouseEvent& event);
208 void OnIdle(wxIdleEvent& event);
209
210 // Returns new filter (will be stored into m_DefaultFilter variable)
211 virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;}
212
213 // cleans static variables
214 static void CleanUpStatics();
215
216 protected:
217 // This is pointer to the first cell in parsed data.
218 // (Note: the first cell is usually top one = all other cells are sub-cells of this one)
219 wxHtmlContainerCell *m_Cell;
220 // parser which is used to parse HTML input.
221 // Each wxHtmlWindow has it's own parser because sharing one global
222 // parser would be problematic (because of reentrancy)
223 wxHtmlWinParser *m_Parser;
224 // contains name of actualy opened page or empty string if no page opened
225 wxString m_OpenedPage;
226 // contains name of current anchor within m_OpenedPage
227 wxString m_OpenedAnchor;
228 // contains title of actualy opened page or empty string if no <TITLE> tag
229 wxString m_OpenedPageTitle;
230 // class for opening files (file system)
231 wxFileSystem* m_FS;
232
233 wxFrame *m_RelatedFrame;
234 wxString m_TitleFormat;
235 // frame in which page title should be displayed & number of it's statusbar
236 // reserved for usage with this html window
237 int m_RelatedStatusBar;
238
239 // borders (free space between text and window borders)
240 // defaults to 10 pixels.
241 int m_Borders;
242
243 int m_Style;
244
245 private:
246 // a flag indicated if mouse moved
247 // (if TRUE we will try to change cursor in last call to OnIdle)
248 bool m_tmpMouseMoved;
249 // contains last link name
250 wxHtmlLinkInfo *m_tmpLastLink;
251 // contains the last (terminal) cell which contained the mouse
252 wxHtmlCell *m_tmpLastCell;
253 // if >0 contents of the window is not redrawn
254 // (in order to avoid ugly blinking)
255 int m_tmpCanDrawLocks;
256
257 // list of HTML filters
258 static wxList m_Filters;
259 // this filter is used when no filter is able to read some file
260 static wxHtmlFilter *m_DefaultFilter;
261
262 static wxCursor *s_cur_hand;
263 static wxCursor *s_cur_arrow;
264
265 wxHtmlHistoryArray *m_History;
266 // browser history
267 int m_HistoryPos;
268 // if this FLAG is false, items are not added to history
269 bool m_HistoryOn;
270
271 // html processors array:
272 wxHtmlProcessorList *m_Processors;
273 static wxHtmlProcessorList *m_GlobalProcessors;
274
275 DECLARE_EVENT_TABLE()
276 DECLARE_NO_COPY_CLASS(wxHtmlWindow)
277 };
278
279
280 #endif
281
282 #endif // _WX_HTMLWIN_H_
283