]>
Commit | Line | Data |
---|---|---|
f68e16c5 VZ |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: src/html/m_span.cpp | |
3 | // Purpose: wxHtml module for span handling | |
4 | // Author: Nigel Paton | |
5 | // RCS-ID: $Id$ | |
6 | // Copyright: wxWidgets team | |
7 | // Licence: wxWindows licence | |
8 | ///////////////////////////////////////////////////////////////////////////// | |
9 | ||
10 | #include "wx/wxprec.h" | |
11 | ||
12 | #ifdef __BORLANDC__ | |
13 | #pragma hdrstop | |
14 | #endif | |
15 | ||
16 | #if wxUSE_HTML | |
17 | ||
18 | #include "wx/html/forcelnk.h" | |
19 | #include "wx/html/m_templ.h" | |
20 | #include "wx/fontenum.h" | |
21 | #include "wx/tokenzr.h" | |
22 | #include "wx/html/styleparams.h" | |
23 | ||
24 | FORCE_LINK_ME(m_span) | |
25 | ||
26 | ||
27 | TAG_HANDLER_BEGIN(SPAN, "SPAN" ) | |
28 | ||
29 | TAG_HANDLER_VARS | |
30 | wxArrayString m_Faces; | |
31 | ||
32 | TAG_HANDLER_CONSTR(SPAN) { } | |
33 | ||
34 | TAG_HANDLER_PROC(tag) | |
35 | { | |
36 | wxColour oldclr = m_WParser->GetActualColor(); | |
37 | int oldsize = m_WParser->GetFontSize(); | |
38 | int oldbold = m_WParser->GetFontBold(); | |
3e65f74e VZ |
39 | int olditalic = m_WParser->GetFontItalic(); |
40 | int oldunderlined = m_WParser->GetFontUnderlined(); | |
41 | wxString oldfontface = m_WParser->GetFontFace(); | |
f68e16c5 VZ |
42 | |
43 | // Load any style parameters | |
44 | wxHtmlStyleParams styleParams(tag); | |
45 | ||
46 | wxString str; | |
47 | ||
48 | str = styleParams.GetParam(wxS("color")); | |
49 | if ( !str.empty() ) | |
50 | { | |
51 | wxColour clr; | |
52 | if ( wxHtmlTag::ParseAsColour(str, &clr) ) | |
53 | { | |
54 | m_WParser->SetActualColor(clr); | |
55 | m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr)); | |
56 | } | |
57 | } | |
58 | ||
59 | str = styleParams.GetParam(wxS("font-size")); | |
60 | if ( !str.empty() ) | |
61 | { | |
62 | // Point size | |
63 | int foundIndex = str.Find(wxS("pt")); | |
64 | if (foundIndex != wxNOT_FOUND) | |
65 | { | |
66 | str.Truncate(foundIndex); | |
67 | ||
68 | long sizeValue; | |
69 | if (str.ToLong(&sizeValue) == true) | |
70 | { | |
71 | // Set point size | |
72 | m_WParser->SetFontPointSize(sizeValue); | |
73 | m_WParser->GetContainer()->InsertCell( | |
74 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
75 | } | |
76 | } | |
77 | // else: check for other ways of specifying size (TODO) | |
78 | } | |
79 | ||
80 | str = styleParams.GetParam(wxS("font-weight")); | |
81 | if ( !str.empty() ) | |
82 | { | |
83 | // Only bold and normal supported just now | |
84 | if ( str == wxS("bold") ) | |
85 | { | |
86 | m_WParser->SetFontBold(true); | |
87 | m_WParser->GetContainer()->InsertCell( | |
88 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
89 | } | |
90 | else if ( str == wxS("normal") ) | |
91 | { | |
92 | m_WParser->SetFontBold(false); | |
93 | m_WParser->GetContainer()->InsertCell( | |
94 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
95 | } | |
96 | } | |
97 | ||
3e65f74e VZ |
98 | str = styleParams.GetParam(wxS("font-style")); |
99 | if ( !str.empty() ) | |
100 | { | |
101 | // "oblique" and "italic" are more or less the same. | |
102 | // "inherit" (using the parent font) is not supported. | |
103 | if ( str == wxS("oblique") || str == wxS("italic") ) | |
104 | { | |
105 | m_WParser->SetFontItalic(true); | |
106 | m_WParser->GetContainer()->InsertCell( | |
107 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
108 | } | |
109 | else if ( str == wxS("normal") ) | |
110 | { | |
111 | m_WParser->SetFontItalic(false); | |
112 | m_WParser->GetContainer()->InsertCell( | |
113 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
114 | } | |
115 | } | |
f68e16c5 | 116 | |
3e65f74e VZ |
117 | str = styleParams.GetParam(wxS("text-decoration")); |
118 | if ( !str.empty() ) | |
f68e16c5 | 119 | { |
3e65f74e VZ |
120 | // Only underline is supported. |
121 | if ( str == wxS("underline") ) | |
122 | { | |
123 | m_WParser->SetFontUnderlined(true); | |
124 | m_WParser->GetContainer()->InsertCell( | |
125 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
126 | } | |
f68e16c5 | 127 | } |
3e65f74e VZ |
128 | |
129 | str = styleParams.GetParam(wxS("font-family")); | |
130 | if ( !str.empty() ) | |
f68e16c5 | 131 | { |
3e65f74e VZ |
132 | m_WParser->SetFontFace(str); |
133 | m_WParser->GetContainer()->InsertCell( | |
134 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
f68e16c5 | 135 | } |
3e65f74e VZ |
136 | |
137 | ParseInner(tag); | |
138 | ||
139 | m_WParser->SetFontSize(oldsize); | |
140 | m_WParser->SetFontBold(oldbold); | |
141 | m_WParser->SetFontUnderlined(oldunderlined); | |
142 | m_WParser->SetFontFace(oldfontface); | |
143 | m_WParser->SetFontItalic(olditalic); | |
144 | m_WParser->GetContainer()->InsertCell( | |
145 | new wxHtmlFontCell(m_WParser->CreateCurrentFont())); | |
146 | ||
f68e16c5 VZ |
147 | if (oldclr != m_WParser->GetActualColor()) |
148 | { | |
149 | m_WParser->SetActualColor(oldclr); | |
3e65f74e VZ |
150 | m_WParser->GetContainer()->InsertCell( |
151 | new wxHtmlColourCell(oldclr)); | |
f68e16c5 VZ |
152 | } |
153 | ||
154 | return true; | |
155 | } | |
156 | ||
157 | TAG_HANDLER_END(SPAN) | |
158 | ||
159 | ||
160 | TAGS_MODULE_BEGIN(Spans) | |
161 | ||
162 | TAGS_MODULE_ADD(SPAN) | |
163 | ||
164 | TAGS_MODULE_END(Spans) | |
165 | ||
166 | #endif // wxUSE_HTML |