]>
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 /////////////////////////////////////////////////////////////////////////////
12 #include <wx/html/forcelink.h>
13 #include <wx/html/mod_templ.h>
15 #include <wx/html/htmlcell.h>
16 #include <wx/tokenzr.h>
18 FORCE_LINK_ME(mod_pre
)
21 //-----------------------------------------------------------------------------
23 //-----------------------------------------------------------------------------
25 class wxHtmlPRECell
: public wxHtmlCell
29 // list of wxString objects.
33 // height of single line of text
36 wxHtmlPRECell(const wxString
& s
, wxDC
& dc
);
38 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
42 wxHtmlPRECell::wxHtmlPRECell(const wxString
& s
, wxDC
& dc
) : wxHtmlCell()
44 wxStringTokenizer
tokenizer(s
, "\n");
49 m_LineHeight
= dc
.GetCharHeight();
52 m_Width
= m_Height
= 0;
55 #if (wxVERSION_NUMBER < 2100)
56 while (tokenizer
.HasMoreToken()) {
58 while (tokenizer
.HasMoreTokens()) {
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
);
71 dc
.GetTextExtent(tmp
, &x
, &z
, &z
);
72 if (x
> m_Width
) m_Width
= x
;
73 m_Height
+= m_LineHeight
;
80 wxHtmlPRECell::~wxHtmlPRECell()
82 for (int i
= 0; i
< m_LinesCnt
; i
++) delete m_Text
[i
];
87 void wxHtmlPRECell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
89 for (int i
= 0; i
< m_LinesCnt
; i
++)
90 dc
.DrawText(*(m_Text
[i
]), x
+ m_PosX
, y
+ m_PosY
+ m_LineHeight
* i
);
92 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
98 //-----------------------------------------------------------------------------
100 //-----------------------------------------------------------------------------
103 TAG_HANDLER_BEGIN(PRE
, "PRE")
105 TAG_HANDLER_PROC(tag
)
107 wxHtmlContainerCell
*c
;
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();
115 m_WParser
-> CloseContainer();
116 c
= m_WParser
-> OpenContainer();
117 c
-> SetAlignHor(HTML_ALIGN_LEFT
);
118 c
-> SetIndent(m_WParser
-> GetCharHeight(), HTML_INDENT_VERTICAL
);
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()));
129 cit
= m_WParser
-> GetSource() -> Mid(tag
.GetBeginPos(), tag
.GetEndPos1() - tag
.GetBeginPos());
130 c
-> InsertCell(new wxHtmlPRECell(cit
, *(m_WParser
-> GetDC())));
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()));
140 m_WParser
-> CloseContainer();
141 m_WParser
-> OpenContainer();
151 TAGS_MODULE_BEGIN(Pre
)