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