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