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