]> git.saurik.com Git - wxWidgets.git/blame - src/html/mod_pre.cpp
wxHW_* flags, fixed client area problem
[wxWidgets.git] / src / html / mod_pre.cpp
CommitLineData
5526e819
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: mod_pre.cpp
3// Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4// Author: Vaclav Slavik
5// Copyright: (c) 1999 Vaclav Slavik
6// Licence: wxWindows Licence
7/////////////////////////////////////////////////////////////////////////////
8
3364ab79
RS
9#ifdef __GNUG__
10#pragma implementation
11#endif
12
13#include <wx/wxprec.h>
14
5526e819 15#if wxUSE_HTML
3364ab79
RS
16#ifdef __BORDLANDC__
17#pragma hdrstop
18#endif
19
20#ifndef WXPRECOMP
21#include <wx/wx.h>
22#endif
23
5526e819
VS
24
25#include <wx/html/forcelink.h>
26#include <wx/html/mod_templ.h>
27
28#include <wx/html/htmlcell.h>
29#include <wx/tokenzr.h>
30
31FORCE_LINK_ME(mod_pre)
32
33
34//-----------------------------------------------------------------------------
35// wxHtmlCodeCell
36//-----------------------------------------------------------------------------
37
38class wxHtmlPRECell : public wxHtmlCell
39{
40 private:
41 wxString** m_Text;
42 // list of wxString objects.
43 int m_LinesCnt;
44 // number of lines
45 int m_LineHeight;
46 // height of single line of text
47
48 public:
49 wxHtmlPRECell(const wxString& s, wxDC& dc);
50 ~wxHtmlPRECell();
51 void Draw(wxDC& dc, int x, int y, int view_y1, int view_y2);
52};
53
54
55wxHtmlPRECell::wxHtmlPRECell(const wxString& s, wxDC& dc) : wxHtmlCell()
56{
57 wxStringTokenizer tokenizer(s, "\n");
58 wxString tmp;
59 long int x, z;
60 int i;
61
62 m_LineHeight = dc.GetCharHeight();
63 m_LinesCnt = 0;
64 m_Text = NULL;
65 m_Width = m_Height = 0;
66
67 i = 0;
68#if (wxVERSION_NUMBER < 2100)
69 while (tokenizer.HasMoreToken()) {
70#else
71 while (tokenizer.HasMoreTokens()) {
72#endif
73 if (i % 10 == 0) m_Text = (wxString**) realloc(m_Text, sizeof(wxString*) * (i + 10));
74 tmp = tokenizer.NextToken();
75 tmp.Replace("&nbsp;", " ", TRUE);
76 tmp.Replace("&quot;", "\"", TRUE);
77 tmp.Replace("&lt;", "<", TRUE);
78 tmp.Replace("&gt;", ">", TRUE);
79 tmp.Replace("&amp;", "&", TRUE);
80 tmp.Replace("\t", " ", TRUE);
81 tmp.Replace("\r", "", TRUE);
82 m_Text[i++] = new wxString(tmp);
83
84 dc.GetTextExtent(tmp, &x, &z, &z);
85 if (x > m_Width) m_Width = x;
86 m_Height += m_LineHeight;
87 m_LinesCnt++;
88 }
89}
90
91
92
93wxHtmlPRECell::~wxHtmlPRECell()
94{
95 for (int i = 0; i < m_LinesCnt; i++) delete m_Text[i];
96 free(m_Text);
97}
98
99
100void wxHtmlPRECell::Draw(wxDC& dc, int x, int y, int view_y1, int view_y2)
101{
102 for (int i = 0; i < m_LinesCnt; i++)
103 dc.DrawText(*(m_Text[i]), x + m_PosX, y + m_PosY + m_LineHeight * i);
104
105 wxHtmlCell::Draw(dc, x, y, view_y1, view_y2);
106}
107
108
109
110
111//-----------------------------------------------------------------------------
112// The list handler:
113//-----------------------------------------------------------------------------
114
115
116TAG_HANDLER_BEGIN(PRE, "PRE")
117
118 TAG_HANDLER_PROC(tag)
119 {
120 wxHtmlContainerCell *c;
121
122 int fixed = m_WParser -> GetFontFixed(),
123 italic = m_WParser -> GetFontItalic(),
124 underlined = m_WParser -> GetFontUnderlined(),
125 bold = m_WParser -> GetFontBold(),
126 fsize = m_WParser -> GetFontSize();
127
128 m_WParser -> CloseContainer();
129 c = m_WParser -> OpenContainer();
130 c -> SetAlignHor(HTML_ALIGN_LEFT);
131 c -> SetIndent(m_WParser -> GetCharHeight(), HTML_INDENT_VERTICAL);
132
133 m_WParser -> SetFontUnderlined(FALSE);
134 m_WParser -> SetFontBold(FALSE);
135 m_WParser -> SetFontItalic(FALSE);
136 m_WParser -> SetFontFixed(TRUE);
137 m_WParser -> SetFontSize(0);
138 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
139
140 {
141 wxString cit;
142 cit = m_WParser -> GetSource() -> Mid(tag.GetBeginPos(), tag.GetEndPos1() - tag.GetBeginPos());
143 c -> InsertCell(new wxHtmlPRECell(cit, *(m_WParser -> GetDC())));
144 }
145
146 m_WParser -> SetFontUnderlined(underlined);
147 m_WParser -> SetFontBold(bold);
148 m_WParser -> SetFontItalic(italic);
149 m_WParser -> SetFontFixed(fixed);
150 m_WParser -> SetFontSize(fsize);
151 c -> InsertCell(new wxHtmlFontCell(m_WParser -> CreateCurrentFont()));
152
153 m_WParser -> CloseContainer();
154 m_WParser -> OpenContainer();
155 return TRUE;
156 }
157
158TAG_HANDLER_END(PRE)
159
160
161
162
163
164TAGS_MODULE_BEGIN(Pre)
165
166 TAGS_MODULE_ADD(PRE)
167
168TAGS_MODULE_END(Pre)
169
170#endif