]> git.saurik.com Git - wxWidgets.git/blame - src/html/htmlwin.cpp
added new files to be included in the installer
[wxWidgets.git] / src / html / htmlwin.cpp
CommitLineData
5526e819
VS
1/////////////////////////////////////////////////////////////////////////////
2// Name: htmlwin.cpp
3// Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation)
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__
892aeafc
VS
12#pragma implementation "htmlwin.h"
13#pragma implementation "htmlproc.h"
5526e819
VS
14#endif
15
3096bd2f 16#include "wx/wxprec.h"
5526e819
VS
17
18#include "wx/defs.h"
f6bcfd97 19#if wxUSE_HTML && wxUSE_STREAMS
5526e819
VS
20
21#ifdef __BORDLANDC__
22#pragma hdrstop
23#endif
24
25#ifndef WXPRECOMP
3096bd2f 26#include "wx/wx.h"
5526e819
VS
27#endif
28
69941f05 29#include "wx/html/htmlwin.h"
69941f05 30#include "wx/html/forcelnk.h"
892aeafc 31#include "wx/html/htmlproc.h"
f3c82859 32#include "wx/log.h"
892aeafc
VS
33#include "wx/arrimpl.cpp"
34#include "wx/list.h"
35#include "wx/listimpl.cpp"
36
37//-----------------------------------------------------------------------------
38// wxHtmlHistoryItem
39//-----------------------------------------------------------------------------
40
41// item of history list
42class WXDLLEXPORT wxHtmlHistoryItem : public wxObject
43{
44public:
45 wxHtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;}
46 int GetPos() const {return m_Pos;}
47 void SetPos(int p) {m_Pos = p;}
48 const wxString& GetPage() const {return m_Page;}
49 const wxString& GetAnchor() const {return m_Anchor;}
50
51private:
52 wxString m_Page;
53 wxString m_Anchor;
54 int m_Pos;
55};
5526e819 56
5526e819
VS
57
58//-----------------------------------------------------------------------------
892aeafc 59// our private arrays:
5526e819
VS
60//-----------------------------------------------------------------------------
61
892aeafc
VS
62WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray);
63WX_DEFINE_OBJARRAY(wxHtmlHistoryArray);
5526e819 64
892aeafc
VS
65WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList);
66WX_DEFINE_LIST(wxHtmlProcessorList);
5526e819 67
892aeafc
VS
68//-----------------------------------------------------------------------------
69// wxHtmlWindow
70//-----------------------------------------------------------------------------
5526e819
VS
71
72
269e8200 73wxHtmlWindow::wxHtmlWindow(wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
f6bcfd97 74 long style, const wxString& name) : wxScrolledWindow(parent, id, pos, size, style | wxVSCROLL | wxHSCROLL, name)
5526e819
VS
75{
76 m_tmpMouseMoved = FALSE;
846914d1 77 m_tmpLastLink = NULL;
89de9af3 78 m_tmpCanDrawLocks = 0;
5526e819
VS
79 m_FS = new wxFileSystem();
80 m_RelatedStatusBar = -1;
81 m_RelatedFrame = NULL;
892aeafc 82 m_TitleFormat = wxT("%s");
d5db80c2 83 m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
5526e819
VS
84 m_Cell = NULL;
85 m_Parser = new wxHtmlWinParser(this);
4f9297b0 86 m_Parser->SetFS(m_FS);
5526e819
VS
87 SetBorders(10);
88 m_HistoryPos = -1;
89 m_HistoryOn = TRUE;
892aeafc
VS
90 m_History = new wxHtmlHistoryArray;
91 m_Processors = NULL;
a547ebff 92 m_Style = style;
4f9297b0 93 SetPage(wxT("<html><body></body></html>"));
5526e819
VS
94}
95
96
97
98wxHtmlWindow::~wxHtmlWindow()
99{
100 HistoryClear();
101
102 if (m_Cell) delete m_Cell;
103
5526e819
VS
104 delete m_Parser;
105 delete m_FS;
892aeafc
VS
106 delete m_History;
107 delete m_Processors;
5526e819
VS
108}
109
110
111
112void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format)
113{
114 m_RelatedFrame = frame;
115 m_TitleFormat = format;
116}
117
118
119
120void wxHtmlWindow::SetRelatedStatusBar(int bar)
121{
122 m_RelatedStatusBar = bar;
123}
269e8200
RD
124
125
126
8eb2940f 127void wxHtmlWindow::SetFonts(wxString normal_face, wxString fixed_face, const int *sizes)
5526e819 128{
d5db80c2
VS
129 wxString op = m_OpenedPage;
130
4f9297b0 131 m_Parser->SetFonts(normal_face, fixed_face, sizes);
892aeafc 132 // fonts changed => contents invalid, so reload the page:
bfb9ee96 133 SetPage(wxT("<html><body></body></html>"));
d5db80c2 134 if (!op.IsEmpty()) LoadPage(op);
5526e819
VS
135}
136
137
138
139bool wxHtmlWindow::SetPage(const wxString& source)
140{
892aeafc
VS
141 wxString newsrc(source);
142
143 // pass HTML through registered processors:
960ba969 144 if (m_Processors || m_GlobalProcessors)
892aeafc 145 {
960ba969
VS
146 wxHtmlProcessorList::Node *nodeL, *nodeG;
147 int prL, prG;
892aeafc
VS
148
149 nodeL = (m_Processors) ? m_Processors->GetFirst() : NULL;
960ba969
VS
150 nodeG = (m_GlobalProcessors) ? m_GlobalProcessors->GetFirst() : NULL;
151
152 // VS: there are two lists, global and local, both of them sorted by
e421922f 153 // priority. Since we have to go through _both_ lists with
960ba969
VS
154 // decreasing priority, we "merge-sort" the lists on-line by
155 // processing that one of the two heads that has higher priority
156 // in every iteration
157 while (nodeL || nodeG)
892aeafc
VS
158 {
159 prL = (nodeL) ? nodeL->GetData()->GetPriority() : -1;
960ba969
VS
160 prG = (nodeG) ? nodeG->GetData()->GetPriority() : -1;
161 if (prL > prG)
892aeafc 162 {
73348d09
VS
163 if (nodeL->GetData()->IsEnabled())
164 newsrc = nodeL->GetData()->Process(newsrc);
892aeafc
VS
165 nodeL = nodeL->GetNext();
166 }
960ba969 167 else // prL <= prG
892aeafc 168 {
73348d09
VS
169 if (nodeG->GetData()->IsEnabled())
170 newsrc = nodeG->GetData()->Process(newsrc);
960ba969 171 nodeG = nodeG->GetNext();
892aeafc
VS
172 }
173 }
174 }
5526e819 175
892aeafc
VS
176 // ...and run the parser on it:
177 wxClientDC *dc = new wxClientDC(this);
4f9297b0 178 dc->SetMapMode(wxMM_TEXT);
5526e819 179 SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
d5db80c2 180 m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
4f9297b0 181 m_Parser->SetDC(dc);
33ac7e6f 182 if (m_Cell)
4f9297b0 183 {
89de9af3
VS
184 delete m_Cell;
185 m_Cell = NULL;
f61815af 186 }
892aeafc 187 m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc);
5526e819 188 delete dc;
4f9297b0
VS
189 m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
190 m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER);
5526e819 191 CreateLayout();
bfb9ee96 192 if (m_tmpCanDrawLocks == 0)
892aeafc 193 Refresh();
5526e819
VS
194 return TRUE;
195}
196
197
198bool wxHtmlWindow::LoadPage(const wxString& location)
199{
200 wxFSFile *f;
201 bool rt_val;
fc7dfaf8 202 bool needs_refresh = FALSE;
33ac7e6f 203
169ee06c 204 SetCursor(*wxHOURGLASS_CURSOR);
fc7dfaf8 205 wxYield(); Refresh(FALSE);
5526e819 206
89de9af3 207 m_tmpCanDrawLocks++;
e421922f 208 if (m_HistoryOn && (m_HistoryPos != -1))
4f9297b0 209 {
960ba969 210 // store scroll position into history item:
5526e819 211 int x, y;
e421922f 212 GetViewStart(&x, &y);
892aeafc 213 (*m_History)[m_HistoryPos].SetPos(y);
5526e819
VS
214 }
215
e421922f 216 if (location[0] == wxT('#'))
4f9297b0 217 {
960ba969 218 // local anchor:
5526e819 219 wxString anch = location.Mid(1) /*1 to end*/;
89de9af3 220 m_tmpCanDrawLocks--;
5526e819 221 rt_val = ScrollToAnchor(anch);
fc7dfaf8
VS
222 m_tmpCanDrawLocks++;
223 }
33ac7e6f 224 else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage)
4f9297b0 225 {
fc7dfaf8
VS
226 wxString anch = location.AfterFirst(wxT('#'));
227 m_tmpCanDrawLocks--;
228 rt_val = ScrollToAnchor(anch);
229 m_tmpCanDrawLocks++;
230 }
33ac7e6f
KB
231 else if (location.Find(wxT('#')) != wxNOT_FOUND &&
232 (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage)
e421922f 233 {
fc7dfaf8
VS
234 wxString anch = location.AfterFirst(wxT('#'));
235 m_tmpCanDrawLocks--;
236 rt_val = ScrollToAnchor(anch);
237 m_tmpCanDrawLocks++;
5526e819
VS
238 }
239
33ac7e6f 240 else
4f9297b0 241 {
fc7dfaf8 242 needs_refresh = TRUE;
5526e819 243 // load&display it:
33ac7e6f 244 if (m_RelatedStatusBar != -1)
e421922f 245 {
4f9297b0 246 m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar);
fc7dfaf8 247 Refresh(FALSE);
5526e819
VS
248 }
249
4f9297b0 250 f = m_FS->OpenFile(location);
33ac7e6f
KB
251
252 if (f == NULL)
e421922f 253 {
f6bcfd97 254 wxLogError(_("Unable to open requested HTML document: %s"), location.c_str());
89de9af3 255 m_tmpCanDrawLocks--;
169ee06c
VS
256
257 SetCursor(*wxSTANDARD_CURSOR);
5526e819
VS
258 return FALSE;
259 }
260
33ac7e6f 261 else
e421922f 262 {
5526e819
VS
263 wxNode *node;
264 wxString src = wxEmptyString;
265
33ac7e6f 266 if (m_RelatedStatusBar != -1)
e421922f 267 {
5526e819 268 wxString msg = _("Loading : ") + location;
4f9297b0 269 m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar);
fc7dfaf8 270 Refresh(FALSE);
5526e819
VS
271 }
272
273 node = m_Filters.GetFirst();
4f9297b0 274 while (node)
e421922f 275 {
4f9297b0
VS
276 wxHtmlFilter *h = (wxHtmlFilter*) node->GetData();
277 if (h->CanRead(*f))
e421922f 278 {
4f9297b0 279 src = h->ReadFile(*f);
5526e819
VS
280 break;
281 }
4f9297b0 282 node = node->GetNext();
5526e819 283 }
33ac7e6f 284 if (src == wxEmptyString)
e421922f 285 {
89de9af3 286 if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter();
4f9297b0 287 src = m_DefaultFilter->ReadFile(*f);
89de9af3 288 }
5526e819 289
4f9297b0 290 m_FS->ChangePathTo(f->GetLocation());
5526e819 291 rt_val = SetPage(src);
4f9297b0 292 m_OpenedPage = f->GetLocation();
33ac7e6f 293 if (f->GetAnchor() != wxEmptyString)
e421922f 294 {
fc7dfaf8 295 wxYield();
4f9297b0 296 ScrollToAnchor(f->GetAnchor());
5526e819
VS
297 }
298
299 delete f;
300
4f9297b0 301 if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar);
5526e819
VS
302 }
303 }
304
4f9297b0
VS
305 if (m_HistoryOn) // add this page to history there:
306 {
892aeafc 307 int c = m_History->GetCount() - (m_HistoryPos + 1);
5526e819 308
ee19c324
VS
309 if (m_HistoryPos < 0 ||
310 (*m_History)[m_HistoryPos].GetPage() != m_OpenedPage ||
311 (*m_History)[m_HistoryPos].GetAnchor() != m_OpenedAnchor)
312 {
313 m_HistoryPos++;
314 for (int i = 0; i < c; i++)
315 m_History->Remove(m_HistoryPos);
316 m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor));
317 }
5526e819
VS
318 }
319
096824d7
VS
320 if (m_OpenedPageTitle == wxEmptyString)
321 OnSetTitle(wxFileNameFromPath(m_OpenedPage));
169ee06c 322 SetCursor(*wxSTANDARD_CURSOR);
fc7dfaf8 323
33ac7e6f 324 if (needs_refresh)
4f9297b0 325 {
fc7dfaf8
VS
326 wxYield();
327 m_tmpCanDrawLocks--;
328 Refresh();
329 }
330 else
331 m_tmpCanDrawLocks--;
332
5526e819
VS
333 return rt_val;
334}
335
336
337
338bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor)
339{
4f9297b0 340 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
f3c82859
VS
341 if (!c)
342 {
f6bcfd97 343 wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str());
f3c82859
VS
344 return FALSE;
345 }
33ac7e6f 346 else
4f9297b0 347 {
5526e819 348 int y;
269e8200 349
4f9297b0 350 for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY();
efba2b89 351 Scroll(-1, y / wxHTML_SCROLL_STEP);
5526e819
VS
352 m_OpenedAnchor = anchor;
353 return TRUE;
354 }
355}
356
357
d5db80c2 358void wxHtmlWindow::OnSetTitle(const wxString& title)
5526e819 359{
33ac7e6f 360 if (m_RelatedFrame)
4f9297b0 361 {
5526e819
VS
362 wxString tit;
363 tit.Printf(m_TitleFormat, title.c_str());
4f9297b0 364 m_RelatedFrame->SetTitle(tit);
5526e819 365 }
d5db80c2 366 m_OpenedPageTitle = title;
5526e819
VS
367}
368
369
370
371
372
373void wxHtmlWindow::CreateLayout()
374{
375 int ClientWidth, ClientHeight;
376
377 if (!m_Cell) return;
a547ebff 378
33ac7e6f 379 if (m_Style & wxHW_SCROLLBAR_NEVER)
4f9297b0
VS
380 {
381 SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off
a547ebff 382 GetClientSize(&ClientWidth, &ClientHeight);
4f9297b0 383 m_Cell->Layout(ClientWidth);
a547ebff
VS
384 }
385
386 else {
387 GetClientSize(&ClientWidth, &ClientHeight);
4f9297b0 388 m_Cell->Layout(ClientWidth);
33ac7e6f 389 if (ClientHeight < m_Cell->GetHeight() + GetCharHeight())
e421922f 390 {
f3bcfd9b
VS
391 SetScrollbars(
392 wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
4f9297b0
VS
393 m_Cell->GetWidth() / wxHTML_SCROLL_STEP,
394 (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP
f3bcfd9b 395 /*cheat: top-level frag is always container*/);
a547ebff 396 }
4f9297b0 397 else /* we fit into window, no need for scrollbars */
e421922f 398 {
4f9297b0 399 SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
89de9af3 400 GetClientSize(&ClientWidth, &ClientHeight);
4f9297b0 401 m_Cell->Layout(ClientWidth); // ...and relayout
89de9af3 402 }
a547ebff 403 }
5526e819
VS
404}
405
269e8200 406
5526e819
VS
407
408void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path)
409{
410 wxString oldpath;
411 wxString tmp;
d5db80c2
VS
412 int p_fontsizes[7];
413 wxString p_fff, p_ffn;
5526e819 414
33ac7e6f 415 if (path != wxEmptyString)
4f9297b0
VS
416 {
417 oldpath = cfg->GetPath();
418 cfg->SetPath(path);
5526e819
VS
419 }
420
892aeafc
VS
421 m_Borders = cfg->Read(wxT("wxHtmlWindow/Borders"), m_Borders);
422 p_fff = cfg->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
423 p_ffn = cfg->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
bfb9ee96 424 for (int i = 0; i < 7; i++)
4f9297b0 425 {
66a77a74 426 tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
4f9297b0 427 p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]);
5526e819 428 }
8eb2940f 429 SetFonts(p_ffn, p_fff, p_fontsizes);
5526e819
VS
430
431 if (path != wxEmptyString)
4f9297b0 432 cfg->SetPath(oldpath);
5526e819
VS
433}
434
435
436
437void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path)
438{
439 wxString oldpath;
440 wxString tmp;
441
33ac7e6f 442 if (path != wxEmptyString)
4f9297b0
VS
443 {
444 oldpath = cfg->GetPath();
445 cfg->SetPath(path);
5526e819
VS
446 }
447
892aeafc
VS
448 cfg->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders);
449 cfg->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
450 cfg->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
bfb9ee96 451 for (int i = 0; i < 7; i++)
4f9297b0 452 {
66a77a74 453 tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
4f9297b0 454 cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]);
5526e819
VS
455 }
456
457 if (path != wxEmptyString)
4f9297b0 458 cfg->SetPath(oldpath);
5526e819
VS
459}
460
461
462
463bool wxHtmlWindow::HistoryBack()
464{
465 wxString a, l;
466
467 if (m_HistoryPos < 1) return FALSE;
468
bbda1088
VS
469 // store scroll position into history item:
470 int x, y;
e421922f 471 GetViewStart(&x, &y);
892aeafc 472 (*m_History)[m_HistoryPos].SetPos(y);
bbda1088
VS
473
474 // go to previous position:
5526e819
VS
475 m_HistoryPos--;
476
892aeafc
VS
477 l = (*m_History)[m_HistoryPos].GetPage();
478 a = (*m_History)[m_HistoryPos].GetAnchor();
5526e819 479 m_HistoryOn = FALSE;
89de9af3 480 m_tmpCanDrawLocks++;
5526e819 481 if (a == wxEmptyString) LoadPage(l);
fc7dfaf8 482 else LoadPage(l + wxT("#") + a);
5526e819 483 m_HistoryOn = TRUE;
c88293a4 484 wxYield();
89de9af3 485 m_tmpCanDrawLocks--;
892aeafc 486 Scroll(0, (*m_History)[m_HistoryPos].GetPos());
5526e819
VS
487 Refresh();
488 return TRUE;
489}
490
1b113a81
VS
491bool wxHtmlWindow::HistoryCanBack()
492{
493 if (m_HistoryPos < 1) return FALSE;
494 return TRUE ;
495}
5526e819
VS
496
497
498bool wxHtmlWindow::HistoryForward()
499{
500 wxString a, l;
501
502 if (m_HistoryPos == -1) return FALSE;
892aeafc 503 if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE;
5526e819
VS
504
505 m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage()
506
507 m_HistoryPos++;
892aeafc
VS
508 l = (*m_History)[m_HistoryPos].GetPage();
509 a = (*m_History)[m_HistoryPos].GetAnchor();
5526e819 510 m_HistoryOn = FALSE;
89de9af3 511 m_tmpCanDrawLocks++;
5526e819 512 if (a == wxEmptyString) LoadPage(l);
fc7dfaf8 513 else LoadPage(l + wxT("#") + a);
5526e819 514 m_HistoryOn = TRUE;
c88293a4 515 wxYield();
89de9af3 516 m_tmpCanDrawLocks--;
892aeafc 517 Scroll(0, (*m_History)[m_HistoryPos].GetPos());
5526e819
VS
518 Refresh();
519 return TRUE;
520}
521
1b113a81
VS
522bool wxHtmlWindow::HistoryCanForward()
523{
524 if (m_HistoryPos == -1) return FALSE;
892aeafc 525 if (m_HistoryPos >= (int)m_History->GetCount() - 1)return FALSE;
1b113a81
VS
526 return TRUE ;
527}
5526e819
VS
528
529
530void wxHtmlWindow::HistoryClear()
531{
892aeafc 532 m_History->Empty();
5526e819
VS
533 m_HistoryPos = -1;
534}
535
892aeafc
VS
536void wxHtmlWindow::AddProcessor(wxHtmlProcessor *processor)
537{
538 if (!m_Processors)
539 {
540 m_Processors = new wxHtmlProcessorList;
541 m_Processors->DeleteContents(TRUE);
542 }
543 wxHtmlProcessorList::Node *node;
bfb9ee96 544
892aeafc
VS
545 for (node = m_Processors->GetFirst(); node; node = node->GetNext())
546 {
bfb9ee96 547 if (processor->GetPriority() > node->GetData()->GetPriority())
892aeafc
VS
548 {
549 m_Processors->Insert(node, processor);
960ba969 550 return;
892aeafc
VS
551 }
552 }
960ba969 553 m_Processors->Append(processor);
892aeafc
VS
554}
555
960ba969 556/*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor *processor)
892aeafc 557{
960ba969 558 if (!m_GlobalProcessors)
892aeafc 559 {
960ba969
VS
560 m_GlobalProcessors = new wxHtmlProcessorList;
561 m_GlobalProcessors->DeleteContents(TRUE);
892aeafc
VS
562 }
563 wxHtmlProcessorList::Node *node;
e421922f 564
960ba969 565 for (node = m_GlobalProcessors->GetFirst(); node; node = node->GetNext())
892aeafc 566 {
bfb9ee96 567 if (processor->GetPriority() > node->GetData()->GetPriority())
892aeafc 568 {
960ba969
VS
569 m_GlobalProcessors->Insert(node, processor);
570 return;
892aeafc
VS
571 }
572 }
960ba969 573 m_GlobalProcessors->Append(processor);
892aeafc
VS
574}
575
5526e819
VS
576
577
578wxList wxHtmlWindow::m_Filters;
a76015e6 579wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL;
66806a0b
VS
580wxCursor *wxHtmlWindow::s_cur_hand = NULL;
581wxCursor *wxHtmlWindow::s_cur_arrow = NULL;
960ba969 582wxHtmlProcessorList *wxHtmlWindow::m_GlobalProcessors = NULL;
a76015e6
VS
583
584void wxHtmlWindow::CleanUpStatics()
585{
892aeafc 586 delete m_DefaultFilter;
a76015e6 587 m_DefaultFilter = NULL;
269e8200
RD
588 m_Filters.DeleteContents(TRUE);
589 m_Filters.Clear();
960ba969
VS
590 delete m_GlobalProcessors;
591 m_GlobalProcessors = NULL;
892aeafc
VS
592 delete s_cur_hand;
593 delete s_cur_arrow;
a76015e6
VS
594}
595
596
5526e819
VS
597
598void wxHtmlWindow::AddFilter(wxHtmlFilter *filter)
599{
5526e819
VS
600 m_Filters.Append(filter);
601}
602
603
604
605
0b2dadd3 606void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
5526e819 607{
0b2dadd3 608 LoadPage(link.GetHref());
5526e819
VS
609}
610
611
612
613void wxHtmlWindow::OnDraw(wxDC& dc)
614{
615 int x, y;
616 wxRegionIterator upd(GetUpdateRegion()); // get the update rect list
617 int v_y, v_h;
618
89de9af3 619 if (m_tmpCanDrawLocks > 0) return;
33ac7e6f 620
5526e819 621 dc.SetMapMode(wxMM_TEXT);
2faa3a6b 622#if 0
33ac7e6f 623/* VS - I don't think this is neccessary any longer
2faa3a6b 624 MSC_VER 1200 means MSVC 6.0 and it works fine */
5526e819
VS
625#if defined(_MSC_VER) && (_MSC_VER == 1200)
626 ::SetMapMode((HDC)dc.GetHDC(), MM_TEXT);
2faa3a6b 627#endif
5526e819
VS
628#endif
629 dc.SetBackgroundMode(wxTRANSPARENT);
e421922f 630 GetViewStart(&x, &y);
5526e819 631
33ac7e6f 632 while (upd)
4f9297b0 633 {
5526e819
VS
634 v_y = upd.GetY();
635 v_h = upd.GetH();
4f9297b0 636 if (m_Cell) m_Cell->Draw(dc, 0, 0, y * wxHTML_SCROLL_STEP + v_y, y * wxHTML_SCROLL_STEP + v_h + v_y);
5526e819
VS
637 upd++;
638 }
639}
640
641
642
643
644void wxHtmlWindow::OnSize(wxSizeEvent& event)
645{
646 wxScrolledWindow::OnSize(event);
647 CreateLayout();
f6bcfd97 648 Refresh();
5526e819
VS
649}
650
651
5526e819
VS
652void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event)
653{
654 m_tmpMouseMoved = TRUE;
655
33ac7e6f 656 if (event.ButtonDown())
4f9297b0 657 {
5526e819
VS
658 int sx, sy;
659 wxPoint pos;
660 wxString lnk;
661
e421922f 662 GetViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP;
5526e819
VS
663 pos = event.GetPosition();
664
665 if (m_Cell)
4f9297b0 666 m_Cell->OnMouseClick(this, sx + pos.x, sy + pos.y, event);
5526e819
VS
667 }
668}
669
670
671
33ac7e6f 672void wxHtmlWindow::OnIdle(wxIdleEvent& WXUNUSED(event))
5526e819 673{
33ac7e6f 674 if (s_cur_hand == NULL)
66806a0b
VS
675 {
676 s_cur_hand = new wxCursor(wxCURSOR_HAND);
677 s_cur_arrow = new wxCursor(wxCURSOR_ARROW);
678 }
5526e819 679
33ac7e6f 680 if (m_tmpMouseMoved && (m_Cell != NULL))
4f9297b0 681 {
5526e819
VS
682 int sx, sy;
683 int x, y;
846914d1 684 wxHtmlLinkInfo *lnk;
5526e819 685
e421922f 686 GetViewStart(&sx, &sy); sx *= wxHTML_SCROLL_STEP; sy *= wxHTML_SCROLL_STEP;
5526e819
VS
687 wxGetMousePosition(&x, &y);
688 ScreenToClient(&x, &y);
4f9297b0 689 lnk = m_Cell->GetLink(sx + x, sy + y);
5526e819 690
33ac7e6f 691 if (lnk != m_tmpLastLink)
e421922f 692 {
33ac7e6f 693 if (lnk == NULL)
e421922f 694 {
66806a0b 695 SetCursor(*s_cur_arrow);
4f9297b0 696 if (m_RelatedStatusBar != -1) m_RelatedFrame->SetStatusText(wxEmptyString, m_RelatedStatusBar);
622ea783 697 }
33ac7e6f 698 else
e421922f 699 {
66806a0b 700 SetCursor(*s_cur_hand);
33ac7e6f 701 if (m_RelatedStatusBar != -1)
4f9297b0 702 m_RelatedFrame->SetStatusText(lnk->GetHref(), m_RelatedStatusBar);
622ea783
VS
703 }
704 m_tmpLastLink = lnk;
5526e819
VS
705 }
706 m_tmpMouseMoved = FALSE;
707 }
708}
709
710
bfb9ee96 711IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject)
5526e819
VS
712
713IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow)
714
715BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
716 EVT_SIZE(wxHtmlWindow::OnSize)
717 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseEvent)
718 EVT_MOTION(wxHtmlWindow::OnMouseEvent)
719 EVT_IDLE(wxHtmlWindow::OnIdle)
5526e819
VS
720END_EVENT_TABLE()
721
722
723
724
725
a76015e6
VS
726// A module to allow initialization/cleanup
727// without calling these functions from app.cpp or from
728// the user's application.
729
730class wxHtmlWinModule: public wxModule
731{
732DECLARE_DYNAMIC_CLASS(wxHtmlWinModule)
733public:
734 wxHtmlWinModule() : wxModule() {}
735 bool OnInit() { return TRUE; }
736 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
737};
738
739IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule)
740
5526e819
VS
741
742
743
744///// default mod handlers are forced there:
745
c88293a4
VS
746FORCE_LINK(m_layout)
747FORCE_LINK(m_fonts)
748FORCE_LINK(m_image)
749FORCE_LINK(m_list)
750FORCE_LINK(m_dflist)
751FORCE_LINK(m_pre)
752FORCE_LINK(m_hline)
753FORCE_LINK(m_links)
754FORCE_LINK(m_tables)
fa146dd7 755FORCE_LINK(m_meta)
5526e819
VS
756
757
483ff5a5 758#endif