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
);
475 // notice that it's important to set m_Cell to NULL here before calling
476 // Parse() below, even if it will be overwritten by its return value:
477 // without this we may crash if it's used from inside Parse()
480 m_Cell
= (wxHtmlContainerCell
*) m_Parser
->Parse(newsrc
);
482 m_Cell
->SetIndent(m_Borders
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
483 m_Cell
->SetAlignHor(wxHTML_ALIGN_CENTER
);
485 if (m_tmpCanDrawLocks
== 0)
490 bool wxHtmlWindow::AppendToPage(const wxString
& source
)
492 return DoSetPage(*(GetParser()->GetSource()) + source
);
495 bool wxHtmlWindow::LoadPage(const wxString
& location
)
497 wxCHECK_MSG( !location
.empty(), false, "location must be non-empty" );
499 wxBusyCursor busyCursor
;
502 bool needs_refresh
= false;
505 if (m_HistoryOn
&& (m_HistoryPos
!= -1))
507 // store scroll position into history item:
509 GetViewStart(&x
, &y
);
510 (*m_History
)[m_HistoryPos
].SetPos(y
);
513 // first check if we're moving to an anchor in the same page
514 size_t posLocalAnchor
= location
.Find('#');
515 if ( posLocalAnchor
!= wxString::npos
&& posLocalAnchor
!= 0 )
517 // check if the part before the anchor is the same as the (either
518 // relative or absolute) URI of the current page
519 const wxString beforeAnchor
= location
.substr(0, posLocalAnchor
);
520 if ( beforeAnchor
!= m_OpenedPage
&&
521 m_FS
->GetPath() + beforeAnchor
!= m_OpenedPage
)
523 // indicate that we're not moving to a local anchor
524 posLocalAnchor
= wxString::npos
;
528 if ( posLocalAnchor
!= wxString::npos
)
531 rt_val
= ScrollToAnchor(location
.substr(posLocalAnchor
+ 1));
534 else // moving to another page
536 needs_refresh
= true;
539 if (m_RelatedStatusBarIndex
!= -1)
541 SetHTMLStatusText(_("Connecting..."));
544 #endif // wxUSE_STATUSBAR
546 wxFSFile
*f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location
);
548 // try to interpret 'location' as filename instead of URL:
551 wxFileName
fn(location
);
552 wxString location2
= wxFileSystem::FileNameToURL(fn
);
553 f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location2
);
558 wxLogError(_("Unable to open requested HTML document: %s"), location
.c_str());
560 SetHTMLStatusText(wxEmptyString
);
566 wxList::compatibility_iterator node
;
567 wxString src
= wxEmptyString
;
570 if (m_RelatedStatusBarIndex
!= -1)
572 wxString msg
= _("Loading : ") + location
;
573 SetHTMLStatusText(msg
);
576 #endif // wxUSE_STATUSBAR
578 node
= m_Filters
.GetFirst();
581 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
584 src
= h
->ReadFile(*f
);
587 node
= node
->GetNext();
589 if (src
== wxEmptyString
)
591 if (m_DefaultFilter
== NULL
) m_DefaultFilter
= GetDefaultFilter();
592 src
= m_DefaultFilter
->ReadFile(*f
);
595 m_FS
->ChangePathTo(f
->GetLocation());
596 rt_val
= SetPage(src
);
597 m_OpenedPage
= f
->GetLocation();
598 if (f
->GetAnchor() != wxEmptyString
)
600 ScrollToAnchor(f
->GetAnchor());
606 if (m_RelatedStatusBarIndex
!= -1)
608 SetHTMLStatusText(_("Done"));
610 #endif // wxUSE_STATUSBAR
614 if (m_HistoryOn
) // add this page to history there:
616 int c
= m_History
->GetCount() - (m_HistoryPos
+ 1);
618 if (m_HistoryPos
< 0 ||
619 (*m_History
)[m_HistoryPos
].GetPage() != m_OpenedPage
||
620 (*m_History
)[m_HistoryPos
].GetAnchor() != m_OpenedAnchor
)
623 for (int i
= 0; i
< c
; i
++)
624 m_History
->RemoveAt(m_HistoryPos
);
625 m_History
->Add(new wxHtmlHistoryItem(m_OpenedPage
, m_OpenedAnchor
));
629 if (m_OpenedPageTitle
== wxEmptyString
)
630 OnSetTitle(wxFileNameFromPath(m_OpenedPage
));
644 bool wxHtmlWindow::LoadFile(const wxFileName
& filename
)
646 wxString url
= wxFileSystem::FileNameToURL(filename
);
647 return LoadPage(url
);
651 bool wxHtmlWindow::ScrollToAnchor(const wxString
& anchor
)
653 const wxHtmlCell
*c
= m_Cell
->Find(wxHTML_COND_ISANCHOR
, &anchor
);
656 wxLogWarning(_("HTML anchor %s does not exist."), anchor
.c_str());
661 // Go to next visible cell in current container, if it exists. This
662 // yields a bit better (even though still imperfect) results in that
663 // there's better chance of using a suitable cell for upper Y
664 // coordinate value. See bug #11406 for additional discussion.
665 const wxHtmlCell
*c_save
= c
;
666 while ( c
&& c
->IsFormattingCell() )
673 for (y
= 0; c
!= NULL
; c
= c
->GetParent()) y
+= c
->GetPosY();
674 Scroll(-1, y
/ wxHTML_SCROLL_STEP
);
675 m_OpenedAnchor
= anchor
;
681 void wxHtmlWindow::OnSetTitle(const wxString
& title
)
686 tit
.Printf(m_TitleFormat
, title
.c_str());
687 m_RelatedFrame
->SetTitle(tit
);
689 m_OpenedPageTitle
= title
;
693 // return scroll steps such that a) scrollbars aren't shown needlessly
694 // and b) entire content is viewable (i.e. round up)
695 static int ScrollSteps(int size
, int available
)
697 if ( size
<= available
)
700 return (size
+ wxHTML_SCROLL_STEP
- 1) / wxHTML_SCROLL_STEP
;
704 void wxHtmlWindow::CreateLayout()
706 // SetScrollbars() results in size change events -- and thus a nested
707 // CreateLayout() call -- on some platforms. Ignore nested calls, toplevel
708 // CreateLayout() will do the right thing eventually.
709 static wxRecursionGuardFlag s_flagReentrancy
;
710 wxRecursionGuard
guard(s_flagReentrancy
);
711 if ( guard
.IsInside() )
717 int clientWidth
, clientHeight
;
718 GetClientSize(&clientWidth
, &clientHeight
);
720 const int vscrollbar
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
721 const int hscrollbar
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
723 if ( HasScrollbar(wxHORIZONTAL
) )
724 clientHeight
+= hscrollbar
;
726 if ( HasScrollbar(wxVERTICAL
) )
727 clientWidth
+= vscrollbar
;
729 if ( HasFlag(wxHW_SCROLLBAR_NEVER
) )
731 SetScrollbars(1, 1, 0, 0); // always off
732 m_Cell
->Layout(clientWidth
);
734 else // !wxHW_SCROLLBAR_NEVER
736 // Lay the content out with the assumption that it's too large to fit
737 // in the window (this is likely to be the case):
738 m_Cell
->Layout(clientWidth
- vscrollbar
);
740 // If the layout is wider than the window, horizontal scrollbar will
741 // certainly be shown. Account for it here for subsequent computations.
742 if ( m_Cell
->GetWidth() > clientWidth
)
743 clientHeight
-= hscrollbar
;
745 if ( m_Cell
->GetHeight() <= clientHeight
)
747 // we fit into the window, hide vertical scrollbar:
750 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
751 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
754 // ...and redo the layout to use the extra space
755 m_Cell
->Layout(clientWidth
);
759 // If the content doesn't fit into the window by only a small
760 // margin, chances are that it may fit fully with scrollbar turned
761 // off. It's something worth trying but on the other hand, we don't
762 // want to waste too much time redoing the layout (twice!) for
763 // long -- and thus expensive to layout -- pages. The cut-off value
764 // is an arbitrary heuristics.
765 static const int SMALL_OVERLAP
= 60;
766 if ( m_Cell
->GetHeight() <= clientHeight
+ SMALL_OVERLAP
)
768 m_Cell
->Layout(clientWidth
);
770 if ( m_Cell
->GetHeight() <= clientHeight
)
772 // Great, we fit in. Hide the scrollbar.
775 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
776 ScrollSteps(m_Cell
->GetWidth(), clientWidth
),
783 // That didn't work out, go back to previous layout. Note
784 // that redoing the layout once again here isn't as bad as
785 // it looks -- thanks to the small cut-off value, it's a
786 // reasonably small page.
787 m_Cell
->Layout(clientWidth
- vscrollbar
);
790 // else: the page is very long, it will certainly need scrollbar
794 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
795 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
796 ScrollSteps(m_Cell
->GetHeight(), clientHeight
)
803 void wxHtmlWindow::ReadCustomization(wxConfigBase
*cfg
, wxString path
)
808 wxString p_fff
, p_ffn
;
810 if (path
!= wxEmptyString
)
812 oldpath
= cfg
->GetPath();
816 m_Borders
= cfg
->Read(wxT("wxHtmlWindow/Borders"), m_Borders
);
817 p_fff
= cfg
->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
818 p_ffn
= cfg
->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
819 for (int i
= 0; i
< 7; i
++)
821 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
822 p_fontsizes
[i
] = cfg
->Read(tmp
, m_Parser
->m_FontsSizes
[i
]);
824 SetFonts(p_ffn
, p_fff
, p_fontsizes
);
826 if (path
!= wxEmptyString
)
827 cfg
->SetPath(oldpath
);
832 void wxHtmlWindow::WriteCustomization(wxConfigBase
*cfg
, wxString path
)
837 if (path
!= wxEmptyString
)
839 oldpath
= cfg
->GetPath();
843 cfg
->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders
);
844 cfg
->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
845 cfg
->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
846 for (int i
= 0; i
< 7; i
++)
848 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
849 cfg
->Write(tmp
, (long) m_Parser
->m_FontsSizes
[i
]);
852 if (path
!= wxEmptyString
)
853 cfg
->SetPath(oldpath
);
855 #endif // wxUSE_CONFIG
857 bool wxHtmlWindow::HistoryBack()
861 if (m_HistoryPos
< 1) return false;
863 // store scroll position into history item:
865 GetViewStart(&x
, &y
);
866 (*m_History
)[m_HistoryPos
].SetPos(y
);
868 // go to previous position:
871 l
= (*m_History
)[m_HistoryPos
].GetPage();
872 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
875 if (a
== wxEmptyString
) LoadPage(l
);
876 else LoadPage(l
+ wxT("#") + a
);
879 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
884 bool wxHtmlWindow::HistoryCanBack()
886 if (m_HistoryPos
< 1) return false;
891 bool wxHtmlWindow::HistoryForward()
895 if (m_HistoryPos
== -1) return false;
896 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
898 m_OpenedPage
= wxEmptyString
; // this will disable adding new entry into history in LoadPage()
901 l
= (*m_History
)[m_HistoryPos
].GetPage();
902 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
905 if (a
== wxEmptyString
) LoadPage(l
);
906 else LoadPage(l
+ wxT("#") + a
);
909 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
914 bool wxHtmlWindow::HistoryCanForward()
916 if (m_HistoryPos
== -1) return false;
917 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
922 void wxHtmlWindow::HistoryClear()
928 void wxHtmlWindow::AddProcessor(wxHtmlProcessor
*processor
)
932 m_Processors
= new wxHtmlProcessorList
;
934 wxHtmlProcessorList::compatibility_iterator node
;
936 for (node
= m_Processors
->GetFirst(); node
; node
= node
->GetNext())
938 if (processor
->GetPriority() > node
->GetData()->GetPriority())
940 m_Processors
->Insert(node
, processor
);
944 m_Processors
->Append(processor
);
947 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor
*processor
)
949 if (!m_GlobalProcessors
)
951 m_GlobalProcessors
= new wxHtmlProcessorList
;
953 wxHtmlProcessorList::compatibility_iterator node
;
955 for (node
= m_GlobalProcessors
->GetFirst(); node
; node
= node
->GetNext())
957 if (processor
->GetPriority() > node
->GetData()->GetPriority())
959 m_GlobalProcessors
->Insert(node
, processor
);
963 m_GlobalProcessors
->Append(processor
);
968 void wxHtmlWindow::AddFilter(wxHtmlFilter
*filter
)
970 m_Filters
.Append(filter
);
974 bool wxHtmlWindow::IsSelectionEnabled() const
977 return !HasFlag(wxHW_NO_SELECTION
);
985 wxString
wxHtmlWindow::DoSelectionToText(wxHtmlSelection
*sel
)
988 return wxEmptyString
;
993 wxHtmlTerminalCellsInterator
i(sel
->GetFromCell(), sel
->GetToCell());
994 const wxHtmlCell
*prev
= NULL
;
998 // When converting HTML content to plain text, the entire paragraph
999 // (container in wxHTML) goes on single line. A new paragraph (that
1000 // should go on its own line) has its own container. Therefore, the
1001 // simplest way of detecting where to insert newlines in plain text
1002 // is to check if the parent container changed -- if it did, we moved
1003 // to a new paragraph.
1004 if ( prev
&& prev
->GetParent() != i
->GetParent() )
1007 // NB: we don't need to pass the selection to ConvertToText() in the
1008 // middle of the selected text; it's only useful when only part of
1009 // a cell is selected
1010 text
<< i
->ConvertToText(sel
);
1018 wxString
wxHtmlWindow::ToText()
1022 wxHtmlSelection sel
;
1023 sel
.Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1024 return DoSelectionToText(&sel
);
1027 return wxEmptyString
;
1030 #endif // wxUSE_CLIPBOARD
1032 bool wxHtmlWindow::CopySelection(ClipboardType t
)
1037 #if defined(__UNIX__) && !defined(__WXMAC__)
1038 wxTheClipboard
->UsePrimarySelection(t
== Primary
);
1040 // Primary selection exists only under X11, so don't do anything under
1041 // the other platforms when we try to access it
1043 // TODO: this should be abstracted at wxClipboard level!
1046 #endif // __UNIX__/!__UNIX__
1048 if ( wxTheClipboard
->Open() )
1050 const wxString
txt(SelectionToText());
1051 wxTheClipboard
->SetData(new wxTextDataObject(txt
));
1052 wxTheClipboard
->Close();
1053 wxLogTrace(wxT("wxhtmlselection"),
1054 _("Copied to clipboard:\"%s\""), txt
.c_str());
1061 #endif // wxUSE_CLIPBOARD
1067 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo
& link
)
1069 wxHtmlLinkEvent
event(GetId(), link
);
1070 event
.SetEventObject(this);
1071 if (!GetEventHandler()->ProcessEvent(event
))
1073 // the default behaviour is to load the URL in this window
1074 const wxMouseEvent
*e
= event
.GetLinkInfo().GetEvent();
1075 if (e
== NULL
|| e
->LeftUp())
1076 LoadPage(event
.GetLinkInfo().GetHref());
1080 void wxHtmlWindow::DoEraseBackground(wxDC
& dc
)
1082 // if we don't have any background bitmap we just fill it with background
1083 // colour and we also must do it if the background bitmap is not fully
1084 // opaque as otherwise junk could be left there
1085 if ( !m_bmpBg
.IsOk() || m_bmpBg
.GetMask() )
1087 dc
.SetBackground(GetBackgroundColour());
1091 if ( m_bmpBg
.IsOk() )
1093 // draw the background bitmap tiling it over the entire window area
1094 const wxSize sz
= GetClientSize();
1095 const wxSize
sizeBmp(m_bmpBg
.GetWidth(), m_bmpBg
.GetHeight());
1096 for ( wxCoord x
= 0; x
< sz
.x
; x
+= sizeBmp
.x
)
1098 for ( wxCoord y
= 0; y
< sz
.y
; y
+= sizeBmp
.y
)
1100 dc
.DrawBitmap(m_bmpBg
, x
, y
, true /* use mask */);
1106 void wxHtmlWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
1108 wxPaintDC
dcPaint(this);
1110 if (m_tmpCanDrawLocks
> 0 || m_Cell
== NULL
)
1114 GetViewStart(&x
, &y
);
1115 const wxRect rect
= GetUpdateRegion().GetBox();
1116 const wxSize sz
= GetClientSize();
1118 // set up the DC we're drawing on: if the window is already double buffered
1119 // we do it directly on wxPaintDC, otherwise we allocate a backing store
1120 // buffer and compose the drawing there and then blit it to screen all at
1124 if ( IsDoubleBuffered() )
1128 else // window is not double buffered by the system, do it ourselves
1130 if ( !m_backBuffer
.IsOk() )
1131 m_backBuffer
.Create(sz
.x
, sz
.y
);
1132 dcm
.SelectObject(m_backBuffer
);
1138 // erase the background: for compatibility, we must generate the event to
1139 // allow the user-defined handlers to do it
1140 wxEraseEvent
eraseEvent(GetId(), dc
);
1141 eraseEvent
.SetEventObject(this);
1142 if ( !ProcessWindowEvent(eraseEvent
) )
1144 // erase background ourselves
1145 DoEraseBackground(*dc
);
1147 //else: background erased by the user-defined handler
1150 // draw the HTML window contents
1151 dc
->SetMapMode(wxMM_TEXT
);
1152 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1154 wxHtmlRenderingInfo rinfo
;
1155 wxDefaultHtmlRenderingStyle rstyle
;
1156 rinfo
.SetSelection(m_selection
);
1157 rinfo
.SetStyle(&rstyle
);
1158 m_Cell
->Draw(*dc
, 0, 0,
1159 y
* wxHTML_SCROLL_STEP
+ rect
.GetTop(),
1160 y
* wxHTML_SCROLL_STEP
+ rect
.GetBottom(),
1163 #ifdef DEBUG_HTML_SELECTION
1166 wxGetMousePosition(&xc
, &yc
);
1167 ScreenToClient(&xc
, &yc
);
1168 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1169 wxHtmlCell
*at
= m_Cell
->FindCellByPos(x
, y
);
1170 wxHtmlCell
*before
=
1171 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_BEFORE
);
1173 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_AFTER
);
1175 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1176 dc
->SetPen(*wxBLACK_PEN
);
1178 dc
->DrawRectangle(at
->GetAbsPos(),
1179 wxSize(at
->GetWidth(),at
->GetHeight()));
1180 dc
->SetPen(*wxGREEN_PEN
);
1182 dc
->DrawRectangle(before
->GetAbsPos().x
+1, before
->GetAbsPos().y
+1,
1183 before
->GetWidth()-2,before
->GetHeight()-2);
1184 dc
->SetPen(*wxRED_PEN
);
1186 dc
->DrawRectangle(after
->GetAbsPos().x
+2, after
->GetAbsPos().y
+2,
1187 after
->GetWidth()-4,after
->GetHeight()-4);
1189 #endif // DEBUG_HTML_SELECTION
1191 if ( dc
!= &dcPaint
)
1193 dc
->SetDeviceOrigin(0,0);
1194 dcPaint
.Blit(0, rect
.GetTop(),
1195 sz
.x
, rect
.GetBottom() - rect
.GetTop() + 1,
1204 void wxHtmlWindow::OnSize(wxSizeEvent
& event
)
1208 m_backBuffer
= wxNullBitmap
;
1212 // Recompute selection if necessary:
1215 m_selection
->Set(m_selection
->GetFromCell(),
1216 m_selection
->GetToCell());
1217 m_selection
->ClearPrivPos();
1224 void wxHtmlWindow::OnMouseMove(wxMouseEvent
& WXUNUSED(event
))
1226 wxHtmlWindowMouseHelper::HandleMouseMoved();
1229 void wxHtmlWindow::OnMouseDown(wxMouseEvent
& event
)
1232 if ( event
.LeftDown() && IsSelectionEnabled() )
1234 const long TRIPLECLICK_LEN
= 200; // 0.2 sec after doubleclick
1235 if ( wxGetLocalTimeMillis() - m_lastDoubleClick
<= TRIPLECLICK_LEN
)
1237 SelectLine(CalcUnscrolledPosition(event
.GetPosition()));
1239 (void) CopySelection();
1243 m_makingSelection
= true;
1247 wxDELETE(m_selection
);
1250 m_tmpSelFromPos
= CalcUnscrolledPosition(event
.GetPosition());
1251 m_tmpSelFromCell
= NULL
;
1256 #endif // wxUSE_CLIPBOARD
1258 // in any case, let the default handler set focus to this window
1262 void wxHtmlWindow::OnMouseUp(wxMouseEvent
& event
)
1265 if ( m_makingSelection
)
1268 m_makingSelection
= false;
1270 // if m_selection=NULL, the user didn't move the mouse far enough from
1271 // starting point and the mouse up event is part of a click, the user
1272 // is not selecting text:
1275 CopySelection(Primary
);
1277 // we don't want mouse up event that ended selecting to be
1278 // handled as mouse click and e.g. follow hyperlink:
1282 #endif // wxUSE_CLIPBOARD
1284 wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
1285 wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell
, pos
, event
);
1289 void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1291 if ( !m_makingSelection
)
1294 // discard the selecting operation
1295 m_makingSelection
= false;
1296 wxDELETE(m_selection
);
1297 m_tmpSelFromCell
= NULL
;
1300 #endif // wxUSE_CLIPBOARD
1303 void wxHtmlWindow::OnInternalIdle()
1305 wxWindow::OnInternalIdle();
1307 if (m_Cell
!= NULL
&& DidMouseMove())
1309 #ifdef DEBUG_HTML_SELECTION
1313 wxGetMousePosition(&xc
, &yc
);
1314 ScreenToClient(&xc
, &yc
);
1315 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1317 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(x
, y
);
1319 // handle selection update:
1320 if ( m_makingSelection
)
1322 if ( !m_tmpSelFromCell
)
1323 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1324 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
);
1326 // NB: a trick - we adjust selFromPos to be upper left or bottom
1327 // right corner of the first cell of the selection depending
1328 // on whether the mouse is moving to the right or to the left.
1329 // This gives us more "natural" behaviour when selecting
1330 // a line (specifically, first cell of the next line is not
1331 // included if you drag selection from left to right over
1334 if ( !m_tmpSelFromCell
)
1336 dirFromPos
= m_tmpSelFromPos
;
1340 dirFromPos
= m_tmpSelFromCell
->GetAbsPos();
1341 if ( x
< m_tmpSelFromPos
.x
)
1343 dirFromPos
.x
+= m_tmpSelFromCell
->GetWidth();
1344 dirFromPos
.y
+= m_tmpSelFromCell
->GetHeight();
1347 bool goingDown
= dirFromPos
.y
< y
||
1348 (dirFromPos
.y
== y
&& dirFromPos
.x
< x
);
1350 // determine selection span:
1351 if ( /*still*/ !m_tmpSelFromCell
)
1355 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1356 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1357 wxHTML_FIND_NEAREST_AFTER
);
1358 if (!m_tmpSelFromCell
)
1359 m_tmpSelFromCell
= m_Cell
->GetFirstTerminal();
1363 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1364 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1365 wxHTML_FIND_NEAREST_BEFORE
);
1366 if (!m_tmpSelFromCell
)
1367 m_tmpSelFromCell
= m_Cell
->GetLastTerminal();
1371 wxHtmlCell
*selcell
= cell
;
1376 selcell
= m_Cell
->FindCellByPos(x
, y
,
1377 wxHTML_FIND_NEAREST_BEFORE
);
1379 selcell
= m_Cell
->GetLastTerminal();
1383 selcell
= m_Cell
->FindCellByPos(x
, y
,
1384 wxHTML_FIND_NEAREST_AFTER
);
1386 selcell
= m_Cell
->GetFirstTerminal();
1390 // NB: it may *rarely* happen that the code above didn't find one
1391 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1393 if ( selcell
&& m_tmpSelFromCell
)
1397 // start selecting only if mouse movement was big enough
1398 // (otherwise it was meant as mouse click, not selection):
1399 const int PRECISION
= 2;
1400 wxPoint diff
= m_tmpSelFromPos
- wxPoint(x
,y
);
1401 if (abs(diff
.x
) > PRECISION
|| abs(diff
.y
) > PRECISION
)
1403 m_selection
= new wxHtmlSelection();
1408 if ( m_tmpSelFromCell
->IsBefore(selcell
) )
1410 m_selection
->Set(m_tmpSelFromPos
, m_tmpSelFromCell
,
1411 wxPoint(x
,y
), selcell
);
1415 m_selection
->Set(wxPoint(x
,y
), selcell
,
1416 m_tmpSelFromPos
, m_tmpSelFromCell
);
1418 m_selection
->ClearPrivPos();
1424 // handle cursor and status bar text changes:
1426 // NB: because we're passing in 'cell' and not 'm_Cell' (so that the
1427 // leaf cell lookup isn't done twice), we need to adjust the
1428 // position for the new root:
1429 wxPoint
posInCell(x
, y
);
1431 posInCell
-= cell
->GetAbsPos();
1432 wxHtmlWindowMouseHelper::HandleIdle(cell
, posInCell
);
1437 void wxHtmlWindow::StopAutoScrolling()
1439 if ( m_timerAutoScroll
)
1441 wxDELETE(m_timerAutoScroll
);
1445 void wxHtmlWindow::OnMouseEnter(wxMouseEvent
& event
)
1447 StopAutoScrolling();
1451 void wxHtmlWindow::OnMouseLeave(wxMouseEvent
& event
)
1453 // don't prevent the usual processing of the event from taking place
1456 // when a captured mouse leave a scrolled window we start generate
1457 // scrolling events to allow, for example, extending selection beyond the
1458 // visible area in some controls
1459 if ( wxWindow::GetCapture() == this )
1461 // where is the mouse leaving?
1463 wxPoint pt
= event
.GetPosition();
1466 orient
= wxHORIZONTAL
;
1469 else if ( pt
.y
< 0 )
1471 orient
= wxVERTICAL
;
1474 else // we're lower or to the right of the window
1476 wxSize size
= GetClientSize();
1477 if ( pt
.x
> size
.x
)
1479 orient
= wxHORIZONTAL
;
1480 pos
= GetVirtualSize().x
/ wxHTML_SCROLL_STEP
;
1482 else if ( pt
.y
> size
.y
)
1484 orient
= wxVERTICAL
;
1485 pos
= GetVirtualSize().y
/ wxHTML_SCROLL_STEP
;
1487 else // this should be impossible
1489 // but seems to happen sometimes under wxMSW - maybe it's a bug
1490 // there but for now just ignore it
1492 //wxFAIL_MSG( wxT("can't understand where has mouse gone") );
1498 // only start the auto scroll timer if the window can be scrolled in
1500 if ( !HasScrollbar(orient
) )
1503 delete m_timerAutoScroll
;
1504 m_timerAutoScroll
= new wxHtmlWinAutoScrollTimer
1507 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
1508 : wxEVT_SCROLLWIN_LINEDOWN
,
1512 m_timerAutoScroll
->Start(50); // FIXME: make configurable
1516 void wxHtmlWindow::OnKeyUp(wxKeyEvent
& event
)
1518 if ( IsSelectionEnabled() &&
1519 (event
.GetKeyCode() == 'C' && event
.CmdDown()) )
1521 wxClipboardTextEvent
evt(wxEVT_COMMAND_TEXT_COPY
, GetId());
1523 evt
.SetEventObject(this);
1525 GetEventHandler()->ProcessEvent(evt
);
1529 void wxHtmlWindow::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1531 (void) CopySelection();
1534 void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent
& WXUNUSED(event
))
1536 (void) CopySelection();
1539 void wxHtmlWindow::OnDoubleClick(wxMouseEvent
& event
)
1541 // select word under cursor:
1542 if ( IsSelectionEnabled() )
1544 SelectWord(CalcUnscrolledPosition(event
.GetPosition()));
1546 (void) CopySelection(Primary
);
1548 m_lastDoubleClick
= wxGetLocalTimeMillis();
1554 void wxHtmlWindow::SelectWord(const wxPoint
& pos
)
1558 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1562 m_selection
= new wxHtmlSelection();
1563 m_selection
->Set(cell
, cell
);
1564 RefreshRect(wxRect(CalcScrolledPosition(cell
->GetAbsPos()),
1565 wxSize(cell
->GetWidth(), cell
->GetHeight())));
1570 void wxHtmlWindow::SelectLine(const wxPoint
& pos
)
1574 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1577 // We use following heuristic to find a "line": let the line be all
1578 // cells in same container as the cell under mouse cursor that are
1579 // neither completely above nor completely bellow the clicked cell
1580 // (i.e. are likely to be words positioned on same line of text).
1582 int y1
= cell
->GetAbsPos().y
;
1583 int y2
= y1
+ cell
->GetHeight();
1585 const wxHtmlCell
*c
;
1586 const wxHtmlCell
*before
= NULL
;
1587 const wxHtmlCell
*after
= NULL
;
1589 // find last cell of line:
1590 for ( c
= cell
->GetNext(); c
; c
= c
->GetNext())
1592 y
= c
->GetAbsPos().y
;
1593 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1601 // find first cell of line:
1602 for ( c
= cell
->GetParent()->GetFirstChild();
1603 c
&& c
!= cell
; c
= c
->GetNext())
1605 y
= c
->GetAbsPos().y
;
1606 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1618 m_selection
= new wxHtmlSelection();
1619 m_selection
->Set(before
, after
);
1626 void wxHtmlWindow::SelectAll()
1631 m_selection
= new wxHtmlSelection();
1632 m_selection
->Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1637 #endif // wxUSE_CLIPBOARD
1641 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor
,wxObject
)
1643 #if wxUSE_EXTENDED_RTTI
1644 IMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow
, wxScrolledWindow
,"wx/html/htmlwin.h")
1646 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow
)
1649 style , wxHW_SCROLLBAR_AUTO
1650 borders , (dimension)
1654 wxEND_PROPERTIES_TABLE()
1656 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow
)
1657 wxEND_HANDLERS_TABLE()
1659 wxCONSTRUCTOR_5( wxHtmlWindow
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1661 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow
,wxScrolledWindow
)
1664 BEGIN_EVENT_TABLE(wxHtmlWindow
, wxScrolledWindow
)
1665 EVT_SIZE(wxHtmlWindow::OnSize
)
1666 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown
)
1667 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp
)
1668 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp
)
1669 EVT_MOTION(wxHtmlWindow::OnMouseMove
)
1670 EVT_PAINT(wxHtmlWindow::OnPaint
)
1672 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick
)
1673 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter
)
1674 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave
)
1675 EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost
)
1676 EVT_KEY_UP(wxHtmlWindow::OnKeyUp
)
1677 EVT_MENU(wxID_COPY
, wxHtmlWindow::OnCopy
)
1678 EVT_TEXT_COPY(wxID_ANY
, wxHtmlWindow::OnClipboardEvent
)
1679 #endif // wxUSE_CLIPBOARD
1682 //-----------------------------------------------------------------------------
1683 // wxHtmlWindowInterface implementation in wxHtmlWindow
1684 //-----------------------------------------------------------------------------
1686 void wxHtmlWindow::SetHTMLWindowTitle(const wxString
& title
)
1691 void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
)
1693 OnLinkClicked(link
);
1696 wxHtmlOpeningStatus
wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type
,
1697 const wxString
& url
,
1698 wxString
*redirect
) const
1700 return OnOpeningURL(type
, url
, redirect
);
1703 wxPoint
wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell
*WXUNUSED(cell
),
1704 const wxPoint
& pos
) const
1706 return CalcScrolledPosition(pos
);
1709 wxWindow
* wxHtmlWindow::GetHTMLWindow()
1714 wxColour
wxHtmlWindow::GetHTMLBackgroundColour() const
1716 return GetBackgroundColour();
1719 void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour
& clr
)
1721 SetBackgroundColour(clr
);
1724 void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap
& bmpBg
)
1726 SetBackgroundImage(bmpBg
);
1729 void wxHtmlWindow::SetHTMLStatusText(const wxString
& text
)
1732 if (m_RelatedStatusBarIndex
!= -1)
1734 if (m_RelatedStatusBar
)
1736 m_RelatedStatusBar
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1738 else if (m_RelatedFrame
)
1740 m_RelatedFrame
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1745 #endif // wxUSE_STATUSBAR
1749 wxCursor
wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type
)
1753 case HTMLCursor_Link
:
1754 if ( !ms_cursorLink
)
1755 ms_cursorLink
= new wxCursor(wxCURSOR_HAND
);
1756 return *ms_cursorLink
;
1758 case HTMLCursor_Text
:
1759 if ( !ms_cursorText
)
1760 ms_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
1761 return *ms_cursorText
;
1763 case HTMLCursor_Default
:
1765 return *wxSTANDARD_CURSOR
;
1769 wxCursor
wxHtmlWindow::GetHTMLCursor(HTMLCursor type
) const
1771 return GetDefaultHTMLCursor(type
);
1775 //-----------------------------------------------------------------------------
1777 //-----------------------------------------------------------------------------
1779 // A module to allow initialization/cleanup
1780 // without calling these functions from app.cpp or from
1781 // the user's application.
1783 class wxHtmlWinModule
: public wxModule
1785 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule
)
1787 wxHtmlWinModule() : wxModule() {}
1788 bool OnInit() { return true; }
1789 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1792 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule
, wxModule
)
1795 // This hack forces the linker to always link in m_* files
1796 // (wxHTML doesn't work without handlers from these files)
1797 #include "wx/html/forcelnk.h"
1798 FORCE_WXHTML_MODULES()
1800 #endif // wxUSE_HTML