From 74af0b13434f4fa5c814a19a6d325d271944accf Mon Sep 17 00:00:00 2001 From: Steve Lamerton Date: Thu, 30 Jun 2011 19:57:26 +0000 Subject: [PATCH] Add support for the new history functions to the ie backend. For this we manage our own history as there are no suitable built-in ways of managing it. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/SOC2011_WEBVIEW@68116 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/msw/webview_ie.h | 30 +++++++++++++--- src/msw/webview_ie.cpp | 72 ++++++++++++++++++++++++++++++++----- 2 files changed, 88 insertions(+), 14 deletions(-) diff --git a/include/wx/msw/webview_ie.h b/include/wx/msw/webview_ie.h index 216df27b93..608f4349cf 100644 --- a/include/wx/msw/webview_ie.h +++ b/include/wx/msw/webview_ie.h @@ -3,7 +3,7 @@ // Purpose: wxMSW IE wxWebView backend // Author: Marianne Gagnon // Id: $Id$ -// Copyright: (c) 2010 Marianne Gagnon +// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -18,6 +18,19 @@ #include "wx/webview.h" #include "wx/msw/ole/automtn.h" #include "wx/msw/ole/activex.h" +#include "wx/sharedptr.h" + +class WXDLLIMPEXP_WEB wxWebHistoryItem +{ +public: + wxWebHistoryItem(const wxString& url, const wxString& title) : + m_url(url), m_title(title) {} + wxString GetUrl() { return m_url; } + wxString GetTitle() { return m_title; } + +private: + wxString m_url, m_title; +}; class WXDLLIMPEXP_WEB wxWebViewIE : public wxWebView { @@ -45,13 +58,14 @@ public: const wxString& name = wxWebViewNameStr); virtual void LoadUrl(const wxString& url); + virtual void LoadHistoryItem(wxWebHistoryItem* item); - virtual bool CanGoForward() { return m_canNavigateForward; } - virtual bool CanGoBack() { return m_canNavigateBack; } + virtual bool CanGoForward(); + virtual bool CanGoBack(); virtual void GoBack(); virtual void GoForward(); - virtual void ClearHistory() {}; - virtual void EnableHistory(bool enable = true) {}; + virtual void ClearHistory(); + virtual void EnableHistory(bool enable = true); virtual void Stop(); virtual void Reload(wxWebViewReloadFlags flags = wxWEB_VIEW_RELOAD_DEFAULT); @@ -110,6 +124,12 @@ private: * Busy property is false but should be true. */ bool m_isBusy; + //We manage our own history + wxVector > m_historyList; + int m_historyPosition; + bool m_historyLoadingFromList; + bool m_historyEnabled; + }; #endif // wxUSE_WEBVIEW_IE diff --git a/src/msw/webview_ie.cpp b/src/msw/webview_ie.cpp index 91393120ef..d87ec525b6 100644 --- a/src/msw/webview_ie.cpp +++ b/src/msw/webview_ie.cpp @@ -3,7 +3,7 @@ // Purpose: wxMSW wxWebViewIE class implementation for web view component // Author: Marianne Gagnon // Id: $Id$ -// Copyright: (c) 2010 Marianne Gagnon +// Copyright: (c) 2010 Marianne Gagnon, Steven Lamerton // Licence: wxWindows licence ///////////////////////////////////////////////////////////////////////////// @@ -93,6 +93,9 @@ bool wxWebViewIE::Create(wxWindow* parent, m_canNavigateBack = false; m_canNavigateForward = false; m_isBusy = false; + m_historyLoadingFromList = false; + m_historyEnabled = true; + m_historyPosition = -1; if (::CoCreateInstance(CLSID_WebBrowser, NULL, CLSCTX_INPROC_SERVER, // CLSCTX_INPROC, @@ -354,20 +357,43 @@ void wxWebViewIE::Print() OLECMDEXECOPT_DODEFAULT, NULL, NULL); } -void wxWebViewIE::GoBack() +bool wxWebViewIE::CanGoBack() { - wxVariant out = m_ie.CallMethod("GoBack"); + if(m_historyEnabled) + return m_historyPosition > 0; + else + return false; +} - // FIXME: why is out value null?? - //return (HRESULT)(out.GetLong()) == S_OK; +bool wxWebViewIE::CanGoForward() +{ + if(m_historyEnabled) + return m_historyPosition != m_historyList.size() - 1; + else + return false; } -void wxWebViewIE::GoForward() +void wxWebViewIE::LoadHistoryItem(wxWebHistoryItem* item) { - wxVariant out = m_ie.CallMethod("GoForward"); + int pos = -1; + for(unsigned int i = 0; i < m_historyList.size(); i++) + { + if(m_historyList[i].get() == item) + pos = i; + } + m_historyLoadingFromList = true; + LoadUrl(item->GetUrl()); + m_historyPosition = pos; +} - // FIXME: why is out value null?? - //return (HRESULT)(out.GetLong()) == S_OK; +void wxWebViewIE::GoBack() +{ + LoadHistoryItem(m_historyList[m_historyPosition - 1].get()); +} + +void wxWebViewIE::GoForward() +{ + LoadHistoryItem(m_historyList[m_historyPosition + 1].get()); } void wxWebViewIE::Stop() @@ -378,6 +404,18 @@ void wxWebViewIE::Stop() //return (HRESULT)(out.GetLong()) == S_OK; } +void wxWebViewIE::ClearHistory() +{ + m_historyList.clear(); + m_historyPosition = -1; +} + +void wxWebViewIE::EnableHistory(bool enable) +{ + m_historyEnabled = enable; + m_historyList.clear(); + m_historyPosition = -1; +} void wxWebViewIE::Reload(wxWebViewReloadFlags flags) { @@ -508,6 +546,22 @@ void wxWebViewIE::onActiveXEvent(wxActiveXEvent& evt) break; wxString url = evt[1].GetString(); + //As we are complete we also add to the history list + if(m_historyEnabled && !m_historyLoadingFromList) + { + //If we are not at the end of the list, then erase everything + //between us and the end before adding the new page + if(m_historyPosition != m_historyList.size() - 1) + { + m_historyList.erase(m_historyList.begin() + m_historyPosition + 1, + m_historyList.end()); + } + wxSharedPtr item(new wxWebHistoryItem(url, GetCurrentTitle())); + m_historyList.push_back(item); + m_historyPosition++; + } + //Reset as we are done now + m_historyLoadingFromList = false; // TODO: set target parameter if possible wxString target = wxEmptyString; wxWebNavigationEvent event(wxEVT_COMMAND_WEB_VIEW_LOADED, GetId(), -- 2.45.2