]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_pre.cpp
addind nonowned window implementation
[wxWidgets.git] / src / html / m_pre.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/html/m_pre.cpp
5526e819
VS
3// Purpose: wxHtml module for <PRE> ... </PRE> tag (code citation)
4// Author: Vaclav Slavik
69941f05 5// RCS-ID: $Id$
5526e819 6// Copyright: (c) 1999 Vaclav Slavik
65571936 7// Licence: wxWindows licence
5526e819
VS
8/////////////////////////////////////////////////////////////////////////////
9
3096bd2f 10#include "wx/wxprec.h"
3364ab79 11
2b5f62a0 12#ifdef __BORLANDC__
93763ad5 13 #pragma hdrstop
3364ab79
RS
14#endif
15
93763ad5
WS
16#if wxUSE_HTML && wxUSE_STREAMS
17
b4f4d3dd 18#ifndef WX_PRECOMP
3364ab79
RS
19#endif
20
69941f05
VS
21#include "wx/html/forcelnk.h"
22#include "wx/html/m_templ.h"
5526e819 23
69941f05 24#include "wx/html/htmlcell.h"
3096bd2f 25#include "wx/tokenzr.h"
57f59026 26#include "wx/encconv.h"
5526e819 27
c88293a4 28FORCE_LINK_ME(m_pre)
5526e819 29
83c9da45 30// replaces '\t', ' ' and '\n' with HTML markup:
9d59f1fc 31static wxString LINKAGEMODE HtmlizeWhitespaces(const wxString& str)
83c9da45
VS
32{
33 wxString out;
999836aa 34 size_t len = str.Len();
0ab8db38 35 size_t linepos = 0;
999836aa 36 for (size_t i = 0; i < len; i++)
83c9da45 37 {
c9f78968 38 switch ( str[i].GetValue() )
83c9da45
VS
39 {
40 case wxT('<'):
c0ce1b03 41 while (i < len && str[i] != wxT('>'))
0ab8db38 42 {
83c9da45 43 out << str[i++];
0ab8db38 44 }
83c9da45
VS
45 out << wxT('>');
46 break;
47 case wxT(' '):
48 out << wxT("&nbsp;");
0ab8db38 49 linepos++;
83c9da45
VS
50 break;
51 case wxT('\n'):
52 out << wxT("<br>");
0ab8db38 53 linepos = 0;
83c9da45
VS
54 break;
55 case wxT('\t'):
999836aa 56 {
0ab8db38 57 for (size_t j = 8 - linepos % 8; j > 0; j--)
999836aa 58 out << wxT("&nbsp;");
0ab8db38 59 linepos += 8 - linepos % 8;
999836aa 60 }
83c9da45
VS
61 break;
62 default:
63 out << str[i];
0ab8db38 64 linepos++;
83c9da45
VS
65 break;
66 }
67 }
68 return out;
69}
70
71
5526e819
VS
72//-----------------------------------------------------------------------------
73// The list handler:
74//-----------------------------------------------------------------------------
75
76
77TAG_HANDLER_BEGIN(PRE, "PRE")
fc7a2a60 78 TAG_HANDLER_CONSTR(PRE) { }
5526e819
VS
79
80 TAG_HANDLER_PROC(tag)
81 {
82 wxHtmlContainerCell *c;
83
4f9297b0
VS
84 int fixed = m_WParser->GetFontFixed(),
85 italic = m_WParser->GetFontItalic(),
86 underlined = m_WParser->GetFontUnderlined(),
87 bold = m_WParser->GetFontBold(),
88 fsize = m_WParser->GetFontSize();
5526e819 89
1309ba6c 90 c = m_WParser->GetContainer();
d1da8872
WS
91 m_WParser->SetFontUnderlined(false);
92 m_WParser->SetFontBold(false);
93 m_WParser->SetFontItalic(false);
94 m_WParser->SetFontFixed(true);
4f9297b0
VS
95 m_WParser->SetFontSize(3);
96 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 97
1309ba6c
VS
98 m_WParser->CloseContainer();
99 c = m_WParser->OpenContainer();
69379916
VS
100 c->SetWidthFloat(tag);
101 c = m_WParser->OpenContainer();
1309ba6c 102 c->SetAlignHor(wxHTML_ALIGN_LEFT);
b3470d76 103 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
1309ba6c 104
e7feeafa
VS
105 wxString srcMid = m_WParser->GetInnerSource(tag);
106 ParseInnerSource(HtmlizeWhitespaces(srcMid));
04dbb646 107
69379916 108 m_WParser->CloseContainer();
1309ba6c
VS
109 m_WParser->CloseContainer();
110 c = m_WParser->OpenContainer();
5526e819 111
4f9297b0
VS
112 m_WParser->SetFontUnderlined(underlined);
113 m_WParser->SetFontBold(bold);
114 m_WParser->SetFontItalic(italic);
115 m_WParser->SetFontFixed(fixed);
116 m_WParser->SetFontSize(fsize);
117 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819 118
d1da8872 119 return true;
5526e819
VS
120 }
121
122TAG_HANDLER_END(PRE)
123
124
125
126
127
128TAGS_MODULE_BEGIN(Pre)
129
130 TAGS_MODULE_ADD(PRE)
131
132TAGS_MODULE_END(Pre)
133
134#endif