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