]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_pre.cpp
Fixed wxscintilla compilation for wxDFB.
[wxWidgets.git] / src / html / m_pre.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/html/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
3096bd2f 10#include "wx/wxprec.h"
3364ab79 11
2b5f62a0 12#ifdef __BORLANDC__
93763ad5 13 #pragma hdrstop
3364ab79
RS
14#endif
15
93763ad5
WS
16#if wxUSE_HTML && wxUSE_STREAMS
17
b4f4d3dd 18#ifndef WX_PRECOMP
3364ab79
RS
19#endif
20
69941f05
VS
21#include "wx/html/forcelnk.h"
22#include "wx/html/m_templ.h"
5526e819 23
69941f05 24#include "wx/html/htmlcell.h"
3096bd2f 25#include "wx/tokenzr.h"
57f59026 26#include "wx/encconv.h"
5526e819 27
c88293a4 28FORCE_LINK_ME(m_pre)
5526e819 29
83c9da45 30// replaces '\t', ' ' and '\n' with HTML markup:
6a603a10 31static wxString LINKAGEMODE HtmlizeLinebreaks(const wxString& str)
83c9da45
VS
32{
33 wxString out;
6a603a10
VS
34 out.reserve(str.length()); // we'll certainly need at least that
35
7bf6f523
VS
36 const wxString::const_iterator end = str.end();
37 for ( wxString::const_iterator i = str.begin(); i != end; ++i )
83c9da45 38 {
f7b64fde 39 switch ( (*i).GetValue() )
83c9da45 40 {
6a603a10 41 case '<':
7bf6f523 42 while ( i != end && *i != '>' )
0ab8db38 43 {
f7b64fde 44 out << *i++;
0ab8db38 45 }
6a603a10 46 out << '>';
7bf6f523
VS
47 if ( i == end )
48 return out;
83c9da45 49 break;
9e570f83
VS
50
51 // We need to translate any line break into exactly one <br>.
52 // Quoting HTML spec: "A line break is defined to be a carriage
53 // return (&#x000D;), a line feed (&#x000A;), or a carriage
54 // return/line feed pair."
55 case '\r':
56 {
57 wxString::const_iterator j(i + 1);
58 if ( j != end && *j == '\n' )
59 i = j;
60 }
61 // fall through
6a603a10
VS
62 case '\n':
63 out << "<br>";
83c9da45 64 break;
9e570f83 65
83c9da45 66 default:
f7b64fde 67 out << *i;
83c9da45
VS
68 break;
69 }
70 }
7bf6f523 71
83c9da45
VS
72 return out;
73}
74
75
5526e819
VS
76//-----------------------------------------------------------------------------
77// The list handler:
78//-----------------------------------------------------------------------------
79
80
81TAG_HANDLER_BEGIN(PRE, "PRE")
fc7a2a60 82 TAG_HANDLER_CONSTR(PRE) { }
5526e819
VS
83
84 TAG_HANDLER_PROC(tag)
85 {
86 wxHtmlContainerCell *c;
87
6a603a10
VS
88 const int fixed = m_WParser->GetFontFixed();
89 const int italic = m_WParser->GetFontItalic();
90 const int underlined = m_WParser->GetFontUnderlined();
91 const int bold = m_WParser->GetFontBold();
92 const int fsize = m_WParser->GetFontSize();
93 const wxHtmlWinParser::WhitespaceMode whitespace =
94 m_WParser->GetWhitespaceMode();
5526e819 95
1309ba6c 96 c = m_WParser->GetContainer();
6a603a10 97 m_WParser->SetWhitespaceMode(wxHtmlWinParser::Whitespace_Pre);
d1da8872
WS
98 m_WParser->SetFontUnderlined(false);
99 m_WParser->SetFontBold(false);
100 m_WParser->SetFontItalic(false);
101 m_WParser->SetFontFixed(true);
4f9297b0
VS
102 m_WParser->SetFontSize(3);
103 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 104
1309ba6c
VS
105 m_WParser->CloseContainer();
106 c = m_WParser->OpenContainer();
69379916
VS
107 c->SetWidthFloat(tag);
108 c = m_WParser->OpenContainer();
1309ba6c 109 c->SetAlignHor(wxHTML_ALIGN_LEFT);
b3470d76 110 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
1309ba6c 111
e7feeafa 112 wxString srcMid = m_WParser->GetInnerSource(tag);
6a603a10
VS
113
114 // setting Whitespace_Pre mode takes care of spaces and TABs, but
115 // not linebreaks, so we have to translate them into <br> by
116 // calling HtmlizeLinebreaks() here
117 ParseInnerSource(HtmlizeLinebreaks(srcMid));
04dbb646 118
69379916 119 m_WParser->CloseContainer();
1309ba6c
VS
120 m_WParser->CloseContainer();
121 c = m_WParser->OpenContainer();
5526e819 122
6a603a10 123 m_WParser->SetWhitespaceMode(whitespace);
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