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