]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_pre.cpp
Eliminate a warning
[wxWidgets.git] / src / html / m_pre.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_pre.cpp
3 // Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
9
10 #include "wx/wxprec.h"
11
12 #ifdef __BORLANDC__
13 #pragma hdrstop
14 #endif
15
16 #if wxUSE_HTML && wxUSE_STREAMS
17
18 #ifndef WX_PRECOMP
19 #endif
20
21 #include "wx/html/forcelnk.h"
22 #include "wx/html/m_templ.h"
23
24 #include "wx/html/htmlcell.h"
25 #include "wx/tokenzr.h"
26 #include "wx/encconv.h"
27
28 FORCE_LINK_ME(m_pre)
29
30 // replaces '\t', ' ' and '\n' with HTML markup:
31 static wxString LINKAGEMODE HtmlizeLinebreaks(const wxString& str)
32 {
33 wxString out;
34 out.reserve(str.length()); // we'll certainly need at least that
35
36 const wxString::const_iterator end = str.end();
37 for ( wxString::const_iterator i = str.begin(); i != end; ++i )
38 {
39 switch ( (*i).GetValue() )
40 {
41 case '<':
42 while ( i != end && *i != '>' )
43 {
44 out << *i++;
45 }
46 out << '>';
47 if ( i == end )
48 return out;
49 break;
50 case '\n':
51 out << "<br>";
52 break;
53 default:
54 out << *i;
55 break;
56 }
57 }
58
59 return out;
60 }
61
62
63 //-----------------------------------------------------------------------------
64 // The list handler:
65 //-----------------------------------------------------------------------------
66
67
68 TAG_HANDLER_BEGIN(PRE, "PRE")
69 TAG_HANDLER_CONSTR(PRE) { }
70
71 TAG_HANDLER_PROC(tag)
72 {
73 wxHtmlContainerCell *c;
74
75 const int fixed = m_WParser->GetFontFixed();
76 const int italic = m_WParser->GetFontItalic();
77 const int underlined = m_WParser->GetFontUnderlined();
78 const int bold = m_WParser->GetFontBold();
79 const int fsize = m_WParser->GetFontSize();
80 const wxHtmlWinParser::WhitespaceMode whitespace =
81 m_WParser->GetWhitespaceMode();
82
83 c = m_WParser->GetContainer();
84 m_WParser->SetWhitespaceMode(wxHtmlWinParser::Whitespace_Pre);
85 m_WParser->SetFontUnderlined(false);
86 m_WParser->SetFontBold(false);
87 m_WParser->SetFontItalic(false);
88 m_WParser->SetFontFixed(true);
89 m_WParser->SetFontSize(3);
90 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
91
92 m_WParser->CloseContainer();
93 c = m_WParser->OpenContainer();
94 c->SetWidthFloat(tag);
95 c = m_WParser->OpenContainer();
96 c->SetAlignHor(wxHTML_ALIGN_LEFT);
97 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
98
99 wxString srcMid = m_WParser->GetInnerSource(tag);
100
101 // setting Whitespace_Pre mode takes care of spaces and TABs, but
102 // not linebreaks, so we have to translate them into <br> by
103 // calling HtmlizeLinebreaks() here
104 ParseInnerSource(HtmlizeLinebreaks(srcMid));
105
106 m_WParser->CloseContainer();
107 m_WParser->CloseContainer();
108 c = m_WParser->OpenContainer();
109
110 m_WParser->SetWhitespaceMode(whitespace);
111 m_WParser->SetFontUnderlined(underlined);
112 m_WParser->SetFontBold(bold);
113 m_WParser->SetFontItalic(italic);
114 m_WParser->SetFontFixed(fixed);
115 m_WParser->SetFontSize(fsize);
116 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
117
118 return true;
119 }
120
121 TAG_HANDLER_END(PRE)
122
123
124
125
126
127 TAGS_MODULE_BEGIN(Pre)
128
129 TAGS_MODULE_ADD(PRE)
130
131 TAGS_MODULE_END(Pre)
132
133 #endif