1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmlwin.cpp
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation)
4 // Author: Vaclav Slavik
6 // Copyright: (c) 1999 Vaclav Slavik
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
10 #include "wx/wxprec.h"
16 #if wxUSE_HTML && wxUSE_STREAMS
22 #include "wx/dcclient.h"
24 #include "wx/dcmemory.h"
26 #include "wx/settings.h"
27 #include "wx/dataobj.h"
28 #include "wx/statusbr.h"
31 #include "wx/html/htmlwin.h"
32 #include "wx/html/htmlproc.h"
33 #include "wx/clipbrd.h"
34 #include "wx/recguard.h"
36 #include "wx/arrimpl.cpp"
37 #include "wx/listimpl.cpp"
39 // uncomment this line to visually show the extent of the selection
40 //#define DEBUG_HTML_SELECTION
43 IMPLEMENT_DYNAMIC_CLASS(wxHtmlLinkEvent
, wxCommandEvent
)
44 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellEvent
, wxCommandEvent
)
46 wxDEFINE_EVENT( wxEVT_COMMAND_HTML_CELL_CLICKED
, wxHtmlCellEvent
);
47 wxDEFINE_EVENT( wxEVT_COMMAND_HTML_CELL_HOVER
, wxHtmlCellEvent
);
48 wxDEFINE_EVENT( wxEVT_COMMAND_HTML_LINK_CLICKED
, wxHtmlLinkEvent
);
52 // ----------------------------------------------------------------------------
53 // wxHtmlWinAutoScrollTimer: the timer used to generate a stream of scroll
54 // events when a captured mouse is held outside the window
55 // ----------------------------------------------------------------------------
57 class wxHtmlWinAutoScrollTimer
: public wxTimer
60 wxHtmlWinAutoScrollTimer(wxScrolledWindow
*win
,
61 wxEventType eventTypeToSend
,
65 m_eventType
= eventTypeToSend
;
70 virtual void Notify();
73 wxScrolledWindow
*m_win
;
74 wxEventType m_eventType
;
78 wxDECLARE_NO_COPY_CLASS(wxHtmlWinAutoScrollTimer
);
81 void wxHtmlWinAutoScrollTimer::Notify()
83 // only do all this as long as the window is capturing the mouse
84 if ( wxWindow::GetCapture() != m_win
)
88 else // we still capture the mouse, continue generating events
90 // first scroll the window if we are allowed to do it
91 wxScrollWinEvent
event1(m_eventType
, m_pos
, m_orient
);
92 event1
.SetEventObject(m_win
);
93 if ( m_win
->GetEventHandler()->ProcessEvent(event1
) )
95 // and then send a pseudo mouse-move event to refresh the selection
96 wxMouseEvent
event2(wxEVT_MOTION
);
97 wxGetMousePosition(&event2
.m_x
, &event2
.m_y
);
99 // the mouse event coordinates should be client, not screen as
100 // returned by wxGetMousePosition
101 wxWindow
*parentTop
= m_win
;
102 while ( parentTop
->GetParent() )
103 parentTop
= parentTop
->GetParent();
104 wxPoint ptOrig
= parentTop
->GetPosition();
105 event2
.m_x
-= ptOrig
.x
;
106 event2
.m_y
-= ptOrig
.y
;
108 event2
.SetEventObject(m_win
);
110 // FIXME: we don't fill in the other members - ok?
111 m_win
->GetEventHandler()->ProcessEvent(event2
);
113 else // can't scroll further, stop
120 #endif // wxUSE_CLIPBOARD
124 //-----------------------------------------------------------------------------
126 //-----------------------------------------------------------------------------
128 // item of history list
129 class WXDLLIMPEXP_HTML wxHtmlHistoryItem
132 wxHtmlHistoryItem(const wxString
& p
, const wxString
& a
) {m_Page
= p
, m_Anchor
= a
, m_Pos
= 0;}
133 int GetPos() const {return m_Pos
;}
134 void SetPos(int p
) {m_Pos
= p
;}
135 const wxString
& GetPage() const {return m_Page
;}
136 const wxString
& GetAnchor() const {return m_Anchor
;}
145 //-----------------------------------------------------------------------------
146 // our private arrays:
147 //-----------------------------------------------------------------------------
149 WX_DECLARE_OBJARRAY(wxHtmlHistoryItem
, wxHtmlHistoryArray
);
150 WX_DEFINE_OBJARRAY(wxHtmlHistoryArray
)
152 WX_DECLARE_LIST(wxHtmlProcessor
, wxHtmlProcessorList
);
153 WX_DEFINE_LIST(wxHtmlProcessorList
)
155 //-----------------------------------------------------------------------------
156 // wxHtmlWindowMouseHelper
157 //-----------------------------------------------------------------------------
159 wxHtmlWindowMouseHelper::wxHtmlWindowMouseHelper(wxHtmlWindowInterface
*iface
)
160 : m_tmpMouseMoved(false),
167 void wxHtmlWindowMouseHelper::HandleMouseMoved()
169 m_tmpMouseMoved
= true;
172 bool wxHtmlWindowMouseHelper::HandleMouseClick(wxHtmlCell
*rootCell
,
174 const wxMouseEvent
& event
)
179 wxHtmlCell
*cell
= rootCell
->FindCellByPos(pos
.x
, pos
.y
);
180 // this check is needed because FindCellByPos returns terminal cell and
181 // containers may have empty borders -- in this case NULL will be
186 // adjust the coordinates to be relative to this cell:
187 wxPoint relpos
= pos
- cell
->GetAbsPos(rootCell
);
189 return OnCellClicked(cell
, relpos
.x
, relpos
.y
, event
);
192 void wxHtmlWindowMouseHelper::HandleIdle(wxHtmlCell
*rootCell
,
195 wxHtmlCell
*cell
= rootCell
? rootCell
->FindCellByPos(pos
.x
, pos
.y
) : NULL
;
197 if (cell
!= m_tmpLastCell
)
199 wxHtmlLinkInfo
*lnk
= NULL
;
202 // adjust the coordinates to be relative to this cell:
203 wxPoint relpos
= pos
- cell
->GetAbsPos(rootCell
);
204 lnk
= cell
->GetLink(relpos
.x
, relpos
.y
);
209 cur
= cell
->GetMouseCursor(m_interface
);
211 cur
= m_interface
->GetHTMLCursor(
212 wxHtmlWindowInterface::HTMLCursor_Default
);
214 m_interface
->GetHTMLWindow()->SetCursor(cur
);
216 if (lnk
!= m_tmpLastLink
)
219 m_interface
->SetHTMLStatusText(lnk
->GetHref());
221 m_interface
->SetHTMLStatusText(wxEmptyString
);
226 m_tmpLastCell
= cell
;
228 else // mouse moved but stayed in the same cell
232 OnCellMouseHover(cell
, pos
.x
, pos
.y
);
236 m_tmpMouseMoved
= false;
239 bool wxHtmlWindowMouseHelper::OnCellClicked(wxHtmlCell
*cell
,
240 wxCoord x
, wxCoord y
,
241 const wxMouseEvent
& event
)
243 wxHtmlCellEvent
ev(wxEVT_COMMAND_HTML_CELL_CLICKED
,
244 m_interface
->GetHTMLWindow()->GetId(),
245 cell
, wxPoint(x
,y
), event
);
247 if (!m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
))
249 // if the event wasn't handled, do the default processing here:
251 wxASSERT_MSG( cell
, wxT("can't be called with NULL cell") );
253 cell
->ProcessMouseClick(m_interface
, ev
.GetPoint(), ev
.GetMouseEvent());
256 // true if a link was clicked, false otherwise
257 return ev
.GetLinkClicked();
260 void wxHtmlWindowMouseHelper::OnCellMouseHover(wxHtmlCell
* cell
,
264 wxHtmlCellEvent
ev(wxEVT_COMMAND_HTML_CELL_HOVER
,
265 m_interface
->GetHTMLWindow()->GetId(),
266 cell
, wxPoint(x
,y
), wxMouseEvent());
267 m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
);
273 //-----------------------------------------------------------------------------
275 //-----------------------------------------------------------------------------
277 wxList
wxHtmlWindow::m_Filters
;
278 wxHtmlFilter
*wxHtmlWindow::m_DefaultFilter
= NULL
;
279 wxHtmlProcessorList
*wxHtmlWindow::m_GlobalProcessors
= NULL
;
280 wxCursor
*wxHtmlWindow::ms_cursorLink
= NULL
;
281 wxCursor
*wxHtmlWindow::ms_cursorText
= NULL
;
283 void wxHtmlWindow::CleanUpStatics()
285 wxDELETE(m_DefaultFilter
);
286 WX_CLEAR_LIST(wxList
, m_Filters
);
287 if (m_GlobalProcessors
)
288 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_GlobalProcessors
);
289 wxDELETE(m_GlobalProcessors
);
290 wxDELETE(ms_cursorLink
);
291 wxDELETE(ms_cursorText
);
294 void wxHtmlWindow::Init()
296 m_tmpCanDrawLocks
= 0;
297 m_FS
= new wxFileSystem();
299 m_RelatedStatusBar
= NULL
;
300 m_RelatedStatusBarIndex
= -1;
301 #endif // wxUSE_STATUSBAR
302 m_RelatedFrame
= NULL
;
303 m_TitleFormat
= wxT("%s");
304 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
306 m_Parser
= new wxHtmlWinParser(this);
307 m_Parser
->SetFS(m_FS
);
310 m_History
= new wxHtmlHistoryArray
;
314 m_makingSelection
= false;
316 m_timerAutoScroll
= NULL
;
317 m_lastDoubleClick
= 0;
318 #endif // wxUSE_CLIPBOARD
319 m_tmpSelFromCell
= NULL
;
322 bool wxHtmlWindow::Create(wxWindow
*parent
, wxWindowID id
,
323 const wxPoint
& pos
, const wxSize
& size
,
324 long style
, const wxString
& name
)
326 if (!wxScrolledWindow::Create(parent
, id
, pos
, size
,
327 style
| wxVSCROLL
| wxHSCROLL
,
331 // We can't erase our background in EVT_ERASE_BACKGROUND handler and use
332 // double buffering in EVT_PAINT handler as this requires blitting back
333 // something already drawn on the window to the backing store bitmap when
334 // handling EVT_PAINT but blitting in this direction is simply not
335 // supported by OS X.
337 // So instead we use a hack with artificial EVT_ERASE_BACKGROUND generation
338 // from OnPaint() and this means that we never need the "real" erase event
339 // at all so disable it to avoid executing any user-defined handlers twice
340 // (and to avoid processing unnecessary event if no handlers are defined).
341 SetBackgroundStyle(wxBG_STYLE_PAINT
);
342 SetPage(wxT("<html><body></body></html>"));
344 SetInitialSize(size
);
349 wxHtmlWindow::~wxHtmlWindow()
353 #endif // wxUSE_CLIPBOARD
362 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_Processors
);
373 void wxHtmlWindow::SetRelatedFrame(wxFrame
* frame
, const wxString
& format
)
375 m_RelatedFrame
= frame
;
376 m_TitleFormat
= format
;
382 void wxHtmlWindow::SetRelatedStatusBar(int index
)
384 m_RelatedStatusBarIndex
= index
;
387 void wxHtmlWindow::SetRelatedStatusBar(wxStatusBar
* statusbar
, int index
)
389 m_RelatedStatusBar
= statusbar
;
390 m_RelatedStatusBarIndex
= index
;
393 #endif // wxUSE_STATUSBAR
397 void wxHtmlWindow::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, const int *sizes
)
399 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
401 // re-layout the page after changing fonts:
402 DoSetPage(*(m_Parser
->GetSource()));
405 void wxHtmlWindow::SetStandardFonts(int size
,
406 const wxString
& normal_face
,
407 const wxString
& fixed_face
)
409 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
411 // re-layout the page after changing fonts:
412 DoSetPage(*(m_Parser
->GetSource()));
415 bool wxHtmlWindow::SetPage(const wxString
& source
)
417 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
418 return DoSetPage(source
);
421 bool wxHtmlWindow::DoSetPage(const wxString
& source
)
423 wxString
newsrc(source
);
425 wxDELETE(m_selection
);
427 // we will soon delete all the cells, so clear pointers to them:
428 m_tmpSelFromCell
= NULL
;
430 // pass HTML through registered processors:
431 if (m_Processors
|| m_GlobalProcessors
)
433 wxHtmlProcessorList::compatibility_iterator nodeL
, nodeG
;
437 nodeL
= m_Processors
->GetFirst();
438 if ( m_GlobalProcessors
)
439 nodeG
= m_GlobalProcessors
->GetFirst();
441 // VS: there are two lists, global and local, both of them sorted by
442 // priority. Since we have to go through _both_ lists with
443 // decreasing priority, we "merge-sort" the lists on-line by
444 // processing that one of the two heads that has higher priority
445 // in every iteration
446 while (nodeL
|| nodeG
)
448 prL
= (nodeL
) ? nodeL
->GetData()->GetPriority() : -1;
449 prG
= (nodeG
) ? nodeG
->GetData()->GetPriority() : -1;
452 if (nodeL
->GetData()->IsEnabled())
453 newsrc
= nodeL
->GetData()->Process(newsrc
);
454 nodeL
= nodeL
->GetNext();
458 if (nodeG
->GetData()->IsEnabled())
459 newsrc
= nodeG
->GetData()->Process(newsrc
);
460 nodeG
= nodeG
->GetNext();
465 // ...and run the parser on it:
466 wxClientDC
*dc
= new wxClientDC(this);
467 dc
->SetMapMode(wxMM_TEXT
);
468 SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
469 SetBackgroundImage(wxNullBitmap
);
473 // notice that it's important to set m_Cell to NULL here before calling
474 // Parse() below, even if it will be overwritten by its return value as
475 // without this we may crash if it's used from inside Parse(), so use
476 // wxDELETE() and not just delete here
479 m_Cell
= (wxHtmlContainerCell
*) m_Parser
->Parse(newsrc
);
481 m_Cell
->SetIndent(m_Borders
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
482 m_Cell
->SetAlignHor(wxHTML_ALIGN_CENTER
);
484 if (m_tmpCanDrawLocks
== 0)
489 bool wxHtmlWindow::AppendToPage(const wxString
& source
)
491 return DoSetPage(*(GetParser()->GetSource()) + source
);
494 bool wxHtmlWindow::LoadPage(const wxString
& location
)
496 wxCHECK_MSG( !location
.empty(), false, "location must be non-empty" );
498 wxBusyCursor busyCursor
;
501 bool needs_refresh
= false;
504 if (m_HistoryOn
&& (m_HistoryPos
!= -1))
506 // store scroll position into history item:
508 GetViewStart(&x
, &y
);
509 (*m_History
)[m_HistoryPos
].SetPos(y
);
512 // first check if we're moving to an anchor in the same page
513 size_t posLocalAnchor
= location
.Find('#');
514 if ( posLocalAnchor
!= wxString::npos
&& posLocalAnchor
!= 0 )
516 // check if the part before the anchor is the same as the (either
517 // relative or absolute) URI of the current page
518 const wxString beforeAnchor
= location
.substr(0, posLocalAnchor
);
519 if ( beforeAnchor
!= m_OpenedPage
&&
520 m_FS
->GetPath() + beforeAnchor
!= m_OpenedPage
)
522 // indicate that we're not moving to a local anchor
523 posLocalAnchor
= wxString::npos
;
527 if ( posLocalAnchor
!= wxString::npos
)
530 rt_val
= ScrollToAnchor(location
.substr(posLocalAnchor
+ 1));
533 else // moving to another page
535 needs_refresh
= true;
538 if (m_RelatedStatusBarIndex
!= -1)
540 SetHTMLStatusText(_("Connecting..."));
543 #endif // wxUSE_STATUSBAR
545 wxFSFile
*f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location
);
547 // try to interpret 'location' as filename instead of URL:
550 wxFileName
fn(location
);
551 wxString location2
= wxFileSystem::FileNameToURL(fn
);
552 f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location2
);
557 wxLogError(_("Unable to open requested HTML document: %s"), location
.c_str());
559 SetHTMLStatusText(wxEmptyString
);
565 wxList::compatibility_iterator node
;
566 wxString src
= wxEmptyString
;
569 if (m_RelatedStatusBarIndex
!= -1)
571 wxString msg
= _("Loading : ") + location
;
572 SetHTMLStatusText(msg
);
575 #endif // wxUSE_STATUSBAR
577 node
= m_Filters
.GetFirst();
580 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
583 src
= h
->ReadFile(*f
);
586 node
= node
->GetNext();
588 if (src
== wxEmptyString
)
590 if (m_DefaultFilter
== NULL
) m_DefaultFilter
= GetDefaultFilter();
591 src
= m_DefaultFilter
->ReadFile(*f
);
594 m_FS
->ChangePathTo(f
->GetLocation());
595 rt_val
= SetPage(src
);
596 m_OpenedPage
= f
->GetLocation();
597 if (f
->GetAnchor() != wxEmptyString
)
599 ScrollToAnchor(f
->GetAnchor());
605 if (m_RelatedStatusBarIndex
!= -1)
607 SetHTMLStatusText(_("Done"));
609 #endif // wxUSE_STATUSBAR
613 if (m_HistoryOn
) // add this page to history there:
615 int c
= m_History
->GetCount() - (m_HistoryPos
+ 1);
617 if (m_HistoryPos
< 0 ||
618 (*m_History
)[m_HistoryPos
].GetPage() != m_OpenedPage
||
619 (*m_History
)[m_HistoryPos
].GetAnchor() != m_OpenedAnchor
)
622 for (int i
= 0; i
< c
; i
++)
623 m_History
->RemoveAt(m_HistoryPos
);
624 m_History
->Add(new wxHtmlHistoryItem(m_OpenedPage
, m_OpenedAnchor
));
628 if (m_OpenedPageTitle
== wxEmptyString
)
629 OnSetTitle(wxFileNameFromPath(m_OpenedPage
));
643 bool wxHtmlWindow::LoadFile(const wxFileName
& filename
)
645 wxString url
= wxFileSystem::FileNameToURL(filename
);
646 return LoadPage(url
);
650 bool wxHtmlWindow::ScrollToAnchor(const wxString
& anchor
)
652 const wxHtmlCell
*c
= m_Cell
->Find(wxHTML_COND_ISANCHOR
, &anchor
);
655 wxLogWarning(_("HTML anchor %s does not exist."), anchor
.c_str());
660 // Go to next visible cell in current container, if it exists. This
661 // yields a bit better (even though still imperfect) results in that
662 // there's better chance of using a suitable cell for upper Y
663 // coordinate value. See bug #11406 for additional discussion.
664 const wxHtmlCell
*c_save
= c
;
665 while ( c
&& c
->IsFormattingCell() )
672 for (y
= 0; c
!= NULL
; c
= c
->GetParent()) y
+= c
->GetPosY();
673 Scroll(-1, y
/ wxHTML_SCROLL_STEP
);
674 m_OpenedAnchor
= anchor
;
680 void wxHtmlWindow::OnSetTitle(const wxString
& title
)
685 tit
.Printf(m_TitleFormat
, title
.c_str());
686 m_RelatedFrame
->SetTitle(tit
);
688 m_OpenedPageTitle
= title
;
692 // return scroll steps such that a) scrollbars aren't shown needlessly
693 // and b) entire content is viewable (i.e. round up)
694 static int ScrollSteps(int size
, int available
)
696 if ( size
<= available
)
699 return (size
+ wxHTML_SCROLL_STEP
- 1) / wxHTML_SCROLL_STEP
;
703 void wxHtmlWindow::CreateLayout()
705 // SetScrollbars() results in size change events -- and thus a nested
706 // CreateLayout() call -- on some platforms. Ignore nested calls, toplevel
707 // CreateLayout() will do the right thing eventually.
708 static wxRecursionGuardFlag s_flagReentrancy
;
709 wxRecursionGuard
guard(s_flagReentrancy
);
710 if ( guard
.IsInside() )
716 int clientWidth
, clientHeight
;
717 GetClientSize(&clientWidth
, &clientHeight
);
719 const int vscrollbar
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
720 const int hscrollbar
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
722 if ( HasScrollbar(wxHORIZONTAL
) )
723 clientHeight
+= hscrollbar
;
725 if ( HasScrollbar(wxVERTICAL
) )
726 clientWidth
+= vscrollbar
;
728 if ( HasFlag(wxHW_SCROLLBAR_NEVER
) )
730 SetScrollbars(1, 1, 0, 0); // always off
731 m_Cell
->Layout(clientWidth
);
733 else // !wxHW_SCROLLBAR_NEVER
735 // Lay the content out with the assumption that it's too large to fit
736 // in the window (this is likely to be the case):
737 m_Cell
->Layout(clientWidth
- vscrollbar
);
739 // If the layout is wider than the window, horizontal scrollbar will
740 // certainly be shown. Account for it here for subsequent computations.
741 if ( m_Cell
->GetWidth() > clientWidth
)
742 clientHeight
-= hscrollbar
;
744 if ( m_Cell
->GetHeight() <= clientHeight
)
746 // we fit into the window, hide vertical scrollbar:
749 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
750 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
753 // ...and redo the layout to use the extra space
754 m_Cell
->Layout(clientWidth
);
758 // If the content doesn't fit into the window by only a small
759 // margin, chances are that it may fit fully with scrollbar turned
760 // off. It's something worth trying but on the other hand, we don't
761 // want to waste too much time redoing the layout (twice!) for
762 // long -- and thus expensive to layout -- pages. The cut-off value
763 // is an arbitrary heuristics.
764 static const int SMALL_OVERLAP
= 60;
765 if ( m_Cell
->GetHeight() <= clientHeight
+ SMALL_OVERLAP
)
767 m_Cell
->Layout(clientWidth
);
769 if ( m_Cell
->GetHeight() <= clientHeight
)
771 // Great, we fit in. Hide the scrollbar.
774 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
775 ScrollSteps(m_Cell
->GetWidth(), clientWidth
),
782 // That didn't work out, go back to previous layout. Note
783 // that redoing the layout once again here isn't as bad as
784 // it looks -- thanks to the small cut-off value, it's a
785 // reasonably small page.
786 m_Cell
->Layout(clientWidth
- vscrollbar
);
789 // else: the page is very long, it will certainly need scrollbar
793 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
794 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
795 ScrollSteps(m_Cell
->GetHeight(), clientHeight
)
802 void wxHtmlWindow::ReadCustomization(wxConfigBase
*cfg
, wxString path
)
807 wxString p_fff
, p_ffn
;
809 if (path
!= wxEmptyString
)
811 oldpath
= cfg
->GetPath();
815 m_Borders
= cfg
->Read(wxT("wxHtmlWindow/Borders"), m_Borders
);
816 p_fff
= cfg
->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
817 p_ffn
= cfg
->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
818 for (int i
= 0; i
< 7; i
++)
820 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
821 p_fontsizes
[i
] = cfg
->Read(tmp
, m_Parser
->m_FontsSizes
[i
]);
823 SetFonts(p_ffn
, p_fff
, p_fontsizes
);
825 if (path
!= wxEmptyString
)
826 cfg
->SetPath(oldpath
);
831 void wxHtmlWindow::WriteCustomization(wxConfigBase
*cfg
, wxString path
)
836 if (path
!= wxEmptyString
)
838 oldpath
= cfg
->GetPath();
842 cfg
->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders
);
843 cfg
->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
844 cfg
->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
845 for (int i
= 0; i
< 7; i
++)
847 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
848 cfg
->Write(tmp
, (long) m_Parser
->m_FontsSizes
[i
]);
851 if (path
!= wxEmptyString
)
852 cfg
->SetPath(oldpath
);
854 #endif // wxUSE_CONFIG
856 bool wxHtmlWindow::HistoryBack()
860 if (m_HistoryPos
< 1) return false;
862 // store scroll position into history item:
864 GetViewStart(&x
, &y
);
865 (*m_History
)[m_HistoryPos
].SetPos(y
);
867 // go to previous position:
870 l
= (*m_History
)[m_HistoryPos
].GetPage();
871 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
874 if (a
== wxEmptyString
) LoadPage(l
);
875 else LoadPage(l
+ wxT("#") + a
);
878 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
883 bool wxHtmlWindow::HistoryCanBack()
885 if (m_HistoryPos
< 1) return false;
890 bool wxHtmlWindow::HistoryForward()
894 if (m_HistoryPos
== -1) return false;
895 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
897 m_OpenedPage
= wxEmptyString
; // this will disable adding new entry into history in LoadPage()
900 l
= (*m_History
)[m_HistoryPos
].GetPage();
901 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
904 if (a
== wxEmptyString
) LoadPage(l
);
905 else LoadPage(l
+ wxT("#") + a
);
908 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
913 bool wxHtmlWindow::HistoryCanForward()
915 if (m_HistoryPos
== -1) return false;
916 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
921 void wxHtmlWindow::HistoryClear()
927 void wxHtmlWindow::AddProcessor(wxHtmlProcessor
*processor
)
931 m_Processors
= new wxHtmlProcessorList
;
933 wxHtmlProcessorList::compatibility_iterator node
;
935 for (node
= m_Processors
->GetFirst(); node
; node
= node
->GetNext())
937 if (processor
->GetPriority() > node
->GetData()->GetPriority())
939 m_Processors
->Insert(node
, processor
);
943 m_Processors
->Append(processor
);
946 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor
*processor
)
948 if (!m_GlobalProcessors
)
950 m_GlobalProcessors
= new wxHtmlProcessorList
;
952 wxHtmlProcessorList::compatibility_iterator node
;
954 for (node
= m_GlobalProcessors
->GetFirst(); node
; node
= node
->GetNext())
956 if (processor
->GetPriority() > node
->GetData()->GetPriority())
958 m_GlobalProcessors
->Insert(node
, processor
);
962 m_GlobalProcessors
->Append(processor
);
967 void wxHtmlWindow::AddFilter(wxHtmlFilter
*filter
)
969 m_Filters
.Append(filter
);
973 bool wxHtmlWindow::IsSelectionEnabled() const
976 return !HasFlag(wxHW_NO_SELECTION
);
984 wxString
wxHtmlWindow::DoSelectionToText(wxHtmlSelection
*sel
)
987 return wxEmptyString
;
992 wxHtmlTerminalCellsInterator
i(sel
->GetFromCell(), sel
->GetToCell());
993 const wxHtmlCell
*prev
= NULL
;
997 // When converting HTML content to plain text, the entire paragraph
998 // (container in wxHTML) goes on single line. A new paragraph (that
999 // should go on its own line) has its own container. Therefore, the
1000 // simplest way of detecting where to insert newlines in plain text
1001 // is to check if the parent container changed -- if it did, we moved
1002 // to a new paragraph.
1003 if ( prev
&& prev
->GetParent() != i
->GetParent() )
1006 // NB: we don't need to pass the selection to ConvertToText() in the
1007 // middle of the selected text; it's only useful when only part of
1008 // a cell is selected
1009 text
<< i
->ConvertToText(sel
);
1017 wxString
wxHtmlWindow::ToText()
1021 wxHtmlSelection sel
;
1022 sel
.Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1023 return DoSelectionToText(&sel
);
1026 return wxEmptyString
;
1029 #endif // wxUSE_CLIPBOARD
1031 bool wxHtmlWindow::CopySelection(ClipboardType t
)
1036 #if defined(__UNIX__) && !defined(__WXMAC__)
1037 wxTheClipboard
->UsePrimarySelection(t
== Primary
);
1039 // Primary selection exists only under X11, so don't do anything under
1040 // the other platforms when we try to access it
1042 // TODO: this should be abstracted at wxClipboard level!
1045 #endif // __UNIX__/!__UNIX__
1047 if ( wxTheClipboard
->Open() )
1049 const wxString
txt(SelectionToText());
1050 wxTheClipboard
->SetData(new wxTextDataObject(txt
));
1051 wxTheClipboard
->Close();
1052 wxLogTrace(wxT("wxhtmlselection"),
1053 _("Copied to clipboard:\"%s\""), txt
.c_str());
1060 #endif // wxUSE_CLIPBOARD
1066 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo
& link
)
1068 wxHtmlLinkEvent
event(GetId(), link
);
1069 event
.SetEventObject(this);
1070 if (!GetEventHandler()->ProcessEvent(event
))
1072 // the default behaviour is to load the URL in this window
1073 const wxMouseEvent
*e
= event
.GetLinkInfo().GetEvent();
1074 if (e
== NULL
|| e
->LeftUp())
1075 LoadPage(event
.GetLinkInfo().GetHref());
1079 void wxHtmlWindow::DoEraseBackground(wxDC
& dc
)
1081 // if we don't have any background bitmap we just fill it with background
1082 // colour and we also must do it if the background bitmap is not fully
1083 // opaque as otherwise junk could be left there
1084 if ( !m_bmpBg
.IsOk() || m_bmpBg
.GetMask() )
1086 dc
.SetBackground(GetBackgroundColour());
1090 if ( m_bmpBg
.IsOk() )
1092 // draw the background bitmap tiling it over the entire window area
1093 const wxSize sz
= GetVirtualSize();
1094 const wxSize
sizeBmp(m_bmpBg
.GetWidth(), m_bmpBg
.GetHeight());
1095 for ( wxCoord x
= 0; x
< sz
.x
; x
+= sizeBmp
.x
)
1097 for ( wxCoord y
= 0; y
< sz
.y
; y
+= sizeBmp
.y
)
1099 dc
.DrawBitmap(m_bmpBg
, x
, y
, true /* use mask */);
1105 void wxHtmlWindow::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
1107 // We never get real erase background events as we changed our background
1108 // style to wxBG_STYLE_PAINT in our ctor so the only time when we get here
1109 // is when an artificial wxEraseEvent is generated by our own OnPaint()
1110 // below. This handler only exists to stop the event from propagating
1111 // downwards to wxWindow which may erase the background itself when it gets
1112 // it in some ports (currently this happens in wxUniv), so we simply stop
1113 // processing here and set a special flag allowing OnPaint() to see that
1114 // the event hadn't been really processed.
1115 m_isBgReallyErased
= false;
1118 void wxHtmlWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
1120 wxPaintDC
dcPaint(this);
1122 if (m_tmpCanDrawLocks
> 0 || m_Cell
== NULL
)
1126 GetViewStart(&x
, &y
);
1127 const wxRect rect
= GetUpdateRegion().GetBox();
1128 const wxSize sz
= GetClientSize();
1130 // set up the DC we're drawing on: if the window is already double buffered
1131 // we do it directly on wxPaintDC, otherwise we allocate a backing store
1132 // buffer and compose the drawing there and then blit it to screen all at
1136 if ( IsDoubleBuffered() )
1140 else // window is not double buffered by the system, do it ourselves
1142 if ( !m_backBuffer
.IsOk() )
1143 m_backBuffer
.Create(sz
.x
, sz
.y
);
1144 dcm
.SelectObject(m_backBuffer
);
1150 // Erase the background: for compatibility, we must generate the event to
1151 // allow the user-defined handlers to do it, hence this hack with sending
1152 // an artificial wxEraseEvent to trigger the execution of such handlers.
1153 wxEraseEvent
eraseEvent(GetId(), dc
);
1154 eraseEvent
.SetEventObject(this);
1156 // Hack inside a hack: the background wasn't really erased if our own
1157 // OnEraseBackground() was executed, so we need to check for the flag set
1158 // by it whenever it's called.
1159 m_isBgReallyErased
= true; // Initially assume it wasn't.
1160 if ( !ProcessWindowEvent(eraseEvent
) || !m_isBgReallyErased
)
1162 // erase background ourselves
1163 DoEraseBackground(*dc
);
1165 //else: background erased by the user-defined handler
1168 // draw the HTML window contents
1169 dc
->SetMapMode(wxMM_TEXT
);
1170 dc
->SetBackgroundMode(wxTRANSPARENT
);
1171 dc
->SetLayoutDirection(GetLayoutDirection());
1173 wxHtmlRenderingInfo rinfo
;
1174 wxDefaultHtmlRenderingStyle rstyle
;
1175 rinfo
.SetSelection(m_selection
);
1176 rinfo
.SetStyle(&rstyle
);
1177 m_Cell
->Draw(*dc
, 0, 0,
1178 y
* wxHTML_SCROLL_STEP
+ rect
.GetTop(),
1179 y
* wxHTML_SCROLL_STEP
+ rect
.GetBottom(),
1182 #ifdef DEBUG_HTML_SELECTION
1185 wxGetMousePosition(&xc
, &yc
);
1186 ScreenToClient(&xc
, &yc
);
1187 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1188 wxHtmlCell
*at
= m_Cell
->FindCellByPos(x
, y
);
1189 wxHtmlCell
*before
=
1190 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_BEFORE
);
1192 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_AFTER
);
1194 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1195 dc
->SetPen(*wxBLACK_PEN
);
1197 dc
->DrawRectangle(at
->GetAbsPos(),
1198 wxSize(at
->GetWidth(),at
->GetHeight()));
1199 dc
->SetPen(*wxGREEN_PEN
);
1201 dc
->DrawRectangle(before
->GetAbsPos().x
+1, before
->GetAbsPos().y
+1,
1202 before
->GetWidth()-2,before
->GetHeight()-2);
1203 dc
->SetPen(*wxRED_PEN
);
1205 dc
->DrawRectangle(after
->GetAbsPos().x
+2, after
->GetAbsPos().y
+2,
1206 after
->GetWidth()-4,after
->GetHeight()-4);
1208 #endif // DEBUG_HTML_SELECTION
1210 if ( dc
!= &dcPaint
)
1212 dc
->SetDeviceOrigin(0,0);
1213 dcPaint
.Blit(0, rect
.GetTop(),
1214 sz
.x
, rect
.GetBottom() - rect
.GetTop() + 1,
1223 void wxHtmlWindow::OnSize(wxSizeEvent
& event
)
1227 m_backBuffer
= wxNullBitmap
;
1231 // Recompute selection if necessary:
1234 m_selection
->Set(m_selection
->GetFromCell(),
1235 m_selection
->GetToCell());
1236 m_selection
->ClearFromToCharacterPos();
1243 void wxHtmlWindow::OnMouseMove(wxMouseEvent
& WXUNUSED(event
))
1245 wxHtmlWindowMouseHelper::HandleMouseMoved();
1248 void wxHtmlWindow::OnMouseDown(wxMouseEvent
& event
)
1251 if ( event
.LeftDown() && IsSelectionEnabled() )
1253 const long TRIPLECLICK_LEN
= 200; // 0.2 sec after doubleclick
1254 if ( wxGetLocalTimeMillis() - m_lastDoubleClick
<= TRIPLECLICK_LEN
)
1256 SelectLine(CalcUnscrolledPosition(event
.GetPosition()));
1258 (void) CopySelection();
1262 m_makingSelection
= true;
1266 wxDELETE(m_selection
);
1269 m_tmpSelFromPos
= CalcUnscrolledPosition(event
.GetPosition());
1270 m_tmpSelFromCell
= NULL
;
1275 #endif // wxUSE_CLIPBOARD
1277 // in any case, let the default handler set focus to this window
1281 void wxHtmlWindow::OnMouseUp(wxMouseEvent
& event
)
1284 if ( m_makingSelection
)
1287 m_makingSelection
= false;
1289 // if m_selection=NULL, the user didn't move the mouse far enough from
1290 // starting point and the mouse up event is part of a click, the user
1291 // is not selecting text:
1294 CopySelection(Primary
);
1296 // we don't want mouse up event that ended selecting to be
1297 // handled as mouse click and e.g. follow hyperlink:
1301 #endif // wxUSE_CLIPBOARD
1303 wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
1304 if ( !wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell
, pos
, event
) )
1309 void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1311 if ( !m_makingSelection
)
1314 // discard the selecting operation
1315 m_makingSelection
= false;
1316 wxDELETE(m_selection
);
1317 m_tmpSelFromCell
= NULL
;
1320 #endif // wxUSE_CLIPBOARD
1323 void wxHtmlWindow::OnInternalIdle()
1325 wxWindow::OnInternalIdle();
1327 if (m_Cell
!= NULL
&& DidMouseMove())
1329 #ifdef DEBUG_HTML_SELECTION
1333 wxGetMousePosition(&xc
, &yc
);
1334 ScreenToClient(&xc
, &yc
);
1335 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1337 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(x
, y
);
1339 // handle selection update:
1340 if ( m_makingSelection
)
1342 if ( !m_tmpSelFromCell
)
1343 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1344 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
);
1346 // NB: a trick - we adjust selFromPos to be upper left or bottom
1347 // right corner of the first cell of the selection depending
1348 // on whether the mouse is moving to the right or to the left.
1349 // This gives us more "natural" behaviour when selecting
1350 // a line (specifically, first cell of the next line is not
1351 // included if you drag selection from left to right over
1354 if ( !m_tmpSelFromCell
)
1356 dirFromPos
= m_tmpSelFromPos
;
1360 dirFromPos
= m_tmpSelFromCell
->GetAbsPos();
1361 if ( x
< m_tmpSelFromPos
.x
)
1363 dirFromPos
.x
+= m_tmpSelFromCell
->GetWidth();
1364 dirFromPos
.y
+= m_tmpSelFromCell
->GetHeight();
1367 bool goingDown
= dirFromPos
.y
< y
||
1368 (dirFromPos
.y
== y
&& dirFromPos
.x
< x
);
1370 // determine selection span:
1371 if ( /*still*/ !m_tmpSelFromCell
)
1375 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1376 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1377 wxHTML_FIND_NEAREST_AFTER
);
1378 if (!m_tmpSelFromCell
)
1379 m_tmpSelFromCell
= m_Cell
->GetFirstTerminal();
1383 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1384 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1385 wxHTML_FIND_NEAREST_BEFORE
);
1386 if (!m_tmpSelFromCell
)
1387 m_tmpSelFromCell
= m_Cell
->GetLastTerminal();
1391 wxHtmlCell
*selcell
= cell
;
1396 selcell
= m_Cell
->FindCellByPos(x
, y
,
1397 wxHTML_FIND_NEAREST_BEFORE
);
1399 selcell
= m_Cell
->GetLastTerminal();
1403 selcell
= m_Cell
->FindCellByPos(x
, y
,
1404 wxHTML_FIND_NEAREST_AFTER
);
1406 selcell
= m_Cell
->GetFirstTerminal();
1410 // NB: it may *rarely* happen that the code above didn't find one
1411 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1413 if ( selcell
&& m_tmpSelFromCell
)
1417 // start selecting only if mouse movement was big enough
1418 // (otherwise it was meant as mouse click, not selection):
1419 const int PRECISION
= 2;
1420 wxPoint diff
= m_tmpSelFromPos
- wxPoint(x
,y
);
1421 if (abs(diff
.x
) > PRECISION
|| abs(diff
.y
) > PRECISION
)
1423 m_selection
= new wxHtmlSelection();
1428 if ( m_tmpSelFromCell
->IsBefore(selcell
) )
1430 m_selection
->Set(m_tmpSelFromPos
, m_tmpSelFromCell
,
1431 wxPoint(x
,y
), selcell
);
1435 m_selection
->Set(wxPoint(x
,y
), selcell
,
1436 m_tmpSelFromPos
, m_tmpSelFromCell
);
1438 m_selection
->ClearFromToCharacterPos();
1444 // handle cursor and status bar text changes:
1446 // NB: because we're passing in 'cell' and not 'm_Cell' (so that the
1447 // leaf cell lookup isn't done twice), we need to adjust the
1448 // position for the new root:
1449 wxPoint
posInCell(x
, y
);
1451 posInCell
-= cell
->GetAbsPos();
1452 wxHtmlWindowMouseHelper::HandleIdle(cell
, posInCell
);
1457 void wxHtmlWindow::StopAutoScrolling()
1459 if ( m_timerAutoScroll
)
1461 wxDELETE(m_timerAutoScroll
);
1465 void wxHtmlWindow::OnMouseEnter(wxMouseEvent
& event
)
1467 StopAutoScrolling();
1471 void wxHtmlWindow::OnMouseLeave(wxMouseEvent
& event
)
1473 // don't prevent the usual processing of the event from taking place
1476 // when a captured mouse leave a scrolled window we start generate
1477 // scrolling events to allow, for example, extending selection beyond the
1478 // visible area in some controls
1479 if ( wxWindow::GetCapture() == this )
1481 // where is the mouse leaving?
1483 wxPoint pt
= event
.GetPosition();
1486 orient
= wxHORIZONTAL
;
1489 else if ( pt
.y
< 0 )
1491 orient
= wxVERTICAL
;
1494 else // we're lower or to the right of the window
1496 wxSize size
= GetClientSize();
1497 if ( pt
.x
> size
.x
)
1499 orient
= wxHORIZONTAL
;
1500 pos
= GetVirtualSize().x
/ wxHTML_SCROLL_STEP
;
1502 else if ( pt
.y
> size
.y
)
1504 orient
= wxVERTICAL
;
1505 pos
= GetVirtualSize().y
/ wxHTML_SCROLL_STEP
;
1507 else // this should be impossible
1509 // but seems to happen sometimes under wxMSW - maybe it's a bug
1510 // there but for now just ignore it
1512 //wxFAIL_MSG( wxT("can't understand where has mouse gone") );
1518 // only start the auto scroll timer if the window can be scrolled in
1520 if ( !HasScrollbar(orient
) )
1523 delete m_timerAutoScroll
;
1524 m_timerAutoScroll
= new wxHtmlWinAutoScrollTimer
1527 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
1528 : wxEVT_SCROLLWIN_LINEDOWN
,
1532 m_timerAutoScroll
->Start(50); // FIXME: make configurable
1536 void wxHtmlWindow::OnKeyUp(wxKeyEvent
& event
)
1538 if ( IsSelectionEnabled() &&
1539 (event
.GetKeyCode() == 'C' && event
.CmdDown()) )
1541 wxClipboardTextEvent
evt(wxEVT_COMMAND_TEXT_COPY
, GetId());
1543 evt
.SetEventObject(this);
1545 GetEventHandler()->ProcessEvent(evt
);
1553 void wxHtmlWindow::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1555 (void) CopySelection();
1558 void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent
& WXUNUSED(event
))
1560 (void) CopySelection();
1563 void wxHtmlWindow::OnDoubleClick(wxMouseEvent
& event
)
1565 // select word under cursor:
1566 if ( IsSelectionEnabled() )
1568 SelectWord(CalcUnscrolledPosition(event
.GetPosition()));
1570 (void) CopySelection(Primary
);
1572 m_lastDoubleClick
= wxGetLocalTimeMillis();
1578 void wxHtmlWindow::SelectWord(const wxPoint
& pos
)
1582 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1586 m_selection
= new wxHtmlSelection();
1587 m_selection
->Set(cell
, cell
);
1588 RefreshRect(wxRect(CalcScrolledPosition(cell
->GetAbsPos()),
1589 wxSize(cell
->GetWidth(), cell
->GetHeight())));
1594 void wxHtmlWindow::SelectLine(const wxPoint
& pos
)
1598 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1601 // We use following heuristic to find a "line": let the line be all
1602 // cells in same container as the cell under mouse cursor that are
1603 // neither completely above nor completely below the clicked cell
1604 // (i.e. are likely to be words positioned on same line of text).
1606 int y1
= cell
->GetAbsPos().y
;
1607 int y2
= y1
+ cell
->GetHeight();
1609 const wxHtmlCell
*c
;
1610 const wxHtmlCell
*before
= NULL
;
1611 const wxHtmlCell
*after
= NULL
;
1613 // find last cell of line:
1614 for ( c
= cell
->GetNext(); c
; c
= c
->GetNext())
1616 y
= c
->GetAbsPos().y
;
1617 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1625 // find first cell of line:
1626 for ( c
= cell
->GetParent()->GetFirstChild();
1627 c
&& c
!= cell
; c
= c
->GetNext())
1629 y
= c
->GetAbsPos().y
;
1630 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1642 m_selection
= new wxHtmlSelection();
1643 m_selection
->Set(before
, after
);
1650 void wxHtmlWindow::SelectAll()
1655 m_selection
= new wxHtmlSelection();
1656 m_selection
->Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1661 #endif // wxUSE_CLIPBOARD
1665 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor
,wxObject
)
1667 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow
)
1670 style , wxHW_SCROLLBAR_AUTO
1671 borders , (dimension)
1675 wxEND_PROPERTIES_TABLE()
1677 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow
)
1678 wxEND_HANDLERS_TABLE()
1680 wxCONSTRUCTOR_5( wxHtmlWindow
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1682 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow
, wxScrolledWindow
,"wx/html/htmlwin.h")
1684 BEGIN_EVENT_TABLE(wxHtmlWindow
, wxScrolledWindow
)
1685 EVT_SIZE(wxHtmlWindow::OnSize
)
1686 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown
)
1687 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp
)
1688 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp
)
1689 EVT_MOTION(wxHtmlWindow::OnMouseMove
)
1690 EVT_PAINT(wxHtmlWindow::OnPaint
)
1691 EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground
)
1693 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick
)
1694 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter
)
1695 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave
)
1696 EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost
)
1697 EVT_KEY_UP(wxHtmlWindow::OnKeyUp
)
1698 EVT_MENU(wxID_COPY
, wxHtmlWindow::OnCopy
)
1699 EVT_TEXT_COPY(wxID_ANY
, wxHtmlWindow::OnClipboardEvent
)
1700 #endif // wxUSE_CLIPBOARD
1703 //-----------------------------------------------------------------------------
1704 // wxHtmlWindowInterface implementation in wxHtmlWindow
1705 //-----------------------------------------------------------------------------
1707 void wxHtmlWindow::SetHTMLWindowTitle(const wxString
& title
)
1712 void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
)
1714 OnLinkClicked(link
);
1717 wxHtmlOpeningStatus
wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type
,
1718 const wxString
& url
,
1719 wxString
*redirect
) const
1721 return OnOpeningURL(type
, url
, redirect
);
1724 wxPoint
wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell
*WXUNUSED(cell
),
1725 const wxPoint
& pos
) const
1727 return CalcScrolledPosition(pos
);
1730 wxWindow
* wxHtmlWindow::GetHTMLWindow()
1735 wxColour
wxHtmlWindow::GetHTMLBackgroundColour() const
1737 return GetBackgroundColour();
1740 void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour
& clr
)
1742 SetBackgroundColour(clr
);
1745 void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap
& bmpBg
)
1747 SetBackgroundImage(bmpBg
);
1750 void wxHtmlWindow::SetHTMLStatusText(const wxString
& text
)
1753 if (m_RelatedStatusBarIndex
!= -1)
1755 if (m_RelatedStatusBar
)
1757 m_RelatedStatusBar
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1759 else if (m_RelatedFrame
)
1761 m_RelatedFrame
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1766 #endif // wxUSE_STATUSBAR
1770 wxCursor
wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type
)
1774 case HTMLCursor_Link
:
1775 if ( !ms_cursorLink
)
1776 ms_cursorLink
= new wxCursor(wxCURSOR_HAND
);
1777 return *ms_cursorLink
;
1779 case HTMLCursor_Text
:
1780 if ( !ms_cursorText
)
1781 ms_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
1782 return *ms_cursorText
;
1784 case HTMLCursor_Default
:
1786 return *wxSTANDARD_CURSOR
;
1790 wxCursor
wxHtmlWindow::GetHTMLCursor(HTMLCursor type
) const
1792 return GetDefaultHTMLCursor(type
);
1796 //-----------------------------------------------------------------------------
1798 //-----------------------------------------------------------------------------
1800 // A module to allow initialization/cleanup
1801 // without calling these functions from app.cpp or from
1802 // the user's application.
1804 class wxHtmlWinModule
: public wxModule
1806 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule
)
1808 wxHtmlWinModule() : wxModule() {}
1809 bool OnInit() { return true; }
1810 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1813 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule
, wxModule
)
1816 // This hack forces the linker to always link in m_* files
1817 // (wxHTML doesn't work without handlers from these files)
1818 #include "wx/html/forcelnk.h"
1819 FORCE_WXHTML_MODULES()
1821 #endif // wxUSE_HTML