]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_pre.cpp
Rewritten wxList docs
[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 HtmlizeWhitespaces(const wxString& str)
32 {
33 wxString out;
34 size_t len = str.Len();
35 size_t linepos = 0;
36 for (size_t i = 0; i < len; i++)
37 {
38 switch ( str[i].GetValue() )
39 {
40 case wxT('<'):
41 while (i < len && str[i] != wxT('>'))
42 {
43 out << str[i++];
44 linepos++;
45 }
46 out << wxT('>');
47 linepos++;
48 break;
49 case wxT(' '):
50 out << wxT("&nbsp;");
51 linepos++;
52 break;
53 case wxT('\n'):
54 out << wxT("<br>");
55 linepos = 0;
56 break;
57 case wxT('\t'):
58 {
59 for (size_t j = 8 - linepos % 8; j > 0; j--)
60 out << wxT("&nbsp;");
61 linepos += 8 - linepos % 8;
62 }
63 break;
64 default:
65 out << str[i];
66 linepos++;
67 break;
68 }
69 }
70 return out;
71 }
72
73
74 //-----------------------------------------------------------------------------
75 // The list handler:
76 //-----------------------------------------------------------------------------
77
78
79 TAG_HANDLER_BEGIN(PRE, "PRE")
80 TAG_HANDLER_CONSTR(PRE) { }
81
82 TAG_HANDLER_PROC(tag)
83 {
84 wxHtmlContainerCell *c;
85
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();
91
92 c = m_WParser->GetContainer();
93 m_WParser->SetFontUnderlined(false);
94 m_WParser->SetFontBold(false);
95 m_WParser->SetFontItalic(false);
96 m_WParser->SetFontFixed(true);
97 m_WParser->SetFontSize(3);
98 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
99
100 m_WParser->CloseContainer();
101 c = m_WParser->OpenContainer();
102 c->SetWidthFloat(tag);
103 c = m_WParser->OpenContainer();
104 c->SetAlignHor(wxHTML_ALIGN_LEFT);
105 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
106
107 wxString srcMid = m_WParser->GetInnerSource(tag);
108 ParseInnerSource(HtmlizeWhitespaces(srcMid));
109
110 m_WParser->CloseContainer();
111 m_WParser->CloseContainer();
112 c = m_WParser->OpenContainer();
113
114 m_WParser->SetFontUnderlined(underlined);
115 m_WParser->SetFontBold(bold);
116 m_WParser->SetFontItalic(italic);
117 m_WParser->SetFontFixed(fixed);
118 m_WParser->SetFontSize(fsize);
119 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
120
121 return true;
122 }
123
124 TAG_HANDLER_END(PRE)
125
126
127
128
129
130 TAGS_MODULE_BEGIN(Pre)
131
132 TAGS_MODULE_ADD(PRE)
133
134 TAGS_MODULE_END(Pre)
135
136 #endif