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