]>
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>
27 #include "wx/html/forcelnk.h"
28 #include "wx/html/m_templ.h"
30 #include "wx/html/htmlcell.h"
31 #include <wx/tokenzr.h>
33 FORCE_LINK_ME(mod_pre
)
36 //-----------------------------------------------------------------------------
38 //-----------------------------------------------------------------------------
40 class wxHtmlPRECell
: public wxHtmlCell
44 // list of wxString objects.
48 // height of single line of text
51 wxHtmlPRECell(const wxString
& s
, wxDC
& dc
);
53 void Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
);
57 wxHtmlPRECell::wxHtmlPRECell(const wxString
& s
, wxDC
& dc
) : wxHtmlCell()
59 wxStringTokenizer
tokenizer(s
, "\n");
64 m_LineHeight
= dc
.GetCharHeight();
67 m_Width
= m_Height
= 0;
70 while (tokenizer
.HasMoreTokens()) {
71 if (i
% 10 == 0) m_Text
= (wxString
**) realloc(m_Text
, sizeof(wxString
*) * (i
+ 10));
72 tmp
= tokenizer
.NextToken();
73 tmp
.Replace(" ", " ", TRUE
);
74 tmp
.Replace(""", "\"", TRUE
);
75 tmp
.Replace("<", "<", TRUE
);
76 tmp
.Replace(">", ">", TRUE
);
77 tmp
.Replace("&", "&", TRUE
);
78 tmp
.Replace("\t", " ", TRUE
);
79 tmp
.Replace("\r", "", TRUE
);
80 m_Text
[i
++] = new wxString(tmp
);
82 dc
.GetTextExtent(tmp
, &x
, &z
, &z
);
83 if (x
> m_Width
) m_Width
= x
;
84 m_Height
+= m_LineHeight
;
91 wxHtmlPRECell::~wxHtmlPRECell()
93 for (int i
= 0; i
< m_LinesCnt
; i
++) delete m_Text
[i
];
98 void wxHtmlPRECell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
100 for (int i
= 0; i
< m_LinesCnt
; i
++)
101 dc
.DrawText(*(m_Text
[i
]), x
+ m_PosX
, y
+ m_PosY
+ m_LineHeight
* i
);
103 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
109 //-----------------------------------------------------------------------------
111 //-----------------------------------------------------------------------------
114 TAG_HANDLER_BEGIN(PRE
, "PRE")
116 TAG_HANDLER_PROC(tag
)
118 wxHtmlContainerCell
*c
;
120 int fixed
= m_WParser
-> GetFontFixed(),
121 italic
= m_WParser
-> GetFontItalic(),
122 underlined
= m_WParser
-> GetFontUnderlined(),
123 bold
= m_WParser
-> GetFontBold(),
124 fsize
= m_WParser
-> GetFontSize();
126 m_WParser
-> CloseContainer();
127 c
= m_WParser
-> OpenContainer();
128 c
-> SetAlignHor(wxHTML_ALIGN_LEFT
);
129 c
-> SetIndent(m_WParser
-> GetCharHeight(), wxHTML_INDENT_VERTICAL
);
131 m_WParser
-> SetFontUnderlined(FALSE
);
132 m_WParser
-> SetFontBold(FALSE
);
133 m_WParser
-> SetFontItalic(FALSE
);
134 m_WParser
-> SetFontFixed(TRUE
);
135 m_WParser
-> SetFontSize(0);
136 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
140 cit
= m_WParser
-> GetSource() -> Mid(tag
.GetBeginPos(), tag
.GetEndPos1() - tag
.GetBeginPos());
141 c
-> InsertCell(new wxHtmlPRECell(cit
, *(m_WParser
-> GetDC())));
144 m_WParser
-> SetFontUnderlined(underlined
);
145 m_WParser
-> SetFontBold(bold
);
146 m_WParser
-> SetFontItalic(italic
);
147 m_WParser
-> SetFontFixed(fixed
);
148 m_WParser
-> SetFontSize(fsize
);
149 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
151 m_WParser
-> CloseContainer();
152 m_WParser
-> OpenContainer();
162 TAGS_MODULE_BEGIN(Pre
)