+ // true is to force the frame to close
+ Close(true);
+}
+
+void MyFrame::OnPageOpen(wxCommandEvent& WXUNUSED(event))
+{
+#if wxUSE_FILEDLG
+ wxString p = wxFileSelector(_("Open HTML document"), wxEmptyString,
+ wxEmptyString, wxEmptyString, wxT("HTML files|*.htm;*.html"));
+
+ if (!p.empty())
+ m_Html->LoadFile(wxFileName(p));
+#endif // wxUSE_FILEDLG
+}
+
+void MyFrame::OnDefaultLocalBrowser(wxCommandEvent& WXUNUSED(event))
+{
+ wxString page = m_Html->GetOpenedPage();
+ if (!page.empty())
+ {
+ wxLaunchDefaultBrowser(page);
+ }
+}
+
+void MyFrame::OnDefaultWebBrowser(wxCommandEvent& WXUNUSED(event))
+{
+ wxString page = m_Html->GetOpenedPage();
+ if (!page.empty())
+ {
+ wxLaunchDefaultBrowser(wxT("http://www.google.com"));
+ }
+}
+
+void MyFrame::OnBack(wxCommandEvent& WXUNUSED(event))
+{
+ if (!m_Html->HistoryBack())
+ {
+ wxMessageBox(_("You reached prehistory era!"));
+ }
+}
+
+void MyFrame::OnForward(wxCommandEvent& WXUNUSED(event))
+{
+ if (!m_Html->HistoryForward())
+ {
+ wxMessageBox(_("No more items in history!"));
+ }
+}
+
+void MyFrame::OnProcessor(wxCommandEvent& WXUNUSED(event))
+{
+ m_Processor->Enable(!m_Processor->IsEnabled());
+ m_Html->LoadPage(m_Html->GetOpenedPage());
+}
+
+void MyFrame::OnHtmlLinkClicked(wxHtmlLinkEvent &event)
+{
+ wxLogMessage(wxT("The url '%s' has been clicked!"), event.GetLinkInfo().GetHref().c_str());
+
+ // skipping this event the default behaviour (load the clicked URL)
+ // will happen...
+ event.Skip();
+}
+
+void MyFrame::OnHtmlCellHover(wxHtmlCellEvent &event)
+{
+ wxLogMessage(wxT("Mouse moved over cell %p at %d;%d"),
+ event.GetCell(), event.GetPoint().x, event.GetPoint().y);
+}
+
+void MyFrame::OnHtmlCellClicked(wxHtmlCellEvent &event)
+{
+ wxLogMessage(wxT("Click over cell %p at %d;%d"),
+ event.GetCell(), event.GetPoint().x, event.GetPoint().y);
+
+ // if we don't skip the event, OnHtmlLinkClicked won't be called!
+ event.Skip();
+}
+
+wxHtmlOpeningStatus MyHtmlWindow::OnOpeningURL(wxHtmlURLType WXUNUSED(type),
+ const wxString& url,
+ wxString *WXUNUSED(redirect)) const
+{
+ GetRelatedFrame()->SetStatusText(url + _T(" lately opened"),1);
+ return wxHTML_OPEN;
+}
+
+#if wxUSE_CLIPBOARD
+BEGIN_EVENT_TABLE(MyHtmlWindow, wxHtmlWindow)
+ EVT_TEXT_COPY(wxID_ANY, MyHtmlWindow::OnClipboardEvent)
+END_EVENT_TABLE()
+
+void MyHtmlWindow::OnClipboardEvent(wxClipboardTextEvent& WXUNUSED(event))
+{
+ // explicitly call wxHtmlWindow::CopySelection() method
+ // and show the first 100 characters of the text copied in the status bar
+ if ( CopySelection() )
+ {
+ wxTextDataObject data;
+ if ( wxTheClipboard && wxTheClipboard->GetData(data) )
+ {
+ const wxString text = data.GetText();
+ const size_t maxTextLength = 100;
+
+ wxLogStatus(wxString::Format(_T("Clipboard: '%s%s'"),
+ wxString(text, maxTextLength).c_str(),
+ (text.length() > maxTextLength) ? _T("...")
+ : _T("")));
+ return;
+ }
+ }
+
+ wxLogStatus(_T("Clipboard: nothing"));
+}
+#endif // wxUSE_CLIPBOARD