]>
Commit | Line | Data |
---|---|---|
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 | ||
3096bd2f | 10 | #include "wx/wxprec.h" |
3364ab79 | 11 | |
314260fb | 12 | #include "wx/defs.h" |
f6bcfd97 | 13 | #if wxUSE_HTML && wxUSE_STREAMS |
2b5f62a0 | 14 | #ifdef __BORLANDC__ |
3364ab79 RS |
15 | #pragma hdrstop |
16 | #endif | |
17 | ||
18 | #ifndef WXPRECOMP | |
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 | 28 | FORCE_LINK_ME(m_pre) |
5526e819 | 29 | |
83c9da45 | 30 | // replaces '\t', ' ' and '\n' with HTML markup: |
9d59f1fc | 31 | static wxString LINKAGEMODE HtmlizeWhitespaces(const wxString& str) |
83c9da45 VS |
32 | { |
33 | wxString out; | |
999836aa | 34 | size_t len = str.Len(); |
0ab8db38 | 35 | size_t linepos = 0; |
999836aa | 36 | for (size_t i = 0; i < len; i++) |
83c9da45 VS |
37 | { |
38 | switch (str[i]) | |
39 | { | |
40 | case wxT('<'): | |
c0ce1b03 | 41 | while (i < len && str[i] != wxT('>')) |
0ab8db38 | 42 | { |
83c9da45 | 43 | out << str[i++]; |
0ab8db38 VS |
44 | linepos++; |
45 | } | |
83c9da45 | 46 | out << wxT('>'); |
0ab8db38 | 47 | linepos++; |
83c9da45 VS |
48 | break; |
49 | case wxT(' '): | |
50 | out << wxT(" "); | |
0ab8db38 | 51 | linepos++; |
83c9da45 VS |
52 | break; |
53 | case wxT('\n'): | |
54 | out << wxT("<br>"); | |
0ab8db38 | 55 | linepos = 0; |
83c9da45 VS |
56 | break; |
57 | case wxT('\t'): | |
999836aa | 58 | { |
0ab8db38 | 59 | for (size_t j = 8 - linepos % 8; j > 0; j--) |
999836aa | 60 | out << wxT(" "); |
0ab8db38 | 61 | linepos += 8 - linepos % 8; |
999836aa | 62 | } |
83c9da45 VS |
63 | break; |
64 | default: | |
65 | out << str[i]; | |
0ab8db38 | 66 | linepos++; |
83c9da45 VS |
67 | break; |
68 | } | |
69 | } | |
70 | return out; | |
71 | } | |
72 | ||
73 | ||
5526e819 VS |
74 | //----------------------------------------------------------------------------- |
75 | // The list handler: | |
76 | //----------------------------------------------------------------------------- | |
77 | ||
78 | ||
79 | TAG_HANDLER_BEGIN(PRE, "PRE") | |
fc7a2a60 | 80 | TAG_HANDLER_CONSTR(PRE) { } |
5526e819 VS |
81 | |
82 | TAG_HANDLER_PROC(tag) | |
83 | { | |
84 | wxHtmlContainerCell *c; | |
85 | ||
4f9297b0 VS |
86 | int fixed = m_WParser->GetFontFixed(), |
87 | italic = m_WParser->GetFontItalic(), | |
88 | underlined = m_WParser->GetFontUnderlined(), | |
89 | bold = m_WParser->GetFontBold(), | |
90 | fsize = m_WParser->GetFontSize(); | |
5526e819 | 91 | |
1309ba6c | 92 | c = m_WParser->GetContainer(); |
d1da8872 WS |
93 | m_WParser->SetFontUnderlined(false); |
94 | m_WParser->SetFontBold(false); | |
95 | m_WParser->SetFontItalic(false); | |
96 | m_WParser->SetFontFixed(true); | |
4f9297b0 VS |
97 | m_WParser->SetFontSize(3); |
98 | c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
5526e819 | 99 | |
1309ba6c VS |
100 | m_WParser->CloseContainer(); |
101 | c = m_WParser->OpenContainer(); | |
69379916 VS |
102 | c->SetWidthFloat(tag); |
103 | c = m_WParser->OpenContainer(); | |
1309ba6c | 104 | c->SetAlignHor(wxHTML_ALIGN_LEFT); |
b3470d76 | 105 | c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP); |
1309ba6c | 106 | |
c0ce1b03 | 107 | wxString srcMid = |
211dfedd VS |
108 | m_WParser->GetSource()->Mid(tag.GetBeginPos(), |
109 | tag.GetEndPos1() - tag.GetBeginPos()); | |
1309ba6c VS |
110 | // It is safe to temporarily change the source being parsed, |
111 | // provided we restore the state back after parsing | |
83c9da45 | 112 | m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid)); |
1309ba6c | 113 | m_Parser->DoParsing(); |
211dfedd | 114 | m_Parser->RestoreState(); |
04dbb646 | 115 | |
69379916 | 116 | m_WParser->CloseContainer(); |
1309ba6c VS |
117 | m_WParser->CloseContainer(); |
118 | c = m_WParser->OpenContainer(); | |
5526e819 | 119 | |
4f9297b0 VS |
120 | m_WParser->SetFontUnderlined(underlined); |
121 | m_WParser->SetFontBold(bold); | |
122 | m_WParser->SetFontItalic(italic); | |
123 | m_WParser->SetFontFixed(fixed); | |
124 | m_WParser->SetFontSize(fsize); | |
125 | c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
5526e819 | 126 | |
d1da8872 | 127 | return true; |
5526e819 VS |
128 | } |
129 | ||
130 | TAG_HANDLER_END(PRE) | |
131 | ||
132 | ||
133 | ||
134 | ||
135 | ||
136 | TAGS_MODULE_BEGIN(Pre) | |
137 | ||
138 | TAGS_MODULE_ADD(PRE) | |
139 | ||
140 | TAGS_MODULE_END(Pre) | |
141 | ||
142 | #endif |