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