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