]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_pre.cpp
reSWIGged
[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 6// Copyright: (c) 1999 Vaclav Slavik
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
14f355c2 10#if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
3364ab79
RS
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
2b5f62a0 18#ifdef __BORLANDC__
3364ab79
RS
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;
999836aa 38 size_t len = str.Len();
0ab8db38 39 size_t linepos = 0;
999836aa 40 for (size_t i = 0; i < len; i++)
83c9da45
VS
41 {
42 switch (str[i])
43 {
44 case wxT('<'):
c0ce1b03 45 while (i < len && str[i] != wxT('>'))
0ab8db38 46 {
83c9da45 47 out << str[i++];
0ab8db38
VS
48 linepos++;
49 }
83c9da45 50 out << wxT('>');
0ab8db38 51 linepos++;
83c9da45
VS
52 break;
53 case wxT(' '):
54 out << wxT("&nbsp;");
0ab8db38 55 linepos++;
83c9da45
VS
56 break;
57 case wxT('\n'):
58 out << wxT("<br>");
0ab8db38 59 linepos = 0;
83c9da45
VS
60 break;
61 case wxT('\t'):
999836aa 62 {
0ab8db38 63 for (size_t j = 8 - linepos % 8; j > 0; j--)
999836aa 64 out << wxT("&nbsp;");
0ab8db38 65 linepos += 8 - linepos % 8;
999836aa 66 }
83c9da45
VS
67 break;
68 default:
69 out << str[i];
0ab8db38 70 linepos++;
83c9da45
VS
71 break;
72 }
73 }
74 return out;
75}
76
77
5526e819
VS
78//-----------------------------------------------------------------------------
79// The list handler:
80//-----------------------------------------------------------------------------
81
82
83TAG_HANDLER_BEGIN(PRE, "PRE")
fc7a2a60 84 TAG_HANDLER_CONSTR(PRE) { }
5526e819
VS
85
86 TAG_HANDLER_PROC(tag)
87 {
88 wxHtmlContainerCell *c;
89
4f9297b0
VS
90 int fixed = m_WParser->GetFontFixed(),
91 italic = m_WParser->GetFontItalic(),
92 underlined = m_WParser->GetFontUnderlined(),
93 bold = m_WParser->GetFontBold(),
94 fsize = m_WParser->GetFontSize();
5526e819 95
1309ba6c 96 c = m_WParser->GetContainer();
d1da8872
WS
97 m_WParser->SetFontUnderlined(false);
98 m_WParser->SetFontBold(false);
99 m_WParser->SetFontItalic(false);
100 m_WParser->SetFontFixed(true);
4f9297b0
VS
101 m_WParser->SetFontSize(3);
102 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 103
1309ba6c
VS
104 m_WParser->CloseContainer();
105 c = m_WParser->OpenContainer();
69379916
VS
106 c->SetWidthFloat(tag);
107 c = m_WParser->OpenContainer();
1309ba6c 108 c->SetAlignHor(wxHTML_ALIGN_LEFT);
b3470d76 109 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
1309ba6c 110
c0ce1b03 111 wxString srcMid =
211dfedd
VS
112 m_WParser->GetSource()->Mid(tag.GetBeginPos(),
113 tag.GetEndPos1() - tag.GetBeginPos());
1309ba6c
VS
114 // It is safe to temporarily change the source being parsed,
115 // provided we restore the state back after parsing
83c9da45 116 m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid));
1309ba6c 117 m_Parser->DoParsing();
211dfedd 118 m_Parser->RestoreState();
04dbb646 119
69379916 120 m_WParser->CloseContainer();
1309ba6c
VS
121 m_WParser->CloseContainer();
122 c = m_WParser->OpenContainer();
5526e819 123
4f9297b0
VS
124 m_WParser->SetFontUnderlined(underlined);
125 m_WParser->SetFontBold(bold);
126 m_WParser->SetFontItalic(italic);
127 m_WParser->SetFontFixed(fixed);
128 m_WParser->SetFontSize(fsize);
129 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 130
d1da8872 131 return true;
5526e819
VS
132 }
133
134TAG_HANDLER_END(PRE)
135
136
137
138
139
140TAGS_MODULE_BEGIN(Pre)
141
142 TAGS_MODULE_ADD(PRE)
143
144TAGS_MODULE_END(Pre)
145
146#endif