// 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
/////////////////////////////////////////////////////////////////////////////
#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
{
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);
* Busy property is false but should be true.
*/
bool m_isBusy;
+ //We manage our own history
+ wxVector<wxSharedPtr<wxWebHistoryItem> > m_historyList;
+ int m_historyPosition;
+ bool m_historyLoadingFromList;
+ bool m_historyEnabled;
+
};
#endif // wxUSE_WEBVIEW_IE
// 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
/////////////////////////////////////////////////////////////////////////////
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,
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()
//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)
{
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<wxWebHistoryItem> 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(),