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