]> git.saurik.com Git - wxWidgets.git/blob - src/html/htmlwin.cpp
don't draw focus rect for custom drawn items when the list control doesn't have focus
[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 #include "wx/wxprec.h"
11
12 #include "wx/defs.h"
13 #if wxUSE_HTML && wxUSE_STREAMS
14
15 #ifdef __BORLANDC__
16 #pragma hdrstop
17 #endif
18
19 #ifndef WXPRECOMP
20 #include "wx/log.h"
21 #include "wx/intl.h"
22 #include "wx/dcclient.h"
23 #include "wx/frame.h"
24 #endif
25
26 #include "wx/html/htmlwin.h"
27 #include "wx/html/htmlproc.h"
28 #include "wx/list.h"
29 #include "wx/clipbrd.h"
30 #include "wx/dataobj.h"
31 #include "wx/timer.h"
32 #include "wx/dcmemory.h"
33 #include "wx/settings.h"
34
35 #include "wx/arrimpl.cpp"
36 #include "wx/listimpl.cpp"
37
38
39 #if wxUSE_CLIPBOARD
40 // ----------------------------------------------------------------------------
41 // wxHtmlWinAutoScrollTimer: the timer used to generate a stream of scroll
42 // events when a captured mouse is held outside the window
43 // ----------------------------------------------------------------------------
44
45 class wxHtmlWinAutoScrollTimer : public wxTimer
46 {
47 public:
48 wxHtmlWinAutoScrollTimer(wxScrolledWindow *win,
49 wxEventType eventTypeToSend,
50 int pos, int orient)
51 {
52 m_win = win;
53 m_eventType = eventTypeToSend;
54 m_pos = pos;
55 m_orient = orient;
56 }
57
58 virtual void Notify();
59
60 private:
61 wxScrolledWindow *m_win;
62 wxEventType m_eventType;
63 int m_pos,
64 m_orient;
65
66 DECLARE_NO_COPY_CLASS(wxHtmlWinAutoScrollTimer)
67 };
68
69 void wxHtmlWinAutoScrollTimer::Notify()
70 {
71 // only do all this as long as the window is capturing the mouse
72 if ( wxWindow::GetCapture() != m_win )
73 {
74 Stop();
75 }
76 else // we still capture the mouse, continue generating events
77 {
78 // first scroll the window if we are allowed to do it
79 wxScrollWinEvent event1(m_eventType, m_pos, m_orient);
80 event1.SetEventObject(m_win);
81 if ( m_win->GetEventHandler()->ProcessEvent(event1) )
82 {
83 // and then send a pseudo mouse-move event to refresh the selection
84 wxMouseEvent event2(wxEVT_MOTION);
85 wxGetMousePosition(&event2.m_x, &event2.m_y);
86
87 // the mouse event coordinates should be client, not screen as
88 // returned by wxGetMousePosition
89 wxWindow *parentTop = m_win;
90 while ( parentTop->GetParent() )
91 parentTop = parentTop->GetParent();
92 wxPoint ptOrig = parentTop->GetPosition();
93 event2.m_x -= ptOrig.x;
94 event2.m_y -= ptOrig.y;
95
96 event2.SetEventObject(m_win);
97
98 // FIXME: we don't fill in the other members - ok?
99 m_win->GetEventHandler()->ProcessEvent(event2);
100 }
101 else // can't scroll further, stop
102 {
103 Stop();
104 }
105 }
106 }
107
108 #endif // wxUSE_CLIPBOARD
109
110
111
112 //-----------------------------------------------------------------------------
113 // wxHtmlHistoryItem
114 //-----------------------------------------------------------------------------
115
116 // item of history list
117 class WXDLLIMPEXP_HTML wxHtmlHistoryItem
118 {
119 public:
120 wxHtmlHistoryItem(const wxString& p, const wxString& a) {m_Page = p, m_Anchor = a, m_Pos = 0;}
121 int GetPos() const {return m_Pos;}
122 void SetPos(int p) {m_Pos = p;}
123 const wxString& GetPage() const {return m_Page;}
124 const wxString& GetAnchor() const {return m_Anchor;}
125
126 private:
127 wxString m_Page;
128 wxString m_Anchor;
129 int m_Pos;
130 };
131
132
133 //-----------------------------------------------------------------------------
134 // our private arrays:
135 //-----------------------------------------------------------------------------
136
137 WX_DECLARE_OBJARRAY(wxHtmlHistoryItem, wxHtmlHistoryArray);
138 WX_DEFINE_OBJARRAY(wxHtmlHistoryArray)
139
140 WX_DECLARE_LIST(wxHtmlProcessor, wxHtmlProcessorList);
141 WX_DEFINE_LIST(wxHtmlProcessorList)
142
143 //-----------------------------------------------------------------------------
144 // wxHtmlWindow
145 //-----------------------------------------------------------------------------
146
147
148 void wxHtmlWindow::Init()
149 {
150 m_tmpMouseMoved = false;
151 m_tmpLastLink = NULL;
152 m_tmpLastCell = NULL;
153 m_tmpCanDrawLocks = 0;
154 m_FS = new wxFileSystem();
155 #if wxUSE_STATUSBAR
156 m_RelatedStatusBar = -1;
157 #endif // wxUSE_STATUSBAR
158 m_RelatedFrame = NULL;
159 m_TitleFormat = wxT("%s");
160 m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
161 m_Cell = NULL;
162 m_Parser = new wxHtmlWinParser(this);
163 m_Parser->SetFS(m_FS);
164 m_HistoryPos = -1;
165 m_HistoryOn = true;
166 m_History = new wxHtmlHistoryArray;
167 m_Processors = NULL;
168 m_Style = 0;
169 SetBorders(10);
170 m_selection = NULL;
171 m_makingSelection = false;
172 #if wxUSE_CLIPBOARD
173 m_timerAutoScroll = NULL;
174 m_lastDoubleClick = 0;
175 #endif // wxUSE_CLIPBOARD
176 m_backBuffer = NULL;
177 m_eraseBgInOnPaint = false;
178 m_tmpSelFromCell = NULL;
179 }
180
181 bool wxHtmlWindow::Create(wxWindow *parent, wxWindowID id,
182 const wxPoint& pos, const wxSize& size,
183 long style, const wxString& name)
184 {
185 if (!wxScrolledWindow::Create(parent, id, pos, size,
186 style | wxVSCROLL | wxHSCROLL,
187 name))
188 return false;
189
190 m_Style = style;
191 SetPage(wxT("<html><body></body></html>"));
192 return true;
193 }
194
195
196 wxHtmlWindow::~wxHtmlWindow()
197 {
198 #if wxUSE_CLIPBOARD
199 StopAutoScrolling();
200 #endif // wxUSE_CLIPBOARD
201 HistoryClear();
202
203 delete m_selection;
204
205 delete m_Cell;
206
207 if ( m_Processors )
208 {
209 WX_CLEAR_LIST(wxHtmlProcessorList, *m_Processors);
210 }
211
212 delete m_Parser;
213 delete m_FS;
214 delete m_History;
215 delete m_Processors;
216 delete m_backBuffer;
217 }
218
219
220
221 void wxHtmlWindow::SetRelatedFrame(wxFrame* frame, const wxString& format)
222 {
223 m_RelatedFrame = frame;
224 m_TitleFormat = format;
225 }
226
227
228
229 #if wxUSE_STATUSBAR
230 void wxHtmlWindow::SetRelatedStatusBar(int bar)
231 {
232 m_RelatedStatusBar = bar;
233 }
234 #endif // wxUSE_STATUSBAR
235
236
237
238 void wxHtmlWindow::SetFonts(const wxString& normal_face, const wxString& fixed_face, const int *sizes)
239 {
240 m_Parser->SetFonts(normal_face, fixed_face, sizes);
241
242 // re-layout the page after changing fonts:
243 DoSetPage(*(m_Parser->GetSource()));
244 }
245
246 void wxHtmlWindow::SetStandardFonts(int size,
247 const wxString& normal_face,
248 const wxString& fixed_face)
249 {
250 m_Parser->SetStandardFonts(size, normal_face, fixed_face);
251
252 // re-layout the page after changing fonts:
253 DoSetPage(*(m_Parser->GetSource()));
254 }
255
256 bool wxHtmlWindow::SetPage(const wxString& source)
257 {
258 m_OpenedPage = m_OpenedAnchor = m_OpenedPageTitle = wxEmptyString;
259 return DoSetPage(source);
260 }
261
262 bool wxHtmlWindow::DoSetPage(const wxString& source)
263 {
264 wxString newsrc(source);
265
266 wxDELETE(m_selection);
267
268 // we will soon delete all the cells, so clear pointers to them:
269 m_tmpSelFromCell = NULL;
270
271 // pass HTML through registered processors:
272 if (m_Processors || m_GlobalProcessors)
273 {
274 wxHtmlProcessorList::compatibility_iterator nodeL, nodeG;
275 int prL, prG;
276
277 nodeL = (m_Processors) ? m_Processors->GetFirst() : wxHtmlProcessorList::compatibility_iterator();
278 nodeG = (m_GlobalProcessors) ? m_GlobalProcessors->GetFirst() : wxHtmlProcessorList::compatibility_iterator();
279
280 // VS: there are two lists, global and local, both of them sorted by
281 // priority. Since we have to go through _both_ lists with
282 // decreasing priority, we "merge-sort" the lists on-line by
283 // processing that one of the two heads that has higher priority
284 // in every iteration
285 while (nodeL || nodeG)
286 {
287 prL = (nodeL) ? nodeL->GetData()->GetPriority() : -1;
288 prG = (nodeG) ? nodeG->GetData()->GetPriority() : -1;
289 if (prL > prG)
290 {
291 if (nodeL->GetData()->IsEnabled())
292 newsrc = nodeL->GetData()->Process(newsrc);
293 nodeL = nodeL->GetNext();
294 }
295 else // prL <= prG
296 {
297 if (nodeG->GetData()->IsEnabled())
298 newsrc = nodeG->GetData()->Process(newsrc);
299 nodeG = nodeG->GetNext();
300 }
301 }
302 }
303
304 // ...and run the parser on it:
305 wxClientDC *dc = new wxClientDC(this);
306 dc->SetMapMode(wxMM_TEXT);
307 SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
308 SetBackgroundImage(wxNullBitmap);
309
310 m_Parser->SetDC(dc);
311 if (m_Cell)
312 {
313 delete m_Cell;
314 m_Cell = NULL;
315 }
316 m_Cell = (wxHtmlContainerCell*) m_Parser->Parse(newsrc);
317 delete dc;
318 m_Cell->SetIndent(m_Borders, wxHTML_INDENT_ALL, wxHTML_UNITS_PIXELS);
319 m_Cell->SetAlignHor(wxHTML_ALIGN_CENTER);
320 CreateLayout();
321 if (m_tmpCanDrawLocks == 0)
322 Refresh();
323 return true;
324 }
325
326 bool wxHtmlWindow::AppendToPage(const wxString& source)
327 {
328 return DoSetPage(*(GetParser()->GetSource()) + source);
329 }
330
331 bool wxHtmlWindow::LoadPage(const wxString& location)
332 {
333 wxBusyCursor busyCursor;
334
335 wxFSFile *f;
336 bool rt_val;
337 bool needs_refresh = false;
338
339 m_tmpCanDrawLocks++;
340 if (m_HistoryOn && (m_HistoryPos != -1))
341 {
342 // store scroll position into history item:
343 int x, y;
344 GetViewStart(&x, &y);
345 (*m_History)[m_HistoryPos].SetPos(y);
346 }
347
348 if (location[0] == wxT('#'))
349 {
350 // local anchor:
351 wxString anch = location.Mid(1) /*1 to end*/;
352 m_tmpCanDrawLocks--;
353 rt_val = ScrollToAnchor(anch);
354 m_tmpCanDrawLocks++;
355 }
356 else if (location.Find(wxT('#')) != wxNOT_FOUND && location.BeforeFirst(wxT('#')) == m_OpenedPage)
357 {
358 wxString anch = location.AfterFirst(wxT('#'));
359 m_tmpCanDrawLocks--;
360 rt_val = ScrollToAnchor(anch);
361 m_tmpCanDrawLocks++;
362 }
363 else if (location.Find(wxT('#')) != wxNOT_FOUND &&
364 (m_FS->GetPath() + location.BeforeFirst(wxT('#'))) == m_OpenedPage)
365 {
366 wxString anch = location.AfterFirst(wxT('#'));
367 m_tmpCanDrawLocks--;
368 rt_val = ScrollToAnchor(anch);
369 m_tmpCanDrawLocks++;
370 }
371
372 else
373 {
374 needs_refresh = true;
375 #if wxUSE_STATUSBAR
376 // load&display it:
377 if (m_RelatedStatusBar != -1)
378 {
379 m_RelatedFrame->SetStatusText(_("Connecting..."), m_RelatedStatusBar);
380 Refresh(false);
381 }
382 #endif // wxUSE_STATUSBAR
383
384 f = m_Parser->OpenURL(wxHTML_URL_PAGE, location);
385
386 // try to interpret 'location' as filename instead of URL:
387 if (f == NULL)
388 {
389 wxFileName fn(location);
390 wxString location2 = wxFileSystem::FileNameToURL(fn);
391 f = m_Parser->OpenURL(wxHTML_URL_PAGE, location2);
392 }
393
394 if (f == NULL)
395 {
396 wxLogError(_("Unable to open requested HTML document: %s"), location.c_str());
397 m_tmpCanDrawLocks--;
398 return false;
399 }
400
401 else
402 {
403 wxList::compatibility_iterator node;
404 wxString src = wxEmptyString;
405
406 #if wxUSE_STATUSBAR
407 if (m_RelatedStatusBar != -1)
408 {
409 wxString msg = _("Loading : ") + location;
410 m_RelatedFrame->SetStatusText(msg, m_RelatedStatusBar);
411 Refresh(false);
412 }
413 #endif // wxUSE_STATUSBAR
414
415 node = m_Filters.GetFirst();
416 while (node)
417 {
418 wxHtmlFilter *h = (wxHtmlFilter*) node->GetData();
419 if (h->CanRead(*f))
420 {
421 src = h->ReadFile(*f);
422 break;
423 }
424 node = node->GetNext();
425 }
426 if (src == wxEmptyString)
427 {
428 if (m_DefaultFilter == NULL) m_DefaultFilter = GetDefaultFilter();
429 src = m_DefaultFilter->ReadFile(*f);
430 }
431
432 m_FS->ChangePathTo(f->GetLocation());
433 rt_val = SetPage(src);
434 m_OpenedPage = f->GetLocation();
435 if (f->GetAnchor() != wxEmptyString)
436 {
437 ScrollToAnchor(f->GetAnchor());
438 }
439
440 delete f;
441
442 #if wxUSE_STATUSBAR
443 if (m_RelatedStatusBar != -1)
444 m_RelatedFrame->SetStatusText(_("Done"), m_RelatedStatusBar);
445 #endif // wxUSE_STATUSBAR
446 }
447 }
448
449 if (m_HistoryOn) // add this page to history there:
450 {
451 int c = m_History->GetCount() - (m_HistoryPos + 1);
452
453 if (m_HistoryPos < 0 ||
454 (*m_History)[m_HistoryPos].GetPage() != m_OpenedPage ||
455 (*m_History)[m_HistoryPos].GetAnchor() != m_OpenedAnchor)
456 {
457 m_HistoryPos++;
458 for (int i = 0; i < c; i++)
459 m_History->RemoveAt(m_HistoryPos);
460 m_History->Add(new wxHtmlHistoryItem(m_OpenedPage, m_OpenedAnchor));
461 }
462 }
463
464 if (m_OpenedPageTitle == wxEmptyString)
465 OnSetTitle(wxFileNameFromPath(m_OpenedPage));
466
467 if (needs_refresh)
468 {
469 m_tmpCanDrawLocks--;
470 Refresh();
471 }
472 else
473 m_tmpCanDrawLocks--;
474
475 return rt_val;
476 }
477
478
479 bool wxHtmlWindow::LoadFile(const wxFileName& filename)
480 {
481 wxString url = wxFileSystem::FileNameToURL(filename);
482 return LoadPage(url);
483 }
484
485
486 bool wxHtmlWindow::ScrollToAnchor(const wxString& anchor)
487 {
488 const wxHtmlCell *c = m_Cell->Find(wxHTML_COND_ISANCHOR, &anchor);
489 if (!c)
490 {
491 wxLogWarning(_("HTML anchor %s does not exist."), anchor.c_str());
492 return false;
493 }
494 else
495 {
496 int y;
497
498 for (y = 0; c != NULL; c = c->GetParent()) y += c->GetPosY();
499 Scroll(-1, y / wxHTML_SCROLL_STEP);
500 m_OpenedAnchor = anchor;
501 return true;
502 }
503 }
504
505
506 void wxHtmlWindow::OnSetTitle(const wxString& title)
507 {
508 if (m_RelatedFrame)
509 {
510 wxString tit;
511 tit.Printf(m_TitleFormat, title.c_str());
512 m_RelatedFrame->SetTitle(tit);
513 }
514 m_OpenedPageTitle = title;
515 }
516
517
518
519
520
521 void wxHtmlWindow::CreateLayout()
522 {
523 int ClientWidth, ClientHeight;
524
525 if (!m_Cell) return;
526
527 if (m_Style & wxHW_SCROLLBAR_NEVER)
528 {
529 SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // always off
530 GetClientSize(&ClientWidth, &ClientHeight);
531 m_Cell->Layout(ClientWidth);
532 }
533
534 else {
535 GetClientSize(&ClientWidth, &ClientHeight);
536 m_Cell->Layout(ClientWidth);
537 if (ClientHeight < m_Cell->GetHeight() + GetCharHeight())
538 {
539 SetScrollbars(
540 wxHTML_SCROLL_STEP, wxHTML_SCROLL_STEP,
541 m_Cell->GetWidth() / wxHTML_SCROLL_STEP,
542 (m_Cell->GetHeight() + GetCharHeight()) / wxHTML_SCROLL_STEP
543 /*cheat: top-level frag is always container*/);
544 }
545 else /* we fit into window, no need for scrollbars */
546 {
547 SetScrollbars(wxHTML_SCROLL_STEP, 1, m_Cell->GetWidth() / wxHTML_SCROLL_STEP, 0); // disable...
548 GetClientSize(&ClientWidth, &ClientHeight);
549 m_Cell->Layout(ClientWidth); // ...and relayout
550 }
551 }
552 }
553
554
555
556 void wxHtmlWindow::ReadCustomization(wxConfigBase *cfg, wxString path)
557 {
558 wxString oldpath;
559 wxString tmp;
560 int p_fontsizes[7];
561 wxString p_fff, p_ffn;
562
563 if (path != wxEmptyString)
564 {
565 oldpath = cfg->GetPath();
566 cfg->SetPath(path);
567 }
568
569 m_Borders = cfg->Read(wxT("wxHtmlWindow/Borders"), m_Borders);
570 p_fff = cfg->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
571 p_ffn = cfg->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
572 for (int i = 0; i < 7; i++)
573 {
574 tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
575 p_fontsizes[i] = cfg->Read(tmp, m_Parser->m_FontsSizes[i]);
576 }
577 SetFonts(p_ffn, p_fff, p_fontsizes);
578
579 if (path != wxEmptyString)
580 cfg->SetPath(oldpath);
581 }
582
583
584
585 void wxHtmlWindow::WriteCustomization(wxConfigBase *cfg, wxString path)
586 {
587 wxString oldpath;
588 wxString tmp;
589
590 if (path != wxEmptyString)
591 {
592 oldpath = cfg->GetPath();
593 cfg->SetPath(path);
594 }
595
596 cfg->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders);
597 cfg->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser->m_FontFaceFixed);
598 cfg->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser->m_FontFaceNormal);
599 for (int i = 0; i < 7; i++)
600 {
601 tmp.Printf(wxT("wxHtmlWindow/FontsSize%i"), i);
602 cfg->Write(tmp, (long) m_Parser->m_FontsSizes[i]);
603 }
604
605 if (path != wxEmptyString)
606 cfg->SetPath(oldpath);
607 }
608
609
610
611 bool wxHtmlWindow::HistoryBack()
612 {
613 wxString a, l;
614
615 if (m_HistoryPos < 1) return false;
616
617 // store scroll position into history item:
618 int x, y;
619 GetViewStart(&x, &y);
620 (*m_History)[m_HistoryPos].SetPos(y);
621
622 // go to previous position:
623 m_HistoryPos--;
624
625 l = (*m_History)[m_HistoryPos].GetPage();
626 a = (*m_History)[m_HistoryPos].GetAnchor();
627 m_HistoryOn = false;
628 m_tmpCanDrawLocks++;
629 if (a == wxEmptyString) LoadPage(l);
630 else LoadPage(l + wxT("#") + a);
631 m_HistoryOn = true;
632 m_tmpCanDrawLocks--;
633 Scroll(0, (*m_History)[m_HistoryPos].GetPos());
634 Refresh();
635 return true;
636 }
637
638 bool wxHtmlWindow::HistoryCanBack()
639 {
640 if (m_HistoryPos < 1) return false;
641 return true ;
642 }
643
644
645 bool wxHtmlWindow::HistoryForward()
646 {
647 wxString a, l;
648
649 if (m_HistoryPos == -1) return false;
650 if (m_HistoryPos >= (int)m_History->GetCount() - 1)return false;
651
652 m_OpenedPage = wxEmptyString; // this will disable adding new entry into history in LoadPage()
653
654 m_HistoryPos++;
655 l = (*m_History)[m_HistoryPos].GetPage();
656 a = (*m_History)[m_HistoryPos].GetAnchor();
657 m_HistoryOn = false;
658 m_tmpCanDrawLocks++;
659 if (a == wxEmptyString) LoadPage(l);
660 else LoadPage(l + wxT("#") + a);
661 m_HistoryOn = true;
662 m_tmpCanDrawLocks--;
663 Scroll(0, (*m_History)[m_HistoryPos].GetPos());
664 Refresh();
665 return true;
666 }
667
668 bool wxHtmlWindow::HistoryCanForward()
669 {
670 if (m_HistoryPos == -1) return false;
671 if (m_HistoryPos >= (int)m_History->GetCount() - 1)return false;
672 return true ;
673 }
674
675
676 void wxHtmlWindow::HistoryClear()
677 {
678 m_History->Empty();
679 m_HistoryPos = -1;
680 }
681
682 void wxHtmlWindow::AddProcessor(wxHtmlProcessor *processor)
683 {
684 if (!m_Processors)
685 {
686 m_Processors = new wxHtmlProcessorList;
687 }
688 wxHtmlProcessorList::compatibility_iterator node;
689
690 for (node = m_Processors->GetFirst(); node; node = node->GetNext())
691 {
692 if (processor->GetPriority() > node->GetData()->GetPriority())
693 {
694 m_Processors->Insert(node, processor);
695 return;
696 }
697 }
698 m_Processors->Append(processor);
699 }
700
701 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor *processor)
702 {
703 if (!m_GlobalProcessors)
704 {
705 m_GlobalProcessors = new wxHtmlProcessorList;
706 }
707 wxHtmlProcessorList::compatibility_iterator node;
708
709 for (node = m_GlobalProcessors->GetFirst(); node; node = node->GetNext())
710 {
711 if (processor->GetPriority() > node->GetData()->GetPriority())
712 {
713 m_GlobalProcessors->Insert(node, processor);
714 return;
715 }
716 }
717 m_GlobalProcessors->Append(processor);
718 }
719
720
721
722 wxList wxHtmlWindow::m_Filters;
723 wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL;
724 wxHtmlProcessorList *wxHtmlWindow::m_GlobalProcessors = NULL;
725
726 void wxHtmlWindow::CleanUpStatics()
727 {
728 wxDELETE(m_DefaultFilter);
729 WX_CLEAR_LIST(wxList, m_Filters);
730 if (m_GlobalProcessors)
731 WX_CLEAR_LIST(wxHtmlProcessorList, *m_GlobalProcessors);
732 wxDELETE(m_GlobalProcessors);
733 }
734
735
736
737 void wxHtmlWindow::AddFilter(wxHtmlFilter *filter)
738 {
739 m_Filters.Append(filter);
740 }
741
742
743 bool wxHtmlWindow::IsSelectionEnabled() const
744 {
745 #if wxUSE_CLIPBOARD
746 return !(m_Style & wxHW_NO_SELECTION);
747 #else
748 return false;
749 #endif
750 }
751
752
753 #if wxUSE_CLIPBOARD
754 wxString wxHtmlWindow::DoSelectionToText(wxHtmlSelection *sel)
755 {
756 if ( !sel )
757 return wxEmptyString;
758
759 wxClientDC dc(this);
760
761 const wxHtmlCell *end = sel->GetToCell();
762 wxString text;
763 wxHtmlTerminalCellsInterator i(sel->GetFromCell(), end);
764 if ( i )
765 {
766 text << i->ConvertToText(sel);
767 ++i;
768 }
769 const wxHtmlCell *prev = *i;
770 while ( i )
771 {
772 if ( prev->GetParent() != i->GetParent() )
773 text << _T('\n');
774 text << i->ConvertToText(*i == end ? sel : NULL);
775 prev = *i;
776 ++i;
777 }
778 return text;
779 }
780
781 wxString wxHtmlWindow::ToText()
782 {
783 if (m_Cell)
784 {
785 wxHtmlSelection sel;
786 sel.Set(m_Cell->GetFirstTerminal(), m_Cell->GetLastTerminal());
787 return DoSelectionToText(&sel);
788 }
789 else
790 return wxEmptyString;
791 }
792
793 #endif // wxUSE_CLIPBOARD
794
795 bool wxHtmlWindow::CopySelection(ClipboardType t)
796 {
797 #if wxUSE_CLIPBOARD
798 if ( m_selection )
799 {
800 #if defined(__UNIX__) && !defined(__WXMAC__)
801 wxTheClipboard->UsePrimarySelection(t == Primary);
802 #else // !__UNIX__
803 // Primary selection exists only under X11, so don't do anything under
804 // the other platforms when we try to access it
805 //
806 // TODO: this should be abstracted at wxClipboard level!
807 if ( t == Primary )
808 return false;
809 #endif // __UNIX__/!__UNIX__
810
811 if ( wxTheClipboard->Open() )
812 {
813 const wxString txt(SelectionToText());
814 wxTheClipboard->SetData(new wxTextDataObject(txt));
815 wxTheClipboard->Close();
816 wxLogTrace(_T("wxhtmlselection"),
817 _("Copied to clipboard:\"%s\""), txt.c_str());
818
819 return true;
820 }
821 }
822 #else
823 wxUnusedVar(t);
824 #endif // wxUSE_CLIPBOARD
825
826 return false;
827 }
828
829
830 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo& link)
831 {
832 const wxMouseEvent *e = link.GetEvent();
833 if (e == NULL || e->LeftUp())
834 LoadPage(link.GetHref());
835 }
836
837 void wxHtmlWindow::OnCellClicked(wxHtmlCell *cell,
838 wxCoord x, wxCoord y,
839 const wxMouseEvent& event)
840 {
841 wxCHECK_RET( cell, _T("can't be called with NULL cell") );
842
843 cell->OnMouseClick(this, x, y, event);
844 }
845
846 void wxHtmlWindow::OnCellMouseHover(wxHtmlCell * WXUNUSED(cell),
847 wxCoord WXUNUSED(x), wxCoord WXUNUSED(y))
848 {
849 // do nothing here
850 }
851
852 void wxHtmlWindow::OnEraseBackground(wxEraseEvent& event)
853 {
854 if ( !m_bmpBg.Ok() )
855 {
856 // don't even skip the event, if we don't have a bg bitmap we're going
857 // to overwrite background in OnPaint() below anyhow, so letting the
858 // default handling take place would only result in flicker, just set a
859 // flag to erase the background below
860 m_eraseBgInOnPaint = true;
861 return;
862 }
863
864 wxDC& dc = *event.GetDC();
865
866 // if the image is not fully opaque, we have to erase the background before
867 // drawing it, however avoid doing it for opaque images as this would just
868 // result in extra flicker without any other effect as background is
869 // completely covered anyhow
870 if ( m_bmpBg.GetMask() )
871 {
872 dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
873 dc.Clear();
874 }
875
876 const wxSize sizeWin(GetClientSize());
877 const wxSize sizeBmp(m_bmpBg.GetWidth(), m_bmpBg.GetHeight());
878 for ( wxCoord x = 0; x < sizeWin.x; x += sizeBmp.x )
879 {
880 for ( wxCoord y = 0; y < sizeWin.y; y += sizeBmp.y )
881 {
882 dc.DrawBitmap(m_bmpBg, x, y, true /* use mask */);
883 }
884 }
885 }
886
887 void wxHtmlWindow::OnPaint(wxPaintEvent& WXUNUSED(event))
888 {
889 wxPaintDC dc(this);
890
891 if (m_tmpCanDrawLocks > 0 || m_Cell == NULL)
892 return;
893
894 int x, y;
895 GetViewStart(&x, &y);
896 wxRect rect = GetUpdateRegion().GetBox();
897 wxSize sz = GetSize();
898
899 wxMemoryDC dcm;
900 if ( !m_backBuffer )
901 m_backBuffer = new wxBitmap(sz.x, sz.y);
902 dcm.SelectObject(*m_backBuffer);
903
904 if ( m_eraseBgInOnPaint )
905 {
906 dcm.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
907 dcm.Clear();
908
909 m_eraseBgInOnPaint = false;
910 }
911 else // someone has already erased the background, keep it
912 {
913 // preserve the existing background, otherwise we'd erase anything the
914 // user code had drawn in its EVT_ERASE_BACKGROUND handler when we do
915 // the Blit back below
916 dcm.Blit(0, rect.GetTop(),
917 sz.x, rect.GetBottom() - rect.GetTop() + 1,
918 &dc,
919 0, rect.GetTop());
920 }
921
922 PrepareDC(dcm);
923 dcm.SetMapMode(wxMM_TEXT);
924 dcm.SetBackgroundMode(wxTRANSPARENT);
925
926 wxHtmlRenderingInfo rinfo;
927 wxDefaultHtmlRenderingStyle rstyle;
928 rinfo.SetSelection(m_selection);
929 rinfo.SetStyle(&rstyle);
930 m_Cell->Draw(dcm, 0, 0,
931 y * wxHTML_SCROLL_STEP + rect.GetTop(),
932 y * wxHTML_SCROLL_STEP + rect.GetBottom(),
933 rinfo);
934
935 //#define DEBUG_HTML_SELECTION
936 #ifdef DEBUG_HTML_SELECTION
937 {
938 int xc, yc, x, y;
939 wxGetMousePosition(&xc, &yc);
940 ScreenToClient(&xc, &yc);
941 CalcUnscrolledPosition(xc, yc, &x, &y);
942 wxHtmlCell *at = m_Cell->FindCellByPos(x, y);
943 wxHtmlCell *before =
944 m_Cell->FindCellByPos(x, y, wxHTML_FIND_NEAREST_BEFORE);
945 wxHtmlCell *after =
946 m_Cell->FindCellByPos(x, y, wxHTML_FIND_NEAREST_AFTER);
947
948 dcm.SetBrush(*wxTRANSPARENT_BRUSH);
949 dcm.SetPen(*wxBLACK_PEN);
950 if (at)
951 dcm.DrawRectangle(at->GetAbsPos(),
952 wxSize(at->GetWidth(),at->GetHeight()));
953 dcm.SetPen(*wxGREEN_PEN);
954 if (before)
955 dcm.DrawRectangle(before->GetAbsPos().x+1, before->GetAbsPos().y+1,
956 before->GetWidth()-2,before->GetHeight()-2);
957 dcm.SetPen(*wxRED_PEN);
958 if (after)
959 dcm.DrawRectangle(after->GetAbsPos().x+2, after->GetAbsPos().y+2,
960 after->GetWidth()-4,after->GetHeight()-4);
961 }
962 #endif
963
964 dcm.SetDeviceOrigin(0,0);
965 dc.Blit(0, rect.GetTop(),
966 sz.x, rect.GetBottom() - rect.GetTop() + 1,
967 &dcm,
968 0, rect.GetTop());
969 }
970
971
972
973
974 void wxHtmlWindow::OnSize(wxSizeEvent& event)
975 {
976 wxDELETE(m_backBuffer);
977
978 wxScrolledWindow::OnSize(event);
979 CreateLayout();
980
981 // Recompute selection if necessary:
982 if ( m_selection )
983 {
984 m_selection->Set(m_selection->GetFromCell(),
985 m_selection->GetToCell());
986 m_selection->ClearPrivPos();
987 }
988
989 Refresh();
990 }
991
992
993 void wxHtmlWindow::OnMouseMove(wxMouseEvent& WXUNUSED(event))
994 {
995 m_tmpMouseMoved = true;
996 }
997
998 void wxHtmlWindow::OnMouseDown(wxMouseEvent& event)
999 {
1000 #if wxUSE_CLIPBOARD
1001 if ( event.LeftDown() && IsSelectionEnabled() )
1002 {
1003 const long TRIPLECLICK_LEN = 200; // 0.2 sec after doubleclick
1004 if ( wxGetLocalTimeMillis() - m_lastDoubleClick <= TRIPLECLICK_LEN )
1005 {
1006 SelectLine(CalcUnscrolledPosition(event.GetPosition()));
1007
1008 (void) CopySelection();
1009 }
1010 else
1011 {
1012 m_makingSelection = true;
1013
1014 if ( m_selection )
1015 {
1016 wxDELETE(m_selection);
1017 Refresh();
1018 }
1019 m_tmpSelFromPos = CalcUnscrolledPosition(event.GetPosition());
1020 m_tmpSelFromCell = NULL;
1021
1022 CaptureMouse();
1023 }
1024 }
1025 #else
1026 wxUnusedVar(event);
1027 #endif // wxUSE_CLIPBOARD
1028 }
1029
1030 void wxHtmlWindow::OnMouseUp(wxMouseEvent& event)
1031 {
1032 #if wxUSE_CLIPBOARD
1033 if ( m_makingSelection )
1034 {
1035 ReleaseMouse();
1036 m_makingSelection = false;
1037
1038 // did the user move the mouse far enough from starting point?
1039 if ( CopySelection(Primary) )
1040 {
1041 // we don't want mouse up event that ended selecting to be
1042 // handled as mouse click and e.g. follow hyperlink:
1043 return;
1044 }
1045 }
1046 #endif // wxUSE_CLIPBOARD
1047
1048 SetFocus();
1049 if ( m_Cell )
1050 {
1051 wxPoint pos = CalcUnscrolledPosition(event.GetPosition());
1052 wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y);
1053
1054 // check is needed because FindCellByPos returns terminal cell and
1055 // containers may have empty borders -- in this case NULL will be
1056 // returned
1057 if ( cell )
1058 OnCellClicked(cell, pos.x, pos.y, event);
1059 }
1060 }
1061
1062
1063
1064 void wxHtmlWindow::OnInternalIdle()
1065 {
1066 wxWindow::OnInternalIdle();
1067
1068 if (m_tmpMouseMoved && (m_Cell != NULL))
1069 {
1070 #ifdef DEBUG_HTML_SELECTION
1071 Refresh();
1072 #endif
1073 int xc, yc, x, y;
1074 wxGetMousePosition(&xc, &yc);
1075 ScreenToClient(&xc, &yc);
1076 CalcUnscrolledPosition(xc, yc, &x, &y);
1077
1078 wxHtmlCell *cell = m_Cell->FindCellByPos(x, y);
1079
1080 // handle selection update:
1081 if ( m_makingSelection )
1082 {
1083 if ( !m_tmpSelFromCell )
1084 m_tmpSelFromCell = m_Cell->FindCellByPos(
1085 m_tmpSelFromPos.x,m_tmpSelFromPos.y);
1086
1087 // NB: a trick - we adjust selFromPos to be upper left or bottom
1088 // right corner of the first cell of the selection depending
1089 // on whether the mouse is moving to the right or to the left.
1090 // This gives us more "natural" behaviour when selecting
1091 // a line (specifically, first cell of the next line is not
1092 // included if you drag selection from left to right over
1093 // entire line):
1094 wxPoint dirFromPos;
1095 if ( !m_tmpSelFromCell )
1096 {
1097 dirFromPos = m_tmpSelFromPos;
1098 }
1099 else
1100 {
1101 dirFromPos = m_tmpSelFromCell->GetAbsPos();
1102 if ( x < m_tmpSelFromPos.x )
1103 {
1104 dirFromPos.x += m_tmpSelFromCell->GetWidth();
1105 dirFromPos.y += m_tmpSelFromCell->GetHeight();
1106 }
1107 }
1108 bool goingDown = dirFromPos.y < y ||
1109 (dirFromPos.y == y && dirFromPos.x < x);
1110
1111 // determine selection span:
1112 if ( /*still*/ !m_tmpSelFromCell )
1113 {
1114 if (goingDown)
1115 {
1116 m_tmpSelFromCell = m_Cell->FindCellByPos(
1117 m_tmpSelFromPos.x,m_tmpSelFromPos.y,
1118 wxHTML_FIND_NEAREST_AFTER);
1119 if (!m_tmpSelFromCell)
1120 m_tmpSelFromCell = m_Cell->GetFirstTerminal();
1121 }
1122 else
1123 {
1124 m_tmpSelFromCell = m_Cell->FindCellByPos(
1125 m_tmpSelFromPos.x,m_tmpSelFromPos.y,
1126 wxHTML_FIND_NEAREST_BEFORE);
1127 if (!m_tmpSelFromCell)
1128 m_tmpSelFromCell = m_Cell->GetLastTerminal();
1129 }
1130 }
1131
1132 wxHtmlCell *selcell = cell;
1133 if (!selcell)
1134 {
1135 if (goingDown)
1136 {
1137 selcell = m_Cell->FindCellByPos(x, y,
1138 wxHTML_FIND_NEAREST_BEFORE);
1139 if (!selcell)
1140 selcell = m_Cell->GetLastTerminal();
1141 }
1142 else
1143 {
1144 selcell = m_Cell->FindCellByPos(x, y,
1145 wxHTML_FIND_NEAREST_AFTER);
1146 if (!selcell)
1147 selcell = m_Cell->GetFirstTerminal();
1148 }
1149 }
1150
1151 // NB: it may *rarely* happen that the code above didn't find one
1152 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1153 // visible cells.
1154 if ( selcell && m_tmpSelFromCell )
1155 {
1156 if ( !m_selection )
1157 {
1158 // start selecting only if mouse movement was big enough
1159 // (otherwise it was meant as mouse click, not selection):
1160 const int PRECISION = 2;
1161 wxPoint diff = m_tmpSelFromPos - wxPoint(x,y);
1162 if (abs(diff.x) > PRECISION || abs(diff.y) > PRECISION)
1163 {
1164 m_selection = new wxHtmlSelection();
1165 }
1166 }
1167 if ( m_selection )
1168 {
1169 if ( m_tmpSelFromCell->IsBefore(selcell) )
1170 {
1171 m_selection->Set(m_tmpSelFromPos, m_tmpSelFromCell,
1172 wxPoint(x,y), selcell); }
1173 else
1174 {
1175 m_selection->Set(wxPoint(x,y), selcell,
1176 m_tmpSelFromPos, m_tmpSelFromCell);
1177 }
1178 m_selection->ClearPrivPos();
1179 Refresh();
1180 }
1181 }
1182 }
1183
1184 // handle cursor and status bar text changes:
1185 if ( cell != m_tmpLastCell )
1186 {
1187 wxHtmlLinkInfo *lnk = cell ? cell->GetLink(x, y) : NULL;
1188 wxCursor cur;
1189 if (cell)
1190 cur = cell->GetCursor();
1191 else
1192 cur = *wxSTANDARD_CURSOR;
1193 SetCursor(cur);
1194
1195 if (lnk != m_tmpLastLink)
1196 {
1197 #if wxUSE_STATUSBAR
1198 if (lnk == NULL)
1199 {
1200 if (m_RelatedStatusBar != -1)
1201 m_RelatedFrame->SetStatusText(wxEmptyString,
1202 m_RelatedStatusBar);
1203 }
1204 else
1205 {
1206 if (m_RelatedStatusBar != -1)
1207 m_RelatedFrame->SetStatusText(lnk->GetHref(),
1208 m_RelatedStatusBar);
1209 }
1210 #endif // wxUSE_STATUSBAR
1211 m_tmpLastLink = lnk;
1212 }
1213
1214 m_tmpLastCell = cell;
1215 }
1216 else // mouse moved but stayed in the same cell
1217 {
1218 if ( cell )
1219 OnCellMouseHover(cell, x, y);
1220 }
1221
1222 m_tmpMouseMoved = false;
1223 }
1224 }
1225
1226 #if wxUSE_CLIPBOARD
1227 void wxHtmlWindow::StopAutoScrolling()
1228 {
1229 if ( m_timerAutoScroll )
1230 {
1231 wxDELETE(m_timerAutoScroll);
1232 }
1233 }
1234
1235 void wxHtmlWindow::OnMouseEnter(wxMouseEvent& event)
1236 {
1237 StopAutoScrolling();
1238 event.Skip();
1239 }
1240
1241 void wxHtmlWindow::OnMouseLeave(wxMouseEvent& event)
1242 {
1243 // don't prevent the usual processing of the event from taking place
1244 event.Skip();
1245
1246 // when a captured mouse leave a scrolled window we start generate
1247 // scrolling events to allow, for example, extending selection beyond the
1248 // visible area in some controls
1249 if ( wxWindow::GetCapture() == this )
1250 {
1251 // where is the mouse leaving?
1252 int pos, orient;
1253 wxPoint pt = event.GetPosition();
1254 if ( pt.x < 0 )
1255 {
1256 orient = wxHORIZONTAL;
1257 pos = 0;
1258 }
1259 else if ( pt.y < 0 )
1260 {
1261 orient = wxVERTICAL;
1262 pos = 0;
1263 }
1264 else // we're lower or to the right of the window
1265 {
1266 wxSize size = GetClientSize();
1267 if ( pt.x > size.x )
1268 {
1269 orient = wxHORIZONTAL;
1270 pos = GetVirtualSize().x / wxHTML_SCROLL_STEP;
1271 }
1272 else if ( pt.y > size.y )
1273 {
1274 orient = wxVERTICAL;
1275 pos = GetVirtualSize().y / wxHTML_SCROLL_STEP;
1276 }
1277 else // this should be impossible
1278 {
1279 // but seems to happen sometimes under wxMSW - maybe it's a bug
1280 // there but for now just ignore it
1281
1282 //wxFAIL_MSG( _T("can't understand where has mouse gone") );
1283
1284 return;
1285 }
1286 }
1287
1288 // only start the auto scroll timer if the window can be scrolled in
1289 // this direction
1290 if ( !HasScrollbar(orient) )
1291 return;
1292
1293 delete m_timerAutoScroll;
1294 m_timerAutoScroll = new wxHtmlWinAutoScrollTimer
1295 (
1296 this,
1297 pos == 0 ? wxEVT_SCROLLWIN_LINEUP
1298 : wxEVT_SCROLLWIN_LINEDOWN,
1299 pos,
1300 orient
1301 );
1302 m_timerAutoScroll->Start(50); // FIXME: make configurable
1303 }
1304 }
1305
1306 void wxHtmlWindow::OnKeyUp(wxKeyEvent& event)
1307 {
1308 if ( IsSelectionEnabled() && event.GetKeyCode() == 'C' && event.CmdDown() )
1309 {
1310 (void) CopySelection();
1311 }
1312 }
1313
1314 void wxHtmlWindow::OnCopy(wxCommandEvent& WXUNUSED(event))
1315 {
1316 (void) CopySelection();
1317 }
1318
1319 void wxHtmlWindow::OnDoubleClick(wxMouseEvent& event)
1320 {
1321 // select word under cursor:
1322 if ( IsSelectionEnabled() )
1323 {
1324 SelectWord(CalcUnscrolledPosition(event.GetPosition()));
1325
1326 (void) CopySelection(Primary);
1327
1328 m_lastDoubleClick = wxGetLocalTimeMillis();
1329 }
1330 else
1331 event.Skip();
1332 }
1333
1334 void wxHtmlWindow::SelectWord(const wxPoint& pos)
1335 {
1336 if ( m_Cell )
1337 {
1338 wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y);
1339 if ( cell )
1340 {
1341 delete m_selection;
1342 m_selection = new wxHtmlSelection();
1343 m_selection->Set(cell, cell);
1344 RefreshRect(wxRect(CalcScrolledPosition(cell->GetAbsPos()),
1345 wxSize(cell->GetWidth(), cell->GetHeight())));
1346 }
1347 }
1348 }
1349
1350 void wxHtmlWindow::SelectLine(const wxPoint& pos)
1351 {
1352 if ( m_Cell )
1353 {
1354 wxHtmlCell *cell = m_Cell->FindCellByPos(pos.x, pos.y);
1355 if ( cell )
1356 {
1357 // We use following heuristic to find a "line": let the line be all
1358 // cells in same container as the cell under mouse cursor that are
1359 // neither completely above nor completely bellow the clicked cell
1360 // (i.e. are likely to be words positioned on same line of text).
1361
1362 int y1 = cell->GetAbsPos().y;
1363 int y2 = y1 + cell->GetHeight();
1364 int y;
1365 const wxHtmlCell *c;
1366 const wxHtmlCell *before = NULL;
1367 const wxHtmlCell *after = NULL;
1368
1369 // find last cell of line:
1370 for ( c = cell->GetNext(); c; c = c->GetNext())
1371 {
1372 y = c->GetAbsPos().y;
1373 if ( y + c->GetHeight() > y1 && y < y2 )
1374 after = c;
1375 else
1376 break;
1377 }
1378 if ( !after )
1379 after = cell;
1380
1381 // find first cell of line:
1382 for ( c = cell->GetParent()->GetFirstChild();
1383 c && c != cell; c = c->GetNext())
1384 {
1385 y = c->GetAbsPos().y;
1386 if ( y + c->GetHeight() > y1 && y < y2 )
1387 {
1388 if ( ! before )
1389 before = c;
1390 }
1391 else
1392 before = NULL;
1393 }
1394 if ( !before )
1395 before = cell;
1396
1397 delete m_selection;
1398 m_selection = new wxHtmlSelection();
1399 m_selection->Set(before, after);
1400
1401 Refresh();
1402 }
1403 }
1404 }
1405
1406 void wxHtmlWindow::SelectAll()
1407 {
1408 if ( m_Cell )
1409 {
1410 delete m_selection;
1411 m_selection = new wxHtmlSelection();
1412 m_selection->Set(m_Cell->GetFirstTerminal(), m_Cell->GetLastTerminal());
1413 Refresh();
1414 }
1415 }
1416
1417 #endif // wxUSE_CLIPBOARD
1418
1419
1420
1421 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor,wxObject)
1422
1423 #if wxUSE_EXTENDED_RTTI
1424 IMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow, wxScrolledWindow,"wx/html/htmlwin.h")
1425
1426 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow)
1427 /*
1428 TODO PROPERTIES
1429 style , wxHW_SCROLLBAR_AUTO
1430 borders , (dimension)
1431 url , string
1432 htmlcode , string
1433 */
1434 wxEND_PROPERTIES_TABLE()
1435
1436 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow)
1437 wxEND_HANDLERS_TABLE()
1438
1439 wxCONSTRUCTOR_5( wxHtmlWindow , wxWindow* , Parent , wxWindowID , Id , wxPoint , Position , wxSize , Size , long , WindowStyle )
1440 #else
1441 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow,wxScrolledWindow)
1442 #endif
1443
1444 BEGIN_EVENT_TABLE(wxHtmlWindow, wxScrolledWindow)
1445 EVT_SIZE(wxHtmlWindow::OnSize)
1446 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown)
1447 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp)
1448 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp)
1449 EVT_MOTION(wxHtmlWindow::OnMouseMove)
1450 EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground)
1451 EVT_PAINT(wxHtmlWindow::OnPaint)
1452 #if wxUSE_CLIPBOARD
1453 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick)
1454 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter)
1455 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave)
1456 EVT_KEY_UP(wxHtmlWindow::OnKeyUp)
1457 EVT_MENU(wxID_COPY, wxHtmlWindow::OnCopy)
1458 #endif // wxUSE_CLIPBOARD
1459 END_EVENT_TABLE()
1460
1461
1462
1463
1464
1465 // A module to allow initialization/cleanup
1466 // without calling these functions from app.cpp or from
1467 // the user's application.
1468
1469 class wxHtmlWinModule: public wxModule
1470 {
1471 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule)
1472 public:
1473 wxHtmlWinModule() : wxModule() {}
1474 bool OnInit() { return true; }
1475 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1476 };
1477
1478 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule, wxModule)
1479
1480
1481 // This hack forces the linker to always link in m_* files
1482 // (wxHTML doesn't work without handlers from these files)
1483 #include "wx/html/forcelnk.h"
1484 FORCE_WXHTML_MODULES()
1485
1486 #endif // wxUSE_HTML
1487