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