]> git.saurik.com Git - wxWidgets.git/blob - src/html/m_pre.cpp
More details about the internal module name changes
[wxWidgets.git] / src / html / m_pre.cpp
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 #if defined(__GNUG__) && !defined(NO_GCC_PRAGMA)
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 len = str.Len();
39 for (size_t 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("&nbsp;");
50 break;
51 case wxT('\n'):
52 out << wxT("<br>");
53 break;
54 case wxT('\t'):
55 {
56 for (size_t j = 8 - i%8; j > 0; j--)
57 out << wxT("&nbsp;");
58 }
59 break;
60 default:
61 out << str[i];
62 break;
63 }
64 }
65 return out;
66 }
67
68
69 //-----------------------------------------------------------------------------
70 // The list handler:
71 //-----------------------------------------------------------------------------
72
73
74 TAG_HANDLER_BEGIN(PRE, "PRE")
75 TAG_HANDLER_CONSTR(PRE) { }
76
77 TAG_HANDLER_PROC(tag)
78 {
79 wxHtmlContainerCell *c;
80
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();
86
87 c = m_WParser->GetContainer();
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()));
94
95 m_WParser->CloseContainer();
96 c = m_WParser->OpenContainer();
97 c->SetWidthFloat(tag);
98 c = m_WParser->OpenContainer();
99 c->SetAlignHor(wxHTML_ALIGN_LEFT);
100 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
101
102 wxString srcMid =
103 m_WParser->GetSource()->Mid(tag.GetBeginPos(),
104 tag.GetEndPos1() - tag.GetBeginPos());
105 // It is safe to temporarily change the source being parsed,
106 // provided we restore the state back after parsing
107 m_Parser->SetSourceAndSaveState(HtmlizeWhitespaces(srcMid));
108 m_Parser->DoParsing();
109 m_Parser->RestoreState();
110
111 m_WParser->CloseContainer();
112 m_WParser->CloseContainer();
113 c = m_WParser->OpenContainer();
114
115 m_WParser->SetFontUnderlined(underlined);
116 m_WParser->SetFontBold(bold);
117 m_WParser->SetFontItalic(italic);
118 m_WParser->SetFontFixed(fixed);
119 m_WParser->SetFontSize(fsize);
120 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
121
122 return TRUE;
123 }
124
125 TAG_HANDLER_END(PRE)
126
127
128
129
130
131 TAGS_MODULE_BEGIN(Pre)
132
133 TAGS_MODULE_ADD(PRE)
134
135 TAGS_MODULE_END(Pre)
136
137 #endif