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