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