]>
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 VS |
6 | // Copyright: (c) 1999 Vaclav Slavik |
7 | // Licence: wxWindows Licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | ||
69941f05 VS |
11 | #ifndef _WX_WINPARS_H_ |
12 | #define _WX_WINPARS_H_ | |
5526e819 VS |
13 | |
14 | #ifdef __GNUG__ | |
15 | #pragma interface | |
16 | #endif | |
17 | ||
18 | #include "wx/defs.h" | |
19 | #if wxUSE_HTML | |
20 | ||
69941f05 | 21 | #include "wx/module.h" |
b250d384 | 22 | #include "wx/font.h" |
69941f05 VS |
23 | #include "wx/html/htmlpars.h" |
24 | #include "wx/html/htmlcell.h" | |
b250d384 | 25 | #include "wx/encconv.h" |
5526e819 VS |
26 | |
27 | class wxHtmlWinParser; | |
28 | class wxHtmlWinTagHandler; | |
29 | class wxHtmlTagsModule; | |
30 | ||
31 | //-------------------------------------------------------------------------------- | |
32 | // wxHtmlWinParser | |
33 | // This class is derived from wxHtmlParser and its mail goal | |
34 | // is to parse HTML input so that it can be displayed in | |
35 | // wxHtmlWindow. It uses special wxHtmlWinTagHandler. | |
36 | //-------------------------------------------------------------------------------- | |
37 | ||
38 | class WXDLLEXPORT wxHtmlWinParser : public wxHtmlParser | |
39 | { | |
5526e819 VS |
40 | friend class wxHtmlWindow; |
41 | ||
5526e819 | 42 | public: |
89966d5c | 43 | wxHtmlWinParser(wxWindow *wnd = NULL); |
b250d384 | 44 | ~wxHtmlWinParser(); |
5526e819 VS |
45 | |
46 | virtual void InitParser(const wxString& source); | |
47 | virtual void DoneParser(); | |
48 | virtual wxObject* GetProduct(); | |
49 | ||
edbd0635 | 50 | virtual void SetDC(wxDC *dc, double pixel_scale = 1.0) {m_DC = dc; m_PixelScale = pixel_scale;} |
5526e819 VS |
51 | // Set's the DC used for parsing. If SetDC() is not called, |
52 | // parsing won't proceed | |
53 | wxDC *GetDC() {return m_DC;} | |
edbd0635 | 54 | double GetPixelScale() {return m_PixelScale;} |
5526e819 VS |
55 | int GetCharHeight() const {return m_CharHeight;} |
56 | int GetCharWidth() const {return m_CharWidth;} | |
846914d1 | 57 | // NOTE : these functions do _not_ return _actual_ |
5526e819 VS |
58 | // height/width. They return h/w of default font |
59 | // for this DC. If you want actual values, call | |
4f9297b0 | 60 | // GetDC()->GetChar...() |
5526e819 VS |
61 | wxWindow *GetWindow() {return m_Window;} |
62 | // returns associated wxWindow | |
63 | ||
8eb2940f | 64 | void SetFonts(wxString normal_face, wxString fixed_face, const int *sizes); |
5526e819 | 65 | // sets fonts to be used when displaying HTML page. |
6e31e940 | 66 | |
5526e819 VS |
67 | static void AddModule(wxHtmlTagsModule *module); |
68 | // Adds tags module. see wxHtmlTagsModule for details. | |
f6bcfd97 | 69 | static void RemoveModule(wxHtmlTagsModule *module); |
5526e819 VS |
70 | |
71 | // parsing-related methods. These methods are called by tag handlers: | |
72 | wxHtmlContainerCell *GetContainer() const {return m_Container;} | |
73 | // Returns pointer to actual container. Common use in tag handler is : | |
4f9297b0 | 74 | // m_WParser->GetContainer()->InsertCell(new ...); |
5526e819 VS |
75 | wxHtmlContainerCell *OpenContainer(); |
76 | // opens new container. This container is sub-container of opened | |
77 | // container. Sets GetContainer to newly created container | |
78 | // and returns it. | |
79 | wxHtmlContainerCell *SetContainer(wxHtmlContainerCell *c); | |
80 | // works like OpenContainer except that new container is not created | |
81 | // but c is used. You can use this to directly set actual container | |
82 | wxHtmlContainerCell *CloseContainer(); | |
83 | // closes the container and sets actual Container to upper-level | |
84 | // container | |
85 | ||
86 | int GetFontSize() const {return m_FontSize;} | |
846914d1 | 87 | void SetFontSize(int s); |
5526e819 VS |
88 | int GetFontBold() const {return m_FontBold;} |
89 | void SetFontBold(int x) {m_FontBold = x;} | |
90 | int GetFontItalic() const {return m_FontItalic;} | |
91 | void SetFontItalic(int x) {m_FontItalic = x;} | |
92 | int GetFontUnderlined() const {return m_FontUnderlined;} | |
93 | void SetFontUnderlined(int x) {m_FontUnderlined = x;} | |
94 | int GetFontFixed() const {return m_FontFixed;} | |
95 | void SetFontFixed(int x) {m_FontFixed = x;} | |
f1ad10f3 | 96 | wxString GetFontFace() const {return GetFontFixed() ? m_FontFaceFixed : m_FontFaceNormal;} |
b250d384 | 97 | void SetFontFace(const wxString& face); |
5526e819 VS |
98 | |
99 | int GetAlign() const {return m_Align;} | |
100 | void SetAlign(int a) {m_Align = a;} | |
b250d384 VS |
101 | const wxColour& GetLinkColor() const { return m_LinkColor; } |
102 | void SetLinkColor(const wxColour& clr) { m_LinkColor = clr; } | |
103 | const wxColour& GetActualColor() const { return m_ActualColor; } | |
104 | void SetActualColor(const wxColour& clr) { m_ActualColor = clr ;} | |
105 | const wxHtmlLinkInfo& GetLink() const { return m_Link; } | |
846914d1 | 106 | void SetLink(const wxHtmlLinkInfo& link); |
5526e819 | 107 | |
b250d384 VS |
108 | void SetInputEncoding(wxFontEncoding enc); |
109 | wxFontEncoding GetInputEncoding() const { return m_InputEnc; } | |
110 | wxFontEncoding GetOutputEncoding() const { return m_OutputEnc; } | |
111 | wxEncodingConverter *GetEncodingConverter() const { return m_EncConv; } | |
112 | ||
5526e819 VS |
113 | virtual wxFont* CreateCurrentFont(); |
114 | // creates font depending on m_Font* members. | |
5526e819 VS |
115 | |
116 | protected: | |
117 | virtual void AddText(const char *txt); | |
118 | ||
119 | private: | |
120 | bool m_tmpLastWasSpace; | |
121 | // temporary variable used by AddText | |
69941f05 VS |
122 | wxWindow *m_Window; |
123 | // window we're parsing for | |
edbd0635 | 124 | double m_PixelScale; |
69941f05 VS |
125 | wxDC *m_DC; |
126 | // Device Context we're parsing for | |
127 | static wxList m_Modules; | |
128 | // list of tags modules (see wxHtmlTagsModule for details) | |
129 | // This list is used to initialize m_Handlers member. | |
130 | ||
131 | wxHtmlContainerCell *m_Container; | |
132 | // actual container. See Open/CloseContainer for details. | |
133 | ||
134 | int m_FontBold, m_FontItalic, m_FontUnderlined, m_FontFixed; // this is not TRUE,FALSE but 1,0, we need it for indexing | |
135 | int m_FontSize; /* -2 to +4, 0 is default */ | |
136 | wxColour m_LinkColor; | |
137 | wxColour m_ActualColor; | |
138 | // basic font parameters. | |
846914d1 | 139 | wxHtmlLinkInfo m_Link; |
69941f05 VS |
140 | // actual hypertext link or empty string |
141 | bool m_UseLink; | |
142 | // TRUE if m_Link is not empty | |
143 | long m_CharHeight, m_CharWidth; | |
144 | // average height of normal-sized text | |
145 | int m_Align; | |
146 | // actual alignment | |
f1ad10f3 VS |
147 | |
148 | wxFont* m_FontsTable[2][2][2][2][7]; | |
149 | wxString m_FontsFacesTable[2][2][2][2][7]; | |
b250d384 | 150 | wxFontEncoding m_FontsEncTable[2][2][2][2][7]; |
69941f05 VS |
151 | // table of loaded fonts. 1st four indexes are 0 or 1, depending on on/off |
152 | // state of these flags (from left to right): | |
153 | // [bold][italic][underlined][fixed_size] | |
846914d1 | 154 | // last index is font size : from 0 to 6 (remapped from html sizes 1 to 7) |
69941f05 VS |
155 | // Note : this table covers all possible combinations of fonts, but not |
156 | // all of them are used, so many items in table are usually NULL. | |
157 | int m_FontsSizes[7]; | |
158 | wxString m_FontFaceFixed, m_FontFaceNormal; | |
69941f05 | 159 | // html font sizes and faces of fixed and proportional fonts |
b250d384 VS |
160 | |
161 | wxFontEncoding m_InputEnc, m_OutputEnc; | |
162 | // I/O font encodings | |
163 | wxEncodingConverter *m_EncConv; | |
5526e819 VS |
164 | }; |
165 | ||
166 | ||
167 | ||
168 | ||
169 | ||
170 | ||
171 | //-------------------------------------------------------------------------------- | |
172 | // wxHtmlWinTagHandler | |
173 | // This is basicly wxHtmlTagHandler except | |
174 | // it is extended with protected member m_Parser pointing to | |
175 | // the wxHtmlWinParser object | |
176 | //-------------------------------------------------------------------------------- | |
177 | ||
178 | class WXDLLEXPORT wxHtmlWinTagHandler : public wxHtmlTagHandler | |
179 | { | |
180 | DECLARE_ABSTRACT_CLASS(wxHtmlWinTagHandler) | |
181 | ||
5526e819 VS |
182 | public: |
183 | wxHtmlWinTagHandler() : wxHtmlTagHandler() {}; | |
6e31e940 | 184 | |
5526e819 | 185 | virtual void SetParser(wxHtmlParser *parser) {wxHtmlTagHandler::SetParser(parser); m_WParser = (wxHtmlWinParser*) parser;}; |
69941f05 VS |
186 | |
187 | protected: | |
188 | wxHtmlWinParser *m_WParser; | |
189 | // same as m_Parser, but overcasted | |
5526e819 VS |
190 | }; |
191 | ||
192 | ||
193 | ||
194 | ||
195 | ||
196 | ||
197 | //-------------------------------------------------------------------------------- | |
198 | // wxHtmlTagsModule | |
199 | // This is basic of dynamic tag handlers binding. | |
200 | // The class provides methods for filling parser's handlers | |
201 | // hash table. | |
202 | // (See documentation for details) | |
203 | //-------------------------------------------------------------------------------- | |
204 | ||
205 | class WXDLLEXPORT wxHtmlTagsModule : public wxModule | |
206 | { | |
207 | DECLARE_DYNAMIC_CLASS(wxHtmlTagsModule) | |
208 | ||
209 | public: | |
210 | wxHtmlTagsModule() : wxModule() {}; | |
211 | ||
212 | virtual bool OnInit(); | |
213 | virtual void OnExit(); | |
214 | ||
6e31e940 | 215 | virtual void FillHandlersTable(wxHtmlWinParser * WXUNUSED(parser)) { } |
5526e819 VS |
216 | // This is called by wxHtmlWinParser. |
217 | // The method must simply call parser->AddTagHandler(new <handler_class_name>); | |
218 | // for each handler | |
219 | ||
220 | }; | |
221 | ||
222 | ||
69941f05 | 223 | #endif |
5526e819 | 224 | |
69941f05 | 225 | #endif // _WX_WINPARS_H_ |
5526e819 | 226 | |
5526e819 VS |
227 | |
228 | ||
229 |