]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
69941f05 | 2 | // Name: 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 | |
6acba9a7 VS |
22 | class WXDLLIMPEXP_HTML wxHtmlWindow; |
23 | class WXDLLIMPEXP_HTML wxHtmlWinParser; | |
24 | class WXDLLIMPEXP_HTML wxHtmlWinTagHandler; | |
25 | class WXDLLIMPEXP_HTML wxHtmlTagsModule; | |
5526e819 VS |
26 | |
27 | //-------------------------------------------------------------------------------- | |
28 | // wxHtmlWinParser | |
29 | // This class is derived from wxHtmlParser and its mail goal | |
30 | // is to parse HTML input so that it can be displayed in | |
31 | // wxHtmlWindow. It uses special wxHtmlWinTagHandler. | |
32 | //-------------------------------------------------------------------------------- | |
33 | ||
6acba9a7 | 34 | class WXDLLIMPEXP_HTML wxHtmlWinParser : public wxHtmlParser |
5526e819 | 35 | { |
4f44ea36 | 36 | DECLARE_ABSTRACT_CLASS(wxHtmlWinParser) |
5526e819 VS |
37 | friend class wxHtmlWindow; |
38 | ||
97494971 | 39 | public: |
04db5c3f | 40 | wxHtmlWinParser(wxHtmlWindow *wnd = NULL); |
97494971 VS |
41 | ~wxHtmlWinParser(); |
42 | ||
43 | virtual void InitParser(const wxString& source); | |
44 | virtual void DoneParser(); | |
45 | virtual wxObject* GetProduct(); | |
46 | ||
6cc4e6b8 | 47 | virtual wxFSFile *OpenURL(wxHtmlURLType type, const wxString& url) const; |
04db5c3f | 48 | |
97494971 VS |
49 | // Set's the DC used for parsing. If SetDC() is not called, |
50 | // parsing won't proceed | |
19193a2c | 51 | virtual void SetDC(wxDC *dc, double pixel_scale = 1.0) |
97494971 VS |
52 | { m_DC = dc; m_PixelScale = pixel_scale; } |
53 | ||
54 | wxDC *GetDC() {return m_DC;} | |
55 | double GetPixelScale() {return m_PixelScale;} | |
56 | int GetCharHeight() const {return m_CharHeight;} | |
57 | int GetCharWidth() const {return m_CharWidth;} | |
58 | ||
59 | // NOTE : these functions do _not_ return _actual_ | |
60 | // height/width. They return h/w of default font | |
61 | // for this DC. If you want actual values, call | |
62 | // GetDC()->GetChar...() | |
19193a2c | 63 | |
97494971 | 64 | // returns associated wxWindow |
04db5c3f | 65 | wxHtmlWindow *GetWindow() {return m_Window;} |
97494971 | 66 | |
4eecf115 | 67 | // Sets fonts to be used when displaying HTML page. (if size null then default sizes used). |
fbfb8bcc | 68 | void SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes = NULL); |
19193a2c | 69 | |
10e5c7ea VS |
70 | // Sets font sizes to be relative to the given size or the system |
71 | // default size; use either specified or default font | |
72 | void SetStandardFonts(int size = -1, | |
73 | const wxString& normal_face = wxEmptyString, | |
74 | const wxString& fixed_face = wxEmptyString); | |
6953da00 | 75 | |
97494971 VS |
76 | // Adds tags module. see wxHtmlTagsModule for details. |
77 | static void AddModule(wxHtmlTagsModule *module); | |
78 | ||
79 | static void RemoveModule(wxHtmlTagsModule *module); | |
80 | ||
81 | // parsing-related methods. These methods are called by tag handlers: | |
82 | ||
83 | // Returns pointer to actual container. Common use in tag handler is : | |
84 | // m_WParser->GetContainer()->InsertCell(new ...); | |
85 | wxHtmlContainerCell *GetContainer() const {return m_Container;} | |
86 | ||
87 | // opens new container. This container is sub-container of opened | |
88 | // container. Sets GetContainer to newly created container | |
89 | // and returns it. | |
90 | wxHtmlContainerCell *OpenContainer(); | |
91 | ||
92 | // works like OpenContainer except that new container is not created | |
93 | // but c is used. You can use this to directly set actual container | |
94 | wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); | |
95 | ||
96 | // closes the container and sets actual Container to upper-level | |
97 | // container | |
98 | wxHtmlContainerCell *CloseContainer(); | |
99 | ||
100 | int GetFontSize() const {return m_FontSize;} | |
101 | void SetFontSize(int s); | |
102 | int GetFontBold() const {return m_FontBold;} | |
103 | void SetFontBold(int x) {m_FontBold = x;} | |
104 | int GetFontItalic() const {return m_FontItalic;} | |
105 | void SetFontItalic(int x) {m_FontItalic = x;} | |
106 | int GetFontUnderlined() const {return m_FontUnderlined;} | |
107 | void SetFontUnderlined(int x) {m_FontUnderlined = x;} | |
108 | int GetFontFixed() const {return m_FontFixed;} | |
109 | void SetFontFixed(int x) {m_FontFixed = x;} | |
110 | wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;} | |
111 | void SetFontFace(const wxString& face); | |
112 | ||
113 | int GetAlign() const {return m_Align;} | |
114 | void SetAlign(int a) {m_Align = a;} | |
3c115835 VS |
115 | |
116 | wxHtmlScriptMode GetScriptMode() const { return m_ScriptMode; } | |
117 | void SetScriptMode(wxHtmlScriptMode mode) { m_ScriptMode = mode; } | |
118 | long GetScriptBaseline() const { return m_ScriptBaseline; } | |
119 | void SetScriptBaseline(long base) { m_ScriptBaseline = base; } | |
120 | ||
97494971 VS |
121 | const wxColour& GetLinkColor() const { return m_LinkColor; } |
122 | void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; } | |
123 | const wxColour& GetActualColor() const { return m_ActualColor; } | |
124 | void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;} | |
125 | const wxHtmlLinkInfo& GetLink() const { return m_Link; } | |
126 | void SetLink(const wxHtmlLinkInfo& link); | |
127 | ||
3c115835 VS |
128 | // applies current parser state (link, sub/supscript, ...) to given cell |
129 | void ApplyStateToCell(wxHtmlCell *cell); | |
130 | ||
2b5f62a0 | 131 | #if !wxUSE_UNICODE |
97494971 VS |
132 | void SetInputEncoding(wxFontEncoding enc); |
133 | wxFontEncoding GetInputEncoding() const { return m_InputEnc; } | |
134 | wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; } | |
135 | wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; } | |
2b5f62a0 | 136 | #endif |
97494971 VS |
137 | |
138 | // creates font depending on m_Font* members. | |
139 | virtual wxFont* CreateCurrentFont(); | |
140 | ||
141 | protected: | |
6c62a62b | 142 | virtual void AddText(const wxChar* txt); |
97494971 VS |
143 | |
144 | private: | |
97eac136 VS |
145 | void DoAddText(wxChar *temp, int& templen, wxChar nbsp); |
146 | ||
97494971 | 147 | bool m_tmpLastWasSpace; |
6c62a62b VS |
148 | wxChar *m_tmpStrBuf; |
149 | size_t m_tmpStrBufSize; | |
150 | // temporary variables used by AddText | |
04db5c3f | 151 | wxHtmlWindow *m_Window; |
97494971 VS |
152 | // window we're parsing for |
153 | double m_PixelScale; | |
154 | wxDC *m_DC; | |
155 | // Device Context we're parsing for | |
156 | static wxList m_Modules; | |
157 | // list of tags modules (see wxHtmlTagsModule for details) | |
158 | // This list is used to initialize m_Handlers member. | |
159 | ||
160 | wxHtmlContainerCell *m_Container; | |
ace0fab4 | 161 | // current container. See Open/CloseContainer for details. |
97494971 | 162 | |
6953da00 | 163 | int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not true,false but 1,0, we need it for indexing |
97494971 VS |
164 | int m_FontSize; /* -2 to +4, 0 is default */ |
165 | wxColour m_LinkColor; | |
166 | wxColour m_ActualColor; | |
167 | // basic font parameters. | |
168 | wxHtmlLinkInfo m_Link; | |
169 | // actual hypertext link or empty string | |
170 | bool m_UseLink; | |
6953da00 | 171 | // true if m_Link is not empty |
97494971 VS |
172 | long m_CharHeight, m_CharWidth; |
173 | // average height of normal-sized text | |
174 | int m_Align; | |
175 | // actual alignment | |
3c115835 VS |
176 | wxHtmlScriptMode m_ScriptMode; |
177 | // current script mode (sub/sup/normal) | |
178 | long m_ScriptBaseline; | |
179 | // current sub/supscript base | |
97494971 VS |
180 | |
181 | wxFont* m_FontsTable[2][2][2][2][7]; | |
182 | wxString m_FontsFacesTable[2][2][2][2][7]; | |
2b5f62a0 | 183 | #if !wxUSE_UNICODE |
97494971 | 184 | wxFontEncoding m_FontsEncTable[2][2][2][2][7]; |
2b5f62a0 | 185 | #endif |
97494971 VS |
186 | // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off |
187 | // state of these flags (from left to right): | |
188 | // [bold][italic][underlined][fixed_size] | |
189 | // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7) | |
190 | // Note : this table covers all possible combinations of fonts, but not | |
191 | // all of them are used, so many items in table are usually NULL. | |
192 | int m_FontsSizes[7]; | |
193 | wxString m_FontFaceFixed, m_FontFaceNormal; | |
194 | // html font sizes and faces of fixed and proportional fonts | |
195 | ||
2b5f62a0 | 196 | #if !wxUSE_UNICODE |
97494971 VS |
197 | wxFontEncoding m_InputEnc, m_OutputEnc; |
198 | // I/O font encodings | |
199 | wxEncodingConverter *m_EncConv; | |
2b5f62a0 | 200 | #endif |
8ba2f3ec VS |
201 | |
202 | wxHtmlWordCell *m_lastWordCell; | |
6953da00 | 203 | |
8ba2f3ec | 204 | DECLARE_NO_COPY_CLASS(wxHtmlWinParser) |
5526e819 VS |
205 | }; |
206 | ||
207 | ||
208 | ||
209 | ||
210 | ||
211 | ||
8ba2f3ec | 212 | //----------------------------------------------------------------------------- |
5526e819 VS |
213 | // wxHtmlWinTagHandler |
214 | // This is basicly wxHtmlTagHandler except | |
215 | // it is extended with protected member m_Parser pointing to | |
216 | // the wxHtmlWinParser object | |
8ba2f3ec | 217 | //----------------------------------------------------------------------------- |
5526e819 | 218 | |
6acba9a7 | 219 | class WXDLLIMPEXP_HTML wxHtmlWinTagHandler : public wxHtmlTagHandler |
5526e819 VS |
220 | { |
221 | DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler) | |
222 | ||
97494971 | 223 | public: |
6fb99eb3 | 224 | wxHtmlWinTagHandler() : wxHtmlTagHandler() {} |
6e31e940 | 225 | |
97494971 | 226 | virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;}; |
69941f05 | 227 | |
97494971 VS |
228 | protected: |
229 | wxHtmlWinParser *m_WParser; // same as m_Parser, but overcasted | |
22f3361e VZ |
230 | |
231 | DECLARE_NO_COPY_CLASS(wxHtmlWinTagHandler) | |
5526e819 VS |
232 | }; |
233 | ||
234 | ||
235 | ||
236 | ||
237 | ||
238 | ||
8ba2f3ec | 239 | //---------------------------------------------------------------------------- |
5526e819 VS |
240 | // wxHtmlTagsModule |
241 | // This is basic of dynamic tag handlers binding. | |
242 | // The class provides methods for filling parser's handlers | |
243 | // hash table. | |
244 | // (See documentation for details) | |
8ba2f3ec | 245 | //---------------------------------------------------------------------------- |
5526e819 | 246 | |
6acba9a7 | 247 | class WXDLLIMPEXP_HTML wxHtmlTagsModule : public wxModule |
5526e819 VS |
248 | { |
249 | DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule) | |
250 | ||
97494971 | 251 | public: |
6fb99eb3 | 252 | wxHtmlTagsModule() : wxModule() {} |
5526e819 | 253 | |
97494971 VS |
254 | virtual bool OnInit(); |
255 | virtual void OnExit(); | |
5526e819 | 256 | |
97494971 | 257 | // This is called by wxHtmlWinParser. |
8ba2f3ec VS |
258 | // The method must simply call parser->AddTagHandler(new |
259 | // <handler_class_name>); for each handler | |
97494971 | 260 | virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { } |
5526e819 VS |
261 | }; |
262 | ||
263 | ||
69941f05 | 264 | #endif |
5526e819 | 265 | |
69941f05 | 266 | #endif // _WX_WINPARS_H_ |