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