1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/m_span.cpp
3 // Purpose: wxHtml module for span handling
6 // Copyright: wxWidgets team
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
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"
27 TAG_HANDLER_BEGIN(SPAN
, "SPAN" )
30 wxArrayString m_Faces
;
32 TAG_HANDLER_CONSTR(SPAN
) { }
36 wxColour oldclr
= m_WParser
->GetActualColor();
37 wxColour oldbackclr
= m_WParser
->GetActualBackgroundColor();
38 int oldbackmode
= m_WParser
->GetActualBackgroundMode();
39 int oldsize
= m_WParser
->GetFontSize();
40 int oldbold
= m_WParser
->GetFontBold();
41 int olditalic
= m_WParser
->GetFontItalic();
42 int oldunderlined
= m_WParser
->GetFontUnderlined();
43 wxString oldfontface
= m_WParser
->GetFontFace();
45 // Load any style parameters
46 wxHtmlStyleParams
styleParams(tag
);
50 str
= styleParams
.GetParam(wxS("color"));
54 if ( wxHtmlTag::ParseAsColour(str
, &clr
) )
56 m_WParser
->SetActualColor(clr
);
57 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
));
61 str
= styleParams
.GetParam(wxS("background-color"));
65 if ( wxHtmlTag::ParseAsColour(str
, &clr
) )
67 m_WParser
->SetActualBackgroundColor(clr
);
68 m_WParser
->SetActualBackgroundMode(wxSOLID
);
69 m_WParser
->GetContainer()->InsertCell(new wxHtmlColourCell(clr
, wxHTML_CLR_BACKGROUND
));
73 str
= styleParams
.GetParam(wxS("font-size"));
77 int foundIndex
= str
.Find(wxS("pt"));
78 if (foundIndex
!= wxNOT_FOUND
)
80 str
.Truncate(foundIndex
);
83 if (str
.ToLong(&sizeValue
) == true)
86 m_WParser
->SetFontPointSize(sizeValue
);
87 m_WParser
->GetContainer()->InsertCell(
88 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
91 // else: check for other ways of specifying size (TODO)
94 str
= styleParams
.GetParam(wxS("font-weight"));
97 // Only bold and normal supported just now
98 if ( str
== wxS("bold") )
100 m_WParser
->SetFontBold(true);
101 m_WParser
->GetContainer()->InsertCell(
102 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
104 else if ( str
== wxS("normal") )
106 m_WParser
->SetFontBold(false);
107 m_WParser
->GetContainer()->InsertCell(
108 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
112 str
= styleParams
.GetParam(wxS("font-style"));
115 // "oblique" and "italic" are more or less the same.
116 // "inherit" (using the parent font) is not supported.
117 if ( str
== wxS("oblique") || str
== wxS("italic") )
119 m_WParser
->SetFontItalic(true);
120 m_WParser
->GetContainer()->InsertCell(
121 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
123 else if ( str
== wxS("normal") )
125 m_WParser
->SetFontItalic(false);
126 m_WParser
->GetContainer()->InsertCell(
127 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
131 str
= styleParams
.GetParam(wxS("text-decoration"));
134 // Only underline is supported.
135 if ( str
== wxS("underline") )
137 m_WParser
->SetFontUnderlined(true);
138 m_WParser
->GetContainer()->InsertCell(
139 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
143 str
= styleParams
.GetParam(wxS("font-family"));
146 m_WParser
->SetFontFace(str
);
147 m_WParser
->GetContainer()->InsertCell(
148 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
153 m_WParser
->SetFontSize(oldsize
);
154 m_WParser
->SetFontBold(oldbold
);
155 m_WParser
->SetFontUnderlined(oldunderlined
);
156 m_WParser
->SetFontFace(oldfontface
);
157 m_WParser
->SetFontItalic(olditalic
);
158 m_WParser
->GetContainer()->InsertCell(
159 new wxHtmlFontCell(m_WParser
->CreateCurrentFont()));
161 if (oldclr
!= m_WParser
->GetActualColor())
163 m_WParser
->SetActualColor(oldclr
);
164 m_WParser
->GetContainer()->InsertCell(
165 new wxHtmlColourCell(oldclr
));
168 if (oldbackmode
!= m_WParser
->GetActualBackgroundMode() ||
169 oldbackclr
!= m_WParser
->GetActualBackgroundColor())
171 m_WParser
->SetActualBackgroundMode(oldbackmode
);
172 m_WParser
->SetActualBackgroundColor(oldbackclr
);
173 m_WParser
->GetContainer()->InsertCell(
174 new wxHtmlColourCell(oldbackclr
, oldbackmode
== wxTRANSPARENT
? wxHTML_CLR_TRANSPARENT_BACKGROUND
: wxHTML_CLR_BACKGROUND
));
180 TAG_HANDLER_END(SPAN
)
183 TAGS_MODULE_BEGIN(Spans
)
185 TAGS_MODULE_ADD(SPAN
)
187 TAGS_MODULE_END(Spans
)