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