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
)
804 void wxHtmlWindow::ReadCustomization(wxConfigBase
*cfg
, wxString path
)
809 wxString p_fff
, p_ffn
;
811 if (path
!= wxEmptyString
)
813 oldpath
= cfg
->GetPath();
817 m_Borders
= cfg
->Read(wxT("wxHtmlWindow/Borders"), m_Borders
);
818 p_fff
= cfg
->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
819 p_ffn
= cfg
->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
820 for (int i
= 0; i
< 7; i
++)
822 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
823 p_fontsizes
[i
] = cfg
->Read(tmp
, m_Parser
->m_FontsSizes
[i
]);
825 SetFonts(p_ffn
, p_fff
, p_fontsizes
);
827 if (path
!= wxEmptyString
)
828 cfg
->SetPath(oldpath
);
833 void wxHtmlWindow::WriteCustomization(wxConfigBase
*cfg
, wxString path
)
838 if (path
!= wxEmptyString
)
840 oldpath
= cfg
->GetPath();
844 cfg
->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders
);
845 cfg
->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
846 cfg
->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
847 for (int i
= 0; i
< 7; i
++)
849 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
850 cfg
->Write(tmp
, (long) m_Parser
->m_FontsSizes
[i
]);
853 if (path
!= wxEmptyString
)
854 cfg
->SetPath(oldpath
);
859 bool wxHtmlWindow::HistoryBack()
863 if (m_HistoryPos
< 1) return false;
865 // store scroll position into history item:
867 GetViewStart(&x
, &y
);
868 (*m_History
)[m_HistoryPos
].SetPos(y
);
870 // go to previous position:
873 l
= (*m_History
)[m_HistoryPos
].GetPage();
874 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
877 if (a
== wxEmptyString
) LoadPage(l
);
878 else LoadPage(l
+ wxT("#") + a
);
881 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
886 bool wxHtmlWindow::HistoryCanBack()
888 if (m_HistoryPos
< 1) return false;
893 bool wxHtmlWindow::HistoryForward()
897 if (m_HistoryPos
== -1) return false;
898 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
900 m_OpenedPage
= wxEmptyString
; // this will disable adding new entry into history in LoadPage()
903 l
= (*m_History
)[m_HistoryPos
].GetPage();
904 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
907 if (a
== wxEmptyString
) LoadPage(l
);
908 else LoadPage(l
+ wxT("#") + a
);
911 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
916 bool wxHtmlWindow::HistoryCanForward()
918 if (m_HistoryPos
== -1) return false;
919 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
924 void wxHtmlWindow::HistoryClear()
930 void wxHtmlWindow::AddProcessor(wxHtmlProcessor
*processor
)
934 m_Processors
= new wxHtmlProcessorList
;
936 wxHtmlProcessorList::compatibility_iterator node
;
938 for (node
= m_Processors
->GetFirst(); node
; node
= node
->GetNext())
940 if (processor
->GetPriority() > node
->GetData()->GetPriority())
942 m_Processors
->Insert(node
, processor
);
946 m_Processors
->Append(processor
);
949 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor
*processor
)
951 if (!m_GlobalProcessors
)
953 m_GlobalProcessors
= new wxHtmlProcessorList
;
955 wxHtmlProcessorList::compatibility_iterator node
;
957 for (node
= m_GlobalProcessors
->GetFirst(); node
; node
= node
->GetNext())
959 if (processor
->GetPriority() > node
->GetData()->GetPriority())
961 m_GlobalProcessors
->Insert(node
, processor
);
965 m_GlobalProcessors
->Append(processor
);
970 void wxHtmlWindow::AddFilter(wxHtmlFilter
*filter
)
972 m_Filters
.Append(filter
);
976 bool wxHtmlWindow::IsSelectionEnabled() const
979 return !HasFlag(wxHW_NO_SELECTION
);
987 wxString
wxHtmlWindow::DoSelectionToText(wxHtmlSelection
*sel
)
990 return wxEmptyString
;
995 wxHtmlTerminalCellsInterator
i(sel
->GetFromCell(), sel
->GetToCell());
996 const wxHtmlCell
*prev
= NULL
;
1000 // When converting HTML content to plain text, the entire paragraph
1001 // (container in wxHTML) goes on single line. A new paragraph (that
1002 // should go on its own line) has its own container. Therefore, the
1003 // simplest way of detecting where to insert newlines in plain text
1004 // is to check if the parent container changed -- if it did, we moved
1005 // to a new paragraph.
1006 if ( prev
&& prev
->GetParent() != i
->GetParent() )
1009 // NB: we don't need to pass the selection to ConvertToText() in the
1010 // middle of the selected text; it's only useful when only part of
1011 // a cell is selected
1012 text
<< i
->ConvertToText(sel
);
1020 wxString
wxHtmlWindow::ToText()
1024 wxHtmlSelection sel
;
1025 sel
.Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1026 return DoSelectionToText(&sel
);
1029 return wxEmptyString
;
1032 #endif // wxUSE_CLIPBOARD
1034 bool wxHtmlWindow::CopySelection(ClipboardType t
)
1039 #if defined(__UNIX__) && !defined(__WXMAC__)
1040 wxTheClipboard
->UsePrimarySelection(t
== Primary
);
1042 // Primary selection exists only under X11, so don't do anything under
1043 // the other platforms when we try to access it
1045 // TODO: this should be abstracted at wxClipboard level!
1048 #endif // __UNIX__/!__UNIX__
1050 if ( wxTheClipboard
->Open() )
1052 const wxString
txt(SelectionToText());
1053 wxTheClipboard
->SetData(new wxTextDataObject(txt
));
1054 wxTheClipboard
->Close();
1055 wxLogTrace(wxT("wxhtmlselection"),
1056 _("Copied to clipboard:\"%s\""), txt
.c_str());
1063 #endif // wxUSE_CLIPBOARD
1069 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo
& link
)
1071 wxHtmlLinkEvent
event(GetId(), link
);
1072 event
.SetEventObject(this);
1073 if (!GetEventHandler()->ProcessEvent(event
))
1075 // the default behaviour is to load the URL in this window
1076 const wxMouseEvent
*e
= event
.GetLinkInfo().GetEvent();
1077 if (e
== NULL
|| e
->LeftUp())
1078 LoadPage(event
.GetLinkInfo().GetHref());
1082 void wxHtmlWindow::DoEraseBackground(wxDC
& dc
)
1084 // if we don't have any background bitmap we just fill it with background
1085 // colour and we also must do it if the background bitmap is not fully
1086 // opaque as otherwise junk could be left there
1087 if ( !m_bmpBg
.IsOk() || m_bmpBg
.GetMask() )
1089 dc
.SetBackground(GetBackgroundColour());
1093 if ( m_bmpBg
.IsOk() )
1095 // draw the background bitmap tiling it over the entire window area
1096 const wxSize sz
= GetClientSize();
1097 const wxSize
sizeBmp(m_bmpBg
.GetWidth(), m_bmpBg
.GetHeight());
1098 for ( wxCoord x
= 0; x
< sz
.x
; x
+= sizeBmp
.x
)
1100 for ( wxCoord y
= 0; y
< sz
.y
; y
+= sizeBmp
.y
)
1102 dc
.DrawBitmap(m_bmpBg
, x
, y
, true /* use mask */);
1108 void wxHtmlWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
1110 wxPaintDC
dcPaint(this);
1112 if (m_tmpCanDrawLocks
> 0 || m_Cell
== NULL
)
1116 GetViewStart(&x
, &y
);
1117 const wxRect rect
= GetUpdateRegion().GetBox();
1118 const wxSize sz
= GetClientSize();
1120 // set up the DC we're drawing on: if the window is already double buffered
1121 // we do it directly on wxPaintDC, otherwise we allocate a backing store
1122 // buffer and compose the drawing there and then blit it to screen all at
1126 if ( IsDoubleBuffered() )
1130 else // window is not double buffered by the system, do it ourselves
1132 if ( !m_backBuffer
.IsOk() )
1133 m_backBuffer
.Create(sz
.x
, sz
.y
);
1134 dcm
.SelectObject(m_backBuffer
);
1140 // erase the background: for compatibility, we must generate the event to
1141 // allow the user-defined handlers to do it
1142 wxEraseEvent
eraseEvent(GetId(), dc
);
1143 eraseEvent
.SetEventObject(this);
1144 if ( !ProcessWindowEvent(eraseEvent
) )
1146 // erase background ourselves
1147 DoEraseBackground(*dc
);
1149 //else: background erased by the user-defined handler
1152 // draw the HTML window contents
1153 dc
->SetMapMode(wxMM_TEXT
);
1154 dc
->SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT
);
1156 wxHtmlRenderingInfo rinfo
;
1157 wxDefaultHtmlRenderingStyle rstyle
;
1158 rinfo
.SetSelection(m_selection
);
1159 rinfo
.SetStyle(&rstyle
);
1160 m_Cell
->Draw(*dc
, 0, 0,
1161 y
* wxHTML_SCROLL_STEP
+ rect
.GetTop(),
1162 y
* wxHTML_SCROLL_STEP
+ rect
.GetBottom(),
1165 #ifdef DEBUG_HTML_SELECTION
1168 wxGetMousePosition(&xc
, &yc
);
1169 ScreenToClient(&xc
, &yc
);
1170 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1171 wxHtmlCell
*at
= m_Cell
->FindCellByPos(x
, y
);
1172 wxHtmlCell
*before
=
1173 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_BEFORE
);
1175 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_AFTER
);
1177 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1178 dc
->SetPen(*wxBLACK_PEN
);
1180 dc
->DrawRectangle(at
->GetAbsPos(),
1181 wxSize(at
->GetWidth(),at
->GetHeight()));
1182 dc
->SetPen(*wxGREEN_PEN
);
1184 dc
->DrawRectangle(before
->GetAbsPos().x
+1, before
->GetAbsPos().y
+1,
1185 before
->GetWidth()-2,before
->GetHeight()-2);
1186 dc
->SetPen(*wxRED_PEN
);
1188 dc
->DrawRectangle(after
->GetAbsPos().x
+2, after
->GetAbsPos().y
+2,
1189 after
->GetWidth()-4,after
->GetHeight()-4);
1191 #endif // DEBUG_HTML_SELECTION
1193 if ( dc
!= &dcPaint
)
1195 dc
->SetDeviceOrigin(0,0);
1196 dcPaint
.Blit(0, rect
.GetTop(),
1197 sz
.x
, rect
.GetBottom() - rect
.GetTop() + 1,
1206 void wxHtmlWindow::OnSize(wxSizeEvent
& event
)
1210 m_backBuffer
= wxNullBitmap
;
1214 // Recompute selection if necessary:
1217 m_selection
->Set(m_selection
->GetFromCell(),
1218 m_selection
->GetToCell());
1219 m_selection
->ClearPrivPos();
1226 void wxHtmlWindow::OnMouseMove(wxMouseEvent
& WXUNUSED(event
))
1228 wxHtmlWindowMouseHelper::HandleMouseMoved();
1231 void wxHtmlWindow::OnMouseDown(wxMouseEvent
& event
)
1234 if ( event
.LeftDown() && IsSelectionEnabled() )
1236 const long TRIPLECLICK_LEN
= 200; // 0.2 sec after doubleclick
1237 if ( wxGetLocalTimeMillis() - m_lastDoubleClick
<= TRIPLECLICK_LEN
)
1239 SelectLine(CalcUnscrolledPosition(event
.GetPosition()));
1241 (void) CopySelection();
1245 m_makingSelection
= true;
1249 wxDELETE(m_selection
);
1252 m_tmpSelFromPos
= CalcUnscrolledPosition(event
.GetPosition());
1253 m_tmpSelFromCell
= NULL
;
1258 #endif // wxUSE_CLIPBOARD
1260 // in any case, let the default handler set focus to this window
1264 void wxHtmlWindow::OnMouseUp(wxMouseEvent
& event
)
1267 if ( m_makingSelection
)
1270 m_makingSelection
= false;
1272 // if m_selection=NULL, the user didn't move the mouse far enough from
1273 // starting point and the mouse up event is part of a click, the user
1274 // is not selecting text:
1277 CopySelection(Primary
);
1279 // we don't want mouse up event that ended selecting to be
1280 // handled as mouse click and e.g. follow hyperlink:
1284 #endif // wxUSE_CLIPBOARD
1286 wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
1287 wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell
, pos
, event
);
1291 void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1293 if ( !m_makingSelection
)
1296 // discard the selecting operation
1297 m_makingSelection
= false;
1298 wxDELETE(m_selection
);
1299 m_tmpSelFromCell
= NULL
;
1302 #endif // wxUSE_CLIPBOARD
1305 void wxHtmlWindow::OnInternalIdle()
1307 wxWindow::OnInternalIdle();
1309 if (m_Cell
!= NULL
&& DidMouseMove())
1311 #ifdef DEBUG_HTML_SELECTION
1315 wxGetMousePosition(&xc
, &yc
);
1316 ScreenToClient(&xc
, &yc
);
1317 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1319 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(x
, y
);
1321 // handle selection update:
1322 if ( m_makingSelection
)
1324 if ( !m_tmpSelFromCell
)
1325 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1326 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
);
1328 // NB: a trick - we adjust selFromPos to be upper left or bottom
1329 // right corner of the first cell of the selection depending
1330 // on whether the mouse is moving to the right or to the left.
1331 // This gives us more "natural" behaviour when selecting
1332 // a line (specifically, first cell of the next line is not
1333 // included if you drag selection from left to right over
1336 if ( !m_tmpSelFromCell
)
1338 dirFromPos
= m_tmpSelFromPos
;
1342 dirFromPos
= m_tmpSelFromCell
->GetAbsPos();
1343 if ( x
< m_tmpSelFromPos
.x
)
1345 dirFromPos
.x
+= m_tmpSelFromCell
->GetWidth();
1346 dirFromPos
.y
+= m_tmpSelFromCell
->GetHeight();
1349 bool goingDown
= dirFromPos
.y
< y
||
1350 (dirFromPos
.y
== y
&& dirFromPos
.x
< x
);
1352 // determine selection span:
1353 if ( /*still*/ !m_tmpSelFromCell
)
1357 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1358 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1359 wxHTML_FIND_NEAREST_AFTER
);
1360 if (!m_tmpSelFromCell
)
1361 m_tmpSelFromCell
= m_Cell
->GetFirstTerminal();
1365 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1366 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1367 wxHTML_FIND_NEAREST_BEFORE
);
1368 if (!m_tmpSelFromCell
)
1369 m_tmpSelFromCell
= m_Cell
->GetLastTerminal();
1373 wxHtmlCell
*selcell
= cell
;
1378 selcell
= m_Cell
->FindCellByPos(x
, y
,
1379 wxHTML_FIND_NEAREST_BEFORE
);
1381 selcell
= m_Cell
->GetLastTerminal();
1385 selcell
= m_Cell
->FindCellByPos(x
, y
,
1386 wxHTML_FIND_NEAREST_AFTER
);
1388 selcell
= m_Cell
->GetFirstTerminal();
1392 // NB: it may *rarely* happen that the code above didn't find one
1393 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1395 if ( selcell
&& m_tmpSelFromCell
)
1399 // start selecting only if mouse movement was big enough
1400 // (otherwise it was meant as mouse click, not selection):
1401 const int PRECISION
= 2;
1402 wxPoint diff
= m_tmpSelFromPos
- wxPoint(x
,y
);
1403 if (abs(diff
.x
) > PRECISION
|| abs(diff
.y
) > PRECISION
)
1405 m_selection
= new wxHtmlSelection();
1410 if ( m_tmpSelFromCell
->IsBefore(selcell
) )
1412 m_selection
->Set(m_tmpSelFromPos
, m_tmpSelFromCell
,
1413 wxPoint(x
,y
), selcell
);
1417 m_selection
->Set(wxPoint(x
,y
), selcell
,
1418 m_tmpSelFromPos
, m_tmpSelFromCell
);
1420 m_selection
->ClearPrivPos();
1426 // handle cursor and status bar text changes:
1428 // NB: because we're passing in 'cell' and not 'm_Cell' (so that the
1429 // leaf cell lookup isn't done twice), we need to adjust the
1430 // position for the new root:
1431 wxPoint
posInCell(x
, y
);
1433 posInCell
-= cell
->GetAbsPos();
1434 wxHtmlWindowMouseHelper::HandleIdle(cell
, posInCell
);
1439 void wxHtmlWindow::StopAutoScrolling()
1441 if ( m_timerAutoScroll
)
1443 wxDELETE(m_timerAutoScroll
);
1447 void wxHtmlWindow::OnMouseEnter(wxMouseEvent
& event
)
1449 StopAutoScrolling();
1453 void wxHtmlWindow::OnMouseLeave(wxMouseEvent
& event
)
1455 // don't prevent the usual processing of the event from taking place
1458 // when a captured mouse leave a scrolled window we start generate
1459 // scrolling events to allow, for example, extending selection beyond the
1460 // visible area in some controls
1461 if ( wxWindow::GetCapture() == this )
1463 // where is the mouse leaving?
1465 wxPoint pt
= event
.GetPosition();
1468 orient
= wxHORIZONTAL
;
1471 else if ( pt
.y
< 0 )
1473 orient
= wxVERTICAL
;
1476 else // we're lower or to the right of the window
1478 wxSize size
= GetClientSize();
1479 if ( pt
.x
> size
.x
)
1481 orient
= wxHORIZONTAL
;
1482 pos
= GetVirtualSize().x
/ wxHTML_SCROLL_STEP
;
1484 else if ( pt
.y
> size
.y
)
1486 orient
= wxVERTICAL
;
1487 pos
= GetVirtualSize().y
/ wxHTML_SCROLL_STEP
;
1489 else // this should be impossible
1491 // but seems to happen sometimes under wxMSW - maybe it's a bug
1492 // there but for now just ignore it
1494 //wxFAIL_MSG( wxT("can't understand where has mouse gone") );
1500 // only start the auto scroll timer if the window can be scrolled in
1502 if ( !HasScrollbar(orient
) )
1505 delete m_timerAutoScroll
;
1506 m_timerAutoScroll
= new wxHtmlWinAutoScrollTimer
1509 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
1510 : wxEVT_SCROLLWIN_LINEDOWN
,
1514 m_timerAutoScroll
->Start(50); // FIXME: make configurable
1518 void wxHtmlWindow::OnKeyUp(wxKeyEvent
& event
)
1520 if ( IsSelectionEnabled() &&
1521 (event
.GetKeyCode() == 'C' && event
.CmdDown()) )
1523 wxClipboardTextEvent
evt(wxEVT_COMMAND_TEXT_COPY
, GetId());
1525 evt
.SetEventObject(this);
1527 GetEventHandler()->ProcessEvent(evt
);
1531 void wxHtmlWindow::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1533 (void) CopySelection();
1536 void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent
& WXUNUSED(event
))
1538 (void) CopySelection();
1541 void wxHtmlWindow::OnDoubleClick(wxMouseEvent
& event
)
1543 // select word under cursor:
1544 if ( IsSelectionEnabled() )
1546 SelectWord(CalcUnscrolledPosition(event
.GetPosition()));
1548 (void) CopySelection(Primary
);
1550 m_lastDoubleClick
= wxGetLocalTimeMillis();
1556 void wxHtmlWindow::SelectWord(const wxPoint
& pos
)
1560 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1564 m_selection
= new wxHtmlSelection();
1565 m_selection
->Set(cell
, cell
);
1566 RefreshRect(wxRect(CalcScrolledPosition(cell
->GetAbsPos()),
1567 wxSize(cell
->GetWidth(), cell
->GetHeight())));
1572 void wxHtmlWindow::SelectLine(const wxPoint
& pos
)
1576 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1579 // We use following heuristic to find a "line": let the line be all
1580 // cells in same container as the cell under mouse cursor that are
1581 // neither completely above nor completely bellow the clicked cell
1582 // (i.e. are likely to be words positioned on same line of text).
1584 int y1
= cell
->GetAbsPos().y
;
1585 int y2
= y1
+ cell
->GetHeight();
1587 const wxHtmlCell
*c
;
1588 const wxHtmlCell
*before
= NULL
;
1589 const wxHtmlCell
*after
= NULL
;
1591 // find last cell of line:
1592 for ( c
= cell
->GetNext(); c
; c
= c
->GetNext())
1594 y
= c
->GetAbsPos().y
;
1595 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1603 // find first cell of line:
1604 for ( c
= cell
->GetParent()->GetFirstChild();
1605 c
&& c
!= cell
; c
= c
->GetNext())
1607 y
= c
->GetAbsPos().y
;
1608 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1620 m_selection
= new wxHtmlSelection();
1621 m_selection
->Set(before
, after
);
1628 void wxHtmlWindow::SelectAll()
1633 m_selection
= new wxHtmlSelection();
1634 m_selection
->Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1639 #endif // wxUSE_CLIPBOARD
1643 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor
,wxObject
)
1645 #if wxUSE_EXTENDED_RTTI
1646 IMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow
, wxScrolledWindow
,"wx/html/htmlwin.h")
1648 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow
)
1651 style , wxHW_SCROLLBAR_AUTO
1652 borders , (dimension)
1656 wxEND_PROPERTIES_TABLE()
1658 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow
)
1659 wxEND_HANDLERS_TABLE()
1661 wxCONSTRUCTOR_5( wxHtmlWindow
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1663 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWindow
,wxScrolledWindow
)
1666 BEGIN_EVENT_TABLE(wxHtmlWindow
, wxScrolledWindow
)
1667 EVT_SIZE(wxHtmlWindow::OnSize
)
1668 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown
)
1669 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp
)
1670 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp
)
1671 EVT_MOTION(wxHtmlWindow::OnMouseMove
)
1672 EVT_PAINT(wxHtmlWindow::OnPaint
)
1674 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick
)
1675 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter
)
1676 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave
)
1677 EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost
)
1678 EVT_KEY_UP(wxHtmlWindow::OnKeyUp
)
1679 EVT_MENU(wxID_COPY
, wxHtmlWindow::OnCopy
)
1680 EVT_TEXT_COPY(wxID_ANY
, wxHtmlWindow::OnClipboardEvent
)
1681 #endif // wxUSE_CLIPBOARD
1684 //-----------------------------------------------------------------------------
1685 // wxHtmlWindowInterface implementation in wxHtmlWindow
1686 //-----------------------------------------------------------------------------
1688 void wxHtmlWindow::SetHTMLWindowTitle(const wxString
& title
)
1693 void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
)
1695 OnLinkClicked(link
);
1698 wxHtmlOpeningStatus
wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type
,
1699 const wxString
& url
,
1700 wxString
*redirect
) const
1702 return OnOpeningURL(type
, url
, redirect
);
1705 wxPoint
wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell
*WXUNUSED(cell
),
1706 const wxPoint
& pos
) const
1708 return CalcScrolledPosition(pos
);
1711 wxWindow
* wxHtmlWindow::GetHTMLWindow()
1716 wxColour
wxHtmlWindow::GetHTMLBackgroundColour() const
1718 return GetBackgroundColour();
1721 void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour
& clr
)
1723 SetBackgroundColour(clr
);
1726 void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap
& bmpBg
)
1728 SetBackgroundImage(bmpBg
);
1731 void wxHtmlWindow::SetHTMLStatusText(const wxString
& text
)
1734 if (m_RelatedStatusBarIndex
!= -1)
1736 if (m_RelatedStatusBar
)
1738 m_RelatedStatusBar
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1740 else if (m_RelatedFrame
)
1742 m_RelatedFrame
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1747 #endif // wxUSE_STATUSBAR
1751 wxCursor
wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type
)
1755 case HTMLCursor_Link
:
1756 if ( !ms_cursorLink
)
1757 ms_cursorLink
= new wxCursor(wxCURSOR_HAND
);
1758 return *ms_cursorLink
;
1760 case HTMLCursor_Text
:
1761 if ( !ms_cursorText
)
1762 ms_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
1763 return *ms_cursorText
;
1765 case HTMLCursor_Default
:
1767 return *wxSTANDARD_CURSOR
;
1771 wxCursor
wxHtmlWindow::GetHTMLCursor(HTMLCursor type
) const
1773 return GetDefaultHTMLCursor(type
);
1777 //-----------------------------------------------------------------------------
1779 //-----------------------------------------------------------------------------
1781 // A module to allow initialization/cleanup
1782 // without calling these functions from app.cpp or from
1783 // the user's application.
1785 class wxHtmlWinModule
: public wxModule
1787 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule
)
1789 wxHtmlWinModule() : wxModule() {}
1790 bool OnInit() { return true; }
1791 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1794 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule
, wxModule
)
1797 // This hack forces the linker to always link in m_* files
1798 // (wxHTML doesn't work without handlers from these files)
1799 #include "wx/html/forcelnk.h"
1800 FORCE_WXHTML_MODULES()
1802 #endif // wxUSE_HTML