]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_fonts.cpp
use CanSetValueAs() instead of CanGetValueAs() in wxGridCellBoolEditor::EndEdit
[wxWidgets.git] / src / html / m_fonts.cpp
CommitLineData
5526e819 1/////////////////////////////////////////////////////////////////////////////
93763ad5 2// Name: src/html/m_fonts.cpp
5526e819
VS
3// Purpose: wxHtml module for fonts & colors of fonts
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"
5526e819 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"
f1ad10f3
VS
23#include "wx/fontenum.h"
24#include "wx/tokenzr.h"
5526e819 25
ef01b72f 26FORCE_LINK_ME(m_fonts)
5526e819
VS
27
28
2b5f62a0 29TAG_HANDLER_BEGIN(FONT, "FONT" )
5526e819 30
f1ad10f3 31 TAG_HANDLER_VARS
955c525d 32 wxArrayString m_Faces;
f1ad10f3 33
fc7a2a60
VZ
34 TAG_HANDLER_CONSTR(FONT) { }
35
5526e819
VS
36 TAG_HANDLER_PROC(tag)
37 {
4f9297b0
VS
38 wxColour oldclr = m_WParser->GetActualColor();
39 int oldsize = m_WParser->GetFontSize();
40 wxString oldface = m_WParser->GetFontFace();
5526e819 41
33ac7e6f 42 if (tag.HasParam(wxT("COLOR")))
04dbb646 43 {
5526e819 44 wxColour clr;
8bd72d90 45 if (tag.GetParamAsColour(wxT("COLOR"), &clr))
04dbb646 46 {
4f9297b0
VS
47 m_WParser->SetActualColor(clr);
48 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
e7ee65ed 49 }
5526e819
VS
50 }
51
33ac7e6f 52 if (tag.HasParam(wxT("SIZE")))
04dbb646 53 {
8bd72d90
VS
54 int tmp = 0;
55 wxChar c = tag.GetParam(wxT("SIZE")).GetChar(0);
56 if (tag.GetParamAsInt(wxT("SIZE"), &tmp))
04dbb646 57 {
8bd72d90 58 if (c == wxT('+') || c == wxT('-'))
4f9297b0 59 m_WParser->SetFontSize(oldsize+tmp);
2463329c 60 else
4f9297b0 61 m_WParser->SetFontSize(tmp);
8bd72d90
VS
62 m_WParser->GetContainer()->InsertCell(
63 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed 64 }
5526e819 65 }
33ac7e6f
KB
66
67 if (tag.HasParam(wxT("FACE")))
04dbb646 68 {
33ac7e6f 69 if (m_Faces.GetCount() == 0)
6540132f
VZ
70 m_Faces = wxFontEnumerator::GetFacenames();
71
8bd72d90 72 wxStringTokenizer tk(tag.GetParam(wxT("FACE")), wxT(","));
f1ad10f3 73 int index;
33ac7e6f
KB
74
75 while (tk.HasMoreTokens())
04dbb646 76 {
d1da8872 77 if ((index = m_Faces.Index(tk.GetNextToken(), false)) != wxNOT_FOUND)
04dbb646 78 {
4f9297b0
VS
79 m_WParser->SetFontFace(m_Faces[index]);
80 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
f1ad10f3
VS
81 break;
82 }
04dbb646 83 }
f1ad10f3 84 }
5526e819
VS
85
86 ParseInner(tag);
87
33ac7e6f 88 if (oldface != m_WParser->GetFontFace())
04dbb646 89 {
4f9297b0
VS
90 m_WParser->SetFontFace(oldface);
91 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
33ac7e6f
KB
92 }
93 if (oldsize != m_WParser->GetFontSize())
04dbb646 94 {
4f9297b0
VS
95 m_WParser->SetFontSize(oldsize);
96 m_WParser->GetContainer()->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
33ac7e6f
KB
97 }
98 if (oldclr != m_WParser->GetActualColor())
04dbb646 99 {
4f9297b0
VS
100 m_WParser->SetActualColor(oldclr);
101 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(oldclr));
5526e819 102 }
d1da8872 103 return true;
5526e819
VS
104 }
105
106TAG_HANDLER_END(FONT)
107
108
e7ee65ed 109TAG_HANDLER_BEGIN(FACES_U, "U,STRIKE")
5526e819 110
fc7a2a60
VZ
111 TAG_HANDLER_CONSTR(FACES_U) { }
112
5526e819
VS
113 TAG_HANDLER_PROC(tag)
114 {
4f9297b0 115 int underlined = m_WParser->GetFontUnderlined();
ef01b72f 116
d1da8872 117 m_WParser->SetFontUnderlined(true);
8bd72d90
VS
118 m_WParser->GetContainer()->InsertCell(
119 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
5526e819
VS
120
121 ParseInner(tag);
122
4f9297b0 123 m_WParser->SetFontUnderlined(underlined);
8bd72d90
VS
124 m_WParser->GetContainer()->InsertCell(
125 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 126 return true;
ef01b72f
VS
127 }
128
129TAG_HANDLER_END(FACES_U)
130
131
132
133
134TAG_HANDLER_BEGIN(FACES_B, "B,STRONG")
fc7a2a60 135 TAG_HANDLER_CONSTR(FACES_B) { }
ef01b72f
VS
136
137 TAG_HANDLER_PROC(tag)
138 {
4f9297b0 139 int bold = m_WParser->GetFontBold();
ef01b72f 140
d1da8872 141 m_WParser->SetFontBold(true);
8bd72d90
VS
142 m_WParser->GetContainer()->InsertCell(
143 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
144
145 ParseInner(tag);
146
4f9297b0 147 m_WParser->SetFontBold(bold);
8bd72d90
VS
148 m_WParser->GetContainer()->InsertCell(
149 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 150 return true;
ef01b72f
VS
151 }
152
153TAG_HANDLER_END(FACES_B)
154
155
156
157
e7ee65ed 158TAG_HANDLER_BEGIN(FACES_I, "I,EM,CITE,ADDRESS")
fc7a2a60 159 TAG_HANDLER_CONSTR(FACES_I) { }
ef01b72f
VS
160
161 TAG_HANDLER_PROC(tag)
162 {
4f9297b0 163 int italic = m_WParser->GetFontItalic();
ef01b72f 164
d1da8872 165 m_WParser->SetFontItalic(true);
8bd72d90
VS
166 m_WParser->GetContainer()->InsertCell(
167 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
168
169 ParseInner(tag);
170
4f9297b0 171 m_WParser->SetFontItalic(italic);
8bd72d90
VS
172 m_WParser->GetContainer()->InsertCell(
173 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 174 return true;
ef01b72f
VS
175 }
176
177TAG_HANDLER_END(FACES_I)
178
179
180
181
e7ee65ed 182TAG_HANDLER_BEGIN(FACES_TT, "TT,CODE,KBD,SAMP")
fc7a2a60 183 TAG_HANDLER_CONSTR(FACES_TT) { }
ef01b72f
VS
184
185 TAG_HANDLER_PROC(tag)
186 {
4f9297b0 187 int fixed = m_WParser->GetFontFixed();
ef01b72f 188
d1da8872 189 m_WParser->SetFontFixed(true);
8bd72d90
VS
190 m_WParser->GetContainer()->InsertCell(
191 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
ef01b72f
VS
192
193 ParseInner(tag);
194
4f9297b0 195 m_WParser->SetFontFixed(fixed);
8bd72d90
VS
196 m_WParser->GetContainer()->InsertCell(
197 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 198 return true;
5526e819
VS
199 }
200
ef01b72f 201TAG_HANDLER_END(FACES_TT)
5526e819
VS
202
203
204
205
206
207TAG_HANDLER_BEGIN(Hx, "H1,H2,H3,H4,H5,H6")
fc7a2a60 208 TAG_HANDLER_CONSTR(Hx) { }
5526e819
VS
209
210 TAG_HANDLER_PROC(tag)
211 {
212 int old_size, old_b, old_i, old_u, old_f, old_al;
213 wxHtmlContainerCell *c;
214
4f9297b0
VS
215 old_size = m_WParser->GetFontSize();
216 old_b = m_WParser->GetFontBold();
217 old_i = m_WParser->GetFontItalic();
218 old_u = m_WParser->GetFontUnderlined();
219 old_f = m_WParser->GetFontFixed();
220 old_al = m_WParser->GetAlign();
5526e819 221
d1da8872
WS
222 m_WParser->SetFontBold(true);
223 m_WParser->SetFontItalic(false);
224 m_WParser->SetFontUnderlined(false);
225 m_WParser->SetFontFixed(false);
5526e819 226
e7ee65ed 227 if (tag.GetName() == wxT("H1"))
4f9297b0 228 m_WParser->SetFontSize(7);
0413cec5 229 else if (tag.GetName() == wxT("H2"))
4f9297b0 230 m_WParser->SetFontSize(6);
0413cec5 231 else if (tag.GetName() == wxT("H3"))
4f9297b0 232 m_WParser->SetFontSize(5);
33ac7e6f 233 else if (tag.GetName() == wxT("H4"))
04dbb646 234 {
4f9297b0 235 m_WParser->SetFontSize(5);
d1da8872
WS
236 m_WParser->SetFontItalic(true);
237 m_WParser->SetFontBold(false);
5526e819 238 }
0413cec5 239 else if (tag.GetName() == wxT("H5"))
4f9297b0 240 m_WParser->SetFontSize(4);
33ac7e6f 241 else if (tag.GetName() == wxT("H6"))
04dbb646 242 {
4f9297b0 243 m_WParser->SetFontSize(4);
d1da8872
WS
244 m_WParser->SetFontItalic(true);
245 m_WParser->SetFontBold(false);
5526e819
VS
246 }
247
4f9297b0 248 c = m_WParser->GetContainer();
e3774124 249 if (c->GetFirstChild())
04dbb646 250 {
4f9297b0
VS
251 m_WParser->CloseContainer();
252 m_WParser->OpenContainer();
253 c = m_WParser->GetContainer();
5526e819 254 }
4f9297b0 255 c = m_WParser->GetContainer();
5526e819 256
4f9297b0
VS
257 c->SetAlign(tag);
258 c->InsertCell(new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
259 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
260 m_WParser->SetAlign(c->GetAlignHor());
5526e819
VS
261
262 ParseInner(tag);
263
4f9297b0
VS
264 m_WParser->SetFontSize(old_size);
265 m_WParser->SetFontBold(old_b);
266 m_WParser->SetFontItalic(old_i);
267 m_WParser->SetFontUnderlined(old_u);
268 m_WParser->SetFontFixed(old_f);
269 m_WParser->SetAlign(old_al);
5526e819 270
8bd72d90
VS
271 m_WParser->GetContainer()->InsertCell(
272 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
4f9297b0
VS
273 m_WParser->CloseContainer();
274 m_WParser->OpenContainer();
275 c = m_WParser->GetContainer();
276 c->SetIndent(m_WParser->GetCharHeight(), wxHTML_INDENT_TOP);
5526e819 277
d1da8872 278 return true;
5526e819
VS
279 }
280
281TAG_HANDLER_END(Hx)
282
283
e7ee65ed 284TAG_HANDLER_BEGIN(BIGSMALL, "BIG,SMALL")
fc7a2a60 285 TAG_HANDLER_CONSTR(BIGSMALL) { }
e7ee65ed
VS
286
287 TAG_HANDLER_PROC(tag)
288 {
4f9297b0 289 int oldsize = m_WParser->GetFontSize();
e7ee65ed
VS
290 int sz = (tag.GetName() == wxT("BIG")) ? +1 : -1;
291
4f9297b0 292 m_WParser->SetFontSize(sz);
8bd72d90
VS
293 m_WParser->GetContainer()->InsertCell(
294 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
e7ee65ed
VS
295
296 ParseInner(tag);
297
4f9297b0 298 m_WParser->SetFontSize(oldsize);
8bd72d90
VS
299 m_WParser->GetContainer()->InsertCell(
300 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
d1da8872 301 return true;
e7ee65ed
VS
302 }
303
304TAG_HANDLER_END(BIGSMALL)
305
306
5526e819
VS
307
308
309TAGS_MODULE_BEGIN(Fonts)
310
311 TAGS_MODULE_ADD(FONT)
ef01b72f
VS
312 TAGS_MODULE_ADD(FACES_U)
313 TAGS_MODULE_ADD(FACES_I)
314 TAGS_MODULE_ADD(FACES_B)
315 TAGS_MODULE_ADD(FACES_TT)
5526e819 316 TAGS_MODULE_ADD(Hx)
e7ee65ed 317 TAGS_MODULE_ADD(BIGSMALL)
5526e819
VS
318
319TAGS_MODULE_END(Fonts)
320
321
3364ab79 322#endif