]>
git.saurik.com Git - wxWidgets.git/blob - src/html/mod_pre.cpp
1 /////////////////////////////////////////////////////////////////////////////
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 /////////////////////////////////////////////////////////////////////////////
10 #pragma implementation
13 #include <wx/wxprec.h>
25 #include <wx/html/forcelink.h>
26 #include <wx/html/mod_templ.h>
28 #include <wx/html/htmlcell.h>
29 #include <wx/tokenzr.h>
31 FORCE_LINK_ME(mod_pre
)
34 //-----------------------------------------------------------------------------
36 //-----------------------------------------------------------------------------
38 class wxHtmlPRECell
: public wxHtmlCell
42 // list of wxString objects.
46 // height of single line of text
49 wxHtmlPRECell(const wxString
& s
, wxDC
& dc
);
51 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
55 wxHtmlPRECell::wxHtmlPRECell(const wxString
& s
, wxDC
& dc
) : wxHtmlCell()
57 wxStringTokenizer
tokenizer(s
, "\n");
62 m_LineHeight
= dc
.GetCharHeight();
65 m_Width
= m_Height
= 0;
68 #if (wxVERSION_NUMBER < 2100)
69 while (tokenizer
.HasMoreToken()) {
71 while (tokenizer
.HasMoreTokens()) {
73 if (i
% 10 == 0) m_Text
= (wxString
**) realloc(m_Text
, sizeof(wxString
*) * (i
+ 10));
74 tmp
= tokenizer
.NextToken();
75 tmp
.Replace(" ", " ", TRUE
);
76 tmp
.Replace(""", "\"", TRUE
);
77 tmp
.Replace("<", "<", TRUE
);
78 tmp
.Replace(">", ">", TRUE
);
79 tmp
.Replace("&", "&", TRUE
);
80 tmp
.Replace("\t", " ", TRUE
);
81 tmp
.Replace("\r", "", TRUE
);
82 m_Text
[i
++] = new wxString(tmp
);
84 dc
.GetTextExtent(tmp
, &x
, &z
, &z
);
85 if (x
> m_Width
) m_Width
= x
;
86 m_Height
+= m_LineHeight
;
93 wxHtmlPRECell::~wxHtmlPRECell()
95 for (int i
= 0; i
< m_LinesCnt
; i
++) delete m_Text
[i
];
100 void wxHtmlPRECell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
102 for (int i
= 0; i
< m_LinesCnt
; i
++)
103 dc
.DrawText(*(m_Text
[i
]), x
+ m_PosX
, y
+ m_PosY
+ m_LineHeight
* i
);
105 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
111 //-----------------------------------------------------------------------------
113 //-----------------------------------------------------------------------------
116 TAG_HANDLER_BEGIN(PRE
, "PRE")
118 TAG_HANDLER_PROC(tag
)
120 wxHtmlContainerCell
*c
;
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();
128 m_WParser
-> CloseContainer();
129 c
= m_WParser
-> OpenContainer();
130 c
-> SetAlignHor(HTML_ALIGN_LEFT
);
131 c
-> SetIndent(m_WParser
-> GetCharHeight(), HTML_INDENT_VERTICAL
);
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()));
142 cit
= m_WParser
-> GetSource() -> Mid(tag
.GetBeginPos(), tag
.GetEndPos1() - tag
.GetBeginPos());
143 c
-> InsertCell(new wxHtmlPRECell(cit
, *(m_WParser
-> GetDC())));
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()));
153 m_WParser
-> CloseContainer();
154 m_WParser
-> OpenContainer();
164 TAGS_MODULE_BEGIN(Pre
)