]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_pre.cpp
removed defs.h include
[wxWidgets.git] / src / html / m_pre.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
c88293a4 2// Name: m_pre.cpp
5526e819
VS
3// Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819
VS
6// Copyright: (c) 1999 Vaclav Slavik
7// Licence: wxWindows Licence
8/////////////////////////////////////////////////////////////////////////////
9
3364ab79
RS
10#ifdef __GNUG__
11#pragma implementation
12#endif
13
3096bd2f 14#include "wx/wxprec.h"
3364ab79 15
314260fb 16#include "wx/defs.h"
f6bcfd97 17#if wxUSE_HTML && wxUSE_STREAMS
3364ab79
RS
18#ifdef __BORDLANDC__
19#pragma hdrstop
20#endif
21
22#ifndef WXPRECOMP
3364ab79
RS
23#endif
24
69941f05
VS
25#include "wx/html/forcelnk.h"
26#include "wx/html/m_templ.h"
5526e819 27
69941f05 28#include "wx/html/htmlcell.h"
3096bd2f 29#include "wx/tokenzr.h"
57f59026 30#include "wx/encconv.h"
5526e819 31
c88293a4 32FORCE_LINK_ME(m_pre)
5526e819 33
83c9da45 34// replaces '\t', ' ' and '\n' with HTML markup:
9d59f1fc 35static wxString LINKAGEMODE HtmlizeWhitespaces(const wxString& str)
83c9da45
VS
36{
37 wxString out;
c0ce1b03 38 size_t i = 0, j = 0, len = str.Len();
83c9da45
VS
39 for (i = 0; i < len; i++)
40 {
41 switch (str[i])
42 {
43 case wxT('<'):
c0ce1b03 44 while (i < len && str[i] != wxT('>'))
83c9da45
VS
45 out << str[i++];
46 out << wxT('>');
47 break;
48 case wxT(' '):
49 out << wxT("&nbsp;");
50 break;
51 case wxT('\n'):
52 out << wxT("<br>");
53 break;
54 case wxT('\t'):
c0ce1b03 55 for (j = 8 - i%8; j > 0; j--) out << wxT("&nbsp;");
83c9da45
VS
56 break;
57 default:
58 out << str[i];
59 break;
60 }
61 }
62 return out;
63}
64
65
5526e819
VS
66//-----------------------------------------------------------------------------
67// The list handler:
68//-----------------------------------------------------------------------------
69
70
71TAG_HANDLER_BEGIN(PRE, "PRE")
72
73 TAG_HANDLER_PROC(tag)
74 {
75 wxHtmlContainerCell *c;
76
4f9297b0
VS
77 int fixed = m_WParser->GetFontFixed(),
78 italic = m_WParser->GetFontItalic(),
79 underlined = m_WParser->GetFontUnderlined(),
80 bold = m_WParser->GetFontBold(),
81 fsize = m_WParser->GetFontSize();
5526e819 82
1309ba6c 83 c = m_WParser->GetContainer();
4f9297b0
VS
84 m_WParser->SetFontUnderlined(FALSE);
85 m_WParser->SetFontBold(FALSE);
86 m_WParser->SetFontItalic(FALSE);
87 m_WParser->SetFontFixed(TRUE);
88 m_WParser->SetFontSize(3);
89 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 90
1309ba6c
VS
91 m_WParser->CloseContainer();
92 c = m_WParser->OpenContainer();
93 c->SetAlignHor(wxHTML_ALIGN_LEFT);
94
c0ce1b03 95 wxString srcMid =
211dfedd
VS
96 m_WParser->GetSource()->Mid(tag.GetBeginPos(),
97 tag.GetEndPos1() - tag.GetBeginPos());
1309ba6c
VS
98 // It is safe to temporarily change the source being parsed,
99 // provided we restore the state back after parsing
83c9da45 100 m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid));
1309ba6c 101 m_Parser->DoParsing();
211dfedd 102 m_Parser->RestoreState();
04dbb646 103
1309ba6c
VS
104 m_WParser->CloseContainer();
105 c = m_WParser->OpenContainer();
5526e819 106
4f9297b0
VS
107 m_WParser->SetFontUnderlined(underlined);
108 m_WParser->SetFontBold(bold);
109 m_WParser->SetFontItalic(italic);
110 m_WParser->SetFontFixed(fixed);
111 m_WParser->SetFontSize(fsize);
112 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 113
5526e819
VS
114 return TRUE;
115 }
116
117TAG_HANDLER_END(PRE)
118
119
120
121
122
123TAGS_MODULE_BEGIN(Pre)
124
125 TAGS_MODULE_ADD(PRE)
126
127TAGS_MODULE_END(Pre)
128
129#endif