]> git.saurik.com Git - wxWidgets.git/blob - src/html/winpars.cpp
Unicode overview added
[wxWidgets.git] / src / html / winpars.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winpars.cpp
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <wx/wxprec.h>
16
17 #include "wx/defs.h"
18 #if wxUSE_HTML
19
20 #ifdef __BORDLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WXPRECOMP
25 #include <wx/wx.h>
26 #endif
27
28 #include "wx/html/htmldefs.h"
29 #include "wx/html/winpars.h"
30 #include "wx/html/htmlwin.h"
31
32
33 //-----------------------------------------------------------------------------
34 // wxHtmlWinParser
35 //-----------------------------------------------------------------------------
36
37 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinParser,wxHtmlParser)
38
39 wxList wxHtmlWinParser::m_Modules;
40
41 wxHtmlWinParser::wxHtmlWinParser(wxWindow *wnd) : wxHtmlParser()
42 {
43 m_Window = wnd;
44 m_Container = NULL;
45 m_DC = NULL;
46 m_CharHeight = m_CharWidth = 0;
47 m_UseLink = FALSE;
48
49 {
50 int i, j, k, l, m;
51 for (i = 0; i < 2; i++)
52 for (j = 0; j < 2; j++)
53 for (k = 0; k < 2; k++)
54 for (l = 0; l < 2; l++)
55 for (m = 0; m < 7; m++)
56 m_FontsTable[i][j][k][l][m] = NULL;
57 #ifdef __WXMSW__
58 int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
59 #else
60 int default_sizes[7] = {10, 12, 14, 16, 19, 24, 32};
61 #endif
62 SetFonts("", wxSLANT, "", wxSLANT, default_sizes);
63 }
64
65 // fill in wxHtmlParser's tables:
66 wxNode *node = m_Modules.GetFirst();
67 while (node){
68 wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node -> GetData();
69 mod -> FillHandlersTable(this);
70 node = node -> GetNext();
71 }
72 }
73
74
75
76 void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module)
77 {
78 m_Modules.Append(module);
79 }
80
81
82
83 void wxHtmlWinParser::SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, int *sizes)
84 {
85 for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
86 m_FontFaceFixed = fixed_face;
87 m_FontFaceNormal = normal_face;
88 m_ItalicModeFixed = fixed_italic_mode;
89 m_ItalicModeNormal = normal_italic_mode;
90 }
91
92
93
94 void wxHtmlWinParser::InitParser(const wxString& source)
95 {
96 wxHtmlParser::InitParser(source);
97 wxASSERT_MSG(m_DC != NULL, _("no DC assigned to wxHtmlWinParser!!"));
98
99 m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE;
100 m_FontSize = 0;
101 CreateCurrentFont(); // we're selecting default font into
102 m_DC -> GetTextExtent("H", &m_CharWidth, &m_CharHeight);
103 /* NOTE : we're not using GetCharWidth/Height() because
104 of differences under X and win
105 */
106
107 m_Link = "";
108 m_LinkColor.Set(0, 0, 0xFF);
109 m_ActualColor.Set(0, 0, 0);
110 m_Align = HTML_ALIGN_LEFT;
111 m_tmpLastWasSpace = FALSE;
112
113 OpenContainer();
114
115 OpenContainer();
116 m_Container -> InsertCell(new wxHtmlColourCell(m_ActualColor));
117 m_Container -> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
118 }
119
120
121
122 void wxHtmlWinParser::DoneParser()
123 {
124 m_Container = NULL;
125 wxHtmlParser::DoneParser();
126 }
127
128
129
130 wxObject* wxHtmlWinParser::GetProduct()
131 {
132 wxHtmlContainerCell *top;
133
134 CloseContainer();
135 OpenContainer();
136 GetContainer() -> SetIndent(m_CharHeight, HTML_INDENT_TOP);
137 top = m_Container;
138 while (top -> GetParent()) top = top -> GetParent();
139 return top;
140 }
141
142
143
144 wxList* wxHtmlWinParser::GetTempData()
145 {
146 int i, j, k, l, m;
147 wxFont *f;
148 wxList *lst = wxHtmlParser::GetTempData();
149
150 if (lst == NULL) lst = new wxList;
151 lst -> DeleteContents(TRUE);
152
153 for (i = 0; i < 2; i++)
154 for (j = 0; j < 2; j++)
155 for (k = 0; k < 2; k++)
156 for (l = 0; l < 2; l++)
157 for (m = 0; m < 7; m++) {
158 f = m_FontsTable[i][j][k][l][m];
159 if (f) lst -> Append(f);
160 }
161 return lst;
162 }
163
164
165
166 void wxHtmlWinParser::AddText(const char* txt)
167 {
168 wxHtmlCell *c;
169 int i = 0, x, lng = strlen(txt);
170 char temp[HTML_BUFLEN];
171 register char d;
172 int templen = 0;
173
174 if (m_tmpLastWasSpace) {
175 while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++;
176 }
177
178 while (i < lng) {
179 x = 0;
180 d = temp[templen++] = txt[i];
181 if ((d == '\n') || (d == '\r') || (d == ' ') || (d == '\t')) {
182 i++, x++;
183 while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++, x++;
184 }
185 else i++;
186
187 if (x) {
188 temp[templen-1] = ' ';
189 temp[templen] = 0;
190 templen = 0;
191 c = new wxHtmlWordCell(temp, *(GetDC()));
192 if (m_UseLink) c -> SetLink(m_Link);
193 m_Container -> InsertCell(c);
194 m_tmpLastWasSpace = TRUE;
195 }
196 }
197 if (templen) {
198 temp[templen] = 0;
199 c = new wxHtmlWordCell(temp, *(GetDC()));
200 if (m_UseLink) c -> SetLink(m_Link);
201 m_Container -> InsertCell(c);
202 m_tmpLastWasSpace = FALSE;
203 }
204 }
205
206
207
208 wxHtmlContainerCell* wxHtmlWinParser::OpenContainer()
209 {
210 m_Container = new wxHtmlContainerCell(m_Container);
211 m_Container -> SetAlignHor(m_Align);
212 m_tmpLastWasSpace = TRUE;
213 /* to avoid space being first character in paragraph */
214 return m_Container;
215 }
216
217
218
219 wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c)
220 {
221 m_tmpLastWasSpace = TRUE;
222 /* to avoid space being first character in paragraph */
223 return m_Container = c;
224 }
225
226
227
228 wxHtmlContainerCell* wxHtmlWinParser::CloseContainer()
229 {
230 m_Container = m_Container -> GetParent();
231 return m_Container;
232 }
233
234
235
236 wxFont* wxHtmlWinParser::CreateCurrentFont()
237 {
238 int fb = GetFontBold(),
239 fi = GetFontItalic(),
240 fu = GetFontUnderlined(),
241 ff = GetFontFixed(),
242 fs = GetFontSize() + 2 /*remap from <-2;4> to <0;7>*/ ;
243
244 if (m_FontsTable[fb][fi][fu][ff][fs] == NULL) {
245 m_FontsTable[fb][fi][fu][ff][fs] =
246 //wxTheFontList -> FindOrCreateFont(
247 new wxFont(
248 m_FontsSizes[fs],
249 ff ? wxMODERN : wxSWISS,
250 fi ? (ff ? m_ItalicModeFixed : m_ItalicModeNormal) : wxNORMAL,
251 fb ? wxBOLD : wxNORMAL,
252 fu ? TRUE : FALSE, ff ? m_FontFaceFixed : m_FontFaceNormal);
253 }
254 m_DC -> SetFont(*(m_FontsTable[fb][fi][fu][ff][fs]));
255 return (m_FontsTable[fb][fi][fu][ff][fs]);
256 }
257
258
259
260
261 //-----------------------------------------------------------------------------
262 // wxHtmlWinTagHandler
263 //-----------------------------------------------------------------------------
264
265 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler)
266
267
268
269 //-----------------------------------------------------------------------------
270 // wxHtmlTagsModule
271 //-----------------------------------------------------------------------------
272
273
274 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule)
275
276
277 bool wxHtmlTagsModule::OnInit()
278 {
279 wxHtmlWinParser::AddModule(this);
280 return TRUE;
281 }
282
283
284
285 void wxHtmlTagsModule::OnExit()
286 {
287 }
288
289 #endif