1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/html/htmlwin.cpp
3 // Purpose: wxHtmlWindow class for parsing & displaying HTML (implementation)
4 // Author: Vaclav Slavik
5 // Copyright: (c) 1999 Vaclav Slavik
6 // Licence: wxWindows licence
7 /////////////////////////////////////////////////////////////////////////////
15 #if wxUSE_HTML && wxUSE_STREAMS
21 #include "wx/dcclient.h"
23 #include "wx/dcmemory.h"
25 #include "wx/settings.h"
26 #include "wx/dataobj.h"
27 #include "wx/statusbr.h"
30 #include "wx/html/htmlwin.h"
31 #include "wx/html/htmlproc.h"
32 #include "wx/clipbrd.h"
33 #include "wx/recguard.h"
35 #include "wx/arrimpl.cpp"
36 #include "wx/listimpl.cpp"
38 // uncomment this line to visually show the extent of the selection
39 //#define DEBUG_HTML_SELECTION
42 IMPLEMENT_DYNAMIC_CLASS(wxHtmlLinkEvent
, wxCommandEvent
)
43 IMPLEMENT_DYNAMIC_CLASS(wxHtmlCellEvent
, wxCommandEvent
)
45 wxDEFINE_EVENT( wxEVT_HTML_CELL_CLICKED
, wxHtmlCellEvent
);
46 wxDEFINE_EVENT( wxEVT_HTML_CELL_HOVER
, wxHtmlCellEvent
);
47 wxDEFINE_EVENT( wxEVT_HTML_LINK_CLICKED
, wxHtmlLinkEvent
);
51 // ----------------------------------------------------------------------------
52 // wxHtmlWinAutoScrollTimer: the timer used to generate a stream of scroll
53 // events when a captured mouse is held outside the window
54 // ----------------------------------------------------------------------------
56 class wxHtmlWinAutoScrollTimer
: public wxTimer
59 wxHtmlWinAutoScrollTimer(wxScrolledWindow
*win
,
60 wxEventType eventTypeToSend
,
64 m_eventType
= eventTypeToSend
;
69 virtual void Notify();
72 wxScrolledWindow
*m_win
;
73 wxEventType m_eventType
;
77 wxDECLARE_NO_COPY_CLASS(wxHtmlWinAutoScrollTimer
);
80 void wxHtmlWinAutoScrollTimer::Notify()
82 // only do all this as long as the window is capturing the mouse
83 if ( wxWindow::GetCapture() != m_win
)
87 else // we still capture the mouse, continue generating events
89 // first scroll the window if we are allowed to do it
90 wxScrollWinEvent
event1(m_eventType
, m_pos
, m_orient
);
91 event1
.SetEventObject(m_win
);
92 if ( m_win
->GetEventHandler()->ProcessEvent(event1
) )
94 // and then send a pseudo mouse-move event to refresh the selection
95 wxMouseEvent
event2(wxEVT_MOTION
);
96 wxGetMousePosition(&event2
.m_x
, &event2
.m_y
);
98 // the mouse event coordinates should be client, not screen as
99 // returned by wxGetMousePosition
100 wxWindow
*parentTop
= m_win
;
101 while ( parentTop
->GetParent() )
102 parentTop
= parentTop
->GetParent();
103 wxPoint ptOrig
= parentTop
->GetPosition();
104 event2
.m_x
-= ptOrig
.x
;
105 event2
.m_y
-= ptOrig
.y
;
107 event2
.SetEventObject(m_win
);
109 // FIXME: we don't fill in the other members - ok?
110 m_win
->GetEventHandler()->ProcessEvent(event2
);
112 else // can't scroll further, stop
119 #endif // wxUSE_CLIPBOARD
123 //-----------------------------------------------------------------------------
125 //-----------------------------------------------------------------------------
127 // item of history list
128 class WXDLLIMPEXP_HTML wxHtmlHistoryItem
131 wxHtmlHistoryItem(const wxString
& p
, const wxString
& a
) {m_Page
= p
, m_Anchor
= a
, m_Pos
= 0;}
132 int GetPos() const {return m_Pos
;}
133 void SetPos(int p
) {m_Pos
= p
;}
134 const wxString
& GetPage() const {return m_Page
;}
135 const wxString
& GetAnchor() const {return m_Anchor
;}
144 //-----------------------------------------------------------------------------
145 // our private arrays:
146 //-----------------------------------------------------------------------------
148 WX_DECLARE_OBJARRAY(wxHtmlHistoryItem
, wxHtmlHistoryArray
);
149 WX_DEFINE_OBJARRAY(wxHtmlHistoryArray
)
151 WX_DECLARE_LIST(wxHtmlProcessor
, wxHtmlProcessorList
);
152 WX_DEFINE_LIST(wxHtmlProcessorList
)
154 //-----------------------------------------------------------------------------
155 // wxHtmlWindowMouseHelper
156 //-----------------------------------------------------------------------------
158 wxHtmlWindowMouseHelper::wxHtmlWindowMouseHelper(wxHtmlWindowInterface
*iface
)
159 : m_tmpMouseMoved(false),
166 void wxHtmlWindowMouseHelper::HandleMouseMoved()
168 m_tmpMouseMoved
= true;
171 bool wxHtmlWindowMouseHelper::HandleMouseClick(wxHtmlCell
*rootCell
,
173 const wxMouseEvent
& event
)
178 wxHtmlCell
*cell
= rootCell
->FindCellByPos(pos
.x
, pos
.y
);
179 // this check is needed because FindCellByPos returns terminal cell and
180 // containers may have empty borders -- in this case NULL will be
185 // adjust the coordinates to be relative to this cell:
186 wxPoint relpos
= pos
- cell
->GetAbsPos(rootCell
);
188 return OnCellClicked(cell
, relpos
.x
, relpos
.y
, event
);
191 void wxHtmlWindowMouseHelper::HandleIdle(wxHtmlCell
*rootCell
,
194 wxHtmlCell
*cell
= rootCell
? rootCell
->FindCellByPos(pos
.x
, pos
.y
) : NULL
;
196 if (cell
!= m_tmpLastCell
)
198 wxHtmlLinkInfo
*lnk
= NULL
;
201 // adjust the coordinates to be relative to this cell:
202 wxPoint relpos
= pos
- cell
->GetAbsPos(rootCell
);
203 lnk
= cell
->GetLink(relpos
.x
, relpos
.y
);
208 cur
= cell
->GetMouseCursorAt(m_interface
, pos
);
210 cur
= m_interface
->GetHTMLCursor(
211 wxHtmlWindowInterface::HTMLCursor_Default
);
213 m_interface
->GetHTMLWindow()->SetCursor(cur
);
215 if (lnk
!= m_tmpLastLink
)
218 m_interface
->SetHTMLStatusText(lnk
->GetHref());
220 m_interface
->SetHTMLStatusText(wxEmptyString
);
225 m_tmpLastCell
= cell
;
227 else // mouse moved but stayed in the same cell
231 // A single cell can have different cursors for different positions,
232 // so update cursor for this case as well.
233 wxCursor cur
= cell
->GetMouseCursorAt(m_interface
, pos
);
234 m_interface
->GetHTMLWindow()->SetCursor(cur
);
236 OnCellMouseHover(cell
, pos
.x
, pos
.y
);
240 m_tmpMouseMoved
= false;
243 bool wxHtmlWindowMouseHelper::OnCellClicked(wxHtmlCell
*cell
,
244 wxCoord x
, wxCoord y
,
245 const wxMouseEvent
& event
)
247 wxHtmlCellEvent
ev(wxEVT_HTML_CELL_CLICKED
,
248 m_interface
->GetHTMLWindow()->GetId(),
249 cell
, wxPoint(x
,y
), event
);
251 if (!m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
))
253 // if the event wasn't handled, do the default processing here:
255 wxASSERT_MSG( cell
, wxT("can't be called with NULL cell") );
257 cell
->ProcessMouseClick(m_interface
, ev
.GetPoint(), ev
.GetMouseEvent());
260 // true if a link was clicked, false otherwise
261 return ev
.GetLinkClicked();
264 void wxHtmlWindowMouseHelper::OnCellMouseHover(wxHtmlCell
* cell
,
268 wxHtmlCellEvent
ev(wxEVT_HTML_CELL_HOVER
,
269 m_interface
->GetHTMLWindow()->GetId(),
270 cell
, wxPoint(x
,y
), wxMouseEvent());
271 m_interface
->GetHTMLWindow()->GetEventHandler()->ProcessEvent(ev
);
277 //-----------------------------------------------------------------------------
279 //-----------------------------------------------------------------------------
281 wxList
wxHtmlWindow::m_Filters
;
282 wxHtmlFilter
*wxHtmlWindow::m_DefaultFilter
= NULL
;
283 wxHtmlProcessorList
*wxHtmlWindow::m_GlobalProcessors
= NULL
;
284 wxCursor
*wxHtmlWindow::ms_cursorLink
= NULL
;
285 wxCursor
*wxHtmlWindow::ms_cursorText
= NULL
;
287 void wxHtmlWindow::CleanUpStatics()
289 wxDELETE(m_DefaultFilter
);
290 WX_CLEAR_LIST(wxList
, m_Filters
);
291 if (m_GlobalProcessors
)
292 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_GlobalProcessors
);
293 wxDELETE(m_GlobalProcessors
);
294 wxDELETE(ms_cursorLink
);
295 wxDELETE(ms_cursorText
);
298 void wxHtmlWindow::Init()
300 m_tmpCanDrawLocks
= 0;
301 m_FS
= new wxFileSystem();
303 m_RelatedStatusBar
= NULL
;
304 m_RelatedStatusBarIndex
= -1;
305 #endif // wxUSE_STATUSBAR
306 m_RelatedFrame
= NULL
;
307 m_TitleFormat
= wxT("%s");
308 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
310 m_Parser
= new wxHtmlWinParser(this);
311 m_Parser
->SetFS(m_FS
);
314 m_History
= new wxHtmlHistoryArray
;
318 m_makingSelection
= false;
320 m_timerAutoScroll
= NULL
;
321 m_lastDoubleClick
= 0;
322 #endif // wxUSE_CLIPBOARD
323 m_tmpSelFromCell
= NULL
;
326 bool wxHtmlWindow::Create(wxWindow
*parent
, wxWindowID id
,
327 const wxPoint
& pos
, const wxSize
& size
,
328 long style
, const wxString
& name
)
330 if (!wxScrolledWindow::Create(parent
, id
, pos
, size
,
331 style
| wxVSCROLL
| wxHSCROLL
,
335 // We can't erase our background in EVT_ERASE_BACKGROUND handler and use
336 // double buffering in EVT_PAINT handler as this requires blitting back
337 // something already drawn on the window to the backing store bitmap when
338 // handling EVT_PAINT but blitting in this direction is simply not
339 // supported by OS X.
341 // So instead we use a hack with artificial EVT_ERASE_BACKGROUND generation
342 // from OnPaint() and this means that we never need the "real" erase event
343 // at all so disable it to avoid executing any user-defined handlers twice
344 // (and to avoid processing unnecessary event if no handlers are defined).
345 SetBackgroundStyle(wxBG_STYLE_PAINT
);
346 SetPage(wxT("<html><body></body></html>"));
348 SetInitialSize(size
);
353 wxHtmlWindow::~wxHtmlWindow()
357 #endif // wxUSE_CLIPBOARD
366 WX_CLEAR_LIST(wxHtmlProcessorList
, *m_Processors
);
377 void wxHtmlWindow::SetRelatedFrame(wxFrame
* frame
, const wxString
& format
)
379 m_RelatedFrame
= frame
;
380 m_TitleFormat
= format
;
386 void wxHtmlWindow::SetRelatedStatusBar(int index
)
388 m_RelatedStatusBarIndex
= index
;
391 void wxHtmlWindow::SetRelatedStatusBar(wxStatusBar
* statusbar
, int index
)
393 m_RelatedStatusBar
= statusbar
;
394 m_RelatedStatusBarIndex
= index
;
397 #endif // wxUSE_STATUSBAR
401 void wxHtmlWindow::SetFonts(const wxString
& normal_face
, const wxString
& fixed_face
, const int *sizes
)
403 m_Parser
->SetFonts(normal_face
, fixed_face
, sizes
);
405 // re-layout the page after changing fonts:
406 DoSetPage(*(m_Parser
->GetSource()));
409 void wxHtmlWindow::SetStandardFonts(int size
,
410 const wxString
& normal_face
,
411 const wxString
& fixed_face
)
413 m_Parser
->SetStandardFonts(size
, normal_face
, fixed_face
);
415 // re-layout the page after changing fonts:
416 DoSetPage(*(m_Parser
->GetSource()));
419 bool wxHtmlWindow::SetPage(const wxString
& source
)
421 m_OpenedPage
= m_OpenedAnchor
= m_OpenedPageTitle
= wxEmptyString
;
422 return DoSetPage(source
);
425 bool wxHtmlWindow::DoSetPage(const wxString
& source
)
427 wxString
newsrc(source
);
429 wxDELETE(m_selection
);
431 // we will soon delete all the cells, so clear pointers to them:
432 m_tmpSelFromCell
= NULL
;
434 // pass HTML through registered processors:
435 if (m_Processors
|| m_GlobalProcessors
)
437 wxHtmlProcessorList::compatibility_iterator nodeL
, nodeG
;
441 nodeL
= m_Processors
->GetFirst();
442 if ( m_GlobalProcessors
)
443 nodeG
= m_GlobalProcessors
->GetFirst();
445 // VS: there are two lists, global and local, both of them sorted by
446 // priority. Since we have to go through _both_ lists with
447 // decreasing priority, we "merge-sort" the lists on-line by
448 // processing that one of the two heads that has higher priority
449 // in every iteration
450 while (nodeL
|| nodeG
)
452 prL
= (nodeL
) ? nodeL
->GetData()->GetPriority() : -1;
453 prG
= (nodeG
) ? nodeG
->GetData()->GetPriority() : -1;
456 if (nodeL
->GetData()->IsEnabled())
457 newsrc
= nodeL
->GetData()->Process(newsrc
);
458 nodeL
= nodeL
->GetNext();
462 if (nodeG
->GetData()->IsEnabled())
463 newsrc
= nodeG
->GetData()->Process(newsrc
);
464 nodeG
= nodeG
->GetNext();
469 // ...and run the parser on it:
470 wxClientDC
*dc
= new wxClientDC(this);
471 dc
->SetMapMode(wxMM_TEXT
);
472 SetBackgroundColour(wxColour(0xFF, 0xFF, 0xFF));
473 SetBackgroundImage(wxNullBitmap
);
477 // notice that it's important to set m_Cell to NULL here before calling
478 // Parse() below, even if it will be overwritten by its return value as
479 // without this we may crash if it's used from inside Parse(), so use
480 // wxDELETE() and not just delete here
483 m_Cell
= (wxHtmlContainerCell
*) m_Parser
->Parse(newsrc
);
485 m_Cell
->SetIndent(m_Borders
, wxHTML_INDENT_ALL
, wxHTML_UNITS_PIXELS
);
486 m_Cell
->SetAlignHor(wxHTML_ALIGN_CENTER
);
488 if (m_tmpCanDrawLocks
== 0)
493 bool wxHtmlWindow::AppendToPage(const wxString
& source
)
495 return DoSetPage(*(GetParser()->GetSource()) + source
);
498 bool wxHtmlWindow::LoadPage(const wxString
& location
)
500 wxCHECK_MSG( !location
.empty(), false, "location must be non-empty" );
502 wxBusyCursor busyCursor
;
505 bool needs_refresh
= false;
508 if (m_HistoryOn
&& (m_HistoryPos
!= -1))
510 // store scroll position into history item:
512 GetViewStart(&x
, &y
);
513 (*m_History
)[m_HistoryPos
].SetPos(y
);
516 // first check if we're moving to an anchor in the same page
517 size_t posLocalAnchor
= location
.Find('#');
518 if ( posLocalAnchor
!= wxString::npos
&& posLocalAnchor
!= 0 )
520 // check if the part before the anchor is the same as the (either
521 // relative or absolute) URI of the current page
522 const wxString beforeAnchor
= location
.substr(0, posLocalAnchor
);
523 if ( beforeAnchor
!= m_OpenedPage
&&
524 m_FS
->GetPath() + beforeAnchor
!= m_OpenedPage
)
526 // indicate that we're not moving to a local anchor
527 posLocalAnchor
= wxString::npos
;
531 if ( posLocalAnchor
!= wxString::npos
)
534 rt_val
= ScrollToAnchor(location
.substr(posLocalAnchor
+ 1));
537 else // moving to another page
539 needs_refresh
= true;
542 if (m_RelatedStatusBarIndex
!= -1)
544 SetHTMLStatusText(_("Connecting..."));
547 #endif // wxUSE_STATUSBAR
549 wxFSFile
*f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location
);
551 // try to interpret 'location' as filename instead of URL:
554 wxFileName
fn(location
);
555 wxString location2
= wxFileSystem::FileNameToURL(fn
);
556 f
= m_Parser
->OpenURL(wxHTML_URL_PAGE
, location2
);
561 wxLogError(_("Unable to open requested HTML document: %s"), location
.c_str());
563 SetHTMLStatusText(wxEmptyString
);
569 wxList::compatibility_iterator node
;
570 wxString src
= wxEmptyString
;
573 if (m_RelatedStatusBarIndex
!= -1)
575 wxString msg
= _("Loading : ") + location
;
576 SetHTMLStatusText(msg
);
579 #endif // wxUSE_STATUSBAR
581 node
= m_Filters
.GetFirst();
584 wxHtmlFilter
*h
= (wxHtmlFilter
*) node
->GetData();
587 src
= h
->ReadFile(*f
);
590 node
= node
->GetNext();
592 if (src
== wxEmptyString
)
594 if (m_DefaultFilter
== NULL
) m_DefaultFilter
= GetDefaultFilter();
595 src
= m_DefaultFilter
->ReadFile(*f
);
598 m_FS
->ChangePathTo(f
->GetLocation());
599 rt_val
= SetPage(src
);
600 m_OpenedPage
= f
->GetLocation();
601 if (f
->GetAnchor() != wxEmptyString
)
603 ScrollToAnchor(f
->GetAnchor());
609 if (m_RelatedStatusBarIndex
!= -1)
611 SetHTMLStatusText(_("Done"));
613 #endif // wxUSE_STATUSBAR
617 if (m_HistoryOn
) // add this page to history there:
619 int c
= m_History
->GetCount() - (m_HistoryPos
+ 1);
621 if (m_HistoryPos
< 0 ||
622 (*m_History
)[m_HistoryPos
].GetPage() != m_OpenedPage
||
623 (*m_History
)[m_HistoryPos
].GetAnchor() != m_OpenedAnchor
)
626 for (int i
= 0; i
< c
; i
++)
627 m_History
->RemoveAt(m_HistoryPos
);
628 m_History
->Add(new wxHtmlHistoryItem(m_OpenedPage
, m_OpenedAnchor
));
632 if (m_OpenedPageTitle
== wxEmptyString
)
633 OnSetTitle(wxFileNameFromPath(m_OpenedPage
));
647 bool wxHtmlWindow::LoadFile(const wxFileName
& filename
)
649 wxString url
= wxFileSystem::FileNameToURL(filename
);
650 return LoadPage(url
);
654 bool wxHtmlWindow::ScrollToAnchor(const wxString
& anchor
)
656 const wxHtmlCell
*c
= m_Cell
->Find(wxHTML_COND_ISANCHOR
, &anchor
);
659 wxLogWarning(_("HTML anchor %s does not exist."), anchor
.c_str());
664 // Go to next visible cell in current container, if it exists. This
665 // yields a bit better (even though still imperfect) results in that
666 // there's better chance of using a suitable cell for upper Y
667 // coordinate value. See bug #11406 for additional discussion.
668 const wxHtmlCell
*c_save
= c
;
669 while ( c
&& c
->IsFormattingCell() )
676 for (y
= 0; c
!= NULL
; c
= c
->GetParent()) y
+= c
->GetPosY();
677 Scroll(-1, y
/ wxHTML_SCROLL_STEP
);
678 m_OpenedAnchor
= anchor
;
684 void wxHtmlWindow::OnSetTitle(const wxString
& title
)
689 tit
.Printf(m_TitleFormat
, title
.c_str());
690 m_RelatedFrame
->SetTitle(tit
);
692 m_OpenedPageTitle
= title
;
696 // return scroll steps such that a) scrollbars aren't shown needlessly
697 // and b) entire content is viewable (i.e. round up)
698 static int ScrollSteps(int size
, int available
)
700 if ( size
<= available
)
703 return (size
+ wxHTML_SCROLL_STEP
- 1) / wxHTML_SCROLL_STEP
;
707 void wxHtmlWindow::CreateLayout()
709 // SetScrollbars() results in size change events -- and thus a nested
710 // CreateLayout() call -- on some platforms. Ignore nested calls, toplevel
711 // CreateLayout() will do the right thing eventually.
712 static wxRecursionGuardFlag s_flagReentrancy
;
713 wxRecursionGuard
guard(s_flagReentrancy
);
714 if ( guard
.IsInside() )
720 int clientWidth
, clientHeight
;
721 GetClientSize(&clientWidth
, &clientHeight
);
723 const int vscrollbar
= wxSystemSettings::GetMetric(wxSYS_VSCROLL_X
);
724 const int hscrollbar
= wxSystemSettings::GetMetric(wxSYS_HSCROLL_Y
);
726 if ( HasScrollbar(wxHORIZONTAL
) )
727 clientHeight
+= hscrollbar
;
729 if ( HasScrollbar(wxVERTICAL
) )
730 clientWidth
+= vscrollbar
;
732 if ( HasFlag(wxHW_SCROLLBAR_NEVER
) )
734 SetScrollbars(1, 1, 0, 0); // always off
735 m_Cell
->Layout(clientWidth
);
737 else // !wxHW_SCROLLBAR_NEVER
739 // Lay the content out with the assumption that it's too large to fit
740 // in the window (this is likely to be the case):
741 m_Cell
->Layout(clientWidth
- vscrollbar
);
743 // If the layout is wider than the window, horizontal scrollbar will
744 // certainly be shown. Account for it here for subsequent computations.
745 if ( m_Cell
->GetWidth() > clientWidth
)
746 clientHeight
-= hscrollbar
;
748 if ( m_Cell
->GetHeight() <= clientHeight
)
750 // we fit into the window, hide vertical scrollbar:
753 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
754 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
757 // ...and redo the layout to use the extra space
758 m_Cell
->Layout(clientWidth
);
762 // If the content doesn't fit into the window by only a small
763 // margin, chances are that it may fit fully with scrollbar turned
764 // off. It's something worth trying but on the other hand, we don't
765 // want to waste too much time redoing the layout (twice!) for
766 // long -- and thus expensive to layout -- pages. The cut-off value
767 // is an arbitrary heuristics.
768 static const int SMALL_OVERLAP
= 60;
769 if ( m_Cell
->GetHeight() <= clientHeight
+ SMALL_OVERLAP
)
771 m_Cell
->Layout(clientWidth
);
773 if ( m_Cell
->GetHeight() <= clientHeight
)
775 // Great, we fit in. Hide the scrollbar.
778 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
779 ScrollSteps(m_Cell
->GetWidth(), clientWidth
),
786 // That didn't work out, go back to previous layout. Note
787 // that redoing the layout once again here isn't as bad as
788 // it looks -- thanks to the small cut-off value, it's a
789 // reasonably small page.
790 m_Cell
->Layout(clientWidth
- vscrollbar
);
793 // else: the page is very long, it will certainly need scrollbar
797 wxHTML_SCROLL_STEP
, wxHTML_SCROLL_STEP
,
798 ScrollSteps(m_Cell
->GetWidth(), clientWidth
- vscrollbar
),
799 ScrollSteps(m_Cell
->GetHeight(), clientHeight
)
806 void wxHtmlWindow::ReadCustomization(wxConfigBase
*cfg
, wxString path
)
811 wxString p_fff
, p_ffn
;
813 if (path
!= wxEmptyString
)
815 oldpath
= cfg
->GetPath();
819 m_Borders
= cfg
->Read(wxT("wxHtmlWindow/Borders"), m_Borders
);
820 p_fff
= cfg
->Read(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
821 p_ffn
= cfg
->Read(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
822 for (int i
= 0; i
< 7; i
++)
824 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
825 p_fontsizes
[i
] = cfg
->Read(tmp
, m_Parser
->m_FontsSizes
[i
]);
827 SetFonts(p_ffn
, p_fff
, p_fontsizes
);
829 if (path
!= wxEmptyString
)
830 cfg
->SetPath(oldpath
);
835 void wxHtmlWindow::WriteCustomization(wxConfigBase
*cfg
, wxString path
)
840 if (path
!= wxEmptyString
)
842 oldpath
= cfg
->GetPath();
846 cfg
->Write(wxT("wxHtmlWindow/Borders"), (long) m_Borders
);
847 cfg
->Write(wxT("wxHtmlWindow/FontFaceFixed"), m_Parser
->m_FontFaceFixed
);
848 cfg
->Write(wxT("wxHtmlWindow/FontFaceNormal"), m_Parser
->m_FontFaceNormal
);
849 for (int i
= 0; i
< 7; i
++)
851 tmp
.Printf(wxT("wxHtmlWindow/FontsSize%i"), i
);
852 cfg
->Write(tmp
, (long) m_Parser
->m_FontsSizes
[i
]);
855 if (path
!= wxEmptyString
)
856 cfg
->SetPath(oldpath
);
858 #endif // wxUSE_CONFIG
860 bool wxHtmlWindow::HistoryBack()
864 if (m_HistoryPos
< 1) return false;
866 // store scroll position into history item:
868 GetViewStart(&x
, &y
);
869 (*m_History
)[m_HistoryPos
].SetPos(y
);
871 // go to previous position:
874 l
= (*m_History
)[m_HistoryPos
].GetPage();
875 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
878 if (a
== wxEmptyString
) LoadPage(l
);
879 else LoadPage(l
+ wxT("#") + a
);
882 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
887 bool wxHtmlWindow::HistoryCanBack()
889 if (m_HistoryPos
< 1) return false;
894 bool wxHtmlWindow::HistoryForward()
898 if (m_HistoryPos
== -1) return false;
899 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
901 m_OpenedPage
= wxEmptyString
; // this will disable adding new entry into history in LoadPage()
904 l
= (*m_History
)[m_HistoryPos
].GetPage();
905 a
= (*m_History
)[m_HistoryPos
].GetAnchor();
908 if (a
== wxEmptyString
) LoadPage(l
);
909 else LoadPage(l
+ wxT("#") + a
);
912 Scroll(0, (*m_History
)[m_HistoryPos
].GetPos());
917 bool wxHtmlWindow::HistoryCanForward()
919 if (m_HistoryPos
== -1) return false;
920 if (m_HistoryPos
>= (int)m_History
->GetCount() - 1)return false;
925 void wxHtmlWindow::HistoryClear()
931 void wxHtmlWindow::AddProcessor(wxHtmlProcessor
*processor
)
935 m_Processors
= new wxHtmlProcessorList
;
937 wxHtmlProcessorList::compatibility_iterator node
;
939 for (node
= m_Processors
->GetFirst(); node
; node
= node
->GetNext())
941 if (processor
->GetPriority() > node
->GetData()->GetPriority())
943 m_Processors
->Insert(node
, processor
);
947 m_Processors
->Append(processor
);
950 /*static */ void wxHtmlWindow::AddGlobalProcessor(wxHtmlProcessor
*processor
)
952 if (!m_GlobalProcessors
)
954 m_GlobalProcessors
= new wxHtmlProcessorList
;
956 wxHtmlProcessorList::compatibility_iterator node
;
958 for (node
= m_GlobalProcessors
->GetFirst(); node
; node
= node
->GetNext())
960 if (processor
->GetPriority() > node
->GetData()->GetPriority())
962 m_GlobalProcessors
->Insert(node
, processor
);
966 m_GlobalProcessors
->Append(processor
);
971 void wxHtmlWindow::AddFilter(wxHtmlFilter
*filter
)
973 m_Filters
.Append(filter
);
977 bool wxHtmlWindow::IsSelectionEnabled() const
980 return !HasFlag(wxHW_NO_SELECTION
);
988 wxString
wxHtmlWindow::DoSelectionToText(wxHtmlSelection
*sel
)
991 return wxEmptyString
;
996 wxHtmlTerminalCellsInterator
i(sel
->GetFromCell(), sel
->GetToCell());
997 const wxHtmlCell
*prev
= NULL
;
1001 // When converting HTML content to plain text, the entire paragraph
1002 // (container in wxHTML) goes on single line. A new paragraph (that
1003 // should go on its own line) has its own container. Therefore, the
1004 // simplest way of detecting where to insert newlines in plain text
1005 // is to check if the parent container changed -- if it did, we moved
1006 // to a new paragraph.
1007 if ( prev
&& prev
->GetParent() != i
->GetParent() )
1010 // NB: we don't need to pass the selection to ConvertToText() in the
1011 // middle of the selected text; it's only useful when only part of
1012 // a cell is selected
1013 text
<< i
->ConvertToText(sel
);
1021 wxString
wxHtmlWindow::ToText()
1025 wxHtmlSelection sel
;
1026 sel
.Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1027 return DoSelectionToText(&sel
);
1030 return wxEmptyString
;
1033 #endif // wxUSE_CLIPBOARD
1035 bool wxHtmlWindow::CopySelection(ClipboardType t
)
1040 #if defined(__UNIX__) && !defined(__WXMAC__)
1041 wxTheClipboard
->UsePrimarySelection(t
== Primary
);
1043 // Primary selection exists only under X11, so don't do anything under
1044 // the other platforms when we try to access it
1046 // TODO: this should be abstracted at wxClipboard level!
1049 #endif // __UNIX__/!__UNIX__
1051 if ( wxTheClipboard
->Open() )
1053 const wxString
txt(SelectionToText());
1054 wxTheClipboard
->SetData(new wxTextDataObject(txt
));
1055 wxTheClipboard
->Close();
1056 wxLogTrace(wxT("wxhtmlselection"),
1057 _("Copied to clipboard:\"%s\""), txt
.c_str());
1064 #endif // wxUSE_CLIPBOARD
1070 void wxHtmlWindow::OnLinkClicked(const wxHtmlLinkInfo
& link
)
1072 wxHtmlLinkEvent
event(GetId(), link
);
1073 event
.SetEventObject(this);
1074 if (!GetEventHandler()->ProcessEvent(event
))
1076 // the default behaviour is to load the URL in this window
1077 const wxMouseEvent
*e
= event
.GetLinkInfo().GetEvent();
1078 if (e
== NULL
|| e
->LeftUp())
1079 LoadPage(event
.GetLinkInfo().GetHref());
1083 void wxHtmlWindow::DoEraseBackground(wxDC
& dc
)
1085 // if we don't have any background bitmap we just fill it with background
1086 // colour and we also must do it if the background bitmap is not fully
1087 // opaque as otherwise junk could be left there
1088 if ( !m_bmpBg
.IsOk() || m_bmpBg
.GetMask() )
1090 dc
.SetBackground(GetBackgroundColour());
1094 if ( m_bmpBg
.IsOk() )
1096 // draw the background bitmap tiling it over the entire window area
1097 const wxSize sz
= GetVirtualSize();
1098 const wxSize
sizeBmp(m_bmpBg
.GetWidth(), m_bmpBg
.GetHeight());
1099 for ( wxCoord x
= 0; x
< sz
.x
; x
+= sizeBmp
.x
)
1101 for ( wxCoord y
= 0; y
< sz
.y
; y
+= sizeBmp
.y
)
1103 dc
.DrawBitmap(m_bmpBg
, x
, y
, true /* use mask */);
1109 void wxHtmlWindow::OnEraseBackground(wxEraseEvent
& WXUNUSED(event
))
1111 // We never get real erase background events as we changed our background
1112 // style to wxBG_STYLE_PAINT in our ctor so the only time when we get here
1113 // is when an artificial wxEraseEvent is generated by our own OnPaint()
1114 // below. This handler only exists to stop the event from propagating
1115 // downwards to wxWindow which may erase the background itself when it gets
1116 // it in some ports (currently this happens in wxUniv), so we simply stop
1117 // processing here and set a special flag allowing OnPaint() to see that
1118 // the event hadn't been really processed.
1119 m_isBgReallyErased
= false;
1122 void wxHtmlWindow::OnPaint(wxPaintEvent
& WXUNUSED(event
))
1124 wxPaintDC
dcPaint(this);
1126 if (m_tmpCanDrawLocks
> 0 || m_Cell
== NULL
)
1130 GetViewStart(&x
, &y
);
1131 const wxRect rect
= GetUpdateRegion().GetBox();
1132 const wxSize sz
= GetClientSize();
1134 // set up the DC we're drawing on: if the window is already double buffered
1135 // we do it directly on wxPaintDC, otherwise we allocate a backing store
1136 // buffer and compose the drawing there and then blit it to screen all at
1140 if ( IsDoubleBuffered() )
1144 else // window is not double buffered by the system, do it ourselves
1146 if ( !m_backBuffer
.IsOk() )
1147 m_backBuffer
.Create(sz
.x
, sz
.y
);
1148 dcm
.SelectObject(m_backBuffer
);
1154 // Erase the background: for compatibility, we must generate the event to
1155 // allow the user-defined handlers to do it, hence this hack with sending
1156 // an artificial wxEraseEvent to trigger the execution of such handlers.
1157 wxEraseEvent
eraseEvent(GetId(), dc
);
1158 eraseEvent
.SetEventObject(this);
1160 // Hack inside a hack: the background wasn't really erased if our own
1161 // OnEraseBackground() was executed, so we need to check for the flag set
1162 // by it whenever it's called.
1163 m_isBgReallyErased
= true; // Initially assume it wasn't.
1164 if ( !ProcessWindowEvent(eraseEvent
) || !m_isBgReallyErased
)
1166 // erase background ourselves
1167 DoEraseBackground(*dc
);
1169 //else: background erased by the user-defined handler
1172 // draw the HTML window contents
1173 dc
->SetMapMode(wxMM_TEXT
);
1174 dc
->SetBackgroundMode(wxTRANSPARENT
);
1175 dc
->SetLayoutDirection(GetLayoutDirection());
1177 wxHtmlRenderingInfo rinfo
;
1178 wxDefaultHtmlRenderingStyle rstyle
;
1179 rinfo
.SetSelection(m_selection
);
1180 rinfo
.SetStyle(&rstyle
);
1181 m_Cell
->Draw(*dc
, 0, 0,
1182 y
* wxHTML_SCROLL_STEP
+ rect
.GetTop(),
1183 y
* wxHTML_SCROLL_STEP
+ rect
.GetBottom(),
1186 #ifdef DEBUG_HTML_SELECTION
1189 wxGetMousePosition(&xc
, &yc
);
1190 ScreenToClient(&xc
, &yc
);
1191 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1192 wxHtmlCell
*at
= m_Cell
->FindCellByPos(x
, y
);
1193 wxHtmlCell
*before
=
1194 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_BEFORE
);
1196 m_Cell
->FindCellByPos(x
, y
, wxHTML_FIND_NEAREST_AFTER
);
1198 dc
->SetBrush(*wxTRANSPARENT_BRUSH
);
1199 dc
->SetPen(*wxBLACK_PEN
);
1201 dc
->DrawRectangle(at
->GetAbsPos(),
1202 wxSize(at
->GetWidth(),at
->GetHeight()));
1203 dc
->SetPen(*wxGREEN_PEN
);
1205 dc
->DrawRectangle(before
->GetAbsPos().x
+1, before
->GetAbsPos().y
+1,
1206 before
->GetWidth()-2,before
->GetHeight()-2);
1207 dc
->SetPen(*wxRED_PEN
);
1209 dc
->DrawRectangle(after
->GetAbsPos().x
+2, after
->GetAbsPos().y
+2,
1210 after
->GetWidth()-4,after
->GetHeight()-4);
1212 #endif // DEBUG_HTML_SELECTION
1214 if ( dc
!= &dcPaint
)
1216 dc
->SetDeviceOrigin(0,0);
1217 dcPaint
.Blit(0, rect
.GetTop(),
1218 sz
.x
, rect
.GetBottom() - rect
.GetTop() + 1,
1227 void wxHtmlWindow::OnSize(wxSizeEvent
& event
)
1231 m_backBuffer
= wxNullBitmap
;
1235 // Recompute selection if necessary:
1238 m_selection
->Set(m_selection
->GetFromCell(),
1239 m_selection
->GetToCell());
1240 m_selection
->ClearFromToCharacterPos();
1247 void wxHtmlWindow::OnMouseMove(wxMouseEvent
& WXUNUSED(event
))
1249 wxHtmlWindowMouseHelper::HandleMouseMoved();
1252 void wxHtmlWindow::OnMouseDown(wxMouseEvent
& event
)
1255 if ( event
.LeftDown() && IsSelectionEnabled() )
1257 const long TRIPLECLICK_LEN
= 200; // 0.2 sec after doubleclick
1258 if ( wxGetLocalTimeMillis() - m_lastDoubleClick
<= TRIPLECLICK_LEN
)
1260 SelectLine(CalcUnscrolledPosition(event
.GetPosition()));
1262 (void) CopySelection();
1266 m_makingSelection
= true;
1270 wxDELETE(m_selection
);
1273 m_tmpSelFromPos
= CalcUnscrolledPosition(event
.GetPosition());
1274 m_tmpSelFromCell
= NULL
;
1279 #endif // wxUSE_CLIPBOARD
1281 // in any case, let the default handler set focus to this window
1285 void wxHtmlWindow::OnMouseUp(wxMouseEvent
& event
)
1288 if ( m_makingSelection
)
1291 m_makingSelection
= false;
1293 // if m_selection=NULL, the user didn't move the mouse far enough from
1294 // starting point and the mouse up event is part of a click, the user
1295 // is not selecting text:
1298 CopySelection(Primary
);
1300 // we don't want mouse up event that ended selecting to be
1301 // handled as mouse click and e.g. follow hyperlink:
1305 #endif // wxUSE_CLIPBOARD
1307 wxPoint pos
= CalcUnscrolledPosition(event
.GetPosition());
1308 if ( !wxHtmlWindowMouseHelper::HandleMouseClick(m_Cell
, pos
, event
) )
1313 void wxHtmlWindow::OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
1315 if ( !m_makingSelection
)
1318 // discard the selecting operation
1319 m_makingSelection
= false;
1320 wxDELETE(m_selection
);
1321 m_tmpSelFromCell
= NULL
;
1324 #endif // wxUSE_CLIPBOARD
1327 void wxHtmlWindow::OnInternalIdle()
1329 wxWindow::OnInternalIdle();
1331 if (m_Cell
!= NULL
&& DidMouseMove())
1333 #ifdef DEBUG_HTML_SELECTION
1337 wxGetMousePosition(&xc
, &yc
);
1338 ScreenToClient(&xc
, &yc
);
1339 CalcUnscrolledPosition(xc
, yc
, &x
, &y
);
1341 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(x
, y
);
1343 // handle selection update:
1344 if ( m_makingSelection
)
1346 if ( !m_tmpSelFromCell
)
1347 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1348 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
);
1350 // NB: a trick - we adjust selFromPos to be upper left or bottom
1351 // right corner of the first cell of the selection depending
1352 // on whether the mouse is moving to the right or to the left.
1353 // This gives us more "natural" behaviour when selecting
1354 // a line (specifically, first cell of the next line is not
1355 // included if you drag selection from left to right over
1358 if ( !m_tmpSelFromCell
)
1360 dirFromPos
= m_tmpSelFromPos
;
1364 dirFromPos
= m_tmpSelFromCell
->GetAbsPos();
1365 if ( x
< m_tmpSelFromPos
.x
)
1367 dirFromPos
.x
+= m_tmpSelFromCell
->GetWidth();
1368 dirFromPos
.y
+= m_tmpSelFromCell
->GetHeight();
1371 bool goingDown
= dirFromPos
.y
< y
||
1372 (dirFromPos
.y
== y
&& dirFromPos
.x
< x
);
1374 // determine selection span:
1375 if ( /*still*/ !m_tmpSelFromCell
)
1379 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1380 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1381 wxHTML_FIND_NEAREST_AFTER
);
1382 if (!m_tmpSelFromCell
)
1383 m_tmpSelFromCell
= m_Cell
->GetFirstTerminal();
1387 m_tmpSelFromCell
= m_Cell
->FindCellByPos(
1388 m_tmpSelFromPos
.x
,m_tmpSelFromPos
.y
,
1389 wxHTML_FIND_NEAREST_BEFORE
);
1390 if (!m_tmpSelFromCell
)
1391 m_tmpSelFromCell
= m_Cell
->GetLastTerminal();
1395 wxHtmlCell
*selcell
= cell
;
1400 selcell
= m_Cell
->FindCellByPos(x
, y
,
1401 wxHTML_FIND_NEAREST_BEFORE
);
1403 selcell
= m_Cell
->GetLastTerminal();
1407 selcell
= m_Cell
->FindCellByPos(x
, y
,
1408 wxHTML_FIND_NEAREST_AFTER
);
1410 selcell
= m_Cell
->GetFirstTerminal();
1414 // NB: it may *rarely* happen that the code above didn't find one
1415 // of the cells, e.g. if wxHtmlWindow doesn't contain any
1417 if ( selcell
&& m_tmpSelFromCell
)
1421 // start selecting only if mouse movement was big enough
1422 // (otherwise it was meant as mouse click, not selection):
1423 const int PRECISION
= 2;
1424 wxPoint diff
= m_tmpSelFromPos
- wxPoint(x
,y
);
1425 if (abs(diff
.x
) > PRECISION
|| abs(diff
.y
) > PRECISION
)
1427 m_selection
= new wxHtmlSelection();
1432 if ( m_tmpSelFromCell
->IsBefore(selcell
) )
1434 m_selection
->Set(m_tmpSelFromPos
, m_tmpSelFromCell
,
1435 wxPoint(x
,y
), selcell
);
1439 m_selection
->Set(wxPoint(x
,y
), selcell
,
1440 m_tmpSelFromPos
, m_tmpSelFromCell
);
1442 m_selection
->ClearFromToCharacterPos();
1448 // handle cursor and status bar text changes:
1450 // NB: because we're passing in 'cell' and not 'm_Cell' (so that the
1451 // leaf cell lookup isn't done twice), we need to adjust the
1452 // position for the new root:
1453 wxPoint
posInCell(x
, y
);
1455 posInCell
-= cell
->GetAbsPos();
1456 wxHtmlWindowMouseHelper::HandleIdle(cell
, posInCell
);
1461 void wxHtmlWindow::StopAutoScrolling()
1463 if ( m_timerAutoScroll
)
1465 wxDELETE(m_timerAutoScroll
);
1469 void wxHtmlWindow::OnMouseEnter(wxMouseEvent
& event
)
1471 StopAutoScrolling();
1475 void wxHtmlWindow::OnMouseLeave(wxMouseEvent
& event
)
1477 // don't prevent the usual processing of the event from taking place
1480 // when a captured mouse leave a scrolled window we start generate
1481 // scrolling events to allow, for example, extending selection beyond the
1482 // visible area in some controls
1483 if ( wxWindow::GetCapture() == this )
1485 // where is the mouse leaving?
1487 wxPoint pt
= event
.GetPosition();
1490 orient
= wxHORIZONTAL
;
1493 else if ( pt
.y
< 0 )
1495 orient
= wxVERTICAL
;
1498 else // we're lower or to the right of the window
1500 wxSize size
= GetClientSize();
1501 if ( pt
.x
> size
.x
)
1503 orient
= wxHORIZONTAL
;
1504 pos
= GetVirtualSize().x
/ wxHTML_SCROLL_STEP
;
1506 else if ( pt
.y
> size
.y
)
1508 orient
= wxVERTICAL
;
1509 pos
= GetVirtualSize().y
/ wxHTML_SCROLL_STEP
;
1511 else // this should be impossible
1513 // but seems to happen sometimes under wxMSW - maybe it's a bug
1514 // there but for now just ignore it
1516 //wxFAIL_MSG( wxT("can't understand where has mouse gone") );
1522 // only start the auto scroll timer if the window can be scrolled in
1524 if ( !HasScrollbar(orient
) )
1527 delete m_timerAutoScroll
;
1528 m_timerAutoScroll
= new wxHtmlWinAutoScrollTimer
1531 pos
== 0 ? wxEVT_SCROLLWIN_LINEUP
1532 : wxEVT_SCROLLWIN_LINEDOWN
,
1536 m_timerAutoScroll
->Start(50); // FIXME: make configurable
1540 void wxHtmlWindow::OnKeyUp(wxKeyEvent
& event
)
1542 if ( IsSelectionEnabled() &&
1543 (event
.GetKeyCode() == 'C' && event
.CmdDown()) )
1545 wxClipboardTextEvent
evt(wxEVT_TEXT_COPY
, GetId());
1547 evt
.SetEventObject(this);
1549 GetEventHandler()->ProcessEvent(evt
);
1557 void wxHtmlWindow::OnCopy(wxCommandEvent
& WXUNUSED(event
))
1559 (void) CopySelection();
1562 void wxHtmlWindow::OnClipboardEvent(wxClipboardTextEvent
& WXUNUSED(event
))
1564 (void) CopySelection();
1567 void wxHtmlWindow::OnDoubleClick(wxMouseEvent
& event
)
1569 // select word under cursor:
1570 if ( IsSelectionEnabled() )
1572 SelectWord(CalcUnscrolledPosition(event
.GetPosition()));
1574 (void) CopySelection(Primary
);
1576 m_lastDoubleClick
= wxGetLocalTimeMillis();
1582 void wxHtmlWindow::SelectWord(const wxPoint
& pos
)
1586 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1590 m_selection
= new wxHtmlSelection();
1591 m_selection
->Set(cell
, cell
);
1592 RefreshRect(wxRect(CalcScrolledPosition(cell
->GetAbsPos()),
1593 wxSize(cell
->GetWidth(), cell
->GetHeight())));
1598 void wxHtmlWindow::SelectLine(const wxPoint
& pos
)
1602 wxHtmlCell
*cell
= m_Cell
->FindCellByPos(pos
.x
, pos
.y
);
1605 // We use following heuristic to find a "line": let the line be all
1606 // cells in same container as the cell under mouse cursor that are
1607 // neither completely above nor completely below the clicked cell
1608 // (i.e. are likely to be words positioned on same line of text).
1610 int y1
= cell
->GetAbsPos().y
;
1611 int y2
= y1
+ cell
->GetHeight();
1613 const wxHtmlCell
*c
;
1614 const wxHtmlCell
*before
= NULL
;
1615 const wxHtmlCell
*after
= NULL
;
1617 // find last cell of line:
1618 for ( c
= cell
->GetNext(); c
; c
= c
->GetNext())
1620 y
= c
->GetAbsPos().y
;
1621 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1629 // find first cell of line:
1630 for ( c
= cell
->GetParent()->GetFirstChild();
1631 c
&& c
!= cell
; c
= c
->GetNext())
1633 y
= c
->GetAbsPos().y
;
1634 if ( y
+ c
->GetHeight() > y1
&& y
< y2
)
1646 m_selection
= new wxHtmlSelection();
1647 m_selection
->Set(before
, after
);
1654 void wxHtmlWindow::SelectAll()
1659 m_selection
= new wxHtmlSelection();
1660 m_selection
->Set(m_Cell
->GetFirstTerminal(), m_Cell
->GetLastTerminal());
1665 #endif // wxUSE_CLIPBOARD
1669 IMPLEMENT_ABSTRACT_CLASS(wxHtmlProcessor
,wxObject
)
1671 wxBEGIN_PROPERTIES_TABLE(wxHtmlWindow
)
1674 style , wxHW_SCROLLBAR_AUTO
1675 borders , (dimension)
1679 wxEND_PROPERTIES_TABLE()
1681 wxBEGIN_HANDLERS_TABLE(wxHtmlWindow
)
1682 wxEND_HANDLERS_TABLE()
1684 wxCONSTRUCTOR_5( wxHtmlWindow
, wxWindow
* , Parent
, wxWindowID
, Id
, wxPoint
, Position
, wxSize
, Size
, long , WindowStyle
)
1686 wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxHtmlWindow
, wxScrolledWindow
,"wx/html/htmlwin.h")
1688 BEGIN_EVENT_TABLE(wxHtmlWindow
, wxScrolledWindow
)
1689 EVT_SIZE(wxHtmlWindow::OnSize
)
1690 EVT_LEFT_DOWN(wxHtmlWindow::OnMouseDown
)
1691 EVT_LEFT_UP(wxHtmlWindow::OnMouseUp
)
1692 EVT_RIGHT_UP(wxHtmlWindow::OnMouseUp
)
1693 EVT_MOTION(wxHtmlWindow::OnMouseMove
)
1694 EVT_PAINT(wxHtmlWindow::OnPaint
)
1695 EVT_ERASE_BACKGROUND(wxHtmlWindow::OnEraseBackground
)
1697 EVT_LEFT_DCLICK(wxHtmlWindow::OnDoubleClick
)
1698 EVT_ENTER_WINDOW(wxHtmlWindow::OnMouseEnter
)
1699 EVT_LEAVE_WINDOW(wxHtmlWindow::OnMouseLeave
)
1700 EVT_MOUSE_CAPTURE_LOST(wxHtmlWindow::OnMouseCaptureLost
)
1701 EVT_KEY_UP(wxHtmlWindow::OnKeyUp
)
1702 EVT_MENU(wxID_COPY
, wxHtmlWindow::OnCopy
)
1703 EVT_TEXT_COPY(wxID_ANY
, wxHtmlWindow::OnClipboardEvent
)
1704 #endif // wxUSE_CLIPBOARD
1707 //-----------------------------------------------------------------------------
1708 // wxHtmlWindowInterface implementation in wxHtmlWindow
1709 //-----------------------------------------------------------------------------
1711 void wxHtmlWindow::SetHTMLWindowTitle(const wxString
& title
)
1716 void wxHtmlWindow::OnHTMLLinkClicked(const wxHtmlLinkInfo
& link
)
1718 OnLinkClicked(link
);
1721 wxHtmlOpeningStatus
wxHtmlWindow::OnHTMLOpeningURL(wxHtmlURLType type
,
1722 const wxString
& url
,
1723 wxString
*redirect
) const
1725 return OnOpeningURL(type
, url
, redirect
);
1728 wxPoint
wxHtmlWindow::HTMLCoordsToWindow(wxHtmlCell
*WXUNUSED(cell
),
1729 const wxPoint
& pos
) const
1731 return CalcScrolledPosition(pos
);
1734 wxWindow
* wxHtmlWindow::GetHTMLWindow()
1739 wxColour
wxHtmlWindow::GetHTMLBackgroundColour() const
1741 return GetBackgroundColour();
1744 void wxHtmlWindow::SetHTMLBackgroundColour(const wxColour
& clr
)
1746 SetBackgroundColour(clr
);
1749 void wxHtmlWindow::SetHTMLBackgroundImage(const wxBitmap
& bmpBg
)
1751 SetBackgroundImage(bmpBg
);
1754 void wxHtmlWindow::SetHTMLStatusText(const wxString
& text
)
1757 if (m_RelatedStatusBarIndex
!= -1)
1759 if (m_RelatedStatusBar
)
1761 m_RelatedStatusBar
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1763 else if (m_RelatedFrame
)
1765 m_RelatedFrame
->SetStatusText(text
, m_RelatedStatusBarIndex
);
1770 #endif // wxUSE_STATUSBAR
1774 wxCursor
wxHtmlWindow::GetDefaultHTMLCursor(HTMLCursor type
)
1778 case HTMLCursor_Link
:
1779 if ( !ms_cursorLink
)
1780 ms_cursorLink
= new wxCursor(wxCURSOR_HAND
);
1781 return *ms_cursorLink
;
1783 case HTMLCursor_Text
:
1784 if ( !ms_cursorText
)
1785 ms_cursorText
= new wxCursor(wxCURSOR_IBEAM
);
1786 return *ms_cursorText
;
1788 case HTMLCursor_Default
:
1790 return *wxSTANDARD_CURSOR
;
1794 wxCursor
wxHtmlWindow::GetHTMLCursor(HTMLCursor type
) const
1796 return GetDefaultHTMLCursor(type
);
1800 //-----------------------------------------------------------------------------
1802 //-----------------------------------------------------------------------------
1804 // A module to allow initialization/cleanup
1805 // without calling these functions from app.cpp or from
1806 // the user's application.
1808 class wxHtmlWinModule
: public wxModule
1810 DECLARE_DYNAMIC_CLASS(wxHtmlWinModule
)
1812 wxHtmlWinModule() : wxModule() {}
1813 bool OnInit() { return true; }
1814 void OnExit() { wxHtmlWindow::CleanUpStatics(); }
1817 IMPLEMENT_DYNAMIC_CLASS(wxHtmlWinModule
, wxModule
)
1820 // This hack forces the linker to always link in m_* files
1821 // (wxHTML doesn't work without handlers from these files)
1822 #include "wx/html/forcelnk.h"
1823 FORCE_WXHTML_MODULES()
1825 #endif // wxUSE_HTML