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