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