]>
git.saurik.com Git - wxWidgets.git/blob - src/html/m_pre.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
11 #pragma implementation
14 #include <wx/wxprec.h>
26 #include "wx/html/forcelnk.h"
27 #include "wx/html/m_templ.h"
29 #include "wx/html/htmlcell.h"
30 #include <wx/tokenzr.h>
32 FORCE_LINK_ME(mod_pre
)
35 //-----------------------------------------------------------------------------
37 //-----------------------------------------------------------------------------
39 class wxHtmlPRECell
: public wxHtmlCell
43 // list of wxString objects.
47 // height of single line of text
50 wxHtmlPRECell(const wxString
& s
, wxDC
& dc
);
52 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
56 wxHtmlPRECell::wxHtmlPRECell(const wxString
& s
, wxDC
& dc
) : wxHtmlCell()
58 wxStringTokenizer
tokenizer(s
, "\n");
63 m_LineHeight
= dc
.GetCharHeight();
66 m_Width
= m_Height
= 0;
69 while (tokenizer
.HasMoreTokens()) {
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
);
81 dc
.GetTextExtent(tmp
, &x
, &z
, &z
);
82 if (x
> m_Width
) m_Width
= x
;
83 m_Height
+= m_LineHeight
;
90 wxHtmlPRECell::~wxHtmlPRECell()
92 for (int i
= 0; i
< m_LinesCnt
; i
++) delete m_Text
[i
];
97 void wxHtmlPRECell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
99 for (int i
= 0; i
< m_LinesCnt
; i
++)
100 dc
.DrawText(*(m_Text
[i
]), x
+ m_PosX
, y
+ m_PosY
+ m_LineHeight
* i
);
102 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
108 //-----------------------------------------------------------------------------
110 //-----------------------------------------------------------------------------
113 TAG_HANDLER_BEGIN(PRE
, "PRE")
115 TAG_HANDLER_PROC(tag
)
117 wxHtmlContainerCell
*c
;
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();
125 m_WParser
-> CloseContainer();
126 c
= m_WParser
-> OpenContainer();
127 c
-> SetAlignHor(HTML_ALIGN_LEFT
);
128 c
-> SetIndent(m_WParser
-> GetCharHeight(), HTML_INDENT_VERTICAL
);
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()));
139 cit
= m_WParser
-> GetSource() -> Mid(tag
.GetBeginPos(), tag
.GetEndPos1() - tag
.GetBeginPos());
140 c
-> InsertCell(new wxHtmlPRECell(cit
, *(m_WParser
-> GetDC())));
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()));
150 m_WParser
-> CloseContainer();
151 m_WParser
-> OpenContainer();
161 TAGS_MODULE_BEGIN(Pre
)