]>
Commit | Line | Data |
---|---|---|
5526e819 | 1 | ///////////////////////////////////////////////////////////////////////////// |
93763ad5 | 2 | // Name: src/html/htmltag.cpp |
5526e819 VS |
3 | // Purpose: wxHtmlTag class (represents single tag) |
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 |
5526e819 VS |
14 | #endif |
15 | ||
93763ad5 WS |
16 | #if wxUSE_HTML |
17 | ||
40989e46 WS |
18 | #include "wx/html/htmltag.h" |
19 | ||
b4f4d3dd | 20 | #ifndef WX_PRECOMP |
7cf41a5d | 21 | #include "wx/colour.h" |
193d0c93 | 22 | #include "wx/wxcrtvararg.h" |
5526e819 VS |
23 | #endif |
24 | ||
daa616fc | 25 | #include "wx/html/htmlpars.h" |
f68e16c5 VZ |
26 | #include "wx/html/styleparams.h" |
27 | ||
4fe7567d VS |
28 | #include "wx/vector.h" |
29 | ||
7e1e0960 | 30 | #include <stdio.h> // for vsscanf |
5526e819 VS |
31 | #include <stdarg.h> |
32 | ||
5526e819 VS |
33 | //----------------------------------------------------------------------------- |
34 | // wxHtmlTagsCache | |
35 | //----------------------------------------------------------------------------- | |
36 | ||
5e8e25e7 VS |
37 | struct wxHtmlCacheItem |
38 | { | |
39 | // this is "pos" value passed to wxHtmlTag's constructor. | |
40 | // it is position of '<' character of the tag | |
b1a3a964 VS |
41 | wxString::const_iterator Key; |
42 | ||
43 | // Tag type | |
44 | enum Type | |
45 | { | |
46 | Type_Normal, // normal tag with a matching ending tag | |
47 | Type_NoMatchingEndingTag, // there's no ending tag for this tag | |
48 | Type_EndingTag // this is ending tag </..> | |
49 | }; | |
50 | Type type; | |
5e8e25e7 VS |
51 | |
52 | // end positions for the tag: | |
53 | // end1 is '<' of ending tag, | |
54 | // end2 is '>' or both are | |
b1a3a964 | 55 | wxString::const_iterator End1, End2; |
5e8e25e7 VS |
56 | |
57 | // name of this tag | |
58 | wxChar *Name; | |
59 | }; | |
60 | ||
4fe7567d VS |
61 | // NB: this is an empty class and not typedef because of forward declaration |
62 | class wxHtmlTagsCacheData : public wxVector<wxHtmlCacheItem> | |
63 | { | |
64 | }; | |
5e8e25e7 | 65 | |
07cc7ddc | 66 | bool wxIsCDATAElement(const wxChar *tag) |
7c6cd4a8 | 67 | { |
9a83f860 VZ |
68 | return (wxStrcmp(tag, wxT("SCRIPT")) == 0) || |
69 | (wxStrcmp(tag, wxT("STYLE")) == 0); | |
7c6cd4a8 VS |
70 | } |
71 | ||
b1a3a964 VS |
72 | bool wxIsCDATAElement(const wxString& tag) |
73 | { | |
d9359369 VS |
74 | return (wxStrcmp(tag.wx_str(), wxS("SCRIPT")) == 0) || |
75 | (wxStrcmp(tag.wx_str(), wxS("STYLE")) == 0); | |
b1a3a964 VS |
76 | } |
77 | ||
5526e819 VS |
78 | wxHtmlTagsCache::wxHtmlTagsCache(const wxString& source) |
79 | { | |
4fe7567d VS |
80 | m_Cache = new wxHtmlTagsCacheData; |
81 | m_CachePos = 0; | |
82 | ||
8cd82622 | 83 | wxChar tagBuffer[256]; |
5526e819 | 84 | |
b1a3a964 VS |
85 | const wxString::const_iterator end = source.end(); |
86 | for ( wxString::const_iterator pos = source.begin(); pos < end; ++pos ) | |
4f9297b0 | 87 | { |
48d8ea6d VZ |
88 | if (*pos != wxT('<')) |
89 | continue; | |
4609ee2e | 90 | |
48d8ea6d | 91 | // possible tag start found: |
4fe7567d | 92 | |
48d8ea6d VZ |
93 | // don't cache comment tags |
94 | if ( wxHtmlParser::SkipCommentTag(pos, end) ) | |
95 | continue; | |
8cd82622 | 96 | |
36258204 | 97 | // Remember the starting tag position. |
48d8ea6d | 98 | wxString::const_iterator stpos = pos++; |
48d8ea6d | 99 | |
36258204 | 100 | // And look for the ending one. |
48d8ea6d VZ |
101 | int i; |
102 | for ( i = 0; | |
103 | pos < end && i < (int)WXSIZEOF(tagBuffer) - 1 && | |
104 | *pos != wxT('>') && !wxIsspace(*pos); | |
105 | ++i, ++pos ) | |
106 | { | |
107 | tagBuffer[i] = (wxChar)wxToupper(*pos); | |
108 | } | |
109 | tagBuffer[i] = wxT('\0'); | |
8cd82622 | 110 | |
48d8ea6d VZ |
111 | while (pos < end && *pos != wxT('>')) |
112 | ++pos; | |
5526e819 | 113 | |
36258204 VZ |
114 | if ( pos == end ) |
115 | { | |
116 | // We didn't find a closing bracket, this is not a valid tag after | |
117 | // all. Notice that we need to roll back pos to avoid creating an | |
118 | // invalid iterator when "++pos" is done in the loop statement. | |
119 | --pos; | |
120 | ||
121 | continue; | |
122 | } | |
123 | ||
124 | // We have a valid tag, add it to the cache. | |
125 | size_t tg = Cache().size(); | |
126 | Cache().push_back(wxHtmlCacheItem()); | |
127 | Cache()[tg].Key = stpos; | |
128 | Cache()[tg].Name = new wxChar[i+1]; | |
129 | memcpy(Cache()[tg].Name, tagBuffer, (i+1)*sizeof(wxChar)); | |
130 | ||
48d8ea6d VZ |
131 | if ((stpos+1) < end && *(stpos+1) == wxT('/')) // ending tag: |
132 | { | |
133 | Cache()[tg].type = wxHtmlCacheItem::Type_EndingTag; | |
134 | // find matching begin tag: | |
135 | for (i = tg; i >= 0; i--) | |
a914db0f | 136 | { |
48d8ea6d | 137 | if ((Cache()[i].type == wxHtmlCacheItem::Type_NoMatchingEndingTag) && (wxStrcmp(Cache()[i].Name, tagBuffer+1) == 0)) |
b1a3a964 | 138 | { |
48d8ea6d VZ |
139 | Cache()[i].type = wxHtmlCacheItem::Type_Normal; |
140 | Cache()[i].End1 = stpos; | |
141 | Cache()[i].End2 = pos + 1; | |
142 | break; | |
b1a3a964 | 143 | } |
5526e819 | 144 | } |
48d8ea6d VZ |
145 | } |
146 | else | |
147 | { | |
148 | Cache()[tg].type = wxHtmlCacheItem::Type_NoMatchingEndingTag; | |
7448de8d | 149 | |
48d8ea6d VZ |
150 | if (wxIsCDATAElement(tagBuffer)) |
151 | { | |
152 | // store the orig pos in case we are missing the closing | |
153 | // tag (see below) | |
154 | const wxString::const_iterator old_pos = pos; | |
155 | bool foundCloseTag = false; | |
156 | ||
157 | // find next matching tag | |
158 | int tag_len = wxStrlen(tagBuffer); | |
159 | while (pos < end) | |
7c6cd4a8 | 160 | { |
48d8ea6d VZ |
161 | // find the ending tag |
162 | while (pos + 1 < end && | |
163 | (*pos != '<' || *(pos+1) != '/')) | |
164 | ++pos; | |
165 | if (*pos == '<') | |
166 | ++pos; | |
167 | ||
168 | // see if it matches | |
169 | int match_pos = 0; | |
170 | while (pos < end && match_pos < tag_len ) | |
7c6cd4a8 | 171 | { |
48d8ea6d VZ |
172 | wxChar c = *pos; |
173 | if ( c == '>' || c == '<' ) | |
174 | break; | |
175 | ||
176 | // cast to wxChar needed to suppress warning in | |
177 | // Unicode build | |
178 | if ((wxChar)wxToupper(c) == tagBuffer[match_pos]) | |
b1a3a964 | 179 | { |
48d8ea6d | 180 | ++match_pos; |
7c6cd4a8 | 181 | } |
48d8ea6d VZ |
182 | else if (c == wxT(' ') || c == wxT('\n') || |
183 | c == wxT('\r') || c == wxT('\t')) | |
313ffa19 | 184 | { |
48d8ea6d | 185 | // need to skip over these |
7c6cd4a8 | 186 | } |
48d8ea6d | 187 | else |
313ffa19 | 188 | { |
48d8ea6d | 189 | match_pos = 0; |
7c6cd4a8 | 190 | } |
48d8ea6d | 191 | ++pos; |
7c6cd4a8 | 192 | } |
48d8ea6d VZ |
193 | |
194 | // found a match | |
195 | if (match_pos == tag_len) | |
196 | { | |
197 | pos = pos - tag_len - 3; | |
198 | foundCloseTag = true; | |
199 | break; | |
200 | } | |
201 | else // keep looking for the closing tag | |
313ffa19 | 202 | { |
48d8ea6d | 203 | ++pos; |
313ffa19 | 204 | } |
7c6cd4a8 | 205 | } |
48d8ea6d VZ |
206 | if (!foundCloseTag) |
207 | { | |
208 | // we didn't find closing tag; this means the markup | |
209 | // is incorrect and the best thing we can do is to | |
210 | // ignore the unclosed tag and continue parsing as if | |
211 | // it didn't exist: | |
212 | pos = old_pos; | |
213 | } | |
5526e819 VS |
214 | } |
215 | } | |
5526e819 VS |
216 | } |
217 | ||
218 | // ok, we're done, now we'll free .Name members of cache - we don't need it anymore: | |
4fe7567d VS |
219 | for ( wxHtmlTagsCacheData::iterator i = Cache().begin(); |
220 | i != Cache().end(); ++i ) | |
4f9297b0 | 221 | { |
5276b0a5 | 222 | wxDELETEA(i->Name); |
5526e819 VS |
223 | } |
224 | } | |
225 | ||
4fe7567d VS |
226 | wxHtmlTagsCache::~wxHtmlTagsCache() |
227 | { | |
228 | delete m_Cache; | |
229 | } | |
230 | ||
b1a3a964 VS |
231 | void wxHtmlTagsCache::QueryTag(const wxString::const_iterator& at, |
232 | const wxString::const_iterator& inputEnd, | |
233 | wxString::const_iterator *end1, | |
234 | wxString::const_iterator *end2, | |
235 | bool *hasEnding) | |
5526e819 | 236 | { |
4fe7567d | 237 | if (Cache().empty()) |
36258204 VZ |
238 | { |
239 | *end1 = | |
240 | *end2 = inputEnd; | |
241 | *hasEnding = true; | |
4fe7567d | 242 | return; |
36258204 | 243 | } |
4fe7567d VS |
244 | |
245 | if (Cache()[m_CachePos].Key != at) | |
4f9297b0 | 246 | { |
4fe7567d | 247 | int delta = (at < Cache()[m_CachePos].Key) ? -1 : 1; |
8cd82622 VZ |
248 | do |
249 | { | |
b1a3a964 VS |
250 | m_CachePos += delta; |
251 | ||
252 | if ( m_CachePos < 0 || m_CachePos >= (int)Cache().size() ) | |
10b9be32 | 253 | { |
b1a3a964 VS |
254 | if ( m_CachePos < 0 ) |
255 | m_CachePos = 0; | |
256 | else | |
257 | m_CachePos = Cache().size() - 1; | |
10b9be32 VZ |
258 | // something is very wrong with HTML, give up by returning an |
259 | // impossibly large value which is going to be ignored by the | |
260 | // caller | |
261 | *end1 = | |
b1a3a964 VS |
262 | *end2 = inputEnd; |
263 | *hasEnding = true; | |
10b9be32 VZ |
264 | return; |
265 | } | |
daa616fc | 266 | } |
4fe7567d | 267 | while (Cache()[m_CachePos].Key != at); |
5526e819 | 268 | } |
61679695 VS |
269 | |
270 | switch ( Cache()[m_CachePos].type ) | |
271 | { | |
272 | case wxHtmlCacheItem::Type_Normal: | |
273 | *end1 = Cache()[m_CachePos].End1; | |
274 | *end2 = Cache()[m_CachePos].End2; | |
275 | *hasEnding = true; | |
276 | break; | |
277 | ||
278 | case wxHtmlCacheItem::Type_EndingTag: | |
279 | wxFAIL_MSG("QueryTag called for ending tag - can't be"); | |
280 | // but if it does happen, fall through, better than crashing | |
281 | ||
282 | case wxHtmlCacheItem::Type_NoMatchingEndingTag: | |
283 | // If input HTML is invalid and there's no closing tag for this | |
284 | // one, pretend that it runs all the way to the end of input | |
285 | *end1 = inputEnd; | |
286 | *end2 = inputEnd; | |
287 | *hasEnding = false; | |
288 | break; | |
289 | } | |
5526e819 VS |
290 | } |
291 | ||
292 | ||
293 | ||
294 | ||
295 | //----------------------------------------------------------------------------- | |
296 | // wxHtmlTag | |
297 | //----------------------------------------------------------------------------- | |
298 | ||
211dfedd | 299 | wxHtmlTag::wxHtmlTag(wxHtmlTag *parent, |
b1a3a964 VS |
300 | const wxString *source, |
301 | const wxString::const_iterator& pos, | |
302 | const wxString::const_iterator& end_pos, | |
daa616fc | 303 | wxHtmlTagsCache *cache, |
7da48d49 | 304 | wxHtmlEntitiesParser *entParser) |
5526e819 | 305 | { |
211dfedd VS |
306 | /* Setup DOM relations */ |
307 | ||
308 | m_Next = NULL; | |
309 | m_FirstChild = m_LastChild = NULL; | |
310 | m_Parent = parent; | |
311 | if (parent) | |
312 | { | |
313 | m_Prev = m_Parent->m_LastChild; | |
314 | if (m_Prev == NULL) | |
315 | m_Parent->m_FirstChild = this; | |
316 | else | |
317 | m_Prev->m_Next = this; | |
318 | m_Parent->m_LastChild = this; | |
319 | } | |
320 | else | |
321 | m_Prev = NULL; | |
322 | ||
323 | /* Find parameters and their values: */ | |
8cd82622 | 324 | |
76de2296 | 325 | wxChar c wxDUMMY_INITIALIZE(0); |
5526e819 VS |
326 | |
327 | // fill-in name, params and begin pos: | |
b1a3a964 | 328 | wxString::const_iterator i(pos+1); |
5526e819 | 329 | |
b076dc01 | 330 | // find tag's name and convert it to uppercase: |
8cd82622 | 331 | while ((i < end_pos) && |
b1a3a964 | 332 | ((c = *(i++)) != wxT(' ') && c != wxT('\r') && |
daa616fc | 333 | c != wxT('\n') && c != wxT('\t') && |
ad20c567 | 334 | c != wxT('>') && c != wxT('/'))) |
a914db0f | 335 | { |
8cd82622 | 336 | if ((c >= wxT('a')) && (c <= wxT('z'))) |
daa616fc VS |
337 | c -= (wxT('a') - wxT('A')); |
338 | m_Name << c; | |
5526e819 VS |
339 | } |
340 | ||
b076dc01 | 341 | // if the tag has parameters, read them and "normalize" them, |
8cd82622 | 342 | // i.e. convert to uppercase, replace whitespaces by spaces and |
b076dc01 | 343 | // remove whitespaces around '=': |
b1a3a964 | 344 | if (*(i-1) != wxT('>')) |
daa616fc VS |
345 | { |
346 | #define IS_WHITE(c) (c == wxT(' ') || c == wxT('\r') || \ | |
347 | c == wxT('\n') || c == wxT('\t')) | |
348 | wxString pname, pvalue; | |
349 | wxChar quote; | |
8cd82622 | 350 | enum |
a914db0f | 351 | { |
8cd82622 | 352 | ST_BEFORE_NAME = 1, |
daa616fc VS |
353 | ST_NAME, |
354 | ST_BEFORE_EQ, | |
355 | ST_BEFORE_VALUE, | |
356 | ST_VALUE | |
357 | } state; | |
8cd82622 | 358 | |
daa616fc VS |
359 | quote = 0; |
360 | state = ST_BEFORE_NAME; | |
361 | while (i < end_pos) | |
362 | { | |
b1a3a964 | 363 | c = *(i++); |
daa616fc | 364 | |
8cd82622 | 365 | if (c == wxT('>') && !(state == ST_VALUE && quote != 0)) |
a914db0f | 366 | { |
daa616fc | 367 | if (state == ST_BEFORE_EQ || state == ST_NAME) |
b076dc01 | 368 | { |
daa616fc | 369 | m_ParamNames.Add(pname); |
b1a3a964 | 370 | m_ParamValues.Add(wxGetEmptyString()); |
b076dc01 | 371 | } |
daa616fc VS |
372 | else if (state == ST_VALUE && quote == 0) |
373 | { | |
374 | m_ParamNames.Add(pname); | |
367c84b9 VS |
375 | if (entParser) |
376 | m_ParamValues.Add(entParser->Parse(pvalue)); | |
377 | else | |
378 | m_ParamValues.Add(pvalue); | |
daa616fc VS |
379 | } |
380 | break; | |
5526e819 | 381 | } |
daa616fc | 382 | switch (state) |
a914db0f | 383 | { |
daa616fc VS |
384 | case ST_BEFORE_NAME: |
385 | if (!IS_WHITE(c)) | |
386 | { | |
387 | pname = c; | |
388 | state = ST_NAME; | |
389 | } | |
390 | break; | |
391 | case ST_NAME: | |
392 | if (IS_WHITE(c)) | |
393 | state = ST_BEFORE_EQ; | |
394 | else if (c == wxT('=')) | |
395 | state = ST_BEFORE_VALUE; | |
396 | else | |
397 | pname << c; | |
398 | break; | |
399 | case ST_BEFORE_EQ: | |
400 | if (c == wxT('=')) | |
401 | state = ST_BEFORE_VALUE; | |
402 | else if (!IS_WHITE(c)) | |
403 | { | |
404 | m_ParamNames.Add(pname); | |
b1a3a964 | 405 | m_ParamValues.Add(wxGetEmptyString()); |
daa616fc VS |
406 | pname = c; |
407 | state = ST_NAME; | |
408 | } | |
409 | break; | |
410 | case ST_BEFORE_VALUE: | |
411 | if (!IS_WHITE(c)) | |
412 | { | |
413 | if (c == wxT('"') || c == wxT('\'')) | |
b1a3a964 | 414 | quote = c, pvalue = wxGetEmptyString(); |
daa616fc VS |
415 | else |
416 | quote = 0, pvalue = c; | |
417 | state = ST_VALUE; | |
418 | } | |
419 | break; | |
420 | case ST_VALUE: | |
421 | if ((quote != 0 && c == quote) || | |
422 | (quote == 0 && IS_WHITE(c))) | |
423 | { | |
424 | m_ParamNames.Add(pname); | |
425 | if (quote == 0) | |
426 | { | |
427 | // VS: backward compatibility, no real reason, | |
428 | // but wxHTML code relies on this... :( | |
429 | pvalue.MakeUpper(); | |
430 | } | |
367c84b9 VS |
431 | if (entParser) |
432 | m_ParamValues.Add(entParser->Parse(pvalue)); | |
433 | else | |
434 | m_ParamValues.Add(pvalue); | |
daa616fc VS |
435 | state = ST_BEFORE_NAME; |
436 | } | |
437 | else | |
438 | pvalue << c; | |
439 | break; | |
72aa4a98 | 440 | } |
5526e819 | 441 | } |
8cd82622 | 442 | |
daa616fc | 443 | #undef IS_WHITE |
7448de8d WS |
444 | } |
445 | m_Begin = i; | |
b1a3a964 | 446 | cache->QueryTag(pos, source->end(), &m_End1, &m_End2, &m_hasEnding); |
7448de8d WS |
447 | if (m_End1 > end_pos) m_End1 = end_pos; |
448 | if (m_End2 > end_pos) m_End2 = end_pos; | |
b1a3a964 VS |
449 | |
450 | #if WXWIN_COMPATIBILITY_2_8 | |
451 | m_sourceStart = source->begin(); | |
452 | #endif | |
f68e16c5 VZ |
453 | |
454 | // Try to parse any style parameters that can be handled simply by | |
455 | // converting them to the equivalent HTML 3 attributes: this is a far cry | |
456 | // from perfect but better than nothing. | |
457 | static const struct EquivAttr | |
458 | { | |
459 | const char *style; | |
460 | const char *attr; | |
461 | } equivAttrs[] = | |
462 | { | |
463 | { "text-align", "ALIGN" }, | |
464 | { "width", "WIDTH" }, | |
465 | { "vertical-align", "VALIGN" }, | |
466 | { "background", "BGCOLOR" }, | |
c7155388 | 467 | { "background-color", "BGCOLOR" }, |
f68e16c5 VZ |
468 | }; |
469 | ||
470 | wxHtmlStyleParams styleParams(*this); | |
471 | for ( unsigned n = 0; n < WXSIZEOF(equivAttrs); n++ ) | |
472 | { | |
473 | const EquivAttr& ea = equivAttrs[n]; | |
474 | if ( styleParams.HasParam(ea.style) && !HasParam(ea.attr) ) | |
475 | { | |
476 | m_ParamNames.Add(ea.attr); | |
477 | m_ParamValues.Add(styleParams.GetParam(ea.style)); | |
478 | } | |
479 | } | |
5526e819 VS |
480 | } |
481 | ||
211dfedd VS |
482 | wxHtmlTag::~wxHtmlTag() |
483 | { | |
0d58bb65 VS |
484 | wxHtmlTag *t1, *t2; |
485 | t1 = m_FirstChild; | |
486 | while (t1) | |
487 | { | |
488 | t2 = t1->GetNextSibling(); | |
489 | delete t1; | |
490 | t1 = t2; | |
491 | } | |
211dfedd VS |
492 | } |
493 | ||
5526e819 VS |
494 | bool wxHtmlTag::HasParam(const wxString& par) const |
495 | { | |
8703bc01 | 496 | return (m_ParamNames.Index(par, false) != wxNOT_FOUND); |
5526e819 VS |
497 | } |
498 | ||
614f9713 | 499 | wxString wxHtmlTag::GetParam(const wxString& par, bool with_quotes) const |
5526e819 | 500 | { |
8703bc01 | 501 | int index = m_ParamNames.Index(par, false); |
daa616fc | 502 | if (index == wxNOT_FOUND) |
b1a3a964 | 503 | return wxGetEmptyString(); |
614f9713 | 504 | if (with_quotes) |
4f9297b0 | 505 | { |
daa616fc VS |
506 | // VS: backward compatibility, seems to be never used by wxHTML... |
507 | wxString s; | |
508 | s << wxT('"') << m_ParamValues[index] << wxT('"'); | |
509 | return s; | |
5526e819 | 510 | } |
daa616fc VS |
511 | else |
512 | return m_ParamValues[index]; | |
5526e819 VS |
513 | } |
514 | ||
90350682 | 515 | int wxHtmlTag::ScanParam(const wxString& par, |
d7640339 VS |
516 | const char *format, |
517 | void *param) const | |
518 | { | |
519 | wxString parval = GetParam(par); | |
520 | return wxSscanf(parval, format, param); | |
521 | } | |
522 | ||
523 | int wxHtmlTag::ScanParam(const wxString& par, | |
524 | const wchar_t *format, | |
90350682 | 525 | void *param) const |
5526e819 | 526 | { |
5526e819 | 527 | wxString parval = GetParam(par); |
161f4f73 | 528 | return wxSscanf(parval, format, param); |
5526e819 VS |
529 | } |
530 | ||
f68e16c5 VZ |
531 | /* static */ |
532 | bool wxHtmlTag::ParseAsColour(const wxString& str, wxColour *clr) | |
8bd72d90 | 533 | { |
9a83f860 | 534 | wxCHECK_MSG( clr, false, wxT("invalid colour argument") ); |
8cd82622 | 535 | |
86766dfd | 536 | // handle colours defined in HTML 4.0 first: |
9a83f860 | 537 | if (str.length() > 1 && str[0] != wxT('#')) |
8bd72d90 | 538 | { |
d9359369 VS |
539 | #define HTML_COLOUR(name, r, g, b) \ |
540 | if (str.IsSameAs(wxS(name), false)) \ | |
86766dfd | 541 | { clr->Set(r, g, b); return true; } |
8bd72d90 VS |
542 | HTML_COLOUR("black", 0x00,0x00,0x00) |
543 | HTML_COLOUR("silver", 0xC0,0xC0,0xC0) | |
544 | HTML_COLOUR("gray", 0x80,0x80,0x80) | |
545 | HTML_COLOUR("white", 0xFF,0xFF,0xFF) | |
546 | HTML_COLOUR("maroon", 0x80,0x00,0x00) | |
547 | HTML_COLOUR("red", 0xFF,0x00,0x00) | |
548 | HTML_COLOUR("purple", 0x80,0x00,0x80) | |
549 | HTML_COLOUR("fuchsia", 0xFF,0x00,0xFF) | |
550 | HTML_COLOUR("green", 0x00,0x80,0x00) | |
551 | HTML_COLOUR("lime", 0x00,0xFF,0x00) | |
552 | HTML_COLOUR("olive", 0x80,0x80,0x00) | |
553 | HTML_COLOUR("yellow", 0xFF,0xFF,0x00) | |
554 | HTML_COLOUR("navy", 0x00,0x00,0x80) | |
555 | HTML_COLOUR("blue", 0x00,0x00,0xFF) | |
556 | HTML_COLOUR("teal", 0x00,0x80,0x80) | |
557 | HTML_COLOUR("aqua", 0x00,0xFF,0xFF) | |
558 | #undef HTML_COLOUR | |
8bd72d90 | 559 | } |
5716a1ab | 560 | |
86766dfd VS |
561 | // then try to parse #rrggbb representations or set from other well |
562 | // known names (note that this doesn't strictly conform to HTML spec, | |
563 | // but it doesn't do real harm -- but it *must* be done after the standard | |
564 | // colors are handled above): | |
565 | if (clr->Set(str)) | |
566 | return true; | |
567 | ||
8703bc01 | 568 | return false; |
8bd72d90 VS |
569 | } |
570 | ||
f68e16c5 VZ |
571 | bool wxHtmlTag::GetParamAsColour(const wxString& par, wxColour *clr) const |
572 | { | |
573 | const wxString str = GetParam(par); | |
574 | return !str.empty() && ParseAsColour(str, clr); | |
575 | } | |
576 | ||
8bd72d90 VS |
577 | bool wxHtmlTag::GetParamAsInt(const wxString& par, int *clr) const |
578 | { | |
3f6901ad VZ |
579 | if ( !HasParam(par) ) |
580 | return false; | |
581 | ||
8bd72d90 | 582 | long i; |
3f6901ad VZ |
583 | if ( !GetParam(par).ToLong(&i) ) |
584 | return false; | |
585 | ||
8bd72d90 | 586 | *clr = (int)i; |
3f6901ad | 587 | return true; |
8bd72d90 VS |
588 | } |
589 | ||
daa616fc VS |
590 | wxString wxHtmlTag::GetAllParams() const |
591 | { | |
3103e8a9 | 592 | // VS: this function is for backward compatibility only, |
daa616fc VS |
593 | // never used by wxHTML |
594 | wxString s; | |
595 | size_t cnt = m_ParamNames.GetCount(); | |
596 | for (size_t i = 0; i < cnt; i++) | |
597 | { | |
598 | s << m_ParamNames[i]; | |
599 | s << wxT('='); | |
600 | if (m_ParamValues[i].Find(wxT('"')) != wxNOT_FOUND) | |
601 | s << wxT('\'') << m_ParamValues[i] << wxT('\''); | |
602 | else | |
603 | s << wxT('"') << m_ParamValues[i] << wxT('"'); | |
604 | } | |
605 | return s; | |
606 | } | |
607 | ||
211dfedd VS |
608 | wxHtmlTag *wxHtmlTag::GetFirstSibling() const |
609 | { | |
610 | if (m_Parent) | |
611 | return m_Parent->m_FirstChild; | |
612 | else | |
613 | { | |
614 | wxHtmlTag *cur = (wxHtmlTag*)this; | |
8cd82622 | 615 | while (cur->m_Prev) |
211dfedd VS |
616 | cur = cur->m_Prev; |
617 | return cur; | |
618 | } | |
619 | } | |
620 | ||
621 | wxHtmlTag *wxHtmlTag::GetLastSibling() const | |
622 | { | |
623 | if (m_Parent) | |
624 | return m_Parent->m_LastChild; | |
625 | else | |
626 | { | |
627 | wxHtmlTag *cur = (wxHtmlTag*)this; | |
8cd82622 | 628 | while (cur->m_Next) |
211dfedd VS |
629 | cur = cur->m_Next; |
630 | return cur; | |
631 | } | |
632 | } | |
633 | ||
634 | wxHtmlTag *wxHtmlTag::GetNextTag() const | |
635 | { | |
636 | if (m_FirstChild) return m_FirstChild; | |
637 | if (m_Next) return m_Next; | |
638 | wxHtmlTag *cur = m_Parent; | |
639 | if (!cur) return NULL; | |
8cd82622 | 640 | while (cur->m_Parent && !cur->m_Next) |
211dfedd VS |
641 | cur = cur->m_Parent; |
642 | return cur->m_Next; | |
643 | } | |
644 | ||
4d223b67 | 645 | #endif |