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_HTML_CELL_CLICKED
, wxHtmlCellEvent
);
47 wxDEFINE_EVENT( wxEVT_HTML_CELL_HOVER
, wxHtmlCellEvent
);
48 wxDEFINE_EVENT( wxEVT_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
->GetMouseCursorAt(m_interface
, pos
);
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 // A single cell can have different cursors for different positions,
233 // so update cursor for this case as well.
234 wxCursor cur
= cell
->GetMouseCursorAt(m_interface
, pos
);
235 m_interface
->GetHTMLWindow()->SetCursor(cur
);
237 OnCellMouseHover(cell
, pos
.x
, pos
.y
);
241 m_tmpMouseMoved
= false;
244 bool wxHtmlWindowMouseHelper::OnCellClicked(wxHtmlCell
*cell
,
245 wxCoord x
, wxCoord y
,
246 const wxMouseEvent
& event
)
248 wxHtmlCellEvent
ev(wxEVT_HTML_CELL_CLICKED
,
249 m_interface
->GetHTMLWindow()->GetId(),
250 cell
, wxPoint(x
,y
), event
);
252 if (!m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
))
254 // if the event wasn't handled, do the default processing here:
256 wxASSERT_MSG( cell
, wxT("can't be called with NULL cell") );
258 cell
->ProcessMouseClick(m_interface
, ev
.GetPoint(), ev
.GetMouseEvent());
261 // true if a link was clicked, false otherwise
262 return ev
.GetLinkClicked();
265 void wxHtmlWindowMouseHelper::OnCellMouseHover(wxHtmlCell
* cell
,
269 wxHtmlCellEvent
ev(wxEVT_HTML_CELL_HOVER
,
270 m_interface
->GetHTMLWindow()->GetId(),
271 cell
, wxPoint(x
,y
), wxMouseEvent());
272 m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
);
278 //-----------------------------------------------------------------------------
280 //-----------------------------------------------------------------------------
282 wxList
wxHtmlWindow::m_Filters
;
283 wxHtmlFilter
*wxHtmlWindow::m_DefaultFilter
= NULL
;
284 wxHtmlProcessorList
*wxHtmlWindow::m_GlobalProcessors
= NULL
;
285 wxCursor
*wxHtmlWindow::ms_cursorLink
= NULL
;
286 wxCursor
*wxHtmlWindow::ms_cursorText
= NULL
;
288 void wxHtmlWindow::CleanUpStatics()
290 wxDELETE(m_DefaultFilter
);
291 WX_CLEAR_LIST(wxList
, m_Filters
);
292 if (m_GlobalProcessors
)
293 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_GlobalProcessors
);
294 wxDELETE(m_GlobalProcessors
);
295 wxDELETE(ms_cursorLink
);
296 wxDELETE(ms_cursorText
);
299 void wxHtmlWindow::Init()
301 m_tmpCanDrawLocks
= 0;
302 m_FS
= new wxFileSystem();
304 m_RelatedStatusBar
= NULL
;
305 m_RelatedStatusBarIndex
= -1;
306 #endif // wxUSE_STATUSBAR
307 m_RelatedFrame
= NULL
;
308 m_TitleFormat
= wxT("%s");
309 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
311 m_Parser
= new wxHtmlWinParser(this);
312 m_Parser
->SetFS(m_FS
);
315 m_History
= new wxHtmlHistoryArray
;
319 m_makingSelection
= false;
321 m_timerAutoScroll
= NULL
;
322 m_lastDoubleClick
= 0;
323 #endif // wxUSE_CLIPBOARD
324 m_tmpSelFromCell
= NULL
;
327 bool wxHtmlWindow::Create(wxWindow
*parent
, wxWindowID id
,
328 const wxPoint
& pos
, const wxSize
& size
,
329 long style
, const wxString
& name
)
331 if (!wxScrolledWindow::Create(parent
, id
, pos
, size
,
332 style
| wxVSCROLL
| wxHSCROLL
,
336 // We can't erase our background in EVT_ERASE_BACKGROUND handler and use
337 // double buffering in EVT_PAINT handler as this requires blitting back
338 // something already drawn on the window to the backing store bitmap when
339 // handling EVT_PAINT but blitting in this direction is simply not
340 // supported by OS X.
342 // So instead we use a hack with artificial EVT_ERASE_BACKGROUND generation
343 // from OnPaint() and this means that we never need the "real" erase event
344 // at all so disable it to avoid executing any user-defined handlers twice
345 // (and to avoid processing unnecessary event if no handlers are defined).
346 SetBackgroundStyle(wxBG_STYLE_PAINT
);
347 SetPage(wxT("<html><body></body></html>"));
349 SetInitialSize(size
);
354 wxHtmlWindow::~wxHtmlWindow()
358 #endif // wxUSE_CLIPBOARD
367 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_Processors
);
378 void wxHtmlWindow::SetRelatedFrame(wxFrame
* frame
, const wxString
& format
)
380 m_RelatedFrame
= frame
;
381 m_TitleFormat
= format
;
387 void wxHtmlWindow::SetRelatedStatusBar(int index
)
389 m_RelatedStatusBarIndex
= index
;
392 void wxHtmlWindow::SetRelatedStatusBar(wxStatusBar
* statusbar
, int index
)
394 m_RelatedStatusBar
= statusbar
;
395 m_RelatedStatusBarIndex
= index
;
398 #endif // wxUSE_STATUSBAR
402 void wxHtmlWindow::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, const int *sizes
)
404 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
406 // re-layout the page after changing fonts:
407 DoSetPage(*(m_Parser
->GetSource()));
410 void wxHtmlWindow::SetStandardFonts(int size
,
411 const wxString
& normal_face
,
412 const wxString
& fixed_face
)
414 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
416 // re-layout the page after changing fonts:
417 DoSetPage(*(m_Parser
->GetSource()));
420 bool wxHtmlWindow::SetPage(const wxString
& source
)
422 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
423 return DoSetPage(source
);
426 bool wxHtmlWindow::DoSetPage(const wxString
& source
)
428 wxString
newsrc(source
);
430 wxDELETE(m_selection
);
432 // we will soon delete all the cells, so clear pointers to them:
433 m_tmpSelFromCell
= NULL
;
435 // pass HTML through registered processors:
436 if (m_Processors
|| m_GlobalProcessors
)
438 wxHtmlProcessorList::compatibility_iterator nodeL
, nodeG
;
442 nodeL
= m_Processors
->GetFirst();
443 if ( m_GlobalProcessors
)
444 nodeG
= m_GlobalProcessors
->GetFirst();
446 // VS: there are two lists, global and local, both of them sorted by
447 // priority. Since we have to go through _both_ lists with
448 // decreasing priority, we "merge-sort" the lists on-line by
449 // processing that one of the two heads that has higher priority
450 // in every iteration
451 while (nodeL
|| nodeG
)
453 prL
= (nodeL
) ? nodeL
->GetData()->GetPriority() : -1;
454 prG
= (nodeG
) ? nodeG
->GetData()->GetPriority() : -1;
457 if (nodeL
->GetData()->IsEnabled())
458 newsrc
= nodeL
->GetData()->Process(newsrc
);
459 nodeL
= nodeL
->GetNext();
463 if (nodeG
->GetData()->IsEnabled())
464 newsrc
= nodeG
->GetData()->Process(newsrc
);
465 nodeG
= nodeG
->GetNext();
470 // ...and run the parser on it:
471 wxClientDC
*dc
= new wxClientDC(this);
472 dc
->SetMapMode(wxMM_TEXT
);
473 SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
474 SetBackgroundImage(wxNullBitmap
);
478 // notice that it's important to set m_Cell to NULL here before calling
479 // Parse() below, even if it will be overwritten by its return value as
480 // without this we may crash if it's used from inside Parse(), so use
481 // wxDELETE() and not just delete here
484 m_Cell
= (wxHtmlContainerCell
*) m_Parser
->Parse(newsrc
);
486 m_Cell
->SetIndent(m_Borders
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
487 m_Cell
->SetAlignHor(wxHTML_ALIGN_CENTER
);
489 if (m_tmpCanDrawLocks
== 0)
494 bool wxHtmlWindow::AppendToPage(const wxString
& source
)
496 return DoSetPage(*(GetParser()->GetSource()) + source
);
499 bool wxHtmlWindow::LoadPage(const wxString
& location
)
501 wxCHECK_MSG( !location
.empty(), false, "location must be non-empty" );
503 wxBusyCursor busyCursor
;
506 bool needs_refresh
= false;
509 if (m_HistoryOn
&& (m_HistoryPos
!= -1))
511 // store scroll position into history item:
513 GetViewStart(&x
, &y
);
514 (*m_History
)[m_HistoryPos
].SetPos(y
);
517 // first check if we're moving to an anchor in the same page
518 size_t posLocalAnchor
= location
.Find('#');
519 if ( posLocalAnchor
!= wxString::npos
&& posLocalAnchor
!= 0 )
521 // check if the part before the anchor is the same as the (either
522 // relative or absolute) URI of the current page
523 const wxString beforeAnchor
= location
.substr(0, posLocalAnchor
);
524 if ( beforeAnchor
!= m_OpenedPage
&&
525 m_FS
->GetPath() + beforeAnchor
!= m_OpenedPage
)
527 // indicate that we're not moving to a local anchor
528 posLocalAnchor
= wxString::npos
;
532 if ( posLocalAnchor
!= wxString::npos
)
535 rt_val
= ScrollToAnchor(location
.substr(posLocalAnchor
+ 1));
538 else // moving to another page
540 needs_refresh
= true;
543 if (m_RelatedStatusBarIndex
!= -1)
545 SetHTMLStatusText(_("Connecting..."));
548 #endif // wxUSE_STATUSBAR
550 wxFSFile
*f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location
);
552 // try to interpret 'location' as filename instead of URL:
555 wxFileName
fn(location
);
556 wxString location2
= wxFileSystem::FileNameToURL(fn
);
557 f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location2
);
562 wxLogError(_("Unable to open requested HTML document: %s"), location
.c_str());
564 SetHTMLStatusText(wxEmptyString
);
570 wxList::compatibility_iterator node
;
571 wxString src
= wxEmptyString
;
574 if (m_RelatedStatusBarIndex
!= -1)
576 wxString msg
= _("Loading : ") + location
;
577 SetHTMLStatusText(msg
);
580 #endif // wxUSE_STATUSBAR
582 node
= m_Filters
.GetFirst();
585 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
588 src
= h
->ReadFile(*f
);
591 node
= node
->GetNext();
593 if (src
== wxEmptyString
)
595 if (m_DefaultFilter
== NULL
) m_DefaultFilter
= GetDefaultFilter();
596 src
= m_DefaultFilter
->ReadFile(*f
);
599 m_FS
->ChangePathTo(f
->GetLocation());
600 rt_val
= SetPage(src
);
601 m_OpenedPage
= f
->GetLocation();
602 if (f
->GetAnchor() != wxEmptyString
)
604 ScrollToAnchor(f
->GetAnchor());
610 if (m_RelatedStatusBarIndex
!= -1)
612 SetHTMLStatusText(_("Done"));
614 #endif // wxUSE_STATUSBAR
618 if (m_HistoryOn
) // add this page to history there:
620 int c
= m_History
->GetCount() - (m_HistoryPos
+ 1);
622 if (m_HistoryPos
< 0 ||
623 (*m_History
)[m_HistoryPos
].GetPage() != m_OpenedPage
||
624 (*m_History
)[m_HistoryPos
].GetAnchor() != m_OpenedAnchor
)
627 for (int i
= 0; i
< c
; i
++)
628 m_History
->RemoveAt(m_HistoryPos
);
629 m_History
->Add(new wxHtmlHistoryItem(m_OpenedPage
, m_OpenedAnchor
));
633 if (m_OpenedPageTitle
== wxEmptyString
)
634 OnSetTitle(wxFileNameFromPath(m_OpenedPage
));
648 bool wxHtmlWindow::LoadFile(const wxFileName
& filename
)
650 wxString url
= wxFileSystem::FileNameToURL(filename
);
651 return LoadPage(url
);
655 bool wxHtmlWindow::ScrollToAnchor(const wxString
& anchor
)
657 const wxHtmlCell
*c
= m_Cell
->Find(wxHTML_COND_ISANCHOR
, &anchor
);
660 wxLogWarning(_("HTML anchor %s does not exist."), anchor
.c_str());
665 // Go to next visible cell in current container, if it exists. This
666 // yields a bit better (even though still imperfect) results in that
667 // there's better chance of using a suitable cell for upper Y
668 // coordinate value. See bug #11406 for additional discussion.
669 const wxHtmlCell
*c_save
= c
;
670 while ( c
&& c
->IsFormattingCell() )
677 for (y
= 0; c
!= NULL
; c
= c
->GetParent()) y
+= c
->GetPosY();
678 Scroll(-1, y
/ wxHTML_SCROLL_STEP
);
679 m_OpenedAnchor
= anchor
;
685 void wxHtmlWindow::OnSetTitle(const wxString
& title
)
690 tit
.Printf(m_TitleFormat
, title
.c_str());
691 m_RelatedFrame
->SetTitle(tit
);
693 m_OpenedPageTitle
= title
;
697 // return scroll steps such that a) scrollbars aren't shown needlessly
698 // and b) entire content is viewable (i.e. round up)
699 static int ScrollSteps(int size
, int available
)
701 if ( size
<= available
)
704 return (size
+ wxHTML_SCROLL_STEP
- 1) / wxHTML_SCROLL_STEP
;
708 void wxHtmlWindow::CreateLayout()
710 // SetScrollbars() results in size change events -- and thus a nested
711 // CreateLayout() call -- on some platforms. Ignore nested calls, toplevel
712 // CreateLayout() will do the right thing eventually.
713 static wxRecursionGuardFlag s_flagReentrancy
;
714 wxRecursionGuard
guard(s_flagReentrancy
);
715 if ( guard
.IsInside() )
721 int clientWidth
, clientHeight
;
722 GetClientSize(&clientWidth
, &clientHeight
);
724 const int vscrollbar
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
725 const int hscrollbar
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
727 if ( HasScrollbar(wxHORIZONTAL
) )
728 clientHeight
+= hscrollbar
;
730 if ( HasScrollbar(wxVERTICAL
) )
731 clientWidth
+= vscrollbar
;
733 if ( HasFlag(wxHW_SCROLLBAR_NEVER
) )
735 SetScrollbars(1, 1, 0, 0); // always off
736 m_Cell
->Layout(clientWidth
);
738 else // !wxHW_SCROLLBAR_NEVER
740 // Lay the content out with the assumption that it's too large to fit
741 // in the window (this is likely to be the case):
742 m_Cell
->Layout(clientWidth
- vscrollbar
);
744 // If the layout is wider than the window, horizontal scrollbar will
745 // certainly be shown. Account for it here for subsequent computations.
746 if ( m_Cell
->GetWidth() > clientWidth
)
747 clientHeight
-= hscrollbar
;
749 if ( m_Cell
->GetHeight() <= clientHeight
)
751 // we fit into the window, hide vertical scrollbar:
754 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
755 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
758 // ...and redo the layout to use the extra space
759 m_Cell
->Layout(clientWidth
);
763 // If the content doesn't fit into the window by only a small
764 // margin, chances are that it may fit fully with scrollbar turned
765 // off. It's something worth trying but on the other hand, we don't
766 // want to waste too much time redoing the layout (twice!) for
767 // long -- and thus expensive to layout -- pages. The cut-off value
768 // is an arbitrary heuristics.
769 static const int SMALL_OVERLAP
= 60;
770 if ( m_Cell
->GetHeight() <= clientHeight
+ SMALL_OVERLAP
)
772 m_Cell
->Layout(clientWidth
);
774 if ( m_Cell
->GetHeight() <= clientHeight
)
776 // Great, we fit in. Hide the scrollbar.
779 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
780 ScrollSteps(m_Cell
->GetWidth(), clientWidth
),
787 // That didn't work out, go back to previous layout. Note
788 // that redoing the layout once again here isn't as bad as
789 // it looks -- thanks to the small cut-off value, it's a
790 // reasonably small page.
791 m_Cell
->Layout(clientWidth
- vscrollbar
);
794 // else: the page is very long, it will certainly need scrollbar
798 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
799 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
800 ScrollSteps(m_Cell
->GetHeight(), clientHeight
)
807 void wxHtmlWindow::ReadCustomization(wxConfigBase
*cfg
, wxString path
)
812 wxString p_fff
, p_ffn
;
814 if (path
!= wxEmptyString
)
816 oldpath
= cfg
->GetPath();
820 m_Borders
= cfg
->Read(wxT("wxHtmlWindow/Borders"), m_Borders
);
821 p_fff
= cfg
->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
822 p_ffn
= cfg
->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
823 for (int i
= 0; i
< 7; i
++)
825 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
826 p_fontsizes
[i
] = cfg
->Read(tmp
, m_Parser
->m_FontsSizes
[i
]);
828 SetFonts(p_ffn
, p_fff
, p_fontsizes
);
830 if (path
!= wxEmptyString
)
831 cfg
->SetPath(oldpath
);
836 void wxHtmlWindow::WriteCustomization(wxConfigBase
*cfg
, wxString path
)
841 if (path
!= wxEmptyString
)
843 oldpath
= cfg
->GetPath();
847 cfg
->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders
);
848 cfg
->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
849 cfg
->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
850 for (int i
= 0; i
< 7; i
++)
852 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
853 cfg
->Write(tmp
, (long) m_Parser
->m_FontsSizes
[i
]);
856 if (path
!= wxEmptyString
)
857 cfg
->SetPath(oldpath
);
859 #endif // wxUSE_CONFIG
861 bool wxHtmlWindow::HistoryBack()
865 if (m_HistoryPos
< 1) return false;
867 // store scroll position into history item:
869 GetViewStart(&x
, &y
);
870 (*m_History
)[m_HistoryPos
].SetPos(y
);
872 // go to previous position:
875 l
= (*m_History
)[m_HistoryPos
].GetPage();
876 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
879 if (a
== wxEmptyString
) LoadPage(l
);
880 else LoadPage(l
+ wxT("#") + a
);
883 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
888 bool wxHtmlWindow::HistoryCanBack()
890 if (m_HistoryPos
< 1) return false;
895 bool wxHtmlWindow::HistoryForward()
899 if (m_HistoryPos
== -1) return false;
900 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
902 m_OpenedPage
= wxEmptyString
; // this will disable adding new entry into history in LoadPage()
905 l
= (*m_History
)[m_HistoryPos
].GetPage();
906 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
909 if (a
== wxEmptyString
) LoadPage(l
);
910 else LoadPage(l
+ wxT("#") + a
);
913 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
918 bool wxHtmlWindow::HistoryCanForward()
920 if (m_HistoryPos
== -1) return false;
921 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
926 void wxHtmlWindow::HistoryClear()
932 void wxHtmlWindow::AddProcessor(wxHtmlProcessor
*processor
)
936 m_Processors
= new wxHtmlProcessorList
;
938 wxHtmlProcessorList::compatibility_iterator node
;
940 for (node
= m_Processors
->GetFirst(); node
; node
= node
->GetNext())
942 if (processor
->GetPriority() > node
->GetData()->GetPriority())
944 m_Processors
->Insert(node
, processor
);
948 m_Processors
->Append(processor
);
951 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor
*processor
)
953 if (!m_GlobalProcessors
)
955 m_GlobalProcessors
= new wxHtmlProcessorList
;
957 wxHtmlProcessorList::compatibility_iterator node
;
959 for (node
= m_GlobalProcessors
->GetFirst(); node
; node
= node
->GetNext())
961 if (processor
->GetPriority() > node
->GetData()->GetPriority())
963 m_GlobalProcessors
->Insert(node
, processor
);
967 m_GlobalProcessors
->Append(processor
);
972 void wxHtmlWindow::AddFilter(wxHtmlFilter
*filter
)
974 m_Filters
.Append(filter
);
978 bool wxHtmlWindow::IsSelectionEnabled() const
981 return !HasFlag(wxHW_NO_SELECTION
);
989 wxString
wxHtmlWindow::DoSelectionToText(wxHtmlSelection
*sel
)
992 return wxEmptyString
;
997 wxHtmlTerminalCellsInterator
i(sel
->GetFromCell(), sel
->GetToCell());
998 const wxHtmlCell
*prev
= NULL
;
1002 // When converting HTML content to plain text, the entire paragraph
1003 // (container in wxHTML) goes on single line. A new paragraph (that
1004 // should go on its own line) has its own container. Therefore, the
1005 // simplest way of detecting where to insert newlines in plain text
1006 // is to check if the parent container changed -- if it did, we moved
1007 // to a new paragraph.
1008 if ( prev
&& prev
->GetParent() != i
->GetParent() )
1011 // NB: we don't need to pass the selection to ConvertToText() in the
1012 // middle of the selected text; it's only useful when only part of
1013 // a cell is selected
1014 text
<< i
->ConvertToText(sel
);
1022 wxString
wxHtmlWindow::ToText()
1026 wxHtmlSelection sel
;
1027 sel
.Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1028 return DoSelectionToText(&sel
);
1031 return wxEmptyString
;
1034 #endif // wxUSE_CLIPBOARD
1036 bool wxHtmlWindow::CopySelection(ClipboardType t
)
1041 #if defined(__UNIX__) && !defined(__WXMAC__)
1042 wxTheClipboard
->UsePrimarySelection(t
== Primary
);
1044 // Primary selection exists only under X11, so don't do anything under
1045 // the other platforms when we try to access it
1047 // TODO: this should be abstracted at wxClipboard level!
1050 #endif // __UNIX__/!__UNIX__
1052 if ( wxTheClipboard
->Open() )
1054 const wxString
txt(SelectionToText());
1055 wxTheClipboard
->SetData(new wxTextDataObject(txt
));
1056 wxTheClipboard
->Close();
1057 wxLogTrace(wxT("wxhtmlselection"),
1058 _("Copied to clipboard:\"%s\""), txt
.c_str());
1065 #endif // wxUSE_CLIPBOARD
1071 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo
& link
)
1073 wxHtmlLinkEvent
event(GetId(), link
);
1074 event
.SetEventObject(this);
1075 if (!GetEventHandler()->ProcessEvent(event
))
1077 // the default behaviour is to load the URL in this window
1078 const wxMouseEvent
*e
= event
.GetLinkInfo().GetEvent();
1079 if (e
== NULL
|| e
->LeftUp())
1080 LoadPage(event
.GetLinkInfo().GetHref());
1084 void wxHtmlWindow::DoEraseBackground(wxDC
& dc
)
1086 // if we don't have any background bitmap we just fill it with background
1087 // colour and we also must do it if the background bitmap is not fully
1088 // opaque as otherwise junk could be left there
1089 if ( !m_bmpBg
.IsOk() || m_bmpBg
.GetMask() )
1091 dc
.SetBackground(GetBackgroundColour());
1095 if ( m_bmpBg
.IsOk() )
1097 // draw the background bitmap tiling it over the entire window area
1098 const wxSize sz
= GetVirtualSize();
1099 const wxSize
sizeBmp(m_bmpBg
.GetWidth(), m_bmpBg
.GetHeight());
1100 for ( wxCoord x
= 0; x
< sz
.x
; x
+= sizeBmp
.x
)
1102 for ( wxCoord y
= 0; y
< sz
.y
; y
+= sizeBmp
.y
)
1104 dc
.DrawBitmap(m_bmpBg
, x
, y
, true /* use mask */);
1110 void wxHtmlWindow::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
1112 // We never get real erase background events as we changed our background
1113 // style to wxBG_STYLE_PAINT in our ctor so the only time when we get here
1114 // is when an artificial wxEraseEvent is generated by our own OnPaint()
1115 // below. This handler only exists to stop the event from propagating
1116 // downwards to wxWindow which may erase the background itself when it gets
1117 // it in some ports (currently this happens in wxUniv), so we simply stop
1118 // processing here and set a special flag allowing OnPaint() to see that
1119 // the event hadn't been really processed.
1120 m_isBgReallyErased
= false;
1123 void wxHtmlWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
1125 wxPaintDC
dcPaint(this);
1127 if (m_tmpCanDrawLocks
> 0 || m_Cell
== NULL
)
1131 GetViewStart(&x
, &y
);
1132 const wxRect rect
= GetUpdateRegion().GetBox();
1133 const wxSize sz
= GetClientSize();
1135 // set up the DC we're drawing on: if the window is already double buffered
1136 // we do it directly on wxPaintDC, otherwise we allocate a backing store
1137 // buffer and compose the drawing there and then blit it to screen all at
1141 if ( IsDoubleBuffered() )
1145 else // window is not double buffered by the system, do it ourselves
1147 if ( !m_backBuffer
.IsOk() )
1148 m_backBuffer
.Create(sz
.x
, sz
.y
);
1149 dcm
.SelectObject(m_backBuffer
);
1155 // Erase the background: for compatibility, we must generate the event to
1156 // allow the user-defined handlers to do it, hence this hack with sending
1157 // an artificial wxEraseEvent to trigger the execution of such handlers.
1158 wxEraseEvent
eraseEvent(GetId(), dc
);
1159 eraseEvent
.SetEventObject(this);
1161 // Hack inside a hack: the background wasn't really erased if our own
1162 // OnEraseBackground() was executed, so we need to check for the flag set
1163 // by it whenever it's called.
1164 m_isBgReallyErased
= true; // Initially assume it wasn't.
1165 if ( !ProcessWindowEvent(eraseEvent
) || !m_isBgReallyErased
)
1167 // erase background ourselves
1168 DoEraseBackground(*dc
);
1170 //else: background erased by the user-defined handler
1173 // draw the HTML window contents
1174 dc
->SetMapMode(wxMM_TEXT
);
1175 dc
->SetBackgroundMode(wxTRANSPARENT
);
1176 dc
->SetLayoutDirection(GetLayoutDirection());
1178 wxHtmlRenderingInfo rinfo
;
1179 wxDefaultHtmlRenderingStyle rstyle
;
1180 rinfo
.SetSelection(m_selection
);
1181 rinfo
.SetStyle(&rstyle
);
1182 m_Cell
->Draw(*dc
, 0, 0,
1183 y
* wxHTML_SCROLL_STEP
+ rect
.GetTop(),
1184 y
* wxHTML_SCROLL_STEP
+ rect
.GetBottom(),
1187 #ifdef DEBUG_HTML_SELECTION
1190 wxGetMousePosition(&xc
, &yc
);
1191 ScreenToClient(&xc
, &yc
);
1192 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1193 wxHtmlCell
*at
= m_Cell
->FindCellByPos(x
, y
);
1194 wxHtmlCell
*before
=
1195 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_BEFORE
);
1197 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_AFTER
);
1199 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1200 dc
->SetPen(*wxBLACK_PEN
);
1202 dc
->DrawRectangle(at
->GetAbsPos(),
1203 wxSize(at
->GetWidth(),at
->GetHeight()));
1204 dc
->SetPen(*wxGREEN_PEN
);
1206 dc
->DrawRectangle(before
->GetAbsPos().x
+1, before
->GetAbsPos().y
+1,
1207 before
->GetWidth()-2,before
->GetHeight()-2);
1208 dc
->SetPen(*wxRED_PEN
);
1210 dc
->DrawRectangle(after
->GetAbsPos().x
+2, after
->GetAbsPos().y
+2,
1211 after
->GetWidth()-4,after
->GetHeight()-4);
1213 #endif // DEBUG_HTML_SELECTION
1215 if ( dc
!= &dcPaint
)
1217 dc
->SetDeviceOrigin(0,0);
1218 dcPaint
.Blit(0, rect
.GetTop(),
1219 sz
.x
, rect
.GetBottom() - rect
.GetTop() + 1,
1228 void wxHtmlWindow::OnSize(wxSizeEvent
& event
)
1232 m_backBuffer
= wxNullBitmap
;
1236 // Recompute selection if necessary:
1239 m_selection
->Set(m_selection
->GetFromCell(),
1240 m_selection
->GetToCell());
1241 m_selection
->ClearFromToCharacterPos();
1248 void wxHtmlWindow::OnMouseMove(wxMouseEvent
& WXUNUSED(event
))
1250 wxHtmlWindowMouseHelper::HandleMouseMoved();
1253 void wxHtmlWindow::OnMouseDown(wxMouseEvent
& event
)
1256 if ( event
.LeftDown() && IsSelectionEnabled() )
1258 const long TRIPLECLICK_LEN
= 200; // 0.2 sec after doubleclick
1259 if ( wxGetLocalTimeMillis() - m_lastDoubleClick
<= TRIPLECLICK_LEN
)
1261 SelectLine(CalcUnscrolledPosition(event
.GetPosition()));
1263 (void) CopySelection();
1267 m_makingSelection
= true;
1271 wxDELETE(m_selection
);
1274 m_tmpSelFromPos
= CalcUnscrolledPosition(event
.GetPosition());
1275 m_tmpSelFromCell
= NULL
;
1280 #endif // wxUSE_CLIPBOARD
1282 // in any case, let the default handler set focus to this window
1286 void wxHtmlWindow::OnMouseUp(wxMouseEvent
& event
)
1289 if ( m_makingSelection
)
1292 m_makingSelection
= false;
1294 // if m_selection=NULL, the user didn't move the mouse far enough from
1295 // starting point and the mouse up event is part of a click, the user
1296 // is not selecting text:
1299 CopySelection(Primary
);
1301 // we don't want mouse up event that ended selecting to be
1302 // handled as mouse click and e.g. follow hyperlink:
1306 #endif // wxUSE_CLIPBOARD
1308 wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
1309 if ( !wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell
, pos
, event
) )
1314 void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1316 if ( !m_makingSelection
)
1319 // discard the selecting operation
1320 m_makingSelection
= false;
1321 wxDELETE(m_selection
);
1322 m_tmpSelFromCell
= NULL
;
1325 #endif // wxUSE_CLIPBOARD
1328 void wxHtmlWindow::OnInternalIdle()
1330 wxWindow::OnInternalIdle();
1332 if (m_Cell
!= NULL
&& DidMouseMove())
1334 #ifdef DEBUG_HTML_SELECTION
1338 wxGetMousePosition(&xc
, &yc
);
1339 ScreenToClient(&xc
, &yc
);
1340 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1342 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(x
, y
);
1344 // handle selection update:
1345 if ( m_makingSelection
)
1347 if ( !m_tmpSelFromCell
)
1348 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1349 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
);
1351 // NB: a trick - we adjust selFromPos to be upper left or bottom
1352 // right corner of the first cell of the selection depending
1353 // on whether the mouse is moving to the right or to the left.
1354 // This gives us more "natural" behaviour when selecting
1355 // a line (specifically, first cell of the next line is not
1356 // included if you drag selection from left to right over
1359 if ( !m_tmpSelFromCell
)
1361 dirFromPos
= m_tmpSelFromPos
;
1365 dirFromPos
= m_tmpSelFromCell
->GetAbsPos();
1366 if ( x
< m_tmpSelFromPos
.x
)
1368 dirFromPos
.x
+= m_tmpSelFromCell
->GetWidth();
1369 dirFromPos
.y
+= m_tmpSelFromCell
->GetHeight();
1372 bool goingDown
= dirFromPos
.y
< y
||
1373 (dirFromPos
.y
== y
&& dirFromPos
.x
< x
);
1375 // determine selection span:
1376 if ( /*still*/ !m_tmpSelFromCell
)
1380 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1381 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1382 wxHTML_FIND_NEAREST_AFTER
);
1383 if (!m_tmpSelFromCell
)
1384 m_tmpSelFromCell
= m_Cell
->GetFirstTerminal();
1388 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1389 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1390 wxHTML_FIND_NEAREST_BEFORE
);
1391 if (!m_tmpSelFromCell
)
1392 m_tmpSelFromCell
= m_Cell
->GetLastTerminal();
1396 wxHtmlCell
*selcell
= cell
;
1401 selcell
= m_Cell
->FindCellByPos(x
, y
,
1402 wxHTML_FIND_NEAREST_BEFORE
);
1404 selcell
= m_Cell
->GetLastTerminal();
1408 selcell
= m_Cell
->FindCellByPos(x
, y
,
1409 wxHTML_FIND_NEAREST_AFTER
);
1411 selcell
= m_Cell
->GetFirstTerminal();
1415 // NB: it may *rarely* happen that the code above didn't find one
1416 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1418 if ( selcell
&& m_tmpSelFromCell
)
1422 // start selecting only if mouse movement was big enough
1423 // (otherwise it was meant as mouse click, not selection):
1424 const int PRECISION
= 2;
1425 wxPoint diff
= m_tmpSelFromPos
- wxPoint(x
,y
);
1426 if (abs(diff
.x
) > PRECISION
|| abs(diff
.y
) > PRECISION
)
1428 m_selection
= new wxHtmlSelection();
1433 if ( m_tmpSelFromCell
->IsBefore(selcell
) )
1435 m_selection
->Set(m_tmpSelFromPos
, m_tmpSelFromCell
,
1436 wxPoint(x
,y
), selcell
);
1440 m_selection
->Set(wxPoint(x
,y
), selcell
,
1441 m_tmpSelFromPos
, m_tmpSelFromCell
);
1443 m_selection
->ClearFromToCharacterPos();
1449 // handle cursor and status bar text changes:
1451 // NB: because we're passing in 'cell' and not 'm_Cell' (so that the
1452 // leaf cell lookup isn't done twice), we need to adjust the
1453 // position for the new root:
1454 wxPoint
posInCell(x
, y
);
1456 posInCell
-= cell
->GetAbsPos();
1457 wxHtmlWindowMouseHelper::HandleIdle(cell
, posInCell
);
1462 void wxHtmlWindow::StopAutoScrolling()
1464 if ( m_timerAutoScroll
)
1466 wxDELETE(m_timerAutoScroll
);
1470 void wxHtmlWindow::OnMouseEnter(wxMouseEvent
& event
)
1472 StopAutoScrolling();
1476 void wxHtmlWindow::OnMouseLeave(wxMouseEvent
& event
)
1478 // don't prevent the usual processing of the event from taking place
1481 // when a captured mouse leave a scrolled window we start generate
1482 // scrolling events to allow, for example, extending selection beyond the
1483 // visible area in some controls
1484 if ( wxWindow::GetCapture() == this )
1486 // where is the mouse leaving?
1488 wxPoint pt
= event
.GetPosition();
1491 orient
= wxHORIZONTAL
;
1494 else if ( pt
.y
< 0 )
1496 orient
= wxVERTICAL
;
1499 else // we're lower or to the right of the window
1501 wxSize size
= GetClientSize();
1502 if ( pt
.x
> size
.x
)
1504 orient
= wxHORIZONTAL
;
1505 pos
= GetVirtualSize().x
/ wxHTML_SCROLL_STEP
;
1507 else if ( pt
.y
> size
.y
)
1509 orient
= wxVERTICAL
;
1510 pos
= GetVirtualSize().y
/ wxHTML_SCROLL_STEP
;
1512 else // this should be impossible
1514 // but seems to happen sometimes under wxMSW - maybe it's a bug
1515 // there but for now just ignore it
1517 //wxFAIL_MSG( wxT("can't understand where has mouse gone") );
1523 // only start the auto scroll timer if the window can be scrolled in
1525 if ( !HasScrollbar(orient
) )
1528 delete m_timerAutoScroll
;
1529 m_timerAutoScroll
= new wxHtmlWinAutoScrollTimer
1532 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
1533 : wxEVT_SCROLLWIN_LINEDOWN
,
1537 m_timerAutoScroll
->Start(50); // FIXME: make configurable
1541 void wxHtmlWindow::OnKeyUp(wxKeyEvent
& event
)
1543 if ( IsSelectionEnabled() &&
1544 (event
.GetKeyCode() == 'C' && event
.CmdDown()) )
1546 wxClipboardTextEvent
evt(wxEVT_TEXT_COPY
, GetId());
1548 evt
.SetEventObject(this);
1550 GetEventHandler()->ProcessEvent(evt
);
1558 void wxHtmlWindow::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1560 (void) CopySelection();
1563 void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent
& WXUNUSED(event
))
1565 (void) CopySelection();
1568 void wxHtmlWindow::OnDoubleClick(wxMouseEvent
& event
)
1570 // select word under cursor:
1571 if ( IsSelectionEnabled() )
1573 SelectWord(CalcUnscrolledPosition(event
.GetPosition()));
1575 (void) CopySelection(Primary
);
1577 m_lastDoubleClick
= wxGetLocalTimeMillis();
1583 void wxHtmlWindow::SelectWord(const wxPoint
& pos
)
1587 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1591 m_selection
= new wxHtmlSelection();
1592 m_selection
->Set(cell
, cell
);
1593 RefreshRect(wxRect(CalcScrolledPosition(cell
->GetAbsPos()),
1594 wxSize(cell
->GetWidth(), cell
->GetHeight())));
1599 void wxHtmlWindow::SelectLine(const wxPoint
& pos
)
1603 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1606 // We use following heuristic to find a "line": let the line be all
1607 // cells in same container as the cell under mouse cursor that are
1608 // neither completely above nor completely below the clicked cell
1609 // (i.e. are likely to be words positioned on same line of text).
1611 int y1
= cell
->GetAbsPos().y
;
1612 int y2
= y1
+ cell
->GetHeight();
1614 const wxHtmlCell
*c
;
1615 const wxHtmlCell
*before
= NULL
;
1616 const wxHtmlCell
*after
= NULL
;
1618 // find last cell of line:
1619 for ( c
= cell
->GetNext(); c
; c
= c
->GetNext())
1621 y
= c
->GetAbsPos().y
;
1622 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1630 // find first cell of line:
1631 for ( c
= cell
->GetParent()->GetFirstChild();
1632 c
&& c
!= cell
; c
= c
->GetNext())
1634 y
= c
->GetAbsPos().y
;
1635 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1647 m_selection
= new wxHtmlSelection();
1648 m_selection
->Set(before
, after
);
1655 void wxHtmlWindow::SelectAll()
1660 m_selection
= new wxHtmlSelection();
1661 m_selection
->Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1666 #endif // wxUSE_CLIPBOARD
1670 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor
,wxObject
)
1672 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow
)
1675 style , wxHW_SCROLLBAR_AUTO
1676 borders , (dimension)
1680 wxEND_PROPERTIES_TABLE()
1682 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow
)
1683 wxEND_HANDLERS_TABLE()
1685 wxCONSTRUCTOR_5( wxHtmlWindow
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1687 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow
, wxScrolledWindow
,"wx/html/htmlwin.h")
1689 BEGIN_EVENT_TABLE(wxHtmlWindow
, wxScrolledWindow
)
1690 EVT_SIZE(wxHtmlWindow::OnSize
)
1691 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown
)
1692 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp
)
1693 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp
)
1694 EVT_MOTION(wxHtmlWindow::OnMouseMove
)
1695 EVT_PAINT(wxHtmlWindow::OnPaint
)
1696 EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground
)
1698 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick
)
1699 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter
)
1700 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave
)
1701 EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost
)
1702 EVT_KEY_UP(wxHtmlWindow::OnKeyUp
)
1703 EVT_MENU(wxID_COPY
, wxHtmlWindow::OnCopy
)
1704 EVT_TEXT_COPY(wxID_ANY
, wxHtmlWindow::OnClipboardEvent
)
1705 #endif // wxUSE_CLIPBOARD
1708 //-----------------------------------------------------------------------------
1709 // wxHtmlWindowInterface implementation in wxHtmlWindow
1710 //-----------------------------------------------------------------------------
1712 void wxHtmlWindow::SetHTMLWindowTitle(const wxString
& title
)
1717 void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
)
1719 OnLinkClicked(link
);
1722 wxHtmlOpeningStatus
wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type
,
1723 const wxString
& url
,
1724 wxString
*redirect
) const
1726 return OnOpeningURL(type
, url
, redirect
);
1729 wxPoint
wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell
*WXUNUSED(cell
),
1730 const wxPoint
& pos
) const
1732 return CalcScrolledPosition(pos
);
1735 wxWindow
* wxHtmlWindow::GetHTMLWindow()
1740 wxColour
wxHtmlWindow::GetHTMLBackgroundColour() const
1742 return GetBackgroundColour();
1745 void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour
& clr
)
1747 SetBackgroundColour(clr
);
1750 void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap
& bmpBg
)
1752 SetBackgroundImage(bmpBg
);
1755 void wxHtmlWindow::SetHTMLStatusText(const wxString
& text
)
1758 if (m_RelatedStatusBarIndex
!= -1)
1760 if (m_RelatedStatusBar
)
1762 m_RelatedStatusBar
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1764 else if (m_RelatedFrame
)
1766 m_RelatedFrame
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1771 #endif // wxUSE_STATUSBAR
1775 wxCursor
wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type
)
1779 case HTMLCursor_Link
:
1780 if ( !ms_cursorLink
)
1781 ms_cursorLink
= new wxCursor(wxCURSOR_HAND
);
1782 return *ms_cursorLink
;
1784 case HTMLCursor_Text
:
1785 if ( !ms_cursorText
)
1786 ms_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
1787 return *ms_cursorText
;
1789 case HTMLCursor_Default
:
1791 return *wxSTANDARD_CURSOR
;
1795 wxCursor
wxHtmlWindow::GetHTMLCursor(HTMLCursor type
) const
1797 return GetDefaultHTMLCursor(type
);
1801 //-----------------------------------------------------------------------------
1803 //-----------------------------------------------------------------------------
1805 // A module to allow initialization/cleanup
1806 // without calling these functions from app.cpp or from
1807 // the user's application.
1809 class wxHtmlWinModule
: public wxModule
1811 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule
)
1813 wxHtmlWinModule() : wxModule() {}
1814 bool OnInit() { return true; }
1815 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1818 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule
, wxModule
)
1821 // This hack forces the linker to always link in m_* files
1822 // (wxHTML doesn't work without handlers from these files)
1823 #include "wx/html/forcelnk.h"
1824 FORCE_WXHTML_MODULES()
1826 #endif // wxUSE_HTML