Skip to content

Commit

Permalink
Manager: support wxWidgets without webview component
Browse files Browse the repository at this point in the history
This is a combination of contributions by Jan Engelhardt (#2093) and Olly Betts (https://anonscm.debian.org/cgit/pkg-boinc/boinc.git/commit/?id=60f4cd232522db0750b2dff56bd327dc44a51534) to make the Manager work without webview support. This is mainly needed for Linux distributions that are migrating to a newer webkitgtk library.
  • Loading branch information
ChristianBeer committed Jan 29, 2018
1 parent 8e3ab60 commit 27bb3c9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 5 deletions.
28 changes: 25 additions & 3 deletions clientgui/NoticeListCtrl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,12 @@ IMPLEMENT_DYNAMIC_CLASS( CNoticeListCtrl, wxWindow )
BEGIN_EVENT_TABLE( CNoticeListCtrl, wxWindow )

////@begin CNoticeListCtrl event table entries
#if wxUSE_WEBVIEW
EVT_WEBVIEW_NAVIGATING(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnLinkClicked)
EVT_WEBVIEW_ERROR(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnWebViewError)
#else
EVT_HTML_LINK_CLICKED(ID_LIST_NOTIFICATIONSVIEW, CNoticeListCtrl::OnLinkClicked)
#endif
////@end CNoticeListCtrl event table entries

END_EVENT_TABLE()
Expand Down Expand Up @@ -83,8 +87,11 @@ bool CNoticeListCtrl::Create( wxWindow* parent ) {
////@begin CNoticeListCtrl creation
wxWindow::Create( parent, ID_LIST_NOTIFICATIONSVIEW, wxDefaultPosition, wxDefaultSize,
wxSUNKEN_BORDER | wxTAB_TRAVERSAL );

#if wxUSE_WEBVIEW
m_browser = wxWebView::New( this, ID_LIST_NOTIFICATIONSVIEW );
#else
m_browser = new wxHtmlWindow( this, ID_LIST_NOTIFICATIONSVIEW );
#endif
////@end CNoticeListCtrl creation

wxBoxSizer *topsizer;
Expand Down Expand Up @@ -238,7 +245,11 @@ void CNoticeListCtrl::SetItemCount(int newCount) {
m_noticesBody += wxT("</font></body></html>");
// baseURL is not needed here (see comments above) and it
// must be an empty string for this to work under OS 10.12.4
#if wxUSE_WEBVIEW
m_browser->SetPage(m_noticesBody, wxEmptyString);
#else
m_browser->SetPage(m_noticesBody);
#endif
}


Expand All @@ -247,7 +258,7 @@ void CNoticeListCtrl::Clear() {
UpdateUI();
}


#if wxUSE_WEBVIEW
void CNoticeListCtrl::OnLinkClicked( wxWebViewEvent& event ) {
if (event.GetURL().StartsWith(wxT("http://")) || event.GetURL().StartsWith(wxT("https://"))) {
event.Veto(); // Tell wxWebView not to follow link
Expand All @@ -264,7 +275,18 @@ void CNoticeListCtrl::OnWebViewError( wxWebViewEvent& event ) {

event.Skip();
}

#else
void CNoticeListCtrl::OnLinkClicked( wxHtmlLinkEvent& event ) {
wxString url = event.GetLinkInfo().GetHref();
if (url.StartsWith(wxT("http://")) || url.StartsWith(wxT("https://"))) {
// wxHtmlLinkEvent doesn't have Veto(), but only loads the page if you
// call Skip().
wxLaunchDefaultBrowser(url);
} else {
event.Skip();
}
}
#endif

/*!
* Update the UI.
Expand Down
11 changes: 9 additions & 2 deletions clientgui/NoticeListCtrl.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,14 @@ class CNoticeListCtrl: public wxWindow

int GetItemCount();
void SetItemCount(int newCount);

////@begin CNoticeListCtrl event handler declarations

////@begin CNoticeListCtrl event handler declarations
#if wxUSE_WEBVIEW
void OnLinkClicked( wxWebViewEvent& event );
void OnWebViewError( wxWebViewEvent& event );
#else
void OnLinkClicked( wxHtmlLinkEvent & event );
#endif

////@end CNoticeListCtrl event handler declarations

Expand All @@ -56,7 +59,11 @@ class CNoticeListCtrl: public wxWindow
bool m_bDisplayFetchingNotices;
bool m_bDisplayEmptyNotice;
private:
#if wxUSE_WEBVIEW
wxWebView* m_browser;
#else
wxHtmlWindow* m_browser;
#endif
bool m_bNeedsReloading;
int m_itemCount;
wxString m_noticesBody;
Expand Down
2 changes: 2 additions & 0 deletions clientgui/stdwx.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,10 @@
#include <wx/mstream.h>
#include <wx/hash.h>
#include <wx/selstore.h>
#if wxUSE_WEBVIEW
#include <wx/webview.h>
#include <wx/webviewfshandler.h>
#endif
#include <wx/snglinst.h>
#include <wx/bmpcbox.h>
#include <wx/evtloop.h>
Expand Down

0 comments on commit 27bb3c9

Please sign in to comment.