]> git.saurik.com Git - wxWidgets.git/blame - src/html/m_span.cpp
Read and write files using binary mode in wxStyledTextCtrl.
[wxWidgets.git] / src / html / m_span.cpp
CommitLineData
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
24FORCE_LINK_ME(m_span)
25
26
27TAG_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();
f5413b87
VZ
37 wxColour oldbackclr = m_WParser->GetActualBackgroundColor();
38 int oldbackmode = m_WParser->GetActualBackgroundMode();
f68e16c5
VZ
39 int oldsize = m_WParser->GetFontSize();
40 int oldbold = m_WParser->GetFontBold();
3e65f74e
VZ
41 int olditalic = m_WParser->GetFontItalic();
42 int oldunderlined = m_WParser->GetFontUnderlined();
43 wxString oldfontface = m_WParser->GetFontFace();
f68e16c5
VZ
44
45 // Load any style parameters
46 wxHtmlStyleParams styleParams(tag);
47
48 wxString str;
49
50 str = styleParams.GetParam(wxS("color"));
51 if ( !str.empty() )
52 {
53 wxColour clr;
54 if ( wxHtmlTag::ParseAsColour(str, &clr) )
55 {
56 m_WParser->SetActualColor(clr);
57 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr));
58 }
59 }
60
f5413b87
VZ
61 str = styleParams.GetParam(wxS("background-color"));
62 if ( !str.empty() )
63 {
64 wxColour clr;
65 if ( wxHtmlTag::ParseAsColour(str, &clr) )
66 {
67 m_WParser->SetActualBackgroundColor(clr);
68 m_WParser->SetActualBackgroundMode(wxBRUSHSTYLE_SOLID);
69 m_WParser->GetContainer()->InsertCell(new wxHtmlColourCell(clr, wxHTML_CLR_BACKGROUND));
70 }
71 }
72
f68e16c5
VZ
73 str = styleParams.GetParam(wxS("font-size"));
74 if ( !str.empty() )
75 {
76 // Point size
77 int foundIndex = str.Find(wxS("pt"));
78 if (foundIndex != wxNOT_FOUND)
79 {
80 str.Truncate(foundIndex);
81
82 long sizeValue;
83 if (str.ToLong(&sizeValue) == true)
84 {
85 // Set point size
86 m_WParser->SetFontPointSize(sizeValue);
87 m_WParser->GetContainer()->InsertCell(
88 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
89 }
90 }
91 // else: check for other ways of specifying size (TODO)
92 }
93
94 str = styleParams.GetParam(wxS("font-weight"));
95 if ( !str.empty() )
96 {
97 // Only bold and normal supported just now
98 if ( str == wxS("bold") )
99 {
100 m_WParser->SetFontBold(true);
101 m_WParser->GetContainer()->InsertCell(
102 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
103 }
104 else if ( str == wxS("normal") )
105 {
106 m_WParser->SetFontBold(false);
107 m_WParser->GetContainer()->InsertCell(
108 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
109 }
110 }
111
3e65f74e
VZ
112 str = styleParams.GetParam(wxS("font-style"));
113 if ( !str.empty() )
114 {
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") )
118 {
119 m_WParser->SetFontItalic(true);
120 m_WParser->GetContainer()->InsertCell(
121 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
122 }
123 else if ( str == wxS("normal") )
124 {
125 m_WParser->SetFontItalic(false);
126 m_WParser->GetContainer()->InsertCell(
127 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
128 }
129 }
f68e16c5 130
3e65f74e
VZ
131 str = styleParams.GetParam(wxS("text-decoration"));
132 if ( !str.empty() )
f68e16c5 133 {
3e65f74e
VZ
134 // Only underline is supported.
135 if ( str == wxS("underline") )
136 {
137 m_WParser->SetFontUnderlined(true);
138 m_WParser->GetContainer()->InsertCell(
139 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
140 }
f68e16c5 141 }
3e65f74e
VZ
142
143 str = styleParams.GetParam(wxS("font-family"));
144 if ( !str.empty() )
f68e16c5 145 {
3e65f74e
VZ
146 m_WParser->SetFontFace(str);
147 m_WParser->GetContainer()->InsertCell(
148 new wxHtmlFontCell(m_WParser->CreateCurrentFont()));
f68e16c5 149 }
3e65f74e
VZ
150
151 ParseInner(tag);
152
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()));
160
f68e16c5
VZ
161 if (oldclr != m_WParser->GetActualColor())
162 {
163 m_WParser->SetActualColor(oldclr);
3e65f74e
VZ
164 m_WParser->GetContainer()->InsertCell(
165 new wxHtmlColourCell(oldclr));
f68e16c5
VZ
166 }
167
f5413b87
VZ
168 if (oldbackmode != m_WParser->GetActualBackgroundMode() ||
169 oldbackclr != m_WParser->GetActualBackgroundColor())
170 {
171 m_WParser->SetActualBackgroundMode(oldbackmode);
172 m_WParser->SetActualBackgroundColor(oldbackclr);
173 m_WParser->GetContainer()->InsertCell(
174 new wxHtmlColourCell(oldbackclr, oldbackmode == wxBRUSHSTYLE_TRANSPARENT ? wxHTML_CLR_TRANSPARENT_BACKGROUND : wxHTML_CLR_BACKGROUND));
175 }
176
f68e16c5
VZ
177 return true;
178 }
179
180TAG_HANDLER_END(SPAN)
181
182
183TAGS_MODULE_BEGIN(Spans)
184
185 TAGS_MODULE_ADD(SPAN)
186
187TAGS_MODULE_END(Spans)
188
189#endif // wxUSE_HTML