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