1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_pre.cpp
3 // Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_HTML && wxUSE_STREAMS
20 #include "wx/html/forcelnk.h"
21 #include "wx/html/m_templ.h"
23 #include "wx/html/htmlcell.h"
24 #include "wx/tokenzr.h"
25 #include "wx/encconv.h"
29 // replaces '\t', ' ' and '\n' with HTML markup:
30 static wxString LINKAGEMODE
HtmlizeLinebreaks(const wxString
& str
)
33 out
.reserve(str
.length()); // we'll certainly need at least that
35 const wxString::const_iterator end
= str
.end();
36 for ( wxString::const_iterator i
= str
.begin(); i
!= end
; ++i
)
38 switch ( (*i
).GetValue() )
41 while ( i
!= end
&& *i
!= '>' )
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 (
), a line feed (
), or a carriage
53 // return/line feed pair."
56 wxString::const_iterator
j(i
+ 1);
57 if ( j
!= end
&& *j
== '\n' )
75 //-----------------------------------------------------------------------------
77 //-----------------------------------------------------------------------------
80 TAG_HANDLER_BEGIN(PRE
, "PRE")
81 TAG_HANDLER_CONSTR(PRE
) { }
85 wxHtmlContainerCell
*c
;
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();
95 c
= m_WParser
->GetContainer();
96 m_WParser
->SetWhitespaceMode(wxHtmlWinParser::Whitespace_Pre
);
97 m_WParser
->SetFontUnderlined(false);
98 m_WParser
->SetFontBold(false);
99 m_WParser
->SetFontItalic(false);
100 m_WParser
->SetFontFixed(true);
101 m_WParser
->SetFontSize(3);
102 c
->InsertCell(new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
104 m_WParser
->CloseContainer();
105 c
= m_WParser
->OpenContainer();
106 c
->SetWidthFloat(tag
);
107 c
= m_WParser
->OpenContainer();
108 c
->SetAlignHor(wxHTML_ALIGN_LEFT
);
109 c
->SetIndent(m_WParser
->GetCharHeight(), wxHTML_INDENT_TOP
);
111 wxString srcMid
= m_WParser
->GetInnerSource(tag
);
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
));
118 m_WParser
->CloseContainer();
119 m_WParser
->CloseContainer();
120 c
= m_WParser
->OpenContainer();
122 m_WParser
->SetWhitespaceMode(whitespace
);
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()));
139 TAGS_MODULE_BEGIN(Pre
)