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