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