]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
80fdcdb9 | 2 | // Name: wx/html/winpars.h |
5526e819 VS |
3 | // Purpose: wxHtmlWinParser class (parser to be used with wxHtmlWindow) |
4 | // Author: Vaclav Slavik | |
5 | // Copyright: (c) 1999 Vaclav Slavik | |
65571936 | 6 | // Licence: wxWindows licence |
5526e819 VS |
7 | ///////////////////////////////////////////////////////////////////////////// |
8 | ||
69941f05 VS |
9 | #ifndef _WX_WINPARS_H_ |
10 | #define _WX_WINPARS_H_ | |
5526e819 | 11 | |
5526e819 VS |
12 | #include "wx/defs.h" |
13 | #if wxUSE_HTML | |
14 | ||
69941f05 | 15 | #include "wx/module.h" |
b250d384 | 16 | #include "wx/font.h" |
69941f05 VS |
17 | #include "wx/html/htmlpars.h" |
18 | #include "wx/html/htmlcell.h" | |
b250d384 | 19 | #include "wx/encconv.h" |
5526e819 | 20 | |
b5dbe15d VS |
21 | class WXDLLIMPEXP_FWD_HTML wxHtmlWindow; |
22 | class WXDLLIMPEXP_FWD_HTML wxHtmlWindowInterface; | |
23 | class WXDLLIMPEXP_FWD_HTML wxHtmlWinParser; | |
24 | class WXDLLIMPEXP_FWD_HTML wxHtmlWinTagHandler; | |
25 | class WXDLLIMPEXP_FWD_HTML wxHtmlTagsModule; | |
5526e819 | 26 | |
bc55e31b | 27 | |
5526e819 VS |
28 | //-------------------------------------------------------------------------------- |
29 | // wxHtmlWinParser | |
30 | // This class is derived from wxHtmlParser and its mail goal | |
31 | // is to parse HTML input so that it can be displayed in | |
32 | // wxHtmlWindow. It uses special wxHtmlWinTagHandler. | |
33 | //-------------------------------------------------------------------------------- | |
34 | ||
6acba9a7 | 35 | class WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser |
5526e819 | 36 | { |
4f44ea36 | 37 | DECLARE_ABSTRACT_CLASS(wxHtmlWinParser) |
5526e819 VS |
38 | friend class wxHtmlWindow; |
39 | ||
97494971 | 40 | public: |
bc55e31b VS |
41 | wxHtmlWinParser(wxHtmlWindowInterface *wndIface = NULL); |
42 | ||
d3c7fc99 | 43 | virtual ~wxHtmlWinParser(); |
97494971 VS |
44 | |
45 | virtual void InitParser(const wxString& source); | |
46 | virtual void DoneParser(); | |
47 | virtual wxObject* GetProduct(); | |
48 | ||
6cc4e6b8 | 49 | virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const; |
04db5c3f | 50 | |
97494971 VS |
51 | // Set's the DC used for parsing. If SetDC() is not called, |
52 | // parsing won't proceed | |
19193a2c | 53 | virtual void SetDC(wxDC *dc, double pixel_scale = 1.0) |
c44a49b8 VS |
54 | { SetDC(dc, pixel_scale, pixel_scale); } |
55 | void SetDC(wxDC *dc, double pixel_scale, double font_scale); | |
97494971 VS |
56 | |
57 | wxDC *GetDC() {return m_DC;} | |
58 | double GetPixelScale() {return m_PixelScale;} | |
59 | int GetCharHeight() const {return m_CharHeight;} | |
60 | int GetCharWidth() const {return m_CharWidth;} | |
61 | ||
62 | // NOTE : these functions do _not_ return _actual_ | |
63 | // height/width. They return h/w of default font | |
64 | // for this DC. If you want actual values, call | |
65 | // GetDC()->GetChar...() | |
19193a2c | 66 | |
968d6f46 | 67 | // returns interface to the rendering window |
bc55e31b VS |
68 | wxHtmlWindowInterface *GetWindowInterface() {return m_windowInterface;} |
69 | #if WXWIN_COMPATIBILITY_2_6 | |
968d6f46 | 70 | // deprecated, use GetWindowInterface()->GetHTMLWindow() instead |
bc55e31b VS |
71 | wxDEPRECATED( wxHtmlWindow *GetWindow() ); |
72 | #endif | |
97494971 | 73 | |
4eecf115 | 74 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
fbfb8bcc | 75 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL); |
19193a2c | 76 | |
10e5c7ea VS |
77 | // Sets font sizes to be relative to the given size or the system |
78 | // default size; use either specified or default font | |
79 | void SetStandardFonts(int size = -1, | |
80 | const wxString& normal_face = wxEmptyString, | |
81 | const wxString& fixed_face = wxEmptyString); | |
6953da00 | 82 | |
97494971 VS |
83 | // Adds tags module. see wxHtmlTagsModule for details. |
84 | static void AddModule(wxHtmlTagsModule *module); | |
85 | ||
86 | static void RemoveModule(wxHtmlTagsModule *module); | |
87 | ||
88 | // parsing-related methods. These methods are called by tag handlers: | |
89 | ||
90 | // Returns pointer to actual container. Common use in tag handler is : | |
91 | // m_WParser->GetContainer()->InsertCell(new ...); | |
92 | wxHtmlContainerCell *GetContainer() const {return m_Container;} | |
93 | ||
94 | // opens new container. This container is sub-container of opened | |
95 | // container. Sets GetContainer to newly created container | |
96 | // and returns it. | |
97 | wxHtmlContainerCell *OpenContainer(); | |
98 | ||
99 | // works like OpenContainer except that new container is not created | |
100 | // but c is used. You can use this to directly set actual container | |
101 | wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); | |
102 | ||
103 | // closes the container and sets actual Container to upper-level | |
104 | // container | |
105 | wxHtmlContainerCell *CloseContainer(); | |
106 | ||
107 | int GetFontSize() const {return m_FontSize;} | |
108 | void SetFontSize(int s); | |
f68e16c5 VZ |
109 | // Try to map a font size in points to the HTML 1-7 font size range. |
110 | void SetFontPointSize(int pt); | |
97494971 VS |
111 | int GetFontBold() const {return m_FontBold;} |
112 | void SetFontBold(int x) {m_FontBold = x;} | |
113 | int GetFontItalic() const {return m_FontItalic;} | |
114 | void SetFontItalic(int x) {m_FontItalic = x;} | |
115 | int GetFontUnderlined() const {return m_FontUnderlined;} | |
116 | void SetFontUnderlined(int x) {m_FontUnderlined = x;} | |
117 | int GetFontFixed() const {return m_FontFixed;} | |
118 | void SetFontFixed(int x) {m_FontFixed = x;} | |
119 | wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;} | |
120 | void SetFontFace(const wxString& face); | |
121 | ||
122 | int GetAlign() const {return m_Align;} | |
123 | void SetAlign(int a) {m_Align = a;} | |
3c115835 VS |
124 | |
125 | wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; } | |
126 | void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; } | |
127 | long GetScriptBaseline() const { return m_ScriptBaseline; } | |
128 | void SetScriptBaseline(long base) { m_ScriptBaseline = base; } | |
129 | ||
97494971 VS |
130 | const wxColour& GetLinkColor() const { return m_LinkColor; } |
131 | void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; } | |
132 | const wxColour& GetActualColor() const { return m_ActualColor; } | |
133 | void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;} | |
f5413b87 VZ |
134 | const wxColour& GetActualBackgroundColor() const { return m_ActualBackgroundColor; } |
135 | void SetActualBackgroundColor(const wxColour& clr) { m_ActualBackgroundColor = clr;} | |
136 | int GetActualBackgroundMode() const { return m_ActualBackgroundMode; } | |
137 | void SetActualBackgroundMode(int mode) { m_ActualBackgroundMode = mode;} | |
97494971 VS |
138 | const wxHtmlLinkInfo& GetLink() const { return m_Link; } |
139 | void SetLink(const wxHtmlLinkInfo& link); | |
140 | ||
3c115835 VS |
141 | // applies current parser state (link, sub/supscript, ...) to given cell |
142 | void ApplyStateToCell(wxHtmlCell *cell); | |
143 | ||
a0393f97 VZ |
144 | // Needs to be called after inserting a cell that interrupts the flow of |
145 | // the text like e.g. <img> and tells us to not consider any of the | |
146 | // following space as being part of the same space run as before. | |
147 | void StopCollapsingSpaces() { m_tmpLastWasSpace = false; } | |
148 | ||
2b5f62a0 | 149 | #if !wxUSE_UNICODE |
97494971 VS |
150 | void SetInputEncoding(wxFontEncoding enc); |
151 | wxFontEncoding GetInputEncoding() const { return m_InputEnc; } | |
152 | wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; } | |
153 | wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; } | |
2b5f62a0 | 154 | #endif |
97494971 VS |
155 | |
156 | // creates font depending on m_Font* members. | |
157 | virtual wxFont* CreateCurrentFont(); | |
158 | ||
6a603a10 VS |
159 | enum WhitespaceMode |
160 | { | |
161 | Whitespace_Normal, // normal mode, collapse whitespace | |
162 | Whitespace_Pre // inside <pre>, keep whitespace as-is | |
163 | }; | |
164 | ||
165 | // change the current whitespace handling mode | |
166 | void SetWhitespaceMode(WhitespaceMode mode) { m_whitespaceMode = mode; } | |
167 | WhitespaceMode GetWhitespaceMode() const { return m_whitespaceMode; } | |
168 | ||
97494971 | 169 | protected: |
5bce3e6f | 170 | virtual void AddText(const wxString& txt); |
97494971 VS |
171 | |
172 | private: | |
6a603a10 VS |
173 | void FlushWordBuf(wxChar *temp, int& len); |
174 | void AddWord(wxHtmlWordCell *word); | |
175 | void AddWord(const wxString& word) | |
176 | { AddWord(new wxHtmlWordCell(word, *(GetDC()))); } | |
177 | void AddPreBlock(const wxString& text); | |
97eac136 | 178 | |
97494971 | 179 | bool m_tmpLastWasSpace; |
6c62a62b VS |
180 | wxChar *m_tmpStrBuf; |
181 | size_t m_tmpStrBufSize; | |
182 | // temporary variables used by AddText | |
bc55e31b | 183 | wxHtmlWindowInterface *m_windowInterface; |
97494971 | 184 | // window we're parsing for |
c44a49b8 | 185 | double m_PixelScale, m_FontScale; |
97494971 VS |
186 | wxDC *m_DC; |
187 | // Device Context we're parsing for | |
188 | static wxList m_Modules; | |
189 | // list of tags modules (see wxHtmlTagsModule for details) | |
190 | // This list is used to initialize m_Handlers member. | |
191 | ||
192 | wxHtmlContainerCell *m_Container; | |
ace0fab4 | 193 | // current container. See Open/CloseContainer for details. |
97494971 | 194 | |
6953da00 | 195 | int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing |
0199dae3 | 196 | int m_FontSize; // From 1 (smallest) to 7, default is 3. |
97494971 VS |
197 | wxColour m_LinkColor; |
198 | wxColour m_ActualColor; | |
f5413b87 VZ |
199 | wxColour m_ActualBackgroundColor; |
200 | int m_ActualBackgroundMode; | |
97494971 VS |
201 | // basic font parameters. |
202 | wxHtmlLinkInfo m_Link; | |
203 | // actual hypertext link or empty string | |
204 | bool m_UseLink; | |
6953da00 | 205 | // true if m_Link is not empty |
17473a77 | 206 | int m_CharHeight, m_CharWidth; |
97494971 VS |
207 | // average height of normal-sized text |
208 | int m_Align; | |
209 | // actual alignment | |
3c115835 VS |
210 | wxHtmlScriptMode m_ScriptMode; |
211 | // current script mode (sub/sup/normal) | |
212 | long m_ScriptBaseline; | |
213 | // current sub/supscript base | |
97494971 VS |
214 | |
215 | wxFont* m_FontsTable[2][2][2][2][7]; | |
216 | wxString m_FontsFacesTable[2][2][2][2][7]; | |
2b5f62a0 | 217 | #if !wxUSE_UNICODE |
97494971 | 218 | wxFontEncoding m_FontsEncTable[2][2][2][2][7]; |
2b5f62a0 | 219 | #endif |
97494971 VS |
220 | // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off |
221 | // state of these flags (from left to right): | |
222 | // [bold][italic][underlined][fixed_size] | |
223 | // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7) | |
224 | // Note : this table covers all possible combinations of fonts, but not | |
225 | // all of them are used, so many items in table are usually NULL. | |
226 | int m_FontsSizes[7]; | |
227 | wxString m_FontFaceFixed, m_FontFaceNormal; | |
228 | // html font sizes and faces of fixed and proportional fonts | |
229 | ||
2b5f62a0 | 230 | #if !wxUSE_UNICODE |
c7820964 | 231 | wxChar m_nbsp; |
97494971 VS |
232 | wxFontEncoding m_InputEnc, m_OutputEnc; |
233 | // I/O font encodings | |
234 | wxEncodingConverter *m_EncConv; | |
2b5f62a0 | 235 | #endif |
8ba2f3ec | 236 | |
6a603a10 VS |
237 | // current whitespace handling mode |
238 | WhitespaceMode m_whitespaceMode; | |
239 | ||
8ba2f3ec | 240 | wxHtmlWordCell *m_lastWordCell; |
6953da00 | 241 | |
6a603a10 VS |
242 | // current position on line, in num. of characters; used to properly |
243 | // expand TABs; only updated while inside <pre> | |
244 | int m_posColumn; | |
245 | ||
c0c133e1 | 246 | wxDECLARE_NO_COPY_CLASS(wxHtmlWinParser); |
5526e819 VS |
247 | }; |
248 | ||
249 | ||
250 | ||
251 | ||
252 | ||
253 | ||
8ba2f3ec | 254 | //----------------------------------------------------------------------------- |
5526e819 VS |
255 | // wxHtmlWinTagHandler |
256 | // This is basicly wxHtmlTagHandler except | |
257 | // it is extended with protected member m_Parser pointing to | |
258 | // the wxHtmlWinParser object | |
8ba2f3ec | 259 | //----------------------------------------------------------------------------- |
5526e819 | 260 | |
754afd10 | 261 | class WXDLLIMPEXP_FWD_HTML wxHtmlStyleParams; |
0d7acfb9 | 262 | |
6acba9a7 | 263 | class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler |
5526e819 VS |
264 | { |
265 | DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler) | |
266 | ||
97494971 | 267 | public: |
6fb99eb3 | 268 | wxHtmlWinTagHandler() : wxHtmlTagHandler() {} |
6e31e940 | 269 | |
47b378bd | 270 | virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;} |
69941f05 | 271 | |
97494971 VS |
272 | protected: |
273 | wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted | |
22f3361e | 274 | |
0d7acfb9 VZ |
275 | void ApplyStyle(const wxHtmlStyleParams &styleParams); |
276 | ||
c0c133e1 | 277 | wxDECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler); |
5526e819 VS |
278 | }; |
279 | ||
280 | ||
281 | ||
282 | ||
283 | ||
284 | ||
8ba2f3ec | 285 | //---------------------------------------------------------------------------- |
5526e819 VS |
286 | // wxHtmlTagsModule |
287 | // This is basic of dynamic tag handlers binding. | |
288 | // The class provides methods for filling parser's handlers | |
289 | // hash table. | |
290 | // (See documentation for details) | |
8ba2f3ec | 291 | //---------------------------------------------------------------------------- |
5526e819 | 292 | |
6acba9a7 | 293 | class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule |
5526e819 VS |
294 | { |
295 | DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule) | |
296 | ||
97494971 | 297 | public: |
6fb99eb3 | 298 | wxHtmlTagsModule() : wxModule() {} |
5526e819 | 299 | |
97494971 VS |
300 | virtual bool OnInit(); |
301 | virtual void OnExit(); | |
5526e819 | 302 | |
97494971 | 303 | // This is called by wxHtmlWinParser. |
8ba2f3ec VS |
304 | // The method must simply call parser->AddTagHandler(new |
305 | // <handler_class_name>); for each handler | |
97494971 | 306 | virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { } |
5526e819 VS |
307 | }; |
308 | ||
309 | ||
69941f05 | 310 | #endif |
5526e819 | 311 | |
69941f05 | 312 | #endif // _WX_WINPARS_H_ |