]> git.saurik.com Git - wxWidgets.git/blob - src/html/winpars.cpp
OnEnter/OnDragOver API update (compiles, links, somewhat runs under wxGTK)
[wxWidgets.git] / src / html / winpars.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: winpars.cpp
3 // Purpose: wxHtmlParser class (generic parser)
4 // Author: Vaclav Slavik
5 // RCS-ID: $Id$
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows Licence
8 /////////////////////////////////////////////////////////////////////////////
9
10
11 #ifdef __GNUG__
12 #pragma implementation
13 #endif
14
15 #include <wx/wxprec.h>
16
17 #include "wx/defs.h"
18 #if wxUSE_HTML
19
20 #ifdef __BORDLANDC__
21 #pragma hdrstop
22 #endif
23
24 #ifndef WXPRECOMP
25 #include <wx/wx.h>
26 #endif
27
28 #include "wx/html/htmldefs.h"
29 #include "wx/html/winpars.h"
30 #include "wx/html/htmlwin.h"
31
32
33 //-----------------------------------------------------------------------------
34 // wxHtmlWinParser
35 //-----------------------------------------------------------------------------
36
37
38 wxList wxHtmlWinParser::m_Modules;
39
40 wxHtmlWinParser::wxHtmlWinParser(wxWindow *wnd) : wxHtmlParser()
41 {
42 m_Window = wnd;
43 m_Container = NULL;
44 m_DC = NULL;
45 m_CharHeight = m_CharWidth = 0;
46 m_UseLink = FALSE;
47
48 {
49 int i, j, k, l, m;
50 for (i = 0; i < 2; i++)
51 for (j = 0; j < 2; j++)
52 for (k = 0; k < 2; k++)
53 for (l = 0; l < 2; l++)
54 for (m = 0; m < 7; m++)
55 m_FontsTable[i][j][k][l][m] = NULL;
56 #ifdef __WXMSW__
57 static int default_sizes[7] = {7, 8, 10, 12, 16, 22, 30};
58 #else
59 static int default_sizes[7] = {10, 12, 14, 16, 19, 24, 32};
60 #endif
61 SetFonts("", wxSLANT, "", wxSLANT, default_sizes);
62 }
63
64 // fill in wxHtmlParser's tables:
65 wxNode *node = m_Modules.GetFirst();
66 while (node){
67 wxHtmlTagsModule *mod = (wxHtmlTagsModule*) node -> GetData();
68 mod -> FillHandlersTable(this);
69 node = node -> GetNext();
70 }
71 }
72
73
74
75 void wxHtmlWinParser::AddModule(wxHtmlTagsModule *module)
76 {
77 m_Modules.Append(module);
78 }
79
80
81
82 void wxHtmlWinParser::SetFonts(wxString normal_face, int normal_italic_mode, wxString fixed_face, int fixed_italic_mode, const int *sizes)
83 {
84 for (int i = 0; i < 7; i++) m_FontsSizes[i] = sizes[i];
85 m_FontFaceFixed = fixed_face;
86 m_FontFaceNormal = normal_face;
87 m_ItalicModeFixed = fixed_italic_mode;
88 m_ItalicModeNormal = normal_italic_mode;
89 }
90
91
92
93 void wxHtmlWinParser::InitParser(const wxString& source)
94 {
95 wxHtmlParser::InitParser(source);
96 wxASSERT_MSG(m_DC != NULL, _("no DC assigned to wxHtmlWinParser!!"));
97
98 m_FontBold = m_FontItalic = m_FontUnderlined = m_FontFixed = FALSE;
99 m_FontSize = 0;
100 CreateCurrentFont(); // we're selecting default font into
101 m_DC -> GetTextExtent("H", &m_CharWidth, &m_CharHeight);
102 /* NOTE : we're not using GetCharWidth/Height() because
103 of differences under X and win
104 */
105
106 m_Link = "";
107 m_LinkColor.Set(0, 0, 0xFF);
108 m_ActualColor.Set(0, 0, 0);
109 m_Align = wxHTML_ALIGN_LEFT;
110 m_tmpLastWasSpace = FALSE;
111
112 OpenContainer();
113
114 OpenContainer();
115 m_Container -> InsertCell(new wxHtmlColourCell(m_ActualColor));
116 m_Container -> InsertCell(new wxHtmlFontCell(CreateCurrentFont()));
117 }
118
119
120
121 void wxHtmlWinParser::DoneParser()
122 {
123 m_Container = NULL;
124 wxHtmlParser::DoneParser();
125 }
126
127
128
129 wxObject* wxHtmlWinParser::GetProduct()
130 {
131 wxHtmlContainerCell *top;
132
133 CloseContainer();
134 OpenContainer();
135 GetContainer() -> SetIndent(m_CharHeight, wxHTML_INDENT_TOP);
136 top = m_Container;
137 while (top -> GetParent()) top = top -> GetParent();
138 return top;
139 }
140
141
142
143 wxList* wxHtmlWinParser::GetTempData()
144 {
145 int i, j, k, l, m;
146 wxFont *f;
147 wxList *lst = wxHtmlParser::GetTempData();
148
149 if (lst == NULL) lst = new wxList;
150 lst -> DeleteContents(TRUE);
151
152 for (i = 0; i < 2; i++)
153 for (j = 0; j < 2; j++)
154 for (k = 0; k < 2; k++)
155 for (l = 0; l < 2; l++)
156 for (m = 0; m < 7; m++) {
157 f = m_FontsTable[i][j][k][l][m];
158 if (f) lst -> Append(f);
159 }
160 return lst;
161 }
162
163
164
165 void wxHtmlWinParser::AddText(const char* txt)
166 {
167 wxHtmlCell *c;
168 int i = 0, x, lng = strlen(txt);
169 char temp[wxHTML_BUFLEN];
170 register char d;
171 int templen = 0;
172
173 if (m_tmpLastWasSpace) {
174 while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++;
175 }
176
177 while (i < lng) {
178 x = 0;
179 d = temp[templen++] = txt[i];
180 if ((d == '\n') || (d == '\r') || (d == ' ') || (d == '\t')) {
181 i++, x++;
182 while ((i < lng) && ((txt[i] == '\n') || (txt[i] == '\r') || (txt[i] == ' ') || (txt[i] == '\t'))) i++, x++;
183 }
184 else i++;
185
186 if (x) {
187 temp[templen-1] = ' ';
188 temp[templen] = 0;
189 templen = 0;
190 c = new wxHtmlWordCell(temp, *(GetDC()));
191 if (m_UseLink) c -> SetLink(m_Link);
192 m_Container -> InsertCell(c);
193 m_tmpLastWasSpace = TRUE;
194 }
195 }
196 if (templen) {
197 temp[templen] = 0;
198 c = new wxHtmlWordCell(temp, *(GetDC()));
199 if (m_UseLink) c -> SetLink(m_Link);
200 m_Container -> InsertCell(c);
201 m_tmpLastWasSpace = FALSE;
202 }
203 }
204
205
206
207 wxHtmlContainerCell* wxHtmlWinParser::OpenContainer()
208 {
209 m_Container = new wxHtmlContainerCell(m_Container);
210 m_Container -> SetAlignHor(m_Align);
211 m_tmpLastWasSpace = TRUE;
212 /* to avoid space being first character in paragraph */
213 return m_Container;
214 }
215
216
217
218 wxHtmlContainerCell* wxHtmlWinParser::SetContainer(wxHtmlContainerCell *c)
219 {
220 m_tmpLastWasSpace = TRUE;
221 /* to avoid space being first character in paragraph */
222 return m_Container = c;
223 }
224
225
226
227 wxHtmlContainerCell* wxHtmlWinParser::CloseContainer()
228 {
229 m_Container = m_Container -> GetParent();
230 return m_Container;
231 }
232
233
234
235 wxFont* wxHtmlWinParser::CreateCurrentFont()
236 {
237 int fb = GetFontBold(),
238 fi = GetFontItalic(),
239 fu = GetFontUnderlined(),
240 ff = GetFontFixed(),
241 fs = GetFontSize() + 2 /*remap from <-2;4> to <0;7>*/ ;
242
243 if (m_FontsTable[fb][fi][fu][ff][fs] == NULL) {
244 m_FontsTable[fb][fi][fu][ff][fs] =
245 //wxTheFontList -> FindOrCreateFont(
246 new wxFont(
247 m_FontsSizes[fs],
248 ff ? wxMODERN : wxSWISS,
249 fi ? (ff ? m_ItalicModeFixed : m_ItalicModeNormal) : wxNORMAL,
250 fb ? wxBOLD : wxNORMAL,
251 fu ? TRUE : FALSE, ff ? m_FontFaceFixed : m_FontFaceNormal);
252 }
253 m_DC -> SetFont(*(m_FontsTable[fb][fi][fu][ff][fs]));
254 return (m_FontsTable[fb][fi][fu][ff][fs]);
255 }
256
257
258
259
260 //-----------------------------------------------------------------------------
261 // wxHtmlWinTagHandler
262 //-----------------------------------------------------------------------------
263
264 IMPLEMENT_ABSTRACT_CLASS(wxHtmlWinTagHandler, wxHtmlTagHandler)
265
266
267
268 //-----------------------------------------------------------------------------
269 // wxHtmlTagsModule
270 //-----------------------------------------------------------------------------
271
272
273 IMPLEMENT_DYNAMIC_CLASS(wxHtmlTagsModule, wxModule)
274
275
276 bool wxHtmlTagsModule::OnInit()
277 {
278 wxHtmlWinParser::AddModule(this);
279 return TRUE;
280 }
281
282
283
284 void wxHtmlTagsModule::OnExit()
285 {
286 }
287 #endif
288