]>
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 #if (wxVERSION_NUMBER < 2100)
70 while (tokenizer
.HasMoreToken()) {
72 while (tokenizer
.HasMoreTokens()) {
74 if (i
% 10 == 0) m_Text
= (wxString
**) realloc(m_Text
, sizeof(wxString
*) * (i
+ 10));
75 tmp
= tokenizer
.NextToken();
76 tmp
.Replace(" ", " ", TRUE
);
77 tmp
.Replace(""", "\"", TRUE
);
78 tmp
.Replace("<", "<", TRUE
);
79 tmp
.Replace(">", ">", TRUE
);
80 tmp
.Replace("&", "&", TRUE
);
81 tmp
.Replace("\t", " ", TRUE
);
82 tmp
.Replace("\r", "", TRUE
);
83 m_Text
[i
++] = new wxString(tmp
);
85 dc
.GetTextExtent(tmp
, &x
, &z
, &z
);
86 if (x
> m_Width
) m_Width
= x
;
87 m_Height
+= m_LineHeight
;
94 wxHtmlPRECell::~wxHtmlPRECell()
96 for (int i
= 0; i
< m_LinesCnt
; i
++) delete m_Text
[i
];
101 void wxHtmlPRECell::Draw(wxDC
& dc
, int x
, int y
, int view_y1
, int view_y2
)
103 for (int i
= 0; i
< m_LinesCnt
; i
++)
104 dc
.DrawText(*(m_Text
[i
]), x
+ m_PosX
, y
+ m_PosY
+ m_LineHeight
* i
);
106 wxHtmlCell::Draw(dc
, x
, y
, view_y1
, view_y2
);
112 //-----------------------------------------------------------------------------
114 //-----------------------------------------------------------------------------
117 TAG_HANDLER_BEGIN(PRE
, "PRE")
119 TAG_HANDLER_PROC(tag
)
121 wxHtmlContainerCell
*c
;
123 int fixed
= m_WParser
-> GetFontFixed(),
124 italic
= m_WParser
-> GetFontItalic(),
125 underlined
= m_WParser
-> GetFontUnderlined(),
126 bold
= m_WParser
-> GetFontBold(),
127 fsize
= m_WParser
-> GetFontSize();
129 m_WParser
-> CloseContainer();
130 c
= m_WParser
-> OpenContainer();
131 c
-> SetAlignHor(HTML_ALIGN_LEFT
);
132 c
-> SetIndent(m_WParser
-> GetCharHeight(), HTML_INDENT_VERTICAL
);
134 m_WParser
-> SetFontUnderlined(FALSE
);
135 m_WParser
-> SetFontBold(FALSE
);
136 m_WParser
-> SetFontItalic(FALSE
);
137 m_WParser
-> SetFontFixed(TRUE
);
138 m_WParser
-> SetFontSize(0);
139 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
143 cit
= m_WParser
-> GetSource() -> Mid(tag
.GetBeginPos(), tag
.GetEndPos1() - tag
.GetBeginPos());
144 c
-> InsertCell(new wxHtmlPRECell(cit
, *(m_WParser
-> GetDC())));
147 m_WParser
-> SetFontUnderlined(underlined
);
148 m_WParser
-> SetFontBold(bold
);
149 m_WParser
-> SetFontItalic(italic
);
150 m_WParser
-> SetFontFixed(fixed
);
151 m_WParser
-> SetFontSize(fsize
);
152 c
-> InsertCell(new wxHtmlFontCell(m_WParser
-> CreateCurrentFont()));
154 m_WParser
-> CloseContainer();
155 m_WParser
-> OpenContainer();
165 TAGS_MODULE_BEGIN(Pre
)