]> git.saurik.com Git - wxWidgets.git/blame - src/html/winpars.cpp
Fixed OS/2 compilation after wxDC changes
[wxWidgets.git] / src / html / winpars.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/html/winpars.cpp
5526e819
VS
3// Purpose: wxHtmlParser class (generic parser)
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819 6// Copyright: (c) 1999 Vaclav Slavik
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
3096bd2f 10#include "wx/wxprec.h"
5526e819 11
2b5f62a0 12#ifdef __BORLANDC__
93763ad5 13 #pragma hdrstop
5526e819
VS
14#endif
15
93763ad5
WS
16#if wxUSE_HTML && wxUSE_STREAMS
17
b4f4d3dd 18#ifndef WX_PRECOMP
04dbb646
VZ
19 #include "wx/intl.h"
20 #include "wx/dc.h"
e4db172a 21 #include "wx/log.h"
9eddec69 22 #include "wx/settings.h"
5526e819
VS
23#endif
24
69941f05
VS
25#include "wx/html/htmldefs.h"
26#include "wx/html/winpars.h"
27#include "wx/html/htmlwin.h"
b250d384 28#include "wx/fontmap.h"
3ec372c8 29#include "wx/uri.h"
5526e819
VS
30
31
32//-----------------------------------------------------------------------------
33// wxHtmlWinParser
34//-----------------------------------------------------------------------------
35
4f44ea36 36IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinParser, wxHtmlParser)
5526e819
VS
37
38wxList wxHtmlWinParser::m_Modules;
39
bc55e31b 40wxHtmlWinParser::wxHtmlWinParser(wxHtmlWindowInterface *wndIface)
5526e819 41{
211dfedd
VS
42 m_tmpStrBuf = NULL;
43 m_tmpStrBufSize = 0;
bc55e31b 44 m_windowInterface = wndIface;
5526e819
VS
45 m_Container = NULL;
46 m_DC = NULL;
47 m_CharHeight = m_CharWidth = 0;
d1da8872 48 m_UseLink = false;
2b5f62a0 49#if !wxUSE_UNICODE
c7820964 50 m_nbsp = 0;
b250d384 51 m_EncConv = NULL;
2b5f62a0
VZ
52 m_InputEnc = wxFONTENCODING_ISO8859_1;
53 m_OutputEnc = wxFONTENCODING_DEFAULT;
54#endif
b6d93b26 55 m_lastWordCell = NULL;
5526e819
VS
56
57 {
58 int i, j, k, l, m;
59 for (i = 0; i < 2; i++)
60 for (j = 0; j < 2; j++)
61 for (k = 0; k < 2; k++)
62 for (l = 0; l < 2; l++)
3c8c8da2 63 for (m = 0; m < 7; m++)
e3c7fd79 64 {
5526e819 65 m_FontsTable[i][j][k][l][m] = NULL;
f1ad10f3 66 m_FontsFacesTable[i][j][k][l][m] = wxEmptyString;
2b5f62a0 67#if !wxUSE_UNICODE
b250d384 68 m_FontsEncTable[i][j][k][l][m] = wxFONTENCODING_DEFAULT;
2b5f62a0 69#endif
f1ad10f3 70 }
4eecf115
VS
71
72 SetFonts(wxEmptyString, wxEmptyString, NULL);
5526e819
VS
73 }
74
75 // fill in wxHtmlParser's tables:
222ed1d6 76 wxList::compatibility_iterator node = m_Modules.GetFirst();
3c8c8da2 77 while (node)
4f9297b0
VS
78 {
79 wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node->GetData();
80 mod->FillHandlersTable(this);
81 node = node->GetNext();
5526e819
VS
82 }
83}
84
b250d384
VS
85wxHtmlWinParser::~wxHtmlWinParser()
86{
87 int i, j, k, l, m;
88
89 for (i = 0; i < 2; i++)
90 for (j = 0; j < 2; j++)
91 for (k = 0; k < 2; k++)
92 for (l = 0; l < 2; l++)
3c8c8da2 93 for (m = 0; m < 7; m++)
e3c7fd79 94 {
3c8c8da2 95 if (m_FontsTable[i][j][k][l][m] != NULL)
b250d384
VS
96 delete m_FontsTable[i][j][k][l][m];
97 }
2b5f62a0 98#if !wxUSE_UNICODE
211dfedd 99 delete m_EncConv;
2b5f62a0 100#endif
211dfedd 101 delete[] m_tmpStrBuf;
b250d384
VS
102}
103
5526e819
VS
104void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module)
105{
106 m_Modules.Append(module);
107}
108
f6bcfd97
BP
109void wxHtmlWinParser::RemoveModule(wxHtmlTagsModule *module)
110{
111 m_Modules.DeleteObject(module);
112}
113
ba804ab2
VZ
114// build all HTML font sizes (1..7) from the given base size
115static void wxBuildFontSizes(int *sizes, int size)
116{
117 // using a fixed factor (1.2, from CSS2) is a bad idea as explained at
118 // http://www.w3.org/TR/CSS21/fonts.html#font-size-props but this is by far
119 // simplest thing to do so still do it like this for now
1d203ed8 120 sizes[0] = int(size * 0.75); // exception to 1.2 rule, otherwise too small
ba804ab2
VZ
121 sizes[1] = int(size * 0.83);
122 sizes[2] = size;
123 sizes[3] = int(size * 1.2);
124 sizes[4] = int(size * 1.44);
125 sizes[5] = int(size * 1.73);
126 sizes[6] = int(size * 2);
127}
128
1d203ed8
VZ
129static int wxGetDefaultHTMLFontSize()
130{
131 // base the default font size on the size of the default system font but
132 // also ensure that we have a font of reasonable size, otherwise small HTML
133 // fonts are unreadable
134 int size = wxNORMAL_FONT->GetPointSize();
135 if ( size < 10 )
136 size = 10;
137 return size;
138}
139
ba804ab2
VZ
140void wxHtmlWinParser::SetFonts(const wxString& normal_face,
141 const wxString& fixed_face,
4eecf115 142 const int *sizes)
5526e819 143{
ba804ab2
VZ
144 static int default_sizes[7] = { 0 };
145 if ( !sizes )
146 {
147 if ( !default_sizes[0] )
1d203ed8 148 wxBuildFontSizes(default_sizes, wxGetDefaultHTMLFontSize());
ba804ab2
VZ
149
150 sizes = default_sizes;
151 }
4eecf115 152
c9f56e70
VS
153 int i, j, k, l, m;
154
ba804ab2
VZ
155 for (i = 0; i < 7; i++)
156 m_FontsSizes[i] = sizes[i];
157
5526e819
VS
158 m_FontFaceFixed = fixed_face;
159 m_FontFaceNormal = normal_face;
3c8c8da2 160
2b5f62a0 161#if !wxUSE_UNICODE
b250d384 162 SetInputEncoding(m_InputEnc);
2b5f62a0 163#endif
c9f56e70
VS
164
165 for (i = 0; i < 2; i++)
166 for (j = 0; j < 2; j++)
167 for (k = 0; k < 2; k++)
168 for (l = 0; l < 2; l++)
169 for (m = 0; m < 7; m++) {
3c8c8da2 170 if (m_FontsTable[i][j][k][l][m] != NULL)
e3c7fd79 171 {
c9f56e70
VS
172 delete m_FontsTable[i][j][k][l][m];
173 m_FontsTable[i][j][k][l][m] = NULL;
174 }
175 }
5526e819
VS
176}
177
10e5c7ea
VS
178void wxHtmlWinParser::SetStandardFonts(int size,
179 const wxString& normal_face,
180 const wxString& fixed_face)
7acd3625 181{
ba804ab2 182 if (size == -1)
1d203ed8 183 size = wxGetDefaultHTMLFontSize();
d1da8872 184
7acd3625 185 int f_sizes[7];
ba804ab2
VZ
186 wxBuildFontSizes(f_sizes, size);
187
188 wxString normal = normal_face;
189 if ( normal.empty() )
190 normal = wxNORMAL_FONT->GetFaceName();
d1da8872 191
10e5c7ea 192 SetFonts(normal, fixed_face, f_sizes);
7acd3625
RD
193}
194
5526e819
VS
195void wxHtmlWinParser::InitParser(const wxString& source)
196{
197 wxHtmlParser::InitParser(source);
2b5f62a0 198 wxASSERT_MSG(m_DC != NULL, wxT("no DC assigned to wxHtmlWinParser!!"));
5526e819
VS
199
200 m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE;
f2c2fa4d 201 m_FontSize = 3; //default one
5526e819 202 CreateCurrentFont(); // we're selecting default font into
5620726f
RR
203
204 // we're not using GetCharWidth/Height() because of
205 // differences under X and win
206 wxCoord w,h;
207 m_DC->GetTextExtent( wxT("H"), &w, &h);
208 m_CharWidth = w;
209 m_CharHeight = h;
5526e819 210
d1da8872 211 m_UseLink = false;
9548f380 212 m_Link = wxHtmlLinkInfo( wxEmptyString );
5526e819
VS
213 m_LinkColor.Set(0, 0, 0xFF);
214 m_ActualColor.Set(0, 0, 0);
efba2b89 215 m_Align = wxHTML_ALIGN_LEFT;
3c115835
VS
216 m_ScriptMode = wxHTML_SCRIPT_NORMAL;
217 m_ScriptBaseline = 0;
d1da8872 218 m_tmpLastWasSpace = false;
b6d93b26 219 m_lastWordCell = NULL;
5526e819 220
69328c1a
VS
221 // open the toplevel container that contains everything else and that
222 // is never closed (this makes parser's life easier):
5526e819 223 OpenContainer();
69328c1a
VS
224
225 // then open the first container into which page's content will go:
5526e819 226 OpenContainer();
2b5f62a0 227
fa2f5d3b 228#if !wxUSE_UNICODE
2b5f62a0
VZ
229 wxString charset = ExtractCharsetInformation(source);
230 if (!charset.empty())
231 {
232 wxFontEncoding enc = wxFontMapper::Get()->CharsetToEncoding(charset);
233 if (enc != wxFONTENCODING_SYSTEM)
234 SetInputEncoding(enc);
235 }
236#endif
237
4f9297b0 238 m_Container->InsertCell(new wxHtmlColourCell(m_ActualColor));
44d0c580 239 wxColour windowColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW) ;
bc55e31b
VS
240
241 m_Container->InsertCell
242 (
243 new wxHtmlColourCell
244 (
245 m_windowInterface
246 ? m_windowInterface->GetHTMLBackgroundColour()
247 : windowColour,
248 wxHTML_CLR_BACKGROUND
249 )
250 );
251
4f9297b0 252 m_Container->InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
5526e819
VS
253}
254
5526e819
VS
255void wxHtmlWinParser::DoneParser()
256{
257 m_Container = NULL;
2b5f62a0
VZ
258#if !wxUSE_UNICODE
259 SetInputEncoding(wxFONTENCODING_ISO8859_1); // for next call
260#endif
5526e819
VS
261 wxHtmlParser::DoneParser();
262}
263
bc55e31b
VS
264#if WXWIN_COMPATIBILITY_2_6
265wxHtmlWindow *wxHtmlWinParser::GetWindow()
266{
267 if (!m_windowInterface)
268 return NULL;
269 return wxDynamicCast(m_windowInterface->GetHTMLWindow(), wxHtmlWindow);
270}
271#endif
272
5526e819
VS
273wxObject* wxHtmlWinParser::GetProduct()
274{
275 wxHtmlContainerCell *top;
276
277 CloseContainer();
278 OpenContainer();
67cfebc2 279
5526e819 280 top = m_Container;
4f9297b0 281 while (top->GetParent()) top = top->GetParent();
ace0fab4
VS
282 top->RemoveExtraSpacing(true, true);
283
5526e819
VS
284 return top;
285}
286
0423bdc7 287wxFSFile *wxHtmlWinParser::OpenURL(wxHtmlURLType type,
6cc4e6b8 288 const wxString& url) const
04db5c3f 289{
bc55e31b
VS
290 if ( !m_windowInterface )
291 return wxHtmlParser::OpenURL(type, url);
292
293 wxString myurl(url);
294 wxHtmlOpeningStatus status;
295 for (;;)
6cc4e6b8 296 {
bc55e31b 297 wxString myfullurl(myurl);
4bfa3189 298
bc55e31b
VS
299 // consider url as absolute path first
300 wxURI current(myurl);
301 myfullurl = current.BuildUnescapedURI();
4bfa3189 302
bc55e31b
VS
303 // if not absolute then ...
304 if( current.IsReference() )
305 {
306 wxString basepath = GetFS()->GetPath();
307 wxURI base(basepath);
4bfa3189 308
bc55e31b
VS
309 // ... try to apply base path if valid ...
310 if( !base.IsReference() )
311 {
312 wxURI path(myfullurl);
313 path.Resolve( base );
314 myfullurl = path.BuildUnescapedURI();
315 }
316 else
317 {
318 // ... or force such addition if not included already
319 if( !current.GetPath().Contains(base.GetPath()) )
4bfa3189 320 {
bc55e31b
VS
321 basepath += myurl;
322 wxURI connected( basepath );
323 myfullurl = connected.BuildUnescapedURI();
4bfa3189
WS
324 }
325 }
6cc4e6b8 326 }
0423bdc7 327
bc55e31b
VS
328 wxString redirect;
329 status = m_windowInterface->OnHTMLOpeningURL(type, myfullurl, &redirect);
330 if ( status != wxHTML_REDIRECT )
331 break;
2c892c0b 332
bc55e31b 333 myurl = redirect;
6cc4e6b8 334 }
2c892c0b 335
bc55e31b
VS
336 if ( status == wxHTML_BLOCK )
337 return NULL;
338
5c4035d6
MW
339 int flags = wxFS_READ;
340 if (type == wxHTML_URL_IMAGE)
341 flags |= wxFS_SEEKABLE;
342
343 return GetFS()->OpenFile(myurl, flags);
04db5c3f 344}
5526e819 345
5bce3e6f 346void wxHtmlWinParser::AddText(const wxString& txt)
5526e819 347{
211dfedd 348 register wxChar d;
5526e819 349 int templen = 0;
211dfedd 350
5bce3e6f 351 size_t lng = txt.length();
211dfedd
VS
352 if (lng+1 > m_tmpStrBufSize)
353 {
354 delete[] m_tmpStrBuf;
355 m_tmpStrBuf = new wxChar[lng+1];
356 m_tmpStrBufSize = lng+1;
357 }
358 wxChar *temp = m_tmpStrBuf;
3c8c8da2 359
5bce3e6f
VS
360 wxString::const_iterator i = txt.begin();
361 wxString::const_iterator end = txt.end();
362
3c8c8da2 363 if (m_tmpLastWasSpace)
4f9297b0 364 {
5bce3e6f
VS
365 while ( (i < end) &&
366 (*i == wxT('\n') || *i == wxT('\r') || *i == wxT(' ') ||
367 *i == wxT('\t')) )
368 {
369 ++i;
370 }
5526e819
VS
371 }
372
5bce3e6f 373 while (i < end)
4f9297b0 374 {
5bce3e6f
VS
375 size_t x = 0;
376 d = temp[templen++] = *i;
3c8c8da2 377 if ((d == wxT('\n')) || (d == wxT('\r')) || (d == wxT(' ')) || (d == wxT('\t')))
e3c7fd79 378 {
5bce3e6f
VS
379 ++i, ++x;
380 while ( (i < end) &&
381 (*i == wxT('\n') || *i == wxT('\r') ||
f5595af6 382 *i == wxT(' ') || *i == wxT('\t')) )
5bce3e6f
VS
383 {
384 ++i;
385 ++x;
386 }
5526e819 387 }
5bce3e6f
VS
388 else
389 ++i;
5526e819 390
3c8c8da2 391 if (x)
e3c7fd79 392 {
211dfedd 393 temp[templen-1] = wxT(' ');
c7820964 394 DoAddText(temp, templen);
d1da8872 395 m_tmpLastWasSpace = true;
5526e819
VS
396 }
397 }
af035b26
VS
398
399 if (templen && (templen > 1 || temp[0] != wxT(' ')))
4f9297b0 400 {
c7820964 401 DoAddText(temp, templen);
97eac136
VS
402 m_tmpLastWasSpace = false;
403 }
404}
405
c7820964 406void wxHtmlWinParser::DoAddText(wxChar *temp, int& templen)
97eac136 407{
c7820964
VS
408 #define NBSP_UNICODE_VALUE 160
409#if !wxUSE_UNICODE
410 if ( m_nbsp == 0 )
411 m_nbsp = GetEntitiesParser()->GetCharForCode(NBSP_UNICODE_VALUE);
412 #define CUR_NBSP_VALUE m_nbsp
413#else
414 #define CUR_NBSP_VALUE NBSP_UNICODE_VALUE
415#endif
416
97eac136
VS
417 temp[templen] = 0;
418 templen = 0;
2b5f62a0 419#if !wxUSE_UNICODE
97eac136
VS
420 if (m_EncConv)
421 m_EncConv->Convert(temp);
2b5f62a0 422#endif
97eac136
VS
423 size_t len = wxStrlen(temp);
424 for (size_t j = 0; j < len; j++)
425 {
c7820964 426 if (temp[j] == CUR_NBSP_VALUE)
97eac136 427 temp[j] = wxT(' ');
5526e819 428 }
97eac136
VS
429
430 wxHtmlCell *c = new wxHtmlWordCell(temp, *(GetDC()));
431
3c115835
VS
432 ApplyStateToCell(c);
433
97eac136
VS
434 m_Container->InsertCell(c);
435 ((wxHtmlWordCell*)c)->SetPreviousWord(m_lastWordCell);
436 m_lastWordCell = (wxHtmlWordCell*)c;
5526e819
VS
437}
438
439
440
441wxHtmlContainerCell* wxHtmlWinParser::OpenContainer()
442{
443 m_Container = new wxHtmlContainerCell(m_Container);
4f9297b0 444 m_Container->SetAlignHor(m_Align);
d1da8872 445 m_tmpLastWasSpace = true;
5526e819
VS
446 /* to avoid space being first character in paragraph */
447 return m_Container;
448}
449
450
451
452wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c)
453{
d1da8872 454 m_tmpLastWasSpace = true;
5526e819
VS
455 /* to avoid space being first character in paragraph */
456 return m_Container = c;
457}
458
459
460
461wxHtmlContainerCell* wxHtmlWinParser::CloseContainer()
462{
4f9297b0 463 m_Container = m_Container->GetParent();
5526e819
VS
464 return m_Container;
465}
466
467
f2c2fa4d
VS
468void wxHtmlWinParser::SetFontSize(int s)
469{
470 if (s < 1) s = 1;
471 else if (s > 7) s = 7;
472 m_FontSize = s;
473}
474
475
476
5526e819
VS
477wxFont* wxHtmlWinParser::CreateCurrentFont()
478{
479 int fb = GetFontBold(),
480 fi = GetFontItalic(),
481 fu = GetFontUnderlined(),
482 ff = GetFontFixed(),
f2c2fa4d 483 fs = GetFontSize() - 1 /*remap from <1;7> to <0;6>*/ ;
5526e819 484
f1ad10f3
VS
485 wxString face = ff ? m_FontFaceFixed : m_FontFaceNormal;
486 wxString *faceptr = &(m_FontsFacesTable[fb][fi][fu][ff][fs]);
487 wxFont **fontptr = &(m_FontsTable[fb][fi][fu][ff][fs]);
2b5f62a0 488#if !wxUSE_UNICODE
b250d384 489 wxFontEncoding *encptr = &(m_FontsEncTable[fb][fi][fu][ff][fs]);
2b5f62a0 490#endif
f1ad10f3 491
2b5f62a0
VZ
492 if (*fontptr != NULL && (*faceptr != face
493#if !wxUSE_UNICODE
494 || *encptr != m_OutputEnc
495#endif
496 ))
4f9297b0 497 {
f1ad10f3
VS
498 delete *fontptr;
499 *fontptr = NULL;
500 }
501
3c8c8da2 502 if (*fontptr == NULL)
4f9297b0 503 {
f1ad10f3
VS
504 *faceptr = face;
505 *fontptr = new wxFont(
7a5e6267 506 (int) (m_FontsSizes[fs] * m_PixelScale),
f1ad10f3
VS
507 ff ? wxMODERN : wxSWISS,
508 fi ? wxITALIC : wxNORMAL,
509 fb ? wxBOLD : wxNORMAL,
d1da8872 510 fu ? true : false, face
2b5f62a0
VZ
511#if wxUSE_UNICODE
512 );
513#else
514 , m_OutputEnc);
515 *encptr = m_OutputEnc;
516#endif
5526e819 517 }
4f9297b0 518 m_DC->SetFont(**fontptr);
f1ad10f3 519 return (*fontptr);
5526e819
VS
520}
521
522
523
f2c2fa4d
VS
524void wxHtmlWinParser::SetLink(const wxHtmlLinkInfo& link)
525{
3c8c8da2 526 m_Link = link;
f2c2fa4d
VS
527 m_UseLink = (link.GetHref() != wxEmptyString);
528}
529
3c8c8da2 530void wxHtmlWinParser::SetFontFace(const wxString& face)
b250d384 531{
3c8c8da2 532 if (GetFontFixed()) m_FontFaceFixed = face;
b250d384
VS
533 else m_FontFaceNormal = face;
534
2b5f62a0 535#if !wxUSE_UNICODE
b250d384
VS
536 if (m_InputEnc != wxFONTENCODING_DEFAULT)
537 SetInputEncoding(m_InputEnc);
2b5f62a0 538#endif
b250d384
VS
539}
540
3c115835
VS
541void wxHtmlWinParser::ApplyStateToCell(wxHtmlCell *cell)
542{
543 // set the link:
544 if (m_UseLink)
545 cell->SetLink(GetLink());
546
547 // apply current script mode settings:
548 cell->SetScriptMode(GetScriptMode(), GetScriptBaseline());
549}
b250d384
VS
550
551
2b5f62a0 552#if !wxUSE_UNICODE
b250d384
VS
553void wxHtmlWinParser::SetInputEncoding(wxFontEncoding enc)
554{
c7820964
VS
555 // the character used for non-breakable space may change:
556 m_nbsp = 0;
557
b250d384 558 m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT;
3c8c8da2 559 if (m_EncConv)
daa616fc 560 {
3c8c8da2 561 delete m_EncConv;
daa616fc
VS
562 m_EncConv = NULL;
563 }
b250d384
VS
564
565 if (enc == wxFONTENCODING_DEFAULT) return;
566
567 wxFontEncoding altfix, altnorm;
568 bool availfix, availnorm;
3c8c8da2
VZ
569
570 // exact match?
142b3bc2
VS
571 availnorm = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceNormal);
572 availfix = wxFontMapper::Get()->IsEncodingAvailable(enc, m_FontFaceFixed);
3c8c8da2 573 if (availnorm && availfix)
b250d384 574 m_OutputEnc = enc;
3c8c8da2 575
b250d384 576 // alternatives?
d1da8872
WS
577 else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false) &&
578 wxFontMapper::Get()->GetAltForEncoding(enc, &altfix, m_FontFaceFixed, false) &&
b250d384
VS
579 altnorm == altfix)
580 m_OutputEnc = altnorm;
3c8c8da2 581
b250d384
VS
582 // at least normal face?
583 else if (availnorm)
584 m_OutputEnc = enc;
d1da8872 585 else if (wxFontMapper::Get()->GetAltForEncoding(enc, &altnorm, m_FontFaceNormal, false))
b250d384 586 m_OutputEnc = altnorm;
3c8c8da2 587
b250d384 588 else
c83e1237
SC
589 {
590#ifndef __WXMAC__
6a17b868 591 // okay, let's convert to ISO_8859-1, available always
b250d384 592 m_OutputEnc = wxFONTENCODING_DEFAULT;
90548138 593#else
c83e1237 594 m_OutputEnc = wxLocale::GetSystemEncoding() ;
90548138 595#endif
c83e1237 596 }
3c8c8da2 597
b250d384 598 m_InputEnc = enc;
daa616fc
VS
599 if (m_OutputEnc == wxFONTENCODING_DEFAULT)
600 GetEntitiesParser()->SetEncoding(wxFONTENCODING_SYSTEM);
601 else
602 GetEntitiesParser()->SetEncoding(m_OutputEnc);
3c8c8da2 603
b250d384
VS
604 if (m_InputEnc == m_OutputEnc) return;
605
606 m_EncConv = new wxEncodingConverter();
3c8c8da2 607 if (!m_EncConv->Init(m_InputEnc,
b250d384
VS
608 (m_OutputEnc == wxFONTENCODING_DEFAULT) ?
609 wxFONTENCODING_ISO8859_1 : m_OutputEnc,
3c8c8da2 610 wxCONVERT_SUBSTITUTE))
6a17b868 611 { // total failure :-(
3c8c8da2
VZ
612 wxLogError(_("Failed to display HTML document in %s encoding"),
613 wxFontMapper::GetEncodingName(enc).c_str());
b250d384
VS
614 m_InputEnc = m_OutputEnc = wxFONTENCODING_DEFAULT;
615 delete m_EncConv;
616 m_EncConv = NULL;
617 }
618}
2b5f62a0 619#endif
b250d384
VS
620
621
f2c2fa4d 622
5526e819
VS
623
624//-----------------------------------------------------------------------------
625// wxHtmlWinTagHandler
626//-----------------------------------------------------------------------------
627
628IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler)
629
5526e819
VS
630//-----------------------------------------------------------------------------
631// wxHtmlTagsModule
632//-----------------------------------------------------------------------------
633
d6a6d666
VS
634// NB: This is *NOT* winpars.cpp's initialization and shutdown code!!
635// This module is an ancestor for tag handlers modules defined
636// in m_*.cpp files with TAGS_MODULE_BEGIN...TAGS_MODULE_END construct.
637//
638// Do not add any winpars.cpp shutdown or initialization code to it,
639// create a new module instead!
5526e819
VS
640
641IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule)
642
5526e819
VS
643bool wxHtmlTagsModule::OnInit()
644{
645 wxHtmlWinParser::AddModule(this);
d1da8872 646 return true;
5526e819
VS
647}
648
5526e819
VS
649void wxHtmlTagsModule::OnExit()
650{
f6bcfd97 651 wxHtmlWinParser::RemoveModule(this);
5526e819 652}
d6a6d666 653
223d09f6 654#endif