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