]>
Commit | Line | Data |
---|---|---|
1 | ///////////////////////////////////////////////////////////////////////////// | |
2 | // Name: 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 | #ifdef __GNUG__ | |
11 | #pragma implementation | |
12 | #endif | |
13 | ||
14 | #include "wx/wxprec.h" | |
15 | ||
16 | #include "wx/defs.h" | |
17 | #if wxUSE_HTML && wxUSE_STREAMS | |
18 | #ifdef __BORLANDC__ | |
19 | #pragma hdrstop | |
20 | #endif | |
21 | ||
22 | #ifndef WXPRECOMP | |
23 | #endif | |
24 | ||
25 | #include "wx/html/forcelnk.h" | |
26 | #include "wx/html/m_templ.h" | |
27 | ||
28 | #include "wx/html/htmlcell.h" | |
29 | #include "wx/tokenzr.h" | |
30 | #include "wx/encconv.h" | |
31 | ||
32 | FORCE_LINK_ME(m_pre) | |
33 | ||
34 | // replaces '\t', ' ' and '\n' with HTML markup: | |
35 | static wxString LINKAGEMODE HtmlizeWhitespaces(const wxString& str) | |
36 | { | |
37 | wxString out; | |
38 | size_t i = 0, j = 0, len = str.Len(); | |
39 | for (i = 0; i < len; i++) | |
40 | { | |
41 | switch (str[i]) | |
42 | { | |
43 | case wxT('<'): | |
44 | while (i < len && str[i] != wxT('>')) | |
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'): | |
55 | for (j = 8 - i%8; j > 0; j--) out << wxT(" "); | |
56 | break; | |
57 | default: | |
58 | out << str[i]; | |
59 | break; | |
60 | } | |
61 | } | |
62 | return out; | |
63 | } | |
64 | ||
65 | ||
66 | //----------------------------------------------------------------------------- | |
67 | // The list handler: | |
68 | //----------------------------------------------------------------------------- | |
69 | ||
70 | ||
71 | TAG_HANDLER_BEGIN(PRE, "PRE") | |
72 | TAG_HANDLER_CONSTR(PRE) { } | |
73 | ||
74 | TAG_HANDLER_PROC(tag) | |
75 | { | |
76 | wxHtmlContainerCell *c; | |
77 | ||
78 | int fixed = m_WParser->GetFontFixed(), | |
79 | italic = m_WParser->GetFontItalic(), | |
80 | underlined = m_WParser->GetFontUnderlined(), | |
81 | bold = m_WParser->GetFontBold(), | |
82 | fsize = m_WParser->GetFontSize(); | |
83 | ||
84 | c = m_WParser->GetContainer(); | |
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->SetAlignHor(wxHTML_ALIGN_LEFT); | |
95 | c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP); | |
96 | ||
97 | wxString srcMid = | |
98 | m_WParser->GetSource()->Mid(tag.GetBeginPos(), | |
99 | tag.GetEndPos1() - tag.GetBeginPos()); | |
100 | // It is safe to temporarily change the source being parsed, | |
101 | // provided we restore the state back after parsing | |
102 | m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid)); | |
103 | m_Parser->DoParsing(); | |
104 | m_Parser->RestoreState(); | |
105 | ||
106 | m_WParser->CloseContainer(); | |
107 | c = m_WParser->OpenContainer(); | |
108 | ||
109 | m_WParser->SetFontUnderlined(underlined); | |
110 | m_WParser->SetFontBold(bold); | |
111 | m_WParser->SetFontItalic(italic); | |
112 | m_WParser->SetFontFixed(fixed); | |
113 | m_WParser->SetFontSize(fsize); | |
114 | c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
115 | ||
116 | return TRUE; | |
117 | } | |
118 | ||
119 | TAG_HANDLER_END(PRE) | |
120 | ||
121 | ||
122 | ||
123 | ||
124 | ||
125 | TAGS_MODULE_BEGIN(Pre) | |
126 | ||
127 | TAGS_MODULE_ADD(PRE) | |
128 | ||
129 | TAGS_MODULE_END(Pre) | |
130 | ||
131 | #endif |